| Index: chrome/browser/local_discovery/pwg_raster_converter.cc
|
| diff --git a/chrome/browser/local_discovery/pwg_raster_converter.cc b/chrome/browser/local_discovery/pwg_raster_converter.cc
|
| index 40f3b0e3c39d723e5fd4734e8fdbf60c39668578..11b6c317ca32294b876ae8cb8bd6db040d9dc1ee 100644
|
| --- a/chrome/browser/local_discovery/pwg_raster_converter.cc
|
| +++ b/chrome/browser/local_discovery/pwg_raster_converter.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "chrome/browser/local_discovery/pwg_raster_converter.h"
|
|
|
| +#include <algorithm>
|
| +
|
| #include "base/bind_helpers.h"
|
| #include "base/cancelable_callback.h"
|
| #include "base/files/file.h"
|
| @@ -12,12 +14,17 @@
|
| #include "base/logging.h"
|
| #include "chrome/common/chrome_utility_messages.h"
|
| #include "chrome/common/chrome_utility_printing_messages.h"
|
| +#include "components/cloud_devices/common/cloud_device_description.h"
|
| +#include "components/cloud_devices/common/printer_description.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/child_process_data.h"
|
| #include "content/public/browser/utility_process_host.h"
|
| #include "content/public/browser/utility_process_host_client.h"
|
| #include "printing/pdf_render_settings.h"
|
| #include "printing/pwg_raster_settings.h"
|
| +#include "printing/units.h"
|
| +#include "ui/gfx/geometry/rect.h"
|
| +#include "ui/gfx/geometry/size.h"
|
|
|
| namespace local_discovery {
|
|
|
| @@ -283,4 +290,70 @@ scoped_ptr<PWGRasterConverter> PWGRasterConverter::CreateDefault() {
|
| return scoped_ptr<PWGRasterConverter>(new PWGRasterConverterImpl());
|
| }
|
|
|
| +// static
|
| +printing::PdfRenderSettings PWGRasterConverter::GetConversionSettings(
|
| + const cloud_devices::CloudDeviceDescription& printer_capabilities,
|
| + const gfx::Size& page_size) {
|
| + int dpi = printing::kDefaultPdfDpi;
|
| + cloud_devices::printer::DpiCapability dpis;
|
| + if (dpis.LoadFrom(printer_capabilities))
|
| + dpi = std::max(dpis.GetDefault().horizontal, dpis.GetDefault().vertical);
|
| +
|
| + double scale = dpi;
|
| + scale /= printing::kPointsPerInch;
|
| +
|
| + // Make vertical rectangle to optimize streaming to printer. Fix orientation
|
| + // by autorotate.
|
| + gfx::Rect area(std::min(page_size.width(), page_size.height()) * scale,
|
| + std::max(page_size.width(), page_size.height()) * scale);
|
| + return printing::PdfRenderSettings(area, dpi, true /* autorotate */);
|
| +}
|
| +
|
| +// static
|
| +printing::PwgRasterSettings PWGRasterConverter::GetBitmapSettings(
|
| + const cloud_devices::CloudDeviceDescription& printer_capabilities,
|
| + const cloud_devices::CloudDeviceDescription& ticket) {
|
| + printing::PwgRasterSettings result;
|
| + cloud_devices::printer::PwgRasterConfigCapability raster_capability;
|
| + // If the raster capability fails to load, raster_capability will contain
|
| + // the default value.
|
| + raster_capability.LoadFrom(printer_capabilities);
|
| +
|
| + cloud_devices::printer::DuplexTicketItem duplex_item;
|
| + cloud_devices::printer::DuplexType duplex_value =
|
| + cloud_devices::printer::NO_DUPLEX;
|
| +
|
| + cloud_devices::printer::DocumentSheetBack document_sheet_back =
|
| + raster_capability.value().document_sheet_back;
|
| +
|
| + if (duplex_item.LoadFrom(ticket)) {
|
| + duplex_value = duplex_item.value();
|
| + }
|
| +
|
| + result.odd_page_transform = printing::TRANSFORM_NORMAL;
|
| + switch (duplex_value) {
|
| + case cloud_devices::printer::NO_DUPLEX:
|
| + result.odd_page_transform = printing::TRANSFORM_NORMAL;
|
| + break;
|
| + case cloud_devices::printer::LONG_EDGE:
|
| + if (document_sheet_back == cloud_devices::printer::ROTATED) {
|
| + result.odd_page_transform = printing::TRANSFORM_ROTATE_180;
|
| + } else if (document_sheet_back == cloud_devices::printer::FLIPPED) {
|
| + result.odd_page_transform = printing::TRANSFORM_FLIP_VERTICAL;
|
| + }
|
| + break;
|
| + case cloud_devices::printer::SHORT_EDGE:
|
| + if (document_sheet_back == cloud_devices::printer::MANUAL_TUMBLE) {
|
| + result.odd_page_transform = printing::TRANSFORM_ROTATE_180;
|
| + } else if (document_sheet_back == cloud_devices::printer::FLIPPED) {
|
| + result.odd_page_transform = printing::TRANSFORM_FLIP_HORIZONTAL;
|
| + }
|
| + }
|
| +
|
| + result.rotate_all_pages = raster_capability.value().rotate_all_pages;
|
| +
|
| + result.reverse_page_order = raster_capability.value().reverse_order_streaming;
|
| + return result;
|
| +}
|
| +
|
| } // namespace local_discovery
|
|
|