0

Revert "PDF a11y: kTextDirection attribute support"

This reverts commit 753f8707ad.

Reason for revert: Test failing on multiple bots.
https://ci.chromium.org/p/chromium/builders/ci/Mac10.10%20Tests/46160
https://ci.chromium.org/p/chromium/builders/ci/Linux%20Tests/81082

Original change's description:
> PDF a11y: kTextDirection attribute support
> 
> The text direction attribute is now properly set for text runs in PDF.
> It is inferred by the position of the first and the last characters of
> a text run.
> 
> This change includes a pdf-template file (text-direction.in) with RTL
> text representation used to generate our unit test PDF file.
> 
> Bug: 985604
> Change-Id: If5d82296463331e95c4ded4e5244d65be3fbadfa
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1737019
> Commit-Queue: Benjamin Beaudry <benjamin.beaudry@microsoft.com>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com>
> Cr-Commit-Position: refs/heads/master@{#690163}

TBR=thestig@chromium.org,kbabbitt@microsoft.com,benjamin.beaudry@microsoft.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 985604
Change-Id: Ic276193fbc4d1d60ae234a653b1decf2094036b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768606
Reviewed-by: Anand Mistry <amistry@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690260}
This commit is contained in:
Anand Mistry
2019-08-26 03:41:28 +00:00
committed by Commit Bot
parent 02536c5796
commit 003b20aba4
12 changed files with 51 additions and 340 deletions

@ -2407,44 +2407,13 @@ class PDFExtensionAccessibilityTreeDumpTest
private:
using PropertyFilter = content::AccessibilityTreeFormatter::PropertyFilter;
// See chrome/test/data/pdf/accessibility/readme.md for more info.
void ParsePdfForExtraDirectives(
const std::string& pdf_contents,
content::AccessibilityTreeFormatter* formatter,
std::vector<PropertyFilter>* property_filters) {
const char kCommentMark = '%';
for (const std::string& line : base::SplitString(
pdf_contents, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
if (line.size() > 1 && line[0] == kCommentMark) {
// Remove first character since it's the comment mark.
std::string trimmed_line = line.substr(1);
const std::string& allow_str = formatter->GetAllowString();
if (base::StartsWith(trimmed_line, allow_str,
base::CompareCase::SENSITIVE)) {
property_filters->push_back(PropertyFilter(
base::UTF8ToUTF16(trimmed_line.substr(allow_str.size())),
PropertyFilter::ALLOW));
}
}
}
}
void RunTest(const base::FilePath& test_file_path, const char* file_dir) {
std::string pdf_contents;
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::ReadFileToString(test_file_path, &pdf_contents));
}
// Set up the tree formatter. Parse filters and other directives in the test
// file.
// Set up the tree formatter.
std::unique_ptr<content::AccessibilityTreeFormatter> formatter =
test_pass_.create_formatter();
std::vector<PropertyFilter> property_filters;
formatter->AddDefaultFilters(&property_filters);
AddDefaultFilters(&property_filters);
ParsePdfForExtraDirectives(pdf_contents, formatter.get(),
&property_filters);
formatter->SetPropertyFilters(property_filters);
// Exit without running the test if we can't find an expectation file or if
@ -2563,7 +2532,3 @@ IN_PROC_BROWSER_TEST_P(PDFExtensionAccessibilityTreeDumpTest,
DirectionalTextRuns) {
RunPDFTest(FILE_PATH_LITERAL("directional-text-runs.pdf"));
}
IN_PROC_BROWSER_TEST_P(PDFExtensionAccessibilityTreeDumpTest, TextDirection) {
RunPDFTest(FILE_PATH_LITERAL("text-direction.pdf"));
}

@ -1,23 +0,0 @@
# PdfExtensionAccessibilityTreeDumpTest
A `PdfExtensionAccessibilityTreeDumpTest` loads a PDF file, waits for it
to load, then dumps the accessibility tree. More about accessibility tree
dump tests at `content/test/data/accessibility/readme.md`.
## Filters and directives
Please refer to `content/test/data/accessibility/readme.md` to see
how to use filters. Supported filters and directives are:
* [x] `@<platform>-ALLOW:`
* [ ] `@<platform>-ALLOW-EMPTY:`
* [ ] `@<platform>-DENY:`
* [ ] `@WAIT-FOR:`
The PdfExtensionAccessibilityTreeDumpTest implementation of extra
directives/filters is similar to the DumpAccessibilityTreeTest. If you
need to support additional directives/filters, see
/src/content/test/data/accessibility/readme.md to respect the same
interface as the one used for HTML accessibility tree dump tests.
Implementation details for parsing extra directives in HTML can be
found in `DumpAccessibilityTestBase::ParseHtmlForExtraDirectives()`.

