Commit adc32c96 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Fix page size dimensions

Update the Letter page size dimensions to be more precise instead of
rounding to the nearest integer. Also, add in some margin when
determining whether a scan area can support a page size in case there
are slight differences due to rounding.

Bug: 171813619
Change-Id: Ie82e8cd28c94540b909884f6f7e89789769bbe22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2504549
Auto-Submit: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821865}
parent f73174ec
......@@ -13,10 +13,14 @@ namespace {
namespace mojo_ipc = chromeos::scanning::mojom;
// The margin allowed when comparing a scannable area dimension to a page size
// dimension. Accounts for differences due to rounding.
constexpr double kMargin = 1;
// POD struct for page size dimensions in mm.
struct PageSize {
int width;
int height;
double width;
double height;
};
// ISO A4: 210 x 297 mm.
......@@ -25,16 +29,17 @@ constexpr PageSize kIsoA4PageSize = {
297,
};
// NA Letter: 216 x 279 mm.
// NA Letter: 215.9 x 279.4 mm.
constexpr PageSize kNaLetterPageSize = {
216,
279,
215.9,
279.4,
};
// Returns true if |area| is large enough to support |page_size|.
bool AreaSupportsPageSize(const lorgnette::ScannableArea& area,
const PageSize& page_size) {
return area.width() >= page_size.width && area.height() >= page_size.height;
return area.width() + kMargin >= page_size.width &&
area.height() + kMargin >= page_size.height;
}
// Returns the page sizes the given |area| supports.
......
......@@ -190,8 +190,8 @@ INSTANTIATE_TEST_SUITE_P(
297},
ScanSettingsTestParams{mojo_ipc::ColorMode::kGrayscale,
lorgnette::MODE_GRAYSCALE,
mojo_ipc::PageSize::kNaLetter, 216,
279},
mojo_ipc::PageSize::kNaLetter, 215.9,
279.4},
ScanSettingsTestParams{mojo_ipc::ColorMode::kColor,
lorgnette::MODE_COLOR,
mojo_ipc::PageSize::kMax, 0, 0}));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment