Chromium Code Reviews| 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 |
| 11 namespace printing { | 11 namespace printing { |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 bool IsPrinterXPS(HDC hdc) { | |
| 16 int device_type = ::GetDeviceCaps(hdc, TECHNOLOGY); | |
| 17 if (device_type != DT_RASPRINTER) | |
| 18 return false; | |
| 19 | |
| 20 const int escape = GETTECHNOLOGY; | |
|
scottmg
2016/10/05 23:21:40
nit; DWORD since that's what the docs say.
https:
Lei Zhang
2016/10/05 23:37:56
Done.
| |
| 21 const char* escape_ptr = reinterpret_cast<const char*>(&escape); | |
| 22 int ret = | |
| 23 ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), escape_ptr, 0, nullptr); | |
| 24 if (ret <= 0) | |
| 25 return false; | |
| 26 | |
| 27 char buffer[256] = {'\0'}; | |
| 28 ret = ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buffer), buffer); | |
| 29 if (ret <= 0) | |
| 30 return false; | |
| 31 | |
| 32 static const char kXPSDriver[] = "http://schemas.microsoft.com/xps/2005/06"; | |
| 33 return strcmp(buffer, kXPSDriver) == 0; | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 13 // static | 38 // static |
| 14 void PrintSettingsInitializerWin::InitPrintSettings( | 39 void PrintSettingsInitializerWin::InitPrintSettings( |
| 15 HDC hdc, | 40 HDC hdc, |
| 16 const DEVMODE& dev_mode, | 41 const DEVMODE& dev_mode, |
| 17 PrintSettings* print_settings) { | 42 PrintSettings* print_settings) { |
| 18 DCHECK(hdc); | 43 DCHECK(hdc); |
| 19 DCHECK(print_settings); | 44 DCHECK(print_settings); |
| 45 | |
| 20 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); | 46 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); |
| 21 | 47 |
| 22 int dpi = GetDeviceCaps(hdc, LOGPIXELSX); | 48 int dpi = GetDeviceCaps(hdc, LOGPIXELSX); |
| 23 print_settings->set_dpi(dpi); | 49 print_settings->set_dpi(dpi); |
| 50 | |
| 24 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; | 51 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; |
| 25 print_settings->set_supports_alpha_blend( | 52 print_settings->set_supports_alpha_blend( |
| 26 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); | 53 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); |
| 54 | |
| 27 // No printer device is known to advertise different dpi in X and Y axis; even | 55 // No printer device is known to advertise different dpi in X and Y axis; even |
| 28 // the fax device using the 200x100 dpi setting. It's ought to break so many | 56 // the fax device using the 200x100 dpi setting. It's ought to break so many |
| 29 // applications that it's not even needed to care about. WebKit doesn't | 57 // applications that it's not even needed to care about. Blink doesn't support |
| 30 // support different dpi settings in X and Y axis. | 58 // different dpi settings in X and Y axis. |
| 31 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY)); | 59 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY)); |
| 32 | 60 |
| 33 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); | 61 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); |
| 34 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); | 62 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); |
| 35 | 63 |
| 36 // Initialize page_setup_device_units_. | 64 // Initialize |page_setup_device_units_|. |
| 37 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH), | 65 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH), |
| 38 GetDeviceCaps(hdc, PHYSICALHEIGHT)); | 66 GetDeviceCaps(hdc, PHYSICALHEIGHT)); |
| 39 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX), | 67 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX), |
| 40 GetDeviceCaps(hdc, PHYSICALOFFSETY), | 68 GetDeviceCaps(hdc, PHYSICALOFFSETY), |
| 41 GetDeviceCaps(hdc, HORZRES), | 69 GetDeviceCaps(hdc, HORZRES), |
| 42 GetDeviceCaps(hdc, VERTRES)); | 70 GetDeviceCaps(hdc, VERTRES)); |
| 43 | 71 |
| 44 // Sanity check the printable_area: we've seen crashes caused by a printable | 72 // Sanity check the printable_area: we've seen crashes caused by a printable |
| 45 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. | 73 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. |
| 46 if (printable_area_device_units.IsEmpty() || | 74 if (printable_area_device_units.IsEmpty() || |
| 47 !gfx::Rect(physical_size_device_units).Contains( | 75 !gfx::Rect(physical_size_device_units).Contains( |
| 48 printable_area_device_units)) { | 76 printable_area_device_units)) { |
| 49 printable_area_device_units = gfx::Rect(physical_size_device_units); | 77 printable_area_device_units = gfx::Rect(physical_size_device_units); |
| 50 } | 78 } |
| 51 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); | 79 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
| 52 print_settings->SetPrinterPrintableArea(physical_size_device_units, | 80 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 53 printable_area_device_units, | 81 printable_area_device_units, |
| 54 false); | 82 false); |
| 83 | |
| 84 print_settings->set_printer_is_xps(IsPrinterXPS(hdc)); | |
| 55 } | 85 } |
| 56 | 86 |
| 57 } // namespace printing | 87 } // namespace printing |
| OLD | NEW |