Remove redundant PDFiumPage::GetCharAtIndex()
Delete this method and switch callers to use GetCharUnicode() instead. They essentially do the same thing. Change-Id: Ibbd1ad354f1e428b0cd7cc98d6b1e95135a1a4f6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5874616 Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Reviewed-by: Andy Phan <andyphan@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1358284}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
951ace7591
commit
eab13f8680
@ -236,7 +236,7 @@ void FormatStringForOS(std::u16string* text) {
|
||||
// For triple clicks, look for line breaks.
|
||||
// The actual algorithm used in Blink is much more complicated, so do a simple
|
||||
// approximation.
|
||||
bool FindMultipleClickBoundary(bool is_double_click, char16_t cur) {
|
||||
bool FindMultipleClickBoundary(bool is_double_click, uint32_t cur) {
|
||||
if (!is_double_click)
|
||||
return cur == '\n';
|
||||
|
||||
@ -1250,7 +1250,7 @@ void PDFiumEngine::OnMultipleClick(int click_count,
|
||||
// now it doesn't.
|
||||
int start_index = char_index;
|
||||
do {
|
||||
char16_t cur = pages_[page_index]->GetCharAtIndex(start_index);
|
||||
uint32_t cur = pages_[page_index]->GetCharUnicode(start_index);
|
||||
if (FindMultipleClickBoundary(is_double_click, cur))
|
||||
break;
|
||||
} while (--start_index >= 0);
|
||||
@ -1260,7 +1260,7 @@ void PDFiumEngine::OnMultipleClick(int click_count,
|
||||
int end_index = char_index;
|
||||
const int total = pages_[page_index]->GetCharCount();
|
||||
for (; end_index < total; ++end_index) {
|
||||
char16_t cur = pages_[page_index]->GetCharAtIndex(end_index);
|
||||
uint32_t cur = pages_[page_index]->GetCharUnicode(end_index);
|
||||
if (FindMultipleClickBoundary(is_double_click, cur))
|
||||
break;
|
||||
}
|
||||
|
@ -470,6 +470,13 @@ void PDFiumPage::CalculatePageObjectTextRunBreaks() {
|
||||
}
|
||||
}
|
||||
|
||||
int PDFiumPage::GetCharCount() {
|
||||
if (!available_) {
|
||||
return 0;
|
||||
}
|
||||
return FPDFText_CountChars(GetTextPage());
|
||||
}
|
||||
|
||||
std::optional<AccessibilityTextRunInfo> PDFiumPage::GetTextRunInfo(
|
||||
int start_char_index) {
|
||||
FPDF_PAGE page = GetPage();
|
||||
@ -643,8 +650,10 @@ std::optional<AccessibilityTextRunInfo> PDFiumPage::GetTextRunInfo(
|
||||
}
|
||||
|
||||
uint32_t PDFiumPage::GetCharUnicode(int char_index) {
|
||||
FPDF_TEXTPAGE text_page = GetTextPage();
|
||||
return FPDFText_GetUnicode(text_page, char_index);
|
||||
// No explicit `available_` check here to return 0 when unavailable.
|
||||
// If this page is unavailable, GetTextPage() returns nullptr and
|
||||
// FPDFText_GetUnicode() naturally returns 0.
|
||||
return FPDFText_GetUnicode(GetTextPage(), char_index);
|
||||
}
|
||||
|
||||
gfx::RectF PDFiumPage::GetCharBounds(int char_index) {
|
||||
@ -1001,18 +1010,6 @@ PDFiumPage::Area PDFiumPage::FormTypeToArea(int form_type) {
|
||||
}
|
||||
}
|
||||
|
||||
char16_t PDFiumPage::GetCharAtIndex(int index) {
|
||||
if (!available_)
|
||||
return u'\0';
|
||||
return static_cast<char16_t>(FPDFText_GetUnicode(GetTextPage(), index));
|
||||
}
|
||||
|
||||
int PDFiumPage::GetCharCount() {
|
||||
if (!available_)
|
||||
return 0;
|
||||
return FPDFText_CountChars(GetTextPage());
|
||||
}
|
||||
|
||||
bool PDFiumPage::IsCharIndexInBounds(int index) {
|
||||
return index >= 0 && index < GetCharCount();
|
||||
}
|
||||
|
@ -74,6 +74,9 @@ class PDFiumPage {
|
||||
// Returns FPDF_TEXTPAGE for the page, loading and parsing it if necessary.
|
||||
FPDF_TEXTPAGE GetTextPage();
|
||||
|
||||
// Gets the number of characters in the page.
|
||||
int GetCharCount();
|
||||
|
||||
// See definition of PDFiumEngine::GetTextRunInfo().
|
||||
std::optional<AccessibilityTextRunInfo> GetTextRunInfo(int start_char_index);
|
||||
|
||||
@ -191,12 +194,6 @@ class PDFiumPage {
|
||||
// Converts a form type to its corresponding Area.
|
||||
static Area FormTypeToArea(int form_type);
|
||||
|
||||
// Gets the character at the given index.
|
||||
char16_t GetCharAtIndex(int index);
|
||||
|
||||
// Gets the number of characters in the page.
|
||||
int GetCharCount();
|
||||
|
||||
// Returns true if the given `char_index` lies within the character range
|
||||
// of the page.
|
||||
bool IsCharIndexInBounds(int char_index);
|
||||
|
@ -165,17 +165,17 @@ TEST_P(PDFiumPageTest, IsCharInPageBounds) {
|
||||
const gfx::RectF page_bounds = page.GetCroppedRect();
|
||||
EXPECT_EQ(page_bounds, gfx::RectF(193.33333f, 129.33333f));
|
||||
|
||||
EXPECT_EQ(page.GetCharAtIndex(0), 'H');
|
||||
EXPECT_EQ(page.GetCharUnicode(0), static_cast<uint32_t>('H'));
|
||||
EXPECT_FALSE(page.IsCharInPageBounds(0, page_bounds));
|
||||
EXPECT_EQ(page.GetCharAtIndex(12), '!');
|
||||
EXPECT_EQ(page.GetCharUnicode(12), static_cast<uint32_t>('!'));
|
||||
EXPECT_TRUE(page.IsCharInPageBounds(12, page_bounds));
|
||||
EXPECT_EQ(page.GetCharAtIndex(13), '\r');
|
||||
EXPECT_EQ(page.GetCharUnicode(13), static_cast<uint32_t>('\r'));
|
||||
EXPECT_TRUE(page.IsCharInPageBounds(13, page_bounds));
|
||||
EXPECT_EQ(page.GetCharAtIndex(14), '\n');
|
||||
EXPECT_EQ(page.GetCharUnicode(14), static_cast<uint32_t>('\n'));
|
||||
EXPECT_TRUE(page.IsCharInPageBounds(14, page_bounds));
|
||||
EXPECT_EQ(page.GetCharAtIndex(15), 'G');
|
||||
EXPECT_EQ(page.GetCharUnicode(15), static_cast<uint32_t>('G'));
|
||||
EXPECT_FALSE(page.IsCharInPageBounds(15, page_bounds));
|
||||
EXPECT_EQ(page.GetCharAtIndex(29), '!');
|
||||
EXPECT_EQ(page.GetCharUnicode(29), static_cast<uint32_t>('!'));
|
||||
EXPECT_FALSE(page.IsCharInPageBounds(29, page_bounds));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user