[unseasoned-pdf] Store print settings in blink::WebPrintParams
Replace usage of PP_PrintSettings_Dev and PP_PdfPrintSettings_Dev by converting them to blink::WebPrintParams as soon as they enter OutOfProcessInstance. Accordingly, replace Pepper struct usage throughout PDF printing code, thus making it compatible with the Pepper-free plugin. Bug: 1200000 Change-Id: I713e4250acbfe9ed73aefbf6c48b8d1e312e5377 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2950949 Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#892266}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
deed5a8fe4
commit
2e6d957fd5
@ -282,6 +282,7 @@ if (enable_pdf) {
|
||||
deps = [
|
||||
"//base",
|
||||
"//ppapi/cpp:objects",
|
||||
"//printing/mojom",
|
||||
"//skia",
|
||||
"//third_party/blink/public:blink",
|
||||
"//third_party/blink/public/common:headers",
|
||||
@ -322,6 +323,7 @@ if (enable_pdf) {
|
||||
"//ppapi/cpp:objects",
|
||||
"//ppapi/cpp/private:internal_module",
|
||||
"//skia",
|
||||
"//third_party/blink/public:blink_headers",
|
||||
"//third_party/blink/public/common:headers",
|
||||
"//ui/base",
|
||||
"//ui/base/cursor/mojom:cursor_type",
|
||||
|
@ -736,9 +736,8 @@ int32_t OutOfProcessInstance::PdfPrintBegin(
|
||||
if ((print_settings->format & supported_formats) == 0)
|
||||
return 0;
|
||||
|
||||
print_settings_.is_printing = true;
|
||||
print_settings_.pepper_print_settings = *print_settings;
|
||||
print_settings_.pdf_print_settings = *pdf_print_settings;
|
||||
print_params_ =
|
||||
WebPrintParamsFromPPPrintSettings(*print_settings, *pdf_print_settings);
|
||||
engine()->PrintBegin();
|
||||
return ret;
|
||||
}
|
||||
@ -761,10 +760,10 @@ int32_t OutOfProcessInstance::PrintBegin(
|
||||
pp::Resource OutOfProcessInstance::PrintPages(
|
||||
const PP_PrintPageNumberRange_Dev* page_ranges,
|
||||
uint32_t page_range_count) {
|
||||
if (!print_settings_.is_printing)
|
||||
if (!print_params_.has_value())
|
||||
return pp::Resource();
|
||||
|
||||
print_settings_.print_pages_called = true;
|
||||
print_pages_called_ = true;
|
||||
if (page_range_count == 0)
|
||||
return pp::Resource();
|
||||
|
||||
@ -772,8 +771,7 @@ pp::Resource OutOfProcessInstance::PrintPages(
|
||||
PageNumbersFromPPPrintPageNumberRange(page_ranges, page_range_count);
|
||||
|
||||
const std::vector<uint8_t> pdf_data =
|
||||
engine()->PrintPages(page_numbers, print_settings_.pepper_print_settings,
|
||||
print_settings_.pdf_print_settings);
|
||||
engine()->PrintPages(page_numbers, print_params_.value());
|
||||
|
||||
// Convert buffer to Pepper type.
|
||||
pp::Buffer_Dev buffer;
|
||||
@ -786,9 +784,10 @@ pp::Resource OutOfProcessInstance::PrintPages(
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::PrintEnd() {
|
||||
if (print_settings_.print_pages_called)
|
||||
if (print_pages_called_)
|
||||
UserMetricsRecordAction("PDF.PrintPage");
|
||||
print_settings_.Clear();
|
||||
print_pages_called_ = false;
|
||||
print_params_.reset();
|
||||
engine()->PrintEnd();
|
||||
}
|
||||
|
||||
@ -1358,11 +1357,4 @@ void OutOfProcessInstance::OnPrint(int32_t /*unused_but_required*/) {
|
||||
pp::PDF::Print(this);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::PrintSettings::Clear() {
|
||||
is_printing = false;
|
||||
print_pages_called = false;
|
||||
memset(&pepper_print_settings, 0, sizeof(pepper_print_settings));
|
||||
memset(&pdf_print_settings, 0, sizeof(pdf_print_settings));
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "ppapi/cpp/image_data.h"
|
||||
#include "ppapi/cpp/instance.h"
|
||||
#include "ppapi/cpp/private/find_private.h"
|
||||
#include "third_party/blink/public/web/web_print_params.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
@ -192,27 +193,11 @@ class OutOfProcessInstance : public PdfViewPluginBase,
|
||||
// The Pepper image data that is in sync with mutable_image_data().
|
||||
pp::ImageData pepper_image_data_;
|
||||
|
||||
struct PrintSettings {
|
||||
PrintSettings() { Clear(); }
|
||||
// Assigned a value only between `PdfPrintBegin()` and `PrintEnd()` calls.
|
||||
absl::optional<blink::WebPrintParams> print_params_;
|
||||
|
||||
void Clear();
|
||||
|
||||
// This is set to true when PdfPrintBegin() is called and false when
|
||||
// PrintEnd() is called.
|
||||
bool is_printing;
|
||||
|
||||
// To know whether this was an actual print operation, so we don't double
|
||||
// count UMA logging.
|
||||
bool print_pages_called;
|
||||
|
||||
// Generic print settings.
|
||||
PP_PrintSettings_Dev pepper_print_settings;
|
||||
|
||||
// PDF-specific print settings.
|
||||
PP_PdfPrintSettings_Dev pdf_print_settings;
|
||||
};
|
||||
|
||||
PrintSettings print_settings_;
|
||||
// For identifying actual print operations to avoid double logging of UMA.
|
||||
bool print_pages_called_;
|
||||
|
||||
// The PreviewModeClient used for print preview. Will be passed to
|
||||
// `preview_engine_`.
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "pdf/document_layout.h"
|
||||
#include "pdf/ppapi_migration/callback.h"
|
||||
#include "ppapi/c/dev/ppp_printing_dev.h"
|
||||
#include "ppapi/cpp/completion_callback.h"
|
||||
#include "ppapi/cpp/private/pdf.h"
|
||||
#include "ppapi/cpp/url_loader.h"
|
||||
@ -41,7 +40,6 @@ typedef void (*PDFEnsureTypefaceCharactersAccessible)(const LOGFONT* font,
|
||||
size_t text_length);
|
||||
#endif
|
||||
|
||||
struct PP_PdfPrintSettings_Dev;
|
||||
class SkBitmap;
|
||||
|
||||
namespace base {
|
||||
@ -50,6 +48,7 @@ class Location;
|
||||
|
||||
namespace blink {
|
||||
class WebInputEvent;
|
||||
struct WebPrintParams;
|
||||
} // namespace blink
|
||||
|
||||
namespace gfx {
|
||||
@ -322,8 +321,7 @@ class PDFEngine {
|
||||
virtual void PrintBegin() = 0;
|
||||
virtual std::vector<uint8_t> PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) = 0;
|
||||
const blink::WebPrintParams& print_params) = 0;
|
||||
virtual void PrintEnd() = 0;
|
||||
virtual void StartFind(const std::string& text, bool case_sensitive) = 0;
|
||||
virtual bool SelectFindResult(bool forward) = 0;
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "third_party/blink/public/common/input/web_pointer_properties.h"
|
||||
#include "third_party/blink/public/common/input/web_touch_event.h"
|
||||
#include "third_party/blink/public/common/input/web_touch_point.h"
|
||||
#include "third_party/blink/public/web/web_print_params.h"
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
#include "third_party/pdfium/public/fpdf_annot.h"
|
||||
#include "third_party/pdfium/public/fpdf_attachment.h"
|
||||
@ -967,25 +968,19 @@ void PDFiumEngine::PrintBegin() {
|
||||
|
||||
std::vector<uint8_t> PDFiumEngine::PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
const blink::WebPrintParams& print_params) {
|
||||
DCHECK(!page_numbers.empty());
|
||||
|
||||
if ((print_settings.format & PP_PRINTOUTPUTFORMAT_PDF) &&
|
||||
HasPermission(PERMISSION_PRINT_HIGH_QUALITY)) {
|
||||
return PrintPagesAsPdf(page_numbers, print_settings, pdf_print_settings);
|
||||
}
|
||||
if (HasPermission(PERMISSION_PRINT_LOW_QUALITY)) {
|
||||
return PrintPagesAsRasterPdf(page_numbers, print_settings,
|
||||
pdf_print_settings);
|
||||
}
|
||||
return std::vector<uint8_t>();
|
||||
return print_params.rasterize_pdf
|
||||
? PrintPagesAsRasterPdf(page_numbers, print_params)
|
||||
: PrintPagesAsPdf(page_numbers, print_params);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> PDFiumEngine::PrintPagesAsRasterPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
const blink::WebPrintParams& print_params) {
|
||||
DCHECK(HasPermission(PERMISSION_PRINT_LOW_QUALITY));
|
||||
|
||||
// If document is not downloaded yet, disable printing.
|
||||
if (doc() && !doc_loader_->IsDocumentComplete())
|
||||
return std::vector<uint8_t>();
|
||||
@ -994,14 +989,13 @@ std::vector<uint8_t> PDFiumEngine::PrintPagesAsRasterPdf(
|
||||
|
||||
SetLastInstance();
|
||||
|
||||
return print_.PrintPagesAsPdf(page_numbers, print_settings,
|
||||
pdf_print_settings, /*raster=*/true);
|
||||
return print_.PrintPagesAsPdf(page_numbers, print_params);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> PDFiumEngine::PrintPagesAsPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
const blink::WebPrintParams& print_params) {
|
||||
DCHECK(HasPermission(PERMISSION_PRINT_HIGH_QUALITY));
|
||||
DCHECK(doc());
|
||||
|
||||
KillFormFocus();
|
||||
@ -1012,8 +1006,7 @@ std::vector<uint8_t> PDFiumEngine::PrintPagesAsPdf(
|
||||
pages_[page_number]->Unload();
|
||||
}
|
||||
|
||||
return print_.PrintPagesAsPdf(page_numbers, print_settings,
|
||||
pdf_print_settings, /*raster=*/false);
|
||||
return print_.PrintPagesAsPdf(page_numbers, print_params);
|
||||
}
|
||||
|
||||
void PDFiumEngine::KillFormFocus() {
|
||||
|
@ -99,8 +99,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
void PrintBegin() override;
|
||||
std::vector<uint8_t> PrintPages(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) override;
|
||||
const blink::WebPrintParams& print_params) override;
|
||||
void PrintEnd() override;
|
||||
void StartFind(const std::string& text, bool case_sensitive) override;
|
||||
bool SelectFindResult(bool forward) override;
|
||||
@ -414,13 +413,11 @@ class PDFiumEngine : public PDFEngine,
|
||||
|
||||
std::vector<uint8_t> PrintPagesAsRasterPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings);
|
||||
const blink::WebPrintParams& print_params);
|
||||
|
||||
std::vector<uint8_t> PrintPagesAsPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings);
|
||||
const blink::WebPrintParams& print_params);
|
||||
|
||||
// Checks if `page` has selected text in a form element. If so, sets that as
|
||||
// the plugin's text selection.
|
||||
|
@ -13,12 +13,10 @@
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
|
||||
#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
|
||||
#include "pdf/ppapi_migration/geometry_conversions.h"
|
||||
#include "ppapi/c/dev/ppp_printing_dev.h"
|
||||
#include "ppapi/c/private/ppp_pdf.h"
|
||||
#include "printing/nup_parameters.h"
|
||||
#include "printing/page_setup.h"
|
||||
#include "printing/units.h"
|
||||
#include "third_party/blink/public/web/web_print_params.h"
|
||||
#include "third_party/pdfium/public/fpdf_flatten.h"
|
||||
#include "third_party/pdfium/public/fpdf_ppo.h"
|
||||
#include "third_party/pdfium/public/fpdf_transformpage.h"
|
||||
@ -72,11 +70,12 @@ void SetPageSizeAndContentRect(bool rotated,
|
||||
}
|
||||
|
||||
// Transform `page` contents to fit in the selected printer paper size.
|
||||
void TransformPDFPageForPrinting(FPDF_PAGE page,
|
||||
float scale_factor,
|
||||
PP_PrintScalingOption_Dev scaling_option,
|
||||
const gfx::Size& paper_size,
|
||||
const gfx::Rect& printable_area) {
|
||||
void TransformPDFPageForPrinting(
|
||||
FPDF_PAGE page,
|
||||
float scale_factor,
|
||||
printing::mojom::PrintScalingOption scaling_option,
|
||||
const gfx::Size& paper_size,
|
||||
const gfx::Rect& printable_area) {
|
||||
// Get the source page width and height in points.
|
||||
gfx::SizeF src_page_size(FPDF_GetPageWidthF(page), FPDF_GetPageHeightF(page));
|
||||
const int src_page_rotation = FPDFPage_GetRotation(page);
|
||||
@ -97,12 +96,12 @@ void TransformPDFPageForPrinting(FPDF_PAGE page,
|
||||
gfx::Rect gfx_printed_rect;
|
||||
bool fitted_scaling;
|
||||
switch (scaling_option) {
|
||||
case PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA:
|
||||
case printing::mojom::PrintScalingOption::kFitToPrintableArea:
|
||||
gfx_printed_rect = gfx::Rect(content_rect.x(), content_rect.y(),
|
||||
content_rect.width(), content_rect.height());
|
||||
fitted_scaling = true;
|
||||
break;
|
||||
case PP_PRINTSCALINGOPTION_FIT_TO_PAPER:
|
||||
case printing::mojom::PrintScalingOption::kFitToPaper:
|
||||
gfx_printed_rect = gfx::Rect(page_size.width(), page_size.height());
|
||||
fitted_scaling = true;
|
||||
break;
|
||||
@ -166,11 +165,11 @@ void TransformPDFPageForPrinting(FPDF_PAGE page,
|
||||
void FitContentsToPrintableAreaIfRequired(
|
||||
FPDF_DOCUMENT doc,
|
||||
float scale_factor,
|
||||
PP_PrintScalingOption_Dev scaling_option,
|
||||
printing::mojom::PrintScalingOption scaling_option,
|
||||
const gfx::Size& paper_size,
|
||||
const gfx::Rect& printable_area) {
|
||||
// Check to see if we need to fit pdf contents to printer paper size.
|
||||
if (scaling_option == PP_PRINTSCALINGOPTION_SOURCE_SIZE)
|
||||
if (scaling_option == printing::mojom::PrintScalingOption::kSourceSize)
|
||||
return;
|
||||
|
||||
int num_pages = FPDF_GetPageCount(doc);
|
||||
@ -292,20 +291,21 @@ void PDFiumPrint::FitContentsToPrintableArea(FPDF_DOCUMENT doc,
|
||||
const gfx::Size& page_size,
|
||||
const gfx::Rect& printable_area) {
|
||||
FitContentsToPrintableAreaIfRequired(
|
||||
doc, /*scale_factor=*/1.0f, PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA,
|
||||
page_size, printable_area);
|
||||
doc, /*scale_factor=*/1.0f,
|
||||
printing::mojom::PrintScalingOption::kFitToPrintableArea, page_size,
|
||||
printable_area);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> PDFiumPrint::PrintPagesAsPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings,
|
||||
bool raster) {
|
||||
const blink::WebPrintParams& print_params) {
|
||||
std::vector<uint8_t> buffer;
|
||||
ScopedFPDFDocument output_doc =
|
||||
CreatePrintPdf(page_numbers, print_settings, pdf_print_settings);
|
||||
if (raster)
|
||||
output_doc = CreateRasterPdf(std::move(output_doc), print_settings);
|
||||
ScopedFPDFDocument output_doc = CreatePrintPdf(page_numbers, print_params);
|
||||
if (print_params.rasterize_pdf) {
|
||||
output_doc =
|
||||
CreateRasterPdf(std::move(output_doc), print_params.printer_dpi);
|
||||
}
|
||||
|
||||
if (GetDocumentPageCount(output_doc.get()))
|
||||
buffer = ConvertDocToBuffer(std::move(output_doc));
|
||||
return buffer;
|
||||
@ -313,8 +313,7 @@ std::vector<uint8_t> PDFiumPrint::PrintPagesAsPdf(
|
||||
|
||||
ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
const blink::WebPrintParams& print_params) {
|
||||
ScopedFPDFDocument output_doc(FPDF_CreateNewDocument());
|
||||
DCHECK(output_doc);
|
||||
FPDF_CopyViewerPreferences(output_doc.get(), engine_->doc());
|
||||
@ -325,36 +324,29 @@ ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
float scale_factor = pdf_print_settings.scale_factor / 100.0f;
|
||||
float scale_factor = print_params.scale_factor / 100.0f;
|
||||
FitContentsToPrintableAreaIfRequired(
|
||||
output_doc.get(), scale_factor, print_settings.print_scaling_option,
|
||||
SizeFromPPSize(print_settings.paper_size),
|
||||
RectFromPPRect(print_settings.printable_area));
|
||||
output_doc.get(), scale_factor, print_params.print_scaling_option,
|
||||
print_params.paper_size, print_params.printable_area);
|
||||
if (!FlattenPrintData(output_doc.get()))
|
||||
return nullptr;
|
||||
|
||||
uint32_t pages_per_sheet = pdf_print_settings.pages_per_sheet;
|
||||
uint32_t pages_per_sheet = print_params.pages_per_sheet;
|
||||
if (!ShouldDoNup(pages_per_sheet))
|
||||
return output_doc;
|
||||
|
||||
gfx::Size page_size(print_settings.paper_size.width,
|
||||
print_settings.paper_size.height);
|
||||
gfx::Rect printable_area(print_settings.printable_area.point.x,
|
||||
print_settings.printable_area.point.y,
|
||||
print_settings.printable_area.size.width,
|
||||
print_settings.printable_area.size.height);
|
||||
gfx::Rect symmetrical_printable_area =
|
||||
printing::PageSetup::GetSymmetricalPrintableArea(page_size,
|
||||
printable_area);
|
||||
printing::PageSetup::GetSymmetricalPrintableArea(
|
||||
print_params.paper_size, print_params.printable_area);
|
||||
if (symmetrical_printable_area.IsEmpty())
|
||||
return nullptr;
|
||||
return CreateNupPdfDocument(std::move(output_doc), pages_per_sheet, page_size,
|
||||
return CreateNupPdfDocument(std::move(output_doc), pages_per_sheet,
|
||||
print_params.paper_size,
|
||||
symmetrical_printable_area);
|
||||
}
|
||||
|
||||
ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(
|
||||
ScopedFPDFDocument doc,
|
||||
const PP_PrintSettings_Dev& print_settings) {
|
||||
ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(ScopedFPDFDocument doc,
|
||||
int dpi) {
|
||||
int page_count = GetDocumentPageCount(doc.get());
|
||||
if (page_count == 0)
|
||||
return nullptr;
|
||||
@ -369,7 +361,7 @@ ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(
|
||||
return nullptr;
|
||||
|
||||
ScopedFPDFDocument temp_doc =
|
||||
CreateSinglePageRasterPdf(pdf_page.get(), print_settings);
|
||||
CreateSinglePageRasterPdf(pdf_page.get(), dpi);
|
||||
if (!temp_doc)
|
||||
return nullptr;
|
||||
|
||||
@ -382,7 +374,7 @@ ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(
|
||||
|
||||
ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
|
||||
FPDF_PAGE page_to_print,
|
||||
const PP_PrintSettings_Dev& print_settings) {
|
||||
int dpi) {
|
||||
ScopedFPDFDocument temp_doc(FPDF_CreateNewDocument());
|
||||
DCHECK(temp_doc);
|
||||
|
||||
@ -391,10 +383,8 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
|
||||
|
||||
// For computing size in pixels, use a square dpi since the source PDF page
|
||||
// has square DPI.
|
||||
int width_in_pixels =
|
||||
ConvertUnit(source_page_width, kPointsPerInch, print_settings.dpi);
|
||||
int height_in_pixels =
|
||||
ConvertUnit(source_page_height, kPointsPerInch, print_settings.dpi);
|
||||
int width_in_pixels = ConvertUnit(source_page_width, kPointsPerInch, dpi);
|
||||
int height_in_pixels = ConvertUnit(source_page_height, kPointsPerInch, dpi);
|
||||
|
||||
gfx::Size bitmap_size(width_in_pixels, height_in_pixels);
|
||||
ScopedFPDFBitmap bitmap(FPDFBitmap_Create(
|
||||
@ -405,13 +395,10 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
|
||||
bitmap_size.height(), 0xFFFFFFFF);
|
||||
|
||||
FPDF_RenderPageBitmap(bitmap.get(), page_to_print, 0, 0, bitmap_size.width(),
|
||||
bitmap_size.height(), print_settings.orientation,
|
||||
FPDF_PRINTING);
|
||||
bitmap_size.height(), /*rotate=*/0, FPDF_PRINTING);
|
||||
|
||||
double ratio_x = ConvertUnitDouble(bitmap_size.width(), print_settings.dpi,
|
||||
kPointsPerInch);
|
||||
double ratio_y = ConvertUnitDouble(bitmap_size.height(), print_settings.dpi,
|
||||
kPointsPerInch);
|
||||
double ratio_x = ConvertUnitDouble(bitmap_size.width(), dpi, kPointsPerInch);
|
||||
double ratio_y = ConvertUnitDouble(bitmap_size.height(), dpi, kPointsPerInch);
|
||||
|
||||
// Add the bitmap to an image object and add the image object to the output
|
||||
// page.
|
||||
|
@ -12,8 +12,9 @@
|
||||
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
|
||||
#include "third_party/pdfium/public/fpdfview.h"
|
||||
|
||||
struct PP_PdfPrintSettings_Dev;
|
||||
struct PP_PrintSettings_Dev;
|
||||
namespace blink {
|
||||
struct WebPrintParams;
|
||||
} // namespace blink
|
||||
|
||||
namespace gfx {
|
||||
class Rect;
|
||||
@ -62,23 +63,16 @@ class PDFiumPrint {
|
||||
|
||||
std::vector<uint8_t> PrintPagesAsPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings,
|
||||
bool raster);
|
||||
const blink::WebPrintParams& print_params);
|
||||
|
||||
private:
|
||||
ScopedFPDFDocument CreatePrintPdf(
|
||||
const std::vector<int>& page_numbers,
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings);
|
||||
ScopedFPDFDocument CreatePrintPdf(const std::vector<int>& page_numbers,
|
||||
const blink::WebPrintParams& print_params);
|
||||
|
||||
ScopedFPDFDocument CreateRasterPdf(
|
||||
ScopedFPDFDocument doc,
|
||||
const PP_PrintSettings_Dev& print_settings);
|
||||
ScopedFPDFDocument CreateRasterPdf(ScopedFPDFDocument doc, int dpi);
|
||||
|
||||
ScopedFPDFDocument CreateSinglePageRasterPdf(
|
||||
FPDF_PAGE page_to_print,
|
||||
const PP_PrintSettings_Dev& print_settings);
|
||||
ScopedFPDFDocument CreateSinglePageRasterPdf(FPDF_PAGE page_to_print,
|
||||
int dpi);
|
||||
|
||||
PDFiumEngine* const engine_;
|
||||
};
|
||||
|
@ -12,12 +12,11 @@
|
||||
#include "pdf/pdfium/pdfium_engine_exports.h"
|
||||
#include "pdf/pdfium/pdfium_test_base.h"
|
||||
#include "pdf/test/test_client.h"
|
||||
#include "ppapi/c/dev/ppp_printing_dev.h"
|
||||
#include "ppapi/c/private/ppp_pdf.h"
|
||||
#include "printing/pdf_render_settings.h"
|
||||
#include "printing/units.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/blink/public/web/web_print_params.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
|
||||
@ -31,12 +30,21 @@ namespace {
|
||||
// Number of color channels in a BGRA bitmap.
|
||||
constexpr int kColorChannels = 4;
|
||||
|
||||
constexpr PP_Size kUSLetterSize = {612, 792};
|
||||
constexpr PP_Rect kUSLetterRect = {{0, 0}, kUSLetterSize};
|
||||
constexpr PP_Rect kPrintableAreaRect = {{18, 18}, {576, 733}};
|
||||
constexpr gfx::Size kUSLetterSize = {612, 792};
|
||||
constexpr gfx::Rect kUSLetterRect = {{0, 0}, kUSLetterSize};
|
||||
constexpr gfx::Rect kPrintableAreaRect = {{18, 18}, {576, 733}};
|
||||
|
||||
using ExpectedDimensions = std::vector<gfx::SizeF>;
|
||||
|
||||
blink::WebPrintParams GetDefaultPrintParams() {
|
||||
blink::WebPrintParams params;
|
||||
params.print_content_area = kUSLetterRect;
|
||||
params.printable_area = kUSLetterRect;
|
||||
params.paper_size = kUSLetterSize;
|
||||
params.print_scaling_option = printing::mojom::PrintScalingOption::kNone;
|
||||
return params;
|
||||
}
|
||||
|
||||
void CheckPdfDimensions(const std::vector<uint8_t>& pdf_data,
|
||||
const ExpectedDimensions& expected_dimensions) {
|
||||
PDFiumEngineExports exports;
|
||||
@ -95,54 +103,39 @@ TEST_F(PDFiumPrintTest, Basic) {
|
||||
|
||||
PDFiumPrint print(engine.get());
|
||||
|
||||
constexpr PP_PrintSettings_Dev print_settings = {kUSLetterRect,
|
||||
kUSLetterRect,
|
||||
kUSLetterSize,
|
||||
72,
|
||||
PP_PRINTORIENTATION_NORMAL,
|
||||
PP_PRINTSCALINGOPTION_NONE,
|
||||
PP_FALSE,
|
||||
PP_PRINTOUTPUTFORMAT_PDF};
|
||||
constexpr PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100};
|
||||
blink::WebPrintParams print_params = GetDefaultPrintParams();
|
||||
blink::WebPrintParams print_params_raster = print_params;
|
||||
print_params_raster.rasterize_pdf = true;
|
||||
|
||||
{
|
||||
// Print 2 pages.
|
||||
const ExpectedDimensions kExpectedDimensions = {{612.0, 792.0},
|
||||
{612.0, 792.0}};
|
||||
const std::vector<int> pages = {0, 1};
|
||||
std::vector<uint8_t> pdf_data =
|
||||
print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/false);
|
||||
std::vector<uint8_t> pdf_data = print.PrintPagesAsPdf(pages, print_params);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/true);
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_params_raster);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
}
|
||||
{
|
||||
// Print 1 page.
|
||||
const ExpectedDimensions kExpectedDimensions = {{612.0, 792.0}};
|
||||
const std::vector<int> pages = {0};
|
||||
std::vector<uint8_t> pdf_data =
|
||||
print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/false);
|
||||
std::vector<uint8_t> pdf_data = print.PrintPagesAsPdf(pages, print_params);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/true);
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_params_raster);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
}
|
||||
{
|
||||
// Print the other page.
|
||||
const ExpectedDimensions kExpectedDimensions = {{612.0, 792.0}};
|
||||
const std::vector<int> pages = {1};
|
||||
std::vector<uint8_t> pdf_data =
|
||||
print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/false);
|
||||
std::vector<uint8_t> pdf_data = print.PrintPagesAsPdf(pages, print_params);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/true);
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_params_raster);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
}
|
||||
}
|
||||
@ -155,15 +148,12 @@ TEST_F(PDFiumPrintTest, AlterScaling) {
|
||||
|
||||
PDFiumPrint print(engine.get());
|
||||
|
||||
PP_PrintSettings_Dev print_settings = {kPrintableAreaRect,
|
||||
kUSLetterRect,
|
||||
kUSLetterSize,
|
||||
72,
|
||||
PP_PRINTORIENTATION_NORMAL,
|
||||
PP_PRINTSCALINGOPTION_NONE,
|
||||
PP_FALSE,
|
||||
PP_PRINTOUTPUTFORMAT_PDF};
|
||||
constexpr PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100};
|
||||
blink::WebPrintParams print_params = GetDefaultPrintParams();
|
||||
print_params.printable_area = kPrintableAreaRect;
|
||||
|
||||
blink::WebPrintParams print_params_raster = print_params;
|
||||
print_params_raster.rasterize_pdf = true;
|
||||
|
||||
const ExpectedDimensions kExpectedDimensions = {{612.0, 792.0}};
|
||||
const std::vector<int> pages = {0};
|
||||
|
||||
@ -173,53 +163,49 @@ TEST_F(PDFiumPrintTest, AlterScaling) {
|
||||
static constexpr char kChecksumRaster[] =
|
||||
"1ab7bfd2c59f6ffb7b1eb0885a9cf18d";
|
||||
|
||||
std::vector<uint8_t> pdf_data =
|
||||
print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/false);
|
||||
std::vector<uint8_t> pdf_data = print.PrintPagesAsPdf(pages, print_params);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
CheckPdfRendering(pdf_data, 0, kExpectedDimensions[0], kChecksum);
|
||||
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/true);
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_params_raster);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
CheckPdfRendering(pdf_data, 0, kExpectedDimensions[0], kChecksumRaster);
|
||||
}
|
||||
{
|
||||
// "Fit to Page" scaling
|
||||
print_settings.print_scaling_option =
|
||||
PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA;
|
||||
// "Fit to Printable Area" scaling
|
||||
print_params.print_scaling_option =
|
||||
printing::mojom::PrintScalingOption::kFitToPrintableArea;
|
||||
print_params_raster.print_scaling_option =
|
||||
printing::mojom::PrintScalingOption::kFitToPrintableArea;
|
||||
|
||||
static constexpr char kChecksum[] = "41847e1f0c581150a84794482528f790";
|
||||
static constexpr char kChecksumRaster[] =
|
||||
"f8c460d4b1a57e6dc580b88aadc73653";
|
||||
|
||||
std::vector<uint8_t> pdf_data =
|
||||
print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/false);
|
||||
std::vector<uint8_t> pdf_data = print.PrintPagesAsPdf(pages, print_params);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
CheckPdfRendering(pdf_data, 0, kExpectedDimensions[0], kChecksum);
|
||||
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/true);
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_params_raster);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
CheckPdfRendering(pdf_data, 0, kExpectedDimensions[0], kChecksumRaster);
|
||||
}
|
||||
{
|
||||
// "Fit to Paper" scaling
|
||||
print_settings.print_scaling_option = PP_PRINTSCALINGOPTION_FIT_TO_PAPER;
|
||||
print_params.print_scaling_option =
|
||||
printing::mojom::PrintScalingOption::kFitToPaper;
|
||||
print_params_raster.print_scaling_option =
|
||||
printing::mojom::PrintScalingOption::kFitToPaper;
|
||||
|
||||
static constexpr char kChecksum[] = "3a4828228bcbae230574c057b7a0669e";
|
||||
static constexpr char kChecksumRaster[] =
|
||||
"93b20afea37f1ec437061c7affc03918";
|
||||
|
||||
std::vector<uint8_t> pdf_data =
|
||||
print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/false);
|
||||
std::vector<uint8_t> pdf_data = print.PrintPagesAsPdf(pages, print_params);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
CheckPdfRendering(pdf_data, 0, kExpectedDimensions[0], kChecksum);
|
||||
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_settings, pdf_print_settings,
|
||||
/*raster=*/true);
|
||||
pdf_data = print.PrintPagesAsPdf(pages, print_params_raster);
|
||||
CheckPdfDimensions(pdf_data, kExpectedDimensions);
|
||||
CheckPdfRendering(pdf_data, 0, kExpectedDimensions[0], kChecksumRaster);
|
||||
}
|
||||
|
@ -9,7 +9,12 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "pdf/ppapi_migration/geometry_conversions.h"
|
||||
#include "ppapi/c/dev/pp_print_settings_dev.h"
|
||||
#include "ppapi/c/dev/ppp_printing_dev.h"
|
||||
#include "ppapi/c/private/ppp_pdf.h"
|
||||
#include "printing/mojom/print.mojom.h"
|
||||
#include "third_party/blink/public/web/web_print_params.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -29,4 +34,21 @@ std::vector<int> PageNumbersFromPPPrintPageNumberRange(
|
||||
return page_numbers;
|
||||
}
|
||||
|
||||
blink::WebPrintParams WebPrintParamsFromPPPrintSettings(
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings) {
|
||||
blink::WebPrintParams params;
|
||||
params.print_content_area = RectFromPPRect(print_settings.content_area);
|
||||
params.printable_area = RectFromPPRect(print_settings.printable_area);
|
||||
params.paper_size = SizeFromPPSize(print_settings.paper_size);
|
||||
params.printer_dpi = print_settings.dpi;
|
||||
params.scale_factor = pdf_print_settings.scale_factor;
|
||||
params.rasterize_pdf = print_settings.format & PP_PRINTOUTPUTFORMAT_RASTER;
|
||||
params.print_scaling_option =
|
||||
static_cast<printing::mojom::PrintScalingOption>(
|
||||
print_settings.print_scaling_option);
|
||||
params.pages_per_sheet = pdf_print_settings.pages_per_sheet;
|
||||
return params;
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -10,6 +10,12 @@
|
||||
#include <vector>
|
||||
|
||||
struct PP_PrintPageNumberRange_Dev;
|
||||
struct PP_PrintSettings_Dev;
|
||||
struct PP_PdfPrintSettings_Dev;
|
||||
|
||||
namespace blink {
|
||||
struct WebPrintParams;
|
||||
} // namespace blink
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -17,6 +23,10 @@ std::vector<int> PageNumbersFromPPPrintPageNumberRange(
|
||||
const PP_PrintPageNumberRange_Dev* page_ranges,
|
||||
uint32_t page_range_count);
|
||||
|
||||
blink::WebPrintParams WebPrintParamsFromPPPrintSettings(
|
||||
const PP_PrintSettings_Dev& print_settings,
|
||||
const PP_PdfPrintSettings_Dev& pdf_print_settings);
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
#endif // PDF_PPAPI_MIGRATION_PRINTING_CONVERSIONS_H_
|
||||
|
Reference in New Issue
Block a user