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

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

Issue 1873923002: Begin switch to SkFontStyle for legacy calls. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Dont update bzl file now. 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 | « src/core/SkFontStyle.cpp ('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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { 80 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
81 SkASSERT((int)style < 4); 81 SkASSERT((int)style < 4);
82 return defaults[style].get([=]{ 82 return defaults[style].get([=]{
83 // It is not safe to call FontConfigTypeface::LegacyCreateTypeface concu rrently. 83 // It is not safe to call FontConfigTypeface::LegacyCreateTypeface concu rrently.
84 // To be safe, we serialize here with a mutex so only one call to 84 // To be safe, we serialize here with a mutex so only one call to
85 // CreateTypeface is happening at any given time. 85 // CreateTypeface is happening at any given time.
86 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? 86 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe?
87 SkAutoMutexAcquire lock(&gCreateDefaultMutex); 87 SkAutoMutexAcquire lock(&gCreateDefaultMutex);
88 88
89 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 89 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
90 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE
90 SkTypeface* t = fm->legacyCreateTypeface(nullptr, style); 91 SkTypeface* t = fm->legacyCreateTypeface(nullptr, style);
92 #else
93 SkTypeface* t = fm->legacyCreateTypeface(nullptr, SkFontStyle::FromOldSt yle(style));
94 #endif
91 return t ? t : SkEmptyTypeface::Create(); 95 return t ? t : SkEmptyTypeface::Create();
92 }); 96 });
93 } 97 }
94 98
95 SkTypeface* SkTypeface::RefDefault(Style style) { 99 SkTypeface* SkTypeface::RefDefault(Style style) {
96 return SkRef(GetDefaultTypeface(style)); 100 return SkRef(GetDefaultTypeface(style));
97 } 101 }
98 102
99 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { 103 uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
100 if (nullptr == face) { 104 if (nullptr == face) {
(...skipping 12 matching lines...) Expand all
113 if (gCreateTypefaceDelegate) { 117 if (gCreateTypefaceDelegate) {
114 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style); 118 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style);
115 if (result) { 119 if (result) {
116 return result; 120 return result;
117 } 121 }
118 } 122 }
119 if (nullptr == name) { 123 if (nullptr == name) {
120 return RefDefault(style); 124 return RefDefault(style);
121 } 125 }
122 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 126 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
127 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE
123 return fm->legacyCreateTypeface(name, style); 128 return fm->legacyCreateTypeface(name, style);
129 #else
130 return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style));
131 #endif
124 } 132 }
125 133
126 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { 134 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
127 if (!family) { 135 if (!family) {
128 return SkTypeface::RefDefault(s); 136 return SkTypeface::RefDefault(s);
129 } 137 }
130 138
131 if (family->style() == s) { 139 if (family->style() == s) {
132 family->ref(); 140 family->ref();
133 return const_cast<SkTypeface*>(family); 141 return const_cast<SkTypeface*>(family);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true)); 361 SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc , true));
354 if (ctx.get()) { 362 if (ctx.get()) {
355 SkPaint::FontMetrics fm; 363 SkPaint::FontMetrics fm;
356 ctx->getFontMetrics(&fm); 364 ctx->getFontMetrics(&fm);
357 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 365 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
358 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 366 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
359 return true; 367 return true;
360 } 368 }
361 return false; 369 return false;
362 } 370 }
OLDNEW
« no previous file with comments | « src/core/SkFontStyle.cpp ('k') | src/fonts/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698