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

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

Issue 12395015: implement fonthost table methods directly in fontconfig backend, _tables now relegated to (Closed) Base URL: http://skia.googlecode.com/svn/
Patch Set: Created 7 years, 9 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
« no previous file with comments | « trunk/gyp/ports.gyp ('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 "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost.h" 10 #include "SkFontHost.h"
11 #include "SkFontStream.h"
11 #include "SkStream.h" 12 #include "SkStream.h"
12 #include "SkTypeface.h" 13 #include "SkTypeface.h"
13 #include "SkTypefaceCache.h" 14 #include "SkTypefaceCache.h"
14 15
15 SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex); 16 SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex);
16 static SkFontConfigInterface* gFontConfigInterface; 17 static SkFontConfigInterface* gFontConfigInterface;
17 18
18 SkFontConfigInterface* SkFontConfigInterface::RefGlobal() { 19 SkFontConfigInterface* SkFontConfigInterface::RefGlobal() {
19 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); 20 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
20 21
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const SkFontConfigInterface::FontIdentity& getIdentity() const { 74 const SkFontConfigInterface::FontIdentity& getIdentity() const {
74 return fIdentity; 75 return fIdentity;
75 } 76 }
76 77
77 const char* getFamilyName() const { return fFamilyName.c_str(); } 78 const char* getFamilyName() const { return fFamilyName.c_str(); }
78 SkStream* getLocalStream() const { return fLocalStream; } 79 SkStream* getLocalStream() const { return fLocalStream; }
79 80
80 bool isFamilyName(const char* name) const { 81 bool isFamilyName(const char* name) const {
81 return fFamilyName.equals(name); 82 return fFamilyName.equals(name);
82 } 83 }
84
85 protected:
86 friend class SkFontHost; // hack until we can make public versions
87
88 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
89 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
90 size_t length, void* data) const SK_OVERRIDE;
91 virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE;
92
93 private:
94 typedef SkTypeface INHERITED;
83 }; 95 };
84 96
85 /////////////////////////////////////////////////////////////////////////////// 97 ///////////////////////////////////////////////////////////////////////////////
86 98
87 struct FindRec { 99 struct FindRec {
88 FindRec(const char* name, SkTypeface::Style style) 100 FindRec(const char* name, SkTypeface::Style style)
89 : fFamilyName(name) // don't need to make a deep copy 101 : fFamilyName(name) // don't need to make a deep copy
90 , fStyle(style) {} 102 , fStyle(style) {}
91 103
92 const char* fFamilyName; 104 const char* fFamilyName;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 SkTypeface* face = NULL; 174 SkTypeface* face = NULL;
163 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); 175 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
164 176
165 if (stream->isValid()) { 177 if (stream->isValid()) {
166 face = CreateTypefaceFromStream(stream); 178 face = CreateTypefaceFromStream(stream);
167 } 179 }
168 stream->unref(); 180 stream->unref();
169 return face; 181 return face;
170 } 182 }
171 183
184 ///////////////////////////////////////////////////////////////////////////////
185
186 // DEPRECATED
187 int SkFontHost::CountTables(SkFontID fontID) {
188 SkTypeface* face = SkTypefaceCache::FindByID(fontID);
189 return face ? face->onGetTableTags(NULL) : 0;
190 }
191
192 // DEPRECATED
193 int SkFontHost::GetTableTags(SkFontID fontID, SkFontTableTag tags[]) {
194 SkTypeface* face = SkTypefaceCache::FindByID(fontID);
195 return face ? face->onGetTableTags(tags) : 0;
196 }
197
198 // DEPRECATED
199 size_t SkFontHost::GetTableSize(SkFontID fontID, SkFontTableTag tag) {
200 SkTypeface* face = SkTypefaceCache::FindByID(fontID);
201 return face ? face->onGetTableData(tag, 0, ~0U, NULL) : 0;
202 }
203
204 // DEPRECATED
205 size_t SkFontHost::GetTableData(SkFontID fontID, SkFontTableTag tag,
206 size_t offset, size_t length, void* dst) {
207 SkTypeface* face = SkTypefaceCache::FindByID(fontID);
208 return face ? face->onGetTableData(tag, offset, length, dst) : 0;
209 }
210
211 // DEPRECATED
172 uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) { 212 uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) {
173 // We don't handle font fallback. 213 // We don't handle font fallback.
174 return 0; 214 return 0;
175 } 215 }
176 216
177 /////////////////////////////////////////////////////////////////////////////// 217 ///////////////////////////////////////////////////////////////////////////////
178 218
179 // Serialize, Deserialize need to be compatible across platforms, hence the use 219 // Serialize, Deserialize need to be compatible across platforms, hence the use
180 // of SkFontDescriptor. 220 // of SkFontDescriptor.
181 221
182 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { 222 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
183 FontConfigTypeface* fct = (FontConfigTypeface*)face; 223 FontConfigTypeface* fct = (FontConfigTypeface*)face;
184 SkFontDescriptor desc(face->style());
185 224
186 desc.setFamilyName(fct->getFamilyName()); 225 SkFontDescriptor desc;
226 fct->onGetFontDescriptor(&desc);
187 desc.serialize(stream); 227 desc.serialize(stream);
188 228
189 // by convention, we also write out the actual sfnt data, preceeded by 229 // by convention, we also write out the actual sfnt data, preceeded by
190 // a packed-length. For now we skip that, so we just write the zero. 230 // a packed-length. For now we skip that, so we just write the zero.
191 stream->writePackedUInt(0); 231 stream->writePackedUInt(0);
192 } 232 }
193 233
194 SkTypeface* SkFontHost::Deserialize(SkStream* stream) { 234 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
195 SkFontDescriptor descriptor(stream); 235 SkFontDescriptor descriptor(stream);
196 const char* familyName = descriptor.getFamilyName(); 236 const char* familyName = descriptor.getFamilyName();
197 const SkTypeface::Style style = descriptor.getStyle(); 237 const SkTypeface::Style style = descriptor.getStyle();
198 238
199 size_t length = stream->readPackedUInt(); 239 size_t length = stream->readPackedUInt();
200 if (length > 0) { 240 if (length > 0) {
201 void* addr = sk_malloc_flags(length, 0); 241 void* addr = sk_malloc_flags(length, 0);
202 if (addr) { 242 if (addr) {
203 SkAutoTUnref<SkStream> localStream(SkNEW_ARGS(SkMemoryStream, 243 SkAutoTUnref<SkStream> localStream(SkNEW_ARGS(SkMemoryStream,
204 (addr, length, false))); 244 (addr, length, false)));
205 return SkFontHost::CreateTypefaceFromStream(localStream.get()); 245 return SkFontHost::CreateTypefaceFromStream(localStream.get());
206 } 246 }
207 // failed to allocate, so just skip and create-from-name 247 // failed to allocate, so just skip and create-from-name
208 stream->skip(length); 248 stream->skip(length);
209 } 249 }
210 250
211 return SkFontHost::CreateTypeface(NULL, familyName, style); 251 return SkFontHost::CreateTypeface(NULL, familyName, style);
212 } 252 }
213 253
214 /////////////////////////////////////////////////////////////////////////////// 254 ///////////////////////////////////////////////////////////////////////////////
215 255
216 SkStream* SkFontHost::OpenStream(uint32_t id) { 256 static SkStream* open_stream(const FontConfigTypeface* face) {
217 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(id );
218 if (NULL == face) {
219 return NULL;
220 }
221
222 SkStream* stream = face->getLocalStream(); 257 SkStream* stream = face->getLocalStream();
223 if (stream) { 258 if (stream) {
224 stream->ref(); 259 stream->ref();
225 } else { 260 } else {
226 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 261 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
227 if (NULL == fci.get()) { 262 if (NULL == fci.get()) {
228 return NULL; 263 return NULL;
229 } 264 }
230 stream = fci->openStream(face->getIdentity()); 265 stream = fci->openStream(face->getIdentity());
231 } 266 }
232 return stream; 267 return stream;
233 } 268 }
234 269
270 SkStream* SkFontHost::OpenStream(uint32_t id) {
271 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(id );
272 if (NULL == face) {
273 return NULL;
274 }
275 return open_stream(face);
276 }
277
235 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, 278 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
236 int32_t* index) { 279 int32_t* index) {
237 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(fo ntID); 280 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(fo ntID);
238 if (NULL == face || face->getLocalStream()) { 281 if (NULL == face || face->getLocalStream()) {
239 return 0; 282 return 0;
240 } 283 }
241 284
242 // Here we cheat, and "know" what is in the identity fields. 285 // Here we cheat, and "know" what is in the identity fields.
243 286
244 const SkString& filename = face->getIdentity().fString; 287 const SkString& filename = face->getIdentity().fString;
245 if (index) { 288 if (index) {
246 *index = (int32_t)face->getIdentity().fIntPtr; 289 *index = (int32_t)face->getIdentity().fIntPtr;
247 } 290 }
248 if (path) { 291 if (path) {
249 size_t len = SkMin32(length, filename.size()); 292 size_t len = SkMin32(length, filename.size());
250 memcpy(path, filename.c_str(), len); 293 memcpy(path, filename.c_str(), len);
251 } 294 }
252 return filename.size(); 295 return filename.size();
253 } 296 }
297
298 ///////////////////////////////////////////////////////////////////////////////
299
300 int FontConfigTypeface::onGetTableTags(SkFontTableTag tags[]) const {
301 SkAutoTUnref<SkStream> stream(open_stream(this));
302 return stream.get() ? SkFontStream::GetTableTags(stream, tags) : 0;
303 }
304
305 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
306 size_t length, void* data) const {
307 SkAutoTUnref<SkStream> stream(open_stream(this));
308 return stream.get() ?
309 SkFontStream::GetTableData(stream, tag, offset, length, data) :
310 0;
311 }
312
313 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
314 desc->setStyle(this->style());
315 desc->setFamilyName(this->getFamilyName());
316 }
317
318
OLDNEW
« no previous file with comments | « trunk/gyp/ports.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698