| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/print_system.h" | 5 #include "chrome/service/cloud_print/print_system.h" |
| 6 | 6 |
| 7 #include <objidl.h> | 7 #include <objidl.h> |
| 8 #include <winspool.h> | 8 #include <winspool.h> |
| 9 #include <xpsprint.h> | 9 #include <xpsprint.h> |
| 10 | 10 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 DevMode pt_dev_mode; | 399 DevMode pt_dev_mode; |
| 400 HRESULT hr = PrintTicketToDevMode(printer_name, print_ticket, | 400 HRESULT hr = PrintTicketToDevMode(printer_name, print_ticket, |
| 401 &pt_dev_mode); | 401 &pt_dev_mode); |
| 402 if (FAILED(hr)) { | 402 if (FAILED(hr)) { |
| 403 NOTREACHED(); | 403 NOTREACHED(); |
| 404 return false; | 404 return false; |
| 405 } | 405 } |
| 406 | 406 |
| 407 HDC dc = CreateDC(L"WINSPOOL", UTF8ToWide(printer_name).c_str(), | 407 HDC dc = CreateDC(L"WINSPOOL", UTF8ToWide(printer_name).c_str(), |
| 408 NULL, pt_dev_mode.dm_); | 408 NULL, pt_dev_mode.dm_); |
| 409 if (!dc) | 409 if (!dc) { |
| 410 NOTREACHED(); |
| 410 return false; | 411 return false; |
| 411 | 412 } |
| 412 printer_dc_.Set(dc); | |
| 413 hr = E_FAIL; | 413 hr = E_FAIL; |
| 414 DOCINFO di = {0}; | 414 DOCINFO di = {0}; |
| 415 di.cbSize = sizeof(DOCINFO); | 415 di.cbSize = sizeof(DOCINFO); |
| 416 std::wstring doc_name = UTF8ToWide(job_title); | 416 std::wstring doc_name = UTF8ToWide(job_title); |
| 417 di.lpszDocName = doc_name.c_str(); | 417 di.lpszDocName = doc_name.c_str(); |
| 418 job_id_ = StartDoc(dc, &di); | 418 job_id_ = StartDoc(dc, &di); |
| 419 if (job_id_ <= 0) | 419 if (job_id_ <= 0) |
| 420 return false; | 420 return false; |
| 421 | 421 |
| 422 saved_dc_ = SaveDC(printer_dc_.get()); | 422 printer_dc_.Set(dc); |
| 423 saved_dc_ = SaveDC(printer_dc_.Get()); |
| 423 print_data_file_path_ = print_data_file_path; | 424 print_data_file_path_ = print_data_file_path; |
| 424 delegate_ = delegate; | 425 delegate_ = delegate; |
| 425 RenderNextPDFPages(); | 426 RenderNextPDFPages(); |
| 426 } else if (print_data_mime_type == "application/vnd.ms-xpsdocument") { | 427 } else if (print_data_mime_type == "application/vnd.ms-xpsdocument") { |
| 427 bool ret = PrintXPSDocument(printer_name, | 428 bool ret = PrintXPSDocument(printer_name, |
| 428 job_title, | 429 job_title, |
| 429 print_data_file_path, | 430 print_data_file_path, |
| 430 print_ticket); | 431 print_ticket); |
| 431 if (ret) | 432 if (ret) |
| 432 delegate_ = delegate; | 433 delegate_ = delegate; |
| 433 return ret; | 434 return ret; |
| 434 } else { | 435 } else { |
| 435 NOTREACHED(); | 436 NOTREACHED(); |
| 436 return false; | 437 return false; |
| 437 } | 438 } |
| 438 return true; | 439 return true; |
| 439 } | 440 } |
| 440 | 441 |
| 441 void PreparePageDCForPrinting(HDC, double scale_factor) { | 442 void PreparePageDCForPrinting(HDC, double scale_factor) { |
| 442 SetGraphicsMode(printer_dc_.get(), GM_ADVANCED); | 443 SetGraphicsMode(printer_dc_.Get(), GM_ADVANCED); |
| 443 // Setup the matrix to translate and scale to the right place. Take in | 444 // Setup the matrix to translate and scale to the right place. Take in |
| 444 // account the scale factor. | 445 // account the scale factor. |
| 445 // Note that the printing output is relative to printable area of | 446 // Note that the printing output is relative to printable area of |
| 446 // the page. That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. | 447 // the page. That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. |
| 447 int offset_x = ::GetDeviceCaps(printer_dc_.get(), PHYSICALOFFSETX); | 448 int offset_x = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETX); |
| 448 int offset_y = ::GetDeviceCaps(printer_dc_.get(), PHYSICALOFFSETY); | 449 int offset_y = ::GetDeviceCaps(printer_dc_.Get(), PHYSICALOFFSETY); |
| 449 XFORM xform = {0}; | 450 XFORM xform = {0}; |
| 450 xform.eDx = static_cast<float>(-offset_x); | 451 xform.eDx = static_cast<float>(-offset_x); |
| 451 xform.eDy = static_cast<float>(-offset_y); | 452 xform.eDy = static_cast<float>(-offset_y); |
| 452 xform.eM11 = xform.eM22 = 1.0 / scale_factor; | 453 xform.eM11 = xform.eM22 = 1.0 / scale_factor; |
| 453 SetWorldTransform(printer_dc_.get(), &xform); | 454 SetWorldTransform(printer_dc_.Get(), &xform); |
| 454 } | 455 } |
| 455 | 456 |
| 456 // ServiceUtilityProcessHost::Client implementation. | 457 // ServiceUtilityProcessHost::Client implementation. |
| 457 virtual void OnRenderPDFPagesToMetafileSucceeded( | 458 virtual void OnRenderPDFPagesToMetafileSucceeded( |
| 458 const printing::Emf& metafile, | 459 const printing::Emf& metafile, |
| 459 int highest_rendered_page_number, | 460 int highest_rendered_page_number, |
| 460 double scale_factor) OVERRIDE { | 461 double scale_factor) OVERRIDE { |
| 461 PreparePageDCForPrinting(printer_dc_.get(), scale_factor); | 462 PreparePageDCForPrinting(printer_dc_.Get(), scale_factor); |
| 462 metafile.SafePlayback(printer_dc_.get()); | 463 metafile.SafePlayback(printer_dc_.Get()); |
| 463 bool done_printing = (highest_rendered_page_number != | 464 bool done_printing = (highest_rendered_page_number != |
| 464 last_page_printed_ + kPageCountPerBatch); | 465 last_page_printed_ + kPageCountPerBatch); |
| 465 last_page_printed_ = highest_rendered_page_number; | 466 last_page_printed_ = highest_rendered_page_number; |
| 466 if (done_printing) | 467 if (done_printing) |
| 467 PrintJobDone(); | 468 PrintJobDone(); |
| 468 else | 469 else |
| 469 RenderNextPDFPages(); | 470 RenderNextPDFPages(); |
| 470 } | 471 } |
| 471 | 472 |
| 472 // base::win::ObjectWatcher::Delegate implementation. | 473 // base::win::ObjectWatcher::Delegate implementation. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 507 |
| 507 virtual void OnChildDied() OVERRIDE { | 508 virtual void OnChildDied() OVERRIDE { |
| 508 PrintJobDone(); | 509 PrintJobDone(); |
| 509 } | 510 } |
| 510 | 511 |
| 511 private: | 512 private: |
| 512 void PrintJobDone() { | 513 void PrintJobDone() { |
| 513 // If there is no delegate, then there is nothing pending to process. | 514 // If there is no delegate, then there is nothing pending to process. |
| 514 if (!delegate_) | 515 if (!delegate_) |
| 515 return; | 516 return; |
| 516 RestoreDC(printer_dc_.get(), saved_dc_); | 517 RestoreDC(printer_dc_.Get(), saved_dc_); |
| 517 EndDoc(printer_dc_.get()); | 518 EndDoc(printer_dc_.Get()); |
| 518 if (-1 == last_page_printed_) { | 519 if (-1 == last_page_printed_) { |
| 519 delegate_->OnJobSpoolFailed(); | 520 delegate_->OnJobSpoolFailed(); |
| 520 } else { | 521 } else { |
| 521 delegate_->OnJobSpoolSucceeded(job_id_); | 522 delegate_->OnJobSpoolSucceeded(job_id_); |
| 522 } | 523 } |
| 523 delegate_ = NULL; | 524 delegate_ = NULL; |
| 524 } | 525 } |
| 525 | 526 |
| 526 void RenderNextPDFPages() { | 527 void RenderNextPDFPages() { |
| 527 printing::PageRange range; | 528 printing::PageRange range; |
| 528 // Render 10 pages at a time. | 529 // Render 10 pages at a time. |
| 529 range.from = last_page_printed_ + 1; | 530 range.from = last_page_printed_ + 1; |
| 530 range.to = last_page_printed_ + kPageCountPerBatch; | 531 range.to = last_page_printed_ + kPageCountPerBatch; |
| 531 std::vector<printing::PageRange> page_ranges; | 532 std::vector<printing::PageRange> page_ranges; |
| 532 page_ranges.push_back(range); | 533 page_ranges.push_back(range); |
| 533 | 534 |
| 534 int printer_dpi = ::GetDeviceCaps(printer_dc_.get(), LOGPIXELSX); | 535 int printer_dpi = ::GetDeviceCaps(printer_dc_.Get(), LOGPIXELSX); |
| 535 int dc_width = GetDeviceCaps(printer_dc_.get(), PHYSICALWIDTH); | 536 int dc_width = GetDeviceCaps(printer_dc_.Get(), PHYSICALWIDTH); |
| 536 int dc_height = GetDeviceCaps(printer_dc_.get(), PHYSICALHEIGHT); | 537 int dc_height = GetDeviceCaps(printer_dc_.Get(), PHYSICALHEIGHT); |
| 537 gfx::Rect render_area(0, 0, dc_width, dc_height); | 538 gfx::Rect render_area(0, 0, dc_width, dc_height); |
| 538 g_service_process->io_thread()->message_loop_proxy()->PostTask( | 539 g_service_process->io_thread()->message_loop_proxy()->PostTask( |
| 539 FROM_HERE, | 540 FROM_HERE, |
| 540 base::Bind(&JobSpoolerWin::Core::RenderPDFPagesInSandbox, this, | 541 base::Bind(&JobSpoolerWin::Core::RenderPDFPagesInSandbox, this, |
| 541 print_data_file_path_, render_area, printer_dpi, | 542 print_data_file_path_, render_area, printer_dpi, |
| 542 page_ranges, base::MessageLoopProxy::current())); | 543 page_ranges, base::MessageLoopProxy::current())); |
| 543 } | 544 } |
| 544 | 545 |
| 545 // Called on the service process IO thread. | 546 // Called on the service process IO thread. |
| 546 void RenderPDFPagesInSandbox( | 547 void RenderPDFPagesInSandbox( |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); | 880 RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); |
| 880 return ret; | 881 return ret; |
| 881 } | 882 } |
| 882 | 883 |
| 883 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 884 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
| 884 const base::DictionaryValue* print_system_settings) { | 885 const base::DictionaryValue* print_system_settings) { |
| 885 return new PrintSystemWin; | 886 return new PrintSystemWin; |
| 886 } | 887 } |
| 887 | 888 |
| 888 } // namespace cloud_print | 889 } // namespace cloud_print |
| OLD | NEW |