Migrate pp::Float* to gfx::*F in pdf/
Update pdf/ to use gfx::*F instead of pp::Float* - pp::FloatRect to gfx::RectF - pp::FloatSize to gfx::SizeF - pp::FloatPoint to gfx::PointF or gfx::Vector2dF gfx::FloatPoint is replaced by gfx::Vector2dF where we need to store the vector difference between two points. All other instances have been replaced by gfx::PointF. Noteworthy points: - In pp::FloatRect, Union() is a utility method which takes in two rects and returns a rect with the specified operation of input rects. Whereas in gfx::RectF, Union() is a member method which modifies the rect in-place. All usage of Union() which are replaced in the CL modify the rect in-place. Added conversions between gfx::RectF and pp::FloatRect, with tests. Bug: 1101101 Change-Id: I57ca3bddd16da1328cbe462e60be862be3811ee9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2413769 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com> Cr-Commit-Position: refs/heads/master@{#808474}
This commit is contained in:

committed by
Commit Bot

parent
6245817c00
commit
1f081d80d2
@ -11,6 +11,7 @@
|
||||
#include "pdf/pdf_engine.h"
|
||||
#include "pdf/ppapi_migration/geometry_conversions.h"
|
||||
#include "ppapi/cpp/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -75,7 +76,7 @@ void GetAccessibilityLinkInfo(
|
||||
pp::PDF::PrivateAccessibilityLinkInfo link_info;
|
||||
link_info.url = std::move(cur_engine_info.url);
|
||||
link_info.index_in_page = i;
|
||||
link_info.bounds = std::move(cur_engine_info.bounds);
|
||||
link_info.bounds = PPFloatRectFromRectF(cur_engine_info.bounds);
|
||||
|
||||
if (!GetEnclosingTextRunRangeForCharRange(
|
||||
text_runs, cur_engine_info.start_char_index,
|
||||
@ -105,7 +106,7 @@ void GetAccessibilityImageInfo(
|
||||
for (auto& cur_engine_info : engine_image_info) {
|
||||
pp::PDF::PrivateAccessibilityImageInfo image_info;
|
||||
image_info.alt_text = std::move(cur_engine_info.alt_text);
|
||||
image_info.bounds = std::move(cur_engine_info.bounds);
|
||||
image_info.bounds = PPFloatRectFromRectF(cur_engine_info.bounds);
|
||||
// TODO(mohitb): Update text run index to nearest text run to image bounds.
|
||||
image_info.text_run_index = text_run_count;
|
||||
images->push_back(std::move(image_info));
|
||||
@ -123,7 +124,7 @@ void GetAccessibilityHighlightInfo(
|
||||
auto& cur_highlight_info = engine_highlight_info[i];
|
||||
pp::PDF::PrivateAccessibilityHighlightInfo highlight_info;
|
||||
highlight_info.index_in_page = i;
|
||||
highlight_info.bounds = std::move(cur_highlight_info.bounds);
|
||||
highlight_info.bounds = PPFloatRectFromRectF(cur_highlight_info.bounds);
|
||||
highlight_info.color = cur_highlight_info.color;
|
||||
highlight_info.note_text = std::move(cur_highlight_info.note_text);
|
||||
|
||||
@ -163,7 +164,7 @@ void GetAccessibilityTextFieldInfo(
|
||||
// TODO(crbug.com/1030242): Update text run index to nearest text run to
|
||||
// text field bounds.
|
||||
text_field_info.text_run_index = text_run_count;
|
||||
text_field_info.bounds = std::move(cur_text_field_info.bounds);
|
||||
text_field_info.bounds = PPFloatRectFromRectF(cur_text_field_info.bounds);
|
||||
text_fields->push_back(std::move(text_field_info));
|
||||
}
|
||||
}
|
||||
@ -225,10 +226,10 @@ bool GetAccessibilityInfo(
|
||||
// x coordinate of the next. The rest of the bounds of each character
|
||||
// can be computed from the bounds of the text run.
|
||||
// The same idea is used for RTL, TTB and BTT text direction.
|
||||
pp::FloatRect char_bounds = engine->GetCharBounds(page_index, char_index);
|
||||
gfx::RectF char_bounds = engine->GetCharBounds(page_index, char_index);
|
||||
for (uint32_t i = char_index; i < text_run_end - 1; i++) {
|
||||
DCHECK_LT(i + 1, static_cast<uint32_t>(char_count));
|
||||
pp::FloatRect next_char_bounds = engine->GetCharBounds(page_index, i + 1);
|
||||
gfx::RectF next_char_bounds = engine->GetCharBounds(page_index, i + 1);
|
||||
double& char_width = (*chars)[i].char_width;
|
||||
switch (text_run_info.direction) {
|
||||
case PP_PRIVATEDIRECTION_NONE:
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "ui/base/window_open_disposition.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include <windows.h>
|
||||
@ -283,7 +284,7 @@ class PDFEngine {
|
||||
std::string url;
|
||||
int start_char_index;
|
||||
int char_count;
|
||||
pp::FloatRect bounds;
|
||||
gfx::RectF bounds;
|
||||
};
|
||||
|
||||
struct AccessibilityImageInfo {
|
||||
@ -292,7 +293,7 @@ class PDFEngine {
|
||||
~AccessibilityImageInfo();
|
||||
|
||||
std::string alt_text;
|
||||
pp::FloatRect bounds;
|
||||
gfx::RectF bounds;
|
||||
};
|
||||
|
||||
struct AccessibilityHighlightInfo {
|
||||
@ -302,7 +303,7 @@ class PDFEngine {
|
||||
|
||||
int start_char_index = -1;
|
||||
int char_count;
|
||||
pp::FloatRect bounds;
|
||||
gfx::RectF bounds;
|
||||
uint32_t color;
|
||||
std::string note_text;
|
||||
};
|
||||
@ -317,7 +318,7 @@ class PDFEngine {
|
||||
bool is_read_only;
|
||||
bool is_required;
|
||||
bool is_password;
|
||||
pp::FloatRect bounds;
|
||||
gfx::RectF bounds;
|
||||
};
|
||||
|
||||
virtual ~PDFEngine() {}
|
||||
@ -419,7 +420,7 @@ class PDFEngine {
|
||||
// Get the number of characters on a given page.
|
||||
virtual int GetCharCount(int page_index) = 0;
|
||||
// Get the bounds in page pixels of a character on a given page.
|
||||
virtual pp::FloatRect GetCharBounds(int page_index, int char_index) = 0;
|
||||
virtual gfx::RectF GetCharBounds(int page_index, int char_index) = 0;
|
||||
// Get a given unicode character on a given page.
|
||||
virtual uint32_t GetCharUnicode(int page_index, int char_index) = 0;
|
||||
// Given a start char index, find the longest continuous run of text that's
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "pdf/test/test_utils.h"
|
||||
#include "ppapi/c/private/ppp_pdf.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -157,7 +158,7 @@ TEST_F(AccessibilityTest, GetUnderlyingTextRangeForRect) {
|
||||
int start_index = -1;
|
||||
int char_count = 0;
|
||||
EXPECT_TRUE(page.GetUnderlyingTextRangeForRect(
|
||||
pp::FloatRect(20.0f, 50.0f, 26.0f, 8.0f), &start_index, &char_count));
|
||||
gfx::RectF(20.0f, 50.0f, 26.0f, 8.0f), &start_index, &char_count));
|
||||
EXPECT_EQ(start_index, 0);
|
||||
EXPECT_EQ(char_count, 5);
|
||||
|
||||
@ -167,7 +168,7 @@ TEST_F(AccessibilityTest, GetUnderlyingTextRangeForRect) {
|
||||
start_index = -1;
|
||||
char_count = 0;
|
||||
EXPECT_TRUE(page.GetUnderlyingTextRangeForRect(
|
||||
pp::FloatRect(20.0f, 0.0f, 26.0f, 58.0f), &start_index, &char_count));
|
||||
gfx::RectF(20.0f, 0.0f, 26.0f, 58.0f), &start_index, &char_count));
|
||||
EXPECT_EQ(start_index, 0);
|
||||
EXPECT_EQ(char_count, 5);
|
||||
|
||||
@ -176,7 +177,7 @@ TEST_F(AccessibilityTest, GetUnderlyingTextRangeForRect) {
|
||||
start_index = -9;
|
||||
char_count = -10;
|
||||
EXPECT_FALSE(page.GetUnderlyingTextRangeForRect(
|
||||
pp::FloatRect(10.0f, 10.0f, 0.0f, 0.0f), &start_index, &char_count));
|
||||
gfx::RectF(10.0f, 10.0f, 0.0f, 0.0f), &start_index, &char_count));
|
||||
EXPECT_EQ(start_index, -9);
|
||||
EXPECT_EQ(char_count, -10);
|
||||
}
|
||||
|
@ -64,6 +64,7 @@
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
#include "ui/gfx/geometry/point_conversions.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
#include "v8/include/v8.h"
|
||||
@ -2480,7 +2481,7 @@ int PDFiumEngine::GetCharCount(int page_index) {
|
||||
return pages_[page_index]->GetCharCount();
|
||||
}
|
||||
|
||||
pp::FloatRect PDFiumEngine::GetCharBounds(int page_index, int char_index) {
|
||||
gfx::RectF PDFiumEngine::GetCharBounds(int page_index, int char_index) {
|
||||
DCHECK(PageIndexInBounds(page_index));
|
||||
return pages_[page_index]->GetCharBounds(char_index);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class PDFiumEngine : public PDFEngine,
|
||||
int GetVerticalScrollbarYPosition() override;
|
||||
void SetGrayscale(bool grayscale) override;
|
||||
int GetCharCount(int page_index) override;
|
||||
pp::FloatRect GetCharBounds(int page_index, int char_index) override;
|
||||
gfx::RectF GetCharBounds(int page_index, int char_index) override;
|
||||
uint32_t GetCharUnicode(int page_index, int char_index) override;
|
||||
base::Optional<pp::PDF::PrivateAccessibilityTextRunInfo> GetTextRunInfo(
|
||||
int page_index,
|
||||
|
@ -31,8 +31,12 @@
|
||||
#include "third_party/pdfium/public/fpdf_catalog.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.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"
|
||||
|
||||
using printing::ConvertUnitDouble;
|
||||
@ -60,8 +64,7 @@ bool IsValidLink(const std::string& url) {
|
||||
return pp::Var(url).is_string();
|
||||
}
|
||||
|
||||
pp::FloatRect FloatPageRectToPixelRect(FPDF_PAGE page,
|
||||
const pp::FloatRect& input) {
|
||||
gfx::RectF FloatPageRectToPixelRect(FPDF_PAGE page, const gfx::RectF& input) {
|
||||
int output_width = FPDF_GetPageWidthF(page);
|
||||
int output_height = FPDF_GetPageHeightF(page);
|
||||
|
||||
@ -81,7 +84,7 @@ pp::FloatRect FloatPageRectToPixelRect(FPDF_PAGE page,
|
||||
if (max_y < min_y)
|
||||
std::swap(min_y, max_y);
|
||||
|
||||
pp::FloatRect output_rect(
|
||||
gfx::RectF output_rect(
|
||||
ConvertUnitDouble(min_x, kPointsPerInch, kPixelsPerInch),
|
||||
ConvertUnitDouble(min_y, kPointsPerInch, kPixelsPerInch),
|
||||
ConvertUnitDouble(max_x - min_x, kPointsPerInch, kPixelsPerInch),
|
||||
@ -89,21 +92,21 @@ pp::FloatRect FloatPageRectToPixelRect(FPDF_PAGE page,
|
||||
return output_rect;
|
||||
}
|
||||
|
||||
pp::FloatRect GetFloatCharRectInPixels(FPDF_PAGE page,
|
||||
FPDF_TEXTPAGE text_page,
|
||||
int index) {
|
||||
gfx::RectF GetFloatCharRectInPixels(FPDF_PAGE page,
|
||||
FPDF_TEXTPAGE text_page,
|
||||
int index) {
|
||||
double left;
|
||||
double right;
|
||||
double bottom;
|
||||
double top;
|
||||
if (!FPDFText_GetCharBox(text_page, index, &left, &right, &bottom, &top))
|
||||
return pp::FloatRect();
|
||||
return gfx::RectF();
|
||||
|
||||
if (right < left)
|
||||
std::swap(left, right);
|
||||
if (bottom < top)
|
||||
std::swap(top, bottom);
|
||||
pp::FloatRect page_coords(left, top, right - left, bottom - top);
|
||||
gfx::RectF page_coords(left, top, right - left, bottom - top);
|
||||
return FloatPageRectToPixelRect(page, page_coords);
|
||||
}
|
||||
|
||||
@ -147,14 +150,8 @@ PP_PrivateDirection GetDirectionFromAngle(float angle) {
|
||||
return PP_PRIVATEDIRECTION_BTT;
|
||||
}
|
||||
|
||||
float GetDistanceBetweenPoints(const pp::FloatPoint& p1,
|
||||
const pp::FloatPoint& p2) {
|
||||
pp::FloatPoint dist_vector = p1 - p2;
|
||||
return sqrtf(powf(dist_vector.x(), 2) + powf(dist_vector.y(), 2));
|
||||
}
|
||||
|
||||
void AddCharSizeToAverageCharSize(pp::FloatSize new_size,
|
||||
pp::FloatSize* avg_size,
|
||||
void AddCharSizeToAverageCharSize(gfx::SizeF new_size,
|
||||
gfx::SizeF* avg_size,
|
||||
int* count) {
|
||||
// Some characters sometimes have a bogus empty bounding box. We don't want
|
||||
// them to impact the average.
|
||||
@ -167,11 +164,11 @@ void AddCharSizeToAverageCharSize(pp::FloatSize new_size,
|
||||
}
|
||||
}
|
||||
|
||||
float GetRotatedCharWidth(float angle, const pp::FloatSize& size) {
|
||||
float GetRotatedCharWidth(float angle, const gfx::SizeF& size) {
|
||||
return fabsf(cosf(angle) * size.width()) + fabsf(sinf(angle) * size.height());
|
||||
}
|
||||
|
||||
float GetAngleOfVector(const pp::FloatPoint& v) {
|
||||
float GetAngleOfVector(const gfx::Vector2dF& v) {
|
||||
float angle = atan2f(v.y(), v.x());
|
||||
if (angle < 0)
|
||||
angle += k360DegreesInRadians;
|
||||
@ -471,10 +468,10 @@ PDFiumPage::GetTextRunInfo(int start_char_index) {
|
||||
// If the first character in a text run is a space, we need to start
|
||||
// |text_run_bounds| from the space character instead of the first
|
||||
// non-space unicode character.
|
||||
pp::FloatRect text_run_bounds =
|
||||
gfx::RectF text_run_bounds =
|
||||
actual_start_char_index > start_char_index
|
||||
? GetFloatCharRectInPixels(page, text_page, start_char_index)
|
||||
: pp::FloatRect();
|
||||
: gfx::RectF();
|
||||
|
||||
// Pdfium trims more than 1 consecutive spaces to 1 space.
|
||||
DCHECK_LE(actual_start_char_index - start_char_index, 1);
|
||||
@ -485,7 +482,7 @@ PDFiumPage::GetTextRunInfo(int start_char_index) {
|
||||
pp::PDF::PrivateAccessibilityTextRunInfo info;
|
||||
CalculateTextRunStyleInfo(char_index, &info.style);
|
||||
|
||||
pp::FloatRect start_char_rect =
|
||||
gfx::RectF start_char_rect =
|
||||
GetFloatCharRectInPixels(page, text_page, char_index);
|
||||
float text_run_font_size = info.style.font_size;
|
||||
|
||||
@ -495,20 +492,19 @@ PDFiumPage::GetTextRunInfo(int start_char_index) {
|
||||
// lead to a break in the text run after only one space. Ex: ". Hello World"
|
||||
// would be split in two runs: "." and "Hello World".
|
||||
double font_size_minimum = FPDFText_GetFontSize(text_page, char_index) / 3.0;
|
||||
pp::FloatSize avg_char_size =
|
||||
pp::FloatSize(font_size_minimum, font_size_minimum);
|
||||
gfx::SizeF avg_char_size(font_size_minimum, font_size_minimum);
|
||||
int non_whitespace_chars_count = 1;
|
||||
AddCharSizeToAverageCharSize(start_char_rect.Floatsize(), &avg_char_size,
|
||||
AddCharSizeToAverageCharSize(start_char_rect.size(), &avg_char_size,
|
||||
&non_whitespace_chars_count);
|
||||
|
||||
// Add first non-space char to text run.
|
||||
text_run_bounds = text_run_bounds.Union(start_char_rect);
|
||||
text_run_bounds.Union(start_char_rect);
|
||||
PP_PrivateDirection char_direction =
|
||||
GetDirectionFromAngle(FPDFText_GetCharAngle(text_page, char_index));
|
||||
if (char_index < chars_count)
|
||||
char_index++;
|
||||
|
||||
pp::FloatRect prev_char_rect = start_char_rect;
|
||||
gfx::RectF prev_char_rect = start_char_rect;
|
||||
float estimated_font_size =
|
||||
std::max(start_char_rect.width(), start_char_rect.height());
|
||||
|
||||
@ -532,7 +528,7 @@ PDFiumPage::GetTextRunInfo(int start_char_index) {
|
||||
break;
|
||||
|
||||
unsigned int character = FPDFText_GetUnicode(text_page, char_index);
|
||||
pp::FloatRect char_rect =
|
||||
gfx::RectF char_rect =
|
||||
GetFloatCharRectInPixels(page, text_page, char_index);
|
||||
|
||||
if (!base::IsUnicodeWhitespace(character)) {
|
||||
@ -563,21 +559,20 @@ PDFiumPage::GetTextRunInfo(int start_char_index) {
|
||||
|
||||
// Heuristic: End the text run if the center-point distance to the
|
||||
// previous character is less than 2.5x the average character size.
|
||||
AddCharSizeToAverageCharSize(char_rect.Floatsize(), &avg_char_size,
|
||||
AddCharSizeToAverageCharSize(char_rect.size(), &avg_char_size,
|
||||
&non_whitespace_chars_count);
|
||||
|
||||
float avg_char_width = GetRotatedCharWidth(current_angle, avg_char_size);
|
||||
|
||||
float distance =
|
||||
GetDistanceBetweenPoints(char_rect.CenterPoint(),
|
||||
prev_char_rect.CenterPoint()) -
|
||||
GetRotatedCharWidth(current_angle, char_rect.Floatsize()) / 2 -
|
||||
GetRotatedCharWidth(current_angle, prev_char_rect.Floatsize()) / 2;
|
||||
(char_rect.CenterPoint() - prev_char_rect.CenterPoint()).Length() -
|
||||
GetRotatedCharWidth(current_angle, char_rect.size()) / 2 -
|
||||
GetRotatedCharWidth(current_angle, prev_char_rect.size()) / 2;
|
||||
|
||||
if (distance > 2.5f * avg_char_width)
|
||||
break;
|
||||
|
||||
text_run_bounds = text_run_bounds.Union(char_rect);
|
||||
text_run_bounds.Union(char_rect);
|
||||
prev_char_rect = char_rect;
|
||||
}
|
||||
|
||||
@ -600,7 +595,7 @@ PDFiumPage::GetTextRunInfo(int start_char_index) {
|
||||
|
||||
info.len = char_index - start_char_index;
|
||||
info.style.font_size = text_run_font_size;
|
||||
info.bounds = text_run_bounds;
|
||||
info.bounds = PPFloatRectFromRectF(text_run_bounds);
|
||||
// Infer text direction from first and last character of the text run. We
|
||||
// can't base our decision on the character direction, since a character of a
|
||||
// RTL language will have an angle of 0 when not rotated, just like a
|
||||
@ -616,7 +611,7 @@ uint32_t PDFiumPage::GetCharUnicode(int char_index) {
|
||||
return FPDFText_GetUnicode(text_page, char_index);
|
||||
}
|
||||
|
||||
pp::FloatRect PDFiumPage::GetCharBounds(int char_index) {
|
||||
gfx::RectF PDFiumPage::GetCharBounds(int char_index) {
|
||||
FPDF_PAGE page = GetPage();
|
||||
FPDF_TEXTPAGE text_page = GetTextPage();
|
||||
return GetFloatCharRectInPixels(page, text_page, char_index);
|
||||
@ -639,8 +634,8 @@ std::vector<PDFEngine::AccessibilityLinkInfo> PDFiumPage::GetLinkInfo() {
|
||||
gfx::Rect link_rect;
|
||||
for (const auto& rect : link.bounding_rects)
|
||||
link_rect.Union(rect);
|
||||
cur_info.bounds = pp::FloatRect(link_rect.x(), link_rect.y(),
|
||||
link_rect.width(), link_rect.height());
|
||||
cur_info.bounds = gfx::RectF(link_rect.x(), link_rect.y(),
|
||||
link_rect.width(), link_rect.height());
|
||||
|
||||
link_info.push_back(std::move(cur_info));
|
||||
}
|
||||
@ -658,9 +653,9 @@ std::vector<PDFEngine::AccessibilityImageInfo> PDFiumPage::GetImageInfo() {
|
||||
for (const Image& image : images_) {
|
||||
PDFEngine::AccessibilityImageInfo cur_info;
|
||||
cur_info.alt_text = image.alt_text;
|
||||
cur_info.bounds = pp::FloatRect(
|
||||
image.bounding_rect.x(), image.bounding_rect.y(),
|
||||
image.bounding_rect.width(), image.bounding_rect.height());
|
||||
cur_info.bounds =
|
||||
gfx::RectF(image.bounding_rect.x(), image.bounding_rect.y(),
|
||||
image.bounding_rect.width(), image.bounding_rect.height());
|
||||
image_info.push_back(std::move(cur_info));
|
||||
}
|
||||
return image_info;
|
||||
@ -679,7 +674,7 @@ PDFiumPage::GetHighlightInfo() {
|
||||
PDFEngine::AccessibilityHighlightInfo cur_info;
|
||||
cur_info.start_char_index = highlight.start_char_index;
|
||||
cur_info.char_count = highlight.char_count;
|
||||
cur_info.bounds = pp::FloatRect(
|
||||
cur_info.bounds = gfx::RectF(
|
||||
highlight.bounding_rect.x(), highlight.bounding_rect.y(),
|
||||
highlight.bounding_rect.width(), highlight.bounding_rect.height());
|
||||
cur_info.color = highlight.color;
|
||||
@ -705,7 +700,7 @@ PDFiumPage::GetTextFieldInfo() {
|
||||
cur_info.is_read_only = !!(text_field.flags & FPDF_FORMFLAG_READONLY);
|
||||
cur_info.is_required = !!(text_field.flags & FPDF_FORMFLAG_REQUIRED);
|
||||
cur_info.is_password = !!(text_field.flags & FPDF_FORMFLAG_TEXT_PASSWORD);
|
||||
cur_info.bounds = pp::FloatRect(
|
||||
cur_info.bounds = gfx::RectF(
|
||||
text_field.bounding_rect.x(), text_field.bounding_rect.y(),
|
||||
text_field.bounding_rect.width(), text_field.bounding_rect.height());
|
||||
text_field_info.push_back(std::move(cur_info));
|
||||
@ -901,8 +896,8 @@ gfx::PointF PDFiumPage::TransformPageToScreenXY(const gfx::PointF& xy) {
|
||||
if (!available_)
|
||||
return gfx::PointF();
|
||||
|
||||
pp::FloatRect page_rect(xy.x(), xy.y(), 0, 0);
|
||||
pp::FloatRect pixel_rect(FloatPageRectToPixelRect(GetPage(), page_rect));
|
||||
gfx::RectF page_rect(xy.x(), xy.y(), 0, 0);
|
||||
gfx::RectF pixel_rect(FloatPageRectToPixelRect(GetPage(), page_rect));
|
||||
return gfx::PointF(pixel_rect.x(), pixel_rect.y());
|
||||
}
|
||||
|
||||
@ -1064,9 +1059,9 @@ void PDFiumPage::PopulateAnnotationLinks() {
|
||||
|
||||
// Calculate underlying text range of link.
|
||||
GetUnderlyingTextRangeForRect(
|
||||
pp::FloatRect(link_rect.left, link_rect.bottom,
|
||||
std::abs(link_rect.right - link_rect.left),
|
||||
std::abs(link_rect.bottom - link_rect.top)),
|
||||
gfx::RectF(link_rect.left, link_rect.bottom,
|
||||
std::abs(link_rect.right - link_rect.left),
|
||||
std::abs(link_rect.bottom - link_rect.top)),
|
||||
&link.start_char_index, &link.char_count);
|
||||
links_.emplace_back(link);
|
||||
}
|
||||
@ -1210,8 +1205,8 @@ void PDFiumPage::PopulateHighlight(FPDF_ANNOTATION annot) {
|
||||
PageToScreen(gfx::Point(), 1.0, rect.left, rect.top, rect.right,
|
||||
rect.bottom, PageOrientation::kOriginal);
|
||||
GetUnderlyingTextRangeForRect(
|
||||
pp::FloatRect(rect.left, rect.bottom, std::abs(rect.right - rect.left),
|
||||
std::abs(rect.bottom - rect.top)),
|
||||
gfx::RectF(rect.left, rect.bottom, std::abs(rect.right - rect.left),
|
||||
std::abs(rect.bottom - rect.top)),
|
||||
&highlight.start_char_index, &highlight.char_count);
|
||||
|
||||
// Retrieve the color of the highlight.
|
||||
@ -1357,7 +1352,7 @@ bool PDFiumPage::PopulateFormFieldProperties(FPDF_ANNOTATION annot,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PDFiumPage::GetUnderlyingTextRangeForRect(const pp::FloatRect& rect,
|
||||
bool PDFiumPage::GetUnderlyingTextRangeForRect(const gfx::RectF& rect,
|
||||
int* start_index,
|
||||
int* char_len) {
|
||||
if (!available_)
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
namespace gfx {
|
||||
class Point;
|
||||
class RectF;
|
||||
} // namespace gfx
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -60,7 +61,7 @@ class PDFiumPage {
|
||||
// Get a unicode character from the page.
|
||||
uint32_t GetCharUnicode(int char_index);
|
||||
// Get the bounds of a character in page pixels.
|
||||
pp::FloatRect GetCharBounds(int char_index);
|
||||
gfx::RectF GetCharBounds(int char_index);
|
||||
// For all the links on the page, get their urls, underlying text ranges and
|
||||
// bounding boxes.
|
||||
std::vector<PDFEngine::AccessibilityLinkInfo> GetLinkInfo();
|
||||
@ -145,7 +146,7 @@ class PDFiumPage {
|
||||
// Given a rectangle in page coordinates, computes the range of continuous
|
||||
// characters which lie inside that rectangle. Returns false without
|
||||
// modifying the out parameters if no character lies inside the rectangle.
|
||||
bool GetUnderlyingTextRangeForRect(const pp::FloatRect& rect,
|
||||
bool GetUnderlyingTextRangeForRect(const gfx::RectF& rect,
|
||||
int* start_index,
|
||||
int* char_len);
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "cc/test/pixel_test_utils.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_test_base.h"
|
||||
#include "pdf/ppapi_migration/geometry_conversions.h"
|
||||
#include "pdf/test/test_client.h"
|
||||
#include "pdf/test/test_utils.h"
|
||||
#include "pdf/thumbnail.h"
|
||||
@ -26,6 +27,7 @@
|
||||
#include "third_party/pdfium/public/fpdf_formfill.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/range/range.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
@ -277,7 +279,7 @@ TEST_F(PDFiumPageTextTest, TestTextRunBounds) {
|
||||
|
||||
EXPECT_TRUE(base::IsUnicodeWhitespace(
|
||||
engine->GetCharUnicode(kPageIndex, kFirstRunStartIndex)));
|
||||
pp::FloatRect text_run_bounds = actual_text_run_1.bounds;
|
||||
gfx::RectF text_run_bounds = RectFFromPPFloatRect(actual_text_run_1.bounds);
|
||||
EXPECT_TRUE(text_run_bounds.Contains(
|
||||
engine->GetCharBounds(kPageIndex, kFirstRunStartIndex)));
|
||||
|
||||
@ -295,7 +297,7 @@ TEST_F(PDFiumPageTextTest, TestTextRunBounds) {
|
||||
|
||||
EXPECT_TRUE(base::IsUnicodeWhitespace(
|
||||
engine->GetCharUnicode(kPageIndex, kFirstRunEndIndex)));
|
||||
pp::FloatRect end_char_rect =
|
||||
gfx::RectF end_char_rect =
|
||||
engine->GetCharBounds(kPageIndex, kFirstRunEndIndex);
|
||||
EXPECT_FALSE(text_run_bounds.Contains(end_char_rect));
|
||||
// Equals to the length of the previous text run.
|
||||
@ -313,7 +315,7 @@ TEST_F(PDFiumPageTextTest, TestTextRunBounds) {
|
||||
|
||||
EXPECT_FALSE(base::IsUnicodeWhitespace(
|
||||
engine->GetCharUnicode(kPageIndex, kSecondRunStartIndex)));
|
||||
text_run_bounds = actual_text_run_2.bounds;
|
||||
text_run_bounds = RectFFromPPFloatRect(actual_text_run_2.bounds);
|
||||
EXPECT_TRUE(text_run_bounds.Contains(
|
||||
engine->GetCharBounds(kPageIndex, kSecondRunStartIndex)));
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#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.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
|
||||
@ -36,6 +37,16 @@ PP_Rect PPRectFromRect(const gfx::Rect& rect) {
|
||||
return PP_MakeRectFromXYWH(rect.x(), rect.y(), rect.width(), rect.height());
|
||||
}
|
||||
|
||||
gfx::RectF RectFFromPPFloatRect(const PP_FloatRect& pp_rect) {
|
||||
return gfx::RectF(pp_rect.point.x, pp_rect.point.y, pp_rect.size.width,
|
||||
pp_rect.size.height);
|
||||
}
|
||||
|
||||
PP_FloatRect PPFloatRectFromRectF(const gfx::RectF& rect) {
|
||||
return PP_MakeFloatRectFromXYWH(rect.x(), rect.y(), rect.width(),
|
||||
rect.height());
|
||||
}
|
||||
|
||||
gfx::Size SizeFromPPSize(const PP_Size& pp_size) {
|
||||
return gfx::Size(pp_size.width, pp_size.height);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define PDF_PPAPI_MIGRATION_GEOMETRY_CONVERSIONS_H_
|
||||
|
||||
struct PP_FloatPoint;
|
||||
struct PP_FloatRect;
|
||||
struct PP_Point;
|
||||
struct PP_Rect;
|
||||
struct PP_Size;
|
||||
@ -14,6 +15,7 @@ namespace gfx {
|
||||
class Point;
|
||||
class PointF;
|
||||
class Rect;
|
||||
class RectF;
|
||||
class Size;
|
||||
class Vector2d;
|
||||
} // namespace gfx
|
||||
@ -28,6 +30,9 @@ gfx::PointF PointFFromPPFloatPoint(const PP_FloatPoint& pp_point);
|
||||
gfx::Rect RectFromPPRect(const PP_Rect& pp_rect);
|
||||
PP_Rect PPRectFromRect(const gfx::Rect& rect);
|
||||
|
||||
gfx::RectF RectFFromPPFloatRect(const PP_FloatRect& pp_rect);
|
||||
PP_FloatRect PPFloatRectFromRectF(const gfx::RectF& rect);
|
||||
|
||||
gfx::Size SizeFromPPSize(const PP_Size& pp_size);
|
||||
PP_Size PPSizeFromSize(const gfx::Size& size);
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#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.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
|
||||
@ -67,6 +68,32 @@ TEST(GeometryConversionsTest, PPRectFromRect) {
|
||||
EXPECT_EQ(pp_c_rect.size.height, 3);
|
||||
}
|
||||
|
||||
TEST(GeometryConversionsTest, RectFFromPPFloatRect) {
|
||||
gfx::RectF rect =
|
||||
RectFFromPPFloatRect(pp::FloatRect(-1.0f, 2.1f, 3.2f, 4.3f));
|
||||
EXPECT_EQ(rect, gfx::RectF(-1.0f, 2.1f, 3.2f, 4.3f));
|
||||
|
||||
rect =
|
||||
RectFFromPPFloatRect(PP_MakeFloatRectFromXYWH(2.9f, -1.8f, 4.7f, 3.6f));
|
||||
EXPECT_EQ(rect, gfx::RectF(2.9f, -1.8f, 4.7f, 3.6f));
|
||||
}
|
||||
|
||||
TEST(GeometryConversionsTest, PPFloatRectFromRectF) {
|
||||
pp::FloatRect pp_cpp_rect =
|
||||
PPFloatRectFromRectF(gfx::RectF(-1.1f, 2.3f, 3.5f, 4.7f));
|
||||
EXPECT_EQ(pp_cpp_rect.x(), -1.1f);
|
||||
EXPECT_EQ(pp_cpp_rect.y(), 2.3f);
|
||||
EXPECT_EQ(pp_cpp_rect.width(), 3.5f);
|
||||
EXPECT_EQ(pp_cpp_rect.height(), 4.7f);
|
||||
|
||||
PP_FloatRect pp_c_rect =
|
||||
PPFloatRectFromRectF(gfx::RectF(2.2f, -1.4f, 4.6f, 3.8f));
|
||||
EXPECT_EQ(pp_c_rect.point.x, 2.2f);
|
||||
EXPECT_EQ(pp_c_rect.point.y, -1.4f);
|
||||
EXPECT_EQ(pp_c_rect.size.width, 4.6f);
|
||||
EXPECT_EQ(pp_c_rect.size.height, 3.8f);
|
||||
}
|
||||
|
||||
TEST(GeometryConversionsTest, SizeFromPPSize) {
|
||||
gfx::Size size = SizeFromPPSize(pp::Size(3, 4));
|
||||
EXPECT_EQ(size, gfx::Size(3, 4));
|
||||
|
Reference in New Issue
Block a user