xref: /aosp_15_r20/external/skia/src/ports/SkFontConfigTypeface.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 
8 #ifndef SkFontConfigTypeface_DEFINED
9 #define SkFontConfigTypeface_DEFINED
10 
11 #include "include/core/SkFontStyle.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkStream.h"
14 #include "include/ports/SkFontConfigInterface.h"
15 #include "src/core/SkFontDescriptor.h"
16 #include "src/ports/SkTypeface_FreeType.h"
17 
18 class SkFontDescriptor;
19 
20 class SkTypeface_FCI : public SkTypeface_FreeType {
21     sk_sp<SkFontConfigInterface> fFCI;
22     SkFontConfigInterface::FontIdentity fIdentity;
23     SkString fFamilyName;
24 
25 public:
Create(sk_sp<SkFontConfigInterface> fci,const SkFontConfigInterface::FontIdentity & fi,SkString familyName,const SkFontStyle & style)26     static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
27                                   const SkFontConfigInterface::FontIdentity& fi,
28                                   SkString familyName,
29                                   const SkFontStyle& style)
30     {
31         return new SkTypeface_FCI(std::move(fci), fi, std::move(familyName), style);
32     }
33 
getIdentity()34     const SkFontConfigInterface::FontIdentity& getIdentity() const {
35         return fIdentity;
36     }
37 
onMakeClone(const SkFontArguments & args)38     sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
39         SkFontStyle style = this->fontStyle();
40         std::unique_ptr<SkFontData> data = this->cloneFontData(args, &style);
41         if (!data) {
42             return nullptr;
43         }
44         return sk_sp<SkTypeface>(new SkTypeface_FreeTypeStream(
45             std::move(data), fFamilyName, style, this->isFixedPitch()));
46     }
47 
48 protected:
SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,const SkFontConfigInterface::FontIdentity & fi,SkString familyName,const SkFontStyle & style)49     SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
50                    const SkFontConfigInterface::FontIdentity& fi,
51                    SkString familyName,
52                    const SkFontStyle& style)
53             : INHERITED(style, false)
54             , fFCI(std::move(fci))
55             , fIdentity(fi)
56             , fFamilyName(std::move(familyName)) {}
57 
onGetFamilyName(SkString * familyName)58     void onGetFamilyName(SkString* familyName) const override { *familyName = fFamilyName; }
59     void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
60     std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
61     std::unique_ptr<SkFontData> onMakeFontData() const override;
62 
63 private:
64     using INHERITED = SkTypeface_FreeType;
65 };
66 
67 #endif  // SkFontConfigTypeface_DEFINED
68