#include "pdf/pdfium/pdfium_print.h"
#include <algorithm>
#include <cstdint>
#include <string>
#include <utility>
#include "build/build_config.h"
#include "pdf/flatten_pdf_result.h"
#include "pdf/pdf_transform.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_write.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"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/size_f.h"
ConvertUnit;
ConvertUnitFloat;
kPixelsPerInch;
kPointsPerInch;
namespace chrome_pdf {
namespace {
bool ShouldDoNup(int pages_per_sheet) { … }
std::optional<uint32_t> GetDocumentPageCount(FPDF_DOCUMENT doc) { … }
void SetPageSizeAndContentRect(bool rotated,
bool is_src_page_landscape,
gfx::Size* page_size,
gfx::Rect* content_rect) { … }
void TransformPDFPageForPrinting(
FPDF_PAGE page,
float scale_factor,
printing::mojom::PrintScalingOption scaling_option,
const gfx::Size& paper_size,
const gfx::Rect& printable_area) { … }
void FitContentsToPrintableAreaIfRequired(
FPDF_DOCUMENT doc,
float scale_factor,
printing::mojom::PrintScalingOption scaling_option,
const gfx::Size& paper_size,
const gfx::Rect& printable_area) { … }
ScopedFPDFDocument CreateNupPdfDocument(ScopedFPDFDocument doc,
size_t pages_per_sheet,
const gfx::Size& page_size,
const gfx::Rect& printable_area) { … }
std::vector<uint8_t> ConvertDocToBuffer(ScopedFPDFDocument doc) { … }
int GetBlockForJpeg(void* param,
unsigned long pos,
unsigned char* buf,
unsigned long size) { … }
std::optional<uint32_t> FlattenPrintData(FPDF_DOCUMENT doc) { … }
gfx::RectF CSSPixelsToPoints(const gfx::RectF& rect) { … }
gfx::SizeF CSSPixelsToPoints(const gfx::SizeF& size) { … }
}
PDFiumPrint::PDFiumPrint(PDFiumEngine* engine) : … { … }
PDFiumPrint::~PDFiumPrint() = default;
#if BUILDFLAG(IS_CHROMEOS)
std::optional<FlattenPdfResult> PDFiumPrint::CreateFlattenedPdf(
ScopedFPDFDocument doc) {
std::optional<uint32_t> pages_flattened = FlattenPrintData(doc.get());
if (!pages_flattened) {
return std::nullopt;
}
std::vector<uint8_t> buffer = ConvertDocToBuffer(std::move(doc));
if (buffer.empty()) {
return std::nullopt;
}
return FlattenPdfResult(std::move(buffer), *pages_flattened);
}
#endif
std::vector<uint8_t> PDFiumPrint::CreateNupPdf(
ScopedFPDFDocument doc,
size_t pages_per_sheet,
const gfx::Size& page_size,
const gfx::Rect& printable_area) { … }
bool PDFiumPrint::IsSourcePdfLandscape(FPDF_DOCUMENT doc) { … }
void PDFiumPrint::FitContentsToPrintableArea(FPDF_DOCUMENT doc,
const gfx::Size& page_size,
const gfx::Rect& printable_area) { … }
std::vector<uint8_t> PDFiumPrint::PrintPagesAsPdf(
const std::vector<int>& page_indices,
const blink::WebPrintParams& print_params) { … }
ScopedFPDFDocument PDFiumPrint::CreatePrintPdf(
const std::vector<int>& page_indices,
const blink::WebPrintParams& print_params) { … }
ScopedFPDFDocument PDFiumPrint::CreateRasterPdf(ScopedFPDFDocument doc,
int dpi) { … }
ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
FPDF_PAGE page_to_print,
int dpi) { … }
}