Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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/printing_context_win.h" | 5 #include "printing/printing_context_win.h" |
| 6 | 6 |
| 7 #include <winspool.h> | 7 #include <winspool.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/i18n/file_util_icu.h" | 11 #include "base/i18n/file_util_icu.h" |
| 12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "printing/print_job_constants.h" | 17 #include "printing/print_job_constants.h" |
| 18 #include "printing/print_settings_initializer_win.h" | 18 #include "printing/print_settings_initializer_win.h" |
| 19 #include "printing/printed_document.h" | 19 #include "printing/printed_document.h" |
| 20 #include "printing/units.h" | |
| 20 #include "skia/ext/platform_device.h" | 21 #include "skia/ext/platform_device.h" |
| 21 | 22 |
| 22 using base::Time; | 23 using base::Time; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 26 // Constants for setting default PDF settings. | |
|
kmadhusu
2011/09/27 20:28:53
nit: Add an empty line before this.
arthurhsu
2011/09/27 21:48:37
Done.
| |
| 27 const int kPDFDpi = 300; // 300 dpi | |
| 28 // LETTER: 8.5 x 11 inches | |
| 29 const int kPDFLetterWidth = 8.5 * kPDFDpi; | |
| 30 const int kPDFLetterHeight = 11 * kPDFDpi; | |
| 31 // LEGAL: 8.5 x 14 inches | |
| 32 const int kPDFLegalWidth = 8.5 * kPDFDpi; | |
| 33 const int kPDFLegalHeight = 11 * kPDFDpi; | |
| 34 // A4: 8.27 x 11.69 inches | |
| 35 const int kPDFA4Width = 8.27 * kPDFDpi; | |
| 36 const int kPDFA4Height = 11.69 * kPDFDpi; | |
| 37 // A3: 11.69 x 16.54 inches | |
| 38 const int kPDFA3Width = 11.69 * kPDFDpi; | |
| 39 const int kPDFA3Height = 16.54 * kPDFDpi; | |
| 25 | 40 |
| 26 // Retrieves the printer's PRINTER_INFO_* structure. | 41 // Retrieves the printer's PRINTER_INFO_* structure. |
| 27 // Output |level| can be 9 (user-default), 8 (admin-default), or 2 | 42 // Output |level| can be 9 (user-default), 8 (admin-default), or 2 |
| 28 // (printer-default). | 43 // (printer-default). |
| 29 // |devmode| is a pointer points to the start of DEVMODE structure in | 44 // |devmode| is a pointer points to the start of DEVMODE structure in |
| 30 // |buffer|. | 45 // |buffer|. |
| 31 bool GetPrinterInfo(HANDLE printer, | 46 bool GetPrinterInfo(HANDLE printer, |
| 32 const std::wstring &device_name, | 47 const std::wstring &device_name, |
| 33 int* level, | 48 int* level, |
| 34 scoped_array<uint8>* buffer, | 49 scoped_array<uint8>* buffer, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || | 339 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || |
| 325 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || | 340 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || |
| 326 !job_settings.GetInteger(kSettingCopies, &copies) || | 341 !job_settings.GetInteger(kSettingCopies, &copies) || |
| 327 !job_settings.GetString(kSettingDeviceName, &device_name)) { | 342 !job_settings.GetString(kSettingDeviceName, &device_name)) { |
| 328 return OnError(); | 343 return OnError(); |
| 329 } | 344 } |
| 330 | 345 |
| 331 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); | 346 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); |
| 332 | 347 |
| 333 if (print_to_pdf || print_to_cloud) { | 348 if (print_to_pdf || print_to_cloud) { |
| 349 // If the |settings_| is empty, update it with default pdf settings. | |
| 350 if (settings_.page_setup_device_units().printable_area().IsEmpty()) { | |
| 351 // Paper size length at most 4. | |
| 352 wchar_t paper_buffer[4] = {0}; | |
|
kmadhusu
2011/09/27 20:28:53
const int paper_type_count = 4;
wchar_t paper_buff
kmadhusu
2011/09/27 20:28:53
paper_buffer => paper_type_buffer
arthurhsu
2011/09/27 21:48:37
Done.
arthurhsu
2011/09/27 21:48:37
Done.
| |
| 353 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_buffer, 4); | |
|
kmadhusu
2011/09/27 20:28:53
Do we need to get LOCALE_SYSTEM_DEFAULT values if
kmadhusu
2011/09/27 20:28:53
4 => arraysize(paper_buffer);
arthurhsu
2011/09/27 21:48:37
No. That will cause UAC. If we can't, we can't.
arthurhsu
2011/09/27 21:48:37
I use the paper_type_count instead.
| |
| 354 if (wcslen(paper_buffer)) { // The call succeeded. | |
| 355 int paper_code = _wtoi(paper_buffer); | |
| 356 gfx::Size paper_size; | |
| 357 gfx::Rect paper_rect; | |
| 358 switch (paper_code) { | |
| 359 case DMPAPER_LETTER: | |
| 360 paper_size.SetSize(kPDFLetterWidth, kPDFLetterHeight); | |
| 361 paper_rect.SetRect(0, 0, kPDFLetterWidth, kPDFLetterHeight); | |
| 362 break; | |
| 363 case DMPAPER_LEGAL: | |
| 364 paper_size.SetSize(kPDFLegalWidth, kPDFLegalHeight); | |
| 365 paper_rect.SetRect(0, 0, kPDFLegalWidth, kPDFLegalHeight); | |
| 366 break; | |
| 367 case DMPAPER_A4: | |
| 368 paper_size.SetSize(kPDFA4Width, kPDFA4Height); | |
| 369 paper_rect.SetRect(0, 0, kPDFA4Width, kPDFA4Height); | |
| 370 break; | |
| 371 case DMPAPER_A3: | |
| 372 paper_size.SetSize(kPDFA3Width, kPDFA3Height); | |
| 373 paper_rect.SetRect(0, 0, kPDFA3Width, kPDFA3Height); | |
| 374 break; | |
| 375 default: | |
| 376 // Invalid size, Windows only returns the sizes above. | |
| 377 DCHECK(false); | |
| 378 break; | |
| 379 } | |
| 380 if (!paper_size.IsEmpty() && !paper_rect.IsEmpty()) { | |
| 381 settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi); | |
| 382 settings_.set_dpi(kPDFDpi); | |
| 383 } | |
|
kmadhusu
2011/09/27 20:28:53
else {
return OnError();
}
arthurhsu
2011/09/27 21:48:37
Based on our discussion, I use LETTER as the defau
| |
| 384 } | |
| 385 } | |
| 386 | |
| 334 // Pseudo printer: handle orientation and ranges only. | 387 // Pseudo printer: handle orientation and ranges only. |
| 335 settings_.SetOrientation(landscape); | 388 settings_.SetOrientation(landscape); |
| 336 settings_.ranges = ranges; | 389 settings_.ranges = ranges; |
| 337 return OK; | 390 return OK; |
| 338 } | 391 } |
| 339 | 392 |
| 340 // Underlying |settings_| do not have these attributes, so we need to | 393 // Underlying |settings_| do not have these attributes, so we need to |
| 341 // operate on printer directly, which involves reloading settings. | 394 // operate on printer directly, which involves reloading settings. |
| 342 // Therefore, reset the settings anyway. | 395 // Therefore, reset the settings anyway. |
| 343 ResetSettings(); | 396 ResetSettings(); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 if (buf_size) { | 818 if (buf_size) { |
| 766 buffer->reset(new uint8[buf_size]); | 819 buffer->reset(new uint8[buf_size]); |
| 767 memset(buffer->get(), 0, buf_size); | 820 memset(buffer->get(), 0, buf_size); |
| 768 if (!GetPrinter(printer, level, buffer->get(), buf_size, &buf_size)) { | 821 if (!GetPrinter(printer, level, buffer->get(), buf_size, &buf_size)) { |
| 769 buffer->reset(); | 822 buffer->reset(); |
| 770 } | 823 } |
| 771 } | 824 } |
| 772 } | 825 } |
| 773 | 826 |
| 774 } // namespace printing | 827 } // namespace printing |
| OLD | NEW |