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 "SkEndian.h" | 9 #include "SkEndian.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
11 #include "SkFontHost.h" | 11 #include "SkFontMgr.h" |
12 #include "SkLazyPtr.h" | 12 #include "SkLazyPtr.h" |
13 #include "SkOTTable_OS_2.h" | 13 #include "SkOTTable_OS_2.h" |
14 #include "SkStream.h" | 14 #include "SkStream.h" |
15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
16 | 16 |
17 //#define TRACE_LIFECYCLE | 17 //#define TRACE_LIFECYCLE |
18 | 18 |
19 #ifdef TRACE_LIFECYCLE | 19 #ifdef TRACE_LIFECYCLE |
20 static int32_t gTypefaceCounter; | 20 static int32_t gTypefaceCounter; |
21 #endif | 21 #endif |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 }; | 77 }; |
78 | 78 |
79 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); | 79 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); |
80 SkTypeface* SkTypeface::CreateDefault(int style) { | 80 SkTypeface* SkTypeface::CreateDefault(int style) { |
81 // If backed by fontconfig, it's not safe to call SkFontHost::CreateTypeface
concurrently. | 81 // If backed by fontconfig, it's not safe to call SkFontHost::CreateTypeface
concurrently. |
82 // To be safe, we serialize here with a mutex so only one call to | 82 // To be safe, we serialize here with a mutex so only one call to |
83 // CreateTypeface is happening at any given time. | 83 // CreateTypeface is happening at any given time. |
84 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? | 84 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? |
85 SkAutoMutexAcquire lock(&gCreateDefaultMutex); | 85 SkAutoMutexAcquire lock(&gCreateDefaultMutex); |
86 | 86 |
87 SkTypeface* t = SkFontHost::CreateTypeface(NULL, NULL, (Style)style); | 87 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 88 SkTypeface* t = fm->legacyCreateTypeface(NULL, style);; |
88 return t ? t : SkEmptyTypeface::Create(); | 89 return t ? t : SkEmptyTypeface::Create(); |
89 } | 90 } |
90 | 91 |
91 void SkTypeface::DeleteDefault(SkTypeface* t) { | 92 void SkTypeface::DeleteDefault(SkTypeface* t) { |
92 // The SkTypeface returned by SkFontHost::CreateTypeface may _itself_ be a | 93 // The SkTypeface returned by SkFontHost::CreateTypeface may _itself_ be a |
93 // cleverly-shared singleton. This is less than ideal. This means we | 94 // cleverly-shared singleton. This is less than ideal. This means we |
94 // cannot just assert our ownership and SkDELETE(t) like we'd want to. | 95 // cannot just assert our ownership and SkDELETE(t) like we'd want to. |
95 SkSafeUnref(t); | 96 SkSafeUnref(t); |
96 } | 97 } |
97 | 98 |
(...skipping 18 matching lines...) Expand all Loading... |
116 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { | 117 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { |
117 return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb); | 118 return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb); |
118 } | 119 } |
119 | 120 |
120 /////////////////////////////////////////////////////////////////////////////// | 121 /////////////////////////////////////////////////////////////////////////////// |
121 | 122 |
122 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { | 123 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { |
123 if (NULL == name) { | 124 if (NULL == name) { |
124 return RefDefault(style); | 125 return RefDefault(style); |
125 } | 126 } |
126 return SkFontHost::CreateTypeface(NULL, name, style); | 127 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 128 return fm->legacyCreateTypeface(name, style); |
127 } | 129 } |
128 | 130 |
129 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { | 131 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { |
130 if (family && family->style() == s) { | 132 if (family && family->style() == s) { |
131 family->ref(); | 133 family->ref(); |
132 return const_cast<SkTypeface*>(family); | 134 return const_cast<SkTypeface*>(family); |
133 } | 135 } |
134 return SkFontHost::CreateTypeface(family, NULL, s); | 136 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 137 bool bold = s & SkTypeface::kBold; |
| 138 bool italic = s & SkTypeface::kItalic; |
| 139 SkFontStyle newStyle = SkFontStyle(bold ? SkFontStyle::kBold_Weight |
| 140 : SkFontStyle::kNormal_Weight, |
| 141 SkFontStyle::kNormal_Width, |
| 142 italic ? SkFontStyle::kItalic_Slant |
| 143 : SkFontStyle::kUpright_Slant); |
| 144 return fm->matchFaceStyle(family, newStyle); |
135 } | 145 } |
136 | 146 |
137 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { | 147 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { |
138 return SkFontHost::CreateTypefaceFromStream(stream); | 148 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 149 return fm->createFromStream(stream); |
139 } | 150 } |
140 | 151 |
141 SkTypeface* SkTypeface::CreateFromFile(const char path[]) { | 152 SkTypeface* SkTypeface::CreateFromFile(const char path[]) { |
142 return SkFontHost::CreateTypefaceFromFile(path); | 153 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 154 return fm->createFromFile(path); |
143 } | 155 } |
144 | 156 |
145 /////////////////////////////////////////////////////////////////////////////// | 157 /////////////////////////////////////////////////////////////////////////////// |
146 | 158 |
147 void SkTypeface::serialize(SkWStream* wstream) const { | 159 void SkTypeface::serialize(SkWStream* wstream) const { |
148 bool isLocal = false; | 160 bool isLocal = false; |
149 SkFontDescriptor desc(this->style()); | 161 SkFontDescriptor desc(this->style()); |
150 this->onGetFontDescriptor(&desc, &isLocal); | 162 this->onGetFontDescriptor(&desc, &isLocal); |
151 | 163 |
152 desc.serialize(wstream); | 164 desc.serialize(wstream); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 306 } |
295 return result; | 307 return result; |
296 } | 308 } |
297 | 309 |
298 /////////////////////////////////////////////////////////////////////////////// | 310 /////////////////////////////////////////////////////////////////////////////// |
299 | 311 |
300 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, | 312 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
301 int32_t adjustments[]) const { | 313 int32_t adjustments[]) const { |
302 return false; | 314 return false; |
303 } | 315 } |
OLD | NEW |