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

Side by Side Diff: tests/FontHostTest.cpp

Issue 22859070: Implement charToGlyph on remaining ports. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 "Test.h" 8 #include "Test.h"
9 #include "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkFontStream.h" 10 #include "SkFontStream.h"
11 #include "SkOSFile.h"
11 #include "SkStream.h" 12 #include "SkStream.h"
12 #include "SkTypeface.h" 13 #include "SkTypeface.h"
13 #include "SkEndian.h" 14 #include "SkEndian.h"
14 15
15 //#define DUMP_TABLES 16 //#define DUMP_TABLES
16 //#define DUMP_TTC_TABLES 17 //#define DUMP_TTC_TABLES
17 18
18 #define kFontTableTag_head SkSetFourByteTag('h', 'e', 'a', 'd') 19 #define kFontTableTag_head SkSetFourByteTag('h', 'e', 'a', 'd')
19 #define kFontTableTag_hhea SkSetFourByteTag('h', 'h', 'e', 'a') 20 #define kFontTableTag_hhea SkSetFourByteTag('h', 'h', 'e', 'a')
20 #define kFontTableTag_maxp SkSetFourByteTag('m', 'a', 'x', 'p') 21 #define kFontTableTag_maxp SkSetFourByteTag('m', 'a', 'x', 'p')
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 66 }
66 67
67 if (tableGlyphs >= 0) { 68 if (tableGlyphs >= 0) {
68 REPORTER_ASSERT(reporter, tableGlyphs == nativeGlyphs); 69 REPORTER_ASSERT(reporter, tableGlyphs == nativeGlyphs);
69 } else { 70 } else {
70 // not sure this is a bug, but lets report it for now as info. 71 // not sure this is a bug, but lets report it for now as info.
71 SkDebugf("--- typeface returned 0 glyphs [%X]\n", face->uniqueID()); 72 SkDebugf("--- typeface returned 0 glyphs [%X]\n", face->uniqueID());
72 } 73 }
73 } 74 }
74 75
76 // Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs.
77 static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
78 const char text[5] = "ABCD";
79 const size_t textLength = SK_ARRAY_COUNT(text)-1;
80
81 uint16_t paintGlyphIds[textLength];
82 SkPaint paint;
83 paint.setTypeface(face);
84 paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
85 paint.textToGlyphs(text, textLength, paintGlyphIds);
86
87 uint16_t faceGlyphIds[textLength];
88 face->charsToGlyphs(text, SkTypeface::kUTF8_Encoding, faceGlyphIds, textLeng th);
89
90 for (size_t i = 0; i < textLength; ++i) {
91 SkString name;
92 face->getFamilyName(&name);
93 SkString a;
94 a.appendf("paintGlyphIds[%d] = %d, faceGlyphIds[%d] = %d, name = %s",
95 (int)i, (int)paintGlyphIds[i], (int)i, (int)faceGlyphIds[i ], name.c_str());
96 REPORTER_ASSERT_MESSAGE(reporter, paintGlyphIds[i] == faceGlyphIds[i], a .c_str());
97 }
98 }
99
75 static void test_fontstream(skiatest::Reporter* reporter, 100 static void test_fontstream(skiatest::Reporter* reporter,
76 SkStream* stream, int ttcIndex) { 101 SkStream* stream, int ttcIndex) {
77 int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL); 102 int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL);
78 SkAutoTArray<SkFontTableTag> array(n); 103 SkAutoTArray<SkFontTableTag> array(n);
79 104
80 int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get()); 105 int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get());
81 REPORTER_ASSERT(reporter, n == n2); 106 REPORTER_ASSERT(reporter, n == n2);
82 107
83 for (int i = 0; i < n; ++i) { 108 for (int i = 0; i < n; ++i) {
84 #ifdef DUMP_TTC_TABLES 109 #ifdef DUMP_TTC_TABLES
(...skipping 18 matching lines...) Expand all
103 int count = SkFontStream::CountTTCEntries(stream); 128 int count = SkFontStream::CountTTCEntries(stream);
104 #ifdef DUMP_TTC_TABLES 129 #ifdef DUMP_TTC_TABLES
105 SkDebugf("CountTTCEntries %d\n", count); 130 SkDebugf("CountTTCEntries %d\n", count);
106 #endif 131 #endif
107 for (int i = 0; i < count; ++i) { 132 for (int i = 0; i < count; ++i) {
108 test_fontstream(reporter, stream, i); 133 test_fontstream(reporter, stream, i);
109 } 134 }
110 } 135 }
111 136
112 static void test_fontstream(skiatest::Reporter* reporter) { 137 static void test_fontstream(skiatest::Reporter* reporter) {
113 // TODO: replace when we get a tools/resources/fonts/test.ttc 138 // This test cannot run if there is no resource path.
114 const char* name = "/AmericanTypewriter.ttc"; 139 SkString resourcePath = skiatest::Test::GetResourcePath();
115 SkFILEStream stream(name); 140 if (resourcePath.isEmpty()) {
141 SkDebugf("Could not run fontstream test because resourcePath not specifi ed.");
142 return;
143 }
144 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "test.ttc");
145
146 SkFILEStream stream(filename.c_str());
116 if (stream.isValid()) { 147 if (stream.isValid()) {
117 test_fontstream(reporter, &stream); 148 test_fontstream(reporter, &stream);
149 } else {
150 SkDebugf("Could not run fontstream test because test.ttc not found.");
118 } 151 }
119 } 152 }
120 153
121 static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) { 154 static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
122 if (false) { // avoid bit rot, suppress warning 155 if (false) { // avoid bit rot, suppress warning
123 SkFontID fontID = face->uniqueID(); 156 SkFontID fontID = face->uniqueID();
124 REPORTER_ASSERT(reporter, fontID); 157 REPORTER_ASSERT(reporter, fontID);
125 } 158 }
126 159
127 int count = face->countTables(); 160 int count = face->countTables();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 195 }
163 196
164 static void test_tables(skiatest::Reporter* reporter) { 197 static void test_tables(skiatest::Reporter* reporter) {
165 static const char* const gNames[] = { 198 static const char* const gNames[] = {
166 NULL, // default font 199 NULL, // default font
167 "Arial", "Times", "Times New Roman", "Helvetica", "Courier", 200 "Arial", "Times", "Times New Roman", "Helvetica", "Courier",
168 "Courier New", "Terminal", "MS Sans Serif", 201 "Courier New", "Terminal", "MS Sans Serif",
169 }; 202 };
170 203
171 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { 204 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
172 SkTypeface* face = SkTypeface::CreateFromName(gNames[i], 205 SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTy peface::kNormal));
173 SkTypeface::kNormal);
174 if (face) { 206 if (face) {
175 #ifdef DUMP_TABLES 207 #ifdef DUMP_TABLES
176 SkDebugf("%s\n", gNames[i]); 208 SkDebugf("%s\n", gNames[i]);
177 #endif 209 #endif
178 test_tables(reporter, face); 210 test_tables(reporter, face);
179 test_unitsPerEm(reporter, face); 211 test_unitsPerEm(reporter, face);
180 test_countGlyphs(reporter, face); 212 test_countGlyphs(reporter, face);
181 face->unref(); 213 test_charsToGlyphs(reporter, face);
182 } 214 }
183 } 215 }
184 } 216 }
185 217
186 /* 218 /*
187 * Verifies that the advance values returned by generateAdvance and 219 * Verifies that the advance values returned by generateAdvance and
188 * generateMetrics match. 220 * generateMetrics match.
189 */ 221 */
190 static void test_advances(skiatest::Reporter* reporter) { 222 static void test_advances(skiatest::Reporter* reporter) {
191 static const char* const faces[] = { 223 static const char* const faces[] = {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 static void TestFontHost(skiatest::Reporter* reporter) { 289 static void TestFontHost(skiatest::Reporter* reporter) {
258 test_tables(reporter); 290 test_tables(reporter);
259 test_fontstream(reporter); 291 test_fontstream(reporter);
260 test_advances(reporter); 292 test_advances(reporter);
261 } 293 }
262 294
263 // need tests for SkStrSearch 295 // need tests for SkStrSearch
264 296
265 #include "TestClassDef.h" 297 #include "TestClassDef.h"
266 DEFINE_TESTCLASS("FontHost", FontHostTestClass, TestFontHost) 298 DEFINE_TESTCLASS("FontHost", FontHostTestClass, TestFontHost)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698