OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/local_discovery/pwg_raster_converter.h" | 5 #include "chrome/browser/local_discovery/pwg_raster_converter.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
8 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
9 #include "base/files/file.h" | 11 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "chrome/common/chrome_utility_messages.h" | 15 #include "chrome/common/chrome_utility_messages.h" |
14 #include "chrome/common/chrome_utility_printing_messages.h" | 16 #include "chrome/common/chrome_utility_printing_messages.h" |
| 17 #include "components/cloud_devices/common/cloud_device_description.h" |
| 18 #include "components/cloud_devices/common/printer_description.h" |
15 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
17 #include "content/public/browser/utility_process_host.h" | 21 #include "content/public/browser/utility_process_host.h" |
18 #include "content/public/browser/utility_process_host_client.h" | 22 #include "content/public/browser/utility_process_host_client.h" |
19 #include "printing/pdf_render_settings.h" | 23 #include "printing/pdf_render_settings.h" |
20 #include "printing/pwg_raster_settings.h" | 24 #include "printing/pwg_raster_settings.h" |
| 25 #include "printing/units.h" |
| 26 #include "ui/gfx/geometry/rect.h" |
| 27 #include "ui/gfx/geometry/size.h" |
21 | 28 |
22 namespace local_discovery { | 29 namespace local_discovery { |
23 | 30 |
24 namespace { | 31 namespace { |
25 | 32 |
26 using content::BrowserThread; | 33 using content::BrowserThread; |
27 | 34 |
28 class FileHandlers { | 35 class FileHandlers { |
29 public: | 36 public: |
30 FileHandlers() {} | 37 FileHandlers() {} |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 utility_client_->Convert(data, callback_.callback()); | 283 utility_client_->Convert(data, callback_.callback()); |
277 } | 284 } |
278 | 285 |
279 } // namespace | 286 } // namespace |
280 | 287 |
281 // static | 288 // static |
282 scoped_ptr<PWGRasterConverter> PWGRasterConverter::CreateDefault() { | 289 scoped_ptr<PWGRasterConverter> PWGRasterConverter::CreateDefault() { |
283 return scoped_ptr<PWGRasterConverter>(new PWGRasterConverterImpl()); | 290 return scoped_ptr<PWGRasterConverter>(new PWGRasterConverterImpl()); |
284 } | 291 } |
285 | 292 |
| 293 // static |
| 294 printing::PdfRenderSettings PWGRasterConverter::GetConversionSettings( |
| 295 const cloud_devices::CloudDeviceDescription& printer_capabilities, |
| 296 const gfx::Size& page_size) { |
| 297 int dpi = printing::kDefaultPdfDpi; |
| 298 cloud_devices::printer::DpiCapability dpis; |
| 299 if (dpis.LoadFrom(printer_capabilities)) |
| 300 dpi = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical); |
| 301 |
| 302 double scale = dpi; |
| 303 scale /= printing::kPointsPerInch; |
| 304 |
| 305 // Make vertical rectangle to optimize streaming to printer. Fix orientation |
| 306 // by autorotate. |
| 307 gfx::Rect area(std::min(page_size.width(), page_size.height()) * scale, |
| 308 std::max(page_size.width(), page_size.height()) * scale); |
| 309 return printing::PdfRenderSettings(area, dpi, true /* autorotate */); |
| 310 } |
| 311 |
| 312 // static |
| 313 printing::PwgRasterSettings PWGRasterConverter::GetBitmapSettings( |
| 314 const cloud_devices::CloudDeviceDescription& printer_capabilities, |
| 315 const cloud_devices::CloudDeviceDescription& ticket) { |
| 316 printing::PwgRasterSettings result; |
| 317 cloud_devices::printer::PwgRasterConfigCapability raster_capability; |
| 318 // If the raster capability fails to load, raster_capability will contain |
| 319 // the default value. |
| 320 raster_capability.LoadFrom(printer_capabilities); |
| 321 |
| 322 cloud_devices::printer::DuplexTicketItem duplex_item; |
| 323 cloud_devices::printer::DuplexType duplex_value = |
| 324 cloud_devices::printer::NO_DUPLEX; |
| 325 |
| 326 cloud_devices::printer::DocumentSheetBack document_sheet_back = |
| 327 raster_capability.value().document_sheet_back; |
| 328 |
| 329 if (duplex_item.LoadFrom(ticket)) { |
| 330 duplex_value = duplex_item.value(); |
| 331 } |
| 332 |
| 333 result.odd_page_transform = printing::TRANSFORM_NORMAL; |
| 334 switch (duplex_value) { |
| 335 case cloud_devices::printer::NO_DUPLEX: |
| 336 result.odd_page_transform = printing::TRANSFORM_NORMAL; |
| 337 break; |
| 338 case cloud_devices::printer::LONG_EDGE: |
| 339 if (document_sheet_back == cloud_devices::printer::ROTATED) { |
| 340 result.odd_page_transform = printing::TRANSFORM_ROTATE_180; |
| 341 } else if (document_sheet_back == cloud_devices::printer::FLIPPED) { |
| 342 result.odd_page_transform = printing::TRANSFORM_FLIP_VERTICAL; |
| 343 } |
| 344 break; |
| 345 case cloud_devices::printer::SHORT_EDGE: |
| 346 if (document_sheet_back == cloud_devices::printer::MANUAL_TUMBLE) { |
| 347 result.odd_page_transform = printing::TRANSFORM_ROTATE_180; |
| 348 } else if (document_sheet_back == cloud_devices::printer::FLIPPED) { |
| 349 result.odd_page_transform = printing::TRANSFORM_FLIP_HORIZONTAL; |
| 350 } |
| 351 } |
| 352 |
| 353 result.rotate_all_pages = raster_capability.value().rotate_all_pages; |
| 354 |
| 355 result.reverse_page_order = raster_capability.value().reverse_order_streaming; |
| 356 return result; |
| 357 } |
| 358 |
286 } // namespace local_discovery | 359 } // namespace local_discovery |
OLD | NEW |