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 "chrome/browser/printing/printed_document.h" | 5 #include "chrome/browser/printing/printed_document.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
11 #include "app/win_util.h" | 11 #include "app/win_util.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/printing/page_number.h" | 17 #include "chrome/browser/printing/page_number.h" |
18 #include "chrome/browser/printing/page_overlays.h" | 18 #include "chrome/browser/printing/page_overlays.h" |
19 #include "chrome/browser/printing/printed_pages_source.h" | 19 #include "chrome/browser/printing/printed_pages_source.h" |
20 #include "chrome/browser/printing/printed_page.h" | 20 #include "chrome/browser/printing/printed_page.h" |
21 #include "chrome/common/gfx/emf.h" | |
22 #include "printing/units.h" | 21 #include "printing/units.h" |
23 #include "skia/ext/platform_device.h" | 22 #include "skia/ext/platform_device.h" |
24 | 23 |
25 using base::Time; | 24 using base::Time; |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 struct PrintDebugDumpPath { | 28 struct PrintDebugDumpPath { |
30 PrintDebugDumpPath() | 29 PrintDebugDumpPath() |
31 : enabled(false) { | 30 : enabled(false) { |
(...skipping 21 matching lines...) Expand all Loading... |
53 for (unsigned i = 0; i < settings.ranges.size(); ++i) { | 52 for (unsigned i = 0; i < settings.ranges.size(); ++i) { |
54 const PageRange& range = settings.ranges[i]; | 53 const PageRange& range = settings.ranges[i]; |
55 mutable_.expected_page_count_ += range.to - range.from + 1; | 54 mutable_.expected_page_count_ += range.to - range.from + 1; |
56 } | 55 } |
57 } | 56 } |
58 } | 57 } |
59 | 58 |
60 PrintedDocument::~PrintedDocument() { | 59 PrintedDocument::~PrintedDocument() { |
61 } | 60 } |
62 | 61 |
63 void PrintedDocument::SetPage(int page_number, gfx::Emf* emf, double shrink) { | 62 void PrintedDocument::SetPage(int page_number, |
| 63 NativeMetafile* metafile, |
| 64 double shrink) { |
64 // Notice the page_number + 1, the reason is that this is the value that will | 65 // Notice the page_number + 1, the reason is that this is the value that will |
65 // be shown. Users dislike 0-based counting. | 66 // be shown. Users dislike 0-based counting. |
66 scoped_refptr<PrintedPage> page( | 67 scoped_refptr<PrintedPage> page( |
67 new PrintedPage(page_number + 1, | 68 new PrintedPage(page_number + 1, |
68 emf, immutable_.settings_.page_setup_pixels().physical_size())); | 69 metafile, immutable_.settings_.page_setup_pixels().physical_size())); |
69 { | 70 { |
70 AutoLock lock(lock_); | 71 AutoLock lock(lock_); |
71 mutable_.pages_[page_number] = page; | 72 mutable_.pages_[page_number] = page; |
72 if (mutable_.shrink_factor == 0) { | 73 if (mutable_.shrink_factor == 0) { |
73 mutable_.shrink_factor = shrink; | 74 mutable_.shrink_factor = shrink; |
74 } else { | 75 } else { |
75 DCHECK_EQ(mutable_.shrink_factor, shrink); | 76 DCHECK_EQ(mutable_.shrink_factor, shrink); |
76 } | 77 } |
77 } | 78 } |
78 DebugDump(*page); | 79 DebugDump(*page); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 XFORM xform = { 0 }; | 117 XFORM xform = { 0 }; |
117 xform.eDx = static_cast<float>( | 118 xform.eDx = static_cast<float>( |
118 immutable_.settings_.page_setup_pixels().content_area().x()); | 119 immutable_.settings_.page_setup_pixels().content_area().x()); |
119 xform.eDy = static_cast<float>( | 120 xform.eDy = static_cast<float>( |
120 immutable_.settings_.page_setup_pixels().content_area().y()); | 121 immutable_.settings_.page_setup_pixels().content_area().y()); |
121 xform.eM11 = static_cast<float>(1. / mutable_.shrink_factor); | 122 xform.eM11 = static_cast<float>(1. / mutable_.shrink_factor); |
122 xform.eM22 = static_cast<float>(1. / mutable_.shrink_factor); | 123 xform.eM22 = static_cast<float>(1. / mutable_.shrink_factor); |
123 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY); | 124 BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY); |
124 DCHECK_NE(res, 0); | 125 DCHECK_NE(res, 0); |
125 | 126 |
126 if (!page.emf()->SafePlayback(context)) { | 127 if (!page.native_metafile()->SafePlayback(context)) { |
127 NOTREACHED(); | 128 NOTREACHED(); |
128 } | 129 } |
129 | 130 |
130 res = RestoreDC(context, saved_state); | 131 res = RestoreDC(context, saved_state); |
131 DCHECK_NE(res, 0); | 132 DCHECK_NE(res, 0); |
132 } | 133 } |
133 | 134 |
134 // Print the header and footer. | 135 // Print the header and footer. |
135 int base_font_size = gfx::Font().height(); | 136 int base_font_size = gfx::Font().height(); |
136 int new_font_size = ConvertUnit(10, | 137 int new_font_size = ConvertUnit(10, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 bool PrintedDocument::IsComplete() const { | 170 bool PrintedDocument::IsComplete() const { |
170 AutoLock lock(lock_); | 171 AutoLock lock(lock_); |
171 if (!mutable_.page_count_) | 172 if (!mutable_.page_count_) |
172 return false; | 173 return false; |
173 PageNumber page(immutable_.settings_, mutable_.page_count_); | 174 PageNumber page(immutable_.settings_, mutable_.page_count_); |
174 if (page == PageNumber::npos()) | 175 if (page == PageNumber::npos()) |
175 return false; | 176 return false; |
176 for (; page != PageNumber::npos(); ++page) { | 177 for (; page != PageNumber::npos(); ++page) { |
177 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); | 178 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); |
178 if (itr == mutable_.pages_.end() || !itr->second.get() || | 179 if (itr == mutable_.pages_.end() || !itr->second.get() || |
179 !itr->second->emf()) | 180 !itr->second->native_metafile()) |
180 return false; | 181 return false; |
181 } | 182 } |
182 return true; | 183 return true; |
183 } | 184 } |
184 | 185 |
185 void PrintedDocument::DisconnectSource() { | 186 void PrintedDocument::DisconnectSource() { |
186 AutoLock lock(lock_); | 187 AutoLock lock(lock_); |
187 mutable_.source_ = NULL; | 188 mutable_.source_ = NULL; |
188 } | 189 } |
189 | 190 |
190 size_t PrintedDocument::MemoryUsage() const { | 191 size_t PrintedDocument::MemoryUsage() const { |
191 std::vector<scoped_refptr<PrintedPage>> pages_copy; | 192 std::vector<scoped_refptr<PrintedPage>> pages_copy; |
192 { | 193 { |
193 AutoLock lock(lock_); | 194 AutoLock lock(lock_); |
194 pages_copy.reserve(mutable_.pages_.size()); | 195 pages_copy.reserve(mutable_.pages_.size()); |
195 PrintedPages::const_iterator end = mutable_.pages_.end(); | 196 PrintedPages::const_iterator end = mutable_.pages_.end(); |
196 for (PrintedPages::const_iterator itr = mutable_.pages_.begin(); | 197 for (PrintedPages::const_iterator itr = mutable_.pages_.begin(); |
197 itr != end; ++itr) { | 198 itr != end; ++itr) { |
198 if (itr->second.get()) { | 199 if (itr->second.get()) { |
199 pages_copy.push_back(itr->second); | 200 pages_copy.push_back(itr->second); |
200 } | 201 } |
201 } | 202 } |
202 } | 203 } |
203 size_t total = 0; | 204 size_t total = 0; |
204 for (size_t i = 0; i < pages_copy.size(); ++i) { | 205 for (size_t i = 0; i < pages_copy.size(); ++i) { |
205 total += pages_copy[i]->emf()->GetDataSize(); | 206 total += pages_copy[i]->native_metafile()->GetDataSize(); |
206 } | 207 } |
207 return total; | 208 return total; |
208 } | 209 } |
209 | 210 |
210 void PrintedDocument::set_page_count(int max_page) { | 211 void PrintedDocument::set_page_count(int max_page) { |
211 AutoLock lock(lock_); | 212 AutoLock lock(lock_); |
212 DCHECK_EQ(0, mutable_.page_count_); | 213 DCHECK_EQ(0, mutable_.page_count_); |
213 mutable_.page_count_ = max_page; | 214 mutable_.page_count_ = max_page; |
214 if (immutable_.settings_.ranges.empty()) { | 215 if (immutable_.settings_.ranges.empty()) { |
215 mutable_.expected_page_count_ = max_page; | 216 mutable_.expected_page_count_ = max_page; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 filename += L"_"; | 315 filename += L"_"; |
315 filename += time(); | 316 filename += time(); |
316 filename += L"_"; | 317 filename += L"_"; |
317 filename += name(); | 318 filename += name(); |
318 filename += L"_"; | 319 filename += L"_"; |
319 filename += StringPrintf(L"%02d", page.page_number()); | 320 filename += StringPrintf(L"%02d", page.page_number()); |
320 filename += L"_.emf"; | 321 filename += L"_.emf"; |
321 file_util::ReplaceIllegalCharacters(&filename, '_'); | 322 file_util::ReplaceIllegalCharacters(&filename, '_'); |
322 std::wstring path(g_debug_dump_info->debug_dump_path); | 323 std::wstring path(g_debug_dump_info->debug_dump_path); |
323 file_util::AppendToPath(&path, filename); | 324 file_util::AppendToPath(&path, filename); |
324 page.emf()->SaveTo(path); | 325 page.native_metafile()->SaveTo(path); |
325 } | 326 } |
326 | 327 |
327 void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) { | 328 void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) { |
328 g_debug_dump_info->enabled = !debug_dump_path.empty(); | 329 g_debug_dump_info->enabled = !debug_dump_path.empty(); |
329 g_debug_dump_info->debug_dump_path = debug_dump_path; | 330 g_debug_dump_info->debug_dump_path = debug_dump_path; |
330 } | 331 } |
331 | 332 |
332 const std::wstring& PrintedDocument::debug_dump_path() { | 333 const std::wstring& PrintedDocument::debug_dump_path() { |
333 return g_debug_dump_info->debug_dump_path; | 334 return g_debug_dump_info->debug_dump_path; |
334 } | 335 } |
(...skipping 21 matching lines...) Expand all Loading... |
356 date_ = win_util::FormatSystemDate(systemtime, std::wstring()); | 357 date_ = win_util::FormatSystemDate(systemtime, std::wstring()); |
357 time_ = win_util::FormatSystemTime(systemtime, std::wstring()); | 358 time_ = win_util::FormatSystemTime(systemtime, std::wstring()); |
358 #else | 359 #else |
359 Time now = Time::Now(); | 360 Time now = Time::Now(); |
360 date_ = TimeFormat::ShortDateNumeric(now); | 361 date_ = TimeFormat::ShortDateNumeric(now); |
361 time_ = TimeFormat::TimeOfDay(now); | 362 time_ = TimeFormat::TimeOfDay(now); |
362 #endif // WIN32 | 363 #endif // WIN32 |
363 } | 364 } |
364 | 365 |
365 } // namespace printing | 366 } // namespace printing |
OLD | NEW |