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

scanning: Add supported page sizes to ScanSource

For each scan source reported by lorgnette, use its scannable area to
determine the page sizes it supports. Add these page sizes to each
ScanSource reported by ScanService.

Bug: 1059779
Change-Id: Id909260f2de8eeebf15d1d67776403c993b81c2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2481742Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818964}
parent 4ec254aa
...@@ -13,6 +13,45 @@ namespace { ...@@ -13,6 +13,45 @@ namespace {
namespace mojo_ipc = chromeos::scanning::mojom; namespace mojo_ipc = chromeos::scanning::mojom;
// POD struct for page size dimensions in mm.
struct PageSize {
int width;
int height;
};
// ISO A4: 210 x 297 mm.
constexpr PageSize kIsoA4PageSize = {
210,
297,
};
// NA Letter: 216 x 279 mm.
constexpr PageSize kNaLetterPageSize = {
216,
279,
};
// 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;
}
// Returns the page sizes the given |area| supports.
std::vector<mojo_ipc::PageSize> GetSupportedPageSizes(
const lorgnette::ScannableArea& area) {
std::vector<mojo_ipc::PageSize> page_sizes;
page_sizes.reserve(3);
page_sizes.push_back(mojo_ipc::PageSize::kMax);
if (AreaSupportsPageSize(area, kIsoA4PageSize))
page_sizes.push_back(mojo_ipc::PageSize::kIsoA4);
if (AreaSupportsPageSize(area, kNaLetterPageSize))
page_sizes.push_back(mojo_ipc::PageSize::kNaLetter);
return page_sizes;
}
} // namespace } // namespace
template <> template <>
...@@ -77,7 +116,8 @@ mojo_ipc::ScannerCapabilitiesPtr TypeConverter<mojo_ipc::ScannerCapabilitiesPtr, ...@@ -77,7 +116,8 @@ mojo_ipc::ScannerCapabilitiesPtr TypeConverter<mojo_ipc::ScannerCapabilitiesPtr,
mojo_caps.sources.reserve(lorgnette_caps.sources().size()); mojo_caps.sources.reserve(lorgnette_caps.sources().size());
for (const auto& source : lorgnette_caps.sources()) { for (const auto& source : lorgnette_caps.sources()) {
mojo_caps.sources.push_back(mojo_ipc::ScanSource::New( mojo_caps.sources.push_back(mojo_ipc::ScanSource::New(
mojo::ConvertTo<mojo_ipc::SourceType>(source.type()), source.name())); mojo::ConvertTo<mojo_ipc::SourceType>(source.type()), source.name(),
GetSupportedPageSizes(source.area())));
} }
mojo_caps.color_modes.reserve(lorgnette_caps.color_modes().size()); mojo_caps.color_modes.reserve(lorgnette_caps.color_modes().size());
......
...@@ -6,12 +6,15 @@ ...@@ -6,12 +6,15 @@
#include "chromeos/components/scanning/mojom/scanning.mojom.h" #include "chromeos/components/scanning/mojom/scanning.mojom.h"
#include "chromeos/dbus/lorgnette/lorgnette_service.pb.h" #include "chromeos/dbus/lorgnette/lorgnette_service.pb.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos { namespace chromeos {
namespace { namespace {
using ::testing::ElementsAreArray;
namespace mojo_ipc = scanning::mojom; namespace mojo_ipc = scanning::mojom;
// POD struct for ScannerCapabilitiesTest. // POD struct for ScannerCapabilitiesTest.
...@@ -31,6 +34,11 @@ struct ScanSettingsTestParams { ...@@ -31,6 +34,11 @@ struct ScanSettingsTestParams {
// Document source name used for tests. // Document source name used for tests.
constexpr char kDocumentSourceName[] = "Test Name"; constexpr char kDocumentSourceName[] = "Test Name";
// Scannable area dimensions used for tests. These are large enough to ensure
// every page size is supported by the scanner.
constexpr int kScanAreaWidthMm = 500;
constexpr int kScanAreaHeightMm = 750;
// Resolutions used for tests. // Resolutions used for tests.
constexpr uint32_t kFirstResolution = 75; constexpr uint32_t kFirstResolution = 75;
constexpr uint32_t kSecondResolution = 300; constexpr uint32_t kSecondResolution = 300;
...@@ -41,6 +49,8 @@ lorgnette::DocumentSource CreateLorgnetteDocumentSource( ...@@ -41,6 +49,8 @@ lorgnette::DocumentSource CreateLorgnetteDocumentSource(
lorgnette::DocumentSource source; lorgnette::DocumentSource source;
source.set_type(source_type); source.set_type(source_type);
source.set_name(kDocumentSourceName); source.set_name(kDocumentSourceName);
source.mutable_area()->set_width(kScanAreaWidthMm);
source.mutable_area()->set_height(kScanAreaHeightMm);
return source; return source;
} }
...@@ -96,6 +106,10 @@ TEST_P(ScannerCapabilitiesTest, LorgnetteCapsToMojom) { ...@@ -96,6 +106,10 @@ TEST_P(ScannerCapabilitiesTest, LorgnetteCapsToMojom) {
ASSERT_EQ(mojo_caps->sources.size(), 1u); ASSERT_EQ(mojo_caps->sources.size(), 1u);
EXPECT_EQ(mojo_caps->sources[0]->type, params().mojom_source_type); EXPECT_EQ(mojo_caps->sources[0]->type, params().mojom_source_type);
EXPECT_EQ(mojo_caps->sources[0]->name, kDocumentSourceName); EXPECT_EQ(mojo_caps->sources[0]->name, kDocumentSourceName);
EXPECT_THAT(
mojo_caps->sources[0]->page_sizes,
ElementsAreArray({mojo_ipc::PageSize::kMax, mojo_ipc::PageSize::kIsoA4,
mojo_ipc::PageSize::kNaLetter}));
ASSERT_EQ(mojo_caps->color_modes.size(), 1u); ASSERT_EQ(mojo_caps->color_modes.size(), 1u);
EXPECT_EQ(mojo_caps->color_modes[0], params().mojom_color_mode); EXPECT_EQ(mojo_caps->color_modes[0], params().mojom_color_mode);
ASSERT_EQ(mojo_caps->resolutions.size(), 2u); ASSERT_EQ(mojo_caps->resolutions.size(), 2u);
......
...@@ -36,6 +36,16 @@ enum SourceType { ...@@ -36,6 +36,16 @@ enum SourceType {
kDefault, kDefault,
}; };
// The page sizes that can be used to perform a scan.
enum PageSize {
// ISO A4 (210 x 297 mm).
kIsoA4,
// NA Letter (216 x 279 mm).
kNaLetter,
// The page size resulting from scanning the scanner's entire scannable area.
kMax,
};
// The source from which a scan can be obtained. // The source from which a scan can be obtained.
struct ScanSource { struct ScanSource {
// The type of this source. // The type of this source.
...@@ -43,6 +53,8 @@ struct ScanSource { ...@@ -43,6 +53,8 @@ struct ScanSource {
// The name of this source. Source names are unique to each SANE backend and // The name of this source. Source names are unique to each SANE backend and
// are required to perform scans. // are required to perform scans.
string name; string name;
// The page sizes supported by this source.
array<PageSize> page_sizes;
}; };
// The capabilities a scanner supports. // The capabilities a scanner supports.
......
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