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 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkTypes.h"
13 
14 #include <memory>
15 
16 class SkData;
17 class SkFontStyle;
18 class SkStreamAsset;
19 class SkString;
20 class SkTypeface;
21 struct SkFontArguments;
22 
23 class SK_API SkFontStyleSet : public SkRefCnt {
24 public:
25  virtual int count() = 0;
26  virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
27  virtual sk_sp<SkTypeface> createTypeface(int index) = 0;
28  virtual sk_sp<SkTypeface> matchStyle(const SkFontStyle& pattern) = 0;
29 
31 
32 protected:
34 };
35 
36 class SK_API SkFontMgr : public SkRefCnt {
37 public:
38  int countFamilies() const;
39  void getFamilyName(int index, SkString* familyName) const;
41 
53  sk_sp<SkFontStyleSet> matchFamily(const char familyName[]) const;
54 
67  sk_sp<SkTypeface> matchFamilyStyle(const char familyName[], const SkFontStyle&) const;
68 
84  sk_sp<SkTypeface> matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
85  const char* bcp47[], int bcp47Count,
86  SkUnichar character) const;
87 
93  sk_sp<SkTypeface> makeFromData(sk_sp<SkData>, int ttcIndex = 0) const;
94 
100  sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, int ttcIndex = 0) const;
101 
102  /* Experimental, API subject to change. */
103  sk_sp<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, const SkFontArguments&) const;
104 
111  sk_sp<SkTypeface> makeFromFile(const char path[], int ttcIndex = 0) const;
112 
113  sk_sp<SkTypeface> legacyMakeTypeface(const char familyName[], SkFontStyle style) const;
114 
115 #if !defined(SK_DISABLE_LEGACY_FONTMGR_REFDEFAULT)
118 #endif
119 
120  /* Returns an empty font manager without any typeface dependencies */
122 
123 protected:
124  virtual int onCountFamilies() const = 0;
125  virtual void onGetFamilyName(int index, SkString* familyName) const = 0;
126  virtual sk_sp<SkFontStyleSet> onCreateStyleSet(int index)const = 0;
127 
129  virtual sk_sp<SkFontStyleSet> onMatchFamily(const char familyName[]) const = 0;
130 
131  virtual sk_sp<SkTypeface> onMatchFamilyStyle(const char familyName[],
132  const SkFontStyle&) const = 0;
133  virtual sk_sp<SkTypeface> onMatchFamilyStyleCharacter(const char familyName[],
134  const SkFontStyle&,
135  const char* bcp47[], int bcp47Count,
136  SkUnichar character) const = 0;
137 
138  virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const = 0;
139  virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
140  int ttcIndex) const = 0;
141  virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
142  const SkFontArguments&) const = 0;
143  virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const = 0;
144 
145  virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0;
146 
147 private:
149 #if !defined(SK_DISABLE_LEGACY_FONTMGR_FACTORY)
150  static sk_sp<SkFontMgr> Factory();
151 #endif
152 };
153 
154 #endif
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:167
SkData holds an immutable data buffer.
Definition: SkData.h:25
Definition: SkFontMgr.h:36
virtual sk_sp< SkTypeface > onMatchFamilyStyle(const char familyName[], const SkFontStyle &) const =0
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...
virtual sk_sp< SkTypeface > onMakeFromStreamIndex(std::unique_ptr< SkStreamAsset >, int ttcIndex) const =0
virtual sk_sp< SkFontStyleSet > onMatchFamily(const char familyName[]) const =0
May return NULL if the name is not found.
static sk_sp< SkFontMgr > RefDefault()
Return the default fontmgr.
virtual sk_sp< SkFontStyleSet > onCreateStyleSet(int index) const =0
sk_sp< SkFontStyleSet > createStyleSet(int index) const
virtual void onGetFamilyName(int index, SkString *familyName) const =0
void getFamilyName(int index, SkString *familyName) const
virtual sk_sp< SkTypeface > onLegacyMakeTypeface(const char familyName[], SkFontStyle) const =0
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const
sk_sp< SkFontStyleSet > matchFamily(const char familyName[]) const
The caller must call unref() on the returned object.
sk_sp< 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.
virtual sk_sp< SkTypeface > onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, const char *bcp47[], int bcp47Count, SkUnichar character) const =0
int countFamilies() const
sk_sp< 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.
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...
virtual sk_sp< SkTypeface > onMakeFromData(sk_sp< SkData >, int ttcIndex) const =0
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
virtual sk_sp< SkTypeface > onMakeFromStreamArgs(std::unique_ptr< SkStreamAsset >, const SkFontArguments &) const =0
virtual sk_sp< SkTypeface > onMakeFromFile(const char path[], int ttcIndex) const =0
static sk_sp< SkFontMgr > RefEmpty()
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...
virtual int onCountFamilies() const =0
Definition: SkFontMgr.h:23
static sk_sp< SkFontStyleSet > CreateEmpty()
virtual sk_sp< SkTypeface > createTypeface(int index)=0
sk_sp< SkTypeface > matchStyleCSS3(const SkFontStyle &pattern)
virtual int count()=0
virtual sk_sp< SkTypeface > matchStyle(const SkFontStyle &pattern)=0
virtual void getStyle(int index, SkFontStyle *, SkString *style)=0
Definition: SkFontStyle.h:16
Definition: SkRefCnt.h:119
SkStreamAsset is a SkStreamSeekable for which getLength is required.
Definition: SkStream.h:186
Light weight class for managing strings.
Definition: SkString.h:118
The SkTypeface class specifies the typeface and intrinsic style of a font.
Definition: SkTypeface.h:52
Represents a set of actual arguments for a font.
Definition: SkFontArguments.h:16