• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 SkRemotableFontMgr_DEFINED
9 #define SkRemotableFontMgr_DEFINED
10 
11 #include "../private/SkTemplates.h"
12 #include "SkFontStyle.h"
13 #include "SkRefCnt.h"
14 #include "SkTypes.h"
15 
16 class SkDataTable;
17 class SkStreamAsset;
18 
19 struct SK_API SkFontIdentity {
20     static const uint32_t kInvalidDataId = 0xFFFFFFFF;
21 
22     // Note that fDataId is a data identifier, not a font identifier.
23     // (fDataID, fTtcIndex) can be seen as a font identifier.
24     uint32_t fDataId;
25     uint32_t fTtcIndex;
26 
27     // On Linux/FontConfig there is also the ability to specify preferences for rendering
28     // antialias, embedded bitmaps, autohint, hinting, hintstyle, lcd rendering
29     // may all be set or set to no-preference
30     // (No-preference is resolved against globals set by the platform)
31     // Since they may be selected against, these are really 'extensions' to SkFontStyle.
32     // SkFontStyle should pick these up.
33     SkFontStyle fFontStyle;
34 };
35 
36 class SK_API SkRemotableFontIdentitySet : public SkRefCnt {
37 public:
38     SkRemotableFontIdentitySet(int count, SkFontIdentity** data);
39 
count()40     int count() const { return fCount; }
at(int index)41     const SkFontIdentity& at(int index) const { return fData[index]; }
42 
43     static SkRemotableFontIdentitySet* NewEmpty();
44 
45 private:
SkRemotableFontIdentitySet()46     SkRemotableFontIdentitySet() : fCount(0), fData() { }
47 
48     friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new();
49 
50     int fCount;
51     SkAutoTMalloc<SkFontIdentity> fData;
52 
53     typedef SkRefCnt INHERITED;
54 };
55 
56 class SK_API SkRemotableFontMgr : public SkRefCnt {
57 public:
58     /**
59      *  Returns the names of the known fonts on the system.
60      *  Will not return NULL, will return an empty table if no families exist.
61      *
62      *  The indexes may be used with getIndex(int) and
63      *  matchIndexStyle(int, SkFontStyle).
64      *
65      *  The caller must unref() the returned object.
66      */
67     virtual SkDataTable* getFamilyNames() const = 0;
68 
69     /**
70      *  Returns all of the fonts with the given familyIndex.
71      *  Returns NULL if the index is out of bounds.
72      *  Returns empty if there are no fonts at the given index.
73      *
74      *  The caller must unref() the returned object.
75      */
76     virtual SkRemotableFontIdentitySet* getIndex(int familyIndex) const = 0;
77 
78     /**
79      *  Returns the closest match to the given style in the given index.
80      *  If there are no available fonts at the given index, the return value's
81      *  data id will be kInvalidDataId.
82      */
83     virtual SkFontIdentity matchIndexStyle(int familyIndex, const SkFontStyle&) const = 0;
84 
85     /**
86      *  Returns all the fonts on the system with the given name.
87      *  If the given name is NULL, will return the default font family.
88      *  Never returns NULL; will return an empty set if the name is not found.
89      *
90      *  It is possible that this will return fonts not accessible from
91      *  getIndex(int) or matchIndexStyle(int, SkFontStyle) due to
92      *  hidden or auto-activated fonts.
93      *
94      *  The matching may be done in a system dependent way. The name may be
95      *  matched case-insensitive, there may be system aliases which resolve,
96      *  and names outside the current locale may be considered. However, this
97      *  should only return fonts which are somehow associated with the requested
98      *  name.
99      *
100      *  The caller must unref() the returned object.
101      */
102     virtual SkRemotableFontIdentitySet* matchName(const char familyName[]) const = 0;
103 
104     /**
105      *  Returns the closest matching font to the specified name and style.
106      *  If there are no available fonts which match the name, the return value's
107      *  data id will be kInvalidDataId.
108      *  If the given name is NULL, the match will be against any default fonts.
109      *
110      *  It is possible that this will return a font identity not accessible from
111      *  methods returning sets due to hidden or auto-activated fonts.
112      *
113      *  The matching may be done in a system dependent way. The name may be
114      *  matched case-insensitive, there may be system aliases which resolve,
115      *  and names outside the current locale may be considered. However, this
116      *  should only return a font which is somehow associated with the requested
117      *  name.
118      *
119      *  The caller must unref() the returned object.
120      */
121     virtual SkFontIdentity matchNameStyle(const char familyName[], const SkFontStyle&) const = 0;
122 
123     /**
124      *  Use the system fall-back to find a font for the given character.
125      *  If no font can be found for the character, the return value's data id
126      *  will be kInvalidDataId.
127      *  If the name is NULL, the match will start against any default fonts.
128      *  If the bpc47 is NULL, a default locale will be assumed.
129      *
130      *  Note that bpc47 is a combination of ISO 639, 15924, and 3166-1 codes,
131      *  so it is fine to just pass a ISO 639 here.
132      */
133     virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&,
134                                                    const char* bcp47[], int bcp47Count,
135                                                    SkUnichar character) const=0;
136 
137     /**
138      *  Returns the data for the given data id.
139      *  Will return NULL if the data id is invalid.
140      *  Note that this is a data id, not a font id.
141      *
142      *  The caller must unref() the returned object.
143      */
144     virtual SkStreamAsset* getData(int dataId) const = 0;
145 
146 private:
147     typedef SkRefCnt INHERITED;
148 };
149 
150 #endif
151