0

[Printing] Change non-square DPI to non-square pixels

It is not the DPI that is non-square. It is the pixels that are
non-square. Change all references to non-square DPI to non-square
pixels.

Change-Id: I6898de9ded7a21bce5835834f5f8ba5bc6093716
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4616147
Reviewed-by: Alan Screen <awscreen@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1157892}
This commit is contained in:
Andy Phan
2023-06-14 23:46:04 +00:00
committed by Chromium LUCI CQ
parent a86a92fb30
commit e53c80bc68
5 changed files with 10 additions and 10 deletions

@ -379,8 +379,8 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
float source_page_width = FPDF_GetPageWidthF(page_to_print); float source_page_width = FPDF_GetPageWidthF(page_to_print);
float source_page_height = FPDF_GetPageHeightF(page_to_print); float source_page_height = FPDF_GetPageHeightF(page_to_print);
// For computing size in pixels, use a square dpi since the source PDF page // For computing size in pixels, use square pixels since the source PDF page
// has square DPI. // has square pixels.
int width_in_pixels = ConvertUnit(source_page_width, kPointsPerInch, dpi); int width_in_pixels = ConvertUnit(source_page_width, kPointsPerInch, dpi);
int height_in_pixels = ConvertUnit(source_page_height, kPointsPerInch, dpi); int height_in_pixels = ConvertUnit(source_page_height, kPointsPerInch, dpi);

@ -136,8 +136,8 @@ gfx::Rect LoadPaperPrintableAreaUm(const wchar_t* printer, DEVMODE* devmode) {
gfx::Rect printable_area_device_units = gfx::Rect printable_area_device_units =
GetPrintableAreaDeviceUnits(hdc.get()); GetPrintableAreaDeviceUnits(hdc.get());
// Device units can be non-square, so scale for non-square DPIs and convert to // Device units can be non-square, so scale for non-square pixels and convert
// microns. // to microns.
gfx::Rect printable_area_um = gfx::Rect printable_area_um =
gfx::Rect(ConvertUnit(printable_area_device_units.x(), gfx::Rect(ConvertUnit(printable_area_device_units.x(),
default_dpi.width(), kMicronsPerInch), default_dpi.width(), kMicronsPerInch),

@ -507,7 +507,7 @@ void PrintSettings::UpdatePrinterPrintableArea(
const gfx::Rect& printable_area_um) { const gfx::Rect& printable_area_um) {
// Scale the page size and printable area to device units. // Scale the page size and printable area to device units.
// Blink doesn't support different dpi settings in X and Y axis. Because of // Blink doesn't support different dpi settings in X and Y axis. Because of
// this, printers with non-square DPIs still scale page size and printable // this, printers with non-square pixels still scale page size and printable
// area using device_units_per_inch() instead of their respective dimensions // area using device_units_per_inch() instead of their respective dimensions
// in device_units_per_inch_size(). // in device_units_per_inch_size().
float scale = static_cast<float>(device_units_per_inch()) / kMicronsPerInch; float scale = static_cast<float>(device_units_per_inch()) / kMicronsPerInch;

@ -102,7 +102,7 @@ void SetPrintableAreaIfValid(PrintSettings& settings,
// Scale the page size and printable area to device units. // Scale the page size and printable area to device units.
// Blink doesn't support different dpi settings in X and Y axis. Because of // Blink doesn't support different dpi settings in X and Y axis. Because of
// this, printers with non-square DPIs still scale page size and printable // this, printers with non-square pixels still scale page size and printable
// area using device_units_per_inch() instead of their respective dimensions // area using device_units_per_inch() instead of their respective dimensions
// in device_units_per_inch_size(). // in device_units_per_inch_size().
float scale = float scale =

@ -93,7 +93,7 @@ const char kPrinterSettingsWithImageableArea[] = R"({
})"; })";
#if !BUILDFLAG(IS_MAC) #if !BUILDFLAG(IS_MAC)
const char kPrinterSettingsWithNonSquareDpi[] = R"({ const char kPrinterSettingsWithNonSquarePixels[] = R"({
"headerFooterEnabled": false, "headerFooterEnabled": false,
"title": "Test Doc", "title": "Test Doc",
"url": "http://localhost/", "url": "http://localhost/",
@ -273,14 +273,14 @@ TEST(PrintSettingsConversionTest, WithCustomMarginsAndImageableArea) {
} }
#if !BUILDFLAG(IS_MAC) #if !BUILDFLAG(IS_MAC)
TEST(PrintSettingsConversionTest, WithNonSquareDpi) { TEST(PrintSettingsConversionTest, WithNonSquarePixels) {
// Check that physical size and printable area are scaled by the max DPI // Check that physical size and printable area are scaled by the max DPI
// value. Not needed for macOS, which always has a square DPI. // value. Not needed for macOS, which always has square pixels.
static constexpr gfx::Size kExpectedSize{6614, 9354}; static constexpr gfx::Size kExpectedSize{6614, 9354};
static constexpr gfx::Rect kExpectedPrintableArea{0, 0, 5669, 9323}; static constexpr gfx::Rect kExpectedPrintableArea{0, 0, 5669, 9323};
base::Value::Dict dict = base::Value::Dict dict =
base::test::ParseJsonDict(kPrinterSettingsWithNonSquareDpi); base::test::ParseJsonDict(kPrinterSettingsWithNonSquarePixels);
std::unique_ptr<PrintSettings> settings = PrintSettingsFromJobSettings(dict); std::unique_ptr<PrintSettings> settings = PrintSettingsFromJobSettings(dict);
ASSERT_TRUE(settings); ASSERT_TRUE(settings);
EXPECT_EQ(settings->dpi_horizontal(), 800); EXPECT_EQ(settings->dpi_horizontal(), 800);