Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FontNamesTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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
16#include "src/base/SkEndian.h"
18#include "tests/Test.h"
21
22#include <algorithm>
23#include <cstddef>
24#include <cstdint>
25#include <cstring>
26
27using namespace skia_private;
28
29namespace {
30
31template <size_t R, size_t D> struct Format0NameTable {
33 SkOTTableName::Record nameRecord[R];
34 char data[D];
35};
36
37template <size_t R, size_t L, size_t D> struct Format1NameTable {
39 SkOTTableName::Record nameRecord[R];
40 struct {
43 } format1ext;
44 char data[D];
45};
46
47typedef Format0NameTable<1, 9> SimpleFormat0NameTable;
48constexpr SimpleFormat0NameTable simpleFormat0NameTable = {
49 /*header*/ {
50 /*format*/ SkOTTableName::format_0,
52 /*stringOffset*/ SkTEndianSwap16<offsetof(SimpleFormat0NameTable, data)>::value,
53 },
54 /*nameRecord[]*/ {
55 /*Record*/ {
62 }
63 },
64 /*data*/ "\x0" "T" "\x0" "e" "\x0" "s" "\x0" "t",
65};
66
67typedef Format1NameTable<1, 1, 19> SimpleFormat1NameTable;
68constexpr SimpleFormat1NameTable simpleFormat1NameTable = {
69 /*header*/ {
70 /*format*/ SkOTTableName::format_1,
72 /*stringOffset*/ SkTEndianSwap16<offsetof(SimpleFormat1NameTable, data)>::value,
73 },
74 /*nameRecord[]*/ {
75 /*Record*/ {
78 /*languageID*/ { SkTEndianSwap16<0x8000 + 0>::value },
82 }
83 },
84 /*format1ext*/ {
85 /*header*/ {
86 /*langTagCount*/ SkTEndianSwap16<1>::value,
87 },
88 /*langTagRecord[]*/ {
89 /*LangTagRecord*/ {
92 },
93 },
94 },
95 /*data*/ "\x0" "T" "\x0" "e" "\x0" "s" "\x0" "t"
96 "\x0" "e" "\x0" "n" "\x0" "-" "\x0" "U" "\x0" "S",
97};
98
99struct FontNamesTest {
100 const uint8_t* data;
101 size_t size;
103 size_t nameCount;
104 struct {
105 const char* name;
106 const char* language;
107 } names[10];
108
109} tests[] = {
110 {
111 reinterpret_cast<const uint8_t*>(&simpleFormat0NameTable),
112 sizeof(simpleFormat0NameTable),
114 1,
115 {
116 { "Test", "en-US" },
117 },
118 },
119 {
120 reinterpret_cast<const uint8_t*>(&simpleFormat1NameTable),
121 sizeof(simpleFormat1NameTable),
123 1,
124 {
125 { "Test", "en-US" },
126 },
127 },
128};
129
130static void test_synthetic(skiatest::Reporter* reporter, bool verbose) {
131 for (const auto& test : tests) {
132 SkOTTableName::Iterator iter(test.data, test.size, test.nameID.predefined.value);
134 size_t nameIndex = 0;
135 while (nameIndex < test.nameCount && iter.next(record)) {
137 strcmp(test.names[nameIndex].name, record.name.c_str()) == 0,
138 "Name did not match.");
139
141 strcmp(test.names[nameIndex].language, record.language.c_str()) == 0,
142 "Language did not match.");
143
144 if (verbose) {
145 SkDebugf("%s <%s>\n", record.name.c_str(), record.language.c_str());
146 }
147
148 ++nameIndex;
149 }
150
151 REPORTER_ASSERT(reporter, nameIndex == test.nameCount, "Fewer names than expected.");
152
153 REPORTER_ASSERT(reporter, !iter.next(record), "More names than expected.");
154 }
155}
156
157#define MAX_FAMILIES 1000
158static void test_systemfonts(skiatest::Reporter* reporter, bool verbose) {
159 static const SkFontTableTag nameTag = SkSetFourByteTag('n','a','m','e');
160
163 int count = std::min(fm->countFamilies(), MAX_FAMILIES);
164 for (int i = 0; i < count; ++i) {
165 sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
166 for (int j = 0; j < set->count(); ++j) {
167 SkString sname;
168 SkFontStyle fs;
169 set->getStyle(j, &fs, &sname);
170
171 sk_sp<SkTypeface> typeface(set->createTypeface(j));
172
173 SkString familyName;
174 typeface->getFamilyName(&familyName);
175 if (verbose) {
176 SkDebugf("[%s]\n", familyName.c_str());
177 }
178
180 typeface->createFamilyNameIterator());
181 SkTypeface::LocalizedString familyNameLocalized;
182 while (familyNamesIter->next(&familyNameLocalized)) {
183 if (verbose) {
184 SkDebugf("(%s) <%s>\n", familyNameLocalized.fString.c_str(),
185 familyNameLocalized.fLanguage.c_str());
186 }
187 }
188
189 size_t nameTableSize = typeface->getTableSize(nameTag);
190 if (0 == nameTableSize) {
191 continue;
192 }
193 AutoTMalloc<uint8_t> nameTableData(nameTableSize);
194 size_t copied = typeface->getTableData(nameTag, 0, nameTableSize, nameTableData.get());
195 if (copied != nameTableSize) {
196 continue;
197 }
198
200 SkOTTableName::Iterator familyNameIter(nameTableData.get(), nameTableSize,
202 while (familyNameIter.next(record)) {
204 reporter,
206 "Requested family name, got something else.");
207 if (verbose) {
208 SkDebugf("{%s} <%s>\n", record.name.c_str(), record.language.c_str());
209 }
210 }
211
212 SkOTTableName::Iterator styleNameIter(nameTableData.get(), nameTableSize,
214 while (styleNameIter.next(record)) {
216 reporter,
218 "Requested subfamily name, got something else.");
219 if (verbose) {
220 SkDebugf("{{%s}} <%s>\n", record.name.c_str(), record.language.c_str());
221 }
222 }
223
224 if (verbose) {
225 SkDebugf("\n");
226 }
227 }
228 }
229}
230
231} // namespace
232
233static DEFINE_bool(verboseFontNames, false, "verbose FontNames test.");
234
235DEF_TEST(FontNames, reporter) {
236 test_synthetic(reporter, FLAGS_verboseFontNames);
237 test_systemfonts(reporter, FLAGS_verboseFontNames);
238}
static BlurTest tests[]
Definition BlurTest.cpp:84
#define DEFINE_bool(name, defaultValue, helpString)
reporter
int count
#define MAX_FAMILIES
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
uint32_t SkFontTableTag
Definition SkTypeface.h:41
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition SkTypes.h:167
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
const char * c_str() const
Definition SkString.h:133
const char * name
Definition fuchsia.cc:50
#define R(r)
sk_sp< SkFontMgr > TestFontMgr()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
static const SK_OT_USHORT format_0
static const SK_OT_USHORT format_1