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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp

Issue 2507063010: Moving string normalization out of HarfBuzz (Closed)
Patch Set: Merge w/HEAD Created 4 years 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
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "platform/fonts/shaping/HarfBuzzShaper.h" 5 #include "platform/fonts/shaping/HarfBuzzShaper.h"
6 6
7 #include "platform/fonts/Font.h" 7 #include "platform/fonts/Font.h"
8 #include "platform/fonts/FontCache.h" 8 #include "platform/fonts/FontCache.h"
9 #include "platform/fonts/shaping/ShapeResultTestInfo.h" 9 #include "platform/fonts/shaping/ShapeResultTestInfo.h"
10 #include "platform/text/TextRun.h" 10 #include "platform/text/TextRun.h"
(...skipping 18 matching lines...) Expand all
29 Font font; 29 Font font;
30 unsigned startIndex = 0; 30 unsigned startIndex = 0;
31 unsigned numGlyphs = 0; 31 unsigned numGlyphs = 0;
32 hb_script_t script = HB_SCRIPT_INVALID; 32 hb_script_t script = HB_SCRIPT_INVALID;
33 }; 33 };
34 34
35 static inline ShapeResultTestInfo* testInfo(RefPtr<ShapeResult>& result) { 35 static inline ShapeResultTestInfo* testInfo(RefPtr<ShapeResult>& result) {
36 return static_cast<ShapeResultTestInfo*>(result.get()); 36 return static_cast<ShapeResultTestInfo*>(result.get());
37 } 37 }
38 38
39 static inline String to16Bit(const char* text, unsigned length) {
40 return String::make16BitFrom8BitSource(reinterpret_cast<const LChar*>(text),
41 length);
42 }
43
39 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) { 44 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) {
40 TextRun latinCommon(reinterpret_cast<const LChar*>("ABC DEF."), 8); 45 String latinCommon = to16Bit("ABC DEF.", 8);
41 HarfBuzzShaper shaper(latinCommon); 46 HarfBuzzShaper shaper(latinCommon.characters16(), 8, LTR);
42 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 47 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
43 48
44 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting()); 49 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting());
45 ASSERT_TRUE( 50 ASSERT_TRUE(
46 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 51 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
47 EXPECT_EQ(0u, startIndex); 52 EXPECT_EQ(0u, startIndex);
48 EXPECT_EQ(8u, numGlyphs); 53 EXPECT_EQ(8u, numGlyphs);
49 EXPECT_EQ(HB_SCRIPT_LATIN, script); 54 EXPECT_EQ(HB_SCRIPT_LATIN, script);
50 } 55 }
51 56
52 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) { 57 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) {
53 TextRun leadingCommon(reinterpret_cast<const LChar*>("... test"), 8); 58 String leadingCommon = to16Bit("... test", 8);
54 HarfBuzzShaper shaper(leadingCommon); 59 HarfBuzzShaper shaper(leadingCommon.characters16(), 8, LTR);
55 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 60 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
56 61
57 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting()); 62 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting());
58 ASSERT_TRUE( 63 ASSERT_TRUE(
59 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 64 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
60 EXPECT_EQ(0u, startIndex); 65 EXPECT_EQ(0u, startIndex);
61 EXPECT_EQ(8u, numGlyphs); 66 EXPECT_EQ(8u, numGlyphs);
62 EXPECT_EQ(HB_SCRIPT_LATIN, script); 67 EXPECT_EQ(HB_SCRIPT_LATIN, script);
63 } 68 }
64 69
65 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) { 70 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) {
66 struct { 71 struct {
67 const char* name; 72 const char* name;
68 UChar string[4]; 73 UChar string[4];
74 unsigned length;
69 hb_script_t script; 75 hb_script_t script;
70 } testlist[] = { 76 } testlist[] = {
71 {"Standard Variants text style", {0x30, 0xFE0E}, HB_SCRIPT_COMMON}, 77 {"Standard Variants text style", {0x30, 0xFE0E}, 2, HB_SCRIPT_COMMON},
72 {"Standard Variants emoji style", {0x203C, 0xFE0F}, HB_SCRIPT_COMMON}, 78 {"Standard Variants emoji style", {0x203C, 0xFE0F}, 2, HB_SCRIPT_COMMON},
73 {"Standard Variants of Ideograph", {0x4FAE, 0xFE00}, HB_SCRIPT_HAN}, 79 {"Standard Variants of Ideograph", {0x4FAE, 0xFE00}, 2, HB_SCRIPT_HAN},
74 {"Ideographic Variants", {0x3402, 0xDB40, 0xDD00}, HB_SCRIPT_HAN}, 80 {"Ideographic Variants", {0x3402, 0xDB40, 0xDD00}, 3, HB_SCRIPT_HAN},
75 {"Not-defined Variants", {0x41, 0xDB40, 0xDDEF}, HB_SCRIPT_LATIN}, 81 {"Not-defined Variants", {0x41, 0xDB40, 0xDDEF}, 3, HB_SCRIPT_LATIN},
76 }; 82 };
77 for (auto& test : testlist) { 83 for (auto& test : testlist) {
78 String str(test.string); 84 HarfBuzzShaper shaper(test.string, test.length, LTR);
79 TextRun run(str);
80 HarfBuzzShaper shaper(run);
81 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 85 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
82 86
83 EXPECT_EQ(1u, testInfo(result)->numberOfRunsForTesting()) << test.name; 87 EXPECT_EQ(1u, testInfo(result)->numberOfRunsForTesting()) << test.name;
84 ASSERT_TRUE( 88 ASSERT_TRUE(
85 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)) 89 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script))
86 << test.name; 90 << test.name;
87 EXPECT_EQ(0u, startIndex) << test.name; 91 EXPECT_EQ(0u, startIndex) << test.name;
88 if (numGlyphs == 2) { 92 if (numGlyphs == 2) {
89 // If the specified VS is not in the font, it's mapped to .notdef. 93 // If the specified VS is not in the font, it's mapped to .notdef.
90 // then hb_ot_hide_default_ignorables() swaps it to a space with zero-advance. 94 // then hb_ot_hide_default_ignorables() swaps it to a space with zero-advance.
91 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.html 95 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.html
92 // OpenType recommends Glyph ID 3 for a space; not a hard requirement though. 96 // OpenType recommends Glyph ID 3 for a space; not a hard requirement though.
93 // https://www.microsoft.com/typography/otspec/recom.htm 97 // https://www.microsoft.com/typography/otspec/recom.htm
94 #if !OS(MACOSX) 98 #if !OS(MACOSX)
95 // TODO(mgiuca): This expectation has been DISABLED due to failing on 99 // TODO(mgiuca): This expectation has been DISABLED due to failing on
96 // Linux bots. See https://crbug.com/667147. 100 // Linux bots. See https://crbug.com/667147.
97 // EXPECT_EQ(3u, testInfo(result)->glyphForTesting(0, 1)) << test.name; 101 // EXPECT_EQ(3u, testInfo(result)->glyphForTesting(0, 1)) << test.name;
98 #endif 102 #endif
99 EXPECT_EQ(0.f, testInfo(result)->advanceForTesting(0, 1)) << test.name; 103 EXPECT_EQ(0.f, testInfo(result)->advanceForTesting(0, 1)) << test.name;
100 } else { 104 } else {
101 EXPECT_EQ(1u, numGlyphs) << test.name; 105 EXPECT_EQ(1u, numGlyphs) << test.name;
102 } 106 }
103 EXPECT_EQ(test.script, script) << test.name; 107 EXPECT_EQ(test.script, script) << test.name;
104 } 108 }
105 } 109 }
106 110
107 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) { 111 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) {
108 UChar devanagariCommonString[] = {0x915, 0x94d, 0x930, 0x28, 0x20, 0x29}; 112 UChar devanagariCommonString[] = {0x915, 0x94d, 0x930, 0x28, 0x20, 0x29};
109 TextRun devanagariCommonLatin(devanagariCommonString, 6); 113 String devanagariCommonLatin(devanagariCommonString, 6);
110 HarfBuzzShaper shaper(devanagariCommonLatin); 114 HarfBuzzShaper shaper(devanagariCommonLatin.characters16(), 6, LTR);
111 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 115 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
112 116
113 ASSERT_EQ(2u, testInfo(result)->numberOfRunsForTesting()); 117 ASSERT_EQ(2u, testInfo(result)->numberOfRunsForTesting());
114 ASSERT_TRUE( 118 ASSERT_TRUE(
115 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 119 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
116 EXPECT_EQ(0u, startIndex); 120 EXPECT_EQ(0u, startIndex);
117 EXPECT_EQ(1u, numGlyphs); 121 EXPECT_EQ(1u, numGlyphs);
118 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 122 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
119 123
120 ASSERT_TRUE( 124 ASSERT_TRUE(
121 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script)); 125 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script));
122 EXPECT_EQ(3u, startIndex); 126 EXPECT_EQ(3u, startIndex);
123 EXPECT_EQ(3u, numGlyphs); 127 EXPECT_EQ(3u, numGlyphs);
124 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 128 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
125 } 129 }
126 130
127 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) { 131 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) {
128 UChar devanagariCommonLatinString[] = {0x915, 0x94d, 0x930, 0x20, 132 UChar devanagariCommonLatinString[] = {0x915, 0x94d, 0x930, 0x20,
129 0x61, 0x62, 0x2E}; 133 0x61, 0x62, 0x2E};
130 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7); 134 HarfBuzzShaper shaper(devanagariCommonLatinString, 7, LTR);
131 HarfBuzzShaper shaper(devanagariCommonLatin);
132 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 135 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
133 136
134 ASSERT_EQ(3u, testInfo(result)->numberOfRunsForTesting()); 137 ASSERT_EQ(3u, testInfo(result)->numberOfRunsForTesting());
135 ASSERT_TRUE( 138 ASSERT_TRUE(
136 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 139 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
137 EXPECT_EQ(0u, startIndex); 140 EXPECT_EQ(0u, startIndex);
138 EXPECT_EQ(1u, numGlyphs); 141 EXPECT_EQ(1u, numGlyphs);
139 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 142 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
140 143
141 ASSERT_TRUE( 144 ASSERT_TRUE(
142 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script)); 145 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script));
143 EXPECT_EQ(3u, startIndex); 146 EXPECT_EQ(3u, startIndex);
144 EXPECT_EQ(1u, numGlyphs); 147 EXPECT_EQ(1u, numGlyphs);
145 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 148 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
146 149
147 ASSERT_TRUE( 150 ASSERT_TRUE(
148 testInfo(result)->runInfoForTesting(2, startIndex, numGlyphs, script)); 151 testInfo(result)->runInfoForTesting(2, startIndex, numGlyphs, script));
149 EXPECT_EQ(4u, startIndex); 152 EXPECT_EQ(4u, startIndex);
150 EXPECT_EQ(3u, numGlyphs); 153 EXPECT_EQ(3u, numGlyphs);
151 EXPECT_EQ(HB_SCRIPT_LATIN, script); 154 EXPECT_EQ(HB_SCRIPT_LATIN, script);
152 } 155 }
153 156
154 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) { 157 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) {
155 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; 158 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62};
156 TextRun mixed(mixedString, 6); 159 HarfBuzzShaper shaper(mixedString, 6, LTR);
157 HarfBuzzShaper shaper(mixed);
158 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 160 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
159 161
160 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting()); 162 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting());
161 ASSERT_TRUE( 163 ASSERT_TRUE(
162 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 164 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
163 EXPECT_EQ(0u, startIndex); 165 EXPECT_EQ(0u, startIndex);
164 EXPECT_EQ(3u, numGlyphs); 166 EXPECT_EQ(3u, numGlyphs);
165 EXPECT_EQ(HB_SCRIPT_ARABIC, script); 167 EXPECT_EQ(HB_SCRIPT_ARABIC, script);
166 168
167 ASSERT_TRUE( 169 ASSERT_TRUE(
(...skipping 10 matching lines...) Expand all
178 180
179 ASSERT_TRUE( 181 ASSERT_TRUE(
180 testInfo(result)->runInfoForTesting(3, startIndex, numGlyphs, script)); 182 testInfo(result)->runInfoForTesting(3, startIndex, numGlyphs, script));
181 EXPECT_EQ(5u, startIndex); 183 EXPECT_EQ(5u, startIndex);
182 EXPECT_EQ(1u, numGlyphs); 184 EXPECT_EQ(1u, numGlyphs);
183 EXPECT_EQ(HB_SCRIPT_LATIN, script); 185 EXPECT_EQ(HB_SCRIPT_LATIN, script);
184 } 186 }
185 187
186 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatinTwice) { 188 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatinTwice) {
187 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; 189 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62};
188 TextRun mixed(mixedString, 6); 190 HarfBuzzShaper shaper(mixedString, 6, LTR);
189 HarfBuzzShaper shaper(mixed);
190 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 191 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
191 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting()); 192 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting());
192 193
193 // Shape again on the same shape object and check the number of runs. 194 // Shape again on the same shape object and check the number of runs.
194 // Should be equal if no state was retained between shape calls. 195 // Should be equal if no state was retained between shape calls.
195 RefPtr<ShapeResult> result2 = shaper.shapeResult(&font); 196 RefPtr<ShapeResult> result2 = shaper.shapeResult(&font);
196 ASSERT_EQ(4u, testInfo(result2)->numberOfRunsForTesting()); 197 ASSERT_EQ(4u, testInfo(result2)->numberOfRunsForTesting());
197 } 198 }
198 199
199 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) { 200 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) {
200 UChar arabicString[] = {0x628, 0x64A, 0x629}; 201 UChar arabicString[] = {0x628, 0x64A, 0x629};
201 TextRun arabic(arabicString, 3); 202 HarfBuzzShaper shaper(arabicString, 3, RTL);
202 HarfBuzzShaper shaper(arabic);
203 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 203 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
204 204
205 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting()); 205 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting());
206 ASSERT_TRUE( 206 ASSERT_TRUE(
207 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 207 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
208 EXPECT_EQ(0u, startIndex); 208 EXPECT_EQ(0u, startIndex);
209 EXPECT_EQ(3u, numGlyphs); 209 EXPECT_EQ(3u, numGlyphs);
210 EXPECT_EQ(HB_SCRIPT_ARABIC, script); 210 EXPECT_EQ(HB_SCRIPT_ARABIC, script);
211 } 211 }
212 212
213 } // namespace blink 213 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp ('k') | third_party/WebKit/Source/platform/text/TextRun.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698