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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 300623003: Fix the Char to Glyph mapping logic in RenderTextHarfBuzz (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add tests, fix implementation 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 30677c126585789cad9bebdb16951ddc2b375755..1314c2661ef2ccf351765ab8672460a3bec65a10 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -14,6 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/break_list.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/render_text_harfbuzz.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
@@ -1924,4 +1925,60 @@ TEST_F(RenderTextTest, Win_BreakRunsByUnicodeBlocks) {
}
#endif // defined(OS_WIN)
+TEST_F(RenderTextTest, HarfBuzz_CharToGlyph) {
msw 2014/06/06 02:00:42 Very nice test; thank you for adding this!
+ struct {
+ uint32 glyph_to_char[4];
+ size_t char_to_glyph_expected[4];
+ Range char_range_to_glyph_range_expected[4];
+ bool is_rtl;
+ } cases[] = {
+ {
+ // From string "A B C D" to glyphs "a b c d".
msw 2014/06/06 02:00:42 nit: move the comments up to share their open curl
ckocagil 2014/06/07 05:40:33 Done.
+ { 0, 1, 2, 3 },
+ { 0, 1, 2, 3 },
+ { 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 },
+ { 3, 2, 1, 0 },
+ { 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, 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(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) },
+ true
+ },
+ };
+
+ internal::TextRunHarfBuzz run;
+ run.range = Range(0, 4);
+ run.glyph_count = 4;
+ run.glyph_to_char.reset(new uint32[4]);
+
+ for (int 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.is_rtl = cases[i].is_rtl;
+ for (int j = 0; j < 4; ++j) {
+ SCOPED_TRACE(base::StringPrintf("Case %d, character %d", 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)));
+ }
+ }
+
+}
+
} // namespace gfx
« 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