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

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

Issue 1905253002: Implement matchFamilyStyle for SkFontMgr_fontconfig (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/fonts/SkFontMgr_fontconfig.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"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // CreateTypeface is happening at any given time. 89 // CreateTypeface is happening at any given time.
90 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? 90 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe?
91 SkAutoMutexAcquire lock(&gCreateDefaultMutex); 91 SkAutoMutexAcquire lock(&gCreateDefaultMutex);
92 92
93 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 93 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
94 SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldSt yle(style)); 94 SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldSt yle(style));
95 return t ? t : SkEmptyTypeface::Create(); 95 return t ? t : SkEmptyTypeface::Create();
96 }); 96 });
97 } 97 }
98 98
99 SkTypeface* SkTypeface::GetDefaultTypeface(SkFontStyle style) {
100 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
101 SkTypeface* t = fm->matchFamilyStyle(nullptr, style);
102 return t ? t : SkEmptyTypeface::Create();
103 }
104
99 SkTypeface* SkTypeface::RefDefault(Style style) { 105 SkTypeface* SkTypeface::RefDefault(Style style) {
100 return SkRef(GetDefaultTypeface(style)); 106 return SkRef(GetDefaultTypeface(style));
101 } 107 }
102 108
109 SkTypeface* SkTypeface::RefDefault(SkFontStyle style) {
110 return SkRef(GetDefaultTypeface(style));
111 }
112
103 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { 113 uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
104 if (nullptr == face) { 114 if (nullptr == face) {
105 face = GetDefaultTypeface(); 115 face = GetDefaultTypeface();
106 } 116 }
107 return face->uniqueID(); 117 return face->uniqueID();
108 } 118 }
109 119
110 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { 120 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
111 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); 121 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb);
112 } 122 }
113 123
114 /////////////////////////////////////////////////////////////////////////////// 124 ///////////////////////////////////////////////////////////////////////////////
115 125
116 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { 126 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
117 if (gCreateTypefaceDelegate) { 127 if (gCreateTypefaceDelegate) {
118 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style); 128 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style);
119 if (result) { 129 if (result) {
120 return result; 130 return result;
121 } 131 }
122 } 132 }
123 if (nullptr == name) { 133 if (nullptr == name) {
124 return RefDefault(style); 134 return RefDefault(style);
125 } 135 }
126 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 136 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
127 return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)); 137 return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style));
128 } 138 }
129 139
140 SkTypeface* SkTypeface::CreateFromName(const char name[], SkFontStyle style) {
141 if (nullptr == name) {
142 return RefDefault(style);
143 }
144 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
145 return fm->matchFamilyStyle(name, style);
146 }
147
130 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { 148 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
131 if (!family) { 149 if (!family) {
132 return SkTypeface::RefDefault(s); 150 return SkTypeface::RefDefault(s);
133 } 151 }
134 152
135 if (family->style() == s) { 153 if (family->style() == s) {
136 family->ref(); 154 family->ref();
137 return const_cast<SkTypeface*>(family); 155 return const_cast<SkTypeface*>(family);
138 } 156 }
139 157
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true)); 375 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true));
358 if (ctx.get()) { 376 if (ctx.get()) {
359 SkPaint::FontMetrics fm; 377 SkPaint::FontMetrics fm;
360 ctx->getFontMetrics(&fm); 378 ctx->getFontMetrics(&fm);
361 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 379 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
362 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 380 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
363 return true; 381 return true;
364 } 382 }
365 return false; 383 return false;
366 } 384 }
OLDNEW
« no previous file with comments | « include/core/SkTypeface.h ('k') | src/fonts/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698