Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Unified Diff: printing/printing_context_win.cc

Issue 8044008: Gives default PDF settings when no printer is installed. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update per code review Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/printing_context_win.cc
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index c467457eef77b54e5de48ee4a80198a0c08637b8..1c5db97727c0c3058e74c435f619ab8f59eec817 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -17,12 +17,28 @@
#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.
+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;
kmadhusu 2011/09/28 00:58:29 Legal height is 14.
arthurhsu 2011/09/28 01:28:01 Done.
+// 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
// (printer-default).
@@ -331,6 +347,41 @@ 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()) {
kmadhusu 2011/09/28 00:58:29 (repeating our conversation for reference): This c
arthurhsu 2011/09/28 01:28:01 Done.
+ // Paper size length at most 4.
+ const int paper_type_count = 4;
+ wchar_t paper_type_buffer[paper_type_count] = {0};
+ GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer,
+ paper_type_count);
+ if (wcslen(paper_type_buffer)) { // The call succeeded.
+ int paper_code = _wtoi(paper_type_buffer);
+ gfx::Size paper_size;
+ gfx::Rect paper_rect;
+ switch (paper_code) {
+ 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: // DMPAPER_LETTER is used for default fallback.
+ // Windows will only return Letter, Legal, A4, and A3.
kmadhusu 2011/09/28 00:58:29 nit: This comment is not required.
arthurhsu 2011/09/28 01:28:01 Done.
+ paper_size.SetSize(kPDFLetterWidth, kPDFLetterHeight);
+ paper_rect.SetRect(0, 0, kPDFLetterWidth, kPDFLetterHeight);
+ break;
+ }
+ settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi);
+ settings_.set_dpi(kPDFDpi);
+ }
+ }
+
// Pseudo printer: handle orientation and ranges only.
settings_.SetOrientation(landscape);
settings_.ranges = ranges;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698