OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #if defined(USE_AURA) | 29 #if defined(USE_AURA) |
30 #include "ui/aura/remote_root_window_host_win.h" | 30 #include "ui/aura/remote_root_window_host_win.h" |
31 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
32 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
33 #endif | 33 #endif |
34 | 34 |
35 using base::Time; | 35 using base::Time; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Constants for setting default PDF settings. | |
40 const int kPDFDpi = 300; // 300 dpi | |
41 // LETTER: 8.5 x 11 inches | |
42 const int kPDFLetterWidth = 8.5 * kPDFDpi; | |
43 const int kPDFLetterHeight = 11 * kPDFDpi; | |
44 // LEGAL: 8.5 x 14 inches | |
45 const int kPDFLegalWidth = 8.5 * kPDFDpi; | |
46 const int kPDFLegalHeight = 14 * kPDFDpi; | |
47 // A4: 8.27 x 11.69 inches | |
48 const int kPDFA4Width = 8.27 * kPDFDpi; | |
49 const int kPDFA4Height = 11.69 * kPDFDpi; | |
50 // A3: 11.69 x 16.54 inches | |
51 const int kPDFA3Width = 11.69 * kPDFDpi; | |
52 const int kPDFA3Height = 16.54 * kPDFDpi; | |
53 | |
54 HWND GetRootWindow(gfx::NativeView view) { | 39 HWND GetRootWindow(gfx::NativeView view) { |
55 HWND window = NULL; | 40 HWND window = NULL; |
56 #if defined(USE_AURA) | 41 #if defined(USE_AURA) |
57 if (view) | 42 if (view) |
58 window = view->GetDispatcher()->GetAcceleratedWidget(); | 43 window = view->GetDispatcher()->GetAcceleratedWidget(); |
59 #else | 44 #else |
60 if (view && IsWindow(view)) { | 45 if (view && IsWindow(view)) { |
61 window = GetAncestor(view, GA_ROOTOWNER); | 46 window = GetAncestor(view, GA_ROOTOWNER); |
62 } | 47 } |
63 #endif | 48 #endif |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 } | 285 } |
301 if (context_) | 286 if (context_) |
302 return OK; | 287 return OK; |
303 } | 288 } |
304 } | 289 } |
305 | 290 |
306 ResetSettings(); | 291 ResetSettings(); |
307 return FAILED; | 292 return FAILED; |
308 } | 293 } |
309 | 294 |
295 gfx::Size PrintingContextWin::GetPdfPaperSizeDeviceUnits() { | |
296 // Default fallback to Letter size. | |
297 gfx::SizeF paper_size; | |
298 paper_size.SetSize(kLetterWidthInch, kLetterHeightInch); | |
Lei Zhang
2013/11/01 18:27:13
nit: can't you just do this in the SizeF ctor?
Vitaly Buka (NO REVIEWS)
2013/11/01 19:46:29
Done.
| |
299 | |
300 // Get settings from locale. Paper type buffer length is at most 4. | |
301 const int paper_type_buffer_len = 4; | |
302 wchar_t paper_type_buffer[paper_type_buffer_len] = {0}; | |
303 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer, | |
304 paper_type_buffer_len); | |
305 if (wcslen(paper_type_buffer)) { // The call succeeded. | |
306 int paper_code = _wtoi(paper_type_buffer); | |
307 switch (paper_code) { | |
308 case DMPAPER_LEGAL: | |
309 paper_size.SetSize(kLegalWidthInch, kLegalHeightInch); | |
310 break; | |
311 case DMPAPER_A4: | |
312 paper_size.SetSize(kA4WidthInch, kA4HeightInch); | |
313 break; | |
314 case DMPAPER_A3: | |
315 paper_size.SetSize(kA3WidthInch, kA3HeightInch); | |
316 break; | |
317 default: // DMPAPER_LETTER is used for default fallback. | |
318 break; | |
319 } | |
320 } | |
321 return gfx::Size( | |
322 paper_size.width() * settings_.device_units_per_inch(), | |
323 paper_size.height() * settings_.device_units_per_inch()); | |
324 } | |
325 | |
310 PrintingContext::Result PrintingContextWin::UpdatePrinterSettings( | 326 PrintingContext::Result PrintingContextWin::UpdatePrinterSettings( |
311 bool target_is_pdf, | |
312 bool external_preview) { | 327 bool external_preview) { |
313 DCHECK(!in_print_job_); | 328 DCHECK(!in_print_job_); |
314 DCHECK(!external_preview) << "Not implemented"; | 329 DCHECK(!external_preview) << "Not implemented"; |
315 | 330 |
316 if (target_is_pdf) { | |
317 // Default fallback to Letter size. | |
318 gfx::Size paper_size; | |
319 gfx::Rect paper_rect; | |
320 paper_size.SetSize(kPDFLetterWidth, kPDFLetterHeight); | |
321 | |
322 // Get settings from locale. Paper type buffer length is at most 4. | |
323 const int paper_type_buffer_len = 4; | |
324 wchar_t paper_type_buffer[paper_type_buffer_len] = {0}; | |
325 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer, | |
326 paper_type_buffer_len); | |
327 if (wcslen(paper_type_buffer)) { // The call succeeded. | |
328 int paper_code = _wtoi(paper_type_buffer); | |
329 switch (paper_code) { | |
330 case DMPAPER_LEGAL: | |
331 paper_size.SetSize(kPDFLegalWidth, kPDFLegalHeight); | |
332 break; | |
333 case DMPAPER_A4: | |
334 paper_size.SetSize(kPDFA4Width, kPDFA4Height); | |
335 break; | |
336 case DMPAPER_A3: | |
337 paper_size.SetSize(kPDFA3Width, kPDFA3Height); | |
338 break; | |
339 default: // DMPAPER_LETTER is used for default fallback. | |
340 break; | |
341 } | |
342 } | |
343 paper_rect.SetRect(0, 0, paper_size.width(), paper_size.height()); | |
344 settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi, true); | |
345 settings_.set_dpi(kPDFDpi); | |
346 return OK; | |
347 } | |
348 | |
349 ScopedPrinterHandle printer; | 331 ScopedPrinterHandle printer; |
350 LPWSTR device_name_wide = | 332 LPWSTR device_name_wide = |
351 const_cast<wchar_t*>(settings_.device_name().c_str()); | 333 const_cast<wchar_t*>(settings_.device_name().c_str()); |
352 if (!printer.OpenPrinter(device_name_wide)) | 334 if (!printer.OpenPrinter(device_name_wide)) |
353 return OnError(); | 335 return OnError(); |
354 | 336 |
355 // Make printer changes local to Chrome. | 337 // Make printer changes local to Chrome. |
356 // See MSDN documentation regarding DocumentProperties. | 338 // See MSDN documentation regarding DocumentProperties. |
357 scoped_ptr<uint8[]> buffer; | 339 scoped_ptr<uint8[]> buffer; |
358 DEVMODE* dev_mode = NULL; | 340 DEVMODE* dev_mode = NULL; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 | 744 |
763 if (dialog_options.hDevMode != NULL) | 745 if (dialog_options.hDevMode != NULL) |
764 GlobalFree(dialog_options.hDevMode); | 746 GlobalFree(dialog_options.hDevMode); |
765 if (dialog_options.hDevNames != NULL) | 747 if (dialog_options.hDevNames != NULL) |
766 GlobalFree(dialog_options.hDevNames); | 748 GlobalFree(dialog_options.hDevNames); |
767 | 749 |
768 return context_ ? OK : FAILED; | 750 return context_ ? OK : FAILED; |
769 } | 751 } |
770 | 752 |
771 } // namespace printing | 753 } // namespace printing |
OLD | NEW |