| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 SkString name; | 104 SkString name; |
| 105 face->getFamilyName(&name); | 105 face->getFamilyName(&name); |
| 106 SkString a; | 106 SkString a; |
| 107 a.appendf("%s, paintGlyphIds[%d] = %d, faceGlyphIds[%d] = %d, face =
%s", | 107 a.appendf("%s, paintGlyphIds[%d] = %d, faceGlyphIds[%d] = %d, face =
%s", |
| 108 test.name, i, (int)paintGlyphIds[i], i, (int)faceGlyphIds[
i], name.c_str()); | 108 test.name, i, (int)paintGlyphIds[i], i, (int)faceGlyphIds[
i], name.c_str()); |
| 109 REPORTER_ASSERT_MESSAGE(reporter, paintGlyphIds[i] == faceGlyphIds[i
], a.c_str()); | 109 REPORTER_ASSERT_MESSAGE(reporter, paintGlyphIds[i] == faceGlyphIds[i
], a.c_str()); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 static void test_fontstream(skiatest::Reporter* reporter, | 114 static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream, int
ttcIndex) { |
| 115 SkStream* stream, int ttcIndex) { | |
| 116 int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL); | 115 int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL); |
| 117 SkAutoTArray<SkFontTableTag> array(n); | 116 SkAutoTArray<SkFontTableTag> array(n); |
| 118 | 117 |
| 119 int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get()); | 118 int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get()); |
| 120 REPORTER_ASSERT(reporter, n == n2); | 119 REPORTER_ASSERT(reporter, n == n2); |
| 121 | 120 |
| 122 for (int i = 0; i < n; ++i) { | 121 for (int i = 0; i < n; ++i) { |
| 123 #ifdef DUMP_TTC_TABLES | 122 #ifdef DUMP_TTC_TABLES |
| 124 SkString str; | 123 SkString str; |
| 125 SkFontTableTag t = array[i]; | 124 SkFontTableTag t = array[i]; |
| 126 str.appendUnichar((t >> 24) & 0xFF); | 125 str.appendUnichar((t >> 24) & 0xFF); |
| 127 str.appendUnichar((t >> 16) & 0xFF); | 126 str.appendUnichar((t >> 16) & 0xFF); |
| 128 str.appendUnichar((t >> 8) & 0xFF); | 127 str.appendUnichar((t >> 8) & 0xFF); |
| 129 str.appendUnichar((t >> 0) & 0xFF); | 128 str.appendUnichar((t >> 0) & 0xFF); |
| 130 SkDebugf("[%d:%d] '%s'\n", ttcIndex, i, str.c_str()); | 129 SkDebugf("[%d:%d] '%s'\n", ttcIndex, i, str.c_str()); |
| 131 #endif | 130 #endif |
| 132 size_t size = SkFontStream::GetTableSize(stream, ttcIndex, array[i]); | 131 size_t size = SkFontStream::GetTableSize(stream, ttcIndex, array[i]); |
| 133 for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) { | 132 for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) { |
| 134 if (gKnownTableSizes[j].fTag == array[i]) { | 133 if (gKnownTableSizes[j].fTag == array[i]) { |
| 135 REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size); | 134 REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size); |
| 136 } | 135 } |
| 137 } | 136 } |
| 138 } | 137 } |
| 139 } | 138 } |
| 140 | 139 |
| 141 static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream) { | 140 static void test_fontstream(skiatest::Reporter* reporter) { |
| 141 SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream("/fonts/test.ttc")); |
| 142 if (!stream) { |
| 143 SkDebugf("Skipping FontHostTest::test_fontstream\n"); |
| 144 return; |
| 145 } |
| 146 |
| 142 int count = SkFontStream::CountTTCEntries(stream); | 147 int count = SkFontStream::CountTTCEntries(stream); |
| 143 #ifdef DUMP_TTC_TABLES | 148 #ifdef DUMP_TTC_TABLES |
| 144 SkDebugf("CountTTCEntries %d\n", count); | 149 SkDebugf("CountTTCEntries %d\n", count); |
| 145 #endif | 150 #endif |
| 146 for (int i = 0; i < count; ++i) { | 151 for (int i = 0; i < count; ++i) { |
| 147 test_fontstream(reporter, stream, i); | 152 test_fontstream(reporter, stream, i); |
| 148 } | 153 } |
| 149 } | 154 } |
| 150 | 155 |
| 151 static void test_fontstream(skiatest::Reporter* reporter) { | |
| 152 // This test cannot run if there is no resource path. | |
| 153 SkString resourcePath = GetResourcePath(); | |
| 154 if (resourcePath.isEmpty()) { | |
| 155 SkDebugf("Could not run fontstream test because resourcePath not specifi
ed."); | |
| 156 return; | |
| 157 } | |
| 158 SkString filename = SkOSPath::Join(resourcePath.c_str(), "test.ttc"); | |
| 159 | |
| 160 SkFILEStream stream(filename.c_str()); | |
| 161 if (stream.isValid()) { | |
| 162 test_fontstream(reporter, &stream); | |
| 163 } else { | |
| 164 SkDebugf("Could not run fontstream test because test.ttc not found."); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) { | 156 static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) { |
| 169 if (false) { // avoid bit rot, suppress warning | 157 if (false) { // avoid bit rot, suppress warning |
| 170 SkFontID fontID = face->uniqueID(); | 158 SkFontID fontID = face->uniqueID(); |
| 171 REPORTER_ASSERT(reporter, fontID); | 159 REPORTER_ASSERT(reporter, fontID); |
| 172 } | 160 } |
| 173 | 161 |
| 174 int count = face->countTables(); | 162 int count = face->countTables(); |
| 175 | 163 |
| 176 SkAutoTMalloc<SkFontTableTag> storage(count); | 164 SkAutoTMalloc<SkFontTableTag> storage(count); |
| 177 SkFontTableTag* tags = storage.get(); | 165 SkFontTableTag* tags = storage.get(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 291 } |
| 304 } | 292 } |
| 305 | 293 |
| 306 DEF_TEST(FontHost, reporter) { | 294 DEF_TEST(FontHost, reporter) { |
| 307 test_tables(reporter); | 295 test_tables(reporter); |
| 308 test_fontstream(reporter); | 296 test_fontstream(reporter); |
| 309 test_advances(reporter); | 297 test_advances(reporter); |
| 310 } | 298 } |
| 311 | 299 |
| 312 // need tests for SkStrSearch | 300 // need tests for SkStrSearch |
| OLD | NEW |