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

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: Android fix + nit fix Created 4 years, 6 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 | « samplecode/SampleXfermodesBlur.cpp ('k') | src/fonts/SkTestScalerContext.h » ('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 sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char[], SkFontStyle) = nullpt r;
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
38 class SkEmptyTypeface : public SkTypeface { 39 class SkEmptyTypeface : public SkTypeface {
39 public: 40 public:
40 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } 41 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 102 }
102 return face->uniqueID(); 103 return face->uniqueID();
103 } 104 }
104 105
105 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { 106 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
106 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); 107 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb);
107 } 108 }
108 109
109 /////////////////////////////////////////////////////////////////////////////// 110 ///////////////////////////////////////////////////////////////////////////////
110 111
112 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_MAKE_FROM_NAME
111 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) { 113 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) {
114 return MakeFromName(name, SkFontStyle::FromOldStyle(style));
115 }
116 #endif
117
118 sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[],
119 SkFontStyle fontStyle) {
112 if (gCreateTypefaceDelegate) { 120 if (gCreateTypefaceDelegate) {
113 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style); 121 sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, fontStyle);
114 if (result) { 122 if (result) {
115 return result; 123 return result;
116 } 124 }
117 } 125 }
118 if (nullptr == name) { 126 if (nullptr == name && (fontStyle.slant() == SkFontStyle::kItalic_Slant ||
119 return MakeDefault(style); 127 fontStyle.slant() == SkFontStyle::kUpright_Slant) &&
128 (fontStyle.weight() == SkFontStyle::kBold_Weight ||
129 fontStyle.weight() == SkFontStyle::kNormal_Weight)) {
130 return MakeDefault(static_cast<SkTypeface::Style>(
131 (fontStyle.slant() == SkFontStyle::kItalic_Slant ? SkTypeface::kItal ic :
132 SkTypeface::kNorm al) |
133 (fontStyle.weight() == SkFontStyle::kBold_Weight ? SkTypeface::kBold :
134 SkTypeface::kNorm al)));
120 } 135 }
121 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 136 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
122 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOld Style(style))); 137 return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, fontStyle));
123 } 138 }
124 139
125 sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) { 140 sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
126 if (!family) { 141 if (!family) {
127 return SkTypeface::MakeDefault(s); 142 return SkTypeface::MakeDefault(s);
128 } 143 }
129 144
130 if (family->style() == s) { 145 if (family->style() == s) {
131 return sk_ref_sp(family); 146 return sk_ref_sp(family);
132 } 147 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return nullptr; 193 return nullptr;
179 } 194 }
180 195
181 SkFontData* data = desc.detachFontData(); 196 SkFontData* data = desc.detachFontData();
182 if (data) { 197 if (data) {
183 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); 198 sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
184 if (typeface) { 199 if (typeface) {
185 return typeface; 200 return typeface;
186 } 201 }
187 } 202 }
188 return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle()); 203
204 return SkTypeface::MakeFromName(desc.getFamilyName(),
205 SkFontStyle::FromOldStyle(desc.getStyle()));
189 } 206 }
190 207
191 /////////////////////////////////////////////////////////////////////////////// 208 ///////////////////////////////////////////////////////////////////////////////
192 209
193 int SkTypeface::countTables() const { 210 int SkTypeface::countTables() const {
194 return this->onGetTableTags(nullptr); 211 return this->onGetTableTags(nullptr);
195 } 212 }
196 213
197 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { 214 int SkTypeface::getTableTags(SkFontTableTag tags[]) const {
198 return this->onGetTableTags(tags); 215 return this->onGetTableTags(tags);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true)); 360 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true));
344 if (ctx.get()) { 361 if (ctx.get()) {
345 SkPaint::FontMetrics fm; 362 SkPaint::FontMetrics fm;
346 ctx->getFontMetrics(&fm); 363 ctx->getFontMetrics(&fm);
347 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 364 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
348 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 365 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
349 return true; 366 return true;
350 } 367 }
351 return false; 368 return false;
352 } 369 }
OLDNEW
« no previous file with comments | « samplecode/SampleXfermodesBlur.cpp ('k') | src/fonts/SkTestScalerContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698