| OLD | NEW |
| 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 Loading... |
| 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, const sk_sp<SkTypeface
>& face) { | 34 static void test_unitsPerEm(skiatest::Reporter* reporter, 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, const sk_sp<SkTypefac
e>& face) { | 53 static void test_countGlyphs(skiatest::Reporter* reporter, SkTypeface* 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 Loading... |
| 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, const sk_sp<SkTypef
ace>& face) { | 89 static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* 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 Loading... |
| 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 SkUnichar c = 0xf021; | 157 SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/SpiderSymbol
.ttf")); |
| 158 uint16_t g; | 158 if (!typeface) { |
| 159 SkPaint paint; | |
| 160 paint.setTypeface(MakeResourceAsTypeface("/fonts/SpiderSymbol.ttf")); | |
| 161 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | |
| 162 paint.textToGlyphs(&c, 4, &g); | |
| 163 | |
| 164 if (!paint.getTypeface()) { | |
| 165 SkDebugf("Skipping FontHostTest::test_symbolfont\n"); | 159 SkDebugf("Skipping FontHostTest::test_symbolfont\n"); |
| 166 return; | 160 return; |
| 167 } | 161 } |
| 168 | 162 |
| 163 SkUnichar c = 0xf021; |
| 164 uint16_t g; |
| 165 SkPaint paint; |
| 166 paint.setTypeface(typeface); |
| 167 paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
| 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, const sk_sp<SkTypeface>& f
ace) { | 172 static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) { |
| 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 Loading... |
| 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 sk_sp<SkTypeface> face(SkTypeface::MakeFromName(gNames[i], SkTypeface::k
Normal)); | 226 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTy
peface::kNormal)); |
| 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 Loading... |
| 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 paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal
)); | 280 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTyp
eface::kNormal)); |
| 281 paint.setTypeface(face); |
| 281 | 282 |
| 282 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { | 283 for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { |
| 283 paint.setHinting(settings[j].hinting); | 284 paint.setHinting(settings[j].hinting); |
| 284 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag)
!= 0); | 285 paint.setLinearText((settings[j].flags & SkPaint::kLinearText_Flag)
!= 0); |
| 285 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl
ag) != 0); | 286 paint.setSubpixelText((settings[j].flags & SkPaint::kSubpixelText_Fl
ag) != 0); |
| 286 | 287 |
| 287 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { | 288 for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { |
| 288 paint.setTextScaleX(gScaleRec[k].fScaleX); | 289 paint.setTextScaleX(gScaleRec[k].fScaleX); |
| 289 paint.setTextSkewX(gScaleRec[k].fSkewX); | 290 paint.setTextSkewX(gScaleRec[k].fSkewX); |
| 290 | 291 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 307 } | 308 } |
| 308 | 309 |
| 309 DEF_TEST(FontHost, reporter) { | 310 DEF_TEST(FontHost, reporter) { |
| 310 test_tables(reporter); | 311 test_tables(reporter); |
| 311 test_fontstream(reporter); | 312 test_fontstream(reporter); |
| 312 test_advances(reporter); | 313 test_advances(reporter); |
| 313 test_symbolfont(reporter); | 314 test_symbolfont(reporter); |
| 314 } | 315 } |
| 315 | 316 |
| 316 // need tests for SkStrSearch | 317 // need tests for SkStrSearch |
| OLD | NEW |