blob: 2b8365849eadd27c54799f2edf41ab5d0ccc93d3 [file] [log] [blame]
reed@google.com17aa07d2012-02-23 14:51:10 +00001/*
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
8#include "Test.h"
9#include "SkTypeface.h"
10#include "SkFontHost.h"
11
12//#define DUMP_TABLES
13
14#define kFontTableTag_head SkSetFourByteTag('h', 'e', 'a', 'd')
15#define kFontTableTag_hhea SkSetFourByteTag('h', 'h', 'e', 'a')
reed@google.com17aa07d2012-02-23 14:51:10 +000016#define kFontTableTag_maxp SkSetFourByteTag('m', 'a', 'x', 'p')
17
18static const struct TagSize {
19 SkFontTableTag fTag;
20 size_t fSize;
21} gKnownTableSizes[] = {
22 { kFontTableTag_head, 54 },
23 { kFontTableTag_hhea, 36 },
reed@google.com17aa07d2012-02-23 14:51:10 +000024 { kFontTableTag_maxp, 32 },
25};
26
27static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
28 SkFontID fontID = face->uniqueID();
29
30 int count = SkFontHost::CountTables(fontID);
reed@google.com17aa07d2012-02-23 14:51:10 +000031
32 SkAutoTMalloc<SkFontTableTag> storage(count);
33 SkFontTableTag* tags = storage.get();
34 SkFontHost::GetTableTags(fontID, tags);
35
36 for (int i = 0; i < count; ++i) {
37 size_t size = SkFontHost::GetTableSize(fontID, tags[i]);
38 REPORTER_ASSERT(reporter, size > 0);
39
40#ifdef DUMP_TABLES
41 char name[5];
42 name[0] = (tags[i] >> 24) & 0xFF;
43 name[1] = (tags[i] >> 16) & 0xFF;
44 name[2] = (tags[i] >> 8) & 0xFF;
45 name[3] = (tags[i] >> 0) & 0xFF;
46 name[4] = 0;
47 SkDebugf("%s %d\n", name, size);
48#endif
49
50 for (size_t j = 0; j < SK_ARRAY_COUNT(gKnownTableSizes); ++j) {
51 if (gKnownTableSizes[j].fTag == tags[i]) {
52 REPORTER_ASSERT(reporter, gKnownTableSizes[j].fSize == size);
53 }
54 }
55 }
56}
57
58static void test_tables(skiatest::Reporter* reporter) {
59 static const char* const gNames[] = {
60 NULL, // default font
61 "Arial", "Times", "Times New Roman", "Helvetica", "Courier",
62 "Courier New",
63 };
64
65 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
66 SkTypeface* face = SkTypeface::CreateFromName(gNames[i],
67 SkTypeface::kNormal);
68 if (face) {
69#ifdef DUMP_TABLES
70 SkDebugf("%s\n", gNames[i]);
71#endif
72 test_tables(reporter, face);
73 face->unref();
74 }
75 }
76}
77
78static void TestFontHost(skiatest::Reporter* reporter) {
79 test_tables(reporter);
80}
81
82// need tests for SkStrSearch
83
84#include "TestClassDef.h"
85DEFINE_TESTCLASS("FontHost", FontHostTestClass, TestFontHost)