Chromium Code Reviews| Index: printing/printing_context_win.cc |
| diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc |
| index c467457eef77b54e5de48ee4a80198a0c08637b8..b3c68024e913a9ee9d8e7c838db265be4b4d6039 100644 |
| --- a/printing/printing_context_win.cc |
| +++ b/printing/printing_context_win.cc |
| @@ -17,11 +17,26 @@ |
| #include "printing/print_job_constants.h" |
| #include "printing/print_settings_initializer_win.h" |
| #include "printing/printed_document.h" |
| +#include "printing/units.h" |
| #include "skia/ext/platform_device.h" |
| using base::Time; |
| namespace { |
| +// 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.
|
| +const int kPDFDpi = 300; // 300 dpi |
| +// LETTER: 8.5 x 11 inches |
| +const int kPDFLetterWidth = 8.5 * kPDFDpi; |
| +const int kPDFLetterHeight = 11 * kPDFDpi; |
| +// LEGAL: 8.5 x 14 inches |
| +const int kPDFLegalWidth = 8.5 * kPDFDpi; |
| +const int kPDFLegalHeight = 11 * kPDFDpi; |
| +// A4: 8.27 x 11.69 inches |
| +const int kPDFA4Width = 8.27 * kPDFDpi; |
| +const int kPDFA4Height = 11.69 * kPDFDpi; |
| +// A3: 11.69 x 16.54 inches |
| +const int kPDFA3Width = 11.69 * kPDFDpi; |
| +const int kPDFA3Height = 16.54 * kPDFDpi; |
| // Retrieves the printer's PRINTER_INFO_* structure. |
| // Output |level| can be 9 (user-default), 8 (admin-default), or 2 |
| @@ -331,6 +346,44 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings( |
| bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); |
| if (print_to_pdf || print_to_cloud) { |
| + // If the |settings_| is empty, update it with default pdf settings. |
| + if (settings_.page_setup_device_units().printable_area().IsEmpty()) { |
| + // Paper size length at most 4. |
| + 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.
|
| + 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.
|
| + if (wcslen(paper_buffer)) { // The call succeeded. |
| + int paper_code = _wtoi(paper_buffer); |
| + gfx::Size paper_size; |
| + gfx::Rect paper_rect; |
| + switch (paper_code) { |
| + case DMPAPER_LETTER: |
| + paper_size.SetSize(kPDFLetterWidth, kPDFLetterHeight); |
| + paper_rect.SetRect(0, 0, kPDFLetterWidth, kPDFLetterHeight); |
| + break; |
| + case DMPAPER_LEGAL: |
| + paper_size.SetSize(kPDFLegalWidth, kPDFLegalHeight); |
| + paper_rect.SetRect(0, 0, kPDFLegalWidth, kPDFLegalHeight); |
| + break; |
| + case DMPAPER_A4: |
| + paper_size.SetSize(kPDFA4Width, kPDFA4Height); |
| + paper_rect.SetRect(0, 0, kPDFA4Width, kPDFA4Height); |
| + break; |
| + case DMPAPER_A3: |
| + paper_size.SetSize(kPDFA3Width, kPDFA3Height); |
| + paper_rect.SetRect(0, 0, kPDFA3Width, kPDFA3Height); |
| + break; |
| + default: |
| + // Invalid size, Windows only returns the sizes above. |
| + DCHECK(false); |
| + break; |
| + } |
| + if (!paper_size.IsEmpty() && !paper_rect.IsEmpty()) { |
| + settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi); |
| + settings_.set_dpi(kPDFDpi); |
| + } |
|
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
|
| + } |
| + } |
| + |
| // Pseudo printer: handle orientation and ranges only. |
| settings_.SetOrientation(landscape); |
| settings_.ranges = ranges; |