OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/print_settings.h" | 5 #include "printing/print_settings.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/sys_string_conversions.h" |
9 #include "printing/units.h" | 10 #include "printing/units.h" |
10 | 11 |
11 namespace printing { | 12 namespace printing { |
12 | 13 |
13 // Global SequenceNumber used for generating unique cookie values. | 14 // Global SequenceNumber used for generating unique cookie values. |
14 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED); | 15 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED); |
15 | 16 |
16 PrintSettings::PrintSettings() | 17 PrintSettings::PrintSettings() |
17 : min_shrink(1.25), | 18 : min_shrink(1.25), |
18 max_shrink(2.0), | 19 max_shrink(2.0), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Initialize page_setup_pixels_. | 62 // Initialize page_setup_pixels_. |
62 gfx::Size physical_size_pixels(GetDeviceCaps(hdc, PHYSICALWIDTH), | 63 gfx::Size physical_size_pixels(GetDeviceCaps(hdc, PHYSICALWIDTH), |
63 GetDeviceCaps(hdc, PHYSICALHEIGHT)); | 64 GetDeviceCaps(hdc, PHYSICALHEIGHT)); |
64 gfx::Rect printable_area_pixels(GetDeviceCaps(hdc, PHYSICALOFFSETX), | 65 gfx::Rect printable_area_pixels(GetDeviceCaps(hdc, PHYSICALOFFSETX), |
65 GetDeviceCaps(hdc, PHYSICALOFFSETY), | 66 GetDeviceCaps(hdc, PHYSICALOFFSETY), |
66 GetDeviceCaps(hdc, HORZRES), | 67 GetDeviceCaps(hdc, HORZRES), |
67 GetDeviceCaps(hdc, VERTRES)); | 68 GetDeviceCaps(hdc, VERTRES)); |
68 | 69 |
69 SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels); | 70 SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels); |
70 } | 71 } |
| 72 #elif defined(OS_MACOSX) |
| 73 void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format, |
| 74 const PageRanges& new_ranges, |
| 75 bool print_selection_only) { |
| 76 printer_name_ = base::SysCFStringRefToWide(PMPrinterGetName(printer)); |
| 77 device_name_ = base::SysCFStringRefToWide(PMPrinterGetID(printer)); |
| 78 ranges = new_ranges; |
| 79 PMOrientation orientation = kPMPortrait; |
| 80 PMGetOrientation(page_format, &orientation); |
| 81 landscape_ = orientation == kPMLandscape; |
| 82 selection_only = print_selection_only; |
| 83 |
| 84 UInt32 resolution_count = 0; |
| 85 PMResolution best_resolution = { 72.0, 72.0 }; |
| 86 OSStatus status = PMPrinterGetPrinterResolutionCount(printer, |
| 87 &resolution_count); |
| 88 if (status == noErr) { |
| 89 // Resolution indexes are 1-based. |
| 90 for (uint32 i = 1; i <= resolution_count; ++i) { |
| 91 PMResolution resolution; |
| 92 PMPrinterGetIndexedPrinterResolution(printer, i, &resolution); |
| 93 if (best_resolution.hRes > resolution.hRes) |
| 94 best_resolution = resolution; |
| 95 } |
| 96 } |
| 97 dpi_ = best_resolution.hRes; |
| 98 // See comment in the Windows code above. |
| 99 DCHECK_EQ(dpi_, best_resolution.vRes); |
| 100 |
| 101 // Get printable area and paper rects (in points) |
| 102 PMRect page_rect, paper_rect; |
| 103 PMGetAdjustedPageRect(page_format, &page_rect); |
| 104 PMGetAdjustedPaperRect(page_format, &paper_rect); |
| 105 const double pixels_per_point = dpi_ / 72.0; |
| 106 gfx::Size physical_size_pixels( |
| 107 (paper_rect.right - paper_rect.left) * pixels_per_point, |
| 108 (paper_rect.bottom - paper_rect.top) * pixels_per_point); |
| 109 gfx::Rect printable_area_pixels( |
| 110 (page_rect.left - paper_rect.left) * pixels_per_point, |
| 111 (page_rect.top - paper_rect.top) * pixels_per_point, |
| 112 (page_rect.right - page_rect.left) * pixels_per_point, |
| 113 (page_rect.bottom - page_rect.top) * pixels_per_point); |
| 114 |
| 115 SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels); |
| 116 } |
71 #endif | 117 #endif |
72 | 118 |
73 void PrintSettings::SetPrinterPrintableArea( | 119 void PrintSettings::SetPrinterPrintableArea( |
74 gfx::Size const& physical_size_pixels, | 120 gfx::Size const& physical_size_pixels, |
75 gfx::Rect const& printable_area_pixels) { | 121 gfx::Rect const& printable_area_pixels) { |
76 | 122 |
77 // Hard-code text_height = 0.5cm = ~1/5 of inch. | 123 // Hard-code text_height = 0.5cm = ~1/5 of inch. |
78 int header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch, dpi_); | 124 int header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch, dpi_); |
79 | 125 |
80 // Start by setting the user configuration | 126 // Start by setting the user configuration |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 dpi_ == rhs.dpi_ && | 158 dpi_ == rhs.dpi_ && |
113 landscape_ == rhs.landscape_; | 159 landscape_ == rhs.landscape_; |
114 } | 160 } |
115 | 161 |
116 int PrintSettings::NewCookie() { | 162 int PrintSettings::NewCookie() { |
117 // A cookie of 0 is used to mark a document as unassigned, count from 1. | 163 // A cookie of 0 is used to mark a document as unassigned, count from 1. |
118 return cookie_seq.GetNext() + 1; | 164 return cookie_seq.GetNext() + 1; |
119 } | 165 } |
120 | 166 |
121 } // namespace printing | 167 } // namespace printing |
OLD | NEW |