Commit eea073a1 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Use ICU definition of brackets in itemize text

This CL is replacing the hardcoded list of parens with a call to the
ICU API to get the codepoints attributes.

Splitting a run on brackets has the side-effect to ensures each
bracket (matching bracket) is rendered with the same font. This
avoid visual mismatch. The code to split text runs on brackets
was introduced to fix this:
  https://bugs.chromium.org/p/chromium/issues/detail?id=396776

Unittests are added with some codepoints that were not included as
brackets and should have been.

Bug: 995789
Change-Id: I268cc62604d755d61da2c87dd597aabfc57b7ef6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881723Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709987}
parent 954e4b97
...@@ -94,13 +94,11 @@ bool IsUnusualBlockCode(UBlockCode block_code) { ...@@ -94,13 +94,11 @@ bool IsUnusualBlockCode(UBlockCode block_code) {
block_code == UBLOCK_MISCELLANEOUS_SYMBOLS; block_code == UBLOCK_MISCELLANEOUS_SYMBOLS;
} }
// Returns true if |character| is a bracket. This is used to avoid "matching" // Returns true if |codepoint| is a bracket. This is used to avoid "matching"
// brackets picking different font fallbacks, thereby appearing mismatched. // brackets picking different font fallbacks, thereby appearing mismatched.
bool IsBracket(UChar32 character) { bool IsBracket(UChar32 codepoint) {
// 0x300c and 0x300d are「foo」 style brackets. return u_getIntPropertyValue(codepoint, UCHAR_BIDI_PAIRED_BRACKET_TYPE) !=
constexpr UChar32 kBrackets[] = {'(', ')', '{', '}', U_BPT_NONE;
'<', '>', L'\u300c', L'\u300d'};
return base::Contains(kBrackets, character);
} }
// If the given scripts match, returns the one that isn't USCRIPT_INHERITED, // If the given scripts match, returns the one that isn't USCRIPT_INHERITED,
......
...@@ -1001,6 +1001,26 @@ INSTANTIATE_TEST_SUITE_P(ItemizeTextToRunsBidi, ...@@ -1001,6 +1001,26 @@ INSTANTIATE_TEST_SUITE_P(ItemizeTextToRunsBidi,
::testing::ValuesIn(kBidiRunListCases), ::testing::ValuesIn(kBidiRunListCases),
RenderTextTestWithRunListCase::ParamInfoToString); RenderTextTestWithRunListCase::ParamInfoToString);
const RunListCase kBracketsRunListCases[] = {
{"matched_parens", L"(a)", "[0][1][2]"},
{"double_matched_parens", L"((a))", "[0->1][2][3->4]"},
{"double_matched_parens2", L"((aaa))", "[0->1][2->4][5->6]"},
{"square_brackets", L"[...]x", "[0][1->3][4][5]"},
{"curly_brackets", L"{}x{}", "[0->1][2][3->4]"},
{"style_brackets", L"\u300c...\u300dx", "[0][1->3][4][5]"},
{"tibetan_brackets", L"\u0f3a\u0f3b\u0f20\u0f20\u0f3c\u0f3d",
"[0->1][2->3][4->5]"},
{"angle_brackets", L"\u3008\u3007\u3007\u3009", "[0][1->2][3]"},
{"double_angle_brackets", L"\u300A\u3007\u3007\u300B", "[0][1->2][3]"},
{"corner_angle_brackets", L"\u300C\u3007\u3007\u300D", "[0][1->2][3]"},
{"fullwidth_parens", L"\uff08\uff01\uff09", "[0][1][2]"},
};
INSTANTIATE_TEST_SUITE_P(ItemizeTextToRunsBrackets,
RenderTextTestWithRunListCase,
::testing::ValuesIn(kBracketsRunListCases),
RenderTextTestWithRunListCase::ParamInfoToString);
TEST_F(RenderTextTest, ElidedText) { TEST_F(RenderTextTest, ElidedText) {
// TODO(skanuj) : Add more test cases for following // TODO(skanuj) : Add more test cases for following
// - RenderText styles. // - RenderText styles.
......
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