Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / printing / print_settings_initializer_win.cc
blobc10562b86c5854284da58a7cc0bae93723ff1857
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.
5 #include "printing/print_settings_initializer_win.h"
7 #include <windows.h>
9 #include "printing/print_settings.h"
11 namespace printing {
13 // static
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);
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));
33 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
34 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
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));
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);
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);
57 } // namespace printing