Skia
2D Graphics Library
SkFontMgr.h
Go to the documentation of this file.
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 SkFontMgr_DEFINED
9 #define SkFontMgr_DEFINED
10 
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkTypes.h"
15 
16 class SkData;
17 class SkFontData;
18 class SkStreamAsset;
19 class SkString;
20 class SkTypeface;
21 
22 class SK_API SkFontStyleSet : public SkRefCnt {
23 public:
24  virtual int count() = 0;
25  virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
26  virtual SkTypeface* createTypeface(int index) = 0;
27  virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0;
28 
30 
31 protected:
33 
34 private:
35  using INHERITED = SkRefCnt;
36 };
37 
38 class SK_API SkFontMgr : public SkRefCnt {
39 public:
40  int countFamilies() const;
41  void getFamilyName(int index, SkString* familyName) const;
42  SkFontStyleSet* createStyleSet(int index) const;
43 
55  SkFontStyleSet* matchFamily(const char familyName[]) const;
56 
69  SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const;
70 
86  SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
87  const char* bcp47[], int bcp47Count,
88  SkUnichar character) const;
89 
95  sk_sp<SkTypeface> makeFromData(sk_sp<SkData>, int ttcIndex = 0) const;
96 
102  sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, int ttcIndex = 0) const;
103 
104  /* Experimental, API subject to change. */
105  sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const;
106 
112  sk_sp<SkTypeface> makeFromFontData(std::unique_ptr<SkFontData>) const;
113 
120  sk_sp<SkTypeface> makeFromFile(const char path[], int ttcIndex = 0) const;
121 
122  sk_sp<SkTypeface> legacyMakeTypeface(const char familyName[], SkFontStyle style) const;
123 
126 
127 protected:
128  virtual int onCountFamilies() const = 0;
129  virtual void onGetFamilyName(int index, SkString* familyName) const = 0;
130  virtual SkFontStyleSet* onCreateStyleSet(int index)const = 0;
131 
133  virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0;
134 
135  virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
136  const SkFontStyle&) const = 0;
137  virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
138  const char* bcp47[], int bcp47Count,
139  SkUnichar character) const = 0;
141  const SkFontStyle&) const = 0;
142 
143  virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const = 0;
144  virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
145  int ttcIndex) const = 0;
146  virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
147  const SkFontArguments&) const = 0;
148  virtual sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const;
149  virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const = 0;
150 
151  virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0;
152 
153 private:
154 
156  static sk_sp<SkFontMgr> Factory();
157 
158  using INHERITED = SkRefCnt;
159 };
160 
161 #endif
SkFontMgr::matchFamily
SkFontStyleSet * matchFamily(const char familyName[]) const
The caller must call unref() on the returned object.
SkFontStyle
Definition: SkFontStyle.h:14
SkFontMgr::RefDefault
static sk_sp< SkFontMgr > RefDefault()
Return the default fontmgr.
SkFontStyleSet::count
virtual int count()=0
SkFontStyleSet::matchStyle
virtual SkTypeface * matchStyle(const SkFontStyle &pattern)=0
SkFontMgr::onMatchFamilyStyleCharacter
virtual SkTypeface * onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const =0
SkRefCnt
Definition: SkRefCnt.h:118
SkFontArguments.h
SkFontMgr::makeFromFile
sk_sp< SkTypeface > makeFromFile(const char path[], int ttcIndex=0) const
Create a typeface for the specified fileName and TTC index (pass 0 for none) or NULL if the file is n...
SkFontMgr::makeFromStream
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
Create a typeface for the specified stream and TTC index (pass 0 for none) or NULL if the stream is n...
SkFontStyleSet::CreateEmpty
static SkFontStyleSet * CreateEmpty()
SkTypes.h
SkFontMgr::onMatchFamilyStyle
virtual SkTypeface * onMatchFamilyStyle(const char familyName[], const SkFontStyle &) const =0
SkFontMgr::onMakeFromStreamArgs
virtual sk_sp< SkTypeface > onMakeFromStreamArgs(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const =0
SkFontMgr::countFamilies
int countFamilies() const
SkData
SkData holds an immutable data buffer.
Definition: SkData.h:22
SkFontMgr::makeFromData
sk_sp< SkTypeface > makeFromData(sk_sp< SkData >, int ttcIndex=0) const
Create a typeface for the specified data and TTC index (pass 0 for none) or NULL if the data is not r...
SkTypeface
Definition: SkTypeface.h:45
SkRefCnt.h
sk_sp< SkTypeface >
SkFontStyleSet::getStyle
virtual void getStyle(int index, SkFontStyle *, SkString *style)=0
SK_API
#define SK_API
Definition: SkTypes.h:181
SkFontMgr::onMakeFromStreamIndex
virtual sk_sp< SkTypeface > onMakeFromStreamIndex(std::unique_ptr< SkStreamAsset >, int ttcIndex) const =0
SkFontMgr::onMatchFaceStyle
virtual SkTypeface * onMatchFaceStyle(const SkTypeface *, const SkFontStyle &) const =0
SkFontMgr::onMatchFamily
virtual SkFontStyleSet * onMatchFamily(const char familyName[]) const =0
May return NULL if the name is not found.
SkFontMgr::makeFromFontData
sk_sp< SkTypeface > makeFromFontData(std::unique_ptr< SkFontData >) const
Create a typeface from the specified font data.
SkFontStyleSet::matchStyleCSS3
SkTypeface * matchStyleCSS3(const SkFontStyle &pattern)
SkFontMgr::legacyMakeTypeface
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
SkFontMgr
Definition: SkFontMgr.h:38
SkFontStyleSet
Definition: SkFontMgr.h:22
SkFontMgr::onMakeFromFontData
virtual sk_sp< SkTypeface > onMakeFromFontData(std::unique_ptr< SkFontData >) const
SkFontMgr::getFamilyName
void getFamilyName(int index, SkString *familyName) const
SkUnichar
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:552
SkFontMgr::onMakeFromData
virtual sk_sp< SkTypeface > onMakeFromData(sk_sp< SkData >, int ttcIndex) const =0
SkStreamAsset
SkStreamAsset is a SkStreamSeekable for which getLength is required.
Definition: SkStream.h:195
SkFontMgr::matchFamilyStyleCharacter
SkTypeface * matchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const
Use the system fallback to find a typeface for the given character.
SkFontMgr::onMakeFromFile
virtual sk_sp< SkTypeface > onMakeFromFile(const char path[], int ttcIndex) const =0
SkFontMgr::createStyleSet
SkFontStyleSet * createStyleSet(int index) const
SkFontMgr::onCountFamilies
virtual int onCountFamilies() const =0
SkFontMgr::makeFromStream
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const
SkFontMgr::onGetFamilyName
virtual void onGetFamilyName(int index, SkString *familyName) const =0
SkString
Definition: SkString.h:116
SkFontStyle.h
SkFontMgr::onLegacyMakeTypeface
virtual sk_sp< SkTypeface > onLegacyMakeTypeface(const char familyName[], SkFontStyle) const =0
SkFontMgr::matchFamilyStyle
SkTypeface * matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Find the closest matching typeface to the specified familyName and style and return a ref to it.
SkFontArguments
Represents a set of actual arguments for a font.
Definition: SkFontArguments.h:15
SkFontMgr::onCreateStyleSet
virtual SkFontStyleSet * onCreateStyleSet(int index) const =0
SkFontStyleSet::createTypeface
virtual SkTypeface * createTypeface(int index)=0