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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/break_list.h" 15 #include "ui/gfx/break_list.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/render_text_harfbuzz.h"
17 18
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
20 #include "ui/gfx/render_text_win.h" 21 #include "ui/gfx/render_text_win.h"
21 #endif 22 #endif
22 23
23 #if defined(OS_LINUX) && !defined(USE_OZONE) 24 #if defined(OS_LINUX) && !defined(USE_OZONE)
24 #include "ui/gfx/render_text_pango.h" 25 #include "ui/gfx/render_text_pango.h"
25 #endif 26 #endif
26 27
(...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 1918
1918 render_text->SetText(WideToUTF16(L"x \x25B6 y")); 1919 render_text->SetText(WideToUTF16(L"x \x25B6 y"));
1919 render_text->EnsureLayout(); 1920 render_text->EnsureLayout();
1920 ASSERT_EQ(3U, render_text->runs_.size()); 1921 ASSERT_EQ(3U, render_text->runs_.size());
1921 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); 1922 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range);
1922 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); 1923 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range);
1923 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); 1924 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range);
1924 } 1925 }
1925 #endif // defined(OS_WIN) 1926 #endif // defined(OS_WIN)
1926 1927
1928 TEST_F(RenderTextTest, HarfBuzz_CharToGlyph) {
msw 2014/06/06 02:00:42 Very nice test; thank you for adding this!
1929 struct {
1930 uint32 glyph_to_char[4];
1931 size_t char_to_glyph_expected[4];
1932 Range char_range_to_glyph_range_expected[4];
1933 bool is_rtl;
1934 } cases[] = {
1935 {
1936 // 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.
1937 { 0, 1, 2, 3 },
1938 { 0, 1, 2, 3 },
1939 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
1940 false
1941 },
1942 {
1943 // From string "A B C D" to glyphs "d b c a".
1944 { 3, 2, 1, 0 },
1945 { 3, 2, 1, 0 },
1946 { Range(3, 4), Range(2, 3), Range(1, 2), Range(0, 1) },
1947 true
1948 },
1949 {
1950 // From string "A B C D" to glyphs "ab c c d".
1951 { 0, 2, 2, 3 },
1952 { 0, 0, 1, 3 },
1953 { Range(0, 1), Range(0, 1), Range(1, 3), Range(3, 4) },
1954 false
1955 },
1956 {
1957 // From string "A B C D" to glyphs "d c c ba".
1958 { 3, 2, 2, 0 },
1959 { 3, 3, 1, 0 },
1960 { Range(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) },
1961 true
1962 },
1963 };
1964
1965 internal::TextRunHarfBuzz run;
1966 run.range = Range(0, 4);
1967 run.glyph_count = 4;
1968 run.glyph_to_char.reset(new uint32[4]);
1969
1970 for (int i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1971 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 4,
1972 run.glyph_to_char.get());
1973 run.is_rtl = cases[i].is_rtl;
1974 for (int j = 0; j < 4; ++j) {
1975 SCOPED_TRACE(base::StringPrintf("Case %d, character %d", i, j));
1976 EXPECT_EQ(cases[i].char_to_glyph_expected[j], run.CharToGlyph(j));
1977 EXPECT_EQ(cases[i].char_range_to_glyph_range_expected[j],
1978 run.CharRangeToGlyphRange(Range(j, j + 1)));
1979 }
1980 }
1981
1982 }
1983
1927 } // namespace gfx 1984 } // namespace gfx
OLDNEW
« 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