Make ServerBoundCertStore interface async, move SQLiteServerBoundCertStore load onto...
[chromium-blink-merge.git] / printing / print_settings_initializer_mac.cc
blob12fe1bdc31bdd9b137a653918bade02ff0fba2d4
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_mac.h"
7 #include "base/sys_string_conversions.h"
8 #include "printing/print_settings.h"
10 namespace printing {
12 // static
13 void PrintSettingsInitializerMac::InitPrintSettings(
14 PMPrinter printer,
15 PMPageFormat page_format,
16 const PageRanges& new_ranges,
17 bool print_selection_only,
18 PrintSettings* print_settings) {
19 DCHECK(print_settings);
21 print_settings->set_printer_name(
22 base::SysCFStringRefToUTF16(PMPrinterGetName(printer)));
23 print_settings->set_device_name(
24 base::SysCFStringRefToUTF16(PMPrinterGetID(printer)));
25 print_settings->ranges = new_ranges;
27 PMOrientation orientation = kPMPortrait;
28 PMGetOrientation(page_format, &orientation);
29 print_settings->set_landscape(orientation == kPMLandscape);
30 print_settings->selection_only = print_selection_only;
32 UInt32 resolution_count = 0;
33 PMResolution best_resolution = { 72.0, 72.0 };
34 OSStatus status = PMPrinterGetPrinterResolutionCount(printer,
35 &resolution_count);
36 if (status == noErr) {
37 // Resolution indexes are 1-based.
38 for (uint32 i = 1; i <= resolution_count; ++i) {
39 PMResolution resolution;
40 PMPrinterGetIndexedPrinterResolution(printer, i, &resolution);
41 if (resolution.hRes > best_resolution.hRes)
42 best_resolution = resolution;
45 int dpi = best_resolution.hRes;
46 print_settings->set_dpi(dpi);
48 DCHECK_EQ(dpi, best_resolution.vRes);
50 // Get printable area and paper rects (in points)
51 PMRect page_rect, paper_rect;
52 PMGetAdjustedPageRect(page_format, &page_rect);
53 PMGetAdjustedPaperRect(page_format, &paper_rect);
55 // Device units are in points. Units per inch is 72.
56 gfx::Size physical_size_device_units(
57 (paper_rect.right - paper_rect.left),
58 (paper_rect.bottom - paper_rect.top));
59 gfx::Rect printable_area_device_units(
60 (page_rect.left - paper_rect.left),
61 (page_rect.top - paper_rect.top),
62 (page_rect.right - page_rect.left),
63 (page_rect.bottom - page_rect.top));
65 print_settings->SetPrinterPrintableArea(physical_size_device_units,
66 printable_area_device_units,
67 72);
70 } // namespace printing