• 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 all of the fonts with the given familyIndex.
60      *  Returns NULL if the index is out of bounds.
61      *  Returns empty if there are no fonts at the given index.
62      *
63      *  The caller must unref() the returned object.
64      */
65     virtual SkRemotableFontIdentitySet* getIndex(int familyIndex) const = 0;
66 
67     /**
68      *  Returns the closest match to the given style in the given index.
69      *  If there are no available fonts at the given index, the return value's
70      *  data id will be kInvalidDataId.
71      */
72     virtual SkFontIdentity matchIndexStyle(int familyIndex, const SkFontStyle&) const = 0;
73 
74     /**
75      *  Returns all the fonts on the system with the given name.
76      *  If the given name is NULL, will return the default font family.
77      *  Never returns NULL; will return an empty set if the name is not found.
78      *
79      *  It is possible that this will return fonts not accessible from
80      *  getIndex(int) or matchIndexStyle(int, SkFontStyle) due to
81      *  hidden or auto-activated fonts.
82      *
83      *  The matching may be done in a system dependent way. The name may be
84      *  matched case-insensitive, there may be system aliases which resolve,
85      *  and names outside the current locale may be considered. However, this
86      *  should only return fonts which are somehow associated with the requested
87      *  name.
88      *
89      *  The caller must unref() the returned object.
90      */
91     virtual SkRemotableFontIdentitySet* matchName(const char familyName[]) const = 0;
92 
93     /**
94      *  Returns the closest matching font to the specified name and style.
95      *  If there are no available fonts which match the name, the return value's
96      *  data id will be kInvalidDataId.
97      *  If the given name is NULL, the match will be against any default fonts.
98      *
99      *  It is possible that this will return a font identity not accessible from
100      *  methods returning sets due to hidden or auto-activated fonts.
101      *
102      *  The matching may be done in a system dependent way. The name may be
103      *  matched case-insensitive, there may be system aliases which resolve,
104      *  and names outside the current locale may be considered. However, this
105      *  should only return a font which is somehow associated with the requested
106      *  name.
107      *
108      *  The caller must unref() the returned object.
109      */
110     virtual SkFontIdentity matchNameStyle(const char familyName[], const SkFontStyle&) const = 0;
111 
112     /**
113      *  Use the system fall-back to find a font for the given character.
114      *  If no font can be found for the character, the return value's data id
115      *  will be kInvalidDataId.
116      *  If the name is NULL, the match will start against any default fonts.
117      *  If the bpc47 is NULL, a default locale will be assumed.
118      *
119      *  Note that bpc47 is a combination of ISO 639, 15924, and 3166-1 codes,
120      *  so it is fine to just pass a ISO 639 here.
121      */
122     virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&,
123                                                    const char* bcp47[], int bcp47Count,
124                                                    SkUnichar character) const=0;
125 
126     /**
127      *  Returns the data for the given data id.
128      *  Will return NULL if the data id is invalid.
129      *  Note that this is a data id, not a font id.
130      *
131      *  The caller must unref() the returned object.
132      */
133     virtual SkStreamAsset* getData(int dataId) const = 0;
134 
135 private:
136     typedef SkRefCnt INHERITED;
137 };
138 
139 #endif
140