Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: src/core/SkTypeface.cpp

Issue 1818043002: SkTypeface::MakeFromName to take SkFontStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: CL rebased. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkTypeface.h ('k') | src/utils/SkWhitelistTypefaces.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef SK_DONT_USE_LEGACY_TYPEFACE_MAKE_FROM_NAME
31 sk_sp<SkTypeface>(*gCreateTypefaceDelegate)(const char[], SkTypeface::Style styl e) = nullptr;
32 #endif
33 sk_sp<SkTypeface> (*gNewCreateTypefaceDelegate)(const char[], SkFontStyle) = nul lptr;
bungeman-skia 2016/05/24 14:49:26 Only Skia uses this gCreateTypefaceDelegate, and o
Mikus 2016/05/24 15:22:26 Done. Seems to me that the 'new' version is not ne
34
31 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; 35 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE;
32 sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; 36 sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
33 37
34 /////////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////////
35 39
36 namespace { 40 namespace {
37 41
38 class SkEmptyTypeface : public SkTypeface { 42 class SkEmptyTypeface : public SkTypeface {
39 public: 43 public:
40 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } 44 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 112 }
109 return face->uniqueID(); 113 return face->uniqueID();
110 } 114 }
111 115
112 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { 116 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
113 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); 117 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb);
114 } 118 }
115 119
116 /////////////////////////////////////////////////////////////////////////////// 120 ///////////////////////////////////////////////////////////////////////////////
117 121
122 #ifndef SK_DONT_USE_LEGACY_TYPEFACE_MAKE_FROM_NAME
118 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) { 123 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) {
119 if (gCreateTypefaceDelegate) { 124 if (gCreateTypefaceDelegate) {
120 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style); 125 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style);
121 if (result) { 126 if (result) {
122 return result; 127 return result;
123 } 128 }
124 } 129 }
125 if (nullptr == name) { 130 if (nullptr == name) {
126 return MakeDefault(style); 131 return MakeDefault(style);
127 } 132 }
128 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 133 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
129 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOld Style(style))); 134 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOld Style(style)));
130 } 135 }
136 #endif
137
138 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[],
139 SkFontStyle fontStyle) {
140 if (gCreateTypefaceDelegate) {
141 sk_sp<SkTypeface> result = (*gNewCreateTypefaceDelegate)(name, fontStyle );
142 if (result) {
143 return result;
144 }
145 }
146 if (nullptr == name) {
bungeman-skia 2016/05/24 14:49:26 MakeDefault is just for caching common requests, a
Mikus 2016/05/24 15:22:26 Done.
147 return MakeDefault(static_cast<Style>((fontStyle.slant() == SkFontStyle: :kItalic_Slant ? kItalic : kNormal) |
bungeman-skia 2016/05/24 14:49:26 nit (here and a few other places): Skia allows 100
Mikus 2016/05/24 15:22:26 Done.
148 (fontStyle.weight() >= SkFontStyle ::kBold_Weight ? kBold : kNormal)));
149 }
150 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
151 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, fontStyle));
152 }
131 153
132 sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) { 154 sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
133 if (!family) { 155 if (!family) {
134 return SkTypeface::MakeDefault(s); 156 return SkTypeface::MakeDefault(s);
135 } 157 }
136 158
137 if (family->style() == s) { 159 if (family->style() == s) {
138 return sk_ref_sp(family); 160 return sk_ref_sp(family);
139 } 161 }
140 162
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return nullptr; 207 return nullptr;
186 } 208 }
187 209
188 SkFontData* data = desc.detachFontData(); 210 SkFontData* data = desc.detachFontData();
189 if (data) { 211 if (data) {
190 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); 212 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
191 if (typeface) { 213 if (typeface) {
192 return typeface; 214 return typeface;
193 } 215 }
194 } 216 }
195 return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle()); 217
218 return SkTypeface::MakeFromName(desc.getFamilyName(), SkFontStyle::FromOldSt yle(desc.getStyle()));
196 } 219 }
197 220
198 /////////////////////////////////////////////////////////////////////////////// 221 ///////////////////////////////////////////////////////////////////////////////
199 222
200 int SkTypeface::countTables() const { 223 int SkTypeface::countTables() const {
201 return this->onGetTableTags(nullptr); 224 return this->onGetTableTags(nullptr);
202 } 225 }
203 226
204 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { 227 int SkTypeface::getTableTags(SkFontTableTag tags[]) const {
205 return this->onGetTableTags(tags); 228 return this->onGetTableTags(tags);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true)); 373 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true));
351 if (ctx.get()) { 374 if (ctx.get()) {
352 SkPaint::FontMetrics fm; 375 SkPaint::FontMetrics fm;
353 ctx->getFontMetrics(&fm); 376 ctx->getFontMetrics(&fm);
354 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 377 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
355 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 378 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
356 return true; 379 return true;
357 } 380 }
358 return false; 381 return false;
359 } 382 }
OLDNEW
« no previous file with comments | « include/core/SkTypeface.h ('k') | src/utils/SkWhitelistTypefaces.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698