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

Side by Side Diff: tests/FontHostTest.cpp

Issue 19231003: Implement onCountGlyphs and onGetUPEM on Windows. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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"
(...skipping 11 matching lines...) Expand all
22 static const struct TagSize { 22 static const struct TagSize {
23 SkFontTableTag fTag; 23 SkFontTableTag fTag;
24 size_t fSize; 24 size_t fSize;
25 } gKnownTableSizes[] = { 25 } gKnownTableSizes[] = {
26 { kFontTableTag_head, 54 }, 26 { kFontTableTag_head, 54 },
27 { kFontTableTag_hhea, 36 }, 27 { kFontTableTag_hhea, 36 },
28 { kFontTableTag_maxp, 32 }, 28 { kFontTableTag_maxp, 32 },
29 }; 29 };
30 30
31 // Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table 31 // Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table
32 // (if that table is available. 32 // (if that table is available).
33 static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) { 33 static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) {
34 int nativeUPEM = face->getUnitsPerEm();; 34 int nativeUPEM = face->getUnitsPerEm();
35 35
36 int tableUPEM = -1; 36 int tableUPEM = -1;
37 size_t size = face->getTableSize(kFontTableTag_head); 37 size_t size = face->getTableSize(kFontTableTag_head);
38 if (size) { 38 if (size) {
vandebo (ex-Chrome) 2013/07/15 17:32:56 Do you want to check that size >= 20 ?
bungeman-skia 2013/07/15 18:21:36 Already did that in test_tables.
39 SkAutoMalloc storage(size);
40 char* ptr = (char*)storage.get();
41 face->getTableData(kFontTableTag_head, 0, size, ptr);
42 // unitsPerEm is at offset 18 into the 'head' table. 39 // unitsPerEm is at offset 18 into the 'head' table.
43 tableUPEM = SkEndian_SwapBE16(*(uint16_t*)&ptr[18]); 40 uint16_t rawUPEM;
41 face->getTableData(kFontTableTag_head, 18, sizeof(rawUPEM), &rawUPEM);
42 tableUPEM = SkEndian_SwapBE16(rawUPEM);
44 } 43 }
45 // SkDebugf("--- typeface returned %d upem [%X]\n", nativeUPEM, face->uniqueI D());
46 44
47 if (tableUPEM >= 0) { 45 if (tableUPEM >= 0) {
48 REPORTER_ASSERT(reporter, tableUPEM == nativeUPEM); 46 REPORTER_ASSERT(reporter, tableUPEM == nativeUPEM);
49 } else { 47 } else {
50 // not sure this is a bug, but lets report it for now as info. 48 // not sure this is a bug, but lets report it for now as info.
51 SkDebugf("--- typeface returned 0 upem [%X]\n", face->uniqueID()); 49 SkDebugf("--- typeface returned 0 upem [%X]\n", face->uniqueID());
52 } 50 }
53 } 51 }
54 52
53 // Test that countGlyphs() agrees with a direct lookup in the 'maxp' table
54 // (if that table is available).
55 static void test_countGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
56 int nativeGlyphs = face->countGlyphs();
57
58 int tableGlyphs = -1;
59 size_t size = face->getTableSize(kFontTableTag_maxp);
60 if (size) {
vandebo (ex-Chrome) 2013/07/15 17:32:56 size >= 6 ?
bungeman-skia 2013/07/15 18:21:36 Already did that in test_tables.
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);
69 } else {
70 // 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 }
73 }
74
55 static void test_fontstream(skiatest::Reporter* reporter, 75 static void test_fontstream(skiatest::Reporter* reporter,
56 SkStream* stream, int ttcIndex) { 76 SkStream* stream, int ttcIndex) {
57 int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL); 77 int n = SkFontStream::GetTableTags(stream, ttcIndex, NULL);
58 SkAutoTArray<SkFontTableTag> array(n); 78 SkAutoTArray<SkFontTableTag> array(n);
59 79
60 int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get()); 80 int n2 = SkFontStream::GetTableTags(stream, ttcIndex, array.get());
61 REPORTER_ASSERT(reporter, n == n2); 81 REPORTER_ASSERT(reporter, n == n2);
62 82
63 for (int i = 0; i < n; ++i) { 83 for (int i = 0; i < n; ++i) {
64 #ifdef DUMP_TTC_TABLES 84 #ifdef DUMP_TTC_TABLES
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 170
151 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { 171 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
152 SkTypeface* face = SkTypeface::CreateFromName(gNames[i], 172 SkTypeface* face = SkTypeface::CreateFromName(gNames[i],
153 SkTypeface::kNormal); 173 SkTypeface::kNormal);
154 if (face) { 174 if (face) {
155 #ifdef DUMP_TABLES 175 #ifdef DUMP_TABLES
156 SkDebugf("%s\n", gNames[i]); 176 SkDebugf("%s\n", gNames[i]);
157 #endif 177 #endif
158 test_tables(reporter, face); 178 test_tables(reporter, face);
159 test_unitsPerEm(reporter, face); 179 test_unitsPerEm(reporter, face);
180 test_countGlyphs(reporter, face);
160 face->unref(); 181 face->unref();
161 } 182 }
162 } 183 }
163 } 184 }
164 185
165 /* 186 /*
166 * Verifies that the advance values returned by generateAdvance and 187 * Verifies that the advance values returned by generateAdvance and
167 * generateMetrics match. 188 * generateMetrics match.
168 */ 189 */
169 static void test_advances(skiatest::Reporter* reporter) { 190 static void test_advances(skiatest::Reporter* reporter) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 static void TestFontHost(skiatest::Reporter* reporter) { 257 static void TestFontHost(skiatest::Reporter* reporter) {
237 test_tables(reporter); 258 test_tables(reporter);
238 test_fontstream(reporter); 259 test_fontstream(reporter);
239 test_advances(reporter); 260 test_advances(reporter);
240 } 261 }
241 262
242 // need tests for SkStrSearch 263 // need tests for SkStrSearch
243 264
244 #include "TestClassDef.h" 265 #include "TestClassDef.h"
245 DEFINE_TESTCLASS("FontHost", FontHostTestClass, TestFontHost) 266 DEFINE_TESTCLASS("FontHost", FontHostTestClass, TestFontHost)
OLDNEW
« src/ports/SkFontHost_win.cpp ('K') | « src/ports/SkFontHost_win_dw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698