OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The Android Open Source Project | 2 * Copyright 2011 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 "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
10 #include "SkFontHost.h" | 10 #include "SkFontHost.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 SkTypeface::~SkTypeface() { | 30 SkTypeface::~SkTypeface() { |
31 #ifdef TRACE_LIFECYCLE | 31 #ifdef TRACE_LIFECYCLE |
32 SkDebugf("SkTypeface: destroy %p fontID %d total %d\n", | 32 SkDebugf("SkTypeface: destroy %p fontID %d total %d\n", |
33 this, fUniqueID, --gTypefaceCounter); | 33 this, fUniqueID, --gTypefaceCounter); |
34 #endif | 34 #endif |
35 } | 35 } |
36 | 36 |
37 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
38 | 38 |
| 39 class SkEmptyTypeface : public SkTypeface { |
| 40 public: |
| 41 SkEmptyTypeface() : SkTypeface(SkTypeface::kNormal, 0, true) { } |
| 42 protected: |
| 43 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { return NUL
L; } |
| 44 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE { |
| 45 return NULL; |
| 46 } |
| 47 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE { } |
| 48 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 49 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
| 50 const uint32_t*, uint32_t) const SK_OVERRIDE { r
eturn NULL; } |
| 51 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
{ } |
| 52 virtual int onCountGlyphs() const SK_OVERRIDE { return 0; }; |
| 53 virtual int onGetUPEM() const SK_OVERRIDE { return 0; }; |
| 54 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings { |
| 55 public: |
| 56 virtual bool next(SkTypeface::LocalizedString*) SK_OVERRIDE { return fal
se; } |
| 57 }; |
| 58 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE { |
| 59 return SkNEW(EmptyLocalizedStrings); |
| 60 }; |
| 61 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE { return
0; } |
| 62 virtual size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const S
K_OVERRIDE { |
| 63 return 0; |
| 64 } |
| 65 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE { return NUL
L; } |
| 66 }; |
| 67 |
39 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { | 68 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { |
40 // we keep a reference to this guy for all time, since if we return its | 69 // we keep a reference to this guy for all time, since if we return its |
41 // fontID, the font cache may later on ask to resolve that back into a | 70 // fontID, the font cache may later on ask to resolve that back into a |
42 // typeface object. | 71 // typeface object. |
43 static const uint32_t FONT_STYLE_COUNT = 4; | 72 static const uint32_t FONT_STYLE_COUNT = 4; |
44 static SkTypeface* gDefaultTypefaces[FONT_STYLE_COUNT]; | 73 static SkTypeface* gDefaultTypefaces[FONT_STYLE_COUNT]; |
45 SkASSERT((unsigned)style < FONT_STYLE_COUNT); | 74 SkASSERT((unsigned)style < FONT_STYLE_COUNT); |
46 | 75 |
47 // mask off any other bits to avoid a crash in SK_RELEASE | 76 // mask off any other bits to avoid a crash in SK_RELEASE |
48 style = (Style)(style & 0x03); | 77 style = (Style)(style & 0x03); |
49 | 78 |
50 if (NULL == gDefaultTypefaces[style]) { | 79 if (NULL == gDefaultTypefaces[style]) { |
51 gDefaultTypefaces[style] = | 80 gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style)
; |
52 SkFontHost::CreateTypeface(NULL, NULL, style); | |
53 } | 81 } |
| 82 if (NULL == gDefaultTypefaces[style]) { |
| 83 gDefaultTypefaces[style] = SkNEW(SkEmptyTypeface); |
| 84 } |
| 85 |
54 return gDefaultTypefaces[style]; | 86 return gDefaultTypefaces[style]; |
55 } | 87 } |
56 | 88 |
57 SkTypeface* SkTypeface::RefDefault(Style style) { | 89 SkTypeface* SkTypeface::RefDefault(Style style) { |
58 return SkRef(GetDefaultTypeface(style)); | 90 return SkRef(GetDefaultTypeface(style)); |
59 } | 91 } |
60 | 92 |
61 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { | 93 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { |
62 if (NULL == face) { | 94 if (NULL == face) { |
63 face = GetDefaultTypeface(); | 95 face = GetDefaultTypeface(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 /////////////////////////////////////////////////////////////////////////////// | 252 /////////////////////////////////////////////////////////////////////////////// |
221 | 253 |
222 int SkTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, | 254 int SkTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, |
223 uint16_t glyphs[], int glyphCount) const { | 255 uint16_t glyphs[], int glyphCount) const { |
224 SkDebugf("onCharsToGlyphs unimplemented\n"); | 256 SkDebugf("onCharsToGlyphs unimplemented\n"); |
225 if (glyphs && glyphCount > 0) { | 257 if (glyphs && glyphCount > 0) { |
226 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); | 258 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); |
227 } | 259 } |
228 return 0; | 260 return 0; |
229 } | 261 } |
OLD | NEW |