22#include <fontconfig/fontconfig.h>
29FcConfig* build_fontconfig_with_fontfile(
const char* fontFilename) {
30 FcConfig* config = FcConfigCreate();
33 FcConfigSetSysRoot(config,
reinterpret_cast<const FcChar8*
>(
GetResourcePath(
"").c_str()));
35 SkString fontFilePath(
reinterpret_cast<const char*
>(FcConfigGetSysRoot(config)));
36 fontFilePath += fontFilename;
37 FcConfigAppFontAddFile(config,
reinterpret_cast<const FcChar8*
>(fontFilePath.c_str()));
39 FcConfigBuildFonts(config);
43bool fontmgr_understands_ft_named_instance_bits() {
52 params.setCollectionIndex(0x00010000);
60 if (!fontmgr_understands_ft_named_instance_bits()) {
64 FcConfig* config = build_fontconfig_with_fontfile(
"/fonts/NotoSansCJK-VF-subset.otf.ttc");
67 static constexpr const char* family_names[]{
"Noto Sans CJK JP",
72 static constexpr const struct Test {
74 bool highBitsExpectation;
85 for (
auto&& font_name : family_names) {
86 for (
auto&& [weight, highBitsExpectation] :
tests) {
92 const bool r = fciDirect->matchFamilyName(
93 font_name, fontStyle, &resultIdentity, &resultFamily, &resultStyle);
98 (resultIdentity.
fTTCIndex >> 16 > 0) == highBitsExpectation,
99 "Expected to have the ttcIndex' upper 16 bits refer to a named instance.");
108 ERRORF(
reporter,
"Could not instantiate typeface, FcVersion: %d", FcGetVersion());
116 family_from_typeface ==
SkString(font_name),
117 "Matched font's family name should match the request.");
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",
128 family_from_typeface.
c_str());
132 std::vector<SkFontArguments::VariationPosition::Coordinate> coords;
133 coords.resize(numAxes);
138 "The font must only have one axis, the weight axis.");
142 "The weight axis must be present and configured.");
145 static_cast<int>(coords[0].
value) == weight,
146 "The weight axis must match the weight from the request.");
DEF_TEST(FontConfigInterface_MatchStyleNamedInstance, reporter)
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
SkString GetResourcePath(const char *resource)
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
#define REPORTER_ASSERT(r, cond,...)
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
const char * c_str() const
void getFamilyName(SkString *name) const
SkFontStyle fontStyle() const
int getVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const
const EmbeddedViewParams * params