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 | 8 |
9 #include "printing/print_settings.h" | 9 #include "printing/print_settings.h" |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 // static | 97 // static |
98 void PrintSettingsInitializerWin::InitPrintSettings( | 98 void PrintSettingsInitializerWin::InitPrintSettings( |
99 HDC hdc, | 99 HDC hdc, |
100 const DEVMODE& dev_mode, | 100 const DEVMODE& dev_mode, |
101 PrintSettings* print_settings) { | 101 PrintSettings* print_settings) { |
102 DCHECK(hdc); | 102 DCHECK(hdc); |
103 DCHECK(print_settings); | 103 DCHECK(print_settings); |
104 | 104 |
105 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); | 105 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); |
106 | 106 int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); |
107 int dpi = GetDeviceCaps(hdc, LOGPIXELSX); | 107 int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); |
108 print_settings->set_dpi(dpi); | 108 print_settings->set_dpi_xy(dpi_x, dpi_y); |
109 | |
110 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; | 109 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; |
111 print_settings->set_supports_alpha_blend( | 110 print_settings->set_supports_alpha_blend( |
112 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); | 111 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); |
113 | 112 |
114 // No printer device is known to advertise different dpi in X and Y axis; even | |
115 // 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 | |
117 // different dpi settings in X and Y axis. | |
118 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY)); | |
119 | |
120 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); | 113 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); |
121 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); | 114 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); |
122 | 115 |
123 // Initialize |page_setup_device_units_|. | 116 // Initialize |page_setup_device_units_|. |
124 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH), | 117 // Blink doesn't support different dpi settings in X and Y axis. However, |
125 GetDeviceCaps(hdc, PHYSICALHEIGHT)); | 118 // some printers use them. So, to avoid a bad page calculation, scale page |
126 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX), | 119 // size components based on the dpi in the appropriate dimension. |
127 GetDeviceCaps(hdc, PHYSICALOFFSETY), | 120 int dpi = print_settings->dpi(); |
128 GetDeviceCaps(hdc, HORZRES), | 121 gfx::Size physical_size_device_units( |
129 GetDeviceCaps(hdc, VERTRES)); | 122 GetDeviceCaps(hdc, PHYSICALWIDTH) * dpi / dpi_x, |
| 123 GetDeviceCaps(hdc, PHYSICALHEIGHT) * dpi / dpi_y); |
| 124 gfx::Rect printable_area_device_units( |
| 125 GetDeviceCaps(hdc, PHYSICALOFFSETX) * dpi / dpi_x, |
| 126 GetDeviceCaps(hdc, PHYSICALOFFSETY) * dpi / dpi_y, |
| 127 GetDeviceCaps(hdc, HORZRES) * dpi / dpi_x, |
| 128 GetDeviceCaps(hdc, VERTRES) * dpi / dpi_y); |
130 | 129 |
131 // Sanity check the printable_area: we've seen crashes caused by a printable | 130 // 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. | 131 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. |
133 if (printable_area_device_units.IsEmpty() || | 132 if (printable_area_device_units.IsEmpty() || |
134 !gfx::Rect(physical_size_device_units).Contains( | 133 !gfx::Rect(physical_size_device_units).Contains( |
135 printable_area_device_units)) { | 134 printable_area_device_units)) { |
136 printable_area_device_units = gfx::Rect(physical_size_device_units); | 135 printable_area_device_units = gfx::Rect(physical_size_device_units); |
137 } | 136 } |
138 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); | 137 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
139 print_settings->SetPrinterPrintableArea(physical_size_device_units, | 138 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
140 printable_area_device_units, | 139 printable_area_device_units, |
141 false); | 140 false); |
| 141 |
142 // Check for postscript first so that we can change the mode with the | 142 // Check for postscript first so that we can change the mode with the |
143 // first command. | 143 // first command. |
144 int level; | 144 int level; |
145 if (IsPrinterPostScript(hdc, &level)) { | 145 if (IsPrinterPostScript(hdc, &level)) { |
146 if (level == 2) { | 146 if (level == 2) { |
147 print_settings->set_printer_type( | 147 print_settings->set_printer_type( |
148 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL2); | 148 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL2); |
149 return; | 149 return; |
150 } | 150 } |
151 DCHECK_EQ(3, level); | 151 DCHECK_EQ(3, level); |
152 print_settings->set_printer_type( | 152 print_settings->set_printer_type( |
153 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); | 153 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); |
154 return; | 154 return; |
155 } | 155 } |
156 if (IsPrinterXPS(hdc)) { | 156 if (IsPrinterXPS(hdc)) { |
157 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); | 157 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); |
158 return; | 158 return; |
159 } | 159 } |
160 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_NONE); | 160 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_NONE); |
161 } | 161 } |
162 | 162 |
163 } // namespace printing | 163 } // namespace printing |
OLD | NEW |