Chromium Code Reviews| Index: printing/print_settings_initializer_win.cc |
| diff --git a/printing/print_settings_initializer_win.cc b/printing/print_settings_initializer_win.cc |
| index 95d2fced08b5ff262a5d92de0105878ffee9e397..e82f54659e31ecf6fb530e45ef65699e915d26fc 100644 |
| --- a/printing/print_settings_initializer_win.cc |
| +++ b/printing/print_settings_initializer_win.cc |
| @@ -21,17 +21,6 @@ bool IsTechnology(HDC hdc, const char* technology) { |
| if (::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASPRINTER) |
| return false; |
| - // If postscript, try to query Postscript Identify and then set to |
| - // postscript mode before calling any more ExtEscape functions. Otherwise, |
| - // PSLEVEL query will not work. |
| - if (strcmp(technology, "PostScript") == 0 && |
| - HasEscapeSupprt(hdc, POSTSCRIPT_IDENTIFY)) { |
| - DWORD mode = PSIDENT_PSCENTRIC; |
| - const char* ptr = reinterpret_cast<const char*>(&mode); |
| - ExtEscape(hdc, POSTSCRIPT_IDENTIFY, sizeof(DWORD), ptr, 0, nullptr); |
| - return true; |
| - } |
| - |
| if (!HasEscapeSupprt(hdc, GETTECHNOLOGY)) |
| return false; |
| @@ -42,36 +31,56 @@ bool IsTechnology(HDC hdc, const char* technology) { |
| return strcmp(buf, technology) == 0; |
| } |
| +bool SetPrinterToGdiMode(HDC hdc) { |
| + // Try to set to GDI centric mode |
| + DWORD mode = PSIDENT_GDICENTRIC; |
| + const char* ptr = reinterpret_cast<const char*>(&mode); |
| + int ret = ExtEscape(hdc, POSTSCRIPT_IDENTIFY, sizeof(DWORD), ptr, 0, nullptr); |
| + return ret > 0; |
| +} |
| + |
| +int GetPrinterPostScriptLevel(HDC hdc) { |
| + constexpr int param = FEATURESETTING_PSLEVEL; |
| + const char* param_char_ptr = reinterpret_cast<const char*>(¶m); |
| + int param_out = 0; |
| + char* param_out_char_ptr = reinterpret_cast<char*>(¶m_out); |
| + if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(param), param_char_ptr, |
| + sizeof(param_out), param_out_char_ptr) > 0) { |
| + return param_out; |
| + } |
| + return -1; |
|
Lei Zhang
2017/02/25 09:09:35
0 here as well?
rbpotter
2017/02/27 16:40:50
Done.
|
| +} |
| + |
| bool IsPrinterPostScript(HDC hdc, int* level) { |
| static constexpr char kPostScriptDriver[] = "PostScript"; |
| - if (!IsTechnology(hdc, kPostScriptDriver)) { |
| + // Try to set to Gdi mode so that language level detection works (not |
|
Lei Zhang
2017/02/25 09:09:35
s/Gdi/GDI/
rbpotter
2017/02/27 16:40:50
Done.
|
| + // supported in compatability mode). Use GDI mode instead of PS mode so that |
| + // if level detection fails we can fall back to normal printing. |
| + // Note: This has to occur before other escape functions are called. Also, if |
| + // the printer supports POSTSCRIPT_IDENTIFY, we know it has a postscript |
| + // driver. |
| + if (HasEscapeSupprt(hdc, POSTSCRIPT_IDENTIFY)) { |
| + SetPrinterToGdiMode(hdc); |
|
Lei Zhang
2017/02/25 09:09:35
This patch set no longer checks the return value.
rbpotter
2017/02/27 16:40:50
Yes- don't need to check since GDI mode doesn't ca
|
| + } else if (!IsTechnology(hdc, kPostScriptDriver)) { |
| + // Doesn't support POSTSCRIPT_IDENTIFY and doesn't look like PostScript. |
| + return false; |
| + } else if (!HasEscapeSupprt(hdc, POSTSCRIPT_PASSTHROUGH) || |
| + !HasEscapeSupprt(hdc, POSTSCRIPT_DATA)) { |
| + // Can't change to GDI mode and doesn't have compatibility mode functions |
| return false; |
| } |
| - // Query the PS Level if possible. |
| - if (HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) { |
| - constexpr int param = FEATURESETTING_PSLEVEL; |
| - const char* param_char_ptr = reinterpret_cast<const char*>(¶m); |
| - int param_out = -1; |
| - char* param_out_char_ptr = reinterpret_cast<char*>(¶m_out); |
| - if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(param), param_char_ptr, |
| - sizeof(param_out), param_out_char_ptr) > 0) { |
| - if (param_out < 2 || param_out > 3) |
| - return false; |
| - |
| - *level = param_out; |
| - return true; |
| - } |
| - } |
| - |
| - // If it looks like a PS printer. |
| - if (HasEscapeSupprt(hdc, POSTSCRIPT_PASSTHROUGH) && |
| - HasEscapeSupprt(hdc, POSTSCRIPT_DATA)) { |
| + if (!HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) { |
|
Lei Zhang
2017/02/25 09:09:35
If a printer does not support POSTSCRIPT_IDENTIFY,
rbpotter
2017/02/27 16:40:50
Done.
|
| + // Can't query the level, use level 2 to be safe |
| *level = 2; |
| return true; |
| } |
| - |
| - return false; |
| + *level = GetPrinterPostScriptLevel(hdc); |
| + if (*level < 2 || *level > 3) { |
| + // Invalid or insufficient postscript language level. |
| + return false; |
| + } |
| + return true; |
| } |
| bool IsPrinterXPS(HDC hdc) { |