Flutter Engine
The Flutter Engine
Functions
FCITest.cpp File Reference
#include "include/core/SkFontArguments.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/ports/SkFontConfigInterface.h"
#include "src/ports/SkFontConfigInterface_direct.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include "tools/fonts/FontToolUtils.h"
#include <fontconfig/fontconfig.h>
#include <memory>
#include <utility>
#include <vector>

Go to the source code of this file.

Functions

 DEF_TEST (FontConfigInterface_MatchStyleNamedInstance, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( FontConfigInterface_MatchStyleNamedInstance  ,
reporter   
)

Definition at line 59 of file FCITest.cpp.

59 {
60 if (!fontmgr_understands_ft_named_instance_bits()) {
61 return;
62 }
63
64 FcConfig* config = build_fontconfig_with_fontfile("/fonts/NotoSansCJK-VF-subset.otf.ttc");
66
67 static constexpr const char* family_names[]{"Noto Sans CJK JP",
68 "Noto Sans CJK HK",
69 "Noto Sans CJK SC",
70 "Noto Sans CJK TC",
71 "Noto Sans CJK KR"};
72 static constexpr const struct Test {
73 int weight;
74 bool highBitsExpectation;
75 } tests[] {
76 {100, false},
77 {300, true },
78 {350, true },
79 {400, true },
80 {500, true },
81 {700, true },
82 {900, true },
83 };
84
85 for (auto&& font_name : family_names) {
86 for (auto&& [weight, highBitsExpectation] : tests) {
88
90 SkFontStyle resultStyle;
91 SkString resultFamily;
92 const bool r = fciDirect->matchFamilyName(
93 font_name, fontStyle, &resultIdentity, &resultFamily, &resultStyle);
94
95 REPORTER_ASSERT(reporter, r, "Expecting to find a match result.");
98 (resultIdentity.fTTCIndex >> 16 > 0) == highBitsExpectation,
99 "Expected to have the ttcIndex' upper 16 bits refer to a named instance.");
100
101 // Intentionally go through manually creating the typeface so that SkFontStyle is
102 // derived from data inside the font, not from the FcPattern that is the FontConfig
103 // match result, see https://crbug.com/skia/12881
104 sk_sp<SkTypeface> typeface(fciDirect->makeTypeface(resultIdentity,
105 ToolUtils::TestFontMgr()).release());
106
107 if (!typeface) {
108 ERRORF(reporter, "Could not instantiate typeface, FcVersion: %d", FcGetVersion());
109 return;
110 }
111
112 SkString family_from_typeface;
113 typeface->getFamilyName(&family_from_typeface);
114
116 family_from_typeface == SkString(font_name),
117 "Matched font's family name should match the request.");
118
119 SkFontStyle intrinsic_style = typeface->fontStyle();
121 intrinsic_style.weight() == weight,
122 "Matched font's weight should match request.");
123 if (intrinsic_style.weight() != weight) {
125 "Matched font had weight: %d, expected %d, family: %s",
126 intrinsic_style.weight(),
127 weight,
128 family_from_typeface.c_str());
129 }
130
131 int numAxes = typeface->getVariationDesignPosition(nullptr, 0);
132 std::vector<SkFontArguments::VariationPosition::Coordinate> coords;
133 coords.resize(numAxes);
134 typeface->getVariationDesignPosition(coords.data(), numAxes);
135
137 coords.size() == 1,
138 "The font must only have one axis, the weight axis.");
139
141 coords[0].axis == SkSetFourByteTag('w', 'g', 'h', 't'),
142 "The weight axis must be present and configured.");
143
145 static_cast<int>(coords[0].value) == weight,
146 "The weight axis must match the weight from the request.");
147 }
148 }
149
150}
static BlurTest tests[]
Definition: BlurTest.cpp:84
reporter
Definition: FontMgrTest.cpp:39
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
int weight() const
Definition: SkFontStyle.h:62
const char * c_str() const
Definition: SkString.h:133
uint8_t value
sk_sp< SkFontMgr > TestFontMgr()