blob: 12050c7e07abfb36753a24f02a9559a9efefc1df [file] [log] [blame]
bungeman@google.com72cf4fc2014-03-21 22:48:32 +00001/*
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
bungemanf3c15b72015-08-19 11:56:48 -070011#include "../private/SkTemplates.h"
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000012#include "SkFontStyle.h"
13#include "SkRefCnt.h"
bungemanf20488b2015-07-29 11:49:40 -070014#include "SkTypes.h"
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000015
16class SkDataTable;
17class SkStreamAsset;
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000018
19struct 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
36class SK_API SkRemotableFontIdentitySet : public SkRefCnt {
37public:
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000038 SkRemotableFontIdentitySet(int count, SkFontIdentity** data);
39
40 int count() const { return fCount; }
41 const SkFontIdentity& at(int index) const { return fData[index]; }
42
43 static SkRemotableFontIdentitySet* NewEmpty();
44
45private:
46 SkRemotableFontIdentitySet() : fCount(0), fData() { }
mtklein148ec592014-10-13 13:17:56 -070047
48 friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new();
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000049
50 int fCount;
51 SkAutoTMalloc<SkFontIdentity> fData;
52
53 typedef SkRefCnt INHERITED;
54};
55
56class SK_API SkRemotableFontMgr : public SkRefCnt {
57public:
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000058 /**
bungeman@google.com72cf4fc2014-03-21 22:48:32 +000059 * 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&,
bungemanc20386e2014-10-23 07:08:05 -0700123 const char* bcp47[], int bcp47Count,
124 SkUnichar character) const=0;
bungeman@google.com72cf4fc2014-03-21 22:48:32 +0000125
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
135private:
136 typedef SkRefCnt INHERITED;
137};
138
139#endif