OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/printed_document.h" | 5 #include "printing/printed_document.h" |
6 | 6 |
7 #include "app/win_util.h" | 7 #include "app/win_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "gfx/font.h" | 10 #include "gfx/font.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #ifndef NDEBUG | 44 #ifndef NDEBUG |
45 { | 45 { |
46 // Make sure the page is from our list. | 46 // Make sure the page is from our list. |
47 AutoLock lock(lock_); | 47 AutoLock lock(lock_); |
48 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); | 48 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); |
49 } | 49 } |
50 #endif | 50 #endif |
51 | 51 |
52 const printing::PageSetup& page_setup( | 52 const printing::PageSetup& page_setup( |
53 immutable_.settings_.page_setup_device_units()); | 53 immutable_.settings_.page_setup_device_units()); |
| 54 gfx::Rect content_area(page.page_content_rect()); |
| 55 const gfx::Size& physical_size = page_setup.physical_size(); |
| 56 // http://dev.w3.org/csswg/css3-page/#positioning-page-box |
| 57 if (physical_size.width() > page.page_size().width()) { |
| 58 int diff = physical_size.width() - page.page_size().width(); |
| 59 content_area.set_x(content_area.x() + diff / 2); |
| 60 } |
| 61 if (physical_size.height() > page.page_size().height()) { |
| 62 int diff = physical_size.height() - page.page_size().height(); |
| 63 content_area.set_y(content_area.y() + diff / 2); |
| 64 } |
54 | 65 |
55 // Save the state to make sure the context this function call does not modify | 66 // Save the state to make sure the context this function call does not modify |
56 // the device context. | 67 // the device context. |
57 int saved_state = SaveDC(context); | 68 int saved_state = SaveDC(context); |
58 DCHECK_NE(saved_state, 0); | 69 DCHECK_NE(saved_state, 0); |
59 skia::PlatformDevice::InitializeDC(context); | 70 skia::PlatformDevice::InitializeDC(context); |
60 { | 71 { |
61 // Save the state (again) to apply the necessary world transformation. | 72 // Save the state (again) to apply the necessary world transformation. |
62 int saved_state = SaveDC(context); | 73 int saved_state = SaveDC(context); |
63 DCHECK_NE(saved_state, 0); | 74 DCHECK_NE(saved_state, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
74 0, | 85 0, |
75 page_setup.printable_area().width(), | 86 page_setup.printable_area().width(), |
76 page_setup.printable_area().height()); | 87 page_setup.printable_area().height()); |
77 // Overlay area: | 88 // Overlay area: |
78 gfx::Rect debug_overlay_area(page_setup.overlay_area()); | 89 gfx::Rect debug_overlay_area(page_setup.overlay_area()); |
79 debug_overlay_area.Offset(-page_setup.printable_area().x(), | 90 debug_overlay_area.Offset(-page_setup.printable_area().x(), |
80 -page_setup.printable_area().y()); | 91 -page_setup.printable_area().y()); |
81 SelectObject(context, CreateSolidBrush(RGB(0xb0, 0xb0, 0xb0))); | 92 SelectObject(context, CreateSolidBrush(RGB(0xb0, 0xb0, 0xb0))); |
82 DrawRect(context, debug_overlay_area); | 93 DrawRect(context, debug_overlay_area); |
83 // Content area: | 94 // Content area: |
84 gfx::Rect debug_content_area(page_setup.content_area()); | 95 gfx::Rect debug_content_area(content_area()); |
85 debug_content_area.Offset(-page_setup.printable_area().x(), | 96 debug_content_area.Offset(-page_setup.printable_area().x(), |
86 -page_setup.printable_area().y()); | 97 -page_setup.printable_area().y()); |
87 SelectObject(context, CreateSolidBrush(RGB(0xd0, 0xd0, 0xd0))); | 98 SelectObject(context, CreateSolidBrush(RGB(0xd0, 0xd0, 0xd0))); |
88 DrawRect(context, debug_content_area); | 99 DrawRect(context, debug_content_area); |
89 #endif | 100 #endif |
90 | 101 |
91 // Setup the matrix to translate and scale to the right place. Take in | 102 // Setup the matrix to translate and scale to the right place. Take in |
92 // account the actual shrinking factor. | 103 // account the actual shrinking factor. |
93 // Note that the printing output is relative to printable area of the page. | 104 // Note that the printing output is relative to printable area of the page. |
94 // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. | 105 // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. |
95 SimpleModifyWorldTransform( | 106 SimpleModifyWorldTransform( |
96 context, | 107 context, |
97 page_setup.content_area().x() - page_setup.printable_area().x(), | 108 content_area.x() - page_setup.printable_area().x(), |
98 page_setup.content_area().y() - page_setup.printable_area().y(), | 109 content_area.y() - page_setup.printable_area().y(), |
99 mutable_.shrink_factor); | 110 mutable_.shrink_factor); |
100 | 111 |
101 if (!page.native_metafile()->SafePlayback(context)) { | 112 if (!page.native_metafile()->SafePlayback(context)) { |
102 NOTREACHED(); | 113 NOTREACHED(); |
103 } | 114 } |
104 | 115 |
105 BOOL res = RestoreDC(context, saved_state); | 116 BOOL res = RestoreDC(context, saved_state); |
106 DCHECK_NE(res, 0); | 117 DCHECK_NE(res, 0); |
107 } | 118 } |
108 | 119 |
(...skipping 24 matching lines...) Expand all Loading... |
133 font); | 144 font); |
134 PrintHeaderFooter(context, page, PageOverlays::CENTER, PageOverlays::BOTTOM, | 145 PrintHeaderFooter(context, page, PageOverlays::CENTER, PageOverlays::BOTTOM, |
135 font); | 146 font); |
136 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::BOTTOM, | 147 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::BOTTOM, |
137 font); | 148 font); |
138 int res = RestoreDC(context, saved_state); | 149 int res = RestoreDC(context, saved_state); |
139 DCHECK_NE(res, 0); | 150 DCHECK_NE(res, 0); |
140 } | 151 } |
141 | 152 |
142 } // namespace printing | 153 } // namespace printing |
OLD | NEW |