| 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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |