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
3 // found in the LICENSE file.
5 #include "components/cloud_devices/printer_description.h"
9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h"
11 #include "base/strings/string_util.h"
12 #include "base/values.h"
13 #include "components/cloud_devices/cloud_device_description_consts.h"
14 #include "components/cloud_devices/description_items_inl.h"
16 namespace cloud_devices
{
22 const int32 kMaxPageNumber
= 1000000;
24 const char kSectionPrint
[] = "print";
25 const char kSectionPrinter
[] = "printer";
27 const char kCustomName
[] = "custom_display_name";
28 const char kKeyContentType
[] = "content_type";
29 const char kKeyName
[] = "name";
30 const char kKeyType
[] = "type";
31 const char kKeyVendorId
[] = "vendor_id";
33 // extern is required to be used in templates.
34 extern const char kOptionCollate
[] = "collate";
35 extern const char kOptionColor
[] = "color";
36 extern const char kOptionContentType
[] = "supported_content_type";
37 extern const char kOptionCopies
[] = "copies";
38 extern const char kOptionDpi
[] = "dpi";
39 extern const char kOptionDuplex
[] = "duplex";
40 extern const char kOptionFitToPage
[] = "fit_to_page";
41 extern const char kOptionMargins
[] = "margins";
42 extern const char kOptionMediaSize
[] = "media_size";
43 extern const char kOptionPageOrientation
[] = "page_orientation";
44 extern const char kOptionPageRange
[] = "page_range";
45 extern const char kOptionReverse
[] = "reverse_order";
47 const char kMargineBottom
[] = "bottom_microns";
48 const char kMargineLeft
[] = "left_microns";
49 const char kMargineRight
[] = "right_microns";
50 const char kMargineTop
[] = "top_microns";
52 const char kDpiHorizontal
[] = "horizontal_dpi";
53 const char kDpiVertical
[] = "vertical_dpi";
55 const char kMediaWidth
[] = "width_microns";
56 const char kMediaHeight
[] = "height_microns";
57 const char kMediaIsContinuous
[] = "is_continuous_feed";
59 const char kPageRangeInterval
[] = "interval";
60 const char kPageRangeEnd
[] = "end";
61 const char kPageRangeStart
[] = "start";
63 const char kTypeColorColor
[] = "STANDARD_COLOR";
64 const char kTypeColorMonochrome
[] = "STANDARD_MONOCHROME";
65 const char kTypeColorCustomColor
[] = "CUSTOM_COLOR";
66 const char kTypeColorCustomMonochrome
[] = "CUSTOM_MONOCHROME";
67 const char kTypeColorAuto
[] = "AUTO";
69 const char kTypeDuplexLongEdge
[] = "LONG_EDGE";
70 const char kTypeDuplexNoDuplex
[] = "NO_DUPLEX";
71 const char kTypeDuplexShortEdge
[] = "SHORT_EDGE";
73 const char kTypeFitToPageFillPage
[] = "FILL_PAGE";
74 const char kTypeFitToPageFitToPage
[] = "FIT_TO_PAGE";
75 const char kTypeFitToPageGrowToPage
[] = "GROW_TO_PAGE";
76 const char kTypeFitToPageNoFitting
[] = "NO_FITTING";
77 const char kTypeFitToPageShrinkToPage
[] = "SHRINK_TO_PAGE";
79 const char kTypeMarginsBorderless
[] = "BORDERLESS";
80 const char kTypeMarginsCustom
[] = "CUSTOM";
81 const char kTypeMarginsStandard
[] = "STANDARD";
82 const char kTypeOrientationAuto
[] = "AUTO";
84 const char kTypeOrientationLandscape
[] = "LANDSCAPE";
85 const char kTypeOrientationPortrait
[] = "PORTRAIT";
87 const struct ColorNames
{
89 const char* const json_name
;
91 { STANDARD_COLOR
, kTypeColorColor
},
92 { STANDARD_MONOCHROME
, kTypeColorMonochrome
},
93 { CUSTOM_COLOR
, kTypeColorCustomColor
},
94 { CUSTOM_MONOCHROME
, kTypeColorCustomMonochrome
},
95 { AUTO_COLOR
, kTypeColorAuto
},
98 const struct DuplexNames
{
100 const char* const json_name
;
102 { NO_DUPLEX
, kTypeDuplexNoDuplex
},
103 { LONG_EDGE
, kTypeDuplexLongEdge
},
104 { SHORT_EDGE
, kTypeDuplexShortEdge
},
107 const struct OrientationNames
{
109 const char* const json_name
;
110 } kOrientationNames
[] = {
111 { PORTRAIT
, kTypeOrientationPortrait
},
112 { LANDSCAPE
, kTypeOrientationLandscape
},
113 { AUTO_ORIENTATION
, kTypeOrientationAuto
},
116 const struct MarginsNames
{
118 const char* const json_name
;
119 } kMarginsNames
[] = {
120 { NO_MARGINS
, kTypeMarginsBorderless
},
121 { STANDARD_MARGINS
, kTypeMarginsStandard
},
122 { CUSTOM_MARGINS
, kTypeMarginsCustom
},
125 const struct FitToPageNames
{
127 const char* const json_name
;
128 } kFitToPageNames
[] = {
129 { NO_FITTING
, kTypeFitToPageNoFitting
},
130 { FIT_TO_PAGE
, kTypeFitToPageFitToPage
},
131 { GROW_TO_PAGE
, kTypeFitToPageGrowToPage
},
132 { SHRINK_TO_PAGE
, kTypeFitToPageShrinkToPage
},
133 { FILL_PAGE
, kTypeFitToPageFillPage
},
136 const int32 kInchToUm
= 25400;
137 const int32 kMmToUm
= 1000;
138 const int32 kSizeTrasholdUm
= 1000;
140 #define MAP_CLOUD_PRINT_MEDIA_TYPE(type, width, height, unit_um) \
142 static_cast<int>(width * unit_um + 0.5), \
143 static_cast<int>(height * unit_um + 0.5) }
145 const struct MadiaDefinition
{
147 const char* const json_name
;
150 } kMediaDefinitions
[] = {
151 { CUSTOM_MEDIA
, "CUSTOM" , 0, 0},
152 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_3X5
, 3, 5, kInchToUm
),
153 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_PERSONAL
, 3.625f
, 6.5f
, kInchToUm
),
154 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_MONARCH
, 3.875f
, 7.5f
, kInchToUm
),
155 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_9
, 3.875f
, 8.875f
, kInchToUm
),
156 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_4X6
, 4, 6, kInchToUm
),
157 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_10
, 4.125f
, 9.5f
, kInchToUm
),
158 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_A2
, 4.375f
, 5.75f
, kInchToUm
),
159 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_11
, 4.5f
, 10.375f
, kInchToUm
),
160 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_12
, 4.75f
, 11, kInchToUm
),
161 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_5X7
, 5, 7, kInchToUm
),
162 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_5X8
, 5, 8, kInchToUm
),
163 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_14
, 5, 11.5f
, kInchToUm
),
164 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INVOICE
, 5.5f
, 8.5f
, kInchToUm
),
165 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_4X6_EXT
, 6, 8, kInchToUm
),
166 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_6X9
, 6, 9, kInchToUm
),
167 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_C5
, 6.5f
, 9.5f
, kInchToUm
),
168 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_7X9
, 7, 9, kInchToUm
),
169 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_EXECUTIVE
, 7.25f
, 10.5f
, kInchToUm
),
170 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_GOVT_LETTER
, 8, 10, kInchToUm
),
171 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_GOVT_LEGAL
, 8, 13, kInchToUm
),
172 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_QUARTO
, 8.5f
, 10.83f
, kInchToUm
),
173 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LETTER
, 8.5f
, 11, kInchToUm
),
174 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_FANFOLD_EUR
, 8.5f
, 12, kInchToUm
),
175 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LETTER_PLUS
, 8.5f
, 12.69f
, kInchToUm
),
176 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_FOOLSCAP
, 8.5f
, 13, kInchToUm
),
177 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LEGAL
, 8.5f
, 14, kInchToUm
),
178 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_SUPER_A
, 8.94f
, 14, kInchToUm
),
179 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_9X11
, 9, 11, kInchToUm
),
180 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_A
, 9, 12, kInchToUm
),
181 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LETTER_EXTRA
, 9.5f
, 12, kInchToUm
),
182 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LEGAL_EXTRA
, 9.5f
, 15, kInchToUm
),
183 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X11
, 10, 11, kInchToUm
),
184 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X13
, 10, 13, kInchToUm
),
185 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X14
, 10, 14, kInchToUm
),
186 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X15
, 10, 15, kInchToUm
),
187 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_11X12
, 11, 12, kInchToUm
),
188 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_EDP
, 11, 14, kInchToUm
),
189 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_FANFOLD_US
, 11, 14.875f
, kInchToUm
),
190 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_11X15
, 11, 15, kInchToUm
),
191 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LEDGER
, 11, 17, kInchToUm
),
192 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_EUR_EDP
, 12, 14, kInchToUm
),
193 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_B
, 12, 18, kInchToUm
),
194 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_12X19
, 12, 19, kInchToUm
),
195 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_B_PLUS
, 12, 19.17f
, kInchToUm
),
196 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_SUPER_B
, 13, 19, kInchToUm
),
197 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_C
, 17, 22, kInchToUm
),
198 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_C
, 18, 24, kInchToUm
),
199 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_D
, 22, 34, kInchToUm
),
200 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_D
, 24, 36, kInchToUm
),
201 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ASME_F
, 28, 40, kInchToUm
),
202 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_WIDE_FORMAT
, 30, 42, kInchToUm
),
203 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_E
, 34, 44, kInchToUm
),
204 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_E
, 36, 48, kInchToUm
),
205 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_F
, 44, 68, kInchToUm
),
206 MAP_CLOUD_PRINT_MEDIA_TYPE(ROC_16K
, 7.75f
, 10.75f
, kInchToUm
),
207 MAP_CLOUD_PRINT_MEDIA_TYPE(ROC_8K
, 10.75f
, 15.5f
, kInchToUm
),
208 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_32K
, 97, 151, kMmToUm
),
209 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_1
, 102, 165, kMmToUm
),
210 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_2
, 102, 176, kMmToUm
),
211 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_4
, 110, 208, kMmToUm
),
212 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_5
, 110, 220, kMmToUm
),
213 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_8
, 120, 309, kMmToUm
),
214 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_6
, 120, 320, kMmToUm
),
215 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_3
, 125, 176, kMmToUm
),
216 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_16K
, 146, 215, kMmToUm
),
217 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_7
, 160, 230, kMmToUm
),
218 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_JUURO_KU_KAI
, 198, 275, kMmToUm
),
219 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_PA_KAI
, 267, 389, kMmToUm
),
220 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_DAI_PA_KAI
, 275, 395, kMmToUm
),
221 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_10
, 324, 458, kMmToUm
),
222 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A10
, 26, 37, kMmToUm
),
223 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A9
, 37, 52, kMmToUm
),
224 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A8
, 52, 74, kMmToUm
),
225 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A7
, 74, 105, kMmToUm
),
226 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A6
, 105, 148, kMmToUm
),
227 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A5
, 148, 210, kMmToUm
),
228 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A5_EXTRA
, 235.5f
, 322.3f
, kMmToUm
),
229 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4
, 210, 297, kMmToUm
),
230 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4_TAB
, 225, 297, kMmToUm
),
231 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4_EXTRA
, 235.5f
, 322.3f
, kMmToUm
),
232 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3
, 297, 420, kMmToUm
),
233 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X3
, 297, 630, kMmToUm
),
234 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X4
, 297, 841, kMmToUm
),
235 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X5
, 297, 1051, kMmToUm
),
236 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X6
, 297, 1261, kMmToUm
),
237 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X7
, 297, 1471, kMmToUm
),
238 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X8
, 297, 1682, kMmToUm
),
239 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X9
, 297, 1892, kMmToUm
),
240 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3_EXTRA
, 322, 445, kMmToUm
),
241 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2
, 420, 594, kMmToUm
),
242 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X3
, 420, 891, kMmToUm
),
243 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X4
, 420, 1189, kMmToUm
),
244 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X5
, 420, 1486, kMmToUm
),
245 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X6
, 420, 1783, kMmToUm
),
246 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X7
, 420, 2080, kMmToUm
),
247 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A1
, 594, 841, kMmToUm
),
248 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2X3
, 594, 1261, kMmToUm
),
249 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2X4
, 594, 1682, kMmToUm
),
250 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2X5
, 594, 2102, kMmToUm
),
251 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A0
, 841, 1189, kMmToUm
),
252 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A1X3
, 841, 1783, kMmToUm
),
253 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A1X4
, 841, 2378, kMmToUm
),
254 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_2A0
, 1189, 1682, kMmToUm
),
255 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A0X3
, 1189, 2523, kMmToUm
),
256 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B10
, 31, 44, kMmToUm
),
257 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B9
, 44, 62, kMmToUm
),
258 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B8
, 62, 88, kMmToUm
),
259 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B7
, 88, 125, kMmToUm
),
260 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B6
, 125, 176, kMmToUm
),
261 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B6C4
, 125, 324, kMmToUm
),
262 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B5
, 176, 250, kMmToUm
),
263 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B5_EXTRA
, 201, 276, kMmToUm
),
264 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B4
, 250, 353, kMmToUm
),
265 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B3
, 353, 500, kMmToUm
),
266 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B2
, 500, 707, kMmToUm
),
267 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B1
, 707, 1000, kMmToUm
),
268 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B0
, 1000, 1414, kMmToUm
),
269 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C10
, 28, 40, kMmToUm
),
270 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C9
, 40, 57, kMmToUm
),
271 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C8
, 57, 81, kMmToUm
),
272 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C7
, 81, 114, kMmToUm
),
273 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C7C6
, 81, 162, kMmToUm
),
274 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C6
, 114, 162, kMmToUm
),
275 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C6C5
, 114, 229, kMmToUm
),
276 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C5
, 162, 229, kMmToUm
),
277 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C4
, 229, 324, kMmToUm
),
278 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C3
, 324, 458, kMmToUm
),
279 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C2
, 458, 648, kMmToUm
),
280 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C1
, 648, 917, kMmToUm
),
281 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C0
, 917, 1297, kMmToUm
),
282 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_DL
, 110, 220, kMmToUm
),
283 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_RA2
, 430, 610, kMmToUm
),
284 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_SRA2
, 450, 640, kMmToUm
),
285 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_RA1
, 610, 860, kMmToUm
),
286 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_SRA1
, 640, 900, kMmToUm
),
287 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_RA0
, 860, 1220, kMmToUm
),
288 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_SRA0
, 900, 1280, kMmToUm
),
289 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B10
, 32, 45, kMmToUm
),
290 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B9
, 45, 64, kMmToUm
),
291 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B8
, 64, 91, kMmToUm
),
292 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B7
, 91, 128, kMmToUm
),
293 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B6
, 128, 182, kMmToUm
),
294 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B5
, 182, 257, kMmToUm
),
295 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B4
, 257, 364, kMmToUm
),
296 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B3
, 364, 515, kMmToUm
),
297 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B2
, 515, 728, kMmToUm
),
298 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B1
, 728, 1030, kMmToUm
),
299 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B0
, 1030, 1456, kMmToUm
),
300 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_EXEC
, 216, 330, kMmToUm
),
301 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_CHOU4
, 90, 205, kMmToUm
),
302 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_HAGAKI
, 100, 148, kMmToUm
),
303 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_YOU4
, 105, 235, kMmToUm
),
304 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_CHOU2
, 111.1f
, 146, kMmToUm
),
305 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_CHOU3
, 120, 235, kMmToUm
),
306 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_OUFUKU
, 148, 200, kMmToUm
),
307 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_KAHU
, 240, 322.1f
, kMmToUm
),
308 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_KAKU2
, 240, 332, kMmToUm
),
309 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_SMALL_PHOTO
, 100, 150, kMmToUm
),
310 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_ITALIAN
, 110, 230, kMmToUm
),
311 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_POSTFIX
, 114, 229, kMmToUm
),
312 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_LARGE_PHOTO
, 200, 300, kMmToUm
),
313 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_FOLIO
, 210, 330, kMmToUm
),
314 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_FOLIO_SP
, 215, 315, kMmToUm
),
315 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_INVITE
, 220, 220, kMmToUm
)
317 #undef MAP_CLOUD_PRINT_MEDIA_TYPE
319 const MadiaDefinition
* FindMediaBySize(int32 width_um
, int32 height_um
) {
320 const MadiaDefinition
* result
= NULL
;
321 for (size_t i
= 0; i
< arraysize(kMediaDefinitions
); ++i
) {
322 int32 diff
= std::max(std::abs(width_um
- kMediaDefinitions
[i
].width_um
),
323 std::abs(height_um
- kMediaDefinitions
[i
].height_um
));
324 if (diff
< kSizeTrasholdUm
)
325 result
= &kMediaDefinitions
[i
];
330 template<class T
, class IdType
>
331 std::string
TypeToString(const T
& names
, IdType id
) {
332 for (size_t i
= 0; i
< arraysize(names
); ++i
) {
333 if (id
== names
[i
].id
)
334 return names
[i
].json_name
;
337 return std::string();
340 template<class T
, class IdType
>
341 bool TypeFromString(const T
& names
, const std::string
& type
, IdType
* id
) {
342 for (size_t i
= 0; i
< arraysize(names
); ++i
) {
343 if (type
== names
[i
].json_name
) {
353 Color::Color() : type(AUTO_COLOR
) {}
355 Color::Color(ColorType type
) : type(type
) {}
357 bool Color::operator==(const Color
& other
) const {
358 return type
== other
.type
&& vendor_id
== other
.vendor_id
&&
359 custom_display_name
== other
.custom_display_name
;
362 bool Color::IsValid() const {
363 if (type
!= CUSTOM_COLOR
&& type
!= CUSTOM_MONOCHROME
)
365 return !vendor_id
.empty() && !custom_display_name
.empty();
369 : type(STANDARD_MARGINS
),
376 Margins::Margins(MarginsType type
,
384 bottom_um(bottom_um
),
388 bool Margins::operator==(const Margins
& other
) const {
389 return type
== other
.type
&&
390 top_um
== other
.top_um
&&
391 right_um
== other
.right_um
&&
392 bottom_um
== other
.bottom_um
;
395 Dpi::Dpi() : horizontal(0), vertical(0) {}
397 Dpi::Dpi(int32 horizontal
, int32 vertical
)
398 : horizontal(horizontal
), vertical(vertical
) {}
400 bool Dpi::IsValid() const {
401 return horizontal
> 0 && vertical
> 0;
404 bool Dpi::operator==(const Dpi
& other
) const {
405 return horizontal
== other
.horizontal
&& vertical
== other
.vertical
;
409 : type(CUSTOM_MEDIA
),
412 is_continuous_feed(false) {
416 Media::Media(MediaType type
, int32 width_um
, int32 height_um
)
419 height_um(height_um
),
420 is_continuous_feed(width_um
<= 0 || height_um
<= 0) {
423 Media::Media(const std::string
& custom_display_name
, int32 width_um
,
425 : type(CUSTOM_MEDIA
),
427 height_um(height_um
),
428 is_continuous_feed(width_um
<= 0 || height_um
<= 0),
429 custom_display_name(custom_display_name
) {
432 bool Media::MatchBySize() {
433 const MadiaDefinition
* media
= FindMediaBySize(width_um
, height_um
);
437 custom_display_name
.clear();
441 bool Media::IsValid() const {
442 if (is_continuous_feed
) {
443 if (width_um
<= 0 && height_um
<= 0)
446 if (width_um
<= 0 || height_um
<= 0)
452 bool Media::operator==(const Media
& other
) const {
453 return type
== other
.type
&&
454 width_um
== other
.width_um
&&
455 height_um
== other
.height_um
&&
456 is_continuous_feed
== other
.is_continuous_feed
;
459 Interval::Interval() : start(0), end(0) {}
461 Interval::Interval(int32 start
, int32 end
)
462 : start(start
), end(end
) {}
464 Interval::Interval(int32 start
)
465 : start(start
), end(kMaxPageNumber
) {}
467 bool Interval::operator==(const Interval
& other
) const {
468 return start
== other
.start
&& end
== other
.end
;
471 template<const char* kName
>
474 static std::string
GetCapabilityPath() {
475 std::string result
= kSectionPrinter
;
481 static std::string
GetTicketItemPath() {
482 std::string result
= kSectionPrint
;
489 class NoValueValidation
{
491 template <class Option
>
492 static bool IsValid(const Option
&) {
497 class ContentTypeTraits
: public NoValueValidation
,
498 public ItemsTraits
<kOptionContentType
> {
500 static bool Load(const base::DictionaryValue
& dict
, ContentType
* option
) {
501 return dict
.GetString(kKeyContentType
, option
);
504 static void Save(ContentType option
, base::DictionaryValue
* dict
) {
505 dict
->SetString(kKeyContentType
, option
);
509 class ColorTraits
: public ItemsTraits
<kOptionColor
> {
511 static bool IsValid(const Color
& option
) {
512 return option
.IsValid();
515 static bool Load(const base::DictionaryValue
& dict
, Color
* option
) {
516 std::string type_str
;
517 if (!dict
.GetString(kKeyType
, &type_str
))
519 if (!TypeFromString(kColorNames
, type_str
, &option
->type
))
521 dict
.GetString(kKeyVendorId
, &option
->vendor_id
);
522 dict
.GetString(kCustomName
, &option
->custom_display_name
);
526 static void Save(const Color
& option
, base::DictionaryValue
* dict
) {
527 dict
->SetString(kKeyType
, TypeToString(kColorNames
, option
.type
));
528 if (!option
.vendor_id
.empty())
529 dict
->SetString(kKeyVendorId
, option
.vendor_id
);
530 if (!option
.custom_display_name
.empty())
531 dict
->SetString(kCustomName
, option
.custom_display_name
);
535 class DuplexTraits
: public NoValueValidation
,
536 public ItemsTraits
<kOptionDuplex
> {
538 static bool Load(const base::DictionaryValue
& dict
, DuplexType
* option
) {
539 std::string type_str
;
540 return dict
.GetString(kKeyType
, &type_str
) &&
541 TypeFromString(kDuplexNames
, type_str
, option
);
544 static void Save(DuplexType option
, base::DictionaryValue
* dict
) {
545 dict
->SetString(kKeyType
, TypeToString(kDuplexNames
, option
));
549 class OrientationTraits
: public NoValueValidation
,
550 public ItemsTraits
<kOptionPageOrientation
> {
552 static bool Load(const base::DictionaryValue
& dict
, OrientationType
* option
) {
553 std::string type_str
;
554 return dict
.GetString(kKeyType
, &type_str
) &&
555 TypeFromString(kOrientationNames
, type_str
, option
);
558 static void Save(OrientationType option
, base::DictionaryValue
* dict
) {
559 dict
->SetString(kKeyType
, TypeToString(kOrientationNames
, option
));
563 class CopiesTraits
: public ItemsTraits
<kOptionCopies
> {
565 static bool IsValid(int32 option
) {
569 static bool Load(const base::DictionaryValue
& dict
, int32
* option
) {
570 return dict
.GetInteger(kOptionCopies
, option
);
573 static void Save(int32 option
, base::DictionaryValue
* dict
) {
574 dict
->SetInteger(kOptionCopies
, option
);
578 class MarginsTraits
: public NoValueValidation
,
579 public ItemsTraits
<kOptionMargins
> {
581 static bool Load(const base::DictionaryValue
& dict
, Margins
* option
) {
582 std::string type_str
;
583 if (!dict
.GetString(kKeyType
, &type_str
))
585 if (!TypeFromString(kMarginsNames
, type_str
, &option
->type
))
588 dict
.GetInteger(kMargineTop
, &option
->top_um
) &&
589 dict
.GetInteger(kMargineRight
, &option
->right_um
) &&
590 dict
.GetInteger(kMargineBottom
, &option
->bottom_um
) &&
591 dict
.GetInteger(kMargineLeft
, &option
->left_um
);
594 static void Save(const Margins
& option
, base::DictionaryValue
* dict
) {
595 dict
->SetString(kKeyType
, TypeToString(kMarginsNames
, option
.type
));
596 dict
->SetInteger(kMargineTop
, option
.top_um
);
597 dict
->SetInteger(kMargineRight
, option
.right_um
);
598 dict
->SetInteger(kMargineBottom
, option
.bottom_um
);
599 dict
->SetInteger(kMargineLeft
, option
.left_um
);
603 class DpiTraits
: public ItemsTraits
<kOptionDpi
> {
605 static bool IsValid(const Dpi
& option
) {
606 return option
.IsValid();
609 static bool Load(const base::DictionaryValue
& dict
, Dpi
* option
) {
610 if (!dict
.GetInteger(kDpiHorizontal
, &option
->horizontal
) ||
611 !dict
.GetInteger(kDpiVertical
, &option
->vertical
)) {
617 static void Save(const Dpi
& option
, base::DictionaryValue
* dict
) {
618 dict
->SetInteger(kDpiHorizontal
, option
.horizontal
);
619 dict
->SetInteger(kDpiVertical
, option
.vertical
);
623 class FitToPageTraits
: public NoValueValidation
,
624 public ItemsTraits
<kOptionFitToPage
> {
626 static bool Load(const base::DictionaryValue
& dict
, FitToPageType
* option
) {
627 std::string type_str
;
628 return dict
.GetString(kKeyType
, &type_str
) &&
629 TypeFromString(kFitToPageNames
, type_str
, option
);
632 static void Save(FitToPageType option
, base::DictionaryValue
* dict
) {
633 dict
->SetString(kKeyType
, TypeToString(kFitToPageNames
, option
));
637 class PageRangeTraits
: public ItemsTraits
<kOptionPageRange
> {
639 static bool IsValid(const PageRange
& option
) {
640 for (size_t i
= 0; i
< option
.size(); ++i
) {
641 if (option
[i
].start
< 1 || option
[i
].end
< 1) {
648 static bool Load(const base::DictionaryValue
& dict
, PageRange
* option
) {
649 const base::ListValue
* list
= NULL
;
650 if (!dict
.GetList(kPageRangeInterval
, &list
))
652 for (size_t i
= 0; i
< list
->GetSize(); ++i
) {
653 const base::DictionaryValue
* interval
= NULL
;
654 if (!list
->GetDictionary(i
, &interval
))
656 Interval
new_interval(1, kMaxPageNumber
);
657 interval
->GetInteger(kPageRangeStart
, &new_interval
.start
);
658 interval
->GetInteger(kPageRangeEnd
, &new_interval
.end
);
659 option
->push_back(new_interval
);
664 static void Save(const PageRange
& option
, base::DictionaryValue
* dict
) {
665 if (!option
.empty()) {
666 base::ListValue
* list
= new base::ListValue
;
667 dict
->Set(kPageRangeInterval
, list
);
668 for (size_t i
= 0; i
< option
.size(); ++i
) {
669 base::DictionaryValue
* interval
= new base::DictionaryValue
;
670 list
->Append(interval
);
671 interval
->SetInteger(kPageRangeStart
, option
[i
].start
);
672 if (option
[i
].end
< kMaxPageNumber
)
673 interval
->SetInteger(kPageRangeEnd
, option
[i
].end
);
679 class MediaTraits
: public ItemsTraits
<kOptionMediaSize
> {
681 static bool IsValid(const Media
& option
) {
682 return option
.IsValid();
685 static bool Load(const base::DictionaryValue
& dict
, Media
* option
) {
686 std::string type_str
;
687 if (dict
.GetString(kKeyName
, &type_str
)) {
688 if (!TypeFromString(kMediaDefinitions
, type_str
, &option
->type
))
692 dict
.GetInteger(kMediaWidth
, &option
->width_um
);
693 dict
.GetInteger(kMediaHeight
, &option
->height_um
);
694 dict
.GetBoolean(kMediaIsContinuous
, &option
->is_continuous_feed
);
695 dict
.GetString(kCustomName
, &option
->custom_display_name
);
699 static void Save(const Media
& option
, base::DictionaryValue
* dict
) {
700 if (option
.type
!= CUSTOM_MEDIA
)
701 dict
->SetString(kKeyName
, TypeToString(kMediaDefinitions
, option
.type
));
702 if (!option
.custom_display_name
.empty() || option
.type
== CUSTOM_MEDIA
)
703 dict
->SetString(kCustomName
, option
.custom_display_name
);
704 if (option
.width_um
> 0)
705 dict
->SetInteger(kMediaWidth
, option
.width_um
);
706 if (option
.height_um
> 0)
707 dict
->SetInteger(kMediaHeight
, option
.height_um
);
708 if (option
.is_continuous_feed
)
709 dict
->SetBoolean(kMediaIsContinuous
, true);
713 class CollateTraits
: public NoValueValidation
,
714 public ItemsTraits
<kOptionCollate
> {
716 static const bool kDefault
= true;
718 static bool Load(const base::DictionaryValue
& dict
, bool* option
) {
719 return dict
.GetBoolean(kOptionCollate
, option
);
722 static void Save(bool option
, base::DictionaryValue
* dict
) {
723 dict
->SetBoolean(kOptionCollate
, option
);
727 class ReverseTraits
: public NoValueValidation
,
728 public ItemsTraits
<kOptionReverse
> {
730 static const bool kDefault
= false;
732 static bool Load(const base::DictionaryValue
& dict
, bool* option
) {
733 return dict
.GetBoolean(kOptionReverse
, option
);
736 static void Save(bool option
, base::DictionaryValue
* dict
) {
737 dict
->SetBoolean(kOptionReverse
, option
);
741 } // namespace printer
743 using namespace printer
;
745 template class ListCapability
<ContentType
, ContentTypeTraits
>;
746 template class SelectionCapability
<Color
, ColorTraits
>;
747 template class SelectionCapability
<DuplexType
, DuplexTraits
>;
748 template class SelectionCapability
<OrientationType
, OrientationTraits
>;
749 template class SelectionCapability
<Margins
, MarginsTraits
>;
750 template class SelectionCapability
<Dpi
, DpiTraits
>;
751 template class SelectionCapability
<FitToPageType
, FitToPageTraits
>;
752 template class SelectionCapability
<Media
, MediaTraits
>;
753 template class EmptyCapability
<class CopiesTraits
>;
754 template class EmptyCapability
<class PageRangeTraits
>;
755 template class BooleanCapability
<class CollateTraits
>;
756 template class BooleanCapability
<class ReverseTraits
>;
758 template class TicketItem
<Color
, ColorTraits
>;
759 template class TicketItem
<DuplexType
, DuplexTraits
>;
760 template class TicketItem
<OrientationType
, OrientationTraits
>;
761 template class TicketItem
<Margins
, MarginsTraits
>;
762 template class TicketItem
<Dpi
, DpiTraits
>;
763 template class TicketItem
<FitToPageType
, FitToPageTraits
>;
764 template class TicketItem
<Media
, MediaTraits
>;
765 template class TicketItem
<int32
, CopiesTraits
>;
766 template class TicketItem
<PageRange
, PageRangeTraits
>;
767 template class TicketItem
<bool, CollateTraits
>;
768 template class TicketItem
<bool, ReverseTraits
>;
770 } // namespace cloud_devices