#include "pdf/pdfium/pdfium_searchify.h"
#include <math.h>
#include <stdint.h>
#include <algorithm>
#include <array>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/functional/callback.h"
#include "base/numerics/angle_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
#include "pdf/pdfium/pdfium_ocr.h"
#include "pdf/pdfium/pdfium_searchify_font.h"
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_edit.h"
#include "third_party/pdfium/public/fpdf_save.h"
#include "third_party/pdfium/public/fpdfview.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkPixmap.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/size.h"
#include "ui/gfx/geometry/size_f.h"
namespace chrome_pdf {
namespace {
std::vector<uint32_t> Utf8ToCharcodes(const std::string& string) { … }
SearchifyBoundingBoxOrigin ConvertToPdfOrigin(const gfx::Rect& rect,
float angle,
float coordinate_system_height) { … }
SearchifyBoundingBoxOrigin ProjectToBaseline(
const gfx::PointF& origin_point,
const SearchifyBoundingBoxOrigin& baseline_origin) { … }
gfx::SizeF GetRenderedImageSize(FPDF_PAGEOBJECT image) { … }
bool CalculateImageWithoutScalingMatrix(FPDF_PAGEOBJECT image,
const gfx::SizeF& rendered_size,
FS_MATRIX& image_matrix) { … }
FS_MATRIX CalculateWordMoveMatrix(const SearchifyBoundingBoxOrigin& word_origin,
int word_bounding_box_width,
bool word_is_rtl) { … }
void AddWordOnImage(FPDF_DOCUMENT document,
FPDF_PAGE page,
FPDF_FONT font,
const screen_ai::mojom::WordBoxPtr& word,
base::span<const FS_MATRIX> transform_matrices) { … }
void AddTextOnImage(FPDF_DOCUMENT document,
FPDF_PAGE page,
FPDF_FONT font,
FPDF_PAGEOBJECT image,
screen_ai::mojom::VisualAnnotationPtr annotation,
const gfx::Size& image_pixel_size) { … }
ScopedFPDFFont CreateFont(FPDF_DOCUMENT document) { … }
int GetBlockForJpeg(void* param,
unsigned long pos,
unsigned char* buf,
unsigned long size) { … }
}
std::vector<uint8_t> PDFiumSearchify(
base::span<const uint8_t> pdf_buffer,
base::RepeatingCallback<screen_ai::mojom::VisualAnnotationPtr(
const SkBitmap& bitmap)> perform_ocr_callback) { … }
SearchifyBoundingBoxOrigin ConvertToPdfOriginForTesting(
const gfx::Rect& rect,
float angle,
float coordinate_system_height) { … }
FS_MATRIX CalculateWordMoveMatrixForTesting(
const SearchifyBoundingBoxOrigin& origin,
int word_bounding_box_width,
bool word_is_rtl) { … }
PdfiumProgressiveSearchifier::ScopedSdkInitializer::ScopedSdkInitializer() { … }
PdfiumProgressiveSearchifier::ScopedSdkInitializer::~ScopedSdkInitializer() { … }
PdfiumProgressiveSearchifier::PdfiumProgressiveSearchifier()
: … { … }
PdfiumProgressiveSearchifier::~PdfiumProgressiveSearchifier() = default;
void PdfiumProgressiveSearchifier::AddPage(
const SkBitmap& bitmap,
uint32_t page_index,
screen_ai::mojom::VisualAnnotationPtr annotation) { … }
void PdfiumProgressiveSearchifier::DeletePage(uint32_t page_index) { … }
std::vector<uint8_t> PdfiumProgressiveSearchifier::Save() { … }
}