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 "SkOnce.h" | 14 #include "SkOnce.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 sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr; | 30 sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char[], SkTypeface::Style) = nullptr; |
31 | |
31 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; | 32 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; |
32 sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; | 33 sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; |
33 | 34 |
34 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
39 bool UsesOnlyItalicOrBoldStyling(SkFontStyle style) { | |
bungeman-skia
2016/05/24 15:29:11
I would prefer not to give this a name and staying
Mikus
2016/05/25 10:57:25
Done.
| |
40 return (style.slant() == SkFontStyle::kItalic_Slant || | |
41 style.slant() == SkFontStyle::kUpright_Slant) && | |
42 (style.weight() == SkFontStyle::kBold_Weight || | |
43 style.weight() == SkFontStyle::kNormal_Weight); | |
44 } | |
45 | |
46 SkTypeface::Style ToSkTypefaceStyle(SkFontStyle style) { | |
47 return static_cast<SkTypeface::Style>( | |
48 (style.slant() == SkFontStyle::kItalic_Slant ? SkTypeface::kItalic : SkTyp eface::kNormal) | | |
49 (style.weight() >= SkFontStyle::kBold_Weight ? SkTypeface::kBold : SkTypef ace::kNormal)); | |
50 } | |
51 | |
38 class SkEmptyTypeface : public SkTypeface { | 52 class SkEmptyTypeface : public SkTypeface { |
39 public: | 53 public: |
40 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } | 54 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } |
41 protected: | 55 protected: |
42 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } | 56 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } |
43 | 57 |
44 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; } | 58 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; } |
45 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, | 59 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, |
46 const SkDescriptor*) const override { | 60 const SkDescriptor*) const override { |
47 return nullptr; | 61 return nullptr; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 } | 122 } |
109 return face->uniqueID(); | 123 return face->uniqueID(); |
110 } | 124 } |
111 | 125 |
112 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { | 126 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { |
113 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); | 127 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); |
114 } | 128 } |
115 | 129 |
116 /////////////////////////////////////////////////////////////////////////////// | 130 /////////////////////////////////////////////////////////////////////////////// |
117 | 131 |
132 #ifndef SK_DONT_USE_LEGACY_TYPEFACE_MAKE_FROM_NAME | |
bungeman-skia
2016/05/24 17:45:44
Usually we would add a define to Chromium to keep
Mikus
2016/05/25 10:57:25
Done.
| |
118 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) { | 133 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) { |
119 if (gCreateTypefaceDelegate) { | 134 if (gCreateTypefaceDelegate) { |
bungeman-skia
2016/05/24 17:45:44
Since the intent is to make this go away in the en
Mikus
2016/05/25 10:57:25
Done.
| |
120 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style); | 135 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style); |
121 if (result) { | 136 if (result) { |
122 return result; | 137 return result; |
123 } | 138 } |
124 } | 139 } |
125 if (nullptr == name) { | 140 if (nullptr == name) { |
126 return MakeDefault(style); | 141 return MakeDefault(style); |
127 } | 142 } |
128 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 143 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
129 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOld Style(style))); | 144 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOld Style(style))); |
130 } | 145 } |
146 #endif | |
147 | |
148 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], | |
149 SkFontStyle fontStyle) { | |
150 if (gCreateTypefaceDelegate && UsesOnlyItalicOrBoldStyling(fontStyle)) { | |
bungeman-skia
2016/05/24 15:29:11
Far from adding to this hack, we need to make it e
Mikus
2016/05/25 10:57:25
Done.
| |
151 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, ToSkTypeface Style(fontStyle)); | |
152 if (result) { | |
153 return result; | |
154 } | |
155 } | |
156 if (nullptr == name && UsesOnlyItalicOrBoldStyling(fontStyle)) { | |
157 return MakeDefault(ToSkTypefaceStyle(fontStyle)); | |
158 } | |
159 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | |
160 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, fontStyle)); | |
161 } | |
131 | 162 |
132 sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) { | 163 sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) { |
133 if (!family) { | 164 if (!family) { |
134 return SkTypeface::MakeDefault(s); | 165 return SkTypeface::MakeDefault(s); |
135 } | 166 } |
136 | 167 |
137 if (family->style() == s) { | 168 if (family->style() == s) { |
138 return sk_ref_sp(family); | 169 return sk_ref_sp(family); |
139 } | 170 } |
140 | 171 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 return nullptr; | 216 return nullptr; |
186 } | 217 } |
187 | 218 |
188 SkFontData* data = desc.detachFontData(); | 219 SkFontData* data = desc.detachFontData(); |
189 if (data) { | 220 if (data) { |
190 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); | 221 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); |
191 if (typeface) { | 222 if (typeface) { |
192 return typeface; | 223 return typeface; |
193 } | 224 } |
194 } | 225 } |
195 return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle()); | 226 |
227 return SkTypeface::MakeFromName(desc.getFamilyName(), | |
228 SkFontStyle::FromOldStyle(desc.getStyle())); | |
196 } | 229 } |
197 | 230 |
198 /////////////////////////////////////////////////////////////////////////////// | 231 /////////////////////////////////////////////////////////////////////////////// |
199 | 232 |
200 int SkTypeface::countTables() const { | 233 int SkTypeface::countTables() const { |
201 return this->onGetTableTags(nullptr); | 234 return this->onGetTableTags(nullptr); |
202 } | 235 } |
203 | 236 |
204 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { | 237 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { |
205 return this->onGetTableTags(tags); | 238 return this->onGetTableTags(tags); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true)); | 383 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true)); |
351 if (ctx.get()) { | 384 if (ctx.get()) { |
352 SkPaint::FontMetrics fm; | 385 SkPaint::FontMetrics fm; |
353 ctx->getFontMetrics(&fm); | 386 ctx->getFontMetrics(&fm); |
354 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, | 387 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, |
355 fm.fXMax * invTextSize, fm.fBottom * invTextSize); | 388 fm.fXMax * invTextSize, fm.fBottom * invTextSize); |
356 return true; | 389 return true; |
357 } | 390 } |
358 return false; | 391 return false; |
359 } | 392 } |
OLD | NEW |