OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/win_util.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
11 #include "gfx/font.h" | 10 #include "gfx/font.h" |
12 #include "printing/page_number.h" | 11 #include "printing/page_number.h" |
13 #include "printing/page_overlays.h" | 12 #include "printing/page_overlays.h" |
14 #include "printing/printed_pages_source.h" | 13 #include "printing/printed_pages_source.h" |
15 #include "printing/printed_page.h" | 14 #include "printing/printed_page.h" |
16 #include "printing/units.h" | 15 #include "printing/units.h" |
17 #include "skia/ext/platform_device.h" | 16 #include "skia/ext/platform_device.h" |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 void SimpleModifyWorldTransform(HDC context, | 20 void SimpleModifyWorldTransform(HDC context, |
22 int offset_x, | 21 int offset_x, |
23 int offset_y, | 22 int offset_y, |
24 double shrink_factor) { | 23 double shrink_factor) { |
25 XFORM xform = { 0 }; | 24 XFORM xform = { 0 }; |
26 xform.eDx = static_cast<float>(offset_x); | 25 xform.eDx = static_cast<float>(offset_x); |
27 xform.eDy = static_cast<float>(offset_y); | 26 xform.eDy = static_cast<float>(offset_y); |
28 xform.eM11 = xform.eM22 = static_cast<float>(1. / shrink_factor); | 27 xform.eM11 = xform.eM22 = static_cast<float>(1. / shrink_factor); |
29 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY); | 28 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY); |
30 DCHECK_NE(res, 0); | 29 DCHECK_NE(res, 0); |
31 } | 30 } |
32 | 31 |
33 void DrawRect(HDC context, gfx::Rect rect) { | 32 void DrawRect(HDC context, gfx::Rect rect) { |
34 Rectangle(context, rect.x(), rect.y(), rect.right(), rect.bottom()); | 33 Rectangle(context, rect.x(), rect.y(), rect.right(), rect.bottom()); |
35 } | 34 } |
36 | 35 |
| 36 // Creates a string interpretation of the time of day represented by the given |
| 37 // SYSTEMTIME that's appropriate for the user's default locale. |
| 38 // Format can be an empty string (for the default format), or a "format picture" |
| 39 // as specified in the Windows documentation for GetTimeFormat(). |
| 40 string16 FormatSystemTime(const SYSTEMTIME& time, const string16& format) { |
| 41 // If the format string is empty, just use the default format. |
| 42 LPCTSTR format_ptr = NULL; |
| 43 if (!format.empty()) |
| 44 format_ptr = format.c_str(); |
| 45 |
| 46 int buffer_size = GetTimeFormat(LOCALE_USER_DEFAULT, NULL, &time, format_ptr, |
| 47 NULL, 0); |
| 48 |
| 49 string16 output; |
| 50 GetTimeFormat(LOCALE_USER_DEFAULT, NULL, &time, format_ptr, |
| 51 WriteInto(&output, buffer_size), buffer_size); |
| 52 |
| 53 return output; |
| 54 } |
| 55 |
| 56 // Creates a string interpretation of the date represented by the given |
| 57 // SYSTEMTIME that's appropriate for the user's default locale. |
| 58 // Format can be an empty string (for the default format), or a "format picture" |
| 59 // as specified in the Windows documentation for GetDateFormat(). |
| 60 string16 FormatSystemDate(const SYSTEMTIME& date, const string16& format) { |
| 61 // If the format string is empty, just use the default format. |
| 62 LPCTSTR format_ptr = NULL; |
| 63 if (!format.empty()) |
| 64 format_ptr = format.c_str(); |
| 65 |
| 66 int buffer_size = GetDateFormat(LOCALE_USER_DEFAULT, NULL, &date, format_ptr, |
| 67 NULL, 0); |
| 68 |
| 69 string16 output; |
| 70 GetDateFormat(LOCALE_USER_DEFAULT, NULL, &date, format_ptr, |
| 71 WriteInto(&output, buffer_size), buffer_size); |
| 72 |
| 73 return output; |
| 74 } |
| 75 |
37 } // namespace | 76 } // namespace |
38 | 77 |
39 namespace printing { | 78 namespace printing { |
40 | 79 |
41 void PrintedDocument::RenderPrintedPage( | 80 void PrintedDocument::RenderPrintedPage( |
42 const PrintedPage& page, gfx::NativeDrawingContext context) const { | 81 const PrintedPage& page, gfx::NativeDrawingContext context) const { |
43 #ifndef NDEBUG | 82 #ifndef NDEBUG |
44 { | 83 { |
45 // Make sure the page is from our list. | 84 // Make sure the page is from our list. |
46 base::AutoLock lock(lock_); | 85 base::AutoLock lock(lock_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 font); | 153 font); |
115 int res = RestoreDC(context, saved_state); | 154 int res = RestoreDC(context, saved_state); |
116 DCHECK_NE(res, 0); | 155 DCHECK_NE(res, 0); |
117 } | 156 } |
118 | 157 |
119 void PrintedDocument::Immutable::SetDocumentDate() { | 158 void PrintedDocument::Immutable::SetDocumentDate() { |
120 // Use the native time formatting for printing on Windows. | 159 // Use the native time formatting for printing on Windows. |
121 SYSTEMTIME systemtime; | 160 SYSTEMTIME systemtime; |
122 GetLocalTime(&systemtime); | 161 GetLocalTime(&systemtime); |
123 date_ = | 162 date_ = |
124 WideToUTF16Hack(app::win::FormatSystemDate(systemtime, std::wstring())); | 163 WideToUTF16Hack(FormatSystemDate(systemtime, std::wstring())); |
125 time_ = | 164 time_ = |
126 WideToUTF16Hack(app::win::FormatSystemTime(systemtime, std::wstring())); | 165 WideToUTF16Hack(FormatSystemTime(systemtime, std::wstring())); |
127 } | 166 } |
128 | 167 |
129 void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context, | 168 void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context, |
130 std::wstring text, | 169 std::wstring text, |
131 gfx::Rect bounds) const { | 170 gfx::Rect bounds) const { |
132 // Save the state for the clipping region. | 171 // Save the state for the clipping region. |
133 int saved_state = SaveDC(context); | 172 int saved_state = SaveDC(context); |
134 DCHECK_NE(saved_state, 0); | 173 DCHECK_NE(saved_state, 0); |
135 | 174 |
136 int result = IntersectClipRect(context, bounds.x(), bounds.y(), | 175 int result = IntersectClipRect(context, bounds.x(), bounds.y(), |
137 bounds.right() + 1, bounds.bottom() + 1); | 176 bounds.right() + 1, bounds.bottom() + 1); |
138 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); | 177 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); |
139 TextOut(context, | 178 TextOut(context, |
140 bounds.x(), bounds.y(), | 179 bounds.x(), bounds.y(), |
141 text.c_str(), | 180 text.c_str(), |
142 static_cast<int>(text.size())); | 181 static_cast<int>(text.size())); |
143 int res = RestoreDC(context, saved_state); | 182 int res = RestoreDC(context, saved_state); |
144 DCHECK_NE(res, 0); | 183 DCHECK_NE(res, 0); |
145 } | 184 } |
146 | 185 |
147 } // namespace printing | 186 } // namespace printing |
OLD | NEW |