@ -1,7 +0,0 @@
embeddedObject textDirection=ltr
++document restriction=readOnly
++++region name='Page 1' restriction=readOnly isPageBreakingObject=true
++++++paragraph restriction=readOnly
++++++++staticText name='abcdef<newline>شممشا' restriction=readOnly
++++++++++inlineTextBox name='abcdef<newline>' restriction=readOnly textDirection=ltr
++++++++++inlineTextBox name='شممشا' restriction=readOnly textDirection=rtl

@ -1,91 +0,0 @@
{{header}}
%@BLINK-ALLOW:textDirection=*
{{object 1 0}} <<
/Type /Catalog
/Pages 2 0 R
>>
endobj
{{object 2 0}} <<
/Type /Pages
/MediaBox [0 0 200 200]
/Count 1
/Kids [3 0 R]
>>
endobj
{{object 3 0}} <<
/Type /Page
/Parent 2 0 R
/Resources <<
/Font <<
/F1 4 0 R
>>
>>
/Contents 8 0 R
>>
endobj
{{object 4 0}} <<
/Type /Font
/Subtype /Type0
/BaseFont /Arial
/Encoding /Identity-H
/DescendantFonts [6 0 R]
/ToUnicode 7 0 R
>>
endobj
{{object 5 0}} <<
/Type /FontDescriptor
/FontName /Arial
>>
endobj
{{object 6 0}} <<
/Type /Font
/FontDescriptor 5 0 R
/BaseFont /Arial
/Subtype /CIDFontType2
/W [0 [778] 68 [444 500 444 500 444 333] 910 [229] 951 952 531 996 [394]]
>>
endobj
{{object 7 0}} <<
{{streamlen}}
>>
stream
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
2 beginbfchar
<038E> <FE8E>
<03E4> <FEE4>
endbfchar
2 beginbfrange
<0044> <0049> <0061>
<03B7> <03B8> <FEB7>
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
endstream
endobj
{{object 8 0}} <<
{{streamlen}}
>>
stream
BT
/F1 16 Tf
30 100 Td
<004400450046004700480049> Tj
ET
BT
/F1 16 Tf
30 50 Td
<038E03B803E403E403B7> Tj
ET
endstream
endobj
{{xref}}
{{trailer}}
{{startxref}}
%%EOF

@ -1,106 +0,0 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
%@BLINK-ALLOW:textDirection=*
1 0 obj <<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj <<
/Type /Pages
/MediaBox [0 0 200 200]
/Count 1
/Kids [3 0 R]
>>
endobj
3 0 obj <<
/Type /Page
/Parent 2 0 R
/Resources <<
/Font <<
/F1 4 0 R
>>
>>
/Contents 8 0 R
>>
endobj
4 0 obj <<
/Type /Font
/Subtype /Type0
/BaseFont /Arial
/Encoding /Identity-H
/DescendantFonts [6 0 R]
/ToUnicode 7 0 R
>>
endobj
5 0 obj <<
/Type /FontDescriptor
/FontName /Arial
>>
endobj
6 0 obj <<
/Type /Font
/FontDescriptor 5 0 R
/BaseFont /Arial
/Subtype /CIDFontType2
/W [0 [778] 68 [444 500 444 500 444 333] 910 [229] 951 952 531 996 [394]]
>>
endobj
7 0 obj <<
/Length 297
>>
stream
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
2 beginbfchar
<038E> <FE8E>
<03E4> <FEE4>
endbfchar
2 beginbfrange
<0044> <0049> <0061>
<03B7> <03B8> <FEB7>
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
endstream
endobj
8 0 obj <<
/Length 107
>>
stream
BT
/F1 16 Tf
30 100 Td
<004400450046004700480049> Tj
ET
BT
/F1 16 Tf
30 50 Td
<038E03B803E403E403B7> Tj
ET
endstream
endobj
xref
0 9
0000000000 65535 f
0000000045 00000 n
0000000098 00000 n
0000000187 00000 n
0000000313 00000 n
0000000455 00000 n
0000000519 00000 n
0000000698 00000 n
0000001047 00000 n
trailer <<
/Root 1 0 R
/Size 9
>>
startxref
1206
%%EOF

