chromium/pdf/pdfium/pdfium_print.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// UI should have done parameter sanity check, when execution
// reaches here, `pages_per_sheet` should be a positive integer.
bool ShouldDoNup(int pages_per_sheet) {}

// Returns the valid, positive page count, or std::nullopt on failure.
std::optional<uint32_t> GetDocumentPageCount(FPDF_DOCUMENT doc) {}

// Set the destination page size and content area in points based on source
// page rotation and orientation.
//
// `rotated` True if source page is rotated 90 degree or 270 degree.
// `is_src_page_landscape` is true if the source page orientation is landscape.
// `page_size` has the actual destination page size in points.
// `content_rect` has the actual destination page printable area values in
// points.
void SetPageSizeAndContentRect(bool rotated,
                               bool is_src_page_landscape,
                               gfx::Size* page_size,
                               gfx::Rect* content_rect) {}

// Transform `page` contents to fit in the selected printer paper size.
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) {}

// Takes the same parameters as PDFiumPrint::CreateNupPdf().
// On success, returns the N-up version of `doc`. On failure, returns nullptr.
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) {}

// On success returns the number of flattened pages.
// On failure returns std::nullopt.
std::optional<uint32_t> FlattenPrintData(FPDF_DOCUMENT doc) {}

gfx::RectF CSSPixelsToPoints(const gfx::RectF& rect) {}

gfx::SizeF CSSPixelsToPoints(const gfx::SizeF& size) {}

}  // namespace

PDFiumPrint::PDFiumPrint(PDFiumEngine* engine) :{}

PDFiumPrint::~PDFiumPrint() = default;

#if BUILDFLAG(IS_CHROMEOS)
// static
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  // BUILDFLAG(IS_CHROMEOS)

// static
std::vector<uint8_t> PDFiumPrint::CreateNupPdf(
    ScopedFPDFDocument doc,
    size_t pages_per_sheet,
    const gfx::Size& page_size,
    const gfx::Rect& printable_area) {}

// static
bool PDFiumPrint::IsSourcePdfLandscape(FPDF_DOCUMENT doc) {}

// static
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) {}

}  // namespace chrome_pdf