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

Side by Side 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, 5 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"
(...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 1917
1918 render_text->SetText(WideToUTF16(L"x \x25B6 y")); 1918 render_text->SetText(WideToUTF16(L"x \x25B6 y"));
1919 render_text->EnsureLayout(); 1919 render_text->EnsureLayout();
1920 ASSERT_EQ(3U, render_text->runs_.size()); 1920 ASSERT_EQ(3U, render_text->runs_.size());
1921 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); 1921 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range);
1922 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); 1922 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range);
1923 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); 1923 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range);
1924 } 1924 }
1925 #endif // defined(OS_WIN) 1925 #endif // defined(OS_WIN)
1926 1926
1927 TEST_F(RenderTextTest, HarfBuzz_CharToGlyph) { 1927 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.
1928 struct { 1928 struct {
1929 uint32 glyph_to_char[4]; 1929 uint32 glyph_to_char[4];
1930 size_t char_to_glyph_expected[4]; 1930 Range chars[4];
1931 Range char_range_to_glyph_range_expected[4]; 1931 Range glyphs[4];
1932 bool is_rtl; 1932 bool is_rtl;
1933 } cases[] = { 1933 } cases[] = {
1934 { // From string "A B C D" to glyphs "a b c d". 1934 { // From string "A B C D" to glyphs "a b c d".
1935 { 0, 1, 2, 3 }, 1935 { 0, 1, 2, 3 },
1936 { 0, 1, 2, 3 }, 1936 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
1937 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) }, 1937 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
1938 false 1938 false
1939 }, 1939 },
1940 { // From string "A B C D" to glyphs "d b c a". 1940 { // From string "A B C D" to glyphs "d c b a".
1941 { 3, 2, 1, 0 }, 1941 { 3, 2, 1, 0 },
1942 { 3, 2, 1, 0 }, 1942 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
1943 { Range(3, 4), Range(2, 3), Range(1, 2), Range(0, 1) }, 1943 { Range(3, 4), Range(2, 3), Range(1, 2), Range(0, 1) },
1944 true 1944 true
1945 }, 1945 },
1946 { // From string "A B C D" to glyphs "ab c c d". 1946 { // From string "A B C D" to glyphs "ab c c d".
1947 { 0, 2, 2, 3 }, 1947 { 0, 2, 2, 3 },
1948 { 0, 0, 1, 3 }, 1948 { Range(0, 2), Range(0, 2), Range(2, 3), Range(3, 4) },
1949 { Range(0, 1), Range(0, 1), Range(1, 3), Range(3, 4) }, 1949 { Range(0, 1), Range(0, 1), Range(1, 3), Range(3, 4) },
1950 false 1950 false
1951 }, 1951 },
1952 { // From string "A B C D" to glyphs "d c c ba". 1952 { // From string "A B C D" to glyphs "d c c ba".
1953 { 3, 2, 2, 0 }, 1953 { 3, 2, 2, 0 },
1954 { 3, 3, 1, 0 }, 1954 { Range(0, 2), Range(0, 2), Range(2, 3), Range(3, 4) },
1955 { Range(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) }, 1955 { Range(3, 4), Range(3, 4), Range(1, 3), Range(0, 1) },
1956 true 1956 true
1957 }, 1957 },
1958 }; 1958 };
1959 1959
1960 internal::TextRunHarfBuzz run; 1960 internal::TextRunHarfBuzz run;
1961 run.range = Range(0, 4); 1961 run.range = Range(0, 4);
1962 run.glyph_count = 4; 1962 run.glyph_count = 4;
1963 run.glyph_to_char.reset(new uint32[4]); 1963 run.glyph_to_char.resize(4);
1964 1964
1965 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 1965 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
1966 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 4, 1966 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 4,
1967 run.glyph_to_char.get()); 1967 run.glyph_to_char.begin());
1968 run.is_rtl = cases[i].is_rtl; 1968 run.is_rtl = cases[i].is_rtl;
1969
1969 for (size_t j = 0; j < 4; ++j) { 1970 for (size_t j = 0; j < 4; ++j) {
1970 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j)); 1971 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j));
1971 EXPECT_EQ(cases[i].char_to_glyph_expected[j], run.CharToGlyph(j)); 1972 Range chars;
1972 EXPECT_EQ(cases[i].char_range_to_glyph_range_expected[j], 1973 Range glyphs;
1973 run.CharRangeToGlyphRange(Range(j, j + 1))); 1974 run.GetClusterAt(j, &chars, &glyphs);
1975 EXPECT_EQ(cases[i].chars[j], chars);
1976 EXPECT_EQ(cases[i].glyphs[j], glyphs);
1977 EXPECT_EQ(cases[i].glyphs[j], run.CharRangeToGlyphRange(chars));
1974 } 1978 }
1975 } 1979 }
1976 } 1980 }
1981
1982 TEST_F(RenderTextTest, HarfBuzz_SubglyphGrapheme) {
1983 struct {
1984 uint32 glyph_to_char[2];
1985 Range bounds[4];
1986 bool is_rtl;
1987 } cases[] = {
1988 { // 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.
1989 { 0, 1 },
1990 { Range(0, 10), Range(10, 13), Range(13, 17), Range(17, 20) },
1991 false
1992 },
1993 { // From string "A B C D" to glyphs "ab cd".
1994 { 0, 2 },
1995 { Range(0, 5), Range(5, 10), Range(10, 15), Range(15, 20) },
1996 false
1997 },
1998 { // From string "A B C D" to glyphs "dcb a".
1999 { 1, 0 },
2000 { Range(10, 20), Range(7, 10), Range(3, 7), Range(0, 3) },
2001 true
2002 },
2003 };
2004
2005 internal::TextRunHarfBuzz run;
2006 run.range = Range(0, 4);
2007 run.glyph_count = 2;
2008 run.glyph_to_char.resize(2);
2009 run.positions.reset(new SkPoint[4]);
2010 run.width = 20;
2011
2012 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
2013 std::copy(cases[i].glyph_to_char, cases[i].glyph_to_char + 2,
2014 run.glyph_to_char.begin());
2015 run.is_rtl = cases[i].is_rtl;
2016 for (int j = 0; j < 2; ++j)
2017 run.positions[j].set(j * 10, 0);
2018
2019 for (size_t j = 0; j < 4; ++j) {
2020 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j));
2021 EXPECT_EQ(cases[i].bounds[j], run.GetGraphemeBounds(L"abcd", j));
2022 }
2023 }
2024 }
1977 2025
1978 TEST_F(RenderTextTest, HarfBuzz_RunDirection) { 2026 TEST_F(RenderTextTest, HarfBuzz_RunDirection) {
1979 RenderTextHarfBuzz render_text; 2027 RenderTextHarfBuzz render_text;
1980 const base::string16 mixed = 2028 const base::string16 mixed =
1981 WideToUTF16(L"\x05D0\x05D1" L"1234" L"\x05D2\x05D3"); 2029 WideToUTF16(L"\x05D0\x05D1" L"1234" L"\x05D2\x05D3");
1982 render_text.SetText(mixed); 2030 render_text.SetText(mixed);
1983 render_text.EnsureLayout(); 2031 render_text.EnsureLayout();
1984 ASSERT_EQ(3U, render_text.runs_.size()); 2032 ASSERT_EQ(3U, render_text.runs_.size());
1985 EXPECT_TRUE(render_text.runs_[0]->is_rtl); 2033 EXPECT_TRUE(render_text.runs_[0]->is_rtl);
1986 EXPECT_FALSE(render_text.runs_[1]->is_rtl); 2034 EXPECT_FALSE(render_text.runs_[1]->is_rtl);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2082 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2035 render_text->SetText(WideToUTF16(kTestStrings[i])); 2083 render_text->SetText(WideToUTF16(kTestStrings[i]));
2036 render_text->EnsureLayout(); 2084 render_text->EnsureLayout();
2037 2085
2038 for (size_t j = 0; j < render_text->text().length(); ++j) 2086 for (size_t j = 0; j < render_text->text().length(); ++j)
2039 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); 2087 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty());
2040 } 2088 }
2041 } 2089 }
2042 2090
2043 } // namespace gfx 2091 } // 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