Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1919)

Unified Diff: printing/print_settings_initializer_win.cc

Issue 2633573002: Add Postscript Printing (Closed)
Patch Set: Fix Linux compile error Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: printing/print_settings_initializer_win.cc
diff --git a/printing/print_settings_initializer_win.cc b/printing/print_settings_initializer_win.cc
index e72033d04ffa46511978e7a2f9a8f8b538dfa54a..450975674c3f4e6eb239e8ab0cfd9f9a7932b2a8 100644
--- a/printing/print_settings_initializer_win.cc
+++ b/printing/print_settings_initializer_win.cc
@@ -12,26 +12,61 @@ namespace printing {
namespace {
-bool IsPrinterXPS(HDC hdc) {
- int device_type = ::GetDeviceCaps(hdc, TECHNOLOGY);
- if (device_type != DT_RASPRINTER)
+bool HasEscapeSupprt(HDC hdc, DWORD escape) {
Vitaly Buka (NO REVIEWS) 2017/01/17 19:29:16 Same here. Extraction of IsTechnology function des
+ const char* ptr = reinterpret_cast<const char*>(&escape);
+ return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0;
+}
+
+bool IsTechnology(HDC hdc, const char* technology) {
+ if (::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASPRINTER)
+ return false;
+
+ if (!HasEscapeSupprt(hdc, GETTECHNOLOGY))
return false;
- const DWORD escape = GETTECHNOLOGY;
- const char* escape_ptr = reinterpret_cast<const char*>(&escape);
- int ret =
- ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), escape_ptr, 0, nullptr);
- if (ret <= 0)
+ char buf[256];
+ memset(buf, 0, sizeof(buf));
+ if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0)
return false;
+ return strcmp(buf, technology) == 0;
+}
- char buffer[256];
- memset(buffer, 0, sizeof(buffer));
- ret = ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buffer) - 1, buffer);
- if (ret <= 0)
+bool IsPrinterPostScript(HDC hdc, int* level) {
+ static constexpr char kPostScriptDriver[] = "PostScript";
+ if (!IsTechnology(hdc, kPostScriptDriver)) {
return false;
+ }
- static const char kXPSDriver[] = "http://schemas.microsoft.com/xps/2005/06";
- return strcmp(buffer, kXPSDriver) == 0;
+ // Query the PS Level if possible. Many PS printers do not implement this.
+ if (HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) {
+ constexpr int param = FEATURESETTING_PSLEVEL;
+ const char* param_char_ptr = reinterpret_cast<const char*>(&param);
+ int param_out = -1;
+ char* param_out_char_ptr = reinterpret_cast<char*>(&param_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)) {
+ *level = 2;
+ return true;
+ }
+
+ return false;
+}
+
+bool IsPrinterXPS(HDC hdc) {
+ static constexpr char kXPSDriver[] =
+ "http://schemas.microsoft.com/xps/2005/06";
+ return IsTechnology(hdc, kXPSDriver);
}
} // namespace
@@ -83,6 +118,17 @@ void PrintSettingsInitializerWin::InitPrintSettings(
false);
print_settings->set_printer_is_xps(IsPrinterXPS(hdc));
+ if (!print_settings->printer_is_xps()) {
+ int level;
+ if (IsPrinterPostScript(hdc, &level)) {
+ if (level == 2) {
+ print_settings->set_printer_is_ps2(true);
+ } else {
+ DCHECK_EQ(3, level);
+ print_settings->set_printer_is_ps3(true);
+ }
+ }
+ }
}
} // namespace printing

Powered by Google App Engine
This is Rietveld 408576698