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

Side by Side Diff: trunk/src/ports/SkFontHost_FreeType.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/core/SkTypeface.cpp ('k') | trunk/src/ports/SkFontHost_fontconfig.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 sk_bzero(&fFTStream, sizeof(fFTStream)); 254 sk_bzero(&fFTStream, sizeof(fFTStream));
255 fFTStream.size = fSkStream->getLength(); 255 fFTStream.size = fSkStream->getLength();
256 fFTStream.descriptor.pointer = fSkStream; 256 fFTStream.descriptor.pointer = fSkStream;
257 fFTStream.read = sk_stream_read; 257 fFTStream.read = sk_stream_read;
258 fFTStream.close = sk_stream_close; 258 fFTStream.close = sk_stream_close;
259 } 259 }
260 260
261 // Will return 0 on failure 261 // Will return 0 on failure
262 // Caller must lock gFTMutex before calling this function. 262 // Caller must lock gFTMutex before calling this function.
263 static SkFaceRec* ref_ft_face(uint32_t fontID) { 263 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) {
264 const SkFontID fontID = typeface->uniqueID();
264 SkFaceRec* rec = gFaceRecHead; 265 SkFaceRec* rec = gFaceRecHead;
265 while (rec) { 266 while (rec) {
266 if (rec->fFontID == fontID) { 267 if (rec->fFontID == fontID) {
267 SkASSERT(rec->fFace); 268 SkASSERT(rec->fFace);
268 rec->fRefCnt += 1; 269 rec->fRefCnt += 1;
269 return rec; 270 return rec;
270 } 271 }
271 rec = rec->fNext; 272 rec = rec->fNext;
272 } 273 }
273 274
274 SkStream* strm = SkFontHost::OpenStream(fontID); 275 int face_index;
276 SkStream* strm = typeface->openStream(&face_index);
275 if (NULL == strm) { 277 if (NULL == strm) {
276 SkDEBUGF(("SkFontHost::OpenStream failed opening %x\n", fontID)); 278 return NULL;
277 return 0;
278 } 279 }
279 280
280 // this passes ownership of strm to the rec 281 // this passes ownership of strm to the rec
281 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID)); 282 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID));
282 283
283 FT_Open_Args args; 284 FT_Open_Args args;
284 memset(&args, 0, sizeof(args)); 285 memset(&args, 0, sizeof(args));
285 const void* memoryBase = strm->getMemoryBase(); 286 const void* memoryBase = strm->getMemoryBase();
286 287
287 if (NULL != memoryBase) { 288 if (NULL != memoryBase) {
288 //printf("mmap(%s)\n", keyString.c_str()); 289 //printf("mmap(%s)\n", keyString.c_str());
289 args.flags = FT_OPEN_MEMORY; 290 args.flags = FT_OPEN_MEMORY;
290 args.memory_base = (const FT_Byte*)memoryBase; 291 args.memory_base = (const FT_Byte*)memoryBase;
291 args.memory_size = strm->getLength(); 292 args.memory_size = strm->getLength();
292 } else { 293 } else {
293 //printf("fopen(%s)\n", keyString.c_str()); 294 //printf("fopen(%s)\n", keyString.c_str());
294 args.flags = FT_OPEN_STREAM; 295 args.flags = FT_OPEN_STREAM;
295 args.stream = &rec->fFTStream; 296 args.stream = &rec->fFTStream;
296 } 297 }
297 298
298 int face_index; 299 FT_Error err = FT_Open_Face(gFTLibrary, &args, face_index, &rec->fFace);
299 int length = SkFontHost::GetFileName(fontID, NULL, 0, &face_index);
300 FT_Error err = FT_Open_Face(gFTLibrary, &args, length ? face_index : 0,
301 &rec->fFace);
302
303 if (err) { // bad filename, try the default font 300 if (err) { // bad filename, try the default font
304 fprintf(stderr, "ERROR: unable to open font '%x'\n", fontID); 301 fprintf(stderr, "ERROR: unable to open font '%x'\n", fontID);
305 SkDELETE(rec); 302 SkDELETE(rec);
306 return 0; 303 return NULL;
307 } else { 304 } else {
308 SkASSERT(rec->fFace); 305 SkASSERT(rec->fFace);
309 //fprintf(stderr, "Opened font '%s'\n", filename.c_str()); 306 //fprintf(stderr, "Opened font '%s'\n", filename.c_str());
310 rec->fNext = gFaceRecHead; 307 rec->fNext = gFaceRecHead;
311 gFaceRecHead = rec; 308 gFaceRecHead = rec;
312 return rec; 309 return rec;
313 } 310 }
314 } 311 }
315 312
316 // Caller must lock gFTMutex before calling this function. 313 // Caller must lock gFTMutex before calling this function.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 return NULL; 452 return NULL;
456 #else 453 #else
457 SkAutoMutexAcquire ac(gFTMutex); 454 SkAutoMutexAcquire ac(gFTMutex);
458 FT_Library libInit = NULL; 455 FT_Library libInit = NULL;
459 if (gFTCount == 0) { 456 if (gFTCount == 0) {
460 if (!InitFreetype()) 457 if (!InitFreetype())
461 sk_throw(); 458 sk_throw();
462 libInit = gFTLibrary; 459 libInit = gFTLibrary;
463 } 460 }
464 SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit); 461 SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit);
465 SkFaceRec* rec = ref_ft_face(this->uniqueID()); 462 SkFaceRec* rec = ref_ft_face(this);
466 if (NULL == rec) 463 if (NULL == rec)
467 return NULL; 464 return NULL;
468 FT_Face face = rec->fFace; 465 FT_Face face = rec->fFace;
469 466
470 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; 467 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
471 info->fFontName.set(FT_Get_Postscript_Name(face)); 468 info->fFontName.set(FT_Get_Postscript_Name(face));
472 info->fMultiMaster = FT_HAS_MULTIPLE_MASTERS(face); 469 info->fMultiMaster = FT_HAS_MULTIPLE_MASTERS(face);
473 info->fLastGlyphID = face->num_glyphs - 1; 470 info->fLastGlyphID = face->num_glyphs - 1;
474 info->fEmSize = 1000; 471 info->fEmSize = 1000;
475 472
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 697
701 int SkTypeface_FreeType::onGetUPEM() const { 698 int SkTypeface_FreeType::onGetUPEM() const {
702 SkAutoMutexAcquire ac(gFTMutex); 699 SkAutoMutexAcquire ac(gFTMutex);
703 FT_Library libInit = NULL; 700 FT_Library libInit = NULL;
704 if (gFTCount == 0) { 701 if (gFTCount == 0) {
705 if (!InitFreetype()) 702 if (!InitFreetype())
706 sk_throw(); 703 sk_throw();
707 libInit = gFTLibrary; 704 libInit = gFTLibrary;
708 } 705 }
709 SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit); 706 SkAutoTCallIProc<struct FT_LibraryRec_, FT_Done_FreeType> ftLib(libInit);
710 SkFaceRec *rec = ref_ft_face(this->uniqueID()); 707 SkFaceRec *rec = ref_ft_face(this);
711 int unitsPerEm = 0; 708 int unitsPerEm = 0;
712 709
713 if (rec != NULL && rec->fFace != NULL) { 710 if (rec != NULL && rec->fFace != NULL) {
714 unitsPerEm = rec->fFace->units_per_EM; 711 unitsPerEm = rec->fFace->units_per_EM;
715 unref_ft_face(rec->fFace); 712 unref_ft_face(rec->fFace);
716 } 713 }
717 714
718 return unitsPerEm; 715 return unitsPerEm;
719 } 716 }
720 717
721 SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface, 718 SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface,
722 const SkDescriptor* desc) 719 const SkDescriptor* desc)
723 : SkScalerContext_FreeType_Base(typeface, desc) { 720 : SkScalerContext_FreeType_Base(typeface, desc) {
724 SkAutoMutexAcquire ac(gFTMutex); 721 SkAutoMutexAcquire ac(gFTMutex);
725 722
726 if (gFTCount == 0) { 723 if (gFTCount == 0) {
727 if (!InitFreetype()) { 724 if (!InitFreetype()) {
728 sk_throw(); 725 sk_throw();
729 } 726 }
730 } 727 }
731 ++gFTCount; 728 ++gFTCount;
732 729
733 // load the font file 730 // load the font file
734 fFTSize = NULL; 731 fFTSize = NULL;
735 fFace = NULL; 732 fFace = NULL;
736 fFaceRec = ref_ft_face(fRec.fFontID); 733 fFaceRec = ref_ft_face(typeface);
737 if (NULL == fFaceRec) { 734 if (NULL == fFaceRec) {
738 return; 735 return;
739 } 736 }
740 fFace = fFaceRec->fFace; 737 fFace = fFaceRec->fFace;
741 738
742 // compute our factors from the record 739 // compute our factors from the record
743 740
744 SkMatrix m; 741 SkMatrix m;
745 742
746 fRec.getSingleMatrix(&m); 743 fRec.getSingleMatrix(&m);
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 *style = (SkTypeface::Style) tempStyle; 1358 *style = (SkTypeface::Style) tempStyle;
1362 } 1359 }
1363 if (isFixedWidth) { 1360 if (isFixedWidth) {
1364 *isFixedWidth = FT_IS_FIXED_WIDTH(face); 1361 *isFixedWidth = FT_IS_FIXED_WIDTH(face);
1365 } 1362 }
1366 1363
1367 FT_Done_Face(face); 1364 FT_Done_Face(face);
1368 FT_Done_FreeType(library); 1365 FT_Done_FreeType(library);
1369 return true; 1366 return true;
1370 } 1367 }
OLDNEW
« no previous file with comments | « trunk/src/core/SkTypeface.cpp ('k') | trunk/src/ports/SkFontHost_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698