reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 8 | #include "Resources.h" |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 9 | #include "SkAutoMalloc.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 10 | #include "SkEndian.h" |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 11 | #include "SkFont.h" |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 12 | #include "SkFontStream.h" |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 13 | #include "SkOSFile.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 14 | #include "SkPaint.h" |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 15 | #include "SkStream.h" |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 16 | #include "SkTypeface.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 17 | #include "Test.h" |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 18 | |
| 19 | //#define DUMP_TABLES |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 20 | //#define DUMP_TTC_TABLES |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 21 | |
| 22 | #define kFontTableTag_head SkSetFourByteTag('h', 'e', 'a', 'd') |
| 23 | #define kFontTableTag_hhea SkSetFourByteTag('h', 'h', 'e', 'a') |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 24 | #define kFontTableTag_maxp SkSetFourByteTag('m', 'a', 'x', 'p') |
| 25 | |
| 26 | static const struct TagSize { |
| 27 | SkFontTableTag fTag; |
| 28 | size_t fSize; |
| 29 | } gKnownTableSizes[] = { |
| 30 | { kFontTableTag_head, 54 }, |
| 31 | { kFontTableTag_hhea, 36 }, |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
reed@google.com | a262eea | 2013-03-21 15:20:00 +0000 | [diff] [blame] | 34 | // Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 35 | // (if that table is available). |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 36 | static void test_unitsPerEm(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) { |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 37 | int nativeUPEM = face->getUnitsPerEm(); |
reed@google.com | 4b2af9c | 2012-07-31 17:24:44 +0000 | [diff] [blame] | 38 | |
reed@google.com | a262eea | 2013-03-21 15:20:00 +0000 | [diff] [blame] | 39 | int tableUPEM = -1; |
reed@google.com | 4b2af9c | 2012-07-31 17:24:44 +0000 | [diff] [blame] | 40 | size_t size = face->getTableSize(kFontTableTag_head); |
| 41 | if (size) { |
reed@google.com | 4b2af9c | 2012-07-31 17:24:44 +0000 | [diff] [blame] | 42 | // unitsPerEm is at offset 18 into the 'head' table. |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 43 | uint16_t rawUPEM; |
| 44 | face->getTableData(kFontTableTag_head, 18, sizeof(rawUPEM), &rawUPEM); |
| 45 | tableUPEM = SkEndian_SwapBE16(rawUPEM); |
reed@google.com | a262eea | 2013-03-21 15:20:00 +0000 | [diff] [blame] | 46 | } |
reed@google.com | a262eea | 2013-03-21 15:20:00 +0000 | [diff] [blame] | 47 | |
| 48 | if (tableUPEM >= 0) { |
| 49 | REPORTER_ASSERT(reporter, tableUPEM == nativeUPEM); |
reed@google.com | 4b2af9c | 2012-07-31 17:24:44 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 53 | // Test that countGlyphs() agrees with a direct lookup in the 'maxp' table |
| 54 | // (if that table is available). |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 55 | static void test_countGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) { |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 56 | int nativeGlyphs = face->countGlyphs(); |
| 57 | |
| 58 | int tableGlyphs = -1; |
| 59 | size_t size = face->getTableSize(kFontTableTag_maxp); |
| 60 | if (size) { |
| 61 | // glyphs is at offset 4 into the 'maxp' table. |
| 62 | uint16_t rawGlyphs; |
| 63 | face->getTableData(kFontTableTag_maxp, 4, sizeof(rawGlyphs), &rawGlyphs); |
| 64 | tableGlyphs = SkEndian_SwapBE16(rawGlyphs); |
| 65 | } |
| 66 | |
| 67 | if (tableGlyphs >= 0) { |
| 68 | REPORTER_ASSERT(reporter, tableGlyphs == nativeGlyphs); |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
bungeman@google.com | 72b8cb2 | 2013-10-25 17:49:08 +0000 | [diff] [blame] | 71 | |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 72 | // The following three are all the same code points in various encodings. |
bungeman | 7b09aab | 2014-09-24 11:04:41 -0700 | [diff] [blame] | 73 | // a中Яיו𝄞a𠮟 |
| 74 | static uint8_t utf8Chars[] = { 0x61, 0xE4,0xB8,0xAD, 0xD0,0xAF, 0xD7,0x99, 0xD7,0x95, 0xF0,0x9D,0x84,0x9E, 0x61, 0xF0,0xA0,0xAE,0x9F }; |
| 75 | static uint16_t utf16Chars[] = { 0x0061, 0x4E2D, 0x042F, 0x05D9, 0x05D5, 0xD834,0xDD1E, 0x0061, 0xD842,0xDF9F }; |
| 76 | static uint32_t utf32Chars[] = { 0x00000061, 0x00004E2D, 0x0000042F, 0x000005D9, 0x000005D5, 0x0001D11E, 0x00000061, 0x00020B9F }; |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 77 | |
| 78 | struct CharsToGlyphs_TestData { |
| 79 | const void* chars; |
| 80 | int charCount; |
| 81 | size_t charsByteLength; |
| 82 | SkTypeface::Encoding typefaceEncoding; |
| 83 | const char* name; |
| 84 | } static charsToGlyphs_TestData[] = { |
bungeman | 7b09aab | 2014-09-24 11:04:41 -0700 | [diff] [blame] | 85 | { utf8Chars, 8, sizeof(utf8Chars), SkTypeface::kUTF8_Encoding, "Simple UTF-8" }, |
| 86 | { utf16Chars, 8, sizeof(utf16Chars), SkTypeface::kUTF16_Encoding, "Simple UTF-16" }, |
| 87 | { utf32Chars, 8, sizeof(utf32Chars), SkTypeface::kUTF32_Encoding, "Simple UTF-32" }, |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | // Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs. |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 91 | static void test_charsToGlyphs(skiatest::Reporter* reporter, sk_sp<SkTypeface> face) { |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 92 | uint16_t paintGlyphIds[256]; |
| 93 | uint16_t faceGlyphIds[256]; |
| 94 | |
| 95 | for (size_t testIndex = 0; testIndex < SK_ARRAY_COUNT(charsToGlyphs_TestData); ++testIndex) { |
| 96 | CharsToGlyphs_TestData& test = charsToGlyphs_TestData[testIndex]; |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 97 | SkTextEncoding encoding = static_cast<SkTextEncoding>(test.typefaceEncoding); |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 98 | |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 99 | SkFont font(face); |
| 100 | font.textToGlyphs(test.chars, test.charsByteLength, encoding, |
| 101 | paintGlyphIds, SK_ARRAY_COUNT(paintGlyphIds)); |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 102 | |
| 103 | face->charsToGlyphs(test.chars, test.typefaceEncoding, faceGlyphIds, test.charCount); |
| 104 | |
| 105 | for (int i = 0; i < test.charCount; ++i) { |
| 106 | SkString name; |
| 107 | face->getFamilyName(&name); |
| 108 | SkString a; |
skia.committer@gmail.com | 7dc4fd0 | 2013-10-25 07:02:14 +0000 | [diff] [blame] | 109 | a.appendf("%s, paintGlyphIds[%d] = %d, faceGlyphIds[%d] = %d, face = %s", |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 110 | test.name, i, (int)paintGlyphIds[i], i, (int)faceGlyphIds[i], name.c_str()); |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, paintGlyphIds[i] == faceGlyphIds[i], a.c_str()); |
bungeman@google.com | 3c996f8 | 2013-10-24 21:39:35 +0000 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
bungeman | 3ffa126 | 2015-04-30 17:12:58 -0400 | [diff] [blame] | 116 | static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream, int ttcIndex) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 117 | int n = SkFontStream::GetTableTags(stream, ttcIndex, nullptr); |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 118 | SkAutoTArray<SkFontTableTag> array(n); |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 119 | |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 120 | int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get()); |
| 121 | REPORTER_ASSERT(reporter, n == n2); |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 122 | |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 123 | for (int i = 0; i < n; ++i) { |
| 124 | #ifdef DUMP_TTC_TABLES |
| 125 | SkString str; |
| 126 | SkFontTableTag t = array[i]; |
| 127 | str.appendUnichar((t >> 24) & 0xFF); |
| 128 | str.appendUnichar((t >> 16) & 0xFF); |
| 129 | str.appendUnichar((t >> 8) & 0xFF); |
| 130 | str.appendUnichar((t >> 0) & 0xFF); |
| 131 | SkDebugf("[%d:%d] '%s'\n", ttcIndex, i, str.c_str()); |
| 132 | #endif |
| 133 | size_t size = SkFontStream::GetTableSize(stream, ttcIndex, array[i]); |
| 134 | for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) { |
| 135 | if (gKnownTableSizes[j].fTag == array[i]) { |
| 136 | REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size); |
| 137 | } |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 138 | } |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
bungeman | 3ffa126 | 2015-04-30 17:12:58 -0400 | [diff] [blame] | 142 | static void test_fontstream(skiatest::Reporter* reporter) { |
Hal Canary | 53e5e7d | 2017-12-08 14:25:14 -0500 | [diff] [blame] | 143 | std::unique_ptr<SkStreamAsset> stream(GetResourceAsStream("fonts/test.ttc")); |
bungeman | 3ffa126 | 2015-04-30 17:12:58 -0400 | [diff] [blame] | 144 | if (!stream) { |
| 145 | SkDebugf("Skipping FontHostTest::test_fontstream\n"); |
| 146 | return; |
| 147 | } |
| 148 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 149 | int count = SkFontStream::CountTTCEntries(stream.get()); |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 150 | #ifdef DUMP_TTC_TABLES |
| 151 | SkDebugf("CountTTCEntries %d\n", count); |
| 152 | #endif |
| 153 | for (int i = 0; i < count; ++i) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 154 | test_fontstream(reporter, stream.get(), i); |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 158 | // Exercise this rare cmap format (platform 3, encoding 0) |
bungeman | 726cf90 | 2015-06-05 13:38:12 -0700 | [diff] [blame] | 159 | static void test_symbolfont(skiatest::Reporter* reporter) { |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 160 | auto tf = MakeResourceAsTypeface("fonts/SpiderSymbol.ttf"); |
| 161 | if (tf) { |
| 162 | SkUnichar c = 0xf021; |
| 163 | uint16_t g = SkFont(tf).unicharToGlyph(c); |
| 164 | REPORTER_ASSERT(reporter, g == 3); |
| 165 | } else { |
| 166 | // not all platforms support data fonts, so we just note that failure |
bungeman | 726cf90 | 2015-06-05 13:38:12 -0700 | [diff] [blame] | 167 | SkDebugf("Skipping FontHostTest::test_symbolfont\n"); |
bungeman | 726cf90 | 2015-06-05 13:38:12 -0700 | [diff] [blame] | 168 | } |
bungeman | 726cf90 | 2015-06-05 13:38:12 -0700 | [diff] [blame] | 169 | } |
| 170 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 171 | static void test_tables(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) { |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 172 | if (false) { // avoid bit rot, suppress warning |
robertphillips@google.com | 5b33211 | 2013-01-30 20:33:12 +0000 | [diff] [blame] | 173 | SkFontID fontID = face->uniqueID(); |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 174 | REPORTER_ASSERT(reporter, fontID); |
| 175 | } |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 176 | |
reed@google.com | 8b0a335 | 2012-04-19 18:52:39 +0000 | [diff] [blame] | 177 | int count = face->countTables(); |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 178 | |
| 179 | SkAutoTMalloc<SkFontTableTag> storage(count); |
| 180 | SkFontTableTag* tags = storage.get(); |
reed@google.com | fbd033d | 2012-02-23 16:15:58 +0000 | [diff] [blame] | 181 | |
reed@google.com | 8b0a335 | 2012-04-19 18:52:39 +0000 | [diff] [blame] | 182 | int count2 = face->getTableTags(tags); |
reed@google.com | fbd033d | 2012-02-23 16:15:58 +0000 | [diff] [blame] | 183 | REPORTER_ASSERT(reporter, count2 == count); |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 184 | |
| 185 | for (int i = 0; i < count; ++i) { |
reed@google.com | 8b0a335 | 2012-04-19 18:52:39 +0000 | [diff] [blame] | 186 | size_t size = face->getTableSize(tags[i]); |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 187 | REPORTER_ASSERT(reporter, size > 0); |
| 188 | |
| 189 | #ifdef DUMP_TABLES |
| 190 | char name[5]; |
| 191 | name[0] = (tags[i] >> 24) & 0xFF; |
| 192 | name[1] = (tags[i] >> 16) & 0xFF; |
| 193 | name[2] = (tags[i] >> 8) & 0xFF; |
| 194 | name[3] = (tags[i] >> 0) & 0xFF; |
| 195 | name[4] = 0; |
| 196 | SkDebugf("%s %d\n", name, size); |
| 197 | #endif |
| 198 | |
| 199 | for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) { |
| 200 | if (gKnownTableSizes[j].fTag == tags[i]) { |
| 201 | REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size); |
| 202 | } |
| 203 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 204 | |
reed@google.com | fbd033d | 2012-02-23 16:15:58 +0000 | [diff] [blame] | 205 | // do we get the same size from GetTableData and GetTableSize |
| 206 | { |
| 207 | SkAutoMalloc data(size); |
reed@google.com | 8b0a335 | 2012-04-19 18:52:39 +0000 | [diff] [blame] | 208 | size_t size2 = face->getTableData(tags[i], 0, size, data.get()); |
reed@google.com | fbd033d | 2012-02-23 16:15:58 +0000 | [diff] [blame] | 209 | REPORTER_ASSERT(reporter, size2 == size); |
| 210 | } |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
| 214 | static void test_tables(skiatest::Reporter* reporter) { |
| 215 | static const char* const gNames[] = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 216 | nullptr, // default font |
bungeman | 7b09aab | 2014-09-24 11:04:41 -0700 | [diff] [blame] | 217 | "Helvetica", "Arial", |
| 218 | "Times", "Times New Roman", |
| 219 | "Courier", "Courier New", |
| 220 | "Terminal", "MS Sans Serif", |
| 221 | "Hiragino Mincho ProN", "MS PGothic", |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 225 | sk_sp<SkTypeface> face(SkTypeface::MakeFromName(gNames[i], SkFontStyle())); |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 226 | if (face) { |
| 227 | #ifdef DUMP_TABLES |
| 228 | SkDebugf("%s\n", gNames[i]); |
| 229 | #endif |
| 230 | test_tables(reporter, face); |
reed@google.com | 4b2af9c | 2012-07-31 17:24:44 +0000 | [diff] [blame] | 231 | test_unitsPerEm(reporter, face); |
bungeman@google.com | 7bdd614 | 2013-07-15 19:42:57 +0000 | [diff] [blame] | 232 | test_countGlyphs(reporter, face); |
bungeman@google.com | 72b8cb2 | 2013-10-25 17:49:08 +0000 | [diff] [blame] | 233 | test_charsToGlyphs(reporter, face); |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 238 | /* |
| 239 | * Verifies that the advance values returned by generateAdvance and |
| 240 | * generateMetrics match. |
| 241 | */ |
| 242 | static void test_advances(skiatest::Reporter* reporter) { |
| 243 | static const char* const faces[] = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 244 | nullptr, // default font |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 245 | "Arial", "Times", "Times New Roman", "Helvetica", "Courier", |
| 246 | "Courier New", "Verdana", "monospace", |
| 247 | }; |
| 248 | |
| 249 | static const struct { |
Mike Reed | 9edbf42 | 2018-11-07 19:54:33 -0500 | [diff] [blame] | 250 | SkFontHinting hinting; |
Mike Reed | e5f9cfa | 2019-01-10 13:55:35 -0500 | [diff] [blame] | 251 | bool linear; |
| 252 | bool subpixel; |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 253 | } settings[] = { |
Mike Reed | e5f9cfa | 2019-01-10 13:55:35 -0500 | [diff] [blame] | 254 | { kNo_SkFontHinting, false, false }, |
| 255 | { kNo_SkFontHinting, true, false }, |
| 256 | { kNo_SkFontHinting, false, true }, |
| 257 | { kSlight_SkFontHinting, false, false }, |
| 258 | { kSlight_SkFontHinting, true, false }, |
| 259 | { kSlight_SkFontHinting, false, true }, |
| 260 | { kNormal_SkFontHinting, false, false }, |
| 261 | { kNormal_SkFontHinting, true, false }, |
| 262 | { kNormal_SkFontHinting, false, true }, |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
reed@google.com | d074c37 | 2012-07-18 13:45:58 +0000 | [diff] [blame] | 265 | static const struct { |
| 266 | SkScalar fScaleX; |
| 267 | SkScalar fSkewX; |
| 268 | } gScaleRec[] = { |
| 269 | { SK_Scalar1, 0 }, |
| 270 | { SK_Scalar1/2, 0 }, |
| 271 | // these two exercise obliquing (skew) |
| 272 | { SK_Scalar1, -SK_Scalar1/4 }, |
| 273 | { SK_Scalar1/2, -SK_Scalar1/4 }, |
| 274 | }; |
| 275 | |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 276 | SkFont font; |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 277 | char txt[] = "long.text.with.lots.of.dots."; |
| 278 | |
| 279 | for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) { |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 280 | font.setTypeface(SkTypeface::MakeFromName(faces[i], SkFontStyle())); |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 281 | |
| 282 | for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 283 | font.setHinting(settings[j].hinting); |
Mike Reed | e5f9cfa | 2019-01-10 13:55:35 -0500 | [diff] [blame] | 284 | font.setLinearMetrics(settings[j].linear); |
| 285 | font.setSubpixel(settings[j].subpixel); |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 286 | |
reed@google.com | d074c37 | 2012-07-18 13:45:58 +0000 | [diff] [blame] | 287 | for (size_t k = 0; k < SK_ARRAY_COUNT(gScaleRec); ++k) { |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 288 | font.setScaleX(gScaleRec[k].fScaleX); |
| 289 | font.setSkewX(gScaleRec[k].fSkewX); |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 290 | |
reed@google.com | d074c37 | 2012-07-18 13:45:58 +0000 | [diff] [blame] | 291 | SkRect bounds; |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 292 | |
reed@google.com | d074c37 | 2012-07-18 13:45:58 +0000 | [diff] [blame] | 293 | // For no hinting and light hinting this should take the |
| 294 | // optimized generateAdvance path. |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 295 | SkScalar width1 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding); |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 296 | |
reed@google.com | d074c37 | 2012-07-18 13:45:58 +0000 | [diff] [blame] | 297 | // Requesting the bounds forces a generateMetrics call. |
Mike Reed | f9e824b | 2018-12-13 10:22:39 -0500 | [diff] [blame] | 298 | SkScalar width2 = font.measureText(txt, strlen(txt), kUTF8_SkTextEncoding, &bounds); |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 299 | |
reed@google.com | d074c37 | 2012-07-18 13:45:58 +0000 | [diff] [blame] | 300 | // SkDebugf("Font: %s, generateAdvance: %f, generateMetrics: %f\n", |
| 301 | // faces[i], SkScalarToFloat(width1), SkScalarToFloat(width2)); |
| 302 | |
| 303 | REPORTER_ASSERT(reporter, width1 == width2); |
| 304 | } |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 309 | DEF_TEST(FontHost, reporter) { |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 310 | test_tables(reporter); |
reed@google.com | ed268bf | 2013-03-11 20:13:36 +0000 | [diff] [blame] | 311 | test_fontstream(reporter); |
bungeman@google.com | 34f1026 | 2012-03-23 18:11:47 +0000 | [diff] [blame] | 312 | test_advances(reporter); |
bungeman | 726cf90 | 2015-06-05 13:38:12 -0700 | [diff] [blame] | 313 | test_symbolfont(reporter); |
reed@google.com | 17aa07d | 2012-02-23 14:51:10 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // need tests for SkStrSearch |