8#include <unordered_map>
25class RecordMatchFamilyStyleSkFontMgr :
public SkFontMgr {
27 const SkFontStyle* styleRequestedWhenMatchingFamily(
const char* family)
const {
28 auto s = fStyleRequestedWhenMatchingFamily.find(family);
29 return s != fStyleRequestedWhenMatchingFamily.end() ? &
s->second :
nullptr;
41 fStyleRequestedWhenMatchingFamily[family] = style;
45 const char* bcp47[],
int bcp47Count,
47 fStyleRequestedWhenMatchingFamily[familyName] = style;
55 int ttcIndex)
const override {
70 mutable std::unordered_map<std::string, SkFontStyle> fStyleRequestedWhenMatchingFamily;
78 static constexpr char json[] =
88 { "fName" : "f1", "fFamily": "f1", "fStyle" : "Regular" },
89 { "fName" : "f2", "fFamily": "f2", "fStyle" : "Medium" },
90 { "fName" : "f3", "fFamily": "f3", "fStyle" : "Bold" },
91 { "fName" : "f4", "fFamily": "f4", "fStyle" : "Light" },
92 { "fName" : "f5", "fFamily": "f5", "fStyle" : "Extra" },
93 { "fName" : "f6", "fFamily": "f6", "fStyle" : "ExtraBold" },
95 { "fName" : "f7" , "fFamily": "f7" , "fStyle" : "Regular Italic" },
96 { "fName" : "f8" , "fFamily": "f8" , "fStyle" : "Medium Italic" },
97 { "fName" : "f9" , "fFamily": "f9" , "fStyle" : "Bold Italic" },
98 { "fName" : "f10", "fFamily": "f10", "fStyle" : "Light Oblique" },
99 { "fName" : "f11", "fFamily": "f11", "fStyle" : "Extra Oblique" },
100 { "fName" : "f12", "fFamily": "f12", "fStyle" : "Extrabold Oblique" },
102 { "fName" : "f13", "fFamily": "f13", "fStyle" : "Italic" },
103 { "fName" : "f14", "fFamily": "f14", "fStyle" : "Oblique" },
104 { "fName" : "f15", "fFamily": "f15", "fStyle" : "" }
110 auto fmgr = sk_make_sp<RecordMatchFamilyStyleSkFontMgr>();
113 .setFontManager(fmgr)
119 static constexpr struct {
143 for (
const auto& exp : expected) {
144 const auto* style = fmgr->styleRequestedWhenMatchingFamily(exp.family);
151DEF_TEST(Skottie_Text_LayoutError, r) {
159 static constexpr char json[] =
199 const std::vector<SkString>&
errors()
const {
return fErrors; }
202 void log(Level lvl,
const char message[],
const char* =
nullptr)
override {
208 std::vector<SkString> fErrors;
219 auto logger = sk_make_sp<Logger>();
223 .setResourceProvider(sk_make_sp<PortableRP>())
231DEF_TEST(Skottie_Text_FontFamily, r) {
232 static constexpr char json[] =
242 "fFamily": "family_1",
272 const std::unique_ptr<TextPropertyHandle>&
text()
const {
return fText; }
276 const LazyHandle<TextPropertyHandle>& lh)
override {
280 std::unique_ptr<TextPropertyHandle> fText;
283 auto fmgr = sk_make_sp<RecordMatchFamilyStyleSkFontMgr>();
284 auto prop_observer = sk_make_sp<TextObserver>();
288 .setFontManager(fmgr)
289 .setPropertyObserver(prop_observer)
295 const auto* style1 = fmgr->styleRequestedWhenMatchingFamily(
"family_1");
298 const auto& text_handle = prop_observer->text();
300 auto txt = (*text_handle).get();
301 txt.fFontFamily =
"family_2";
305 const auto* style2 = fmgr->styleRequestedWhenMatchingFamily(
"family_2");
#define REPORTER_ASSERT(r, cond,...)
virtual void onGetFamilyName(int index, SkString *familyName) const =0
virtual sk_sp< SkTypeface > onMakeFromData(sk_sp< SkData >, int ttcIndex) const =0
virtual sk_sp< SkFontStyleSet > onCreateStyleSet(int index) const =0
virtual sk_sp< SkTypeface > onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const =0
virtual sk_sp< SkFontStyleSet > onMatchFamily(const char familyName[]) const =0
virtual sk_sp< SkTypeface > onMakeFromStreamIndex(std::unique_ptr< SkStreamAsset >, int ttcIndex) const =0
virtual sk_sp< SkTypeface > onMakeFromStreamArgs(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const =0
virtual sk_sp< SkTypeface > onMatchFamilyStyle(const char familyName[], const SkFontStyle &) const =0
virtual sk_sp< SkTypeface > onLegacyMakeTypeface(const char familyName[], SkFontStyle) const =0
virtual sk_sp< SkTypeface > onMakeFromFile(const char path[], int ttcIndex) const =0
virtual int onCountFamilies() const =0
virtual void onTextProperty(const char node_name[], const LazyHandle< TextPropertyHandle > &)
virtual sk_sp< SkTypeface > loadTypeface(const char[], const char[]) const
sk_sp< Factory > BestAvailable()
DlVertices::Builder Builder
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_TEST(Skottie_Text_Style, r)