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

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

Issue 16439004: Fix issues related to resolving fonts based on name. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« src/core/SkTypeface.cpp ('K') | « src/core/SkTypeface.cpp ('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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 SkTypeface::Style fStyle; 65 SkTypeface::Style fStyle;
66 }; 66 };
67 67
68 static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) { 68 static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) {
69 FontConfigTypeface* fci = (FontConfigTypeface*)face; 69 FontConfigTypeface* fci = (FontConfigTypeface*)face;
70 const FindRec* rec = (const FindRec*)ctx; 70 const FindRec* rec = (const FindRec*)ctx;
71 71
72 return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName); 72 return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName);
73 } 73 }
74 74
75 static bool find_proc_by_id(SkTypeface* face, SkTypeface::Style style, void* ctx ) {
76 const uint32_t* fontID = (const uint32_t*)ctx;
77 uint32_t currFontID = ((FontConfigTypeface*)face)->getIdentity().fID;
78 return currFontID == *fontID;
79 }
80
75 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 81 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
76 const char familyName[], 82 const char familyName[],
77 SkTypeface::Style style) { 83 SkTypeface::Style style) {
78 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 84 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
79 if (NULL == fci.get()) { 85 if (NULL == fci.get()) {
80 return NULL; 86 return NULL;
81 } 87 }
82 88
83 if (familyFace) { 89 if (familyFace) {
84 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; 90 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace;
85 familyName = fct->getFamilyName(); 91 familyName = fct->getFamilyName();
86 } 92 }
87 93
88 FindRec rec(familyName, style); 94 FindRec rec(familyName, style);
89 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); 95 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec);
90 if (face) { 96 if (face) {
91 // SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontCo nfigTypeface*)face)->getFamilyName(), face, face->getRefCnt()); 97 // SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontCo nfigTypeface*)face)->getFamilyName(), face, face->getRefCnt());
92 return face; 98 return face;
93 } 99 }
94 100
95 SkFontConfigInterface::FontIdentity indentity; 101 SkFontConfigInterface::FontIdentity identity;
96 SkString outFamilyName; 102 SkString outFamilyName;
97 SkTypeface::Style outStyle; 103 SkTypeface::Style outStyle;
98 104
99 if (!fci->matchFamilyName(familyName, style, 105 if (!fci->matchFamilyName(familyName, style,
100 &indentity, &outFamilyName, &outStyle)) { 106 &identity, &outFamilyName, &outStyle)) {
101 return NULL; 107 return NULL;
102 } 108 }
103 109
104 face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); 110 face = SkTypefaceCache::FindByProcAndRef(find_proc_by_id, &identity.fID);
reed1 2013/06/05 13:23:57 this may be correct, but is it strictly needed for
djsollen 2013/06/05 13:51:59 No this is still needed. If an app asks for a font
111 if (face) {
112 return face;
113 }
114
115 face = SkNEW_ARGS(FontConfigTypeface, (outStyle, identity, outFamilyName));
105 SkTypefaceCache::Add(face, style); 116 SkTypefaceCache::Add(face, style);
106 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str() , face, face->getRefCnt()); 117 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str() , face, face->getRefCnt());
107 return face; 118 return face;
108 } 119 }
109 120
110 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 121 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
111 if (!stream) { 122 if (!stream) {
112 return NULL; 123 return NULL;
113 } 124 }
114 const size_t length = stream->getLength(); 125 const size_t length = stream->getLength();
115 if (!length) { 126 if (!length) {
116 return NULL; 127 return NULL;
117 } 128 }
118 if (length >= 1024 * 1024 * 1024) { 129 if (length >= 1024 * 1024 * 1024) {
119 return NULL; // don't accept too large fonts (>= 1GB) for safety. 130 return NULL; // don't accept too large fonts (>= 1GB) for safety.
120 } 131 }
121 132
122 // TODO should the caller give us the style? 133 // TODO should the caller give us the style?
123 SkTypeface::Style style = SkTypeface::kNormal; 134 SkTypeface::Style style = SkTypeface::kNormal;
124 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream)); 135 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream));
125 SkTypefaceCache::Add(face, style);
126 return face; 136 return face;
127 } 137 }
128 138
129 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 139 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
130 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 140 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
131 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; 141 return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
132 } 142 }
133 143
134 /////////////////////////////////////////////////////////////////////////////// 144 ///////////////////////////////////////////////////////////////////////////////
135 145
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 : 0; 199 : 0;
190 } 200 }
191 201
192 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 202 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
193 bool* isLocalStream) const { 203 bool* isLocalStream) const {
194 desc->setFamilyName(this->getFamilyName()); 204 desc->setFamilyName(this->getFamilyName());
195 *isLocalStream = SkToBool(this->getLocalStream()); 205 *isLocalStream = SkToBool(this->getLocalStream());
196 } 206 }
197 207
198 /////////////////////////////////////////////////////////////////////////////// 208 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« src/core/SkTypeface.cpp ('K') | « src/core/SkTypeface.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698