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 { |
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 Loading... | |
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 paper_rect.SetRect(0, 0, kPDFLetterWidth, kPDFLetterHeight); | |
355 settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi); | |
kmadhusu
2011/09/28 17:16:10
You want to call SetPrinterPrintableArea() after l
arthurhsu
2011/09/28 17:57:39
Done.
| |
356 settings_.set_dpi(kPDFDpi); | |
357 | |
358 // Get settings from locale. Paper size length at most 4. | |
kmadhusu
2011/09/28 17:16:10
Paper size length is ambiguous. How about "default
arthurhsu
2011/09/28 17:57:39
paper_type_buffer_len is used instead.
| |
359 const int paper_type_count = 4; | |
360 wchar_t paper_type_buffer[paper_type_count] = {0}; | |
361 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer, | |
362 paper_type_count); | |
363 if (wcslen(paper_type_buffer)) { // The call succeeded. | |
364 int paper_code = _wtoi(paper_type_buffer); | |
365 switch (paper_code) { | |
366 case DMPAPER_LEGAL: | |
367 paper_size.SetSize(kPDFLegalWidth, kPDFLegalHeight); | |
368 paper_rect.SetRect(0, 0, kPDFLegalWidth, kPDFLegalHeight); | |
kmadhusu
2011/09/28 17:16:10
You can just do the following once rather than cal
arthurhsu
2011/09/28 17:57:39
Done.
| |
369 break; | |
370 case DMPAPER_A4: | |
371 paper_size.SetSize(kPDFA4Width, kPDFA4Height); | |
372 paper_rect.SetRect(0, 0, kPDFA4Width, kPDFA4Height); | |
373 break; | |
374 case DMPAPER_A3: | |
375 paper_size.SetSize(kPDFA3Width, kPDFA3Height); | |
376 paper_rect.SetRect(0, 0, kPDFA3Width, kPDFA3Height); | |
377 break; | |
378 default: // DMPAPER_LETTER is used for default fallback. | |
379 break; | |
380 } | |
381 } | |
335 settings_.SetOrientation(landscape); | 382 settings_.SetOrientation(landscape); |
336 settings_.ranges = ranges; | 383 settings_.ranges = ranges; |
337 return OK; | 384 return OK; |
338 } | 385 } |
339 | 386 |
340 // Underlying |settings_| do not have these attributes, so we need to | 387 // Underlying |settings_| do not have these attributes, so we need to |
341 // operate on printer directly, which involves reloading settings. | 388 // operate on printer directly, which involves reloading settings. |
342 // Therefore, reset the settings anyway. | 389 // Therefore, reset the settings anyway. |
343 ResetSettings(); | 390 ResetSettings(); |
344 | 391 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 if (buf_size) { | 812 if (buf_size) { |
766 buffer->reset(new uint8[buf_size]); | 813 buffer->reset(new uint8[buf_size]); |
767 memset(buffer->get(), 0, buf_size); | 814 memset(buffer->get(), 0, buf_size); |
768 if (!GetPrinter(printer, level, buffer->get(), buf_size, &buf_size)) { | 815 if (!GetPrinter(printer, level, buffer->get(), buf_size, &buf_size)) { |
769 buffer->reset(); | 816 buffer->reset(); |
770 } | 817 } |
771 } | 818 } |
772 } | 819 } |
773 | 820 |
774 } // namespace printing | 821 } // namespace printing |
OLD | NEW |