#include "pdf/pdfium/pdfium_page.h"
#include <math.h>
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/angle_conversions.h"
#include "base/numerics/safe_math.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/accessibility_helper.h"
#include "pdf/accessibility_structs.h"
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_ocr.h"
#include "pdf/pdfium/pdfium_unsupported_features.h"
#include "pdf/ui/thumbnail.h"
#include "printing/units.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_annot.h"
#include "third_party/pdfium/public/fpdf_catalog.h"
#include "third_party/pdfium/public/fpdf_edit.h"
#include "third_party/pdfium/public/fpdfview.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/skbitmap_operations.h"
ConvertUnitFloat;
kPixelsPerInch;
kPointsPerInch;
namespace chrome_pdf {
namespace {
constexpr float k45DegreesInRadians = …;
constexpr float k90DegreesInRadians = …;
constexpr float k180DegreesInRadians = …;
constexpr float k270DegreesInRadians = …;
constexpr float k360DegreesInRadians = …;
constexpr float kPointsToPixels = …;
enum class Rotation { … };
gfx::RectF FloatPageRectToPixelRect(FPDF_PAGE page, const gfx::RectF& input) { … }
gfx::RectF GetFloatCharRectInPixels(FPDF_PAGE page,
FPDF_TEXTPAGE text_page,
int index) { … }
int GetFirstNonUnicodeWhiteSpaceCharIndex(FPDF_TEXTPAGE text_page,
int start_char_index,
int chars_count) { … }
AccessibilityTextDirection GetDirectionFromAngle(float angle) { … }
void AddCharSizeToAverageCharSize(gfx::SizeF new_size,
gfx::SizeF* avg_size,
int* count) { … }
float GetRotatedCharWidth(float angle, const gfx::SizeF& size) { … }
float GetAngleOfVector(const gfx::Vector2dF& v) { … }
float GetAngleDifference(float a, float b) { … }
bool FloatEquals(float f1, float f2) { … }
bool IsRadioButtonOrCheckBox(int button_type) { … }
template <typename T>
bool CompareTextRuns(const T& a, const T& b) { … }
AccessibilityTextStyleInfo CalculateTextRunStyleInfo(
FPDF_PAGEOBJECT text_object) { … }
bool AreTextStyleEqual(FPDF_PAGEOBJECT text_object,
const AccessibilityTextStyleInfo& style) { … }
FS_RECTF GetLargestBounds(const FS_RECTF& largest_bounds,
const FS_RECTF& bounds) { … }
gfx::RectF GetRotatedRectF(Rotation rotation,
gfx::SizeF page_size,
const FS_RECTF& original_bounds) { … }
gfx::RectF GetEffectiveCropBox(FPDF_PAGE page,
Rotation rotation,
const gfx::SizeF& page_size) { … }
}
PDFiumPage::LinkTarget::LinkTarget() : … { … }
PDFiumPage::LinkTarget::LinkTarget(const LinkTarget& other) = default;
PDFiumPage::LinkTarget::~LinkTarget() = default;
PDFiumPage::PDFiumPage(PDFiumEngine* engine, int i)
: … { … }
PDFiumPage::PDFiumPage(PDFiumPage&& that) = default;
PDFiumPage::~PDFiumPage() { … }
void PDFiumPage::Unload() { … }
FPDF_PAGE PDFiumPage::GetPage() { … }
FPDF_TEXTPAGE PDFiumPage::GetTextPage() { … }
void PDFiumPage::CalculatePageObjectTextRunBreaks() { … }
std::optional<AccessibilityTextRunInfo> PDFiumPage::GetTextRunInfo(
int start_char_index) { … }
uint32_t PDFiumPage::GetCharUnicode(int char_index) { … }
gfx::RectF PDFiumPage::GetCharBounds(int char_index) { … }
gfx::RectF PDFiumPage::GetCroppedRect() { … }
gfx::RectF PDFiumPage::GetBoundingBox() { … }
bool PDFiumPage::IsCharInPageBounds(int char_index,
const gfx::RectF& page_bounds) { … }
std::vector<AccessibilityLinkInfo> PDFiumPage::GetLinkInfo(
const std::vector<AccessibilityTextRunInfo>& text_runs) { … }
std::vector<AccessibilityImageInfo> PDFiumPage::GetImageInfo(
uint32_t text_run_count) { … }
SkBitmap PDFiumPage::GetImageForOcr(int page_object_index) { … }
std::vector<AccessibilityHighlightInfo> PDFiumPage::GetHighlightInfo(
const std::vector<AccessibilityTextRunInfo>& text_runs) { … }
std::vector<AccessibilityTextFieldInfo> PDFiumPage::GetTextFieldInfo(
uint32_t text_run_count) { … }
PDFiumPage::Area PDFiumPage::GetLinkTargetAtIndex(int link_index,
LinkTarget* target) { … }
PDFiumPage::Area PDFiumPage::GetLinkTarget(FPDF_LINK link, LinkTarget* target) { … }
PDFiumPage::Area PDFiumPage::GetCharIndex(const gfx::Point& point,
PageOrientation orientation,
int* char_index,
int* form_type,
LinkTarget* target) { … }
PDFiumPage::Area PDFiumPage::FormTypeToArea(int form_type) { … }
char16_t PDFiumPage::GetCharAtIndex(int index) { … }
int PDFiumPage::GetCharCount() { … }
bool PDFiumPage::IsCharIndexInBounds(int index) { … }
PDFiumPage::Area PDFiumPage::GetDestinationTarget(FPDF_DEST destination,
LinkTarget* target) { … }
void PDFiumPage::GetPageDestinationTarget(FPDF_DEST destination,
std::optional<float>* dest_x,
std::optional<float>* dest_y,
std::optional<float>* zoom_value) { … }
float PDFiumPage::PreProcessAndTransformInPageCoordX(float x) { … }
float PDFiumPage::PreProcessAndTransformInPageCoordY(float y) { … }
gfx::PointF PDFiumPage::TransformPageToScreenXY(const gfx::PointF& xy) { … }
float PDFiumPage::TransformPageToScreenX(float x) { … }
float PDFiumPage::TransformPageToScreenY(float y) { … }
PDFiumPage::Area PDFiumPage::GetURITarget(FPDF_ACTION uri_action,
LinkTarget* target) const { … }
int PDFiumPage::GetLink(int char_index, LinkTarget* target) { … }
void PDFiumPage::CalculateLinks() { … }
void PDFiumPage::PopulateWebLinks() { … }
void PDFiumPage::PopulateAnnotationLinks() { … }
void PDFiumPage::CalculateImages() { … }
void PDFiumPage::PopulateImageAltText(
const MarkedContentIdToImageMap& marked_content_id_image_map) { … }
void PDFiumPage::PopulateImageAltTextForStructElement(
const MarkedContentIdToImageMap& marked_content_id_image_map,
FPDF_STRUCTELEMENT current_element,
std::set<FPDF_STRUCTELEMENT>* visited_elements) { … }
void PDFiumPage::PopulateAnnotations() { … }
void PDFiumPage::PopulateHighlight(FPDF_ANNOTATION annot) { … }
void PDFiumPage::PopulateTextField(FPDF_ANNOTATION annot) { … }
void PDFiumPage::PopulateChoiceField(FPDF_ANNOTATION annot) { … }
void PDFiumPage::PopulateButton(FPDF_ANNOTATION annot) { … }
void PDFiumPage::PopulateFormField(FPDF_ANNOTATION annot) { … }
bool PDFiumPage::PopulateFormFieldProperties(FPDF_ANNOTATION annot,
FormField* form_field) { … }
bool PDFiumPage::GetUnderlyingTextRangeForRect(const gfx::RectF& rect,
int* start_index,
int* char_len) { … }
gfx::Rect PDFiumPage::PageToScreen(const gfx::Point& page_point,
double zoom,
double left,
double top,
double right,
double bottom,
PageOrientation orientation) const { … }
void PDFiumPage::RequestThumbnail(float device_pixel_ratio,
SendThumbnailCallback send_callback) { … }
Thumbnail PDFiumPage::GenerateThumbnail(float device_pixel_ratio) { … }
void PDFiumPage::GenerateAndSendThumbnail(float device_pixel_ratio,
SendThumbnailCallback send_callback) { … }
void PDFiumPage::MarkAvailable() { … }
PDFiumPage::ScopedUnloadPreventer::ScopedUnloadPreventer(PDFiumPage* page)
: … { … }
PDFiumPage::ScopedUnloadPreventer::ScopedUnloadPreventer(
const ScopedUnloadPreventer& that)
: … { … }
PDFiumPage::ScopedUnloadPreventer& PDFiumPage::ScopedUnloadPreventer::operator=(
const ScopedUnloadPreventer& that) { … }
PDFiumPage::ScopedUnloadPreventer::~ScopedUnloadPreventer() { … }
PDFiumPage::Link::Link() = default;
PDFiumPage::Link::Link(const Link& that) = default;
PDFiumPage::Link::~Link() = default;
PDFiumPage::Image::Image() = default;
PDFiumPage::Image::Image(const Image& that) = default;
PDFiumPage::Image::~Image() = default;
PDFiumPage::Highlight::Highlight() = default;
PDFiumPage::Highlight::Highlight(const Highlight& that) = default;
PDFiumPage::Highlight::~Highlight() = default;
PDFiumPage::FormField::FormField() = default;
PDFiumPage::FormField::FormField(const FormField& that) = default;
PDFiumPage::FormField::~FormField() = default;
PDFiumPage::TextField::TextField() = default;
PDFiumPage::TextField::TextField(const TextField& that) = default;
PDFiumPage::TextField::~TextField() = default;
PDFiumPage::ChoiceFieldOption::ChoiceFieldOption() = default;
PDFiumPage::ChoiceFieldOption::ChoiceFieldOption(
const ChoiceFieldOption& that) = default;
PDFiumPage::ChoiceFieldOption::~ChoiceFieldOption() = default;
PDFiumPage::ChoiceField::ChoiceField() = default;
PDFiumPage::ChoiceField::ChoiceField(const ChoiceField& that) = default;
PDFiumPage::ChoiceField::~ChoiceField() = default;
PDFiumPage::Button::Button() = default;
PDFiumPage::Button::Button(const Button& that) = default;
PDFiumPage::Button::~Button() = default;
}