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

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

Issue 1088093005: Unit tests for HarfBuzzShaper (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "platform/fonts/shaping/HarfBuzzShaper.h"
7
8 #include "platform/fonts/Font.h"
9 #include "platform/fonts/FontCache.h"
10 #include "platform/fonts/GlyphPage.h"
11 #include "platform/text/TextRun.h"
12 #include "wtf/Vector.h"
13 #include <gtest/gtest.h>
14 #include <unicode/uscript.h>
15
16 namespace {
17
18 using namespace blink;
19 using namespace WTF;
20
21 struct TestRun {
22 unsigned start;
23 unsigned end;
24 UScriptCode script;
25 };
26
27 // A port of hb_icu_script_to_script because harfbuzz on CrOS is built
28 // without hb-icu. See http://crbug.com/356929
29 static inline hb_script_t ICUScriptToHBScript(UScriptCode script)
30 {
31 if (UNLIKELY(script == USCRIPT_INVALID_CODE))
32 return HB_SCRIPT_INVALID;
33
34 return hb_script_from_string(uscript_getShortName(script), -1);
35 }
36
37 TEST(HarfBuzzShaper, ResolveCandidateRunsLatin)
38 {
39 FontCachePurgePreventer fontCachePurgePreventer;
Dominik Röttsches 2015/04/22 14:17:51 These setup lines seem to be identical in all test
40 FontDescription fontDescription;
41 fontDescription.setComputedSize(12.0);
42 Font* font = new Font(fontDescription);
43 font->update(nullptr);
44
45 unsigned startIndex = 0;
46 unsigned numGlyphs = 0;
47 hb_script_t script = HB_SCRIPT_INVALID;
48
49 TextRun latinCommon("ABC DEF.", 8);
50 HarfBuzzShaper shaper(font, latinCommon);
51 shaper.shape();
52
53 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
54 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
55 ASSERT_EQ(startIndex, 0u);
56 ASSERT_EQ(numGlyphs, 8u);
57 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
58
59 delete font;
60 }
61
62 TEST(HarfBuzzShaper, ResolveCandidateRunsLeadingCommon)
63 {
64 FontCachePurgePreventer fontCachePurgePreventer;
65 FontDescription fontDescription;
66 fontDescription.setComputedSize(12.0);
67 Font* font = new Font(fontDescription);
68 font->update(nullptr);
69
70 unsigned startIndex = 0;
71 unsigned numGlyphs = 0;
72 hb_script_t script = HB_SCRIPT_INVALID;
73
74 TextRun leadingCommon("... test", 8);
75 HarfBuzzShaper shaper(font, leadingCommon);
76 shaper.shape();
77
78 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
79 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
80 ASSERT_EQ(startIndex, 0u);
81 ASSERT_EQ(numGlyphs, 8u);
82 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
83
84 delete font;
85 }
86
87 TEST(HarfBuzzShaper, ResolveCandidateRunsDevanagariCommon)
88 {
89 FontCachePurgePreventer fontCachePurgePreventer;
90 FontDescription fontDescription;
91 fontDescription.setComputedSize(12.0);
92 Font* font = new Font(fontDescription);
93 font->update(nullptr);
94
95 unsigned startIndex = 0;
96 unsigned numGlyphs = 0;
97 hb_script_t script = HB_SCRIPT_INVALID;
98
99 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 };
100 TextRun devanagariCommonLatin(devanagariCommonString, 6);
101 HarfBuzzShaper shaper(font, devanagariCommonLatin);
102 shaper.shape();
103
104 ASSERT_EQ(shaper.numberOfRunsForTesting(), 2u);
105 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
106 ASSERT_EQ(startIndex, 0u);
107 ASSERT_EQ(numGlyphs, 1u);
108 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
109
110 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
111 ASSERT_EQ(startIndex, 3u);
112 ASSERT_EQ(numGlyphs, 3u);
113 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
114
115 delete font;
116 }
117
118 TEST(HarfBuzzShaper, ResolveCandidateRunsDevanagariCommonLatinCommon)
119 {
120 FontCachePurgePreventer fontCachePurgePreventer;
121 FontDescription fontDescription;
122 fontDescription.setComputedSize(12.0);
123 Font* font = new Font(fontDescription);
124 font->update(nullptr);
125
126 unsigned startIndex = 0;
127 unsigned numGlyphs = 0;
128 hb_script_t script = HB_SCRIPT_INVALID;
129
130 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6 2, 0x2E };
131 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7);
132 HarfBuzzShaper shaper(font, devanagariCommonLatin);
133 shaper.shape();
134
135 ASSERT_EQ(shaper.numberOfRunsForTesting(), 3u);
136 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
137 ASSERT_EQ(startIndex, 0u);
138 ASSERT_EQ(numGlyphs, 1u);
139 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
140
141 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
142 ASSERT_EQ(startIndex, 3u);
143 ASSERT_EQ(numGlyphs, 1u);
144 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_DEVANAGARI));
145
146 ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true);
147 ASSERT_EQ(startIndex, 4u);
148 ASSERT_EQ(numGlyphs, 3u);
149 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
150
151 delete font;
152 }
153
154 TEST(HarfBuzzShaper, ResolveCandidateRunsArabicThaiHanLatin)
155 {
156 FontCachePurgePreventer fontCachePurgePreventer;
157 FontDescription fontDescription;
158 fontDescription.setComputedSize(12.0);
159 Font* font = new Font(fontDescription);
160 font->update(nullptr);
161
162 unsigned startIndex = 0;
163 unsigned numGlyphs = 0;
164 hb_script_t script = HB_SCRIPT_INVALID;
165
166 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 };
167 TextRun mixed(mixedString, 6);
168 HarfBuzzShaper shaper(font, mixed);
169 shaper.shape();
170
171 ASSERT_EQ(shaper.numberOfRunsForTesting(), 4u);
172 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
173 ASSERT_EQ(startIndex, 0u);
174 ASSERT_EQ(numGlyphs, 3u);
175 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_ARABIC));
176
177 ASSERT_EQ(shaper.runInfoForTesting(1, startIndex, numGlyphs, script), true);
178 ASSERT_EQ(startIndex, 3u);
179 ASSERT_EQ(numGlyphs, 1u);
180 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_THAI));
181
182 ASSERT_EQ(shaper.runInfoForTesting(2, startIndex, numGlyphs, script), true);
183 ASSERT_EQ(startIndex, 4u);
184 ASSERT_EQ(numGlyphs, 1u);
185 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_HAN));
186
187 ASSERT_EQ(shaper.runInfoForTesting(3, startIndex, numGlyphs, script), true);
188 ASSERT_EQ(startIndex, 5u);
189 ASSERT_EQ(numGlyphs, 1u);
190 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_LATIN));
191
192 delete font;
193 }
194
195 TEST(HarfBuzzShaper, ResolveCandidateRunsArabic)
196 {
197 FontCachePurgePreventer fontCachePurgePreventer;
198 FontDescription fontDescription;
199 fontDescription.setComputedSize(12.0);
200 Font* font = new Font(fontDescription);
201 font->update(nullptr);
202
203 unsigned startIndex = 0;
204 unsigned numGlyphs = 0;
205 hb_script_t script = HB_SCRIPT_INVALID;
206
207 UChar arabicString[] = { 0x628, 0x64A, 0x629 };
208 TextRun arabic(arabicString, 3);
209 HarfBuzzShaper shaper(font, arabic);
210 shaper.shape();
211
212 ASSERT_EQ(shaper.numberOfRunsForTesting(), 1u);
213 ASSERT_EQ(shaper.runInfoForTesting(0, startIndex, numGlyphs, script), true);
214 ASSERT_EQ(startIndex, 0u);
215 ASSERT_EQ(numGlyphs, 3u);
216 ASSERT_EQ(script, ICUScriptToHBScript(USCRIPT_ARABIC));
217
218 delete font;
219 }
220
221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698