Commit 82637b85 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Make PDF printing transformations consistent between 1-up and N-up.

Currently, 1-up printing and N-up printing have separate paths that do
transformations on PDFs to fit them to the printable area for printing.
The 1-up path has been in use for years. The N-up path is in development
but has some trouble with certain PDFs.

To fix the N-up path, make it go through the 1-up path first. Now with a
properly transformed 1-up PDF, the N-up path can just do N-up layout in
addition. This also makes N-up PDF printing work correctly with the
scaling setting.

BUG=844211

Change-Id: I911187e585214ff40327752801c38bda8cf129b7
Reviewed-on: https://chromium-review.googlesource.com/1238078Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595118}
parent cd1d470c
......@@ -174,31 +174,27 @@ void FitContentsToPrintableAreaIfRequired(
// Performs N-up PDF generation for |doc| based on |pages_per_sheet| and
// the parameters in |print_settings|.
// On success, returns the N-up version of |doc|. On failure, returns nullptr.
ScopedFPDFDocument NupPdfToPdf(FPDF_DOCUMENT doc,
ScopedFPDFDocument NupPdfToPdf(ScopedFPDFDocument doc,
uint32_t pages_per_sheet,
const PP_PrintSettings_Dev& print_settings) {
DCHECK(doc);
DCHECK(ShouldDoNup(pages_per_sheet));
PP_Size page_size = print_settings.paper_size;
printing::NupParameters nup_params;
bool is_landscape = PDFiumPrint::IsSourcePdfLandscape(doc);
bool is_landscape = PDFiumPrint::IsSourcePdfLandscape(doc.get());
nup_params.SetParameters(pages_per_sheet, is_landscape);
// Import n pages to one.
PP_Size page_size = print_settings.paper_size;
bool paper_is_landscape = page_size.width > page_size.height;
if (nup_params.landscape() != paper_is_landscape)
std::swap(page_size.width, page_size.height);
ScopedFPDFDocument output_doc_nup(FPDF_ImportNPagesToOne(
doc, page_size.width, page_size.height, nup_params.num_pages_on_x_axis(),
nup_params.num_pages_on_y_axis()));
if (output_doc_nup) {
FitContentsToPrintableAreaIfRequired(output_doc_nup.get(), 1.0f,
print_settings);
}
return output_doc_nup;
ScopedFPDFDocument nup_doc(FPDF_ImportNPagesToOne(
doc.get(), page_size.width, page_size.height,
nup_params.num_pages_on_x_axis(), nup_params.num_pages_on_y_axis()));
if (nup_doc)
FitContentsToPrintableAreaIfRequired(nup_doc.get(), 1.0f, print_settings);
return nup_doc;
}
int GetBlockForJpeg(void* param,
......@@ -311,19 +307,17 @@ ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
return nullptr;
}
uint32_t pages_per_sheet = pdf_print_settings.pages_per_sheet;
if (ShouldDoNup(pages_per_sheet)) {
if (!FlattenPrintData(output_doc.get()))
return nullptr;
return NupPdfToPdf(output_doc.get(), pages_per_sheet, print_settings);
}
double scale_factor = pdf_print_settings.scale_factor / 100.0;
FitContentsToPrintableAreaIfRequired(output_doc.get(), scale_factor,
print_settings);
if (!FlattenPrintData(output_doc.get()))
return nullptr;
return output_doc;
uint32_t pages_per_sheet = pdf_print_settings.pages_per_sheet;
if (!ShouldDoNup(pages_per_sheet))
return output_doc;
return NupPdfToPdf(std::move(output_doc), pages_per_sheet, print_settings);
}
ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment