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

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

Issue 1317913005: whitelist fallback typefaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove string change Created 5 years, 3 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
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 "SkLazyPtr.h" 12 #include "SkLazyPtr.h"
13 #include "SkMutex.h" 13 #include "SkMutex.h"
14 #include "SkOTTable_OS_2.h" 14 #include "SkOTTable_OS_2.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
24 extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
25 #define SK_TYPEFACE_DELEGATE WhitelistSerializeTypeface
26 #else
27 #define SK_TYPEFACE_DELEGATE nullptr
28 #endif
23 29
24 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = null ptr; 30 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = null ptr;
31 void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE _DELEGATE;
32 SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
25 33
26 /////////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////////
27 35
28 class SkEmptyTypeface : public SkTypeface { 36 class SkEmptyTypeface : public SkTypeface {
29 public: 37 public:
30 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } 38 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
31 protected: 39 protected:
32 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } 40 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { }
33 41
34 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; } 42 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 165 }
158 166
159 SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) { 167 SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
160 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 168 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
161 return fm->createFromFile(path, index); 169 return fm->createFromFile(path, index);
162 } 170 }
163 171
164 /////////////////////////////////////////////////////////////////////////////// 172 ///////////////////////////////////////////////////////////////////////////////
165 173
166 void SkTypeface::serialize(SkWStream* wstream) const { 174 void SkTypeface::serialize(SkWStream* wstream) const {
175 if (gSerializeTypefaceDelegate) {
176 (*gSerializeTypefaceDelegate)(this, wstream);
177 return;
178 }
167 bool isLocal = false; 179 bool isLocal = false;
168 SkFontDescriptor desc(this->style()); 180 SkFontDescriptor desc(this->style());
169 this->onGetFontDescriptor(&desc, &isLocal); 181 this->onGetFontDescriptor(&desc, &isLocal);
170 182
171 // Embed font data if it's a local font. 183 // Embed font data if it's a local font.
172 if (isLocal && !desc.hasFontData()) { 184 if (isLocal && !desc.hasFontData()) {
173 desc.setFontData(this->onCreateFontData()); 185 desc.setFontData(this->onCreateFontData());
174 } 186 }
175 desc.serialize(wstream); 187 desc.serialize(wstream);
176 } 188 }
177 189
178 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const {
179 bool ignoredIsLocal;
180 SkFontDescriptor desc(this->style());
181 this->onGetFontDescriptor(&desc, &ignoredIsLocal);
182
183 // Always embed font data.
184 if (!desc.hasFontData()) {
185 desc.setFontData(this->onCreateFontData());
186 }
187 desc.serialize(wstream);
188 }
189
190 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { 190 SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
191 if (gDeserializeTypefaceDelegate) {
192 return (*gDeserializeTypefaceDelegate)(stream);
193 }
191 SkFontDescriptor desc(stream); 194 SkFontDescriptor desc(stream);
192 SkFontData* data = desc.detachFontData(); 195 SkFontData* data = desc.detachFontData();
193 if (data) { 196 if (data) {
194 SkTypeface* typeface = SkTypeface::CreateFromFontData(data); 197 SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
195 if (typeface) { 198 if (typeface) {
196 return typeface; 199 return typeface;
197 } 200 }
198 } 201 }
199 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); 202 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
200 } 203 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (ctx.get()) { 366 if (ctx.get()) {
364 SkPaint::FontMetrics fm; 367 SkPaint::FontMetrics fm;
365 ctx->getFontMetrics(&fm); 368 ctx->getFontMetrics(&fm);
366 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, 369 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize,
367 fm.fXMax * invTextSize, fm.fBottom * invTextSize); 370 fm.fXMax * invTextSize, fm.fBottom * invTextSize);
368 return true; 371 return true;
369 } 372 }
370 return false; 373 return false;
371 } 374 }
372 375
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698