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.h" | 5 #include "printing/printing_context.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "printing/page_setup.h" | 9 #include "printing/page_setup.h" |
10 #include "printing/page_size_margins.h" | 10 #include "printing/page_size_margins.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 in_print_job_ = false; | 41 in_print_job_ = false; |
42 dialog_box_dismissed_ = false; | 42 dialog_box_dismissed_ = false; |
43 abort_printing_ = false; | 43 abort_printing_ = false; |
44 } | 44 } |
45 | 45 |
46 PrintingContext::Result PrintingContext::OnError() { | 46 PrintingContext::Result PrintingContext::OnError() { |
47 ResetSettings(); | 47 ResetSettings(); |
48 return abort_printing_ ? CANCEL : FAILED; | 48 return abort_printing_ ? CANCEL : FAILED; |
49 } | 49 } |
50 | 50 |
51 PrintingContext::Result PrintingContext::UsePdfSettings() { | |
52 scoped_ptr<base::DictionaryValue> pdf_settings(new base::DictionaryValue); | |
53 pdf_settings->SetBoolean(kSettingHeaderFooterEnabled, false); | |
54 pdf_settings->SetBoolean(kSettingShouldPrintBackgrounds, false); | |
55 pdf_settings->SetBoolean(kSettingShouldPrintSelectionOnly, false); | |
56 pdf_settings->SetInteger(kSettingMarginsType, printing::NO_MARGINS); | |
57 pdf_settings->SetBoolean(kSettingCollate, true); | |
58 pdf_settings->SetInteger(kSettingCopies, 1); | |
59 pdf_settings->SetInteger(kSettingColor, printing::COLOR); | |
60 pdf_settings->SetInteger(kSettingDuplexMode, printing::SIMPLEX); | |
61 pdf_settings->SetBoolean(kSettingLandscape, false); | |
62 pdf_settings->SetString(kSettingDeviceName, ""); | |
63 pdf_settings->SetBoolean(kSettingPrintToPDF, true); | |
64 pdf_settings->SetBoolean(kSettingCloudPrintDialog, false); | |
65 pdf_settings->SetBoolean(kSettingPrintWithPrivet, false); | |
66 return UpdatePrintSettings(*pdf_settings, PageRanges()); | |
67 } | |
68 | |
51 PrintingContext::Result PrintingContext::UpdatePrintSettings( | 69 PrintingContext::Result PrintingContext::UpdatePrintSettings( |
52 const base::DictionaryValue& job_settings, | 70 const base::DictionaryValue& job_settings, |
53 const PageRanges& ranges) { | 71 const PageRanges& ranges) { |
54 ResetSettings(); | 72 ResetSettings(); |
55 | 73 |
56 if (!PrintSettingsInitializer::InitSettings(job_settings, ranges, | 74 if (!PrintSettingsInitializer::InitSettings(job_settings, ranges, |
57 &settings_)) { | 75 &settings_)) { |
58 NOTREACHED(); | 76 NOTREACHED(); |
59 return OnError(); | 77 return OnError(); |
60 } | 78 } |
(...skipping 17 matching lines...) Expand all Loading... | |
78 is_cloud_dialog || print_with_privet)) { | 96 is_cloud_dialog || print_with_privet)) { |
79 settings_.set_dpi(kDefaultPdfDpi); | 97 settings_.set_dpi(kDefaultPdfDpi); |
80 gfx::Size paper_size(GetPdfPaperSizeDeviceUnits()); | 98 gfx::Size paper_size(GetPdfPaperSizeDeviceUnits()); |
81 const base::DictionaryValue* media_size = NULL; | 99 const base::DictionaryValue* media_size = NULL; |
82 if (job_settings.GetDictionary(kSettingMediaSize, &media_size)) { | 100 if (job_settings.GetDictionary(kSettingMediaSize, &media_size)) { |
83 int width_microns = 0; | 101 int width_microns = 0; |
84 int height_microns = 0; | 102 int height_microns = 0; |
85 if (media_size->GetInteger(kSettingMediaSizeWidthMicrons, | 103 if (media_size->GetInteger(kSettingMediaSizeWidthMicrons, |
86 &width_microns) && | 104 &width_microns) && |
87 media_size->GetInteger(kSettingMediaSizeHeightMicrons, | 105 media_size->GetInteger(kSettingMediaSizeHeightMicrons, |
88 &height_microns)) { | 106 &height_microns) && |
107 settings_.device_units_per_inch() > 0) { | |
Vitaly Buka (NO REVIEWS)
2014/05/22 01:11:21
?
Aleksey Shlyapnikov
2014/05/22 03:51:18
Done.
| |
89 float deviceMicronsPerDeviceUnit = | 108 float deviceMicronsPerDeviceUnit = |
90 (kHundrethsMMPerInch * 10.0f) / settings_.device_units_per_inch(); | 109 (kHundrethsMMPerInch * 10.0f) / settings_.device_units_per_inch(); |
91 paper_size = gfx::Size(width_microns / deviceMicronsPerDeviceUnit, | 110 paper_size = gfx::Size(width_microns / deviceMicronsPerDeviceUnit, |
92 height_microns / deviceMicronsPerDeviceUnit); | 111 height_microns / deviceMicronsPerDeviceUnit); |
93 } | 112 } |
94 } | 113 } |
95 gfx::Rect paper_rect(0, 0, paper_size.width(), paper_size.height()); | 114 gfx::Rect paper_rect(0, 0, paper_size.width(), paper_size.height()); |
96 if (print_to_cloud || print_with_privet) { | 115 if (print_to_cloud || print_with_privet) { |
97 paper_rect.Inset( | 116 paper_rect.Inset( |
98 kCloudPrintMarginInch * settings_.device_units_per_inch(), | 117 kCloudPrintMarginInch * settings_.device_units_per_inch(), |
99 kCloudPrintMarginInch * settings_.device_units_per_inch()); | 118 kCloudPrintMarginInch * settings_.device_units_per_inch()); |
100 } | 119 } |
101 settings_.SetPrinterPrintableArea(paper_size, paper_rect, true); | 120 settings_.SetPrinterPrintableArea(paper_size, paper_rect, true); |
102 return OK; | 121 return OK; |
103 } | 122 } |
104 | 123 |
105 return UpdatePrinterSettings(open_in_external_preview); | 124 return UpdatePrinterSettings(open_in_external_preview); |
106 } | 125 } |
107 | 126 |
108 } // namespace printing | 127 } // namespace printing |
OLD | NEW |