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