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

Side by Side 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 unified diff | Download patch
OLDNEW
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
(...skipping 13 matching lines...) Expand all
24 if (!HasEscapeSupprt(hdc, GETTECHNOLOGY)) 24 if (!HasEscapeSupprt(hdc, GETTECHNOLOGY))
25 return false; 25 return false;
26 26
27 char buf[256]; 27 char buf[256];
28 memset(buf, 0, sizeof(buf)); 28 memset(buf, 0, sizeof(buf));
29 if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0) 29 if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0)
30 return false; 30 return false;
31 return strcmp(buf, technology) == 0; 31 return strcmp(buf, technology) == 0;
32 } 32 }
33 33
34 bool IsPrinterPostScript(HDC hdc, int* level) {
35 static constexpr char kPostScriptDriver[] = "PostScript";
36 if (!IsTechnology(hdc, kPostScriptDriver)) {
37 return false;
38 }
39
40 // Query the PS Level if possible. Many PS printers do not implement this.
41 if (HasEscapeSupprt(hdc, GET_PS_FEATURESETTING)) {
42 constexpr int param = FEATURESETTING_PSLEVEL;
43 const char* param_char_ptr = reinterpret_cast<const char*>(&param);
44 int param_out = -1;
45 char* param_out_char_ptr = reinterpret_cast<char*>(&param_out);
46 if (ExtEscape(hdc, GET_PS_FEATURESETTING, sizeof(param), param_char_ptr,
47 sizeof(param_out), param_out_char_ptr) > 0) {
48 if (param_out < 2 || param_out > 3)
49 return false;
50
51 *level = param_out;
52 return true;
53 }
54 }
55
56 // If it looks like a PS printer.
57 if (HasEscapeSupprt(hdc, POSTSCRIPT_PASSTHROUGH) &&
58 HasEscapeSupprt(hdc, POSTSCRIPT_DATA)) {
59 *level = 2;
60 return true;
61 }
62
63 return false;
64 }
65
34 bool IsPrinterXPS(HDC hdc) { 66 bool IsPrinterXPS(HDC hdc) {
35 static constexpr char kXPSDriver[] = 67 static constexpr char kXPSDriver[] =
36 "http://schemas.microsoft.com/xps/2005/06"; 68 "http://schemas.microsoft.com/xps/2005/06";
37 return IsTechnology(hdc, kXPSDriver); 69 return IsTechnology(hdc, kXPSDriver);
38 } 70 }
39 71
40 } // namespace 72 } // namespace
41 73
42 // static 74 // static
43 void PrintSettingsInitializerWin::InitPrintSettings( 75 void PrintSettingsInitializerWin::InitPrintSettings(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 !gfx::Rect(physical_size_device_units).Contains( 111 !gfx::Rect(physical_size_device_units).Contains(
80 printable_area_device_units)) { 112 printable_area_device_units)) {
81 printable_area_device_units = gfx::Rect(physical_size_device_units); 113 printable_area_device_units = gfx::Rect(physical_size_device_units);
82 } 114 }
83 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); 115 DCHECK_EQ(print_settings->device_units_per_inch(), dpi);
84 print_settings->SetPrinterPrintableArea(physical_size_device_units, 116 print_settings->SetPrinterPrintableArea(physical_size_device_units,
85 printable_area_device_units, 117 printable_area_device_units,
86 false); 118 false);
87 119
88 print_settings->set_printer_is_xps(IsPrinterXPS(hdc)); 120 print_settings->set_printer_is_xps(IsPrinterXPS(hdc));
121 if (!print_settings->printer_is_xps()) {
122 int level;
123 if (IsPrinterPostScript(hdc, &level)) {
124 if (level == 2) {
125 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.
126 } else {
127 DCHECK_EQ(3, level);
128 print_settings->set_printer_is_ps3(true);
129 }
130 }
131 }
89 } 132 }
90 133
91 } // namespace printing 134 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698