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/printer_description.h" | 7 #include "components/cloud_devices/printer_description.h" |
8 #include "printing/backend/print_backend.h" | 8 #include "printing/backend/print_backend.h" |
9 #include "printing/backend/win_helper.h" | 9 #include "printing/backend/win_helper.h" |
10 | 10 |
11 namespace cloud_print { | 11 namespace cloud_print { |
12 | 12 |
| 13 bool IsValidCjt(const std::string& print_ticket_data) { |
| 14 cloud_devices::CloudDeviceDescription description; |
| 15 return description.InitFromString(print_ticket_data); |
| 16 } |
| 17 |
| 18 scoped_ptr<DEVMODE[]> CjtToDevMode(const base::string16& printer_name, |
| 19 const std::string& print_ticket) { |
| 20 cloud_devices::CloudDeviceDescription description; |
| 21 if (!description.InitFromString(print_ticket)) |
| 22 return scoped_ptr<DEVMODE[]>(); |
| 23 |
| 24 printing::ScopedPrinterHandle printer; |
| 25 if (!printer.OpenPrinter(printer_name.c_str())) |
| 26 return scoped_ptr<DEVMODE[]>(); |
| 27 |
| 28 wchar_t* mutable_name = const_cast<wchar_t*>(printer_name.c_str()); |
| 29 LONG buffer_size = |
| 30 DocumentProperties(NULL, printer, mutable_name, NULL, NULL, 0); |
| 31 if (buffer_size <= 0) |
| 32 return scoped_ptr<DEVMODE[]>(); |
| 33 |
| 34 scoped_ptr<DEVMODE[]> scoped_dev_mode( |
| 35 reinterpret_cast<DEVMODE*>(new uint8[buffer_size])); |
| 36 DEVMODE* dev_mode = scoped_dev_mode.get(); |
| 37 if (DocumentProperties(NULL, printer, mutable_name, dev_mode, NULL, |
| 38 DM_OUT_BUFFER) != IDOK) { |
| 39 return scoped_ptr<DEVMODE[]>(); |
| 40 } |
| 41 |
| 42 using namespace cloud_devices::printer; |
| 43 ColorTicketItem color; |
| 44 DuplexTicketItem duplex; |
| 45 OrientationTicketItem orientation; |
| 46 MarginsTicketItem margins; |
| 47 DpiTicketItem dpi; |
| 48 FitToPageTicketItem fit_to_page; |
| 49 MediaTicketItem media; |
| 50 CopiesTicketItem copies; |
| 51 PageRangeTicketItem page_range; |
| 52 CollateTicketItem collate; |
| 53 ReverseTicketItem reverse; |
| 54 |
| 55 if (orientation.LoadFrom(description)) { |
| 56 dev_mode->dmFields |= DM_ORIENTATION; |
| 57 if (orientation.value() == LANDSCAPE) { |
| 58 dev_mode->dmOrientation = DMORIENT_LANDSCAPE; |
| 59 } else { |
| 60 dev_mode->dmOrientation = DMORIENT_PORTRAIT; |
| 61 } |
| 62 } |
| 63 |
| 64 if (color.LoadFrom(description)) { |
| 65 dev_mode->dmFields |= DM_COLOR; |
| 66 if (color.value().type == STANDARD_MONOCHROME) { |
| 67 dev_mode->dmColor = DMCOLOR_MONOCHROME; |
| 68 } else if (color.value().type == STANDARD_COLOR) { |
| 69 dev_mode->dmColor = DMCOLOR_COLOR; |
| 70 } else { |
| 71 NOTREACHED(); |
| 72 } |
| 73 } |
| 74 |
| 75 if (duplex.LoadFrom(description)) { |
| 76 dev_mode->dmFields |= DM_DUPLEX; |
| 77 if (duplex.value() == NO_DUPLEX) { |
| 78 dev_mode->dmDuplex = DMDUP_SIMPLEX; |
| 79 } else if (duplex.value() == LONG_EDGE) { |
| 80 dev_mode->dmDuplex = DMDUP_VERTICAL; |
| 81 } else if (duplex.value() == SHORT_EDGE) { |
| 82 dev_mode->dmDuplex = DMDUP_HORIZONTAL; |
| 83 } else { |
| 84 NOTREACHED(); |
| 85 } |
| 86 } |
| 87 |
| 88 if (copies.LoadFrom(description)) { |
| 89 dev_mode->dmFields |= DM_COPIES; |
| 90 dev_mode->dmCopies = copies.value(); |
| 91 } |
| 92 |
| 93 if (dpi.LoadFrom(description)) { |
| 94 if (dpi.value().horizontal > 0) { |
| 95 dev_mode->dmFields |= DM_PRINTQUALITY; |
| 96 dev_mode->dmPrintQuality = dpi.value().horizontal; |
| 97 } |
| 98 if (dpi.value().vertical > 0) { |
| 99 dev_mode->dmFields |= DM_YRESOLUTION; |
| 100 dev_mode->dmYResolution = dpi.value().vertical; |
| 101 } |
| 102 } |
| 103 |
| 104 if (collate.LoadFrom(description)) { |
| 105 dev_mode->dmFields |= DM_COLLATE; |
| 106 dev_mode->dmCollate = (collate.value() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); |
| 107 } |
| 108 |
| 109 if (media.LoadFrom(description)) { |
| 110 static const size_t kFromUm = 100; // Windows uses 0.1mm. |
| 111 int width = media.value().width_um / kFromUm; |
| 112 int height = media.value().height_um / kFromUm; |
| 113 if (width > 0) { |
| 114 dev_mode->dmFields |= DM_PAPERWIDTH; |
| 115 dev_mode->dmPaperWidth = width; |
| 116 } |
| 117 if (height > 0) { |
| 118 dev_mode->dmFields |= DM_PAPERLENGTH; |
| 119 dev_mode->dmPaperLength = height; |
| 120 } |
| 121 } |
| 122 |
| 123 if (DocumentProperties(NULL, printer, mutable_name, dev_mode, dev_mode, |
| 124 DM_OUT_BUFFER | DM_IN_BUFFER) != IDOK) { |
| 125 return scoped_ptr<DEVMODE[]>(); |
| 126 } |
| 127 |
| 128 return scoped_dev_mode.Pass(); |
| 129 } |
| 130 |
13 std::string CapabilitiesToCdd( | 131 std::string CapabilitiesToCdd( |
14 const printing::PrinterSemanticCapsAndDefaults& semantic_info) { | 132 const printing::PrinterSemanticCapsAndDefaults& semantic_info) { |
15 using namespace cloud_devices::printer; | 133 using namespace cloud_devices::printer; |
16 cloud_devices::CloudDeviceDescription description; | 134 cloud_devices::CloudDeviceDescription description; |
17 | 135 |
18 ContentTypesCapability content_types; | 136 ContentTypesCapability content_types; |
19 content_types.AddOption("application/pdf"); | 137 content_types.AddOption("application/pdf"); |
20 content_types.SaveTo(&description); | 138 content_types.SaveTo(&description); |
21 | 139 |
22 ColorCapability color; | 140 ColorCapability color; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (dpi.IsValid()) { | 222 if (dpi.IsValid()) { |
105 dpi.SaveTo(&description); | 223 dpi.SaveTo(&description); |
106 } else { | 224 } else { |
107 NOTREACHED(); | 225 NOTREACHED(); |
108 } | 226 } |
109 } | 227 } |
110 return description.ToString(); | 228 return description.ToString(); |
111 } | 229 } |
112 | 230 |
113 } // namespace cloud_print | 231 } // namespace cloud_print |
OLD | NEW |