Skip to content

Commit

Permalink
Merge pull request #9044 from rreimann/1-4-x
Browse files Browse the repository at this point in the history
Fix printing selected pages on Windows
  • Loading branch information
kevinsawicki committed Apr 4, 2017
2 parents 2cddb5b + 3d54b23 commit 634eb67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions chromium_src/chrome/browser/printing/print_job.cc
Expand Up @@ -270,6 +270,10 @@ class PrintJob::PdfToEmfState {
std::unique_ptr<PdfToEmfConverter> converter_;
};

void PrintJob::AppendPrintedPage(int page_number) {
pdf_page_mapping_.push_back(page_number);
}

void PrintJob::StartPdfToEmfConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size,
Expand Down Expand Up @@ -298,14 +302,15 @@ void PrintJob::OnPdfToEmfPageConverted(int page_number,
float scale_factor,
std::unique_ptr<MetafilePlayer> emf) {
DCHECK(ptd_to_emf_state_);
if (!document_.get() || !emf) {
if (!document_.get() || !emf || page_number < 0 ||
static_cast<size_t>(page_number) >= pdf_page_mapping_.size()) {
ptd_to_emf_state_.reset();
Cancel();
return;
}

// Update the rendered document. It will send notifications to the listener.
document_->SetPage(page_number,
document_->SetPage(pdf_page_mapping_[page_number],
std::move(emf),
scale_factor,
ptd_to_emf_state_->page_size(),
Expand Down
5 changes: 5 additions & 0 deletions chromium_src/chrome/browser/printing/print_job.h
Expand Up @@ -6,6 +6,7 @@
#define CHROME_BROWSER_PRINTING_PRINT_JOB_H_

#include <memory>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
Expand Down Expand Up @@ -91,6 +92,9 @@ class PrintJob : public PrintJobWorkerOwner,
PrintedDocument* document() const;

#if defined(OS_WIN)
// Let the PrintJob know the 0-based |page_number| of a given printed page.
void AppendPrintedPage(int page_number);

void StartPdfToEmfConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size,
Expand Down Expand Up @@ -153,6 +157,7 @@ class PrintJob : public PrintJobWorkerOwner,
#if defined(OS_WIN)
class PdfToEmfState;
std::unique_ptr<PdfToEmfState> ptd_to_emf_state_;
std::vector<int> pdf_page_mapping_;
#endif // OS_WIN

// Used at shutdown so that we can quit a nested message loop.
Expand Down
Expand Up @@ -153,6 +153,7 @@ void PrintViewManagerBase::OnDidPrintPage(

ShouldQuitFromInnerMessageLoop();
#else
print_job_->AppendPrintedPage(params.page_number);
if (metafile_must_be_valid) {
scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes(
reinterpret_cast<const unsigned char*>(shared_buf.memory()),
Expand Down

0 comments on commit 634eb67

Please sign in to comment.