libtxt: pass an RTL bool flag instead of a bidiFlags enum to measureText (flutter/engine#13736)

Fixes https://github.com/flutter/flutter/issues/41086
This commit is contained in:
Jason Simmons
2019-11-08 15:18:06 -08:00
committed by GitHub
parent da4ce37c91
commit b374cbe299
5 changed files with 38 additions and 6 deletions

View File

@@ -218,6 +218,7 @@ test_fixtures("txt_fixtures") {
"third_party/fonts/NotoColorEmoji.ttf",
"third_party/fonts/NotoNaskhArabic-Regular.ttf",
"third_party/fonts/NotoSansCJK-Regular.ttc",
"third_party/fonts/NotoSansKhmer-Regular.ttf",
"third_party/fonts/Regular.ttf",
"third_party/fonts/Regular.ttx",
"third_party/fonts/Roboto-Black.ttf",

View File

@@ -122,13 +122,12 @@ float LineBreaker::addStyleRun(MinikinPaint* paint,
size_t end,
bool isRtl) {
float width = 0.0f;
int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;
float hyphenPenalty = 0.0;
if (paint != nullptr) {
width = Layout::measureText(mTextBuf.data(), start, end - start,
mTextBuf.size(), bidiFlags, style, *paint,
typeface, mCharWidths.data() + start);
mTextBuf.size(), isRtl, style, *paint, typeface,
mCharWidths.data() + start);
// a heuristic that seems to perform well
hyphenPenalty =
@@ -195,12 +194,12 @@ float LineBreaker::addStyleRun(MinikinPaint* paint,
paint->hyphenEdit = HyphenEdit::editForThisLine(hyph);
const float firstPartWidth = Layout::measureText(
mTextBuf.data(), lastBreak, j - lastBreak, mTextBuf.size(),
bidiFlags, style, *paint, typeface, nullptr);
isRtl, style, *paint, typeface, nullptr);
ParaWidth hyphPostBreak = lastBreakWidth + firstPartWidth;
paint->hyphenEdit = HyphenEdit::editForNextLine(hyph);
const float secondPartWidth = Layout::measureText(
mTextBuf.data(), j, afterWord - j, mTextBuf.size(), bidiFlags,
mTextBuf.data(), j, afterWord - j, mTextBuf.size(), isRtl,
style, *paint, typeface, nullptr);
ParaWidth hyphPreBreak = postBreak - secondPartWidth;

View File

@@ -161,6 +161,7 @@ class ParagraphTxt : public Paragraph {
FRIEND_TEST(ParagraphTest, InlinePlaceholder0xFFFCParagraph);
FRIEND_TEST(ParagraphTest, FontFeaturesParagraph);
FRIEND_TEST(ParagraphTest, GetGlyphPositionAtCoordinateSegfault);
FRIEND_TEST(ParagraphTest, KhmerLineBreaker);
// Starting data to layout.
std::vector<uint16_t> text_;

View File

@@ -354,7 +354,7 @@ TEST_F(ParagraphTest, DISABLE_ON_MAC(LineMetricsParagraph2)) {
ASSERT_EQ(paragraph->GetLineMetrics()[0].hard_break, false);
ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].ascent, 27.84);
ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].descent, 7.6799998);
ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].width, 349.26953);
ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].width, 348.61328);
ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].left, 0.0);
ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].baseline, 28.32);
ASSERT_EQ(paragraph->GetLineMetrics()[0].line_number, 0ull);
@@ -5815,4 +5815,35 @@ TEST_F(ParagraphTest, FontFeaturesParagraph) {
ASSERT_TRUE(Snapshot());
}
TEST_F(ParagraphTest, KhmerLineBreaker) {
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;
txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
txt::TextStyle text_style;
text_style.font_families = std::vector<std::string>(1, "Noto Sans Khmer");
text_style.font_size = 24;
text_style.color = SK_ColorBLACK;
builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = BuildParagraph(builder);
paragraph->Layout(200);
paragraph->Paint(GetCanvas(), 0, 0);
ASSERT_EQ(paragraph->glyph_lines_.size(), 3ull);
EXPECT_EQ(paragraph->glyph_lines_[0].positions.size(), 7ul);
EXPECT_EQ(paragraph->glyph_lines_[1].positions.size(), 12ul);
EXPECT_EQ(paragraph->glyph_lines_[2].positions.size(), 7ul);
ASSERT_TRUE(Snapshot());
}
} // namespace txt