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

Side by Side Diff: src/ports/SkFontHost_fontconfig.cpp

Issue 936893002: Clarify desired behavior of FontConfigTypeface::LegacyCreateTypeface. (Closed) Base URL: https://skia.googlesource.com/skia.git@typefacecache
Patch Set: Line wrapping. Created 5 years, 10 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/ports/SkFontConfigTypeface.h ('k') | no next file » | 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 2008 Google Inc. 2 * Copyright 2008 Google Inc.
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 "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 // export this to SkFontMgr_fontconfig.cpp until this file just goes away. 54 // export this to SkFontMgr_fontconfig.cpp until this file just goes away.
55 SkFontConfigInterface* SkFontHost_fontconfig_ref_global(); 55 SkFontConfigInterface* SkFontHost_fontconfig_ref_global();
56 SkFontConfigInterface* SkFontHost_fontconfig_ref_global() { 56 SkFontConfigInterface* SkFontHost_fontconfig_ref_global() {
57 return RefFCI(); 57 return RefFCI();
58 } 58 }
59 59
60 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
61 61
62 struct FindRec { 62 struct NameStyle {
63 FindRec(const char* name, const SkFontStyle& style) 63 NameStyle(const char* name, const SkFontStyle& style)
64 : fFamilyName(name) // don't need to make a deep copy 64 : fFamilyName(name) // don't need to make a deep copy
65 , fStyle(style) {} 65 , fStyle(style) {}
66 66
67 const char* fFamilyName; 67 const char* fFamilyName;
68 SkFontStyle fStyle; 68 SkFontStyle fStyle;
69 }; 69 };
70 70
71 static bool find_proc(SkTypeface* cachedTypeface, const SkFontStyle& cachedStyle , void* ctx) { 71 static bool find_by_NameStyle(SkTypeface* cachedTypeface,
72 FontConfigTypeface* cachedFCTypeface = (FontConfigTypeface*)cachedTypeface; 72 const SkFontStyle& cachedStyle,
73 const FindRec* rec = static_cast<const FindRec*>(ctx); 73 void* ctx)
74 {
75 FontConfigTypeface* cachedFCTypeface = static_cast<FontConfigTypeface*>(cach edTypeface);
76 const NameStyle* nameStyle = static_cast<const NameStyle*>(ctx);
74 77
75 return rec->fStyle == cachedStyle && 78 return nameStyle->fStyle == cachedStyle &&
76 cachedFCTypeface->isFamilyName(rec->fFamilyName); 79 cachedFCTypeface->isFamilyName(nameStyle->fFamilyName);
77 } 80 }
78 81
79 SkTypeface* FontConfigTypeface::LegacyCreateTypeface( 82 static bool find_by_FontIdentity(SkTypeface* cachedTypeface, const SkFontStyle&, void* ctx) {
80 const SkTypeface* familyFace, 83 typedef SkFontConfigInterface::FontIdentity FontIdentity;
81 const char familyName[], 84 FontConfigTypeface* cachedFCTypeface = static_cast<FontConfigTypeface*>(cach edTypeface);
82 SkTypeface::Style style) { 85 FontIdentity* indentity = static_cast<FontIdentity*>(ctx);
86
87 return cachedFCTypeface->getIdentity() == *indentity;
88 }
89
90 SkTypeface* FontConfigTypeface::LegacyCreateTypeface(const char familyName[],
91 SkTypeface::Style style)
92 {
83 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 93 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
84 if (NULL == fci.get()) { 94 if (NULL == fci.get()) {
85 return NULL; 95 return NULL;
86 } 96 }
87 97
88 SkString familyFaceName; 98 // Check if requested NameStyle is in the NameStyle cache.
89 if (familyFace) {
90 familyFace->getFamilyName(&familyFaceName);
91 familyName = familyFaceName.c_str();
92 }
93
94 SkFontStyle requestedStyle(style); 99 SkFontStyle requestedStyle(style);
95 FindRec rec(familyName, requestedStyle); 100 NameStyle nameStyle(familyName, requestedStyle);
96 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); 101 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &nam eStyle);
97 if (face) { 102 if (face) {
98 //SkDebugf("found cached face <%s> <%s> %p [%d]\n", 103 //SkDebugf("found cached face <%s> <%s> %p [%d]\n",
99 // familyName, ((FontConfigTypeface*)face)->getFamilyName(), 104 // familyName, ((FontConfigTypeface*)face)->getFamilyName(),
100 // face, face->getRefCnt()); 105 // face, face->getRefCnt());
101 return face; 106 return face;
102 } 107 }
103 108
104 SkFontConfigInterface::FontIdentity indentity; 109 SkFontConfigInterface::FontIdentity indentity;
105 SkString outFamilyName; 110 SkString outFamilyName;
106 SkTypeface::Style outStyle; 111 SkTypeface::Style outStyle;
107 if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &ou tStyle)) { 112 if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &ou tStyle)) {
108 return NULL; 113 return NULL;
109 } 114 }
110 115
111 // check if we, in fact, already have this. perhaps fontconfig aliased the 116 // Check if a typeface with this FontIdentity is already in the FontIdentity cache.
112 // requested name to some other name we actually have... 117 face = SkTypefaceCache::FindByProcAndRef(find_by_FontIdentity, &indentity);
113 rec.fFamilyName = outFamilyName.c_str(); 118 if (!face) {
114 rec.fStyle = SkFontStyle(outStyle); 119 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outF amilyName);
115 face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); 120 // Add this FontIdentity to the FontIdentity cache.
116 if (face) { 121 SkTypefaceCache::Add(face, requestedStyle);
117 return face;
118 } 122 }
123 // TODO: Ensure requested NameStyle and resolved NameStyle are both in the N ameStyle cache.
119 124
120 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outFamil yName);
121 SkTypefaceCache::Add(face, requestedStyle);
122 //SkDebugf("add face <%s> <%s> %p [%d]\n", 125 //SkDebugf("add face <%s> <%s> %p [%d]\n",
123 // familyName, outFamilyName.c_str(), 126 // familyName, outFamilyName.c_str(),
124 // face, face->getRefCnt()); 127 // face, face->getRefCnt());
125 return face; 128 return face;
126 } 129 }
127 130
128 /////////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////////
129 132
130 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const { 133 SkStreamAsset* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
131 SkStreamAsset* stream = this->getLocalStream(); 134 SkStreamAsset* stream = this->getLocalStream();
(...skipping 17 matching lines...) Expand all
149 } 152 }
150 153
151 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 154 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
152 bool* isLocalStream) const { 155 bool* isLocalStream) const {
153 SkString name; 156 SkString name;
154 this->getFamilyName(&name); 157 this->getFamilyName(&name);
155 desc->setFamilyName(name.c_str()); 158 desc->setFamilyName(name.c_str());
156 desc->setFontIndex(this->getIdentity().fTTCIndex); 159 desc->setFontIndex(this->getIdentity().fTTCIndex);
157 *isLocalStream = SkToBool(this->getLocalStream()); 160 *isLocalStream = SkToBool(this->getLocalStream());
158 } 161 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698