OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFontHost.h" | 8 #include "SkFontHost.h" |
9 #include "SkFontHost_FreeType_common.h" | 9 #include "SkFontHost_FreeType_common.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 #ifndef SK_FONT_FILE_PREFIX | 24 #ifndef SK_FONT_FILE_PREFIX |
25 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/" | 25 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/" |
26 #endif | 26 #endif |
27 | 27 |
28 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
29 | 29 |
30 /** The base SkTypeface implementation for the custom font manager. */ | 30 /** The base SkTypeface implementation for the custom font manager. */ |
31 class SkTypeface_Custom : public SkTypeface_FreeType { | 31 class SkTypeface_Custom : public SkTypeface_FreeType { |
32 public: | 32 public: |
33 SkTypeface_Custom(Style style, bool isFixedPitch, | 33 SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch, |
34 bool sysFont, const SkString familyName, int index) | 34 bool sysFont, const SkString familyName, int index) |
35 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) | 35 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) |
36 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) | 36 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) |
37 { } | 37 { } |
38 | 38 |
39 bool isSysFont() const { return fIsSysFont; } | 39 bool isSysFont() const { return fIsSysFont; } |
40 | 40 |
41 virtual const char* getUniqueString() const = 0; | 41 virtual const char* getUniqueString() const = 0; |
42 | 42 |
43 protected: | 43 protected: |
(...skipping 16 matching lines...) Expand all Loading... |
60 const int fIndex; | 60 const int fIndex; |
61 | 61 |
62 typedef SkTypeface_FreeType INHERITED; | 62 typedef SkTypeface_FreeType INHERITED; |
63 }; | 63 }; |
64 | 64 |
65 /** The empty SkTypeface implementation for the custom font manager. | 65 /** The empty SkTypeface implementation for the custom font manager. |
66 * Used as the last resort fallback typeface. | 66 * Used as the last resort fallback typeface. |
67 */ | 67 */ |
68 class SkTypeface_Empty : public SkTypeface_Custom { | 68 class SkTypeface_Empty : public SkTypeface_Custom { |
69 public: | 69 public: |
70 SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, false, true, SkString(),
0) {} | 70 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {} |
71 | 71 |
72 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } | 72 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } |
73 | 73 |
74 protected: | 74 protected: |
75 virtual SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; } | 75 virtual SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; } |
76 | 76 |
77 private: | 77 private: |
78 typedef SkTypeface_Custom INHERITED; | 78 typedef SkTypeface_Custom INHERITED; |
79 }; | 79 }; |
80 | 80 |
81 /** The stream SkTypeface implementation for the custom font manager. */ | 81 /** The stream SkTypeface implementation for the custom font manager. */ |
82 class SkTypeface_Stream : public SkTypeface_Custom { | 82 class SkTypeface_Stream : public SkTypeface_Custom { |
83 public: | 83 public: |
84 SkTypeface_Stream(Style style, bool isFixedPitch, bool sysFont, const SkStri
ng familyName, | 84 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont, |
85 SkStream* stream, int ttcIndex) | 85 const SkString familyName, SkStream* stream, int index) |
86 : INHERITED(style, isFixedPitch, sysFont, familyName, ttcIndex) | 86 : INHERITED(style, isFixedPitch, sysFont, familyName, index) |
87 , fStream(SkRef(stream)) | 87 , fStream(SkRef(stream)) |
88 { } | 88 { } |
89 | 89 |
90 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } | 90 virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; } |
91 | 91 |
92 protected: | 92 protected: |
93 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 93 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
94 *ttcIndex = this->getIndex(); | 94 *ttcIndex = this->getIndex(); |
95 return fStream->duplicate(); | 95 return fStream->duplicate(); |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 const SkAutoTUnref<const SkStream> fStream; | 99 const SkAutoTUnref<const SkStream> fStream; |
100 | 100 |
101 typedef SkTypeface_Custom INHERITED; | 101 typedef SkTypeface_Custom INHERITED; |
102 }; | 102 }; |
103 | 103 |
104 /** The file SkTypeface implementation for the custom font manager. */ | 104 /** The file SkTypeface implementation for the custom font manager. */ |
105 class SkTypeface_File : public SkTypeface_Custom { | 105 class SkTypeface_File : public SkTypeface_Custom { |
106 public: | 106 public: |
107 SkTypeface_File(Style style, bool isFixedPitch, bool sysFont, const SkString
familyName, | 107 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, |
108 const char path[], int index) | 108 const SkString familyName, const char path[], int index) |
109 : INHERITED(style, isFixedPitch, sysFont, familyName, index) | 109 : INHERITED(style, isFixedPitch, sysFont, familyName, index) |
110 , fPath(path) | 110 , fPath(path) |
111 { } | 111 { } |
112 | 112 |
113 virtual const char* getUniqueString() const SK_OVERRIDE { | 113 virtual const char* getUniqueString() const SK_OVERRIDE { |
114 const char* str = strrchr(fPath.c_str(), '/'); | 114 const char* str = strrchr(fPath.c_str(), '/'); |
115 if (str) { | 115 if (str) { |
116 str += 1; // skip the '/' | 116 str += 1; // skip the '/' |
117 } | 117 } |
118 return str; | 118 return str; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return this->createFromStream(stream, ttcIndex); | 266 return this->createFromStream(stream, ttcIndex); |
267 } | 267 } |
268 | 268 |
269 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { | 269 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const
SK_OVERRIDE { |
270 if (NULL == stream || stream->getLength() <= 0) { | 270 if (NULL == stream || stream->getLength() <= 0) { |
271 SkDELETE(stream); | 271 SkDELETE(stream); |
272 return NULL; | 272 return NULL; |
273 } | 273 } |
274 | 274 |
275 bool isFixedPitch; | 275 bool isFixedPitch; |
276 SkTypeface::Style style; | 276 SkFontStyle style; |
277 SkString name; | 277 SkString name; |
278 if (SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isFi
xedPitch)) { | 278 if (SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isFi
xedPitch)) { |
279 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na
me, | 279 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na
me, |
280 stream, ttcIndex)); | 280 stream, ttcIndex)); |
281 } else { | 281 } else { |
282 return NULL; | 282 return NULL; |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { | 286 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const
SK_OVERRIDE { |
(...skipping 21 matching lines...) Expand all Loading... |
308 if (NULL == tf) { | 308 if (NULL == tf) { |
309 tf = gDefaultFamily->matchStyle(style); | 309 tf = gDefaultFamily->matchStyle(style); |
310 } | 310 } |
311 | 311 |
312 return SkSafeRef(tf); | 312 return SkSafeRef(tf); |
313 } | 313 } |
314 | 314 |
315 private: | 315 private: |
316 | 316 |
317 static bool get_name_and_style(const char path[], SkString* name, | 317 static bool get_name_and_style(const char path[], SkString* name, |
318 SkTypeface::Style* style, bool* isFixedPitch)
{ | 318 SkFontStyle* style, bool* isFixedPitch) { |
319 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 319 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
320 if (stream.get()) { | 320 if (stream.get()) { |
321 return SkTypeface_FreeType::ScanFont(stream, 0, name, style, isFixed
Pitch); | 321 return SkTypeface_FreeType::ScanFont(stream, 0, name, style, isFixed
Pitch); |
322 } else { | 322 } else { |
323 SkDebugf("---- failed to open <%s> as a font\n", path); | 323 SkDebugf("---- failed to open <%s> as a font\n", path); |
324 return false; | 324 return false; |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 void load_directory_fonts(const SkString& directory) { | 328 void load_directory_fonts(const SkString& directory) { |
329 SkOSFile::Iter iter(directory.c_str(), ".ttf"); | 329 SkOSFile::Iter iter(directory.c_str(), ".ttf"); |
330 SkString name; | 330 SkString name; |
331 | 331 |
332 while (iter.next(&name, false)) { | 332 while (iter.next(&name, false)) { |
333 SkString filename( | 333 SkString filename( |
334 SkOSPath::Join(directory.c_str(), name.c_str())); | 334 SkOSPath::Join(directory.c_str(), name.c_str())); |
335 | 335 |
336 bool isFixedPitch; | 336 bool isFixedPitch; |
337 SkString realname; | 337 SkString realname; |
338 SkTypeface::Style style = SkTypeface::kNormal; // avoid uninitialize
d warning | 338 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning |
339 | |
340 if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixe
dPitch)) { | 339 if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixe
dPitch)) { |
341 SkDebugf("------ can't load <%s> as a font\n", filename.c_str())
; | 340 SkDebugf("------ can't load <%s> as a font\n", filename.c_str())
; |
342 continue; | 341 continue; |
343 } | 342 } |
344 | 343 |
345 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( | 344 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( |
346 style, | 345 style, |
347 isFixedPitch, | 346 isFixedPitch, |
348 true, // system-font (cannot de
lete) | 347 true, // system-font (cannot de
lete) |
349 realname, | 348 realname, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 404 } |
406 | 405 |
407 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; | 406 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; |
408 SkFontStyleSet_Custom* gDefaultFamily; | 407 SkFontStyleSet_Custom* gDefaultFamily; |
409 SkTypeface* gDefaultNormal; | 408 SkTypeface* gDefaultNormal; |
410 }; | 409 }; |
411 | 410 |
412 SkFontMgr* SkFontMgr::Factory() { | 411 SkFontMgr* SkFontMgr::Factory() { |
413 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); | 412 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); |
414 } | 413 } |
OLD | NEW |