Chromium Code Reviews| Index: chrome/browser/printing/print_job.cc |
| diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc |
| index 2569af4ea7743c7727f212f75da4edcab3654da5..9a85ed770800cbc4ab2d7f80429a787aab4b84b5 100644 |
| --- a/chrome/browser/printing/print_job.cc |
| +++ b/chrome/browser/printing/print_job.cc |
| @@ -17,6 +17,11 @@ |
| #include "printing/printed_document.h" |
| #include "printing/printed_page.h" |
| +#if defined(OS_WIN) |
| +#include "chrome/browser/printing/pdf_to_emf_converter.h" |
| +#include "printing/pdf_render_settings.h" |
| +#endif |
| + |
| using base::TimeDelta; |
| namespace { |
| @@ -37,6 +42,10 @@ PrintJob::PrintJob() |
| settings_(), |
| is_job_pending_(false), |
| is_canceling_(false), |
| +#if defined(OS_WIN) |
| + pdf_to_emf_page_count_(0), |
| + pdf_to_emf_current_page_(0), |
| +#endif |
| quit_factory_(this) { |
| // This is normally a UI message loop, but in unit tests, the message loop is |
| // of the 'default' type. |
| @@ -214,6 +223,57 @@ PrintedDocument* PrintJob::document() const { |
| return document_.get(); |
| } |
| +#if defined(OS_WIN) |
| +void PrintJob::ConvertPdfToEmf( |
| + const scoped_refptr<base::RefCountedMemory>& bytes, |
| + gfx::Size page_size, |
| + gfx::Rect content_area) { |
|
Lei Zhang
2014/09/15 21:49:53
Can you DCHECK here and in the callbacks to make s
Vitaly Buka (NO REVIEWS)
2014/09/15 22:33:50
Done.
|
| + DCHECK(!pdf_to_emf_converter_.get()); |
| + pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault(); |
| + const int kPrinterDpi = settings().dpi(); |
| + pdf_to_emf_page_size_ = page_size; |
|
Lei Zhang
2014/09/15 21:49:53
This is set once here for PDF file. Is the PDF fil
Vitaly Buka (NO REVIEWS)
2014/09/15 22:33:50
That's looks incorrect.
But I don't change behaiv
|
| + pdf_to_emf_content_area_ = content_area; |
| + pdf_to_emf_converter_->Start( |
| + bytes, |
| + printing::PdfRenderSettings(content_area, kPrinterDpi, true), |
| + base::Bind(&PrintJob::OnPdfLoaded, this)); |
| +} |
| + |
| +void PrintJob::OnPdfPageConvertedToEmf(int page_number, |
| + double scale_factor, |
| + scoped_ptr<MetafilePlayer> emf) { |
| + DCHECK(pdf_to_emf_converter_); |
| + if (!document_.get() || !emf) |
| + return OnPdfLoaded(false); |
| + |
| + // Update the rendered document. It will send notifications to the listener. |
| + document_->SetPage(pdf_to_emf_current_page_++, |
| + emf.Pass(), |
| + scale_factor, |
| + pdf_to_emf_page_size_, |
| + pdf_to_emf_content_area_); |
| + |
| + if (pdf_to_emf_current_page_ < pdf_to_emf_page_count_) |
|
Lei Zhang
2014/09/15 21:49:53
nit: wrap inner block in braces.
Vitaly Buka (NO REVIEWS)
2014/09/15 22:33:50
Done.
Vitaly Buka (NO REVIEWS)
2014/09/15 22:33:50
Done.
|
| + pdf_to_emf_converter_->GetPage( |
| + pdf_to_emf_current_page_, |
| + base::Bind(&PrintJob::OnPdfPageConvertedToEmf, this)); |
| +} |
| + |
| +void PrintJob::OnPdfLoaded(int page_count) { |
| + if (page_count <= 0) { |
| + pdf_to_emf_converter_.reset(); |
| + Cancel(); |
| + return; |
| + } |
| + pdf_to_emf_page_count_ = page_count; |
| + pdf_to_emf_current_page_ = 0; |
| + |
| + pdf_to_emf_converter_->GetPage( |
| + pdf_to_emf_current_page_, |
| + base::Bind(&PrintJob::OnPdfPageConvertedToEmf, this)); |
| +} |
| +#endif // OS_WIN |
| + |
| void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { |
| if (document_.get() == new_document) |
| return; |