| 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 19 matching lines...) Expand all Loading... |
| 30 #ifdef TRACE_LIFECYCLE | 30 #ifdef TRACE_LIFECYCLE |
| 31 SkDebugf("SkTypeface: destroy %p fontID %d total %d\n", | 31 SkDebugf("SkTypeface: destroy %p fontID %d total %d\n", |
| 32 this, fUniqueID, --gTypefaceCounter); | 32 this, fUniqueID, --gTypefaceCounter); |
| 33 #endif | 33 #endif |
| 34 } | 34 } |
| 35 | 35 |
| 36 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
| 37 | 37 |
| 38 class SkEmptyTypeface : public SkTypeface { | 38 class SkEmptyTypeface : public SkTypeface { |
| 39 public: | 39 public: |
| 40 static SkEmptyTypeface* Create() { |
| 41 return SkNEW(SkEmptyTypeface); |
| 42 } |
| 43 protected: |
| 40 SkEmptyTypeface() : SkTypeface(SkTypeface::kNormal, 0, true) { } | 44 SkEmptyTypeface() : SkTypeface(SkTypeface::kNormal, 0, true) { } |
| 41 protected: | 45 |
| 42 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { return NUL
L; } | 46 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { return NUL
L; } |
| 43 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE { | 47 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE { |
| 44 return NULL; | 48 return NULL; |
| 45 } | 49 } |
| 46 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE { } | 50 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE { } |
| 47 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 51 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 48 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 52 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
| 49 const uint32_t*, uint32_t) const SK_OVERRIDE { r
eturn NULL; } | 53 const uint32_t*, uint32_t) const SK_OVERRIDE { r
eturn NULL; } |
| 50 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
{ } | 54 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
{ } |
| 51 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, | 55 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 78 template <uintmax_t N> struct SkTIsPow2 { | 82 template <uintmax_t N> struct SkTIsPow2 { |
| 79 static const bool value = (N & (N - 1)) == 0; | 83 static const bool value = (N & (N - 1)) == 0; |
| 80 }; | 84 }; |
| 81 SK_COMPILE_ASSERT(SkTIsPow2<FONT_STYLE_COUNT>::value, FONT_STYLE_COUNT_not_power
_of_2); | 85 SK_COMPILE_ASSERT(SkTIsPow2<FONT_STYLE_COUNT>::value, FONT_STYLE_COUNT_not_power
_of_2); |
| 82 | 86 |
| 83 void SkTypeface::create_default_typeface(Style style) { | 87 void SkTypeface::create_default_typeface(Style style) { |
| 84 if (NULL == gDefaultTypefaces[style]) { | 88 if (NULL == gDefaultTypefaces[style]) { |
| 85 gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style)
; | 89 gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style)
; |
| 86 } | 90 } |
| 87 if (NULL == gDefaultTypefaces[style]) { | 91 if (NULL == gDefaultTypefaces[style]) { |
| 88 gDefaultTypefaces[style] = SkNEW(SkEmptyTypeface); | 92 // FIXME: Use a singleton for SkEmptyTypeface. |
| 93 gDefaultTypefaces[style] = SkEmptyTypeface::Create(); |
| 89 } | 94 } |
| 90 } | 95 } |
| 91 | 96 |
| 92 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { | 97 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { |
| 93 SkASSERT((size_t)style < FONT_STYLE_COUNT); | 98 SkASSERT((size_t)style < FONT_STYLE_COUNT); |
| 94 | 99 |
| 95 // mask off any other bits to avoid a crash in SK_RELEASE | 100 // mask off any other bits to avoid a crash in SK_RELEASE |
| 96 style = (Style)(style & (FONT_STYLE_COUNT - 1)); | 101 style = (Style)(style & (FONT_STYLE_COUNT - 1)); |
| 97 | 102 |
| 98 SkOnce(&gDefaultTypefaceOnce[style], SkTypeface::create_default_typeface, st
yle); | 103 SkOnce(&gDefaultTypefaceOnce[style], SkTypeface::create_default_typeface, st
yle); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 uint32_t glyphIDsCount) const { | 275 uint32_t glyphIDsCount) const { |
| 271 return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); | 276 return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); |
| 272 } | 277 } |
| 273 | 278 |
| 274 /////////////////////////////////////////////////////////////////////////////// | 279 /////////////////////////////////////////////////////////////////////////////// |
| 275 | 280 |
| 276 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, | 281 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
| 277 int32_t adjustments[]) const { | 282 int32_t adjustments[]) const { |
| 278 return false; | 283 return false; |
| 279 } | 284 } |
| OLD | NEW |