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