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 HasEscapeSupprt(HDC hdc, DWORD escape) { | 15 bool HasEscapeSupprt(HDC hdc, DWORD escape) { |
| 16 const char* ptr = reinterpret_cast<const char*>(&escape); | 16 const char* ptr = reinterpret_cast<const char*>(&escape); |
| 17 return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0; | 17 return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0; |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool IsTechnology(HDC hdc, const char* technology) { | 20 bool IsTechnology(HDC hdc, const char* technology) { |
| 21 if (::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASPRINTER) | 21 if (::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASPRINTER) |
| 22 return false; | 22 return false; |
| 23 | 23 |
| 24 // If postscript, try to query Postscript Identify and then set to | |
| 25 // postscript mode before calling any more ExtEscape functions. Otherwise, | |
| 26 // PSLEVEL query will not work. | |
| 27 if (strcmp(technology, "PostScript") == 0 && | |
|
Lei Zhang
2017/02/25 02:49:50
Doing this within IsTechnology() seems weird, but
| |
| 28 HasEscapeSupprt(hdc, POSTSCRIPT_IDENTIFY)) { | |
| 29 DWORD mode = PSIDENT_PSCENTRIC; | |
| 30 const char* ptr = reinterpret_cast<const char*>(&mode); | |
| 31 ExtEscape(hdc, POSTSCRIPT_IDENTIFY, sizeof(DWORD), ptr, 0, nullptr); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 24 if (!HasEscapeSupprt(hdc, GETTECHNOLOGY)) | 35 if (!HasEscapeSupprt(hdc, GETTECHNOLOGY)) |
| 25 return false; | 36 return false; |
| 26 | 37 |
| 27 char buf[256]; | 38 char buf[256]; |
| 28 memset(buf, 0, sizeof(buf)); | 39 memset(buf, 0, sizeof(buf)); |
| 29 if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0) | 40 if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0) |
| 30 return false; | 41 return false; |
| 31 return strcmp(buf, technology) == 0; | 42 return strcmp(buf, technology) == 0; |
| 32 } | 43 } |
| 33 | 44 |
| 34 bool IsPrinterPostScript(HDC hdc, int* level) { | 45 bool IsPrinterPostScript(HDC hdc, int* level) { |
| 35 static constexpr char kPostScriptDriver[] = "PostScript"; | 46 static constexpr char kPostScriptDriver[] = "PostScript"; |
| 36 if (!IsTechnology(hdc, kPostScriptDriver)) { | 47 if (!IsTechnology(hdc, kPostScriptDriver)) { |
| 37 return false; | 48 return false; |
| 38 } | 49 } |
| 39 | 50 |
| 40 // Query the PS Level if possible. Many PS printers do not implement this. | 51 // Query the PS Level if possible. |
|
Lei Zhang
2017/02/25 02:49:50
Are there printers that only support this in PS mo
| |
| 41 if (HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) { | 52 if (HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) { |
| 42 constexpr int param = FEATURESETTING_PSLEVEL; | 53 constexpr int param = FEATURESETTING_PSLEVEL; |
| 43 const char* param_char_ptr = reinterpret_cast<const char*>(¶m); | 54 const char* param_char_ptr = reinterpret_cast<const char*>(¶m); |
| 44 int param_out = -1; | 55 int param_out = -1; |
| 45 char* param_out_char_ptr = reinterpret_cast<char*>(¶m_out); | 56 char* param_out_char_ptr = reinterpret_cast<char*>(¶m_out); |
| 46 if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(param), param_char_ptr, | 57 if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(param), param_char_ptr, |
| 47 sizeof(param_out), param_out_char_ptr) > 0) { | 58 sizeof(param_out), param_out_char_ptr) > 0) { |
| 48 if (param_out < 2 || param_out > 3) | 59 if (param_out < 2 || param_out > 3) |
| 49 return false; | 60 return false; |
| 50 | 61 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. | 120 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. |
| 110 if (printable_area_device_units.IsEmpty() || | 121 if (printable_area_device_units.IsEmpty() || |
| 111 !gfx::Rect(physical_size_device_units).Contains( | 122 !gfx::Rect(physical_size_device_units).Contains( |
| 112 printable_area_device_units)) { | 123 printable_area_device_units)) { |
| 113 printable_area_device_units = gfx::Rect(physical_size_device_units); | 124 printable_area_device_units = gfx::Rect(physical_size_device_units); |
| 114 } | 125 } |
| 115 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); | 126 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
| 116 print_settings->SetPrinterPrintableArea(physical_size_device_units, | 127 print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 117 printable_area_device_units, | 128 printable_area_device_units, |
| 118 false); | 129 false); |
| 119 if (IsPrinterXPS(hdc)) { | 130 // Check for postscript first so that we can change the mode with the |
| 120 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); | 131 // first command. |
| 121 return; | |
| 122 } | |
| 123 int level; | 132 int level; |
| 124 if (IsPrinterPostScript(hdc, &level)) { | 133 if (IsPrinterPostScript(hdc, &level)) { |
| 125 if (level == 2) { | 134 if (level == 2) { |
| 126 print_settings->set_printer_type( | 135 print_settings->set_printer_type( |
| 127 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL2); | 136 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL2); |
| 128 return; | 137 return; |
| 129 } | 138 } |
| 130 DCHECK_EQ(3, level); | 139 DCHECK_EQ(3, level); |
| 131 print_settings->set_printer_type( | 140 print_settings->set_printer_type( |
| 132 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); | 141 PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); |
| 133 return; | 142 return; |
| 134 } | 143 } |
| 144 if (IsPrinterXPS(hdc)) { | |
| 145 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); | |
| 146 return; | |
| 147 } | |
| 135 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_NONE); | 148 print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_NONE); |
| 136 } | 149 } |
| 137 | 150 |
| 138 } // namespace printing | 151 } // namespace printing |
| OLD | NEW |