@ -574,8 +574,6 @@ ui::AXNodeData* PdfAccessibilityTree::CreateInlineTextBoxNode(
std::string chars_utf8 = GetTextRunCharsAsUTF8(text_run, chars, char_index);
inline_text_box_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
chars_utf8);
inline_text_box_node->AddIntAttribute(ax::mojom::IntAttribute::kTextDirection,
text_run.direction);
inline_text_box_node->relative_bounds.bounds =
ToGfxRectF(text_run.bounds) + page_bounds.OffsetFromOrigin();
std::vector<int32_t> char_offsets =

@ -40,51 +40,33 @@ bool GetAccessibilityInfo(
int char_index = 0;
while (char_index < char_count) {
PP_PrivateAccessibilityTextRunInfo text_run_info;
engine->GetTextRunInfo(page_index, char_index, &text_run_info);
pp::FloatRect bounds;
engine->GetTextRunInfo(page_index, char_index, &text_run_info.len,
&text_run_info.font_size, &bounds);
DCHECK_LE(char_index + text_run_info.len,
static_cast<uint32_t>(char_count));
text_run_info.direction = PP_PRIVATEDIRECTION_LTR;
text_run_info.bounds = bounds;
text_runs->push_back(text_run_info);
// We need to provide enough information to draw a bounding box
// around any arbitrary text range, but the bounding boxes of characters
// we get from PDFium don't necessarily "line up".
// Example for LTR text direction: walk through the
// we get from PDFium don't necessarily "line up". Walk through the
// characters in each text run and let the width of each character be
// the difference between the x coordinate of one character and the
// 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);
for (uint32_t i = 0; i < text_run_info.len - 1; i++) {
DCHECK_LT(char_index + i + 1, static_cast<uint32_t>(char_count));
pp::FloatRect next_char_bounds =
engine->GetCharBounds(page_index, char_index + i + 1);
double& char_width = (*chars)[char_index + i].char_width;
switch (text_run_info.direction) {
case PP_PRIVATEDIRECTION_NONE:
case PP_PRIVATEDIRECTION_LTR:
char_width = next_char_bounds.x() - char_bounds.x();
break;
case PP_PRIVATEDIRECTION_TTB:
char_width = next_char_bounds.y() - char_bounds.y();
break;
case PP_PRIVATEDIRECTION_RTL:
char_width = char_bounds.right() - next_char_bounds.right();
break;
case PP_PRIVATEDIRECTION_BTT:
char_width = char_bounds.bottom() - next_char_bounds.bottom();
break;
}
(*chars)[char_index + i].char_width =
next_char_bounds.x() - char_bounds.x();
char_bounds = next_char_bounds;
}
double& char_width =
(*chars)[char_index + text_run_info.len - 1].char_width;
if (text_run_info.direction == PP_PRIVATEDIRECTION_BTT ||
text_run_info.direction == PP_PRIVATEDIRECTION_TTB) {
char_width = char_bounds.height();
} else {
char_width = char_bounds.width();
}
(*chars)[char_index + text_run_info.len - 1].char_width =
char_bounds.width();
char_index += text_run_info.len;
}

@ -41,7 +41,6 @@ typedef void (*PDFEnsureTypefaceCharactersAccessible)(const LOGFONT* font,
struct PP_PdfAccessibilityActionData;
struct PP_PdfPrintSettings_Dev;
struct PP_PrivateAccessibilityTextRunInfo;
namespace gfx {
class Rect;
@ -359,13 +358,13 @@ class PDFEngine {
// 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
// in a single direction and with the same style and font size. Fill the
// |text_run_info| with the length of that sequence, text direction, bounding
// box and font size.
virtual void GetTextRunInfo(
int page_index,
int start_char_index,
PP_PrivateAccessibilityTextRunInfo* text_run_info) = 0;
// in a single direction and with the same style and font size. Return the
// length of that sequence and its font size and bounding box.
virtual void GetTextRunInfo(int page_index,
int start_char_index,
uint32_t* out_len,
double* out_font_size,
pp::FloatRect* out_bounds) = 0;
// Gets the PDF document's print scaling preference. True if the document can
// be scaled to fit.
virtual bool GetPrintScaling() = 0;

@ -2189,12 +2189,14 @@ uint32_t PDFiumEngine::GetCharUnicode(int page_index, int char_index) {
return pages_[page_index]->GetCharUnicode(char_index);
}
void PDFiumEngine::GetTextRunInfo(
int page_index,
int start_char_index,
PP_PrivateAccessibilityTextRunInfo* text_run_info) {
void PDFiumEngine::GetTextRunInfo(int page_index,
int start_char_index,
uint32_t* out_len,
double* out_font_size,
pp::FloatRect* out_bounds) {
DCHECK(PageIndexInBounds(page_index));
return pages_[page_index]->GetTextRunInfo(start_char_index, text_run_info);
return pages_[page_index]->GetTextRunInfo(start_char_index, out_len,
out_font_size, out_bounds);
}
bool PDFiumEngine::GetPrintScaling() {

@ -113,10 +113,11 @@ class PDFiumEngine : public PDFEngine,
int GetCharCount(int page_index) override;
pp::FloatRect GetCharBounds(int page_index, int char_index) override;
uint32_t GetCharUnicode(int page_index, int char_index) override;
void GetTextRunInfo(
int page_index,
int start_char_index,
PP_PrivateAccessibilityTextRunInfo* text_run_info) override;
void GetTextRunInfo(int page_index,
int start_char_index,
uint32_t* out_len,
double* out_font_size,
pp::FloatRect* out_bounds) override;
bool GetPrintScaling() override;
int GetCopiesToPrint() override;
int GetDuplexType() override;

@ -251,30 +251,29 @@ FPDF_TEXTPAGE PDFiumPage::GetTextPage() {
return text_page();
}
void PDFiumPage::GetTextRunInfo(
int start_char_index,
PP_PrivateAccessibilityTextRunInfo* text_run_info) {
void PDFiumPage::GetTextRunInfo(int start_char_index,
uint32_t* out_len,
double* out_font_size,
pp::FloatRect* out_bounds) {
if (start_char_index < 0) {
text_run_info->len = 0;
text_run_info->font_size = 0;
text_run_info->bounds = pp::FloatRect();
text_run_info->direction = PP_PRIVATEDIRECTION_NONE;
*out_len = 0;
*out_font_size = 0;
*out_bounds = pp::FloatRect();
return;
}
FPDF_PAGE page = GetPage();
FPDF_TEXTPAGE text_page = GetTextPage();
int chars_count = FPDFText_CountChars(text_page);
int actual_start_char_index = GetFirstNonUnicodeWhiteSpaceCharIndex(
int char_index = GetFirstNonUnicodeWhiteSpaceCharIndex(
text_page, start_char_index, chars_count);
if (actual_start_char_index >= chars_count) {
text_run_info->len = 0;
text_run_info->font_size = 0;
text_run_info->bounds = pp::FloatRect();
text_run_info->direction = PP_PRIVATEDIRECTION_NONE;
if (char_index >= chars_count) {
*out_len = 0;
*out_font_size = 0;
*out_bounds = pp::FloatRect();
return;
}
int char_index = actual_start_char_index;
pp::FloatRect start_char_rect =
GetFloatCharRectInPixels(page, text_page, char_index);
@ -377,16 +376,9 @@ void PDFiumPage::GetTextRunInfo(
text_run_font_size = estimated_font_size;
}
// 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
// character in a LTR language.
text_run_info->direction = char_index - actual_start_char_index > 1
? GetDirectionFromAngle(text_run_angle)
: PP_PRIVATEDIRECTION_NONE;
text_run_info->len = char_index - start_char_index;
text_run_info->font_size = text_run_font_size;
text_run_info->bounds = text_run_bounds;
*out_len = char_index - start_char_index;
*out_font_size = text_run_font_size;
*out_bounds = text_run_bounds;
}
uint32_t PDFiumPage::GetCharUnicode(int char_index) {

@ -20,8 +20,6 @@
#include "third_party/pdfium/public/fpdf_text.h"
#include "ui/gfx/geometry/point_f.h"
struct PP_PrivateAccessibilityTextRunInfo;
namespace chrome_pdf {
class PDFiumEngine;
@ -45,11 +43,12 @@ class PDFiumPage {
FPDF_TEXTPAGE GetTextPage();
// Given a start char index, find the longest continuous run of text that's
// in a single direction and with the same style and font size. Fill the
// |text_run_info| with the length of that sequence, text direction, bounding
// box and font size.
// in a single direction and with the same style and font size. Return the
// length of that sequence and its font size and bounding box.
void GetTextRunInfo(int start_char_index,
PP_PrivateAccessibilityTextRunInfo* text_run_info);
uint32_t* out_len,
double* out_font_size,
pp::FloatRect* out_bounds);
// Get a unicode character from the page.
uint32_t GetCharUnicode(int char_index);
// Get the bounds of a character in page pixels.