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 { | 13 namespace { |
| 14 | 14 |
| 15 bool IsPrinterXPS(HDC hdc) { | 15 bool HasEscapeSupprt(HDC hdc, DWORD escape) { |
|
Vitaly Buka (NO REVIEWS)
2017/01/17 19:29:16
Same here.
Extraction of IsTechnology function des
| |
| 16 int device_type = ::GetDeviceCaps(hdc, TECHNOLOGY); | 16 const char* ptr = reinterpret_cast<const char*>(&escape); |
| 17 if (device_type != DT_RASPRINTER) | 17 return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0; |
| 18 } | |
| 19 | |
| 20 bool IsTechnology(HDC hdc, const char* technology) { | |
| 21 if (::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASPRINTER) | |
| 18 return false; | 22 return false; |
| 19 | 23 |
| 20 const DWORD escape = GETTECHNOLOGY; | 24 if (!HasEscapeSupprt(hdc, GETTECHNOLOGY)) |
| 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; | 25 return false; |
| 26 | 26 |
| 27 char buffer[256]; | 27 char buf[256]; |
| 28 memset(buffer, 0, sizeof(buffer)); | 28 memset(buf, 0, sizeof(buf)); |
| 29 ret = ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buffer) - 1, buffer); | 29 if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0) |
| 30 if (ret <= 0) | |
| 31 return false; | 30 return false; |
| 31 return strcmp(buf, technology) == 0; | |
| 32 } | |
| 32 | 33 |
| 33 static const char kXPSDriver[] = "http://schemas.microsoft.com/xps/2005/06"; | 34 bool IsPrinterPostScript(HDC hdc, int* level) { |
| 34 return strcmp(buffer, kXPSDriver) == 0; | 35 static constexpr char kPostScriptDriver[] = "PostScript"; |
| 36 if (!IsTechnology(hdc, kPostScriptDriver)) { | |
| 37 return false; | |
| 38 } | |
| 39 | |
| 40 // Query the PS Level if possible. Many PS printers do not implement this. | |
| 41 if (HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) { | |
| 42 constexpr int param = FEATURESETTING_PSLEVEL; | |
| 43 const char* param_char_ptr = reinterpret_cast<const char*>(¶m); | |
| 44 int param_out = -1; | |
| 45 char* param_out_char_ptr = reinterpret_cast<char*>(¶m_out); | |
| 46 if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(param), param_char_ptr, | |
| 47 sizeof(param_out), param_out_char_ptr) > 0) { | |
| 48 if (param_out < 2 || param_out > 3) | |
| 49 return false; | |
| 50 | |
| 51 *level = param_out; | |
| 52 return true; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 // If it looks like a PS printer. | |
| 57 if (HasEscapeSupprt(hdc, POSTSCRIPT_PASSTHROUGH) && | |
| 58 HasEscapeSupprt(hdc, POSTSCRIPT_DATA)) { | |
| 59 *level = 2; | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 bool IsPrinterXPS(HDC hdc) { | |
| 67 static constexpr char kXPSDriver[] = | |
| 68 "http://schemas.microsoft.com/xps/2005/06"; | |
| 69 return IsTechnology(hdc, kXPSDriver); | |
| 35 } | 70 } |
| 36 | 71 |
| 37 } // namespace | 72 } // namespace |
| 38 | 73 |
| 39 // static | 74 // static |
| 40 void PrintSettingsInitializerWin::InitPrintSettings( | 75 void PrintSettingsInitializerWin::InitPrintSettings( |
| 41 HDC hdc, | 76 HDC hdc, |
| 42 const DEVMODE& dev_mode, | 77 const DEVMODE& dev_mode, |
| 43 PrintSettings* print_settings) { | 78 PrintSettings* print_settings) { |
| 44 DCHECK(hdc); | 79 DCHECK(hdc); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 !gfx::Rect(physical_size_device_units).Contains( | 111 !gfx::Rect(physical_size_device_units).Contains( |
| 77 printable_area_device_units)) { | 112 printable_area_device_units)) { |
| 78 printable_area_device_units = gfx::Rect(physical_size_device_units); | 113 printable_area_device_units = gfx::Rect(physical_size_device_units); |
| 79 } | 114 } |
| 80 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); | 115 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
| 81 print_settings->SetPrinterPrintableArea(physical_size_device_units, | 116 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 82 printable_area_device_units, | 117 printable_area_device_units, |
| 83 false); | 118 false); |
| 84 | 119 |
| 85 print_settings->set_printer_is_xps(IsPrinterXPS(hdc)); | 120 print_settings->set_printer_is_xps(IsPrinterXPS(hdc)); |
| 121 if (!print_settings->printer_is_xps()) { | |
| 122 int level; | |
| 123 if (IsPrinterPostScript(hdc, &level)) { | |
| 124 if (level == 2) { | |
| 125 print_settings->set_printer_is_ps2(true); | |
| 126 } else { | |
| 127 DCHECK_EQ(3, level); | |
| 128 print_settings->set_printer_is_ps3(true); | |
| 129 } | |
| 130 } | |
| 131 } | |
| 86 } | 132 } |
| 87 | 133 |
| 88 } // namespace printing | 134 } // namespace printing |
| OLD | NEW |