Fix the coverage build which used to complain about the missing pyautolib target.
[chromium-blink-merge.git] / printing / print_settings_initializer_win.cc
blob0ec96d0ab624a5f7f59240c3409bfe9331b4cd8c
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 const PageRanges& new_ranges,
18 const std::wstring& new_device_name,
19 bool print_selection_only,
20 PrintSettings* print_settings) {
21 DCHECK(hdc);
22 DCHECK(print_settings);
24 print_settings->set_printer_name(dev_mode.dmDeviceName);
25 print_settings->set_device_name(new_device_name);
26 print_settings->ranges = const_cast<PageRanges&>(new_ranges);
27 print_settings->set_landscape(dev_mode.dmOrientation == DMORIENT_LANDSCAPE);
28 print_settings->selection_only = print_selection_only;
30 int dpi = GetDeviceCaps(hdc, LOGPIXELSX);
31 print_settings->set_dpi(dpi);
32 const int kAlphaCaps = SB_CONST_ALPHA | SB_PIXEL_ALPHA;
33 print_settings->set_supports_alpha_blend(
34 (GetDeviceCaps(hdc, SHADEBLENDCAPS) & kAlphaCaps) == kAlphaCaps);
35 // No printer device is known to advertise different dpi in X and Y axis; even
36 // the fax device using the 200x100 dpi setting. It's ought to break so many
37 // applications that it's not even needed to care about. WebKit doesn't
38 // support different dpi settings in X and Y axis.
39 DCHECK_EQ(dpi, GetDeviceCaps(hdc, LOGPIXELSY));
41 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0);
42 DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0);
44 // Initialize page_setup_device_units_.
45 gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
46 GetDeviceCaps(hdc, PHYSICALHEIGHT));
47 gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
48 GetDeviceCaps(hdc, PHYSICALOFFSETY),
49 GetDeviceCaps(hdc, HORZRES),
50 GetDeviceCaps(hdc, VERTRES));
52 // Sanity check the printable_area: we've seen crashes caused by a printable
53 // area rect of 0, 0, 0, 0, so it seems some drivers don't set it.
54 if (printable_area_device_units.IsEmpty() ||
55 !gfx::Rect(physical_size_device_units).Contains(
56 printable_area_device_units)) {
57 printable_area_device_units = gfx::Rect(physical_size_device_units);
60 print_settings->SetPrinterPrintableArea(physical_size_device_units,
61 printable_area_device_units,
62 dpi);
65 } // namespace printing