| 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/browser/printing/print_job.h" | 5 #include "chrome/browser/printing/print_job.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 const scoped_refptr<base::RefCountedMemory>& bytes, | 278 const scoped_refptr<base::RefCountedMemory>& bytes, |
| 279 const gfx::Size& page_size, | 279 const gfx::Size& page_size, |
| 280 const gfx::Rect& content_area, | 280 const gfx::Rect& content_area, |
| 281 bool print_text_with_gdi) { | 281 bool print_text_with_gdi) { |
| 282 DCHECK(!pdf_conversion_state_); | 282 DCHECK(!pdf_conversion_state_); |
| 283 pdf_conversion_state_ = | 283 pdf_conversion_state_ = |
| 284 base::MakeUnique<PdfConversionState>(page_size, content_area, | 284 base::MakeUnique<PdfConversionState>(page_size, content_area, |
| 285 PdfConverter::CreatePdfToEmfConverter()); | 285 PdfConverter::CreatePdfToEmfConverter()); |
| 286 const int kPrinterDpi = settings().dpi(); | 286 const int kPrinterDpi = settings().dpi(); |
| 287 PdfRenderSettings settings( | 287 PdfRenderSettings settings( |
| 288 content_area, kPrinterDpi, /*autorotate=*/true, | 288 content_area, gfx::Point(0,0), kPrinterDpi, /*autorotate=*/true, |
| 289 print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT | 289 print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT |
| 290 : PdfRenderSettings::Mode::NORMAL); | 290 : PdfRenderSettings::Mode::NORMAL); |
| 291 pdf_conversion_state_->Start( | 291 pdf_conversion_state_->Start( |
| 292 bytes, settings, | 292 bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); |
| 293 base::Bind(&PrintJob::OnPdfConversionStarted, this)); | |
| 294 } | 293 } |
| 295 | 294 |
| 296 void PrintJob::OnPdfConversionStarted(int page_count) { | 295 void PrintJob::OnPdfConversionStarted(int page_count) { |
| 297 if (page_count <= 0) { | 296 if (page_count <= 0) { |
| 298 pdf_conversion_state_.reset(); | 297 pdf_conversion_state_.reset(); |
| 299 Cancel(); | 298 Cancel(); |
| 300 return; | 299 return; |
| 301 } | 300 } |
| 302 pdf_conversion_state_->set_page_count(page_count); | 301 pdf_conversion_state_->set_page_count(page_count); |
| 303 pdf_conversion_state_->GetMorePages( | 302 pdf_conversion_state_->GetMorePages( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 316 } | 315 } |
| 317 | 316 |
| 318 // Update the rendered document. It will send notifications to the listener. | 317 // Update the rendered document. It will send notifications to the listener. |
| 319 document_->SetPage(pdf_page_mapping_[page_number], std::move(metafile), | 318 document_->SetPage(pdf_page_mapping_[page_number], std::move(metafile), |
| 320 scale_factor, pdf_conversion_state_->page_size(), | 319 scale_factor, pdf_conversion_state_->page_size(), |
| 321 pdf_conversion_state_->content_area()); | 320 pdf_conversion_state_->content_area()); |
| 322 | 321 |
| 323 pdf_conversion_state_->GetMorePages( | 322 pdf_conversion_state_->GetMorePages( |
| 324 base::Bind(&PrintJob::OnPdfPageConverted, this)); | 323 base::Bind(&PrintJob::OnPdfPageConverted, this)); |
| 325 } | 324 } |
| 325 |
| 326 void PrintJob::StartPdfToPostScriptConversion( |
| 327 const scoped_refptr<base::RefCountedMemory>& bytes, |
| 328 const gfx::Rect& content_area, |
| 329 const gfx::Point& physical_offsets, |
| 330 bool ps_level2) { |
| 331 DCHECK(!pdf_conversion_state_); |
| 332 pdf_conversion_state_ = base::MakeUnique<PdfConversionState>( |
| 333 gfx::Size(), gfx::Rect(), PdfConverter::CreatePdfToPostScriptConverter()); |
| 334 const int kPrinterDpi = settings().dpi(); |
| 335 PdfRenderSettings settings( |
| 336 content_area, physical_offsets, kPrinterDpi, true /* autorotate? */, |
| 337 ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 |
| 338 : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3); |
| 339 pdf_conversion_state_->Start( |
| 340 bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); |
| 341 } |
| 326 #endif // defined(OS_WIN) | 342 #endif // defined(OS_WIN) |
| 327 | 343 |
| 328 void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { | 344 void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { |
| 329 if (document_.get() == new_document) | 345 if (document_.get() == new_document) |
| 330 return; | 346 return; |
| 331 | 347 |
| 332 document_ = new_document; | 348 document_ = new_document; |
| 333 | 349 |
| 334 if (document_.get()) | 350 if (document_.get()) |
| 335 settings_ = document_->settings(); | 351 settings_ = document_->settings(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 477 } |
| 462 | 478 |
| 463 JobEventDetails::~JobEventDetails() { | 479 JobEventDetails::~JobEventDetails() { |
| 464 } | 480 } |
| 465 | 481 |
| 466 PrintedDocument* JobEventDetails::document() const { return document_.get(); } | 482 PrintedDocument* JobEventDetails::document() const { return document_.get(); } |
| 467 | 483 |
| 468 PrintedPage* JobEventDetails::page() const { return page_.get(); } | 484 PrintedPage* JobEventDetails::page() const { return page_.get(); } |
| 469 | 485 |
| 470 } // namespace printing | 486 } // namespace printing |
| OLD | NEW |