OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/service/cloud_print/cdd_conversion_win.h" | 5 #include "chrome/service/cloud_print/cdd_conversion_win.h" |
6 | 6 |
7 #include "components/cloud_devices/common/printer_description.h" | 7 #include "components/cloud_devices/common/printer_description.h" |
8 #include "printing/backend/print_backend.h" | |
9 #include "printing/backend/win_helper.h" | 8 #include "printing/backend/win_helper.h" |
10 | 9 |
11 namespace cloud_print { | 10 namespace cloud_print { |
12 | 11 |
13 bool IsValidCjt(const std::string& print_ticket_data) { | 12 bool IsValidCjt(const std::string& print_ticket_data) { |
14 cloud_devices::CloudDeviceDescription description; | 13 cloud_devices::CloudDeviceDescription description; |
15 return description.InitFromString(print_ticket_data); | 14 return description.InitFromString(print_ticket_data); |
16 } | 15 } |
17 | 16 |
18 scoped_ptr<DEVMODE, base::FreeDeleter> CjtToDevMode( | 17 scoped_ptr<DEVMODE, base::FreeDeleter> CjtToDevMode( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 117 } |
119 if (height > 0) { | 118 if (height > 0) { |
120 dev_mode->dmFields |= DM_PAPERLENGTH; | 119 dev_mode->dmFields |= DM_PAPERLENGTH; |
121 dev_mode->dmPaperLength = height; | 120 dev_mode->dmPaperLength = height; |
122 } | 121 } |
123 } | 122 } |
124 | 123 |
125 return printing::CreateDevMode(printer, dev_mode.get()); | 124 return printing::CreateDevMode(printer, dev_mode.get()); |
126 } | 125 } |
127 | 126 |
128 std::string CapabilitiesToCdd( | |
129 const printing::PrinterSemanticCapsAndDefaults& semantic_info) { | |
130 using namespace cloud_devices::printer; | |
131 cloud_devices::CloudDeviceDescription description; | |
132 | |
133 ContentTypesCapability content_types; | |
134 content_types.AddOption("application/pdf"); | |
135 content_types.SaveTo(&description); | |
136 | |
137 ColorCapability color; | |
138 if (semantic_info.color_default || semantic_info.color_changeable) { | |
139 color.AddDefaultOption(Color(STANDARD_COLOR), semantic_info.color_default); | |
140 } | |
141 | |
142 if (!semantic_info.color_default || semantic_info.color_changeable) { | |
143 color.AddDefaultOption(Color(STANDARD_MONOCHROME), | |
144 !semantic_info.color_default); | |
145 } | |
146 color.SaveTo(&description); | |
147 | |
148 if (semantic_info.duplex_capable) { | |
149 DuplexCapability duplex; | |
150 duplex.AddDefaultOption( | |
151 NO_DUPLEX, semantic_info.duplex_default == printing::SIMPLEX); | |
152 duplex.AddDefaultOption( | |
153 LONG_EDGE, semantic_info.duplex_default == printing::LONG_EDGE); | |
154 duplex.AddDefaultOption( | |
155 SHORT_EDGE, semantic_info.duplex_default == printing::SHORT_EDGE); | |
156 duplex.SaveTo(&description); | |
157 } | |
158 | |
159 if (!semantic_info.papers.empty()) { | |
160 Media default_media(semantic_info.default_paper.name, | |
161 semantic_info.default_paper.size_um.width(), | |
162 semantic_info.default_paper.size_um.height()); | |
163 default_media.MatchBySize(); | |
164 | |
165 MediaCapability media; | |
166 bool is_default_set = false; | |
167 for (size_t i = 0; i < semantic_info.papers.size(); ++i) { | |
168 gfx::Size paper_size = semantic_info.papers[i].size_um; | |
169 if (paper_size.width() > paper_size.height()) | |
170 paper_size.SetSize(paper_size.height(), paper_size.width()); | |
171 Media new_media(semantic_info.papers[i].name, paper_size.width(), | |
172 paper_size.height()); | |
173 new_media.MatchBySize(); | |
174 if (new_media.IsValid() && !media.Contains(new_media)) { | |
175 if (!default_media.IsValid()) | |
176 default_media = new_media; | |
177 media.AddDefaultOption(new_media, new_media == default_media); | |
178 is_default_set = is_default_set || (new_media == default_media); | |
179 } | |
180 } | |
181 if (!is_default_set && default_media.IsValid()) | |
182 media.AddDefaultOption(default_media, true); | |
183 | |
184 if (media.IsValid()) { | |
185 media.SaveTo(&description); | |
186 } else { | |
187 NOTREACHED(); | |
188 } | |
189 } | |
190 | |
191 if (semantic_info.collate_capable) { | |
192 CollateCapability collate; | |
193 collate.set_default_value(semantic_info.collate_default); | |
194 collate.SaveTo(&description); | |
195 } | |
196 | |
197 if (semantic_info.copies_capable) { | |
198 CopiesCapability copies; | |
199 copies.SaveTo(&description); | |
200 } | |
201 | |
202 if (!semantic_info.dpis.empty()) { | |
203 DpiCapability dpi; | |
204 Dpi default_dpi(semantic_info.default_dpi.width(), | |
205 semantic_info.default_dpi.height()); | |
206 bool is_default_set = false; | |
207 for (size_t i = 0; i < semantic_info.dpis.size(); ++i) { | |
208 Dpi new_dpi(semantic_info.dpis[i].width(), | |
209 semantic_info.dpis[i].height()); | |
210 if (new_dpi.IsValid() && !dpi.Contains(new_dpi)) { | |
211 if (!default_dpi.IsValid()) | |
212 default_dpi = new_dpi; | |
213 dpi.AddDefaultOption(new_dpi, new_dpi == default_dpi); | |
214 is_default_set = is_default_set || (new_dpi == default_dpi); | |
215 } | |
216 } | |
217 if (!is_default_set && default_dpi.IsValid()) | |
218 dpi.AddDefaultOption(default_dpi, true); | |
219 if (dpi.IsValid()) { | |
220 dpi.SaveTo(&description); | |
221 } else { | |
222 NOTREACHED(); | |
223 } | |
224 } | |
225 | |
226 OrientationCapability orientation; | |
227 orientation.AddDefaultOption(PORTRAIT, true); | |
228 orientation.AddOption(LANDSCAPE); | |
229 orientation.AddOption(AUTO_ORIENTATION); | |
230 orientation.SaveTo(&description); | |
231 | |
232 return description.ToString(); | |
233 } | |
234 | |
235 } // namespace cloud_print | 127 } // namespace cloud_print |
OLD | NEW |