Break on hyphens without minikin::Hyphenator, tests.
Change-Id: I42e449134ac8c007ffa07d7f56a8c56a26ec47a5
This commit is contained in:
@@ -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 <consonant, ASAT, VIRAMA, consonant>. This is to go
|
||||
// around a bug in ICU line breaking: http://bugs.icu-project.org/trac/ticket/12561. To avoid
|
||||
|
||||
@@ -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<uint16_t> text_;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user