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" |
11 #include "SkOnce.h" | |
11 #include "SkStream.h" | 12 #include "SkStream.h" |
12 #include "SkTypeface.h" | 13 #include "SkTypeface.h" |
13 | 14 |
14 //#define TRACE_LIFECYCLE | 15 //#define TRACE_LIFECYCLE |
15 | 16 |
16 #ifdef TRACE_LIFECYCLE | 17 #ifdef TRACE_LIFECYCLE |
17 static int32_t gTypefaceCounter; | 18 static int32_t gTypefaceCounter; |
18 #endif | 19 #endif |
19 | 20 |
20 SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedPitch) | 21 SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedPitch) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 }; | 63 }; |
63 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_ OVERRIDE { | 64 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_ OVERRIDE { |
64 return SkNEW(EmptyLocalizedStrings); | 65 return SkNEW(EmptyLocalizedStrings); |
65 }; | 66 }; |
66 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE { return 0; } | 67 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE { return 0; } |
67 virtual size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const S K_OVERRIDE { | 68 virtual size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const S K_OVERRIDE { |
68 return 0; | 69 return 0; |
69 } | 70 } |
70 }; | 71 }; |
71 | 72 |
72 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { | 73 static SkTypeface* gDefaultTypefaces[] = { NULL, NULL, NULL, NULL }; |
73 // we keep a reference to this guy for all time, since if we return its | 74 static const size_t FONT_STYLE_COUNT = SK_ARRAY_COUNT(gDefaultTypefaces); |
74 // fontID, the font cache may later on ask to resolve that back into a | 75 static SkOnceFlag gDefaultTypefaceOnce[FONT_STYLE_COUNT] = { |
75 // typeface object. | 76 SK_ONCE_INIT, SK_ONCE_INIT, SK_ONCE_INIT, SK_ONCE_INIT |
76 static const uint32_t FONT_STYLE_COUNT = 4; | 77 }; |
77 static SkTypeface* gDefaultTypefaces[FONT_STYLE_COUNT]; | 78 template <uintmax_t N> struct SkTIsPow2 { |
78 SkASSERT((unsigned)style < FONT_STYLE_COUNT); | 79 static const bool value = (N & (N - 1)) == 0; |
80 }; | |
81 SK_COMPILE_ASSERT(SkTIsPow2<FONT_STYLE_COUNT>::value, FONT_STYLE_COUNT_not_power _of_2); | |
mtklein
2014/01/09 17:08:22
Since we're leaving SkTIsPow2 in this file, why no
bungeman-skia
2014/01/09 17:12:57
Because I like naming it (it isn't immediately obv
| |
79 | 82 |
80 // mask off any other bits to avoid a crash in SK_RELEASE | 83 void SkTypeface::create_default_typeface(Style style) { |
81 style = (Style)(style & 0x03); | |
82 | |
83 if (NULL == gDefaultTypefaces[style]) { | 84 if (NULL == gDefaultTypefaces[style]) { |
84 gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style) ; | 85 gDefaultTypefaces[style] = SkFontHost::CreateTypeface(NULL, NULL, style) ; |
85 } | 86 } |
86 if (NULL == gDefaultTypefaces[style]) { | 87 if (NULL == gDefaultTypefaces[style]) { |
87 gDefaultTypefaces[style] = SkNEW(SkEmptyTypeface); | 88 gDefaultTypefaces[style] = SkNEW(SkEmptyTypeface); |
88 } | 89 } |
90 } | |
89 | 91 |
92 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { | |
93 SkASSERT((size_t)style < FONT_STYLE_COUNT); | |
94 | |
95 // mask off any other bits to avoid a crash in SK_RELEASE | |
96 style = (Style)(style & (FONT_STYLE_COUNT - 1)); | |
97 | |
98 SkOnce(&gDefaultTypefaceOnce[style], SkTypeface::create_default_typeface, st yle); | |
90 return gDefaultTypefaces[style]; | 99 return gDefaultTypefaces[style]; |
91 } | 100 } |
92 | 101 |
93 SkTypeface* SkTypeface::RefDefault(Style style) { | 102 SkTypeface* SkTypeface::RefDefault(Style style) { |
94 return SkRef(GetDefaultTypeface(style)); | 103 return SkRef(GetDefaultTypeface(style)); |
95 } | 104 } |
96 | 105 |
97 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { | 106 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { |
98 if (NULL == face) { | 107 if (NULL == face) { |
99 face = GetDefaultTypeface(); | 108 face = GetDefaultTypeface(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 uint32_t glyphIDsCount) const { | 270 uint32_t glyphIDsCount) const { |
262 return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); | 271 return this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); |
263 } | 272 } |
264 | 273 |
265 /////////////////////////////////////////////////////////////////////////////// | 274 /////////////////////////////////////////////////////////////////////////////// |
266 | 275 |
267 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, | 276 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
268 int32_t adjustments[]) const { | 277 int32_t adjustments[]) const { |
269 return false; | 278 return false; |
270 } | 279 } |
OLD | NEW |