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

Side by Side Diff: printing/print_settings_initializer_win.cc

Issue 2395373003: M54: Fix printing with XPS printers on Windows. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « printing/print_settings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 namespace printing { 11 namespace printing {
12 12
13 namespace {
14
15 bool IsPrinterXPS(HDC hdc) {
16 int device_type = ::GetDeviceCaps(hdc, TECHNOLOGY);
17 if (device_type != DT_RASPRINTER)
18 return false;
19
20 const DWORD escape = GETTECHNOLOGY;
21 const char* escape_ptr = reinterpret_cast<const char*>(&escape);
22 int ret =
23 ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), escape_ptr, 0, nullptr);
24 if (ret <= 0)
25 return false;
26
27 char buffer[256];
28 memset(buffer, 0, sizeof(buffer));
29 ret = ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buffer) - 1, buffer);
30 if (ret <= 0)
31 return false;
32
33 static const char kXPSDriver[] = "http://schemas.microsoft.com/xps/2005/06";
34 return strcmp(buffer, kXPSDriver) == 0;
35 }
36
37 } // namespace
38
13 // static 39 // static
14 void PrintSettingsInitializerWin::InitPrintSettings( 40 void PrintSettingsInitializerWin::InitPrintSettings(
15 HDC hdc, 41 HDC hdc,
16 const DEVMODE& dev_mode, 42 const DEVMODE& dev_mode,
17 PrintSettings* print_settings) { 43 PrintSettings* print_settings) {
18 DCHECK(hdc); 44 DCHECK(hdc);
19 DCHECK(print_settings); 45 DCHECK(print_settings);
46
20 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); 47 print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE);
21 48
22 int dpi = GetDeviceCaps(hdc, LOGPIXELSX); 49 int dpi = GetDeviceCaps(hdc, LOGPIXELSX);
23 print_settings->set_dpi(dpi); 50 print_settings->set_dpi(dpi);
51
24 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA; 52 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA;
25 print_settings->set_supports_alpha_blend( 53 print_settings->set_supports_alpha_blend(
26 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps); 54 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps);
55
27 // No printer device is known to advertise different dpi in X and Y axis; even 56 // No printer device is known to advertise different dpi in X and Y axis; even
28 // the fax device using the 200x100 dpi setting. It's ought to break so many 57 // the fax device using the 200x100 dpi setting. It's ought to break so many
29 // applications that it's not even needed to care about. WebKit doesn't 58 // applications that it's not even needed to care about. Blink doesn't support
30 // support different dpi settings in X and Y axis. 59 // different dpi settings in X and Y axis.
31 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY)); 60 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY));
32 61
33 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); 62 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
34 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); 63 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
35 64
36 // Initialize page_setup_device_units_. 65 // Initialize |page_setup_device_units_|.
37 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH), 66 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
38 GetDeviceCaps(hdc, PHYSICALHEIGHT)); 67 GetDeviceCaps(hdc, PHYSICALHEIGHT));
39 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX), 68 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
40 GetDeviceCaps(hdc, PHYSICALOFFSETY), 69 GetDeviceCaps(hdc, PHYSICALOFFSETY),
41 GetDeviceCaps(hdc, HORZRES), 70 GetDeviceCaps(hdc, HORZRES),
42 GetDeviceCaps(hdc, VERTRES)); 71 GetDeviceCaps(hdc, VERTRES));
43 72
44 // Sanity check the printable_area: we've seen crashes caused by a printable 73 // Sanity check the printable_area: we've seen crashes caused by a printable
45 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it. 74 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it.
46 if (printable_area_device_units.IsEmpty() || 75 if (printable_area_device_units.IsEmpty() ||
47 !gfx::Rect(physical_size_device_units).Contains( 76 !gfx::Rect(physical_size_device_units).Contains(
48 printable_area_device_units)) { 77 printable_area_device_units)) {
49 printable_area_device_units = gfx::Rect(physical_size_device_units); 78 printable_area_device_units = gfx::Rect(physical_size_device_units);
50 } 79 }
51 DCHECK_EQ(print_settings->device_units_per_inch(), dpi); 80 DCHECK_EQ(print_settings->device_units_per_inch(), dpi);
52 print_settings->SetPrinterPrintableArea(physical_size_device_units, 81 print_settings->SetPrinterPrintableArea(physical_size_device_units,
53 printable_area_device_units, 82 printable_area_device_units,
54 false); 83 false);
84
85 print_settings->set_printer_is_xps(IsPrinterXPS(hdc));
55 } 86 }
56 87
57 } // namespace printing 88 } // namespace printing
OLDNEW
« no previous file with comments | « printing/print_settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698