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

Side by Side Diff: tests/FontHostTest.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments. Created 4 years, 7 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 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkEndian.h" 9 #include "SkEndian.h"
10 #include "SkFontStream.h" 10 #include "SkFontStream.h"
(...skipping 13 matching lines...) Expand all
24 static const struct TagSize { 24 static const struct TagSize {
25 SkFontTableTag fTag; 25 SkFontTableTag fTag;
26 size_t fSize; 26 size_t fSize;
27 } gKnownTableSizes[] = { 27 } gKnownTableSizes[] = {
28 { kFontTableTag_head, 54 }, 28 { kFontTableTag_head, 54 },
29 { kFontTableTag_hhea, 36 }, 29 { kFontTableTag_hhea, 36 },
30 }; 30 };
31 31
32 // Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table 32 // Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table
33 // (if that table is available). 33 // (if that table is available).
34 static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) { 34 static void test_unitsPerEm(skiatest::Reporter* reporter, const sk_sp<SkTypeface >& face) {
35 int nativeUPEM = face->getUnitsPerEm(); 35 int nativeUPEM = face->getUnitsPerEm();
36 36
37 int tableUPEM = -1; 37 int tableUPEM = -1;
38 size_t size = face->getTableSize(kFontTableTag_head); 38 size_t size = face->getTableSize(kFontTableTag_head);
39 if (size) { 39 if (size) {
40 // unitsPerEm is at offset 18 into the 'head' table. 40 // unitsPerEm is at offset 18 into the 'head' table.
41 uint16_t rawUPEM; 41 uint16_t rawUPEM;
42 face->getTableData(kFontTableTag_head, 18, sizeof(rawUPEM), &rawUPEM); 42 face->getTableData(kFontTableTag_head, 18, sizeof(rawUPEM), &rawUPEM);
43 tableUPEM = SkEndian_SwapBE16(rawUPEM); 43 tableUPEM = SkEndian_SwapBE16(rawUPEM);
44 } 44 }
45 45
46 if (tableUPEM >= 0) { 46 if (tableUPEM >= 0) {
47 REPORTER_ASSERT(reporter, tableUPEM == nativeUPEM); 47 REPORTER_ASSERT(reporter, tableUPEM == nativeUPEM);
48 } 48 }
49 } 49 }
50 50
51 // Test that countGlyphs() agrees with a direct lookup in the 'maxp' table 51 // Test that countGlyphs() agrees with a direct lookup in the 'maxp' table
52 // (if that table is available). 52 // (if that table is available).
53 static void test_countGlyphs(skiatest::Reporter* reporter, SkTypeface* face) { 53 static void test_countGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypefac e>& face) {
54 int nativeGlyphs = face->countGlyphs(); 54 int nativeGlyphs = face->countGlyphs();
55 55
56 int tableGlyphs = -1; 56 int tableGlyphs = -1;
57 size_t size = face->getTableSize(kFontTableTag_maxp); 57 size_t size = face->getTableSize(kFontTableTag_maxp);
58 if (size) { 58 if (size) {
59 // glyphs is at offset 4 into the 'maxp' table. 59 // glyphs is at offset 4 into the 'maxp' table.
60 uint16_t rawGlyphs; 60 uint16_t rawGlyphs;
61 face->getTableData(kFontTableTag_maxp, 4, sizeof(rawGlyphs), &rawGlyphs) ; 61 face->getTableData(kFontTableTag_maxp, 4, sizeof(rawGlyphs), &rawGlyphs) ;
62 tableGlyphs = SkEndian_SwapBE16(rawGlyphs); 62 tableGlyphs = SkEndian_SwapBE16(rawGlyphs);
63 } 63 }
(...skipping 15 matching lines...) Expand all
79 size_t charsByteLength; 79 size_t charsByteLength;
80 SkTypeface::Encoding typefaceEncoding; 80 SkTypeface::Encoding typefaceEncoding;
81 const char* name; 81 const char* name;
82 } static charsToGlyphs_TestData[] = { 82 } static charsToGlyphs_TestData[] = {
83 { utf8Chars, 8, sizeof(utf8Chars), SkTypeface::kUTF8_Encoding, "Simple UTF-8 " }, 83 { utf8Chars, 8, sizeof(utf8Chars), SkTypeface::kUTF8_Encoding, "Simple UTF-8 " },
84 { utf16Chars, 8, sizeof(utf16Chars), SkTypeface::kUTF16_Encoding, "Simple UT F-16" }, 84 { utf16Chars, 8, sizeof(utf16Chars), SkTypeface::kUTF16_Encoding, "Simple UT F-16" },
85 { utf32Chars, 8, sizeof(utf32Chars), SkTypeface::kUTF32_Encoding, "Simple UT F-32" }, 85 { utf32Chars, 8, sizeof(utf32Chars), SkTypeface::kUTF32_Encoding, "Simple UT F-32" },
86 }; 86 };
87 87
88 // Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs. 88 // Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs.
89 static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* face) { 89 static void test_charsToGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypef ace>& face) {
90 uint16_t paintGlyphIds[256]; 90 uint16_t paintGlyphIds[256];
91 uint16_t faceGlyphIds[256]; 91 uint16_t faceGlyphIds[256];
92 92
93 for (size_t testIndex = 0; testIndex < SK_ARRAY_COUNT(charsToGlyphs_TestData ); ++testIndex) { 93 for (size_t testIndex = 0; testIndex < SK_ARRAY_COUNT(charsToGlyphs_TestData ); ++testIndex) {
94 CharsToGlyphs_TestData& test = charsToGlyphs_TestData[testIndex]; 94 CharsToGlyphs_TestData& test = charsToGlyphs_TestData[testIndex];
95 95
96 SkPaint paint; 96 SkPaint paint;
97 paint.setTypeface(face); 97 paint.setTypeface(face);
98 paint.setTextEncoding((SkPaint::TextEncoding)test.typefaceEncoding); 98 paint.setTextEncoding((SkPaint::TextEncoding)test.typefaceEncoding);
99 paint.textToGlyphs(test.chars, test.charsByteLength, paintGlyphIds); 99 paint.textToGlyphs(test.chars, test.charsByteLength, paintGlyphIds);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 int count = SkFontStream::CountTTCEntries(stream); 147 int count = SkFontStream::CountTTCEntries(stream);
148 #ifdef DUMP_TTC_TABLES 148 #ifdef DUMP_TTC_TABLES
149 SkDebugf("CountTTCEntries %d\n", count); 149 SkDebugf("CountTTCEntries %d\n", count);
150 #endif 150 #endif
151 for (int i = 0; i < count; ++i) { 151 for (int i = 0; i < count; ++i) {
152 test_fontstream(reporter, stream, i); 152 test_fontstream(reporter, stream, i);
153 } 153 }
154 } 154 }
155 155
156 static void test_symbolfont(skiatest::Reporter* reporter) { 156 static void test_symbolfont(skiatest::Reporter* reporter) {
157 SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/SpiderSymbol .ttf")); 157 sk_sp<SkTypeface> typeface(MakeResourceAsTypeface("/fonts/SpiderSymbol.ttf") );
158 if (!typeface) { 158 if (!typeface) {
159 SkDebugf("Skipping FontHostTest::test_symbolfont\n"); 159 SkDebugf("Skipping FontHostTest::test_symbolfont\n");
160 return; 160 return;
161 } 161 }
162 162
163 SkUnichar c = 0xf021; 163 SkUnichar c = 0xf021;
164 uint16_t g; 164 uint16_t g;
165 SkPaint paint; 165 SkPaint paint;
166 paint.setTypeface(typeface); 166 paint.setTypeface(typeface);
f(malita) 2016/05/02 13:46:36 Nit: std::move(typeface)
bungeman-skia 2016/05/02 20:24:54 Done.
167 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); 167 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
168 paint.textToGlyphs(&c, 4, &g); 168 paint.textToGlyphs(&c, 4, &g);
169 REPORTER_ASSERT(reporter, g == 3); 169 REPORTER_ASSERT(reporter, g == 3);
170 } 170 }
171 171
172 static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) { 172 static void test_tables(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& f ace) {
173 if (false) { // avoid bit rot, suppress warning 173 if (false) { // avoid bit rot, suppress warning
174 SkFontID fontID = face->uniqueID(); 174 SkFontID fontID = face->uniqueID();
175 REPORTER_ASSERT(reporter, fontID); 175 REPORTER_ASSERT(reporter, fontID);
176 } 176 }
177 177
178 int count = face->countTables(); 178 int count = face->countTables();
179 179
180 SkAutoTMalloc<SkFontTableTag> storage(count); 180 SkAutoTMalloc<SkFontTableTag> storage(count);
181 SkFontTableTag* tags = storage.get(); 181 SkFontTableTag* tags = storage.get();
182 182
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 static const char* const gNames[] = { 216 static const char* const gNames[] = {
217 nullptr, // default font 217 nullptr, // default font
218 "Helvetica", "Arial", 218 "Helvetica", "Arial",
219 "Times", "Times New Roman", 219 "Times", "Times New Roman",
220 "Courier", "Courier New", 220 "Courier", "Courier New",
221 "Terminal", "MS Sans Serif", 221 "Terminal", "MS Sans Serif",
222 "Hiragino Mincho ProN", "MS PGothic", 222 "Hiragino Mincho ProN", "MS PGothic",
223 }; 223 };
224 224
225 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { 225 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
226 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTy peface::kNormal)); 226 sk_sp<SkTypeface> face(SkTypeface::MakeFromName(gNames[i], SkTypeface::k Normal));
227 if (face) { 227 if (face) {
228 #ifdef DUMP_TABLES 228 #ifdef DUMP_TABLES
229 SkDebugf("%s\n", gNames[i]); 229 SkDebugf("%s\n", gNames[i]);
230 #endif 230 #endif
231 test_tables(reporter, face); 231 test_tables(reporter, face);
232 test_unitsPerEm(reporter, face); 232 test_unitsPerEm(reporter, face);
233 test_countGlyphs(reporter, face); 233 test_countGlyphs(reporter, face);
234 test_charsToGlyphs(reporter, face); 234 test_charsToGlyphs(reporter, face);
235 } 235 }
236 } 236 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 { SK_Scalar1/2, 0 }, 270 { SK_Scalar1/2, 0 },
271 // these two exercise obliquing (skew) 271 // these two exercise obliquing (skew)
272 { SK_Scalar1, -SK_Scalar1/4 }, 272 { SK_Scalar1, -SK_Scalar1/4 },
273 { SK_Scalar1/2, -SK_Scalar1/4 }, 273 { SK_Scalar1/2, -SK_Scalar1/4 },
274 }; 274 };
275 275
276 SkPaint paint; 276 SkPaint paint;
277 char txt[] = "long.text.with.lots.of.dots."; 277 char txt[] = "long.text.with.lots.of.dots.";
278 278
279 for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) { 279 for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
280 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTyp eface::kNormal)); 280 paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal ));
281 paint.setTypeface(face);
282 281
283 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { 282 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
284 paint.setHinting(settings[j].hinting); 283 paint.setHinting(settings[j].hinting);
285 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0); 284 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag) != 0);
286 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl ag) != 0); 285 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl ag) != 0);
287 286
288 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { 287 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) {
289 paint.setTextScaleX(gScaleRec[k].fScaleX); 288 paint.setTextScaleX(gScaleRec[k].fScaleX);
290 paint.setTextSkewX(gScaleRec[k].fSkewX); 289 paint.setTextSkewX(gScaleRec[k].fSkewX);
291 290
(...skipping 16 matching lines...) Expand all
308 } 307 }
309 308
310 DEF_TEST(FontHost, reporter) { 309 DEF_TEST(FontHost, reporter) {
311 test_tables(reporter); 310 test_tables(reporter);
312 test_fontstream(reporter); 311 test_fontstream(reporter);
313 test_advances(reporter); 312 test_advances(reporter);
314 test_symbolfont(reporter); 313 test_symbolfont(reporter);
315 } 314 }
316 315
317 // need tests for SkStrSearch 316 // need tests for SkStrSearch
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698