Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: printing/print_settings_initializer_win.cc

Issue 2795453002: Use DPI from Print Preview on Windows, handle non square (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: printing/print_settings_initializer_win.cc
diff --git a/printing/print_settings_initializer_win.cc b/printing/print_settings_initializer_win.cc
index 685c8fd6cf96dfb1ec2cf7ff08cdde161a4a9540..a9d8c3e7330b39a1405b9e48894eff4005ac8b33 100644
--- a/printing/print_settings_initializer_win.cc
+++ b/printing/print_settings_initializer_win.cc
@@ -5,6 +5,7 @@
#include "printing/print_settings_initializer_win.h"
#include <windows.h>
+#include <algorithm>
#include "printing/print_settings.h"
@@ -104,7 +105,8 @@ void PrintSettingsInitializerWin::InitPrintSettings(
print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE);
- int dpi = GetDeviceCaps(hdc, LOGPIXELSX);
+ int dpi =
+ std::min(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
print_settings->set_dpi(dpi);
const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA;
@@ -115,18 +117,21 @@ void PrintSettingsInitializerWin::InitPrintSettings(
// the fax device using the 200x100 dpi setting. It's ought to break so many
// applications that it's not even needed to care about. Blink doesn't support
// different dpi settings in X and Y axis.
- DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY));
-
DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
// Initialize |page_setup_device_units_|.
- gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
- GetDeviceCaps(hdc, PHYSICALHEIGHT));
- gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
- GetDeviceCaps(hdc, PHYSICALOFFSETY),
- GetDeviceCaps(hdc, HORZRES),
- GetDeviceCaps(hdc, VERTRES));
+ // DPI ratio should be an integer.
Lei Zhang 2017/03/31 22:21:13 As in, we don't expect a printer to have a DPI of
rbpotter 2017/04/01 00:08:02 Actually fixed this. I have not seen any non-integ
+ int scale_x = GetDeviceCaps(hdc, LOGPIXELSX) / dpi;
+ int scale_y = GetDeviceCaps(hdc, LOGPIXELSY) / dpi;
+ gfx::Size physical_size_device_units(
+ GetDeviceCaps(hdc, PHYSICALWIDTH) / scale_x,
+ GetDeviceCaps(hdc, PHYSICALHEIGHT) / scale_y);
+ gfx::Rect printable_area_device_units(
+ GetDeviceCaps(hdc, PHYSICALOFFSETX) / scale_x,
+ GetDeviceCaps(hdc, PHYSICALOFFSETY) / scale_y,
+ GetDeviceCaps(hdc, HORZRES) / scale_x,
+ GetDeviceCaps(hdc, VERTRES) / scale_y);
// Sanity check the printable_area: we've seen crashes caused by a printable
// area rect of 0, 0, 0, 0, so it seems some drivers don't set it.
@@ -139,6 +144,7 @@ void PrintSettingsInitializerWin::InitPrintSettings(
print_settings->SetPrinterPrintableArea(physical_size_device_units,
printable_area_device_units,
false);
+
// Check for postscript first so that we can change the mode with the
// first command.
int level;

Powered by Google App Engine
This is Rietveld 408576698