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

Unified Diff: printing/print_settings_initializer_win.cc

Issue 2633573002: Add Postscript Printing (Closed)
Patch Set: Rebase 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 0776e9e5c0e5636864e8d611edbbc704ae5686d4..450975674c3f4e6eb239e8ab0cfd9f9a7932b2a8 100644
--- a/printing/print_settings_initializer_win.cc
+++ b/printing/print_settings_initializer_win.cc
@@ -31,6 +31,38 @@ bool IsTechnology(HDC hdc, const char* technology) {
return strcmp(buf, technology) == 0;
}
+bool IsPrinterPostScript(HDC hdc, int* level) {
+ static constexpr char kPostScriptDriver[] = "PostScript";
+ if (!IsTechnology(hdc, kPostScriptDriver)) {
+ return false;
+ }
+
+ // 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";
@@ -86,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);
Vitaly Buka (NO REVIEWS) 2017/01/27 00:38:49 Looks like printer_is* flags exclusive probably cl
rbpotter 2017/01/27 16:37:21 Done.
+ } else {
+ DCHECK_EQ(3, level);
+ print_settings->set_printer_is_ps3(true);
+ }
+ }
+ }
}
} // namespace printing

Powered by Google App Engine
This is Rietveld 408576698