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/common/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/common/cloud_device_description_consts.h"
14 #include "components/cloud_devices/common/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";
46 extern const char kOptionPwgRasterConfig
[] = "pwg_raster_config";
48 const char kMargineBottom
[] = "bottom_microns";
49 const char kMargineLeft
[] = "left_microns";
50 const char kMargineRight
[] = "right_microns";
51 const char kMargineTop
[] = "top_microns";
53 const char kDpiHorizontal
[] = "horizontal_dpi";
54 const char kDpiVertical
[] = "vertical_dpi";
56 const char kMediaWidth
[] = "width_microns";
57 const char kMediaHeight
[] = "height_microns";
58 const char kMediaIsContinuous
[] = "is_continuous_feed";
60 const char kPageRangeInterval
[] = "interval";
61 const char kPageRangeEnd
[] = "end";
62 const char kPageRangeStart
[] = "start";
64 const char kPwgRasterDocumentSheetBack
[] = "document_sheet_back";
65 const char kPwgRasterReverseOrderStreaming
[] = "reverse_order_streaming";
66 const char kPwgRasterRotateAllPages
[] = "rotate_all_pages";
68 const char kTypeColorColor
[] = "STANDARD_COLOR";
69 const char kTypeColorMonochrome
[] = "STANDARD_MONOCHROME";
70 const char kTypeColorCustomColor
[] = "CUSTOM_COLOR";
71 const char kTypeColorCustomMonochrome
[] = "CUSTOM_MONOCHROME";
72 const char kTypeColorAuto
[] = "AUTO";
74 const char kTypeDuplexLongEdge
[] = "LONG_EDGE";
75 const char kTypeDuplexNoDuplex
[] = "NO_DUPLEX";
76 const char kTypeDuplexShortEdge
[] = "SHORT_EDGE";
78 const char kTypeFitToPageFillPage
[] = "FILL_PAGE";
79 const char kTypeFitToPageFitToPage
[] = "FIT_TO_PAGE";
80 const char kTypeFitToPageGrowToPage
[] = "GROW_TO_PAGE";
81 const char kTypeFitToPageNoFitting
[] = "NO_FITTING";
82 const char kTypeFitToPageShrinkToPage
[] = "SHRINK_TO_PAGE";
84 const char kTypeMarginsBorderless
[] = "BORDERLESS";
85 const char kTypeMarginsCustom
[] = "CUSTOM";
86 const char kTypeMarginsStandard
[] = "STANDARD";
87 const char kTypeOrientationAuto
[] = "AUTO";
89 const char kTypeOrientationLandscape
[] = "LANDSCAPE";
90 const char kTypeOrientationPortrait
[] = "PORTRAIT";
92 const char kTypeDocumentSheetBackNormal
[] = "NORMAL";
93 const char kTypeDocumentSheetBackRotated
[] = "ROTATED";
94 const char kTypeDocumentSheetBackManualTumble
[] = "MANUAL_TUMBLE";
95 const char kTypeDocumentSheetBackFlipped
[] = "FLIPPED";
97 const struct ColorNames
{
99 const char* const json_name
;
101 {STANDARD_COLOR
, kTypeColorColor
},
102 {STANDARD_MONOCHROME
, kTypeColorMonochrome
},
103 {CUSTOM_COLOR
, kTypeColorCustomColor
},
104 {CUSTOM_MONOCHROME
, kTypeColorCustomMonochrome
},
105 {AUTO_COLOR
, kTypeColorAuto
},
108 const struct DuplexNames
{
110 const char* const json_name
;
112 {NO_DUPLEX
, kTypeDuplexNoDuplex
},
113 {LONG_EDGE
, kTypeDuplexLongEdge
},
114 {SHORT_EDGE
, kTypeDuplexShortEdge
},
117 const struct OrientationNames
{
119 const char* const json_name
;
120 } kOrientationNames
[] = {
121 {PORTRAIT
, kTypeOrientationPortrait
},
122 {LANDSCAPE
, kTypeOrientationLandscape
},
123 {AUTO_ORIENTATION
, kTypeOrientationAuto
},
126 const struct MarginsNames
{
128 const char* const json_name
;
129 } kMarginsNames
[] = {
130 {NO_MARGINS
, kTypeMarginsBorderless
},
131 {STANDARD_MARGINS
, kTypeMarginsStandard
},
132 {CUSTOM_MARGINS
, kTypeMarginsCustom
},
135 const struct FitToPageNames
{
137 const char* const json_name
;
138 } kFitToPageNames
[] = {
139 {NO_FITTING
, kTypeFitToPageNoFitting
},
140 {FIT_TO_PAGE
, kTypeFitToPageFitToPage
},
141 {GROW_TO_PAGE
, kTypeFitToPageGrowToPage
},
142 {SHRINK_TO_PAGE
, kTypeFitToPageShrinkToPage
},
143 {FILL_PAGE
, kTypeFitToPageFillPage
},
146 const struct DocumentSheetBackNames
{
147 DocumentSheetBack id
;
148 const char* const json_name
;
149 } kDocumentSheetBackNames
[] = {
150 {NORMAL
, kTypeDocumentSheetBackNormal
},
151 {ROTATED
, kTypeDocumentSheetBackRotated
},
152 {MANUAL_TUMBLE
, kTypeDocumentSheetBackManualTumble
},
153 {FLIPPED
, kTypeDocumentSheetBackFlipped
}};
155 const int32 kInchToUm
= 25400;
156 const int32 kMmToUm
= 1000;
157 const int32 kSizeTrasholdUm
= 1000;
159 #define MAP_CLOUD_PRINT_MEDIA_TYPE(type, width, height, unit_um) \
161 type, #type, static_cast<int>(width* unit_um + 0.5), \
162 static_cast<int>(height* unit_um + 0.5) \
165 const struct MediaDefinition
{
167 const char* const json_name
;
170 } kMediaDefinitions
[] = {
171 {CUSTOM_MEDIA
, "CUSTOM", 0, 0},
172 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_3X5
, 3, 5, kInchToUm
),
173 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_PERSONAL
, 3.625f
, 6.5f
, kInchToUm
),
174 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_MONARCH
, 3.875f
, 7.5f
, kInchToUm
),
175 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_9
, 3.875f
, 8.875f
, kInchToUm
),
176 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_4X6
, 4, 6, kInchToUm
),
177 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_10
, 4.125f
, 9.5f
, kInchToUm
),
178 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_A2
, 4.375f
, 5.75f
, kInchToUm
),
179 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_11
, 4.5f
, 10.375f
, kInchToUm
),
180 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_12
, 4.75f
, 11, kInchToUm
),
181 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_5X7
, 5, 7, kInchToUm
),
182 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_5X8
, 5, 8, kInchToUm
),
183 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_NUMBER_14
, 5, 11.5f
, kInchToUm
),
184 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INVOICE
, 5.5f
, 8.5f
, kInchToUm
),
185 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_4X6_EXT
, 6, 8, kInchToUm
),
186 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_6X9
, 6, 9, kInchToUm
),
187 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_C5
, 6.5f
, 9.5f
, kInchToUm
),
188 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_7X9
, 7, 9, kInchToUm
),
189 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_EXECUTIVE
, 7.25f
, 10.5f
, kInchToUm
),
190 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_GOVT_LETTER
, 8, 10, kInchToUm
),
191 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_GOVT_LEGAL
, 8, 13, kInchToUm
),
192 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_QUARTO
, 8.5f
, 10.83f
, kInchToUm
),
193 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LETTER
, 8.5f
, 11, kInchToUm
),
194 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_FANFOLD_EUR
, 8.5f
, 12, kInchToUm
),
195 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LETTER_PLUS
, 8.5f
, 12.69f
, kInchToUm
),
196 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_FOOLSCAP
, 8.5f
, 13, kInchToUm
),
197 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LEGAL
, 8.5f
, 14, kInchToUm
),
198 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_SUPER_A
, 8.94f
, 14, kInchToUm
),
199 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_9X11
, 9, 11, kInchToUm
),
200 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_A
, 9, 12, kInchToUm
),
201 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LETTER_EXTRA
, 9.5f
, 12, kInchToUm
),
202 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LEGAL_EXTRA
, 9.5f
, 15, kInchToUm
),
203 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X11
, 10, 11, kInchToUm
),
204 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X13
, 10, 13, kInchToUm
),
205 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X14
, 10, 14, kInchToUm
),
206 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_10X15
, 10, 15, kInchToUm
),
207 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_11X12
, 11, 12, kInchToUm
),
208 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_EDP
, 11, 14, kInchToUm
),
209 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_FANFOLD_US
, 11, 14.875f
, kInchToUm
),
210 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_11X15
, 11, 15, kInchToUm
),
211 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_LEDGER
, 11, 17, kInchToUm
),
212 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_EUR_EDP
, 12, 14, kInchToUm
),
213 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_B
, 12, 18, kInchToUm
),
214 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_12X19
, 12, 19, kInchToUm
),
215 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_B_PLUS
, 12, 19.17f
, kInchToUm
),
216 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_SUPER_B
, 13, 19, kInchToUm
),
217 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_C
, 17, 22, kInchToUm
),
218 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_C
, 18, 24, kInchToUm
),
219 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_D
, 22, 34, kInchToUm
),
220 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_D
, 24, 36, kInchToUm
),
221 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ASME_F
, 28, 40, kInchToUm
),
222 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_WIDE_FORMAT
, 30, 42, kInchToUm
),
223 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_E
, 34, 44, kInchToUm
),
224 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_ARCH_E
, 36, 48, kInchToUm
),
225 MAP_CLOUD_PRINT_MEDIA_TYPE(NA_F
, 44, 68, kInchToUm
),
226 MAP_CLOUD_PRINT_MEDIA_TYPE(ROC_16K
, 7.75f
, 10.75f
, kInchToUm
),
227 MAP_CLOUD_PRINT_MEDIA_TYPE(ROC_8K
, 10.75f
, 15.5f
, kInchToUm
),
228 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_32K
, 97, 151, kMmToUm
),
229 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_1
, 102, 165, kMmToUm
),
230 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_2
, 102, 176, kMmToUm
),
231 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_4
, 110, 208, kMmToUm
),
232 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_5
, 110, 220, kMmToUm
),
233 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_8
, 120, 309, kMmToUm
),
234 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_6
, 120, 230, kMmToUm
),
235 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_3
, 125, 176, kMmToUm
),
236 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_16K
, 146, 215, kMmToUm
),
237 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_7
, 160, 230, kMmToUm
),
238 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_JUURO_KU_KAI
, 198, 275, kMmToUm
),
239 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_PA_KAI
, 267, 389, kMmToUm
),
240 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_DAI_PA_KAI
, 275, 395, kMmToUm
),
241 MAP_CLOUD_PRINT_MEDIA_TYPE(PRC_10
, 324, 458, kMmToUm
),
242 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A10
, 26, 37, kMmToUm
),
243 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A9
, 37, 52, kMmToUm
),
244 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A8
, 52, 74, kMmToUm
),
245 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A7
, 74, 105, kMmToUm
),
246 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A6
, 105, 148, kMmToUm
),
247 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A5
, 148, 210, kMmToUm
),
248 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A5_EXTRA
, 174, 235, kMmToUm
),
249 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4
, 210, 297, kMmToUm
),
250 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4_TAB
, 225, 297, kMmToUm
),
251 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4_EXTRA
, 235, 322, kMmToUm
),
252 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3
, 297, 420, kMmToUm
),
253 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X3
, 297, 630, kMmToUm
),
254 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X4
, 297, 841, kMmToUm
),
255 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X5
, 297, 1051, kMmToUm
),
256 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X6
, 297, 1261, kMmToUm
),
257 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X7
, 297, 1471, kMmToUm
),
258 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X8
, 297, 1682, kMmToUm
),
259 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A4X9
, 297, 1892, kMmToUm
),
260 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3_EXTRA
, 322, 445, kMmToUm
),
261 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2
, 420, 594, kMmToUm
),
262 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X3
, 420, 891, kMmToUm
),
263 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X4
, 420, 1189, kMmToUm
),
264 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X5
, 420, 1486, kMmToUm
),
265 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X6
, 420, 1783, kMmToUm
),
266 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A3X7
, 420, 2080, kMmToUm
),
267 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A1
, 594, 841, kMmToUm
),
268 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2X3
, 594, 1261, kMmToUm
),
269 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2X4
, 594, 1682, kMmToUm
),
270 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A2X5
, 594, 2102, kMmToUm
),
271 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A0
, 841, 1189, kMmToUm
),
272 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A1X3
, 841, 1783, kMmToUm
),
273 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A1X4
, 841, 2378, kMmToUm
),
274 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_2A0
, 1189, 1682, kMmToUm
),
275 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_A0X3
, 1189, 2523, kMmToUm
),
276 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B10
, 31, 44, kMmToUm
),
277 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B9
, 44, 62, kMmToUm
),
278 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B8
, 62, 88, kMmToUm
),
279 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B7
, 88, 125, kMmToUm
),
280 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B6
, 125, 176, kMmToUm
),
281 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B6C4
, 125, 324, kMmToUm
),
282 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B5
, 176, 250, kMmToUm
),
283 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B5_EXTRA
, 201, 276, kMmToUm
),
284 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B4
, 250, 353, kMmToUm
),
285 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B3
, 353, 500, kMmToUm
),
286 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B2
, 500, 707, kMmToUm
),
287 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B1
, 707, 1000, kMmToUm
),
288 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_B0
, 1000, 1414, kMmToUm
),
289 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C10
, 28, 40, kMmToUm
),
290 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C9
, 40, 57, kMmToUm
),
291 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C8
, 57, 81, kMmToUm
),
292 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C7
, 81, 114, kMmToUm
),
293 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C7C6
, 81, 162, kMmToUm
),
294 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C6
, 114, 162, kMmToUm
),
295 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C6C5
, 114, 229, kMmToUm
),
296 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C5
, 162, 229, kMmToUm
),
297 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C4
, 229, 324, kMmToUm
),
298 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C3
, 324, 458, kMmToUm
),
299 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C2
, 458, 648, kMmToUm
),
300 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C1
, 648, 917, kMmToUm
),
301 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_C0
, 917, 1297, kMmToUm
),
302 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_DL
, 110, 220, kMmToUm
),
303 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_RA2
, 430, 610, kMmToUm
),
304 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_SRA2
, 450, 640, kMmToUm
),
305 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_RA1
, 610, 860, kMmToUm
),
306 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_SRA1
, 640, 900, kMmToUm
),
307 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_RA0
, 860, 1220, kMmToUm
),
308 MAP_CLOUD_PRINT_MEDIA_TYPE(ISO_SRA0
, 900, 1280, kMmToUm
),
309 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B10
, 32, 45, kMmToUm
),
310 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B9
, 45, 64, kMmToUm
),
311 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B8
, 64, 91, kMmToUm
),
312 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B7
, 91, 128, kMmToUm
),
313 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B6
, 128, 182, kMmToUm
),
314 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B5
, 182, 257, kMmToUm
),
315 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B4
, 257, 364, kMmToUm
),
316 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B3
, 364, 515, kMmToUm
),
317 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B2
, 515, 728, kMmToUm
),
318 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B1
, 728, 1030, kMmToUm
),
319 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_B0
, 1030, 1456, kMmToUm
),
320 MAP_CLOUD_PRINT_MEDIA_TYPE(JIS_EXEC
, 216, 330, kMmToUm
),
321 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_CHOU4
, 90, 205, kMmToUm
),
322 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_HAGAKI
, 100, 148, kMmToUm
),
323 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_YOU4
, 105, 235, kMmToUm
),
324 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_CHOU2
, 111.1f
, 146, kMmToUm
),
325 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_CHOU3
, 120, 235, kMmToUm
),
326 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_OUFUKU
, 148, 200, kMmToUm
),
327 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_KAHU
, 240, 322.1f
, kMmToUm
),
328 MAP_CLOUD_PRINT_MEDIA_TYPE(JPN_KAKU2
, 240, 332, kMmToUm
),
329 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_SMALL_PHOTO
, 100, 150, kMmToUm
),
330 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_ITALIAN
, 110, 230, kMmToUm
),
331 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_POSTFIX
, 114, 229, kMmToUm
),
332 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_LARGE_PHOTO
, 200, 300, kMmToUm
),
333 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_FOLIO
, 210, 330, kMmToUm
),
334 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_FOLIO_SP
, 215, 315, kMmToUm
),
335 MAP_CLOUD_PRINT_MEDIA_TYPE(OM_INVITE
, 220, 220, kMmToUm
)};
336 #undef MAP_CLOUD_PRINT_MEDIA_TYPE
338 const MediaDefinition
& FindMediaByType(MediaType type
) {
339 for (size_t i
= 0; i
< arraysize(kMediaDefinitions
); ++i
) {
340 if (kMediaDefinitions
[i
].id
== type
)
341 return kMediaDefinitions
[i
];
344 return kMediaDefinitions
[0];
347 const MediaDefinition
* FindMediaBySize(int32 width_um
, int32 height_um
) {
348 const MediaDefinition
* result
= NULL
;
349 for (size_t i
= 0; i
< arraysize(kMediaDefinitions
); ++i
) {
350 int32 diff
= std::max(std::abs(width_um
- kMediaDefinitions
[i
].width_um
),
351 std::abs(height_um
- kMediaDefinitions
[i
].height_um
));
352 if (diff
< kSizeTrasholdUm
)
353 result
= &kMediaDefinitions
[i
];
358 template <class T
, class IdType
>
359 std::string
TypeToString(const T
& names
, IdType id
) {
360 for (size_t i
= 0; i
< arraysize(names
); ++i
) {
361 if (id
== names
[i
].id
)
362 return names
[i
].json_name
;
365 return std::string();
368 template <class T
, class IdType
>
369 bool TypeFromString(const T
& names
, const std::string
& type
, IdType
* id
) {
370 for (size_t i
= 0; i
< arraysize(names
); ++i
) {
371 if (type
== names
[i
].json_name
) {
381 PwgRasterConfig::PwgRasterConfig()
382 : document_sheet_back(ROTATED
),
383 reverse_order_streaming(false),
384 rotate_all_pages(false) {
387 Color::Color() : type(AUTO_COLOR
) {
390 Color::Color(ColorType type
) : type(type
) {
393 bool Color::operator==(const Color
& other
) const {
394 return type
== other
.type
&& vendor_id
== other
.vendor_id
&&
395 custom_display_name
== other
.custom_display_name
;
398 bool Color::IsValid() const {
399 if (type
!= CUSTOM_COLOR
&& type
!= CUSTOM_MONOCHROME
)
401 return !vendor_id
.empty() && !custom_display_name
.empty();
405 : type(STANDARD_MARGINS
), top_um(0), right_um(0), bottom_um(0), left_um(0) {
408 Margins::Margins(MarginsType type
,
416 bottom_um(bottom_um
),
420 bool Margins::operator==(const Margins
& other
) const {
421 return type
== other
.type
&& top_um
== other
.top_um
&&
422 right_um
== other
.right_um
&& bottom_um
== other
.bottom_um
;
425 Dpi::Dpi() : horizontal(0), vertical(0) {
428 Dpi::Dpi(int32 horizontal
, int32 vertical
)
429 : horizontal(horizontal
), vertical(vertical
) {
432 bool Dpi::IsValid() const {
433 return horizontal
> 0 && vertical
> 0;
436 bool Dpi::operator==(const Dpi
& other
) const {
437 return horizontal
== other
.horizontal
&& vertical
== other
.vertical
;
441 : type(CUSTOM_MEDIA
), width_um(0), height_um(0), is_continuous_feed(false) {
444 Media::Media(MediaType type
)
448 is_continuous_feed(false) {
449 const MediaDefinition
& media
= FindMediaByType(type
);
450 width_um
= media
.width_um
;
451 height_um
= media
.height_um
;
452 is_continuous_feed
= width_um
<= 0 || height_um
<= 0;
455 Media::Media(MediaType type
, int32 width_um
, int32 height_um
)
458 height_um(height_um
),
459 is_continuous_feed(width_um
<= 0 || height_um
<= 0) {
462 Media::Media(const std::string
& custom_display_name
,
465 : type(CUSTOM_MEDIA
),
467 height_um(height_um
),
468 is_continuous_feed(width_um
<= 0 || height_um
<= 0),
469 custom_display_name(custom_display_name
) {
472 bool Media::MatchBySize() {
473 const MediaDefinition
* media
= FindMediaBySize(width_um
, height_um
);
477 custom_display_name
.clear();
481 bool Media::IsValid() const {
482 if (is_continuous_feed
) {
483 if (width_um
<= 0 && height_um
<= 0)
486 if (width_um
<= 0 || height_um
<= 0)
492 bool Media::operator==(const Media
& other
) const {
493 return type
== other
.type
&& width_um
== other
.width_um
&&
494 height_um
== other
.height_um
&&
495 is_continuous_feed
== other
.is_continuous_feed
;
498 Interval::Interval() : start(0), end(0) {
501 Interval::Interval(int32 start
, int32 end
) : start(start
), end(end
) {
504 Interval::Interval(int32 start
) : start(start
), end(kMaxPageNumber
) {
507 bool Interval::operator==(const Interval
& other
) const {
508 return start
== other
.start
&& end
== other
.end
;
511 template <const char* kName
>
514 static std::string
GetCapabilityPath() {
515 std::string result
= kSectionPrinter
;
521 static std::string
GetTicketItemPath() {
522 std::string result
= kSectionPrint
;
529 class NoValueValidation
{
531 template <class Option
>
532 static bool IsValid(const Option
&) {
537 class ContentTypeTraits
: public NoValueValidation
,
538 public ItemsTraits
<kOptionContentType
> {
540 static bool Load(const base::DictionaryValue
& dict
, ContentType
* option
) {
541 return dict
.GetString(kKeyContentType
, option
);
544 static void Save(ContentType option
, base::DictionaryValue
* dict
) {
545 dict
->SetString(kKeyContentType
, option
);
549 class PwgRasterConfigTraits
: public NoValueValidation
,
550 public ItemsTraits
<kOptionPwgRasterConfig
> {
552 static bool Load(const base::DictionaryValue
& dict
, PwgRasterConfig
* option
) {
553 std::string document_sheet_back
;
554 PwgRasterConfig option_out
;
555 if (dict
.GetString(kPwgRasterDocumentSheetBack
, &document_sheet_back
)) {
556 if (!TypeFromString(kDocumentSheetBackNames
,
558 &option_out
.document_sheet_back
)) {
563 dict
.GetBoolean(kPwgRasterReverseOrderStreaming
,
564 &option_out
.reverse_order_streaming
);
565 dict
.GetBoolean(kPwgRasterRotateAllPages
, &option_out
.rotate_all_pages
);
566 *option
= option_out
;
570 static void Save(const PwgRasterConfig
& option
, base::DictionaryValue
* dict
) {
572 kPwgRasterDocumentSheetBack
,
573 TypeToString(kDocumentSheetBackNames
, option
.document_sheet_back
));
574 if (option
.reverse_order_streaming
)
575 dict
->SetBoolean(kPwgRasterReverseOrderStreaming
,
576 option
.reverse_order_streaming
);
578 if (option
.rotate_all_pages
)
579 dict
->SetBoolean(kPwgRasterRotateAllPages
, option
.rotate_all_pages
);
583 class ColorTraits
: public ItemsTraits
<kOptionColor
> {
585 static bool IsValid(const Color
& option
) { return option
.IsValid(); }
587 static bool Load(const base::DictionaryValue
& dict
, Color
* option
) {
588 std::string type_str
;
589 if (!dict
.GetString(kKeyType
, &type_str
))
591 if (!TypeFromString(kColorNames
, type_str
, &option
->type
))
593 dict
.GetString(kKeyVendorId
, &option
->vendor_id
);
594 dict
.GetString(kCustomName
, &option
->custom_display_name
);
598 static void Save(const Color
& option
, base::DictionaryValue
* dict
) {
599 dict
->SetString(kKeyType
, TypeToString(kColorNames
, option
.type
));
600 if (!option
.vendor_id
.empty())
601 dict
->SetString(kKeyVendorId
, option
.vendor_id
);
602 if (!option
.custom_display_name
.empty())
603 dict
->SetString(kCustomName
, option
.custom_display_name
);
607 class DuplexTraits
: public NoValueValidation
,
608 public ItemsTraits
<kOptionDuplex
> {
610 static bool Load(const base::DictionaryValue
& dict
, DuplexType
* option
) {
611 std::string type_str
;
612 return dict
.GetString(kKeyType
, &type_str
) &&
613 TypeFromString(kDuplexNames
, type_str
, option
);
616 static void Save(DuplexType option
, base::DictionaryValue
* dict
) {
617 dict
->SetString(kKeyType
, TypeToString(kDuplexNames
, option
));
621 class OrientationTraits
: public NoValueValidation
,
622 public ItemsTraits
<kOptionPageOrientation
> {
624 static bool Load(const base::DictionaryValue
& dict
, OrientationType
* option
) {
625 std::string type_str
;
626 return dict
.GetString(kKeyType
, &type_str
) &&
627 TypeFromString(kOrientationNames
, type_str
, option
);
630 static void Save(OrientationType option
, base::DictionaryValue
* dict
) {
631 dict
->SetString(kKeyType
, TypeToString(kOrientationNames
, option
));
635 class CopiesTraits
: public ItemsTraits
<kOptionCopies
> {
637 static bool IsValid(int32 option
) { return option
>= 1; }
639 static bool Load(const base::DictionaryValue
& dict
, int32
* option
) {
640 return dict
.GetInteger(kOptionCopies
, option
);
643 static void Save(int32 option
, base::DictionaryValue
* dict
) {
644 dict
->SetInteger(kOptionCopies
, option
);
648 class MarginsTraits
: public NoValueValidation
,
649 public ItemsTraits
<kOptionMargins
> {
651 static bool Load(const base::DictionaryValue
& dict
, Margins
* option
) {
652 std::string type_str
;
653 if (!dict
.GetString(kKeyType
, &type_str
))
655 if (!TypeFromString(kMarginsNames
, type_str
, &option
->type
))
657 return dict
.GetInteger(kMargineTop
, &option
->top_um
) &&
658 dict
.GetInteger(kMargineRight
, &option
->right_um
) &&
659 dict
.GetInteger(kMargineBottom
, &option
->bottom_um
) &&
660 dict
.GetInteger(kMargineLeft
, &option
->left_um
);
663 static void Save(const Margins
& option
, base::DictionaryValue
* dict
) {
664 dict
->SetString(kKeyType
, TypeToString(kMarginsNames
, option
.type
));
665 dict
->SetInteger(kMargineTop
, option
.top_um
);
666 dict
->SetInteger(kMargineRight
, option
.right_um
);
667 dict
->SetInteger(kMargineBottom
, option
.bottom_um
);
668 dict
->SetInteger(kMargineLeft
, option
.left_um
);
672 class DpiTraits
: public ItemsTraits
<kOptionDpi
> {
674 static bool IsValid(const Dpi
& option
) { return option
.IsValid(); }
676 static bool Load(const base::DictionaryValue
& dict
, Dpi
* option
) {
677 if (!dict
.GetInteger(kDpiHorizontal
, &option
->horizontal
) ||
678 !dict
.GetInteger(kDpiVertical
, &option
->vertical
)) {
684 static void Save(const Dpi
& option
, base::DictionaryValue
* dict
) {
685 dict
->SetInteger(kDpiHorizontal
, option
.horizontal
);
686 dict
->SetInteger(kDpiVertical
, option
.vertical
);
690 class FitToPageTraits
: public NoValueValidation
,
691 public ItemsTraits
<kOptionFitToPage
> {
693 static bool Load(const base::DictionaryValue
& dict
, FitToPageType
* option
) {
694 std::string type_str
;
695 return dict
.GetString(kKeyType
, &type_str
) &&
696 TypeFromString(kFitToPageNames
, type_str
, option
);
699 static void Save(FitToPageType option
, base::DictionaryValue
* dict
) {
700 dict
->SetString(kKeyType
, TypeToString(kFitToPageNames
, option
));
704 class PageRangeTraits
: public ItemsTraits
<kOptionPageRange
> {
706 static bool IsValid(const PageRange
& option
) {
707 for (size_t i
= 0; i
< option
.size(); ++i
) {
708 if (option
[i
].start
< 1 || option
[i
].end
< 1) {
715 static bool Load(const base::DictionaryValue
& dict
, PageRange
* option
) {
716 const base::ListValue
* list
= NULL
;
717 if (!dict
.GetList(kPageRangeInterval
, &list
))
719 for (size_t i
= 0; i
< list
->GetSize(); ++i
) {
720 const base::DictionaryValue
* interval
= NULL
;
721 if (!list
->GetDictionary(i
, &interval
))
723 Interval
new_interval(1, kMaxPageNumber
);
724 interval
->GetInteger(kPageRangeStart
, &new_interval
.start
);
725 interval
->GetInteger(kPageRangeEnd
, &new_interval
.end
);
726 option
->push_back(new_interval
);
731 static void Save(const PageRange
& option
, base::DictionaryValue
* dict
) {
732 if (!option
.empty()) {
733 base::ListValue
* list
= new base::ListValue
;
734 dict
->Set(kPageRangeInterval
, list
);
735 for (size_t i
= 0; i
< option
.size(); ++i
) {
736 base::DictionaryValue
* interval
= new base::DictionaryValue
;
737 list
->Append(interval
);
738 interval
->SetInteger(kPageRangeStart
, option
[i
].start
);
739 if (option
[i
].end
< kMaxPageNumber
)
740 interval
->SetInteger(kPageRangeEnd
, option
[i
].end
);
746 class MediaTraits
: public ItemsTraits
<kOptionMediaSize
> {
748 static bool IsValid(const Media
& option
) { return option
.IsValid(); }
750 static bool Load(const base::DictionaryValue
& dict
, Media
* option
) {
751 std::string type_str
;
752 if (dict
.GetString(kKeyName
, &type_str
)) {
753 if (!TypeFromString(kMediaDefinitions
, type_str
, &option
->type
))
757 dict
.GetInteger(kMediaWidth
, &option
->width_um
);
758 dict
.GetInteger(kMediaHeight
, &option
->height_um
);
759 dict
.GetBoolean(kMediaIsContinuous
, &option
->is_continuous_feed
);
760 dict
.GetString(kCustomName
, &option
->custom_display_name
);
764 static void Save(const Media
& option
, base::DictionaryValue
* dict
) {
765 if (option
.type
!= CUSTOM_MEDIA
)
766 dict
->SetString(kKeyName
, TypeToString(kMediaDefinitions
, option
.type
));
767 if (!option
.custom_display_name
.empty() || option
.type
== CUSTOM_MEDIA
)
768 dict
->SetString(kCustomName
, option
.custom_display_name
);
769 if (option
.width_um
> 0)
770 dict
->SetInteger(kMediaWidth
, option
.width_um
);
771 if (option
.height_um
> 0)
772 dict
->SetInteger(kMediaHeight
, option
.height_um
);
773 if (option
.is_continuous_feed
)
774 dict
->SetBoolean(kMediaIsContinuous
, true);
778 class CollateTraits
: public NoValueValidation
,
779 public ItemsTraits
<kOptionCollate
> {
781 static const bool kDefault
= true;
783 static bool Load(const base::DictionaryValue
& dict
, bool* option
) {
784 return dict
.GetBoolean(kOptionCollate
, option
);
787 static void Save(bool option
, base::DictionaryValue
* dict
) {
788 dict
->SetBoolean(kOptionCollate
, option
);
792 class ReverseTraits
: public NoValueValidation
,
793 public ItemsTraits
<kOptionReverse
> {
795 static const bool kDefault
= false;
797 static bool Load(const base::DictionaryValue
& dict
, bool* option
) {
798 return dict
.GetBoolean(kOptionReverse
, option
);
801 static void Save(bool option
, base::DictionaryValue
* dict
) {
802 dict
->SetBoolean(kOptionReverse
, option
);
806 } // namespace printer
808 using namespace printer
;
810 template class ListCapability
<ContentType
, ContentTypeTraits
>;
811 template class ValueCapability
<PwgRasterConfig
, PwgRasterConfigTraits
>;
812 template class SelectionCapability
<Color
, ColorTraits
>;
813 template class SelectionCapability
<DuplexType
, DuplexTraits
>;
814 template class SelectionCapability
<OrientationType
, OrientationTraits
>;
815 template class SelectionCapability
<Margins
, MarginsTraits
>;
816 template class SelectionCapability
<Dpi
, DpiTraits
>;
817 template class SelectionCapability
<FitToPageType
, FitToPageTraits
>;
818 template class SelectionCapability
<Media
, MediaTraits
>;
819 template class EmptyCapability
<class CopiesTraits
>;
820 template class EmptyCapability
<class PageRangeTraits
>;
821 template class BooleanCapability
<class CollateTraits
>;
822 template class BooleanCapability
<class ReverseTraits
>;
824 template class TicketItem
<PwgRasterConfig
, PwgRasterConfigTraits
>;
825 template class TicketItem
<Color
, ColorTraits
>;
826 template class TicketItem
<DuplexType
, DuplexTraits
>;
827 template class TicketItem
<OrientationType
, OrientationTraits
>;
828 template class TicketItem
<Margins
, MarginsTraits
>;
829 template class TicketItem
<Dpi
, DpiTraits
>;
830 template class TicketItem
<FitToPageType
, FitToPageTraits
>;
831 template class TicketItem
<Media
, MediaTraits
>;
832 template class TicketItem
<int32
, CopiesTraits
>;
833 template class TicketItem
<PageRange
, PageRangeTraits
>;
834 template class TicketItem
<bool, CollateTraits
>;
835 template class TicketItem
<bool, ReverseTraits
>;
837 } // namespace cloud_devices