Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FontScanner.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
10#include "src/core/SkTHash.h"
12#include "tests/Test.h"
13#include "tools/Resources.h"
15
16#ifdef SK_TYPEFACE_FACTORY_FREETYPE
18#endif
19#ifdef SK_TYPEFACE_FACTORY_FONTATIONS
21#endif
22
23[[maybe_unused]]
25 SkFontScanner* scanner,
26 bool defaultInstanceOnly) {
27 SkString name = GetResourcePath("fonts/Variable.ttf");
28
29 std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(name.c_str());
30 if (!stream) {
31 REPORTER_ASSERT(reporter, false, "Cannot open the font file %s\n", name.c_str());
32 }
33
34 int numFaces;
35 if (!scanner->scanFile(stream.get(), &numFaces)) {
36 REPORTER_ASSERT(reporter, false, "Cannot scanFile\n");
37 }
38 REPORTER_ASSERT(reporter, numFaces == 1);
39
41 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
42 int numInstances;
43 if (!scanner->scanFace(stream.get(), faceIndex, &numInstances)) {
44 REPORTER_ASSERT(reporter, false, "Cannot scanFace\n");
45 continue;
46 }
47 if (defaultInstanceOnly) {
48 REPORTER_ASSERT(reporter, numInstances == 1);
49 continue;
50 }
51 REPORTER_ASSERT(reporter, numInstances == 5);
52 for (int instanceIndex = 1; instanceIndex <= numInstances; ++instanceIndex) {
53 bool isFixedPitch;
54 SkString realname;
55 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
56 if (!scanner->scanInstance(stream.get(),
57 faceIndex,
58 instanceIndex,
59 &realname,
60 &style,
61 &isFixedPitch,
62 nullptr)) {
64 false,
65 "Cannot scanInstance %s %d\n",
66 name.c_str(),
67 faceIndex);
68 continue;
69 } else {
70 if (uniqueStyles.find(style) == nullptr) {
71 uniqueStyles.add(style);
72 } else {
75 false,
76 "Font: %s (%d %d %d)\n",
77 realname.c_str(), style.weight(), style.width(), style.slant());
78 }
79 }
80 }
81 REPORTER_ASSERT(reporter, uniqueStyles.count() == numInstances);
82 }
83}
84
85#ifdef SK_TYPEFACE_FACTORY_FREETYPE
86DEF_TEST(FontScanner_FreeType_VariableFont, reporter) {
87 SkFontScanner_FreeType free_type;
88 FontScanner_VariableFont(reporter, &free_type, /*defaultInstanceOnly=*/ false);
89}
90#endif
91
92#ifdef SK_TYPEFACE_FACTORY_FONTATIONS
93DEF_TEST(FontScanner_Fontations_VariableFont, reporter) {
94 SkFontScanner_Fontations fontations;
95 FontScanner_VariableFont(reporter, &fontations,/*defaultInstanceOnly=*/ true);
96}
97#endif
reporter
static void FontScanner_VariableFont(skiatest::Reporter *reporter, SkFontScanner *scanner, bool defaultInstanceOnly)
SkString GetResourcePath(const char *resource)
Definition Resources.cpp:23
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
virtual bool scanFace(SkStreamAsset *stream, int faceIndex, int *numInstances) const =0
virtual bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const =0
virtual bool scanFile(SkStreamAsset *stream, int *numFaces) const =0
Slant slant() const
Definition SkFontStyle.h:64
int width() const
Definition SkFontStyle.h:63
int weight() const
Definition SkFontStyle.h:62
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
Definition SkStream.cpp:922
const char * c_str() const
Definition SkString.h:133
int count() const
Definition SkTHash.h:564
const T * find(const T &item) const
Definition SkTHash.h:580
void add(T item)
Definition SkTHash.h:573
const char * name
Definition fuchsia.cc:50