Skip to content

Commit b4ed303

Browse files
authored
Revert "RTL handling for ghost runs, NotoNaskhArabic test font (flutter#8638)" (flutter#8681)
This reverts commit 6e79dcd. Reverts flutter/engine#8638 Reason: flutter/engine#8638 breaks the post-submit Cirrus tests. See https://cirrus-ci.com/build/5143341531398144 and subsequent post-submit failures. Specifically, ParagraphTest.RightAlignParagraph is failing. TBR: @GaryQian
1 parent 8b5f776 commit b4ed303

File tree

4 files changed

+24
-228
lines changed

4 files changed

+24
-228
lines changed

third_party/txt/src/txt/paragraph.cc

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
#include "paragraph.h"
1818

1919
#include <hb.h>
20-
#include <minikin/Layout.h>
21-
2220
#include <algorithm>
2321
#include <limits>
2422
#include <map>
2523
#include <numeric>
2624
#include <utility>
2725
#include <vector>
2826

27+
#include <minikin/Layout.h>
2928
#include "flutter/fml/logging.h"
3029
#include "font_collection.h"
3130
#include "font_skia.h"
@@ -35,6 +34,9 @@
3534
#include "minikin/LayoutUtils.h"
3635
#include "minikin/LineBreaker.h"
3736
#include "minikin/MinikinFont.h"
37+
#include "unicode/ubidi.h"
38+
#include "unicode/utf16.h"
39+
3840
#include "third_party/skia/include/core/SkCanvas.h"
3941
#include "third_party/skia/include/core/SkFont.h"
4042
#include "third_party/skia/include/core/SkFontMetrics.h"
@@ -44,8 +46,6 @@
4446
#include "third_party/skia/include/core/SkTypeface.h"
4547
#include "third_party/skia/include/effects/SkDashPathEffect.h"
4648
#include "third_party/skia/include/effects/SkDiscretePathEffect.h"
47-
#include "unicode/ubidi.h"
48-
#include "unicode/utf16.h"
4949

5050
namespace txt {
5151
namespace {
@@ -552,39 +552,28 @@ void Paragraph::Layout(double width, bool force) {
552552
// Find the runs comprising this line.
553553
std::vector<BidiRun> line_runs;
554554
for (const BidiRun& bidi_run : bidi_runs) {
555+
if (bidi_run.start() < line_end_index &&
556+
bidi_run.end() > line_range.start) {
557+
line_runs.emplace_back(std::max(bidi_run.start(), line_range.start),
558+
std::min(bidi_run.end(), line_end_index),
559+
bidi_run.direction(), bidi_run.style());
560+
}
555561
// A "ghost" run is a run that does not impact the layout, breaking,
556-
// alignment, width, etc but is still "visible" through getRectsForRange.
562+
// alignment, width, etc but is still "visible" though getRectsForRange.
557563
// For example, trailing whitespace on centered text can be scrolled
558564
// through with the caret but will not wrap the line.
559565
//
560566
// Here, we add an additional run for the whitespace, but dont
561567
// let it impact metrics. After layout of the whitespace run, we do not
562568
// add its width into the x-offset adjustment, effectively nullifying its
563569
// impact on the layout.
564-
std::unique_ptr<BidiRun> ghost_run = nullptr;
565570
if (paragraph_style_.ellipsis.empty() &&
566571
line_range.end_excluding_whitespace < line_range.end &&
567572
bidi_run.start() <= line_range.end &&
568573
bidi_run.end() > line_end_index) {
569-
ghost_run = std::make_unique<BidiRun>(
570-
std::max(bidi_run.start(), line_end_index),
571-
std::min(bidi_run.end(), line_range.end), bidi_run.direction(),
572-
bidi_run.style(), true);
573-
}
574-
// Include the ghost run before normal run if RTL
575-
if (bidi_run.direction() == TextDirection::rtl && ghost_run != nullptr) {
576-
line_runs.push_back(*ghost_run);
577-
}
578-
// Emplace a normal line run.
579-
if (bidi_run.start() < line_end_index &&
580-
bidi_run.end() > line_range.start) {
581-
line_runs.emplace_back(std::max(bidi_run.start(), line_range.start),
582-
std::min(bidi_run.end(), line_end_index),
583-
bidi_run.direction(), bidi_run.style());
584-
}
585-
// Include the ghost run after normal run if LTR
586-
if (bidi_run.direction() == TextDirection::ltr && ghost_run != nullptr) {
587-
line_runs.push_back(*ghost_run);
574+
line_runs.emplace_back(std::max(bidi_run.start(), line_end_index),
575+
std::min(bidi_run.end(), line_range.end),
576+
bidi_run.direction(), bidi_run.style(), true);
588577
}
589578
}
590579
bool line_runs_all_rtl =
@@ -672,17 +661,6 @@ void Paragraph::Layout(double width, bool force) {
672661
if (layout.nGlyphs() == 0)
673662
continue;
674663

675-
// When laying out RTL ghost runs, shift the run_x_offset here by the
676-
// advance so that the ghost run is positioned to the left of the first
677-
// real run of text in the line. However, since we do not want it to
678-
// impact the layout of real text, this advance is subsequently added
679-
// back into the run_x_offset after the ghost run positions have been
680-
// calcuated and before the next real run of text is laid out, ensuring
681-
// later runs are laid out in the same position as if there were no ghost
682-
// run.
683-
if (run.is_ghost() && run.is_rtl())
684-
run_x_offset -= layout.getAdvance();
685-
686664
std::vector<float> layout_advances(text_count);
687665
layout.getAdvances(layout_advances.data());
688666

@@ -830,25 +808,21 @@ void Paragraph::Layout(double width, bool force) {
830808
[](const GlyphPosition& a, const GlyphPosition& b) {
831809
return a.code_units.start < b.code_units.start;
832810
});
833-
834811
line_code_unit_runs.emplace_back(
835812
std::move(code_unit_positions),
836813
Range<size_t>(run.start(), run.end()),
837814
Range<double>(glyph_positions.front().x_pos.start,
838815
glyph_positions.back().x_pos.end),
839816
line_number, metrics, run.direction());
840817

841-
if (!run.is_ghost()) {
842-
min_left_ = std::min(min_left_, glyph_positions.front().x_pos.start);
843-
max_right_ = std::max(max_right_, glyph_positions.back().x_pos.end);
844-
}
818+
min_left_ = std::min(min_left_, glyph_positions.front().x_pos.start);
819+
max_right_ = std::max(max_right_, glyph_positions.back().x_pos.end);
845820
} // for each in glyph_blobs
846-
// Do not increase x offset for LTR trailing ghost runs as it should not
847-
// impact the layout of visible glyphs. RTL tailing ghost runs have the
848-
// advance subtracted, so we do add the advance here to reset the
849-
// run_x_offset. We do keep the record though so GetRectsForRange() can
850-
// find metrics for trailing spaces.
851-
if (!run.is_ghost() || run.is_rtl()) {
821+
822+
// Do not increase x offset for trailing ghost runs as it should not
823+
// impact the layout of visible glyphs. We do keep the record though so
824+
// GetRectsForRange() can find metrics for trailing spaces.
825+
if (!run.is_ghost()) {
852826
run_x_offset += layout.getAdvance();
853827
}
854828
} // for each in line_runs

third_party/txt/tests/paragraph_unittests.cc

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(JustifyRTL)) {
706706
txt::ParagraphStyle paragraph_style;
707707
paragraph_style.max_lines = 14;
708708
paragraph_style.text_align = TextAlign::justify;
709-
paragraph_style.text_direction = TextDirection::rtl;
710709
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
711710

712711
txt::TextStyle text_style;
@@ -726,33 +725,16 @@ TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(JustifyRTL)) {
726725

727726
paragraph->Paint(GetCanvas(), 0, 0);
728727

728+
ASSERT_TRUE(Snapshot());
729+
729730
auto glyph_line_width = [&paragraph](int index) {
730731
size_t second_to_last_position_index =
731-
paragraph->glyph_lines_[index].positions.size() - 1;
732+
paragraph->glyph_lines_[index].positions.size() - 2;
732733
return paragraph->glyph_lines_[index]
733734
.positions[second_to_last_position_index]
734735
.x_pos.end;
735736
};
736737

737-
SkPaint paint;
738-
paint.setStyle(SkPaint::kStroke_Style);
739-
paint.setAntiAlias(true);
740-
paint.setStrokeWidth(1);
741-
742-
// Tests for GetRectsForRange()
743-
Paragraph::RectHeightStyle rect_height_style =
744-
Paragraph::RectHeightStyle::kMax;
745-
Paragraph::RectWidthStyle rect_width_style =
746-
Paragraph::RectWidthStyle::kTight;
747-
paint.setColor(SK_ColorRED);
748-
std::vector<txt::Paragraph::TextBox> boxes =
749-
paragraph->GetRectsForRange(0, 100, rect_height_style, rect_width_style);
750-
for (size_t i = 0; i < boxes.size(); ++i) {
751-
GetCanvas()->drawRect(boxes[i].rect, paint);
752-
}
753-
ASSERT_EQ(boxes.size(), 5ull);
754-
ASSERT_TRUE(Snapshot());
755-
756738
// All lines except the last should be justified to the width of the
757739
// paragraph.
758740
for (size_t i = 0; i < paragraph->glyph_lines_.size() - 1; ++i) {
@@ -989,74 +971,6 @@ TEST_F(ParagraphTest, DISABLED_ArabicParagraph) {
989971
ASSERT_TRUE(Snapshot());
990972
}
991973

992-
// Checks if the rects are in the correct positions after typing spaces in
993-
// Arabic.
994-
TEST_F(ParagraphTest, DISABLE_ON_WINDOWS(ArabicRectsParagraph)) {
995-
const char* text = "بمباركة التقليدية قام عن. تصفح يد ";
996-
auto icu_text = icu::UnicodeString::fromUTF8(text);
997-
std::u16string u16_text(icu_text.getBuffer(),
998-
icu_text.getBuffer() + icu_text.length());
999-
1000-
txt::ParagraphStyle paragraph_style;
1001-
paragraph_style.max_lines = 14;
1002-
paragraph_style.text_align = TextAlign::right;
1003-
paragraph_style.text_direction = TextDirection::rtl;
1004-
txt::ParagraphBuilder builder(paragraph_style, GetTestFontCollection());
1005-
1006-
txt::TextStyle text_style;
1007-
text_style.font_families = std::vector<std::string>(1, "Noto Naskh Arabic");
1008-
text_style.font_size = 26;
1009-
text_style.letter_spacing = 1;
1010-
text_style.word_spacing = 5;
1011-
text_style.color = SK_ColorBLACK;
1012-
text_style.height = 1;
1013-
text_style.decoration = TextDecoration::kUnderline;
1014-
text_style.decoration_color = SK_ColorBLACK;
1015-
builder.PushStyle(text_style);
1016-
1017-
builder.AddText(u16_text);
1018-
1019-
builder.Pop();
1020-
1021-
auto paragraph = builder.Build();
1022-
paragraph->Layout(GetTestCanvasWidth() - 100);
1023-
1024-
paragraph->Paint(GetCanvas(), 0, 0);
1025-
1026-
SkPaint paint;
1027-
paint.setStyle(SkPaint::kStroke_Style);
1028-
paint.setAntiAlias(true);
1029-
paint.setStrokeWidth(1);
1030-
1031-
// Tests for GetRectsForRange()
1032-
Paragraph::RectHeightStyle rect_height_style =
1033-
Paragraph::RectHeightStyle::kMax;
1034-
Paragraph::RectWidthStyle rect_width_style =
1035-
Paragraph::RectWidthStyle::kTight;
1036-
paint.setColor(SK_ColorRED);
1037-
std::vector<txt::Paragraph::TextBox> boxes =
1038-
paragraph->GetRectsForRange(0, 100, rect_height_style, rect_width_style);
1039-
for (size_t i = 0; i < boxes.size(); ++i) {
1040-
GetCanvas()->drawRect(boxes[i].rect, paint);
1041-
}
1042-
EXPECT_EQ(boxes.size(), 2ull);
1043-
1044-
EXPECT_FLOAT_EQ(boxes[0].rect.left(), 556.54688);
1045-
EXPECT_FLOAT_EQ(boxes[0].rect.top(), -0.26855469);
1046-
EXPECT_FLOAT_EQ(boxes[0].rect.right(), 900);
1047-
EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 44);
1048-
1049-
EXPECT_FLOAT_EQ(boxes[1].rect.left(), 510.09375);
1050-
EXPECT_FLOAT_EQ(boxes[1].rect.top(), -0.26855469);
1051-
EXPECT_FLOAT_EQ(boxes[1].rect.right(), 557.04688);
1052-
EXPECT_FLOAT_EQ(boxes[1].rect.bottom(), 44);
1053-
1054-
ASSERT_EQ(paragraph_style.text_align,
1055-
paragraph->GetParagraphStyle().text_align);
1056-
1057-
ASSERT_TRUE(Snapshot());
1058-
}
1059-
1060974
TEST_F(ParagraphTest, GetGlyphPositionAtCoordinateParagraph) {
1061975
const char* text =
1062976
"12345 67890 12345 67890 12345 67890 12345 67890 12345 67890 12345 "

third_party/txt/third_party/fonts/NotoNaskhArabic-LICENSE.txt

Lines changed: 0 additions & 92 deletions
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)