Add a max height to Paper
Certain printers can print custom sizes in addition to specific sizes. Update Paper so that is supports these custom sizes using a range. Bug: b:271874152 Test: ./out/Default/printing_unittests Change-Id: Id110754b3aa67ca7db5953a847df2ef6dd841302 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4574990 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Nathan Muggli <nmuggli@google.com> Cr-Commit-Position: refs/heads/main@{#1160636}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
43f3f30907
commit
97f147f67a
@ -110,6 +110,14 @@ constexpr char kExpectedMediaSize[] = R"json({
|
||||
"imageable_area_top_microns": 10200,
|
||||
"vendor_id": "89",
|
||||
"width_microns": 6600
|
||||
}, {
|
||||
"custom_display_name": "Custom",
|
||||
"height_microns": 5080,
|
||||
"imageable_area_bottom_microns": 0,
|
||||
"imageable_area_left_microns": 0,
|
||||
"imageable_area_right_microns": 2540,
|
||||
"imageable_area_top_microns": 5080,
|
||||
"width_microns": 2540
|
||||
}
|
||||
]})json";
|
||||
|
||||
@ -180,6 +188,14 @@ constexpr char kExpectedMediaSizeWithWiderPaper[] = R"json({
|
||||
"imageable_area_top_microns": 10200,
|
||||
"vendor_id": "89",
|
||||
"width_microns": 6600
|
||||
}, {
|
||||
"custom_display_name": "Custom",
|
||||
"height_microns": 5080,
|
||||
"imageable_area_bottom_microns": 0,
|
||||
"imageable_area_left_microns": 0,
|
||||
"imageable_area_right_microns": 2540,
|
||||
"imageable_area_top_microns": 5080,
|
||||
"width_microns": 2540
|
||||
}
|
||||
]})json";
|
||||
|
||||
|
@ -29,6 +29,7 @@ struct Paper {
|
||||
string vendor_id;
|
||||
gfx.mojom.Size size_um;
|
||||
[MinVersion=1] gfx.mojom.Rect? printable_area_um;
|
||||
[MinVersion=2] int32 max_height_um;
|
||||
};
|
||||
|
||||
// An advanced capability value for ChromeOS printing.
|
||||
|
@ -118,6 +118,7 @@ bool StructTraits<printing::mojom::PaperDataView,
|
||||
!data.ReadPrintableAreaUm(&printable_area_um)) {
|
||||
return false;
|
||||
}
|
||||
out->max_height_um = data.max_height_um();
|
||||
|
||||
// For backwards compatibility, allow printable area to be missing. Set the
|
||||
// default printable area to be the page size.
|
||||
@ -126,12 +127,19 @@ bool StructTraits<printing::mojom::PaperDataView,
|
||||
// Allow empty Papers, since PrinterSemanticCapsAndDefaults can have empty
|
||||
// default Papers.
|
||||
if (out->display_name.empty() && out->vendor_id.empty() &&
|
||||
out->size_um.IsEmpty() && out->printable_area_um.IsEmpty()) {
|
||||
out->size_um.IsEmpty() && out->printable_area_um.IsEmpty() &&
|
||||
out->max_height_um == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If `max_height_um` is specified, ensure it's larger than size.
|
||||
if (out->max_height_um > 0 && out->max_height_um < out->size_um.height()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Invalid if the printable area is empty or if the printable area is out of
|
||||
// bounds of the paper size.
|
||||
// bounds of the paper size. `max_height_um` doesn't need to be checked here
|
||||
// since `printable_area_um` is always relative to `size_um`.
|
||||
return !out->printable_area_um.IsEmpty() &&
|
||||
gfx::Rect(out->size_um).Contains(out->printable_area_um);
|
||||
}
|
||||
|
@ -64,6 +64,10 @@ struct StructTraits<printing::mojom::PaperDataView,
|
||||
const printing::PrinterSemanticCapsAndDefaults::Paper& p) {
|
||||
return p.printable_area_um;
|
||||
}
|
||||
static int max_height_um(
|
||||
const printing::PrinterSemanticCapsAndDefaults::Paper& p) {
|
||||
return p.max_height_um;
|
||||
}
|
||||
|
||||
static bool Read(printing::mojom::PaperDataView data,
|
||||
printing::PrinterSemanticCapsAndDefaults::Paper* out);
|
||||
|
@ -79,7 +79,10 @@ TEST(PrintBackendMojomTraitsTest,
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestSerializeAndDeserializePaper) {
|
||||
for (const auto& paper : kPapers) {
|
||||
PrinterSemanticCapsAndDefaults::Papers test_papers = kPapers;
|
||||
test_papers.push_back(kPaperCustom);
|
||||
|
||||
for (const auto& paper : test_papers) {
|
||||
PrinterSemanticCapsAndDefaults::Paper input = paper;
|
||||
PrinterSemanticCapsAndDefaults::Paper output;
|
||||
EXPECT_TRUE(
|
||||
@ -97,6 +100,20 @@ TEST(PrintBackendMojomTraitsTest, TestPaperEmpty) {
|
||||
EXPECT_EQ(input, output);
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestPaperInvalidCustomSize) {
|
||||
// The min height is larger than the max height, so it should be invalid.
|
||||
PrinterSemanticCapsAndDefaults::Paper input{
|
||||
/*display_name=*/"display_name",
|
||||
/*vendor_id=*/"vendor_id",
|
||||
/*size_um=*/gfx::Size(4000, 7000),
|
||||
/*printable_area_um=*/gfx::Rect(0, 0, 4000, 7000),
|
||||
/*max_height_um=*/6000};
|
||||
PrinterSemanticCapsAndDefaults::Paper output;
|
||||
|
||||
EXPECT_FALSE(
|
||||
mojo::test::SerializeAndDeserialize<mojom::Paper>(input, output));
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestPaperEmptyPrintableArea) {
|
||||
// The printable area is empty, but the other fields are not, so it should be
|
||||
// invalid.
|
||||
@ -122,6 +139,20 @@ TEST(PrintBackendMojomTraitsTest, TestPaperPrintableAreaLargerThanSize) {
|
||||
mojo::test::SerializeAndDeserialize<mojom::Paper>(input, output));
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestPaperPrintableAreaLargerThanCustomSize) {
|
||||
// The printable area is larger than the custom size, so it should be invalid.
|
||||
PrinterSemanticCapsAndDefaults::Paper input{
|
||||
/*display_name=*/"display_name",
|
||||
/*vendor_id=*/"vendor_id",
|
||||
/*size_um=*/gfx::Size(4000, 7000),
|
||||
/*printable_area_um=*/gfx::Rect(0, 100, 4100, 7200),
|
||||
/*max_height_um=*/8000};
|
||||
PrinterSemanticCapsAndDefaults::Paper output;
|
||||
|
||||
EXPECT_FALSE(
|
||||
mojo::test::SerializeAndDeserialize<mojom::Paper>(input, output));
|
||||
}
|
||||
|
||||
TEST(PrintBackendMojomTraitsTest, TestPaperPrintableAreaOutOfBounds) {
|
||||
// The printable area is out of bounds of the size, so it should be invalid.
|
||||
PrinterSemanticCapsAndDefaults::Paper input{
|
||||
|
@ -158,7 +158,8 @@ bool PrinterSemanticCapsAndDefaults::Paper::operator==(
|
||||
const PrinterSemanticCapsAndDefaults::Paper& other) const {
|
||||
return display_name == other.display_name && vendor_id == other.vendor_id &&
|
||||
size_um == other.size_um &&
|
||||
printable_area_um == other.printable_area_um;
|
||||
printable_area_um == other.printable_area_um &&
|
||||
max_height_um == other.max_height_um;
|
||||
}
|
||||
|
||||
PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults() = default;
|
||||
|
@ -195,6 +195,13 @@ struct COMPONENT_EXPORT(PRINT_BACKEND) PrinterSemanticCapsAndDefaults {
|
||||
// Origin (x,y) is at the bottom-left.
|
||||
gfx::Rect printable_area_um;
|
||||
|
||||
// This is used to represent a printer that supports a variable height.
|
||||
// This will either be equal to 0 (which indicates the height is not
|
||||
// variable) or this will be larger than the height in `size_um` (which
|
||||
// indicates the height can be anywhere in that range). Note that
|
||||
// `printable_area_um` is always based on `size_um`.
|
||||
int max_height_um = 0;
|
||||
|
||||
bool operator==(const Paper& other) const;
|
||||
};
|
||||
using Papers = std::vector<Paper>;
|
||||
|
@ -54,6 +54,12 @@ inline const PrinterSemanticCapsAndDefaults::Paper kPaperLedger{
|
||||
/*display_name=*/"Ledger", /*vendor_id=*/"89",
|
||||
/*size_um=*/gfx::Size(6600, 10200),
|
||||
/*printable_area_um=*/gfx::Rect(0, 0, 6600, 10200)};
|
||||
inline const PrinterSemanticCapsAndDefaults::Paper kPaperCustom{
|
||||
/*display_name=*/"Custom",
|
||||
/*vendor_id=*/"",
|
||||
/*size_um=*/gfx::Size(2540, 5080),
|
||||
/*printable_area_um=*/gfx::Rect(0, 0, 2540, 5080),
|
||||
/*max_height_um=*/20000};
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
inline const AdvancedCapability kAdvancedCapability1(
|
||||
@ -116,7 +122,7 @@ inline constexpr mojom::ColorModel kBwModel = mojom::ColorModel::kGrayscale;
|
||||
inline const PrinterSemanticCapsAndDefaults::Papers kPapers{kPaperA4,
|
||||
kPaperLetter};
|
||||
inline const PrinterSemanticCapsAndDefaults::Papers kUserDefinedPapers{
|
||||
kPaperA3, kPaperLedger};
|
||||
kPaperA3, kPaperLedger, kPaperCustom};
|
||||
inline const PrinterSemanticCapsAndDefaults::Paper kDefaultPaper = kPaperLetter;
|
||||
inline constexpr gfx::Size kDpi600(600, 600);
|
||||
inline constexpr gfx::Size kDpi1200(1200, 1200);
|
||||
|
Reference in New Issue
Block a user