Chromium Code Reviews| 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" |
| 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 "SkOncePtr.h" | 14 #include "SkOncePtr.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 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = null ptr; | 30 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkFontStyle ) = nullptr; |
| 31 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; | 31 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE; |
| 32 SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; | 32 SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; |
| 33 | 33 |
| 34 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
| 35 | 35 |
| 36 class SkEmptyTypeface : public SkTypeface { | 36 class SkEmptyTypeface : public SkTypeface { |
| 37 public: | 37 public: |
| 38 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } | 38 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } |
| 39 protected: | 39 protected: |
| 40 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } | 40 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } | 101 } |
| 102 return face->uniqueID(); | 102 return face->uniqueID(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { | 105 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { |
| 106 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); | 106 return facea == faceb || SkTypeface::UniqueID(facea) == SkTypeface::UniqueID (faceb); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /////////////////////////////////////////////////////////////////////////////// | 109 /////////////////////////////////////////////////////////////////////////////// |
| 110 | 110 |
| 111 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { | 111 SkTypeface* SkTypeface::CreateFromName(const char name[], |
| 112 if (gCreateTypefaceDelegate) { | 112 SkFontStyle fontStyle) { |
| 113 SkTypeface* result = (*gCreateTypefaceDelegate)(name, style); | 113 if (gCreateTypefaceDelegate) { |
| 114 if (result) { | 114 SkTypeface* result = (*gCreateTypefaceDelegate)(name, fontStyle); |
| 115 return result; | 115 if (result) { |
| 116 } | 116 return result; |
| 117 } | 117 } |
| 118 if (nullptr == name) { | 118 } |
| 119 return RefDefault(style); | 119 if (nullptr == name) { |
| 120 } | 120 return RefDefault(); |
| 121 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 121 } |
| 122 return fm->legacyCreateTypeface(name, style); | 122 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
| 123 return fm->matchFamilyStyle(name, fontStyle); | |
|
bungeman-skia
2016/03/22 20:16:43
I'm not sure we can make this change directly eith
Mikus
2016/03/23 10:47:17
What do you suggest, then? Should I restore the Cr
Mikus
2016/03/24 12:08:26
I suggest that we roll this and check the test res
| |
| 123 } | 124 } |
| 124 | 125 |
| 126 | |
| 125 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { | 127 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { |
| 126 if (!family) { | 128 if (!family) { |
| 127 return SkTypeface::RefDefault(s); | 129 return SkTypeface::RefDefault(s); |
| 128 } | 130 } |
| 129 | 131 |
| 130 if (family->style() == s) { | 132 if (family->style() == s) { |
| 131 family->ref(); | 133 family->ref(); |
| 132 return const_cast<SkTypeface*>(family); | 134 return const_cast<SkTypeface*>(family); |
| 133 } | 135 } |
| 134 | 136 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 return nullptr; | 188 return nullptr; |
| 187 } | 189 } |
| 188 | 190 |
| 189 SkFontData* data = desc.detachFontData(); | 191 SkFontData* data = desc.detachFontData(); |
| 190 if (data) { | 192 if (data) { |
| 191 SkTypeface* typeface = SkTypeface::CreateFromFontData(data); | 193 SkTypeface* typeface = SkTypeface::CreateFromFontData(data); |
| 192 if (typeface) { | 194 if (typeface) { |
| 193 return typeface; | 195 return typeface; |
| 194 } | 196 } |
| 195 } | 197 } |
| 196 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); | 198 return SkTypeface::CreateFromName(desc.getFamilyName(), |
| 199 SkFontStyle(desc.getStyle())); | |
| 197 } | 200 } |
| 198 | 201 |
| 199 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
| 200 | 203 |
| 201 int SkTypeface::countTables() const { | 204 int SkTypeface::countTables() const { |
| 202 return this->onGetTableTags(nullptr); | 205 return this->onGetTableTags(nullptr); |
| 203 } | 206 } |
| 204 | 207 |
| 205 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { | 208 int SkTypeface::getTableTags(SkFontTableTag tags[]) const { |
| 206 return this->onGetTableTags(tags); | 209 return this->onGetTableTags(tags); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 if (ctx.get()) { | 355 if (ctx.get()) { |
| 353 SkPaint::FontMetrics fm; | 356 SkPaint::FontMetrics fm; |
| 354 ctx->getFontMetrics(&fm); | 357 ctx->getFontMetrics(&fm); |
| 355 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, | 358 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, |
| 356 fm.fXMax * invTextSize, fm.fBottom * invTextSize); | 359 fm.fXMax * invTextSize, fm.fBottom * invTextSize); |
| 357 return true; | 360 return true; |
| 358 } | 361 } |
| 359 return false; | 362 return false; |
| 360 } | 363 } |
| 361 | 364 |
| OLD | NEW |