From 39f8a13f4dc5d785b5f68ea7f5cd3ce6112b7745 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 7 Aug 2017 10:22:13 -0700 Subject: [PATCH] Break on hyphens without minikin::Hyphenator, tests. Change-Id: I42e449134ac8c007ffa07d7f56a8c56a26ec47a5 --- .../src/flutter/libs/minikin/WordBreaker.cpp | 3 +- engine/src/flutter/src/paragraph.h | 1 + engine/src/flutter/src/styled_runs.h | 1 + .../flutter/tests/txt/paragraph_unittests.cc | 45 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 8d0d0fb4b4..3577ddd6aa 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -70,7 +70,8 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { U16_PREV(buf, 0, prev_offset, codePoint); // Do not break on hard or soft hyphens. These are handled by automatic hyphenation. if (Hyphenator::isLineBreakingHyphen(codePoint) || codePoint == CHAR_SOFT_HYPHEN) { - return false; + // txt addition: Temporarily always break on hyphen. Changed from false to true. + return true; } // For Myanmar kinzi sequences, created by . This is to go // around a bug in ICU line breaking: http://bugs.icu-project.org/trac/ticket/12561. To avoid diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 3208c65d8c..08d90e7846 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -162,6 +162,7 @@ class Paragraph { FRIEND_TEST(RenderTest, KernScaleParagraph); FRIEND_TEST(RenderTest, NewlineParagraph); FRIEND_TEST(RenderTest, EmojiParagraph); + FRIEND_TEST(RenderTest, HyphenBreakParagraph); // Starting data to layout. std::vector text_; diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index 24ac305700..e731d61b16 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -76,6 +76,7 @@ class StyledRuns { FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph); FRIEND_TEST(RenderTest, LongWordParagraph); FRIEND_TEST(RenderTest, KernParagraph); + FRIEND_TEST(RenderTest, HyphenBreakParagraph); 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 8c45dbbd02..abdff311e7 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -1439,4 +1439,49 @@ TEST_F(RenderTest, EmojiParagraph) { ASSERT_TRUE(Snapshot()); } +TEST_F(RenderTest, HyphenBreakParagraph) { + const char* text = + "A " + "very-very-long-Hyphen-word-to-see-where-this-will-wrap-or-if-it-will-at-" + "all-and-if-it-does-thent-hat-" + "would-be-a-good-thing-because-the-breaking."; + 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.break_strategy = minikin::kBreakStrategy_HighQuality; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + + txt::TextStyle text_style; + text_style.font_family = "Roboto"; + text_style.font_size = 31; + text_style.letter_spacing = 0; + text_style.word_spacing = 0; + text_style.color = SK_ColorBLACK; + text_style.height = 1; + builder.PushStyle(text_style); + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() / 2); + + paragraph->Paint(GetCanvas(), 0, 0); + + ASSERT_TRUE(Snapshot()); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } + 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->GetLineCount(), 5); + ASSERT_TRUE(Snapshot()); +} + } // namespace txt