Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 14 | void PrintSettingsInitializerWin::InitPrintSettings( |
| 15 | HDC hdc, |
| 16 | const DEVMODE& dev_mode, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 17 | PrintSettings* print_settings) { |
| 18 | DCHECK(hdc); |
| 19 | DCHECK(print_settings); |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 20 | print_settings->SetOrientation(dev_mode.dmOrientation == DMORIENT_LANDSCAPE); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | } |
Torne (Richard Coles) | 0f1bc08 | 2013-11-06 12:27:47 +0000 | [diff] [blame] | 51 | DCHECK_EQ(print_settings->device_units_per_inch(), dpi); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 52 | print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 53 | printable_area_device_units, |
Torne (Richard Coles) | 0f1bc08 | 2013-11-06 12:27:47 +0000 | [diff] [blame] | 54 | false); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace printing |