Commit 8831eb95 authored by Ankit Kumar 🌪️'s avatar Ankit Kumar 🌪️ Committed by Commit Bot

PDF Accessibility: Refactor paragraph breaking logic

Moving paragraph breaking logic from AddPageContent() into its own
function.

Bug: 981448
Change-Id: I6b23a39824a5aac7599a912ec162e195b01939d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775680Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#691513}
parent 8701d624
...@@ -153,6 +153,23 @@ void FinishStaticNode(ui::AXNodeData** static_text_node, ...@@ -153,6 +153,23 @@ void FinishStaticNode(ui::AXNodeData** static_text_node,
*previous_on_line_node = nullptr; *previous_on_line_node = nullptr;
} }
bool BreakParagraph(
const std::vector<PP_PrivateAccessibilityTextRunInfo>& text_runs,
uint32_t text_run_index,
double paragraph_spacing_threshold) {
// Check to see if its also a new paragraph, i.e., if the distance between
// lines is greater than the threshold. If there's no threshold, that
// means there weren't enough lines to compute an accurate median, so
// we compare against the line size instead.
double line_spacing = fabs(text_runs[text_run_index + 1].bounds.point.y -
text_runs[text_run_index].bounds.point.y);
return ((paragraph_spacing_threshold > 0 &&
line_spacing > paragraph_spacing_threshold) ||
(paragraph_spacing_threshold == 0 &&
line_spacing > kParagraphLineSpacingRatio *
text_runs[text_run_index].bounds.size.height));
}
ui::AXNode* GetStaticTextNodeFromNode(ui::AXNode* node) { ui::AXNode* GetStaticTextNodeFromNode(ui::AXNode* node) {
// Returns the appropriate static text node given |node|'s type. // Returns the appropriate static text node given |node|'s type.
// Returns nullptr if there is no appropriate static text node. // Returns nullptr if there is no appropriate static text node.
...@@ -448,17 +465,8 @@ void PdfAccessibilityTree::AddPageContent( ...@@ -448,17 +465,8 @@ void PdfAccessibilityTree::AddPageContent(
// The next run is on a new line. // The next run is on a new line.
previous_on_line_node = nullptr; previous_on_line_node = nullptr;
// Check to see if its also a new paragraph, i.e., if the distance between if (BreakParagraph(text_runs, text_run_index,
// lines is greater than the threshold. If there's no threshold, that paragraph_spacing_threshold)) {
// means there weren't enough lines to compute an accurate median, so
// we compare against the line size instead.
double line_spacing = fabs(text_runs[text_run_index + 1].bounds.point.y -
text_runs[text_run_index].bounds.point.y);
if ((paragraph_spacing_threshold > 0 &&
line_spacing > paragraph_spacing_threshold) ||
(paragraph_spacing_threshold == 0 &&
line_spacing > kParagraphLineSpacingRatio *
text_runs[text_run_index].bounds.size.height)) {
if (static_text_node) { if (static_text_node) {
static_text_node->AddStringAttribute( static_text_node->AddStringAttribute(
ax::mojom::StringAttribute::kName, static_text); ax::mojom::StringAttribute::kName, static_text);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment