• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "SkFontConfigInterface.h"
9 #include "SkFontDescriptor.h"
10 #include "SkFontHost_FreeType_common.h"
11 #include "SkRefCnt.h"
12 #include "SkStream.h"
13 
14 class SkFontDescriptor;
15 
16 class SkTypeface_FCI : public SkTypeface_FreeType {
17     sk_sp<SkFontConfigInterface> fFCI;
18     SkFontConfigInterface::FontIdentity fIdentity;
19     SkString fFamilyName;
20     std::unique_ptr<SkFontData> fFontData;
21 
22 public:
Create(sk_sp<SkFontConfigInterface> fci,const SkFontConfigInterface::FontIdentity & fi,SkString familyName,const SkFontStyle & style)23     static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
24                                   const SkFontConfigInterface::FontIdentity& fi,
25                                   SkString familyName,
26                                   const SkFontStyle& style)
27     {
28         return new SkTypeface_FCI(std::move(fci), fi, std::move(familyName), style);
29     }
30 
Create(std::unique_ptr<SkFontData> data,SkString familyName,SkFontStyle style,bool isFixedPitch)31     static SkTypeface_FCI* Create(std::unique_ptr<SkFontData> data,
32                                   SkString familyName, SkFontStyle style, bool isFixedPitch)
33     {
34         return new SkTypeface_FCI(std::move(data), std::move(familyName), style, isFixedPitch);
35     }
36 
getIdentity()37     const SkFontConfigInterface::FontIdentity& getIdentity() const {
38         return fIdentity;
39     }
40 
41 protected:
SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,const SkFontConfigInterface::FontIdentity & fi,SkString familyName,const SkFontStyle & style)42     SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
43                    const SkFontConfigInterface::FontIdentity& fi,
44                    SkString familyName,
45                    const SkFontStyle& style)
46             : INHERITED(style, false)
47             , fFCI(std::move(fci))
48             , fIdentity(fi)
49             , fFamilyName(std::move(familyName))
50             , fFontData(nullptr) {}
51 
SkTypeface_FCI(std::unique_ptr<SkFontData> data,SkString familyName,SkFontStyle style,bool isFixedPitch)52     SkTypeface_FCI(std::unique_ptr<SkFontData> data,
53                    SkString familyName, SkFontStyle style, bool isFixedPitch)
54             : INHERITED(style, isFixedPitch)
55             , fFamilyName(std::move(familyName))
56             , fFontData(std::move(data))
57     {
58         SkASSERT(fFontData);
59         fIdentity.fTTCIndex = fFontData->getIndex();
60     }
61 
onGetFamilyName(SkString * familyName)62     void onGetFamilyName(SkString* familyName) const override { *familyName = fFamilyName; }
63     void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
64     SkStreamAsset* onOpenStream(int* ttcIndex) const override;
65     std::unique_ptr<SkFontData> onMakeFontData() const override;
66 
67 private:
68     typedef SkTypeface_FreeType INHERITED;
69 };
70