diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 3b07c4ee70..9c789b9d0b 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -328,7 +328,8 @@ void Paragraph::Layout(double width, bool force) { alphabetic_baseline_ = metrics.fCapHeight * run.style.height; // TODO(garyq): Properly implement ideographic_baseline_. ideographic_baseline_ = - (metrics.fDescent + metrics.fCapHeight) * run.style.height; + (metrics.fUnderlinePosition + metrics.fCapHeight) * + run.style.height; } } if (max_descent < metrics.fDescent * run.style.height) @@ -412,7 +413,7 @@ double Paragraph::GetAlphabeticBaseline() const { } double Paragraph::GetIdeographicBaseline() const { - // TODO(garyq): Implement. + // TODO(garyq): Currently fCapHeight + fUnderlinePosition. Verify this. return ideographic_baseline_; } @@ -421,8 +422,8 @@ double Paragraph::GetMaxIntrinsicWidth() const { } double Paragraph::GetMinIntrinsicWidth() const { - // TODO(garyq): Implement. - return min_intrinsic_width_; + // TODO(garyq): This is a lower bound. Actual value may be slightly higher. + return max_intrinsic_width_ / paragraph_style_.max_lines; } double Paragraph::GetHeight() const { @@ -531,8 +532,8 @@ void Paragraph::PaintDecorations(SkCanvas* canvas, // Overline if (style.decoration & 0x2) { if (style.decoration_style != TextDecorationStyle::kWavy) - canvas->drawLine(x, y + metrics.fAscent + y_offset, x + width, - y + metrics.fAscent + y_offset, paint); + canvas->drawLine(x, y + metrics.fAscent - y_offset, x + width, + y + metrics.fAscent - y_offset, paint); else PaintWavyDecoration(canvas, wave_coords, paint, x, y, metrics.fAscent, width); diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 04ed7e7a60..845d94f3af 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -73,6 +73,7 @@ class Paragraph { FRIEND_TEST(RenderTest, DecorationsParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); FRIEND_TEST(RenderTest, ChineseParagraph); + FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph); std::vector text_; StyledRuns runs_; diff --git a/engine/src/flutter/src/paragraph_style.h b/engine/src/flutter/src/paragraph_style.h index 45f1dd745d..9f30869a15 100644 --- a/engine/src/flutter/src/paragraph_style.h +++ b/engine/src/flutter/src/paragraph_style.h @@ -34,7 +34,10 @@ class ParagraphStyle { double font_size = 14; size_t max_lines = 1; double line_height = 1.0; - std::string ellipsis; + std::string ellipsis = "..."; + // TODO(garyq): Implement right to left. + // Right to left (Arabic, Hebrew, etc). + bool rtl = false; }; } // namespace txt diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index d61ea1c57f..dbaa111db3 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -67,6 +67,7 @@ class StyledRuns { FRIEND_TEST(RenderTest, DecorationsParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); FRIEND_TEST(RenderTest, ChineseParagraph); + FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph); struct IndexedRun { size_t style_index = 0; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 5cb2a75bc6..bec51d51b3 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -763,6 +763,7 @@ TEST_F(RenderTest, ChineseParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::right; auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); txt::ParagraphBuilder builder(paragraph_style, &font_collection); @@ -794,4 +795,55 @@ TEST_F(RenderTest, ChineseParagraph) { ASSERT_TRUE(Snapshot()); } +// TODO(garyq): Support RTL languages. +TEST_F(RenderTest, DISABLED_ArabicParagraph) { + const char* text = + "من أسر وإعلان الخاصّة وهولندا،, عل قائمة الضغوط بالمطالبة تلك. الصفحة " + "بمباركة التقليدية قام عن. تصفح"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::right; + paragraph_style.rtl = true; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + text_style.font_size = 35; + text_style.letter_spacing = 2; + text_style.font_family = "Katibeh"; + text_style.decoration = txt::TextDecoration(0x1 | 0x2 | 0x4); + text_style.decoration_style = txt::TextDecorationStyle::kSolid; + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() - 100); + + paragraph->Paint(GetCanvas(), 0, 0); + + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_EQ(paragraph->records_.size(), 2ull); + ASSERT_EQ(paragraph->paragraph_style_.rtl, true); + + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[u16_text.length() - i]); + } + + ASSERT_TRUE(Snapshot()); +} + } // namespace txt