| 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) { |
| 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 IsPrinterXPS(HDC hdc) { |
| 34 return strcmp(buffer, kXPSDriver) == 0; | 35 static constexpr char kXPSDriver[] = |
| 36 "http://schemas.microsoft.com/xps/2005/06"; |
| 37 return IsTechnology(hdc, kXPSDriver); |
| 35 } | 38 } |
| 36 | 39 |
| 37 } // namespace | 40 } // namespace |
| 38 | 41 |
| 39 // static | 42 // static |
| 40 void PrintSettingsInitializerWin::InitPrintSettings( | 43 void PrintSettingsInitializerWin::InitPrintSettings( |
| 41 HDC hdc, | 44 HDC hdc, |
| 42 const DEVMODE& dev_mode, | 45 const DEVMODE& dev_mode, |
| 43 PrintSettings* print_settings) { | 46 PrintSettings* print_settings) { |
| 44 DCHECK(hdc); | 47 DCHECK(hdc); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 82 } |
| 80 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); | 83 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
| 81 print_settings->SetPrinterPrintableArea(physical_size_device_units, | 84 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 82 printable_area_device_units, | 85 printable_area_device_units, |
| 83 false); | 86 false); |
| 84 | 87 |
| 85 print_settings->set_printer_is_xps(IsPrinterXPS(hdc)); | 88 print_settings->set_printer_is_xps(IsPrinterXPS(hdc)); |
| 86 } | 89 } |
| 87 | 90 |
| 88 } // namespace printing | 91 } // namespace printing |
| OLD | NEW |