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 "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkMutex.h" | 12 #include "SkMutex.h" |
13 #include "SkOTTable_OS_2.h" | 13 #include "SkOTTable_OS_2.h" |
14 #include "SkOncePtr.h" | 14 #include "SkOncePtr.h" |
15 #include "SkStream.h" | 15 #include "SkStream.h" |
16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
17 | 17 |
18 SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPi tch) | 18 SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPi tch) |
19 : fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) { } | 19 : fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) { } |
20 | 20 |
21 SkTypeface::~SkTypeface() { } | 21 SkTypeface::~SkTypeface() { } |
22 | 22 |
23 #ifdef SK_WHITELIST_SERIALIZED_TYPEFACES | 23 #ifdef SK_WHITELIST_SERIALIZED_TYPEFACES |
24 extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* ); | 24 extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* ); |
25 #define SK_TYPEFACE_DELEGATE WhitelistSerializeTypeface | 25 #define SK_TYPEFACE_DELEGATE WhitelistSerializeTypeface |
26 #else | 26 #else |
27 #define SK_TYPEFACE_DELEGATE nullptr | 27 #define SK_TYPEFACE_DELEGATE nullptr |
28 #endif | 28 #endif |
29 | 29 |
30 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = null ptr; | 30 #ifndef SK_DONT_USE_LEGACY_TYPEFACE_CREATE_FROM_NAME |
31 SkTypeface* (*gCreateTypefaceDelegate)(const char[], SkTypeface::Style style) = nullptr; | |
32 #endif | |
33 SkTypeface* (*gNewCreateTypefaceDelegate)(const char[], SkFontStyle) = nullptr; | |
31 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; | 34 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; |
32 SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; | 35 SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; |
33 | 36 |
34 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
35 | 38 |
36 class SkEmptyTypeface : public SkTypeface { | 39 class SkEmptyTypeface : public SkTypeface { |
37 public: | 40 public: |
38 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } | 41 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } |
39 protected: | 42 protected: |
40 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } | 43 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 } | 104 } |
102 return face->uniqueID(); | 105 return face->uniqueID(); |
103 } | 106 } |
104 | 107 |
105 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { | 108 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { |
106 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); | 109 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); |
107 } | 110 } |
108 | 111 |
109 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
110 | 113 |
111 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { | 114 #ifndef SK_DONT_USE_LEGACY_TYPEFACE_CREATE_FROM_NAME |
115 SkTypeface* SkTypeface::CreateFromName(const char name[], SkTypeface::Style styl e) { | |
112 if (gCreateTypefaceDelegate) { | 116 if (gCreateTypefaceDelegate) { |
113 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style); | 117 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style); |
114 if (result) { | 118 if (result) { |
115 return result; | 119 return result; |
116 } | 120 } |
117 } | 121 } |
118 if (nullptr == name) { | 122 if (nullptr == name) { |
119 return RefDefault(style); | 123 return RefDefault(style); |
120 } | 124 } |
121 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 125 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
122 return fm->legacyCreateTypeface(name, style); | 126 return fm->legacyCreateTypeface(name, style); |
123 } | 127 } |
128 #endif | |
129 | |
130 SkTypeface* SkTypeface::CreateFromName(const char name[], | |
131 SkFontStyle fontStyle) { | |
132 if (gNewCreateTypefaceDelegate) { | |
133 SkTypeface* result = (*gNewCreateTypefaceDelegate)(name, fontStyle); | |
134 if (result) { | |
135 return result; | |
136 } | |
137 } | |
138 if (nullptr == name) { | |
139 return RefDefault(); | |
140 } | |
141 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | |
142 return fm->matchFamilyStyle(name, fontStyle); | |
bungeman-skia
2016/04/08 18:59:21
I believe Chromium on Linux is currently using an
Mikus
2016/05/19 09:34:02
Maybe I'll disable this for Linux and let the Linu
| |
143 } | |
144 | |
124 | 145 |
125 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { | 146 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { |
126 if (!family) { | 147 if (!family) { |
127 return SkTypeface::RefDefault(s); | 148 return SkTypeface::RefDefault(s); |
128 } | 149 } |
129 | 150 |
130 if (family->style() == s) { | 151 if (family->style() == s) { |
131 family->ref(); | 152 family->ref(); |
132 return const_cast<SkTypeface*>(family); | 153 return const_cast<SkTypeface*>(family); |
133 } | 154 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 return nullptr; | 207 return nullptr; |
187 } | 208 } |
188 | 209 |
189 SkFontData* data = desc.detachFontData(); | 210 SkFontData* data = desc.detachFontData(); |
190 if (data) { | 211 if (data) { |
191 SkTypeface* typeface = SkTypeface::CreateFromFontData(data); | 212 SkTypeface* typeface = SkTypeface::CreateFromFontData(data); |
192 if (typeface) { | 213 if (typeface) { |
193 return typeface; | 214 return typeface; |
194 } | 215 } |
195 } | 216 } |
196 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); | 217 return SkTypeface::CreateFromName(desc.getFamilyName(), |
218 SkFontStyle(desc.getStyle())); | |
197 } | 219 } |
198 | 220 |
199 /////////////////////////////////////////////////////////////////////////////// | 221 /////////////////////////////////////////////////////////////////////////////// |
200 | 222 |
201 int SkTypeface::countTables() const { | 223 int SkTypeface::countTables() const { |
202 return this->onGetTableTags(nullptr); | 224 return this->onGetTableTags(nullptr); |
203 } | 225 } |
204 | 226 |
205 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { | 227 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { |
206 return this->onGetTableTags(tags); | 228 return this->onGetTableTags(tags); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 if (ctx.get()) { | 374 if (ctx.get()) { |
353 SkPaint::FontMetrics fm; | 375 SkPaint::FontMetrics fm; |
354 ctx->getFontMetrics(&fm); | 376 ctx->getFontMetrics(&fm); |
355 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, | 377 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, |
356 fm.fXMax * invTextSize, fm.fBottom * invTextSize); | 378 fm.fXMax * invTextSize, fm.fBottom * invTextSize); |
357 return true; | 379 return true; |
358 } | 380 } |
359 return false; | 381 return false; |
360 } | 382 } |
361 | 383 |
OLD | NEW |