| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 return is_job_pending_; | 217 return is_job_pending_; |
| 218 } | 218 } |
| 219 | 219 |
| 220 PrintedDocument* PrintJob::document() const { | 220 PrintedDocument* PrintJob::document() const { |
| 221 return document_.get(); | 221 return document_.get(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 #if defined(OS_WIN) | 224 #if defined(OS_WIN) |
| 225 class PrintJob::PdfConversionState { | 225 class PrintJob::PdfConversionState { |
| 226 public: | 226 public: |
| 227 PdfConversionState(gfx::Size page_size, | 227 PdfConversionState(gfx::Size page_size, gfx::Rect content_area) |
| 228 gfx::Rect content_area, | |
| 229 std::unique_ptr<PdfConverter> converter) | |
| 230 : page_count_(0), | 228 : page_count_(0), |
| 231 current_page_(0), | 229 current_page_(0), |
| 232 pages_in_progress_(0), | 230 pages_in_progress_(0), |
| 233 page_size_(page_size), | 231 page_size_(page_size), |
| 234 content_area_(content_area), | 232 content_area_(content_area) {} |
| 235 converter_(std::move(converter)) {} | |
| 236 | 233 |
| 237 void Start(const scoped_refptr<base::RefCountedMemory>& data, | 234 void Start(const scoped_refptr<base::RefCountedMemory>& data, |
| 238 const PdfRenderSettings& conversion_settings, | 235 const PdfRenderSettings& conversion_settings, |
| 239 const PdfConverter::StartCallback& start_callback) { | 236 const PdfConverter::StartCallback& start_callback) { |
| 240 converter_->Start(data, conversion_settings, start_callback); | 237 converter_ = std::move(PdfConverter::StartPdfToEmfConverter( |
| 238 data, conversion_settings, start_callback)); |
| 241 } | 239 } |
| 242 | 240 |
| 243 void GetMorePages(const PdfConverter::GetPageCallback& get_page_callback) { | 241 void GetMorePages(const PdfConverter::GetPageCallback& get_page_callback) { |
| 244 const int kMaxNumberOfTempFilesPerDocument = 3; | 242 const int kMaxNumberOfTempFilesPerDocument = 3; |
| 245 while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && | 243 while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && |
| 246 current_page_ < page_count_) { | 244 current_page_ < page_count_) { |
| 247 ++pages_in_progress_; | 245 ++pages_in_progress_; |
| 248 converter_->GetPage(current_page_++, get_page_callback); | 246 converter_->GetPage(current_page_++, get_page_callback); |
| 249 } | 247 } |
| 250 } | 248 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 274 pdf_page_mapping_.push_back(page_number); | 272 pdf_page_mapping_.push_back(page_number); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void PrintJob::StartPdfToEmfConversion( | 275 void PrintJob::StartPdfToEmfConversion( |
| 278 const scoped_refptr<base::RefCountedMemory>& bytes, | 276 const scoped_refptr<base::RefCountedMemory>& bytes, |
| 279 const gfx::Size& page_size, | 277 const gfx::Size& page_size, |
| 280 const gfx::Rect& content_area, | 278 const gfx::Rect& content_area, |
| 281 bool print_text_with_gdi) { | 279 bool print_text_with_gdi) { |
| 282 DCHECK(!pdf_conversion_state_); | 280 DCHECK(!pdf_conversion_state_); |
| 283 pdf_conversion_state_ = | 281 pdf_conversion_state_ = |
| 284 base::MakeUnique<PdfConversionState>(page_size, content_area, | 282 base::MakeUnique<PdfConversionState>(page_size, content_area); |
| 285 PdfConverter::CreatePdfToEmfConverter()); | |
| 286 const int kPrinterDpi = settings().dpi(); | 283 const int kPrinterDpi = settings().dpi(); |
| 287 PdfRenderSettings settings( | 284 PdfRenderSettings settings( |
| 288 content_area, gfx::Point(0, 0), kPrinterDpi, /*autorotate=*/true, | 285 content_area, gfx::Point(0, 0), kPrinterDpi, /*autorotate=*/true, |
| 289 print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT | 286 print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT |
| 290 : PdfRenderSettings::Mode::NORMAL); | 287 : PdfRenderSettings::Mode::NORMAL); |
| 291 pdf_conversion_state_->Start( | 288 pdf_conversion_state_->Start( |
| 292 bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); | 289 bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); |
| 293 } | 290 } |
| 294 | 291 |
| 295 void PrintJob::OnPdfConversionStarted(int page_count) { | 292 void PrintJob::OnPdfConversionStarted(int page_count) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 322 pdf_conversion_state_->GetMorePages( | 319 pdf_conversion_state_->GetMorePages( |
| 323 base::Bind(&PrintJob::OnPdfPageConverted, this)); | 320 base::Bind(&PrintJob::OnPdfPageConverted, this)); |
| 324 } | 321 } |
| 325 | 322 |
| 326 void PrintJob::StartPdfToPostScriptConversion( | 323 void PrintJob::StartPdfToPostScriptConversion( |
| 327 const scoped_refptr<base::RefCountedMemory>& bytes, | 324 const scoped_refptr<base::RefCountedMemory>& bytes, |
| 328 const gfx::Rect& content_area, | 325 const gfx::Rect& content_area, |
| 329 const gfx::Point& physical_offsets, | 326 const gfx::Point& physical_offsets, |
| 330 bool ps_level2) { | 327 bool ps_level2) { |
| 331 DCHECK(!pdf_conversion_state_); | 328 DCHECK(!pdf_conversion_state_); |
| 332 pdf_conversion_state_ = base::MakeUnique<PdfConversionState>( | 329 pdf_conversion_state_ = |
| 333 gfx::Size(), gfx::Rect(), PdfConverter::CreatePdfToPostScriptConverter()); | 330 base::MakeUnique<PdfConversionState>(gfx::Size(), gfx::Rect()); |
| 334 const int kPrinterDpi = settings().dpi(); | 331 const int kPrinterDpi = settings().dpi(); |
| 335 PdfRenderSettings settings( | 332 PdfRenderSettings settings( |
| 336 content_area, physical_offsets, kPrinterDpi, true /* autorotate? */, | 333 content_area, physical_offsets, kPrinterDpi, true /* autorotate? */, |
| 337 ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 | 334 ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 |
| 338 : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3); | 335 : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3); |
| 339 pdf_conversion_state_->Start( | 336 pdf_conversion_state_->Start( |
| 340 bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); | 337 bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); |
| 341 } | 338 } |
| 342 #endif // defined(OS_WIN) | 339 #endif // defined(OS_WIN) |
| 343 | 340 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 } | 474 } |
| 478 | 475 |
| 479 JobEventDetails::~JobEventDetails() { | 476 JobEventDetails::~JobEventDetails() { |
| 480 } | 477 } |
| 481 | 478 |
| 482 PrintedDocument* JobEventDetails::document() const { return document_.get(); } | 479 PrintedDocument* JobEventDetails::document() const { return document_.get(); } |
| 483 | 480 |
| 484 PrintedPage* JobEventDetails::page() const { return page_.get(); } | 481 PrintedPage* JobEventDetails::page() const { return page_.get(); } |
| 485 | 482 |
| 486 } // namespace printing | 483 } // namespace printing |
| OLD | NEW |