[email protected] | a0f5900 | 2011-09-20 03:59:05 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 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_mac.h" |
| 6 | |
avi | 126e93c | 2015-12-21 21:48:16 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
[email protected] | 13ac5353 | 2013-03-30 00:27:00 | [diff] [blame] | 9 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 10 | #include "printing/print_settings.h" |
[email protected] | 4c9054b | 2013-11-04 18:34:29 | [diff] [blame] | 11 | #include "printing/units.h" |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 12 | |
| 13 | namespace printing { |
| 14 | |
| 15 | // static |
| 16 | void PrintSettingsInitializerMac::InitPrintSettings( |
| 17 | PMPrinter printer, |
| 18 | PMPageFormat page_format, |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 19 | PrintSettings* print_settings) { |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 20 | print_settings->set_device_name( |
[email protected] | a0f5900 | 2011-09-20 03:59:05 | [diff] [blame] | 21 | base::SysCFStringRefToUTF16(PMPrinterGetID(printer))); |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 22 | |
| 23 | PMOrientation orientation = kPMPortrait; |
| 24 | PMGetOrientation(page_format, &orientation); |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 25 | print_settings->SetOrientation(orientation == kPMLandscape); |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 26 | |
| 27 | UInt32 resolution_count = 0; |
| 28 | PMResolution best_resolution = { 72.0, 72.0 }; |
| 29 | OSStatus status = PMPrinterGetPrinterResolutionCount(printer, |
| 30 | &resolution_count); |
| 31 | if (status == noErr) { |
| 32 | // Resolution indexes are 1-based. |
thestig | 707a24b2 | 2015-09-14 18:16:33 | [diff] [blame] | 33 | for (uint32_t i = 1; i <= resolution_count; ++i) { |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 34 | PMResolution resolution; |
| 35 | PMPrinterGetIndexedPrinterResolution(printer, i, &resolution); |
| 36 | if (resolution.hRes > best_resolution.hRes) |
| 37 | best_resolution = resolution; |
| 38 | } |
| 39 | } |
| 40 | int dpi = best_resolution.hRes; |
| 41 | print_settings->set_dpi(dpi); |
| 42 | |
| 43 | DCHECK_EQ(dpi, best_resolution.vRes); |
| 44 | |
| 45 | // Get printable area and paper rects (in points) |
| 46 | PMRect page_rect, paper_rect; |
| 47 | PMGetAdjustedPageRect(page_format, &page_rect); |
| 48 | PMGetAdjustedPaperRect(page_format, &paper_rect); |
| 49 | |
| 50 | // Device units are in points. Units per inch is 72. |
| 51 | gfx::Size physical_size_device_units( |
| 52 | (paper_rect.right - paper_rect.left), |
| 53 | (paper_rect.bottom - paper_rect.top)); |
| 54 | gfx::Rect printable_area_device_units( |
| 55 | (page_rect.left - paper_rect.left), |
| 56 | (page_rect.top - paper_rect.top), |
| 57 | (page_rect.right - page_rect.left), |
| 58 | (page_rect.bottom - page_rect.top)); |
| 59 | |
[email protected] | 4c9054b | 2013-11-04 18:34:29 | [diff] [blame] | 60 | DCHECK_EQ(print_settings->device_units_per_inch(), kPointsPerInch); |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 61 | print_settings->SetPrinterPrintableArea(physical_size_device_units, |
| 62 | printable_area_device_units, |
[email protected] | 4c9054b | 2013-11-04 18:34:29 | [diff] [blame] | 63 | false); |
[email protected] | 4993f34 | 2010-10-26 17:57:52 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace printing |