Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 351963002: RenderTextHarfBuzz: Allow mid-glyph cursors in multi-grapheme clusters (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reuse breakiterator Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/gfx/render_text_harfbuzz.cc ('K') | « ui/gfx/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 4686066f088953085ff1df8d5e7bb381efa47866..182a06f587183e34a2534ab43321416f4d5f5f04 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -1924,34 +1924,34 @@ TEST_F(RenderTextTest, Win_BreakRunsByUnicodeBlocks) {
}
#endif // defined(OS_WIN)
-TEST_F(RenderTextTest, HarfBuzz_CharToGlyph) {
+TEST_F(RenderTextTest, HarfBuzz_Clusters) {
msw 2014/06/29 22:29:10 nit: can you add high-level comments for each of t
ckocagil 2014/07/24 21:46:56 Done.
struct {
uint32 glyph_to_char[4];
- size_t char_to_glyph_expected[4];
- Range char_range_to_glyph_range_expected[4];
+ Range chars[4];
+ Range glyphs[4];
bool is_rtl;
} cases[] = {
{ // From string "A B C D" to glyphs "a b c d".
{ 0, 1, 2, 3 },
- { 0, 1, 2, 3 },
+ { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
{ Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
false
},
- { // From string "A B C D" to glyphs "d b c a".
- { 3, 2, 1, 0 },
+ { // From string "A B C D" to glyphs "d c b a".
{ 3, 2, 1, 0 },
+ { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
{ Range(3, 4), Range(2, 3), Range(1, 2), Range(0, 1) },
true
},
{ // From string "A B C D" to glyphs "ab c c d".
{ 0, 2, 2, 3 },
- { 0, 0, 1, 3 },
+ { Range(0, 2), Range(0, 2), Range(2, 3), Range(3, 4) },
{ Range(0, 1), Range(0, 1), Range(1, 3), Range(3, 4) },
false
},
{ // From string "A B C D" to glyphs "d c c ba".
{ 3, 2, 2, 0 },
- { 3, 3, 1, 0 },
+ { Range(0, 2), Range(0, 2), Range(2, 3), Range(3, 4) },
{ Range(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) },
true
},
@@ -1960,17 +1960,65 @@ TEST_F(RenderTextTest, HarfBuzz_CharToGlyph) {
internal::TextRunHarfBuzz run;
run.range = Range(0, 4);
run.glyph_count = 4;
- run.glyph_to_char.reset(new uint32[4]);
+ run.glyph_to_char.resize(4);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 4,
- run.glyph_to_char.get());
+ run.glyph_to_char.begin());
+ run.is_rtl = cases[i].is_rtl;
+
+ for (size_t j = 0; j < 4; ++j) {
+ SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j));
+ Range chars;
+ Range glyphs;
+ run.GetClusterAt(j, &chars, &glyphs);
+ EXPECT_EQ(cases[i].chars[j], chars);
+ EXPECT_EQ(cases[i].glyphs[j], glyphs);
+ EXPECT_EQ(cases[i].glyphs[j], run.CharRangeToGlyphRange(chars));
+ }
+ }
+}
+
+TEST_F(RenderTextTest, HarfBuzz_SubglyphGrapheme) {
+ struct {
+ uint32 glyph_to_char[2];
+ Range bounds[4];
+ bool is_rtl;
+ } cases[] = {
+ { // From string "A B C D" to glyphs "a bcd".
msw 2014/06/29 22:29:10 Are there still cases where we'd expect a cursor n
ckocagil 2014/07/24 21:46:56 Done, see HarfBuzz_SubglyphGraphemeCases.
+ { 0, 1 },
+ { Range(0, 10), Range(10, 13), Range(13, 17), Range(17, 20) },
+ false
+ },
+ { // From string "A B C D" to glyphs "ab cd".
+ { 0, 2 },
+ { Range(0, 5), Range(5, 10), Range(10, 15), Range(15, 20) },
+ false
+ },
+ { // From string "A B C D" to glyphs "dcb a".
+ { 1, 0 },
+ { Range(10, 20), Range(7, 10), Range(3, 7), Range(0, 3) },
+ true
+ },
+ };
+
+ internal::TextRunHarfBuzz run;
+ run.range = Range(0, 4);
+ run.glyph_count = 2;
+ run.glyph_to_char.resize(2);
+ run.positions.reset(new SkPoint[4]);
+ run.width = 20;
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 2,
+ run.glyph_to_char.begin());
run.is_rtl = cases[i].is_rtl;
+ for (int j = 0; j < 2; ++j)
+ run.positions[j].set(j * 10, 0);
+
for (size_t j = 0; j < 4; ++j) {
SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j));
- EXPECT_EQ(cases[i].char_to_glyph_expected[j], run.CharToGlyph(j));
- EXPECT_EQ(cases[i].char_range_to_glyph_range_expected[j],
- run.CharRangeToGlyphRange(Range(j, j + 1)));
+ EXPECT_EQ(cases[i].bounds[j], run.GetGraphemeBounds(L"abcd", j));
}
}
}
« ui/gfx/render_text_harfbuzz.cc ('K') | « ui/gfx/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698