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

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

Issue 2614883007: Change computed style enums to be prefixed with 'k'. (Closed)
Patch Set: Rebase on ToT. Created 3 years, 11 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
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 25 matching lines...) Expand all
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) { 39 static inline String to16Bit(const char* text, unsigned length) {
40 return String::make16BitFrom8BitSource(reinterpret_cast<const LChar*>(text), 40 return String::make16BitFrom8BitSource(reinterpret_cast<const LChar*>(text),
41 length); 41 length);
42 } 42 }
43 43
44 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) { 44 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) {
45 String latinCommon = to16Bit("ABC DEF.", 8); 45 String latinCommon = to16Bit("ABC DEF.", 8);
46 HarfBuzzShaper shaper(latinCommon.characters16(), 8, TextDirection::Ltr); 46 HarfBuzzShaper shaper(latinCommon.characters16(), 8, TextDirection::kLtr);
47 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 47 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
48 48
49 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting()); 49 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting());
50 ASSERT_TRUE( 50 ASSERT_TRUE(
51 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 51 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
52 EXPECT_EQ(0u, startIndex); 52 EXPECT_EQ(0u, startIndex);
53 EXPECT_EQ(8u, numGlyphs); 53 EXPECT_EQ(8u, numGlyphs);
54 EXPECT_EQ(HB_SCRIPT_LATIN, script); 54 EXPECT_EQ(HB_SCRIPT_LATIN, script);
55 } 55 }
56 56
57 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) { 57 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) {
58 String leadingCommon = to16Bit("... test", 8); 58 String leadingCommon = to16Bit("... test", 8);
59 HarfBuzzShaper shaper(leadingCommon.characters16(), 8, TextDirection::Ltr); 59 HarfBuzzShaper shaper(leadingCommon.characters16(), 8, TextDirection::kLtr);
60 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 60 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
61 61
62 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting()); 62 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting());
63 ASSERT_TRUE( 63 ASSERT_TRUE(
64 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 64 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
65 EXPECT_EQ(0u, startIndex); 65 EXPECT_EQ(0u, startIndex);
66 EXPECT_EQ(8u, numGlyphs); 66 EXPECT_EQ(8u, numGlyphs);
67 EXPECT_EQ(HB_SCRIPT_LATIN, script); 67 EXPECT_EQ(HB_SCRIPT_LATIN, script);
68 } 68 }
69 69
70 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) { 70 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) {
71 struct { 71 struct {
72 const char* name; 72 const char* name;
73 UChar string[4]; 73 UChar string[4];
74 unsigned length; 74 unsigned length;
75 hb_script_t script; 75 hb_script_t script;
76 } testlist[] = { 76 } testlist[] = {
77 {"Standard Variants text style", {0x30, 0xFE0E}, 2, HB_SCRIPT_COMMON}, 77 {"Standard Variants text style", {0x30, 0xFE0E}, 2, HB_SCRIPT_COMMON},
78 {"Standard Variants emoji style", {0x203C, 0xFE0F}, 2, HB_SCRIPT_COMMON}, 78 {"Standard Variants emoji style", {0x203C, 0xFE0F}, 2, HB_SCRIPT_COMMON},
79 {"Standard Variants of Ideograph", {0x4FAE, 0xFE00}, 2, HB_SCRIPT_HAN}, 79 {"Standard Variants of Ideograph", {0x4FAE, 0xFE00}, 2, HB_SCRIPT_HAN},
80 {"Ideographic Variants", {0x3402, 0xDB40, 0xDD00}, 3, HB_SCRIPT_HAN}, 80 {"Ideographic Variants", {0x3402, 0xDB40, 0xDD00}, 3, HB_SCRIPT_HAN},
81 {"Not-defined Variants", {0x41, 0xDB40, 0xDDEF}, 3, HB_SCRIPT_LATIN}, 81 {"Not-defined Variants", {0x41, 0xDB40, 0xDDEF}, 3, HB_SCRIPT_LATIN},
82 }; 82 };
83 for (auto& test : testlist) { 83 for (auto& test : testlist) {
84 HarfBuzzShaper shaper(test.string, test.length, TextDirection::Ltr); 84 HarfBuzzShaper shaper(test.string, test.length, TextDirection::kLtr);
85 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 85 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
86 86
87 EXPECT_EQ(1u, testInfo(result)->numberOfRunsForTesting()) << test.name; 87 EXPECT_EQ(1u, testInfo(result)->numberOfRunsForTesting()) << test.name;
88 ASSERT_TRUE( 88 ASSERT_TRUE(
89 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)) 89 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script))
90 << test.name; 90 << test.name;
91 EXPECT_EQ(0u, startIndex) << test.name; 91 EXPECT_EQ(0u, startIndex) << test.name;
92 if (numGlyphs == 2) { 92 if (numGlyphs == 2) {
93 // 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.
94 // 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.
95 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.html 95 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.html
96 #if !OS(MACOSX) 96 #if !OS(MACOSX)
97 EXPECT_EQ(testInfo(result)->fontDataForTesting(0)->spaceGlyph(), 97 EXPECT_EQ(testInfo(result)->fontDataForTesting(0)->spaceGlyph(),
98 testInfo(result)->glyphForTesting(0, 1)) 98 testInfo(result)->glyphForTesting(0, 1))
99 << test.name; 99 << test.name;
100 #endif 100 #endif
101 EXPECT_EQ(0.f, testInfo(result)->advanceForTesting(0, 1)) << test.name; 101 EXPECT_EQ(0.f, testInfo(result)->advanceForTesting(0, 1)) << test.name;
102 } else { 102 } else {
103 EXPECT_EQ(1u, numGlyphs) << test.name; 103 EXPECT_EQ(1u, numGlyphs) << test.name;
104 } 104 }
105 EXPECT_EQ(test.script, script) << test.name; 105 EXPECT_EQ(test.script, script) << test.name;
106 } 106 }
107 } 107 }
108 108
109 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) { 109 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) {
110 UChar devanagariCommonString[] = {0x915, 0x94d, 0x930, 0x28, 0x20, 0x29}; 110 UChar devanagariCommonString[] = {0x915, 0x94d, 0x930, 0x28, 0x20, 0x29};
111 String devanagariCommonLatin(devanagariCommonString, 6); 111 String devanagariCommonLatin(devanagariCommonString, 6);
112 HarfBuzzShaper shaper(devanagariCommonLatin.characters16(), 6, 112 HarfBuzzShaper shaper(devanagariCommonLatin.characters16(), 6,
113 TextDirection::Ltr); 113 TextDirection::kLtr);
114 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 114 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
115 115
116 ASSERT_EQ(2u, testInfo(result)->numberOfRunsForTesting()); 116 ASSERT_EQ(2u, testInfo(result)->numberOfRunsForTesting());
117 ASSERT_TRUE( 117 ASSERT_TRUE(
118 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 118 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
119 EXPECT_EQ(0u, startIndex); 119 EXPECT_EQ(0u, startIndex);
120 EXPECT_EQ(1u, numGlyphs); 120 EXPECT_EQ(1u, numGlyphs);
121 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 121 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
122 122
123 ASSERT_TRUE( 123 ASSERT_TRUE(
124 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script)); 124 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script));
125 EXPECT_EQ(3u, startIndex); 125 EXPECT_EQ(3u, startIndex);
126 EXPECT_EQ(3u, numGlyphs); 126 EXPECT_EQ(3u, numGlyphs);
127 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 127 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
128 } 128 }
129 129
130 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) { 130 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) {
131 UChar devanagariCommonLatinString[] = {0x915, 0x94d, 0x930, 0x20, 131 UChar devanagariCommonLatinString[] = {0x915, 0x94d, 0x930, 0x20,
132 0x61, 0x62, 0x2E}; 132 0x61, 0x62, 0x2E};
133 HarfBuzzShaper shaper(devanagariCommonLatinString, 7, TextDirection::Ltr); 133 HarfBuzzShaper shaper(devanagariCommonLatinString, 7, TextDirection::kLtr);
134 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 134 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
135 135
136 ASSERT_EQ(3u, testInfo(result)->numberOfRunsForTesting()); 136 ASSERT_EQ(3u, testInfo(result)->numberOfRunsForTesting());
137 ASSERT_TRUE( 137 ASSERT_TRUE(
138 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 138 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
139 EXPECT_EQ(0u, startIndex); 139 EXPECT_EQ(0u, startIndex);
140 EXPECT_EQ(1u, numGlyphs); 140 EXPECT_EQ(1u, numGlyphs);
141 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 141 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
142 142
143 ASSERT_TRUE( 143 ASSERT_TRUE(
144 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script)); 144 testInfo(result)->runInfoForTesting(1, startIndex, numGlyphs, script));
145 EXPECT_EQ(3u, startIndex); 145 EXPECT_EQ(3u, startIndex);
146 EXPECT_EQ(1u, numGlyphs); 146 EXPECT_EQ(1u, numGlyphs);
147 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 147 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
148 148
149 ASSERT_TRUE( 149 ASSERT_TRUE(
150 testInfo(result)->runInfoForTesting(2, startIndex, numGlyphs, script)); 150 testInfo(result)->runInfoForTesting(2, startIndex, numGlyphs, script));
151 EXPECT_EQ(4u, startIndex); 151 EXPECT_EQ(4u, startIndex);
152 EXPECT_EQ(3u, numGlyphs); 152 EXPECT_EQ(3u, numGlyphs);
153 EXPECT_EQ(HB_SCRIPT_LATIN, script); 153 EXPECT_EQ(HB_SCRIPT_LATIN, script);
154 } 154 }
155 155
156 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) { 156 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) {
157 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; 157 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62};
158 HarfBuzzShaper shaper(mixedString, 6, TextDirection::Ltr); 158 HarfBuzzShaper shaper(mixedString, 6, TextDirection::kLtr);
159 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 159 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
160 160
161 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting()); 161 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting());
162 ASSERT_TRUE( 162 ASSERT_TRUE(
163 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 163 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
164 EXPECT_EQ(0u, startIndex); 164 EXPECT_EQ(0u, startIndex);
165 EXPECT_EQ(3u, numGlyphs); 165 EXPECT_EQ(3u, numGlyphs);
166 EXPECT_EQ(HB_SCRIPT_ARABIC, script); 166 EXPECT_EQ(HB_SCRIPT_ARABIC, script);
167 167
168 ASSERT_TRUE( 168 ASSERT_TRUE(
(...skipping 10 matching lines...) Expand all
179 179
180 ASSERT_TRUE( 180 ASSERT_TRUE(
181 testInfo(result)->runInfoForTesting(3, startIndex, numGlyphs, script)); 181 testInfo(result)->runInfoForTesting(3, startIndex, numGlyphs, script));
182 EXPECT_EQ(5u, startIndex); 182 EXPECT_EQ(5u, startIndex);
183 EXPECT_EQ(1u, numGlyphs); 183 EXPECT_EQ(1u, numGlyphs);
184 EXPECT_EQ(HB_SCRIPT_LATIN, script); 184 EXPECT_EQ(HB_SCRIPT_LATIN, script);
185 } 185 }
186 186
187 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatinTwice) { 187 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatinTwice) {
188 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; 188 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62};
189 HarfBuzzShaper shaper(mixedString, 6, TextDirection::Ltr); 189 HarfBuzzShaper shaper(mixedString, 6, TextDirection::kLtr);
190 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 190 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
191 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting()); 191 ASSERT_EQ(4u, testInfo(result)->numberOfRunsForTesting());
192 192
193 // Shape again on the same shape object and check the number of runs. 193 // 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. 194 // Should be equal if no state was retained between shape calls.
195 RefPtr<ShapeResult> result2 = shaper.shapeResult(&font); 195 RefPtr<ShapeResult> result2 = shaper.shapeResult(&font);
196 ASSERT_EQ(4u, testInfo(result2)->numberOfRunsForTesting()); 196 ASSERT_EQ(4u, testInfo(result2)->numberOfRunsForTesting());
197 } 197 }
198 198
199 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) { 199 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) {
200 UChar arabicString[] = {0x628, 0x64A, 0x629}; 200 UChar arabicString[] = {0x628, 0x64A, 0x629};
201 HarfBuzzShaper shaper(arabicString, 3, TextDirection::Rtl); 201 HarfBuzzShaper shaper(arabicString, 3, TextDirection::kRtl);
202 RefPtr<ShapeResult> result = shaper.shapeResult(&font); 202 RefPtr<ShapeResult> result = shaper.shapeResult(&font);
203 203
204 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting()); 204 ASSERT_EQ(1u, testInfo(result)->numberOfRunsForTesting());
205 ASSERT_TRUE( 205 ASSERT_TRUE(
206 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script)); 206 testInfo(result)->runInfoForTesting(0, startIndex, numGlyphs, script));
207 EXPECT_EQ(0u, startIndex); 207 EXPECT_EQ(0u, startIndex);
208 EXPECT_EQ(3u, numGlyphs); 208 EXPECT_EQ(3u, numGlyphs);
209 EXPECT_EQ(HB_SCRIPT_ARABIC, script); 209 EXPECT_EQ(HB_SCRIPT_ARABIC, script);
210 } 210 }
211 211
212 } // namespace blink 212 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698