• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "printing/print_settings_initializer_win.h"
6 
7 #include <windows.h>
8 
9 #include "printing/print_settings.h"
10 
11 namespace printing {
12 
13 // static
InitPrintSettings(HDC hdc,const DEVMODE & dev_mode,PrintSettings * print_settings)14 void PrintSettingsInitializerWin::InitPrintSettings(
15     HDC hdc,
16     const DEVMODE& dev_mode,
17     PrintSettings* print_settings) {
18   DCHECK(hdc);
19   DCHECK(print_settings);
20   print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE);
21 
22   int dpi = GetDeviceCaps(hdc, LOGPIXELSX);
23   print_settings->set_dpi(dpi);
24   const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA;
25   print_settings->set_supports_alpha_blend(
26     (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps);
27   // 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
29   // applications that it's not even needed to care about. WebKit doesn't
30   // support different dpi settings in X and Y axis.
31   DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY));
32 
33   DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
34   DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
35 
36   // Initialize page_setup_device_units_.
37   gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
38                                        GetDeviceCaps(hdc, PHYSICALHEIGHT));
39   gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
40                                         GetDeviceCaps(hdc, PHYSICALOFFSETY),
41                                         GetDeviceCaps(hdc, HORZRES),
42                                         GetDeviceCaps(hdc, VERTRES));
43 
44   // 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.
46   if (printable_area_device_units.IsEmpty() ||
47       !gfx::Rect(physical_size_device_units).Contains(
48           printable_area_device_units)) {
49     printable_area_device_units = gfx::Rect(physical_size_device_units);
50   }
51   DCHECK_EQ(print_settings->device_units_per_inch(), dpi);
52   print_settings->SetPrinterPrintableArea(physical_size_device_units,
53                                           printable_area_device_units,
54                                           false);
55 }
56 
57 }  // namespace printing
58