| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/text_elider.h" | 12 #include "app/text_elider.h" |
| 13 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 14 #include "base/i18n/file_util_icu.h" | 15 #include "base/i18n/file_util_icu.h" |
| 15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 16 #include "base/singleton.h" | 17 #include "base/singleton.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 #include "base/time.h" | 20 #include "base/time.h" |
| 20 #include "base/i18n/time_formatting.h" | 21 #include "base/i18n/time_formatting.h" |
| 21 #include "gfx/font.h" | 22 #include "gfx/font.h" |
| 22 #include "printing/page_number.h" | 23 #include "printing/page_number.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 using base::Time; | 34 using base::Time; |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 struct PrintDebugDumpPath { | 38 struct PrintDebugDumpPath { |
| 38 PrintDebugDumpPath() | 39 PrintDebugDumpPath() |
| 39 : enabled(false) { | 40 : enabled(false) { |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool enabled; | 43 bool enabled; |
| 43 std::wstring debug_dump_path; | 44 FilePath debug_dump_path; |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 Singleton<PrintDebugDumpPath> g_debug_dump_info; | 47 Singleton<PrintDebugDumpPath> g_debug_dump_info; |
| 47 | 48 |
| 48 } // namespace | 49 } // namespace |
| 49 | 50 |
| 50 namespace printing { | 51 namespace printing { |
| 51 | 52 |
| 52 PrintedDocument::PrintedDocument(const PrintSettings& settings, | 53 PrintedDocument::PrintedDocument(const PrintSettings& settings, |
| 53 PrintedPagesSource* source, | 54 PrintedPagesSource* source, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 DCHECK_NE(res, 0); | 263 DCHECK_NE(res, 0); |
| 263 #else // OS_WIN | 264 #else // OS_WIN |
| 264 NOTIMPLEMENTED(); | 265 NOTIMPLEMENTED(); |
| 265 #endif // OS_WIN | 266 #endif // OS_WIN |
| 266 } | 267 } |
| 267 | 268 |
| 268 void PrintedDocument::DebugDump(const PrintedPage& page) { | 269 void PrintedDocument::DebugDump(const PrintedPage& page) { |
| 269 if (!g_debug_dump_info->enabled) | 270 if (!g_debug_dump_info->enabled) |
| 270 return; | 271 return; |
| 271 | 272 |
| 272 std::wstring filename; | 273 string16 filename; |
| 273 filename += date(); | 274 filename += date(); |
| 274 filename += L"_"; | 275 filename += ASCIIToUTF16("_"); |
| 275 filename += time(); | 276 filename += time(); |
| 276 filename += L"_"; | 277 filename += ASCIIToUTF16("_"); |
| 277 filename += name(); | 278 filename += name(); |
| 278 filename += L"_"; | 279 filename += ASCIIToUTF16("_"); |
| 279 filename += StringPrintf(L"%02d", page.page_number()); | 280 filename += ASCIIToUTF16(StringPrintf("%02d", page.page_number())); |
| 280 filename += L"_.emf"; | 281 filename += ASCIIToUTF16("_.emf"); |
| 281 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
| 282 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); | 283 page.native_metafile()->SaveTo( |
| 283 #else | 284 g_debug_dump_info->debug_dump_path.Append(filename).ToWStringHack()); |
| 284 std::string narrow_filename = WideToUTF8(filename); | |
| 285 file_util::ReplaceIllegalCharactersInPath(&narrow_filename, '_'); | |
| 286 filename = UTF8ToWide(narrow_filename); | |
| 287 #endif | |
| 288 FilePath path = FilePath::FromWStringHack( | |
| 289 g_debug_dump_info->debug_dump_path); | |
| 290 #if defined(OS_WIN) | |
| 291 page.native_metafile()->SaveTo(path.Append(filename).ToWStringHack()); | |
| 292 #else // OS_WIN | 285 #else // OS_WIN |
| 293 NOTIMPLEMENTED(); | 286 NOTIMPLEMENTED(); |
| 294 #endif // OS_WIN | 287 #endif // OS_WIN |
| 295 } | 288 } |
| 296 | 289 |
| 297 void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) { | 290 void PrintedDocument::set_debug_dump_path(const FilePath& debug_dump_path) { |
| 298 g_debug_dump_info->enabled = !debug_dump_path.empty(); | 291 g_debug_dump_info->enabled = !debug_dump_path.empty(); |
| 299 g_debug_dump_info->debug_dump_path = debug_dump_path; | 292 g_debug_dump_info->debug_dump_path = debug_dump_path; |
| 300 } | 293 } |
| 301 | 294 |
| 302 const std::wstring& PrintedDocument::debug_dump_path() { | 295 const FilePath& PrintedDocument::debug_dump_path() { |
| 303 return g_debug_dump_info->debug_dump_path; | 296 return g_debug_dump_info->debug_dump_path; |
| 304 } | 297 } |
| 305 | 298 |
| 306 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) | 299 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) |
| 307 : source_(source), | 300 : source_(source), |
| 308 expected_page_count_(0), | 301 expected_page_count_(0), |
| 309 page_count_(0), | 302 page_count_(0), |
| 310 shrink_factor(0) { | 303 shrink_factor(0) { |
| 311 } | 304 } |
| 312 | 305 |
| 313 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, | 306 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, |
| 314 PrintedPagesSource* source, | 307 PrintedPagesSource* source, |
| 315 int cookie) | 308 int cookie) |
| 316 : settings_(settings), | 309 : settings_(settings), |
| 317 source_message_loop_(MessageLoop::current()), | 310 source_message_loop_(MessageLoop::current()), |
| 318 name_(source->RenderSourceName()), | 311 name_(source->RenderSourceName()), |
| 319 url_(source->RenderSourceUrl()), | 312 url_(source->RenderSourceUrl()), |
| 320 cookie_(cookie) { | 313 cookie_(cookie) { |
| 321 // Setup the document's date. | 314 // Setup the document's date. |
| 322 #if defined(OS_WIN) | 315 #if defined(OS_WIN) |
| 323 // On Windows, use the native time formatting for printing. | 316 // On Windows, use the native time formatting for printing. |
| 324 SYSTEMTIME systemtime; | 317 SYSTEMTIME systemtime; |
| 325 GetLocalTime(&systemtime); | 318 GetLocalTime(&systemtime); |
| 326 date_ = win_util::FormatSystemDate(systemtime, std::wstring()); | 319 date_ = |
| 327 time_ = win_util::FormatSystemTime(systemtime, std::wstring()); | 320 WideToUTF16Hack(win_util::FormatSystemDate(systemtime, std::wstring())); |
| 321 time_ = |
| 322 WideToUTF16Hack(win_util::FormatSystemTime(systemtime, std::wstring())); |
| 328 #else // OS_WIN | 323 #else // OS_WIN |
| 329 Time now = Time::Now(); | 324 Time now = Time::Now(); |
| 330 date_ = base::TimeFormatShortDateNumeric(now); | 325 date_ = WideToUTF16Hack(base::TimeFormatShortDateNumeric(now)); |
| 331 time_ = base::TimeFormatTimeOfDay(now); | 326 time_ = WideToUTF16Hack(base::TimeFormatTimeOfDay(now)); |
| 332 #endif // OS_WIN | 327 #endif // OS_WIN |
| 333 } | 328 } |
| 334 | 329 |
| 335 } // namespace printing | 330 } // namespace printing |
| OLD | NEW |