diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-14 20:19:54 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-14 20:19:54 +0000 |
commit | b3b6b6fca87730c2bdda9c75d06c8823731db433 (patch) | |
tree | e552af1b44c8871683ca0dac7d7e9518e3f1c71b /chrome/service | |
parent | d652c33131ef384aea1f3a794957c1154fbc599d (diff) | |
download | chromium_src-b3b6b6fca87730c2bdda9c75d06c8823731db433.zip chromium_src-b3b6b6fca87730c2bdda9c75d06c8823731db433.tar.gz chromium_src-b3b6b6fca87730c2bdda9c75d06c8823731db433.tar.bz2 |
Use XPS to set color for HP printers.
Wrap DocumentProperties into printing::CreateDevMode().
BUG=166587
Review URL: https://codereview.chromium.org/165993002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251408 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/cloud_print/cdd_conversion_win.cc | 31 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 77 |
2 files changed, 19 insertions, 89 deletions
diff --git a/chrome/service/cloud_print/cdd_conversion_win.cc b/chrome/service/cloud_print/cdd_conversion_win.cc index 4965309..f71ed64 100644 --- a/chrome/service/cloud_print/cdd_conversion_win.cc +++ b/chrome/service/cloud_print/cdd_conversion_win.cc @@ -17,6 +17,7 @@ bool IsValidCjt(const std::string& print_ticket_data) { scoped_ptr<DEVMODE[]> CjtToDevMode(const base::string16& printer_name, const std::string& print_ticket) { + using namespace cloud_devices::printer; cloud_devices::CloudDeviceDescription description; if (!description.InitFromString(print_ticket)) return scoped_ptr<DEVMODE[]>(); @@ -25,21 +26,22 @@ scoped_ptr<DEVMODE[]> CjtToDevMode(const base::string16& printer_name, if (!printer.OpenPrinter(printer_name.c_str())) return scoped_ptr<DEVMODE[]>(); - wchar_t* mutable_name = const_cast<wchar_t*>(printer_name.c_str()); - LONG buffer_size = - DocumentProperties(NULL, printer, mutable_name, NULL, NULL, 0); - if (buffer_size <= 0) + scoped_ptr<DEVMODE[]> scoped_dev_mode; + { + ColorTicketItem color; + if (color.LoadFrom(description)) { + bool is_color = color.value().type == STANDARD_COLOR; + scoped_dev_mode = CreateDevModeWithColor(printer, printer_name, is_color); + } else { + scoped_dev_mode = printing::CreateDevMode(printer, NULL); + } + } + + if (!scoped_dev_mode) return scoped_ptr<DEVMODE[]>(); - scoped_ptr<DEVMODE[]> scoped_dev_mode( - reinterpret_cast<DEVMODE*>(new uint8[buffer_size])); DEVMODE* dev_mode = scoped_dev_mode.get(); - if (DocumentProperties(NULL, printer, mutable_name, dev_mode, NULL, - DM_OUT_BUFFER) != IDOK) { - return scoped_ptr<DEVMODE[]>(); - } - using namespace cloud_devices::printer; ColorTicketItem color; DuplexTicketItem duplex; OrientationTicketItem orientation; @@ -120,12 +122,7 @@ scoped_ptr<DEVMODE[]> CjtToDevMode(const base::string16& printer_name, } } - if (DocumentProperties(NULL, printer, mutable_name, dev_mode, dev_mode, - DM_OUT_BUFFER | DM_IN_BUFFER) != IDOK) { - return scoped_ptr<DEVMODE[]>(); - } - - return scoped_dev_mode.Pass(); + return printing::CreateDevMode(printer, dev_mode); } std::string CapabilitiesToCdd( diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index 765ea0f..82d1c72 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -27,73 +27,6 @@ namespace cloud_print { namespace { -HRESULT StreamFromPrintTicket(const std::string& print_ticket, - IStream** stream) { - DCHECK(stream); - HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, stream); - if (FAILED(hr)) { - return hr; - } - ULONG bytes_written = 0; - (*stream)->Write(print_ticket.c_str(), print_ticket.length(), &bytes_written); - DCHECK(bytes_written == print_ticket.length()); - LARGE_INTEGER pos = {0}; - ULARGE_INTEGER new_pos = {0}; - (*stream)->Seek(pos, STREAM_SEEK_SET, &new_pos); - return S_OK; -} - -scoped_ptr<DEVMODE[]> XpsTicketToDevMode(const base::string16& printer_name, - const std::string& print_ticket) { - scoped_ptr<DEVMODE[]> scoped_dev_mode; - printing::ScopedXPSInitializer xps_initializer; - if (!xps_initializer.initialized()) { - // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) - return scoped_dev_mode.Pass(); - } - - printing::ScopedPrinterHandle printer; - if (!printer.OpenPrinter(printer_name.c_str())) - return scoped_dev_mode.Pass(); - - base::win::ScopedComPtr<IStream> pt_stream; - HRESULT hr = StreamFromPrintTicket(print_ticket, pt_stream.Receive()); - if (FAILED(hr)) - return scoped_dev_mode.Pass(); - - HPTPROVIDER provider = NULL; - hr = printing::XPSModule::OpenProvider(printer_name, 1, &provider); - if (SUCCEEDED(hr)) { - ULONG size = 0; - DEVMODE* dm = NULL; - // Use kPTJobScope, because kPTDocumentScope breaks duplex. - hr = printing::XPSModule::ConvertPrintTicketToDevMode(provider, - pt_stream, - kUserDefaultDevmode, - kPTJobScope, - &size, - &dm, - NULL); - if (SUCCEEDED(hr)) { - // Correct DEVMODE using DocumentProperties. See documentation for - // PTConvertPrintTicketToDevMode. - wchar_t* mutable_name = const_cast<wchar_t*>(printer_name.c_str()); - LONG buffer_size = DocumentProperties(NULL, printer, mutable_name, NULL, - dm, DM_IN_BUFFER); - if (buffer_size <= 0) - return scoped_ptr<DEVMODE[]>(); - scoped_dev_mode.reset(reinterpret_cast<DEVMODE*>(new uint8[buffer_size])); - if (DocumentProperties(NULL, printer, mutable_name, scoped_dev_mode.get(), - dm, DM_OUT_BUFFER | DM_IN_BUFFER) != IDOK) { - scoped_dev_mode.reset(); - } - printing::XPSModule::ReleaseMemory(dm); - } - printing::XPSModule::CloseProvider(provider); - } - return scoped_dev_mode.Pass(); -} - class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate { public: PrintSystemWatcherWin() @@ -331,16 +264,16 @@ class JobSpoolerWin : public PrintSystem::JobSpooler { NOTREACHED(); return false; } + base::string16 printer_wide = base::UTF8ToWide(printer_name); last_page_printed_ = -1; // We only support PDF and XPS documents for now. if (print_data_mime_type == kContentTypePDF) { scoped_ptr<DEVMODE[]> dev_mode; if (print_ticket_mime_type == kContentTypeJSON) { - dev_mode = CjtToDevMode(base::UTF8ToWide(printer_name), print_ticket); + dev_mode = CjtToDevMode(printer_wide, print_ticket); } else { DCHECK(print_ticket_mime_type == kContentTypeXML); - dev_mode = XpsTicketToDevMode(base::UTF8ToWide(printer_name), - print_ticket); + dev_mode = printing::XpsTicketToDevMode(printer_wide, print_ticket); } if (!dev_mode) { @@ -348,8 +281,8 @@ class JobSpoolerWin : public PrintSystem::JobSpooler { return false; } - HDC dc = CreateDC(L"WINSPOOL", base::UTF8ToWide(printer_name).c_str(), - NULL, dev_mode.get()); + HDC dc = CreateDC(L"WINSPOOL", printer_wide.c_str(), NULL, + dev_mode.get()); if (!dc) { NOTREACHED(); return false; |