OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/print_settings_initializer_win.h" | 5 #include "printing/print_settings_initializer_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <algorithm> | |
8 | 9 |
9 #include "printing/print_settings.h" | 10 #include "printing/print_settings.h" |
10 | 11 |
11 namespace printing { | 12 namespace printing { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 bool HasEscapeSupport(HDC hdc, DWORD escape) { | 16 bool HasEscapeSupport(HDC hdc, DWORD escape) { |
16 const char* ptr = reinterpret_cast<const char*>(&escape); | 17 const char* ptr = reinterpret_cast<const char*>(&escape); |
17 return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0; | 18 return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 // static | 98 // static |
98 void PrintSettingsInitializerWin::InitPrintSettings( | 99 void PrintSettingsInitializerWin::InitPrintSettings( |
99 HDC hdc, | 100 HDC hdc, |
100 const DEVMODE& dev_mode, | 101 const DEVMODE& dev_mode, |
101 PrintSettings* print_settings) { | 102 PrintSettings* print_settings) { |
102 DCHECK(hdc); | 103 DCHECK(hdc); |
103 DCHECK(print_settings); | 104 DCHECK(print_settings); |
104 | 105 |
105 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); | 106 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); |
106 | 107 |
107 int dpi = GetDeviceCaps(hdc, LOGPIXELSX); | 108 int dpi = |
109 std::min(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY)); | |
108 print_settings->set_dpi(dpi); | 110 print_settings->set_dpi(dpi); |
109 | 111 |
110 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; | 112 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; |
111 print_settings->set_supports_alpha_blend( | 113 print_settings->set_supports_alpha_blend( |
112 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); | 114 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); |
113 | 115 |
114 // No printer device is known to advertise different dpi in X and Y axis; even | 116 // No printer device is known to advertise different dpi in X and Y axis; even |
Lei Zhang
2017/03/31 22:21:13
Don't we have a printer that refutes this statemen
rbpotter
2017/04/01 00:08:02
Done
| |
115 // the fax device using the 200x100 dpi setting. It's ought to break so many | 117 // the fax device using the 200x100 dpi setting. It's ought to break so many |
116 // applications that it's not even needed to care about. Blink doesn't support | 118 // applications that it's not even needed to care about. Blink doesn't support |
117 // different dpi settings in X and Y axis. | 119 // different dpi settings in X and Y axis. |
118 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY)); | |
119 | |
120 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); | 120 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); |
121 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); | 121 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); |
122 | 122 |
123 // Initialize |page_setup_device_units_|. | 123 // Initialize |page_setup_device_units_|. |
124 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH), | 124 // 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
| |
125 GetDeviceCaps(hdc, PHYSICALHEIGHT)); | 125 int scale_x = GetDeviceCaps(hdc, LOGPIXELSX) / dpi; |
126 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX), | 126 int scale_y = GetDeviceCaps(hdc, LOGPIXELSY) / dpi; |
127 GetDeviceCaps(hdc, PHYSICALOFFSETY), | 127 gfx::Size physical_size_device_units( |
128 GetDeviceCaps(hdc, HORZRES), | 128 GetDeviceCaps(hdc, PHYSICALWIDTH) / scale_x, |
129 GetDeviceCaps(hdc, VERTRES)); | 129 GetDeviceCaps(hdc, PHYSICALHEIGHT) / scale_y); |
130 gfx::Rect printable_area_device_units( | |
131 GetDeviceCaps(hdc, PHYSICALOFFSETX) / scale_x, | |
132 GetDeviceCaps(hdc, PHYSICALOFFSETY) / scale_y, | |
133 GetDeviceCaps(hdc, HORZRES) / scale_x, | |
134 GetDeviceCaps(hdc, VERTRES) / scale_y); | |
130 | 135 |
131 // Sanity check the printable_area: we've seen crashes caused by a printable | 136 // Sanity check the printable_area: we've seen crashes caused by a printable |
132 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. | 137 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. |
133 if (printable_area_device_units.IsEmpty() || | 138 if (printable_area_device_units.IsEmpty() || |
134 !gfx::Rect(physical_size_device_units).Contains( | 139 !gfx::Rect(physical_size_device_units).Contains( |
135 printable_area_device_units)) { | 140 printable_area_device_units)) { |
136 printable_area_device_units = gfx::Rect(physical_size_device_units); | 141 printable_area_device_units = gfx::Rect(physical_size_device_units); |
137 } | 142 } |
138 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); | 143 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
139 print_settings->SetPrinterPrintableArea(physical_size_device_units, | 144 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
140 printable_area_device_units, | 145 printable_area_device_units, |
141 false); | 146 false); |
147 | |
142 // Check for postscript first so that we can change the mode with the | 148 // Check for postscript first so that we can change the mode with the |
143 // first command. | 149 // first command. |
144 int level; | 150 int level; |
145 if (IsPrinterPostScript(hdc, &level)) { | 151 if (IsPrinterPostScript(hdc, &level)) { |
146 if (level == 2) { | 152 if (level == 2) { |
147 print_settings->set_printer_type( | 153 print_settings->set_printer_type( |
148 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL2); | 154 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL2); |
149 return; | 155 return; |
150 } | 156 } |
151 DCHECK_EQ(3, level); | 157 DCHECK_EQ(3, level); |
152 print_settings->set_printer_type( | 158 print_settings->set_printer_type( |
153 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); | 159 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); |
154 return; | 160 return; |
155 } | 161 } |
156 if (IsPrinterXPS(hdc)) { | 162 if (IsPrinterXPS(hdc)) { |
157 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); | 163 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); |
158 return; | 164 return; |
159 } | 165 } |
160 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_NONE); | 166 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_NONE); |
161 } | 167 } |
162 | 168 |
163 } // namespace printing | 169 } // namespace printing |
OLD | NEW |