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

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

Issue 12988002: add virtual SkTypeface::onOpenStream and override that for fontconfig (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/src/ports/SkFontHost_FreeType.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 "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost.h" 10 #include "SkFontHost.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return fFamilyName.equals(name); 83 return fFamilyName.equals(name);
84 } 84 }
85 85
86 protected: 86 protected:
87 friend class SkFontHost; // hack until we can make public versions 87 friend class SkFontHost; // hack until we can make public versions
88 88
89 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; 89 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
90 virtual size_t onGetTableData(SkFontTableTag, size_t offset, 90 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
91 size_t length, void* data) const SK_OVERRIDE; 91 size_t length, void* data) const SK_OVERRIDE;
92 virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE; 92 virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE;
93 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
93 94
94 private: 95 private:
95 typedef SkTypeface_FreeType INHERITED; 96 typedef SkTypeface_FreeType INHERITED;
96 }; 97 };
97 98
98 /////////////////////////////////////////////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////////////
99 100
100 struct FindRec { 101 struct FindRec {
101 FindRec(const char* name, SkTypeface::Style style) 102 FindRec(const char* name, SkTypeface::Style style)
102 : fFamilyName(name) // don't need to make a deep copy 103 : fFamilyName(name) // don't need to make a deep copy
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 238 }
238 // failed to allocate, so just skip and create-from-name 239 // failed to allocate, so just skip and create-from-name
239 stream->skip(length); 240 stream->skip(length);
240 } 241 }
241 242
242 return SkFontHost::CreateTypeface(NULL, familyName, style); 243 return SkFontHost::CreateTypeface(NULL, familyName, style);
243 } 244 }
244 245
245 /////////////////////////////////////////////////////////////////////////////// 246 ///////////////////////////////////////////////////////////////////////////////
246 247
247 static SkStream* open_stream(const FontConfigTypeface* face, int* ttcIndex) { 248 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
248 SkStream* stream = face->getLocalStream(); 249 SkStream* stream = this->getLocalStream();
249 if (stream) { 250 if (stream) {
250 // TODO: fix issue 1176. 251 // TODO: fix issue 1176.
251 // As of now open_stream will return a stream and unwind it, but the 252 // As of now open_stream will return a stream and unwind it, but the
252 // SkStream is not thread safe, and if two threads use the stream they 253 // SkStream is not thread safe, and if two threads use the stream they
253 // may collide and print preview for example could still fail, 254 // may collide and print preview for example could still fail,
254 // or there could be some failures in rendering if this stream is used 255 // or there could be some failures in rendering if this stream is used
255 // there. 256 // there.
256 stream->rewind(); 257 stream->rewind();
257 stream->ref(); 258 stream->ref();
258 // should have been provided by CreateFromStream() 259 // should have been provided by CreateFromStream()
259 *ttcIndex = 0; 260 *ttcIndex = 0;
260 } else { 261 } else {
261 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 262 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
262 if (NULL == fci.get()) { 263 if (NULL == fci.get()) {
263 return NULL; 264 return NULL;
264 } 265 }
265 stream = fci->openStream(face->getIdentity()); 266 stream = fci->openStream(this->getIdentity());
266 *ttcIndex = face->getIdentity().fTTCIndex; 267 *ttcIndex = this->getIdentity().fTTCIndex;
267 } 268 }
268 return stream; 269 return stream;
269 } 270 }
270 271
271 SkStream* SkFontHost::OpenStream(uint32_t id) { 272 SkStream* SkFontHost::OpenStream(uint32_t) {
272 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(id ); 273 SkASSERT(!"SkFontHost::OpenStream is DEPRECATED: call SkTypeface::openStream \n");
273 if (NULL == face) { 274 return NULL;
274 return NULL;
275 }
276
277 int ttcIndex;
278 // We should return ttcIndex from this call.
279 return open_stream(face, &ttcIndex);
280 } 275 }
281 276
282 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, 277 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
283 int32_t* index) { 278 int32_t* index) {
284 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(fo ntID); 279 SkASSERT(!"SkFontHost::GetFileName is DEPRECATED: call SkTypeface::openStrea m\n");
285 if (NULL == face || face->getLocalStream()) { 280 return 0;
286 return 0;
287 }
288
289 // Here we cheat, and "know" what is in the identity fields.
290
291 const SkString& filename = face->getIdentity().fString;
292 if (index) {
293 *index = face->getIdentity().fTTCIndex;
294 }
295 if (path) {
296 size_t len = SkMin32(length, filename.size());
297 memcpy(path, filename.c_str(), len);
298 }
299 return filename.size();
300 } 281 }
301 282
302 /////////////////////////////////////////////////////////////////////////////// 283 ///////////////////////////////////////////////////////////////////////////////
303 284
304 int FontConfigTypeface::onGetTableTags(SkFontTableTag tags[]) const { 285 int FontConfigTypeface::onGetTableTags(SkFontTableTag tags[]) const {
305 int ttcIndex; 286 int ttcIndex;
306 SkAutoTUnref<SkStream> stream(open_stream(this, &ttcIndex)); 287 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
307 return stream.get() 288 return stream.get()
308 ? SkFontStream::GetTableTags(stream, ttcIndex, tags) 289 ? SkFontStream::GetTableTags(stream, ttcIndex, tags)
309 : 0; 290 : 0;
310 } 291 }
311 292
312 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 293 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
313 size_t length, void* data) const { 294 size_t length, void* data) const {
314 int ttcIndex; 295 int ttcIndex;
315 SkAutoTUnref<SkStream> stream(open_stream(this, &ttcIndex)); 296 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
316 return stream.get() 297 return stream.get()
317 ? SkFontStream::GetTableData(stream, ttcIndex, 298 ? SkFontStream::GetTableData(stream, ttcIndex,
318 tag, offset, length, data) 299 tag, offset, length, data)
319 : 0; 300 : 0;
320 } 301 }
321 302
322 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { 303 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const {
323 desc->setStyle(this->style()); 304 desc->setStyle(this->style());
324 desc->setFamilyName(this->getFamilyName()); 305 desc->setFamilyName(this->getFamilyName());
325 } 306 }
OLDNEW
« no previous file with comments | « trunk/src/ports/SkFontHost_FreeType.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698