blob: 6003c095c164ee23125a34ca5ed0eedc00005d65 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#include "SkFontHost.h"
reed@google.com0fc17c32013-03-21 13:33:49 +00009#include "SkFontHost_FreeType_common.h"
djsollen@google.com97145162012-05-31 19:55:08 +000010#include "SkFontDescriptor.h"
bungeman@google.comb3d154d2013-11-11 15:53:29 +000011#include "SkFontMgr.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkDescriptor.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkOSFile.h"
14#include "SkPaint.h"
15#include "SkString.h"
16#include "SkStream.h"
17#include "SkThread.h"
18#include "SkTSearch.h"
bungeman@google.comb3d154d2013-11-11 15:53:29 +000019#include "SkTypefaceCache.h"
20#include "SkTArray.h"
21
22#include <limits>
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
reed@android.com8a1c16f2008-12-17 15:59:43 +000024#ifndef SK_FONT_FILE_PREFIX
bungeman14df8332014-10-28 15:07:23 -070025# define SK_FONT_FILE_PREFIX "/usr/share/fonts/"
bungeman@google.com2cf84ec2012-09-26 19:16:54 +000026#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000027
reed@android.com8a1c16f2008-12-17 15:59:43 +000028///////////////////////////////////////////////////////////////////////////////
29
bungeman@google.comb3d154d2013-11-11 15:53:29 +000030/** The base SkTypeface implementation for the custom font manager. */
31class SkTypeface_Custom : public SkTypeface_FreeType {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032public:
bungemana4c4a2d2014-10-20 13:33:19 -070033 SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch,
bungemand71b7572014-09-18 10:55:32 -070034 bool sysFont, const SkString familyName, int index)
bungeman@google.comb3d154d2013-11-11 15:53:29 +000035 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
bungemand71b7572014-09-18 10:55:32 -070036 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
bungeman@google.comb3d154d2013-11-11 15:53:29 +000037 { }
chudy@google.comada44802012-07-30 12:59:12 +000038
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 bool isSysFont() const { return fIsSysFont; }
reed@google.com292b1d42013-03-22 17:21:59 +000040
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 virtual const char* getUniqueString() const = 0;
chudy@google.comada44802012-07-30 12:59:12 +000042
reed@google.com5526ede2013-03-25 13:03:37 +000043protected:
bungemanb374d6a2014-09-17 07:48:59 -070044 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
45 *familyName = fFamilyName;
46 }
47
bungeman@google.comb3d154d2013-11-11 15:53:29 +000048 virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVERRIDE {
49 desc->setFamilyName(fFamilyName.c_str());
50 desc->setFontFileName(this->getUniqueString());
bungemand71b7572014-09-18 10:55:32 -070051 desc->setFontIndex(fIndex);
bungeman@google.comb3d154d2013-11-11 15:53:29 +000052 *isLocal = !this->isSysFont();
53 }
reed@google.com5526ede2013-03-25 13:03:37 +000054
bungemand71b7572014-09-18 10:55:32 -070055 int getIndex() const { return fIndex; }
56
reed@android.com8a1c16f2008-12-17 15:59:43 +000057private:
bungemand71b7572014-09-18 10:55:32 -070058 const bool fIsSysFont;
59 const SkString fFamilyName;
60 const int fIndex;
chudy@google.comada44802012-07-30 12:59:12 +000061
reed@google.com032fbb82013-03-21 13:38:18 +000062 typedef SkTypeface_FreeType INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000063};
64
bungeman@google.comb3d154d2013-11-11 15:53:29 +000065/** The empty SkTypeface implementation for the custom font manager.
66 * Used as the last resort fallback typeface.
reed@android.comf244f1b2010-04-16 12:40:08 +000067 */
bungeman@google.comb3d154d2013-11-11 15:53:29 +000068class SkTypeface_Empty : public SkTypeface_Custom {
reed@android.comf244f1b2010-04-16 12:40:08 +000069public:
bungemana4c4a2d2014-10-20 13:33:19 -070070 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {}
chudy@google.comada44802012-07-30 12:59:12 +000071
bungeman@google.comb3d154d2013-11-11 15:53:29 +000072 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
chudy@google.comada44802012-07-30 12:59:12 +000073
reed@google.com292b1d42013-03-22 17:21:59 +000074protected:
75 virtual SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; }
76
reed@android.comf244f1b2010-04-16 12:40:08 +000077private:
bungeman@google.comb3d154d2013-11-11 15:53:29 +000078 typedef SkTypeface_Custom INHERITED;
reed@android.comf244f1b2010-04-16 12:40:08 +000079};
80
bungeman@google.comb3d154d2013-11-11 15:53:29 +000081/** The stream SkTypeface implementation for the custom font manager. */
82class SkTypeface_Stream : public SkTypeface_Custom {
reed@android.com8a1c16f2008-12-17 15:59:43 +000083public:
bungemana4c4a2d2014-10-20 13:33:19 -070084 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
85 const SkString familyName, SkStream* stream, int index)
86 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
bungemand71b7572014-09-18 10:55:32 -070087 , fStream(SkRef(stream))
bungeman@google.comb3d154d2013-11-11 15:53:29 +000088 { }
chudy@google.comada44802012-07-30 12:59:12 +000089
reed@google.come1575aa2013-03-18 21:08:46 +000090 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
chudy@google.comada44802012-07-30 12:59:12 +000091
reed@google.com292b1d42013-03-22 17:21:59 +000092protected:
93 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
bungemand71b7572014-09-18 10:55:32 -070094 *ttcIndex = this->getIndex();
commit-bot@chromium.orga2b44dc2014-03-24 21:42:01 +000095 return fStream->duplicate();
reed@google.com292b1d42013-03-22 17:21:59 +000096 }
97
reed@android.com8a1c16f2008-12-17 15:59:43 +000098private:
bungemand71b7572014-09-18 10:55:32 -070099 const SkAutoTUnref<const SkStream> fStream;
chudy@google.comada44802012-07-30 12:59:12 +0000100
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000101 typedef SkTypeface_Custom INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102};
103
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000104/** The file SkTypeface implementation for the custom font manager. */
105class SkTypeface_File : public SkTypeface_Custom {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000106public:
bungemana4c4a2d2014-10-20 13:33:19 -0700107 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
108 const SkString familyName, const char path[], int index)
bungemand71b7572014-09-18 10:55:32 -0700109 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000110 , fPath(path)
111 { }
chudy@google.comada44802012-07-30 12:59:12 +0000112
reed@google.come1575aa2013-03-18 21:08:46 +0000113 virtual const char* getUniqueString() const SK_OVERRIDE {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000114 const char* str = strrchr(fPath.c_str(), '/');
115 if (str) {
116 str += 1; // skip the '/'
117 }
118 return str;
119 }
chudy@google.comada44802012-07-30 12:59:12 +0000120
reed@google.com292b1d42013-03-22 17:21:59 +0000121protected:
122 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
bungemand71b7572014-09-18 10:55:32 -0700123 *ttcIndex = this->getIndex();
reed@google.com292b1d42013-03-22 17:21:59 +0000124 return SkStream::NewFromFile(fPath.c_str());
125 }
126
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127private:
128 SkString fPath;
chudy@google.comada44802012-07-30 12:59:12 +0000129
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000130 typedef SkTypeface_Custom INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131};
132
133///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000134
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000135/**
136 * SkFontStyleSet_Custom
137 *
138 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families.
139 */
140class SkFontStyleSet_Custom : public SkFontStyleSet {
141public:
142 explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(familyName) { }
143
144 virtual int count() SK_OVERRIDE {
145 return fStyles.count();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000146 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000147
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000148 virtual void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVERRIDE {
149 SkASSERT(index < fStyles.count());
150 bool bold = fStyles[index]->isBold();
151 bool italic = fStyles[index]->isItalic();
152 *style = SkFontStyle(bold ? SkFontStyle::kBold_Weight : SkFontStyle::kNormal_Weight,
153 SkFontStyle::kNormal_Width,
154 italic ? SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant);
155 name->reset();
156 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000157
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000158 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
159 SkASSERT(index < fStyles.count());
160 return SkRef(fStyles[index].get());
161 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000162
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000163 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
164 int score = 0;
165 score += (pattern.width() - candidate.width()) * 100;
166 score += (pattern.isItalic() == candidate.isItalic()) ? 0 : 1000;
167 score += pattern.weight() - candidate.weight();
168 return score;
169 }
170
171 virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE {
172 if (0 == fStyles.count()) {
173 return NULL;
174 }
175
176 SkTypeface_Custom* closest = fStyles[0];
177 int minScore = std::numeric_limits<int>::max();
178 for (int i = 0; i < fStyles.count(); ++i) {
179 bool bold = fStyles[i]->isBold();
180 bool italic = fStyles[i]->isItalic();
181 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight
182 : SkFontStyle::kNormal_Weight,
183 SkFontStyle::kNormal_Width,
184 italic ? SkFontStyle::kItalic_Slant
185 : SkFontStyle::kUpright_Slant);
186
187 int score = match_score(pattern, style);
188 if (score < minScore) {
189 closest = fStyles[i];
190 minScore = score;
191 }
192 }
193 return SkRef(closest);
194 }
195
196private:
197 SkTArray<SkAutoTUnref<SkTypeface_Custom>, true> fStyles;
198 SkString fFamilyName;
199
200 void appendTypeface(SkTypeface_Custom* typeface) {
201 fStyles.push_back().reset(typeface);
202 }
203
204 friend class SkFontMgr_Custom;
205};
206
207/**
208 * SkFontMgr_Custom
209 *
210 * This class is essentially a collection of SkFontStyleSet_Custom,
211 * one SkFontStyleSet_Custom for each family. This class may be modified
212 * to load fonts from any source by changing the initialization.
213 */
214class SkFontMgr_Custom : public SkFontMgr {
215public:
216 explicit SkFontMgr_Custom(const char* dir) {
217 this->load_system_fonts(dir);
218 }
219
220protected:
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000221 virtual int onCountFamilies() const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000222 return fFamilies.count();
223 }
224
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000225 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000226 SkASSERT(index < fFamilies.count());
227 familyName->set(fFamilies[index]->fFamilyName);
228 }
229
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000230 virtual SkFontStyleSet_Custom* onCreateStyleSet(int index) const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000231 SkASSERT(index < fFamilies.count());
232 return SkRef(fFamilies[index].get());
233 }
234
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000235 virtual SkFontStyleSet_Custom* onMatchFamily(const char familyName[]) const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000236 for (int i = 0; i < fFamilies.count(); ++i) {
237 if (fFamilies[i]->fFamilyName.equals(familyName)) {
238 return SkRef(fFamilies[i].get());
239 }
240 }
241 return NULL;
242 }
243
244 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000245 const SkFontStyle& fontStyle) const SK_OVERRIDE
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000246 {
247 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName));
248 return sset->matchStyle(fontStyle);
249 }
250
djsollen33068c12014-11-14 10:52:53 -0800251 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
252 const char* bcp47[], int bcp47Count,
253 SkUnichar character) const SK_OVERRIDE
254 {
255 return NULL;
256 }
257
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000258 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000259 const SkFontStyle& fontStyle) const SK_OVERRIDE
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000260 {
261 for (int i = 0; i < fFamilies.count(); ++i) {
262 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) {
263 if (fFamilies[i]->fStyles[j] == familyMember) {
264 return fFamilies[i]->matchStyle(fontStyle);
265 }
266 }
267 }
268 return NULL;
269 }
270
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000271 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000272 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data));
273 return this->createFromStream(stream, ttcIndex);
274 }
275
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000276 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000277 if (NULL == stream || stream->getLength() <= 0) {
278 SkDELETE(stream);
279 return NULL;
280 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000281
bungeman@google.comfe747652013-03-25 19:36:11 +0000282 bool isFixedPitch;
bungemana4c4a2d2014-10-20 13:33:19 -0700283 SkFontStyle style;
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000284 SkString name;
bungeman14df8332014-10-28 15:07:23 -0700285 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
bungeman3a21d612014-07-11 08:52:26 -0700286 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, name,
287 stream, ttcIndex));
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000288 } else {
289 return NULL;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000290 }
reed@android.comf244f1b2010-04-16 12:40:08 +0000291 }
292
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000293 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000294 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
295 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
296 }
297
298 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
commit-bot@chromium.org967dee32014-02-04 22:35:01 +0000299 unsigned styleBits) const SK_OVERRIDE
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000300 {
301 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
302 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
303 ? SkFontStyle::kBold_Weight
304 : SkFontStyle::kNormal_Weight,
305 SkFontStyle::kNormal_Width,
306 oldStyle & SkTypeface::kItalic
307 ? SkFontStyle::kItalic_Slant
308 : SkFontStyle::kUpright_Slant);
309 SkTypeface* tf = NULL;
310
bsalomon49f085d2014-09-05 13:34:00 -0700311 if (familyName) {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000312 tf = this->onMatchFamilyStyle(familyName, style);
bungeman@google.com2cf84ec2012-09-26 19:16:54 +0000313 }
bungeman@google.com2cf84ec2012-09-26 19:16:54 +0000314
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000315 if (NULL == tf) {
316 tf = gDefaultFamily->matchStyle(style);
317 }
318
319 return SkSafeRef(tf);
bungeman@google.com2cf84ec2012-09-26 19:16:54 +0000320 }
321
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000322private:
bungeman@google.com2cf84ec2012-09-26 19:16:54 +0000323
bungeman14df8332014-10-28 15:07:23 -0700324 void load_directory_fonts(const SkString& directory, const char* suffix) {
325 SkOSFile::Iter iter(directory.c_str(), suffix);
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000326 SkString name;
327
328 while (iter.next(&name, false)) {
bungeman14df8332014-10-28 15:07:23 -0700329 SkString filename(SkOSPath::Join(directory.c_str(), name.c_str()));
330 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str()));
331 if (!stream.get()) {
332 SkDebugf("---- failed to open <%s>\n", filename.c_str());
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000333 continue;
334 }
335
bungeman14df8332014-10-28 15:07:23 -0700336 int numFaces;
337 if (!fScanner.recognizedFont(stream, &numFaces)) {
338 SkDebugf("---- failed to open <%s> as a font\n", filename.c_str());
339 continue;
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000340 }
bungeman14df8332014-10-28 15:07:23 -0700341
342 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
343 bool isFixedPitch;
344 SkString realname;
345 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
346 if (!fScanner.scanFont(stream, faceIndex, &realname, &style, &isFixedPitch)) {
347 SkDebugf("---- failed to open <%s> <%d> as a font\n",
348 filename.c_str(), faceIndex);
349 continue;
350 }
351
352 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, (
353 style,
354 isFixedPitch,
355 true, // system-font (cannot delete)
356 realname,
357 filename.c_str(), 0));
358
359 SkFontStyleSet_Custom* addTo = this->onMatchFamily(realname.c_str());
360 if (NULL == addTo) {
361 addTo = new SkFontStyleSet_Custom(realname);
362 fFamilies.push_back().reset(addTo);
363 }
364 addTo->appendTypeface(tf);
365 }
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000366 }
367
368 SkOSFile::Iter dirIter(directory.c_str());
369 while (dirIter.next(&name, true)) {
370 if (name.startsWith(".")) {
371 continue;
372 }
tfarinaa8e2e152014-07-28 19:26:58 -0700373 SkString dirname(SkOSPath::Join(directory.c_str(), name.c_str()));
bungeman14df8332014-10-28 15:07:23 -0700374 load_directory_fonts(dirname, suffix);
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000375 }
376 }
377
378 void load_system_fonts(const char* dir) {
379 SkString baseDirectory(dir);
bungeman14df8332014-10-28 15:07:23 -0700380 load_directory_fonts(baseDirectory, ".ttf");
381 load_directory_fonts(baseDirectory, ".ttc");
382 load_directory_fonts(baseDirectory, ".otf");
383 load_directory_fonts(baseDirectory, ".pfb");
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000384
385 if (fFamilies.empty()) {
386 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
387 fFamilies.push_back().reset(family);
388 family->appendTypeface(SkNEW(SkTypeface_Empty));
389 }
390
391 // Try to pick a default font.
392 static const char* gDefaultNames[] = {
commit-bot@chromium.orgea163cc2014-03-13 16:24:49 +0000393 "Arial", "Verdana", "Times New Roman", "Droid Sans", NULL
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000394 };
395 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) {
396 SkFontStyleSet_Custom* set = this->onMatchFamily(gDefaultNames[i]);
397 if (NULL == set) {
398 continue;
399 }
400
401 SkTypeface* tf = set->matchStyle(SkFontStyle(SkFontStyle::kNormal_Weight,
402 SkFontStyle::kNormal_Width,
403 SkFontStyle::kUpright_Slant));
404 if (NULL == tf) {
405 continue;
406 }
407
408 gDefaultFamily = set;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000409 gDefaultNormal = tf;
410 break;
411 }
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000412 if (NULL == gDefaultNormal) {
413 gDefaultFamily = fFamilies[0];
414 gDefaultNormal = gDefaultFamily->fStyles[0];
reed@android.com8a1c16f2008-12-17 15:59:43 +0000415 }
416 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000417
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000418 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies;
419 SkFontStyleSet_Custom* gDefaultFamily;
420 SkTypeface* gDefaultNormal;
bungeman14df8332014-10-28 15:07:23 -0700421 SkTypeface_FreeType::Scanner fScanner;
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000422};
reed@google.com070da5e2013-03-27 20:01:49 +0000423
424SkFontMgr* SkFontMgr::Factory() {
bungeman@google.comb3d154d2013-11-11 15:53:29 +0000425 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX);
reed@google.com070da5e2013-03-27 20:01:49 +0000426}