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