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

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

Issue 1244973003: Reland "Change fallback font collection in HarfBuzzShaper" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase (resolved conflicts) Created 5 years, 4 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
« no previous file with comments | « Source/platform/fonts/shaping/HarfBuzzShaper.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 #include "platform/fonts/shaping/HarfBuzzShaper.h" 6 #include "platform/fonts/shaping/HarfBuzzShaper.h"
7 7
8 #include "platform/fonts/Font.h" 8 #include "platform/fonts/Font.h"
9 #include "platform/fonts/FontCache.h" 9 #include "platform/fonts/FontCache.h"
10 #include "platform/fonts/GlyphPage.h" 10 #include "platform/fonts/GlyphPage.h"
(...skipping 11 matching lines...) Expand all
22 fontDescription.setComputedSize(12.0); 22 fontDescription.setComputedSize(12.0);
23 font = new Font(fontDescription); 23 font = new Font(fontDescription);
24 font->update(nullptr); 24 font->update(nullptr);
25 } 25 }
26 26
27 void TearDown() override 27 void TearDown() override
28 { 28 {
29 delete font; 29 delete font;
30 } 30 }
31 31
32 HashSet<const SimpleFontData*> fallbackFonts;
33 FontCachePurgePreventer fontCachePurgePreventer; 32 FontCachePurgePreventer fontCachePurgePreventer;
34 FontDescription fontDescription; 33 FontDescription fontDescription;
35 Font* font; 34 Font* font;
36 unsigned startIndex = 0; 35 unsigned startIndex = 0;
37 unsigned numGlyphs = 0; 36 unsigned numGlyphs = 0;
38 hb_script_t script = HB_SCRIPT_INVALID; 37 hb_script_t script = HB_SCRIPT_INVALID;
39 }; 38 };
40 39
41 40
42 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) 41 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin)
43 { 42 {
44 TextRun latinCommon(reinterpret_cast<const LChar*>("ABC DEF."), 8); 43 TextRun latinCommon(reinterpret_cast<const LChar*>("ABC DEF."), 8);
45 HarfBuzzShaper shaper(font, latinCommon, &fallbackFonts); 44 HarfBuzzShaper shaper(font, latinCommon);
46 RefPtr<ShapeResult> result = shaper.shapeResult(); 45 RefPtr<ShapeResult> result = shaper.shapeResult();
47 46
48 ASSERT_EQ(1u, result->numberOfRunsForTesting()); 47 ASSERT_EQ(1u, result->numberOfRunsForTesting());
49 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); 48 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script));
50 EXPECT_EQ(0u, startIndex); 49 EXPECT_EQ(0u, startIndex);
51 EXPECT_EQ(8u, numGlyphs); 50 EXPECT_EQ(8u, numGlyphs);
52 EXPECT_EQ(HB_SCRIPT_LATIN, script); 51 EXPECT_EQ(HB_SCRIPT_LATIN, script);
53 } 52 }
54 53
55 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon) 54 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLeadingCommon)
56 { 55 {
57 TextRun leadingCommon(reinterpret_cast<const LChar*>("... test"), 8); 56 TextRun leadingCommon(reinterpret_cast<const LChar*>("... test"), 8);
58 HarfBuzzShaper shaper(font, leadingCommon, &fallbackFonts); 57 HarfBuzzShaper shaper(font, leadingCommon);
59 RefPtr<ShapeResult> result = shaper.shapeResult(); 58 RefPtr<ShapeResult> result = shaper.shapeResult();
60 59
61 ASSERT_EQ(1u, result->numberOfRunsForTesting()); 60 ASSERT_EQ(1u, result->numberOfRunsForTesting());
62 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); 61 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script));
63 EXPECT_EQ(0u, startIndex); 62 EXPECT_EQ(0u, startIndex);
64 EXPECT_EQ(8u, numGlyphs); 63 EXPECT_EQ(8u, numGlyphs);
65 EXPECT_EQ(HB_SCRIPT_LATIN, script); 64 EXPECT_EQ(HB_SCRIPT_LATIN, script);
66 } 65 }
67 66
68 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants) 67 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsUnicodeVariants)
69 { 68 {
70 struct { 69 struct {
71 const char* name; 70 const char* name;
72 UChar string[4]; 71 UChar string[4];
73 hb_script_t script; 72 hb_script_t script;
74 } testlist[] = { 73 } testlist[] = {
75 { "Standard Variants text style", { 0x30, 0xFE0E }, HB_SCRIPT_COMMON }, 74 { "Standard Variants text style", { 0x30, 0xFE0E }, HB_SCRIPT_COMMON },
76 { "Standard Variants emoji style", { 0x203C, 0xFE0F }, HB_SCRIPT_COMMON }, 75 { "Standard Variants emoji style", { 0x203C, 0xFE0F }, HB_SCRIPT_COMMON },
77 { "Standard Variants of Ideograph", { 0x4FAE, 0xFE00 }, HB_SCRIPT_HAN }, 76 { "Standard Variants of Ideograph", { 0x4FAE, 0xFE00 }, HB_SCRIPT_HAN },
78 { "Ideographic Variants", { 0x3402, 0xDB40, 0xDD00 }, HB_SCRIPT_HAN }, 77 { "Ideographic Variants", { 0x3402, 0xDB40, 0xDD00 }, HB_SCRIPT_HAN },
79 { "Not-defined Variants", { 0x41, 0xDB40, 0xDDEF }, HB_SCRIPT_LATIN }, 78 { "Not-defined Variants", { 0x41, 0xDB40, 0xDDEF }, HB_SCRIPT_LATIN },
80 }; 79 };
81 for (auto& test : testlist) { 80 for (auto& test : testlist) {
82 String str(test.string); 81 String str(test.string);
83 TextRun run(str); 82 TextRun run(str);
84 HarfBuzzShaper shaper(font, run, &fallbackFonts); 83 HarfBuzzShaper shaper(font, run);
85 RefPtr<ShapeResult> result = shaper.shapeResult(); 84 RefPtr<ShapeResult> result = shaper.shapeResult();
86 85
87 EXPECT_EQ(1u, result->numberOfRunsForTesting()) << test.name; 86 EXPECT_EQ(1u, result->numberOfRunsForTesting()) << test.name;
88 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)) << test.name; 87 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)) << test.name;
89 EXPECT_EQ(0u, startIndex) << test.name; 88 EXPECT_EQ(0u, startIndex) << test.name;
90 if (numGlyphs == 2) { 89 if (numGlyphs == 2) {
91 // If the specified VS is not in the font, it's mapped to .notdef. 90 // If the specified VS is not in the font, it's mapped to .notdef.
92 // then hb_ot_hide_default_ignorables() swaps it to a space with zer o-advance. 91 // then hb_ot_hide_default_ignorables() swaps it to a space with zer o-advance.
93 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.ht ml 92 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.ht ml
94 // OpenType recommends Glyph ID 3 for a space; not a hard requiremen t though. 93 // OpenType recommends Glyph ID 3 for a space; not a hard requiremen t though.
95 // https://www.microsoft.com/typography/otspec/recom.htm 94 // https://www.microsoft.com/typography/otspec/recom.htm
96 #if !OS(MACOSX) 95 #if !OS(MACOSX)
97 EXPECT_EQ(3u, result->glyphForTesting(0, 1)) << test.name; 96 EXPECT_EQ(3u, result->glyphForTesting(0, 1)) << test.name;
98 #endif 97 #endif
99 EXPECT_EQ(0.f, result->advanceForTesting(0, 1)) << test.name; 98 EXPECT_EQ(0.f, result->advanceForTesting(0, 1)) << test.name;
100 } else { 99 } else {
101 EXPECT_EQ(1u, numGlyphs) << test.name; 100 EXPECT_EQ(1u, numGlyphs) << test.name;
102 } 101 }
103 EXPECT_EQ(test.script, script) << test.name; 102 EXPECT_EQ(test.script, script) << test.name;
104 } 103 }
105 } 104 }
106 105
107 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon) 106 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommon)
108 { 107 {
109 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 }; 108 UChar devanagariCommonString[] = { 0x915, 0x94d, 0x930, 0x28, 0x20, 0x29 };
110 TextRun devanagariCommonLatin(devanagariCommonString, 6); 109 TextRun devanagariCommonLatin(devanagariCommonString, 6);
111 HarfBuzzShaper shaper(font, devanagariCommonLatin, &fallbackFonts); 110 HarfBuzzShaper shaper(font, devanagariCommonLatin);
112 RefPtr<ShapeResult> result = shaper.shapeResult(); 111 RefPtr<ShapeResult> result = shaper.shapeResult();
113 112
114 ASSERT_EQ(2u, result->numberOfRunsForTesting()); 113 ASSERT_EQ(2u, result->numberOfRunsForTesting());
115 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); 114 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script));
116 EXPECT_EQ(0u, startIndex); 115 EXPECT_EQ(0u, startIndex);
117 EXPECT_EQ(1u, numGlyphs); 116 EXPECT_EQ(1u, numGlyphs);
118 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 117 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
119 118
120 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); 119 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script));
121 EXPECT_EQ(3u, startIndex); 120 EXPECT_EQ(3u, startIndex);
122 EXPECT_EQ(3u, numGlyphs); 121 EXPECT_EQ(3u, numGlyphs);
123 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 122 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
124 } 123 }
125 124
126 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon) 125 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsDevanagariCommonLatinCommon)
127 { 126 {
128 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6 2, 0x2E }; 127 UChar devanagariCommonLatinString[] = { 0x915, 0x94d, 0x930, 0x20, 0x61, 0x6 2, 0x2E };
129 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7); 128 TextRun devanagariCommonLatin(devanagariCommonLatinString, 7);
130 HarfBuzzShaper shaper(font, devanagariCommonLatin, &fallbackFonts); 129 HarfBuzzShaper shaper(font, devanagariCommonLatin);
131 RefPtr<ShapeResult> result = shaper.shapeResult(); 130 RefPtr<ShapeResult> result = shaper.shapeResult();
132 131
133 ASSERT_EQ(3u, result->numberOfRunsForTesting()); 132 ASSERT_EQ(3u, result->numberOfRunsForTesting());
134 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); 133 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script));
135 EXPECT_EQ(0u, startIndex); 134 EXPECT_EQ(0u, startIndex);
136 EXPECT_EQ(1u, numGlyphs); 135 EXPECT_EQ(1u, numGlyphs);
137 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 136 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
138 137
139 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); 138 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script));
140 EXPECT_EQ(3u, startIndex); 139 EXPECT_EQ(3u, startIndex);
141 EXPECT_EQ(1u, numGlyphs); 140 EXPECT_EQ(1u, numGlyphs);
142 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script); 141 EXPECT_EQ(HB_SCRIPT_DEVANAGARI, script);
143 142
144 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script)); 143 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script));
145 EXPECT_EQ(4u, startIndex); 144 EXPECT_EQ(4u, startIndex);
146 EXPECT_EQ(3u, numGlyphs); 145 EXPECT_EQ(3u, numGlyphs);
147 EXPECT_EQ(HB_SCRIPT_LATIN, script); 146 EXPECT_EQ(HB_SCRIPT_LATIN, script);
148 } 147 }
149 148
150 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin) 149 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabicThaiHanLatin)
151 { 150 {
152 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 }; 151 UChar mixedString[] = { 0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62 };
153 TextRun mixed(mixedString, 6); 152 TextRun mixed(mixedString, 6);
154 HarfBuzzShaper shaper(font, mixed, &fallbackFonts); 153 HarfBuzzShaper shaper(font, mixed);
155 RefPtr<ShapeResult> result = shaper.shapeResult(); 154 RefPtr<ShapeResult> result = shaper.shapeResult();
156 155
157 ASSERT_EQ(4u, result->numberOfRunsForTesting()); 156 ASSERT_EQ(4u, result->numberOfRunsForTesting());
158 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); 157 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script));
159 EXPECT_EQ(0u, startIndex); 158 EXPECT_EQ(0u, startIndex);
160 EXPECT_EQ(3u, numGlyphs); 159 EXPECT_EQ(3u, numGlyphs);
161 EXPECT_EQ(HB_SCRIPT_ARABIC, script); 160 EXPECT_EQ(HB_SCRIPT_ARABIC, script);
162 161
163 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script)); 162 ASSERT_TRUE(result->runInfoForTesting(1, startIndex, numGlyphs, script));
164 EXPECT_EQ(3u, startIndex); 163 EXPECT_EQ(3u, startIndex);
165 EXPECT_EQ(1u, numGlyphs); 164 EXPECT_EQ(1u, numGlyphs);
166 EXPECT_EQ(HB_SCRIPT_THAI, script); 165 EXPECT_EQ(HB_SCRIPT_THAI, script);
167 166
168 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script)); 167 ASSERT_TRUE(result->runInfoForTesting(2, startIndex, numGlyphs, script));
169 EXPECT_EQ(4u, startIndex); 168 EXPECT_EQ(4u, startIndex);
170 EXPECT_EQ(1u, numGlyphs); 169 EXPECT_EQ(1u, numGlyphs);
171 EXPECT_EQ(HB_SCRIPT_HAN, script); 170 EXPECT_EQ(HB_SCRIPT_HAN, script);
172 171
173 ASSERT_TRUE(result->runInfoForTesting(3, startIndex, numGlyphs, script)); 172 ASSERT_TRUE(result->runInfoForTesting(3, startIndex, numGlyphs, script));
174 EXPECT_EQ(5u, startIndex); 173 EXPECT_EQ(5u, startIndex);
175 EXPECT_EQ(1u, numGlyphs); 174 EXPECT_EQ(1u, numGlyphs);
176 EXPECT_EQ(HB_SCRIPT_LATIN, script); 175 EXPECT_EQ(HB_SCRIPT_LATIN, script);
177 } 176 }
178 177
179 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic) 178 TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsArabic)
180 { 179 {
181 UChar arabicString[] = { 0x628, 0x64A, 0x629 }; 180 UChar arabicString[] = { 0x628, 0x64A, 0x629 };
182 TextRun arabic(arabicString, 3); 181 TextRun arabic(arabicString, 3);
183 HarfBuzzShaper shaper(font, arabic, &fallbackFonts); 182 HarfBuzzShaper shaper(font, arabic);
184 RefPtr<ShapeResult> result = shaper.shapeResult(); 183 RefPtr<ShapeResult> result = shaper.shapeResult();
185 184
186 ASSERT_EQ(1u, result->numberOfRunsForTesting()); 185 ASSERT_EQ(1u, result->numberOfRunsForTesting());
187 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script)); 186 ASSERT_TRUE(result->runInfoForTesting(0, startIndex, numGlyphs, script));
188 EXPECT_EQ(0u, startIndex); 187 EXPECT_EQ(0u, startIndex);
189 EXPECT_EQ(3u, numGlyphs); 188 EXPECT_EQ(3u, numGlyphs);
190 EXPECT_EQ(HB_SCRIPT_ARABIC, script); 189 EXPECT_EQ(HB_SCRIPT_ARABIC, script);
191 } 190 }
192 191
193 } // namespace blink 192 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/fonts/shaping/HarfBuzzShaper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698