Commit ac7c2593 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

RenderTextHarfBuzz: treat 「」 as brackets.

Brackets have the "common script" unicode property and need special handling
when breaking runs (see http://www.unicode.org/reports/tr24/#Common ).

Currently, emoji breaks runs correctly around other bracket and quote mark
types, but not around 「」, which is commonly used in CJK languages.

Bug: 843426, 396776
Change-Id: Ia5ff5165d5c260aa1876488e2f51d566f2164cd6
Reviewed-on: https://chromium-review.googlesource.com/1146401Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577345}
parent 276b18d4
......@@ -65,10 +65,13 @@ bool IsUnusualBlockCode(UBlockCode block_code) {
block_code == UBLOCK_MISCELLANEOUS_SYMBOLS;
}
// Returns true if |character| is a bracket. This is used to avoid "matching"
// brackets picking different font fallbacks, thereby appearing mismatched.
bool IsBracket(UChar32 character) {
static const char kBrackets[] = { '(', ')', '{', '}', '<', '>', };
static const char* kBracketsEnd = kBrackets + arraysize(kBrackets);
return std::find(kBrackets, kBracketsEnd, character) != kBracketsEnd;
// 0x300c and 0x300d are「foo」 style brackets.
constexpr UChar32 kBrackets[] = {'(', ')', '{', '}',
'<', '>', L'\u300c', L'\u300d'};
return base::ContainsValue(kBrackets, character);
}
// If the given scripts match, returns the one that isn't USCRIPT_INHERITED,
......
......@@ -4004,6 +4004,13 @@ TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByEmoji) {
EXPECT_EQ(ToString16Vec({"x", "😁", "y", "✨"}), GetRunListStrings());
// U+1F601 is represented as a surrogate pair in UTF-16.
EXPECT_EQ("[0][1->2][3][4]", GetRunListStructureString());
// Ensure non-latin 「foo」 brackets around Emoji correctly break runs.
render_text->SetText(UTF8ToUTF16("「🦋」「"));
test_api()->EnsureLayout();
EXPECT_EQ(ToString16Vec({"「", "🦋", "」「"}), GetRunListStrings());
// Note 🦋 is a surrogate pair [1->2].
EXPECT_EQ("[0][1->2][3->4]", GetRunListStructureString());
}
TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByEmojiVariationSelectors) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment