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

Side by Side 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: Fix grammar in comments Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
25 26
27 // Constants for setting default PDF settings.
28 const int kPDFDpi = 300; // 300 dpi
29 // LETTER: 8.5 x 11 inches
30 const int kPDFLetterWidth = 8.5 * kPDFDpi;
31 const int kPDFLetterHeight = 11 * kPDFDpi;
32 // LEGAL: 8.5 x 14 inches
33 const int kPDFLegalWidth = 8.5 * kPDFDpi;
34 const int kPDFLegalHeight = 14 * kPDFDpi;
35 // A4: 8.27 x 11.69 inches
36 const int kPDFA4Width = 8.27 * kPDFDpi;
37 const int kPDFA4Height = 11.69 * kPDFDpi;
38 // A3: 11.69 x 16.54 inches
39 const int kPDFA3Width = 11.69 * kPDFDpi;
40 const int kPDFA3Height = 16.54 * kPDFDpi;
41
26 // Retrieves the printer's PRINTER_INFO_* structure. 42 // Retrieves the printer's PRINTER_INFO_* structure.
27 // Output |level| can be 9 (user-default), 8 (admin-default), or 2 43 // Output |level| can be 9 (user-default), 8 (admin-default), or 2
28 // (printer-default). 44 // (printer-default).
29 // |devmode| is a pointer points to the start of DEVMODE structure in 45 // |devmode| is a pointer points to the start of DEVMODE structure in
30 // |buffer|. 46 // |buffer|.
31 bool GetPrinterInfo(HANDLE printer, 47 bool GetPrinterInfo(HANDLE printer,
32 const std::wstring &device_name, 48 const std::wstring &device_name,
33 int* level, 49 int* level,
34 scoped_array<uint8>* buffer, 50 scoped_array<uint8>* buffer,
35 DEVMODE** dev_mode) { 51 DEVMODE** dev_mode) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || 340 !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) ||
325 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || 341 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) ||
326 !job_settings.GetInteger(kSettingCopies, &copies) || 342 !job_settings.GetInteger(kSettingCopies, &copies) ||
327 !job_settings.GetString(kSettingDeviceName, &device_name)) { 343 !job_settings.GetString(kSettingDeviceName, &device_name)) {
328 return OnError(); 344 return OnError();
329 } 345 }
330 346
331 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); 347 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId);
332 348
333 if (print_to_pdf || print_to_cloud) { 349 if (print_to_pdf || print_to_cloud) {
334 // Pseudo printer: handle orientation and ranges only. 350 // Default fallback to Letter size.
351 gfx::Size paper_size;
352 gfx::Rect paper_rect;
353 paper_size.SetSize(kPDFLetterWidth, kPDFLetterHeight);
354
355 // Get settings from locale. Paper type buffer length is at most 4.
356 const int paper_type_buffer_len = 4;
357 wchar_t paper_type_buffer[paper_type_buffer_len] = {0};
358 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer,
359 paper_type_buffer_len);
360 if (wcslen(paper_type_buffer)) { // The call succeeded.
361 int paper_code = _wtoi(paper_type_buffer);
362 switch (paper_code) {
363 case DMPAPER_LEGAL:
364 paper_size.SetSize(kPDFLegalWidth, kPDFLegalHeight);
365 break;
366 case DMPAPER_A4:
367 paper_size.SetSize(kPDFA4Width, kPDFA4Height);
368 break;
369 case DMPAPER_A3:
370 paper_size.SetSize(kPDFA3Width, kPDFA3Height);
371 break;
372 default: // DMPAPER_LETTER is used for default fallback.
373 break;
374 }
375 }
376 paper_rect.SetRect(0, 0, paper_size.width(), paper_size.height());
377 settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi);
378 settings_.set_dpi(kPDFDpi);
335 settings_.SetOrientation(landscape); 379 settings_.SetOrientation(landscape);
336 settings_.ranges = ranges; 380 settings_.ranges = ranges;
337 return OK; 381 return OK;
338 } 382 }
339 383
340 // Underlying |settings_| do not have these attributes, so we need to 384 // Underlying |settings_| do not have these attributes, so we need to
341 // operate on printer directly, which involves reloading settings. 385 // operate on printer directly, which involves reloading settings.
342 // Therefore, reset the settings anyway. 386 // Therefore, reset the settings anyway.
343 ResetSettings(); 387 ResetSettings();
344 388
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (buf_size) { 809 if (buf_size) {
766 buffer->reset(new uint8[buf_size]); 810 buffer->reset(new uint8[buf_size]);
767 memset(buffer->get(), 0, buf_size); 811 memset(buffer->get(), 0, buf_size);
768 if (!GetPrinter(printer, level, buffer->get(), buf_size, &buf_size)) { 812 if (!GetPrinter(printer, level, buffer->get(), buf_size, &buf_size)) {
769 buffer->reset(); 813 buffer->reset();
770 } 814 }
771 } 815 }
772 } 816 }
773 817
774 } // namespace printing 818 } // namespace printing
OLDNEW
« 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