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

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

Issue 748063003: Clean up FreeType code for 2.3.8. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Already assuming FT_LCD_FILTER_H is defined. Created 6 years 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 | « gyp/freetype.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 /* 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 "SkAdvancedTypefaceMetrics.h" 9 #include "SkAdvancedTypefaceMetrics.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 13 matching lines...) Expand all
24 #include "SkScalerContext.h" 24 #include "SkScalerContext.h"
25 #include "SkStream.h" 25 #include "SkStream.h"
26 #include "SkString.h" 26 #include "SkString.h"
27 #include "SkTemplates.h" 27 #include "SkTemplates.h"
28 #include "SkThread.h" 28 #include "SkThread.h"
29 29
30 #if defined(SK_CAN_USE_DLOPEN) 30 #if defined(SK_CAN_USE_DLOPEN)
31 #include <dlfcn.h> 31 #include <dlfcn.h>
32 #endif 32 #endif
33 #include <ft2build.h> 33 #include <ft2build.h>
34 #include FT_ADVANCES_H
35 #include FT_BITMAP_H
34 #include FT_FREETYPE_H 36 #include FT_FREETYPE_H
37 #include FT_LCD_FILTER_H
35 #include FT_OUTLINE_H 38 #include FT_OUTLINE_H
36 #include FT_SIZES_H 39 #include FT_SIZES_H
37 #include FT_TRUETYPE_TABLES_H 40 #include FT_TRUETYPE_TABLES_H
38 #include FT_TYPE1_TABLES_H 41 #include FT_TYPE1_TABLES_H
39 #include FT_BITMAP_H
40 // In the past, FT_GlyphSlot_Own_Bitmap was defined in this header file.
41 #include FT_SYNTHESIS_H
42 #include FT_XFREE86_H 42 #include FT_XFREE86_H
43 #ifdef FT_LCD_FILTER_H
44 #include FT_LCD_FILTER_H
45 #endif
46
47 // Defined in FreeType 2.3.8 and later.
48 // This is a silly build time check, we would need a runtime check if we really cared.
49 #ifdef FT_ADVANCES_H
50 #include FT_ADVANCES_H
51 #endif
52
53 #if 0
54 // Also include the files by name for build tools which require this.
55 #include <freetype/freetype.h>
56 #include <freetype/ftoutln.h>
57 #include <freetype/ftsizes.h>
58 #include <freetype/tttables.h>
59 #include <freetype/ftadvanc.h>
60 #include <freetype/ftlcdfil.h>
61 #include <freetype/ftbitmap.h>
62 #include <freetype/ftsynth.h>
63 #endif
64 43
65 // FT_LOAD_COLOR and the corresponding FT_Pixel_Mode::FT_PIXEL_MODE_BGRA 44 // FT_LOAD_COLOR and the corresponding FT_Pixel_Mode::FT_PIXEL_MODE_BGRA
66 // were introduced in FreeType 2.5.0. 45 // were introduced in FreeType 2.5.0.
67 // The following may be removed once FreeType 2.5.0 is required to build. 46 // The following may be removed once FreeType 2.5.0 is required to build.
68 #ifndef FT_LOAD_COLOR 47 #ifndef FT_LOAD_COLOR
69 # define FT_LOAD_COLOR ( 1L << 20 ) 48 # define FT_LOAD_COLOR ( 1L << 20 )
70 # define FT_PIXEL_MODE_BGRA 7 49 # define FT_PIXEL_MODE_BGRA 7
71 #endif 50 #endif
72 51
73 // FT_HAS_COLOR and the corresponding FT_FACE_FLAG_COLOR 52 // FT_HAS_COLOR and the corresponding FT_FACE_FLAG_COLOR
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // The following platforms provide FreeType of at least 2.4.0. 90 // The following platforms provide FreeType of at least 2.4.0.
112 // Ubuntu >= 11.04 (previous deprecated April 2013) 91 // Ubuntu >= 11.04 (previous deprecated April 2013)
113 // Debian >= 6.0 (good) 92 // Debian >= 6.0 (good)
114 // OpenSuse >= 11.4 (previous deprecated January 2012 / Nov 2013 for Evergreen 1 1.2) 93 // OpenSuse >= 11.4 (previous deprecated January 2012 / Nov 2013 for Evergreen 1 1.2)
115 // Fedora >= 14 (good) 94 // Fedora >= 14 (good)
116 // Android >= Gingerbread (good) 95 // Android >= Gingerbread (good)
117 typedef FT_Error (*FT_Library_SetLcdFilterWeightsProc)(FT_Library, unsigned char *); 96 typedef FT_Error (*FT_Library_SetLcdFilterWeightsProc)(FT_Library, unsigned char *);
118 97
119 // Caller must lock gFTMutex before calling this function. 98 // Caller must lock gFTMutex before calling this function.
120 static bool InitFreetype() { 99 static bool InitFreetype() {
100 SkDEBUGCODE(gFTMutex.assertHeld());
mtklein 2014/11/21 21:00:03 Isn't the body of assertHeld() itself SkDEBUGCODE?
bungeman-skia 2014/11/21 21:07:43 Hmmm... so it is. Done.
101
121 FT_Error err = FT_Init_FreeType(&gFTLibrary); 102 FT_Error err = FT_Init_FreeType(&gFTLibrary);
122 if (err) { 103 if (err) {
123 return false; 104 return false;
124 } 105 }
125 106
126 // Setup LCD filtering. This reduces color fringes for LCD smoothed glyphs. 107 // Setup LCD filtering. This reduces color fringes for LCD smoothed glyphs.
127 #ifdef FT_LCD_FILTER_H
128 // Use default { 0x10, 0x40, 0x70, 0x40, 0x10 }, as it adds up to 0x110, sim ulating ink spread. 108 // Use default { 0x10, 0x40, 0x70, 0x40, 0x10 }, as it adds up to 0x110, sim ulating ink spread.
129 // SetLcdFilter must be called before SetLcdFilterWeights. 109 // SetLcdFilter must be called before SetLcdFilterWeights.
130 err = FT_Library_SetLcdFilter(gFTLibrary, FT_LCD_FILTER_DEFAULT); 110 err = FT_Library_SetLcdFilter(gFTLibrary, FT_LCD_FILTER_DEFAULT);
131 if (0 == err) { 111 if (0 == err) {
132 gLCDSupport = true; 112 gLCDSupport = true;
133 gLCDExtra = 2; //Using a filter adds one full pixel to each side. 113 gLCDExtra = 2; //Using a filter adds one full pixel to each side.
134 114
135 #ifdef SK_FONTHOST_FREETYPE_USE_NORMAL_LCD_FILTER 115 #ifdef SK_FONTHOST_FREETYPE_USE_NORMAL_LCD_FILTER
136 // This also adds to 0x110 simulating ink spread, but provides better re sults than default. 116 // This also adds to 0x110 simulating ink spread, but provides better re sults than default.
137 static unsigned char gGaussianLikeHeavyWeights[] = { 0x1A, 0x43, 0x56, 0 x43, 0x1A, }; 117 static unsigned char gGaussianLikeHeavyWeights[] = { 0x1A, 0x43, 0x56, 0 x43, 0x1A, };
138 118
139 #if defined(SK_FONTHOST_FREETYPE_RUNTIME_VERSION) && \ 119 #if SK_FONTHOST_FREETYPE_RUNTIME_VERSION > 0x020400
140 SK_FONTHOST_FREETYPE_RUNTIME_VERSION > 0x020400
141 err = FT_Library_SetLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeigh ts); 120 err = FT_Library_SetLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeigh ts);
142 #elif defined(SK_CAN_USE_DLOPEN) && SK_CAN_USE_DLOPEN == 1 121 #elif SK_CAN_USE_DLOPEN == 1
143 //The FreeType library is already loaded, so symbols are available in pr ocess. 122 //The FreeType library is already loaded, so symbols are available in pr ocess.
144 void* self = dlopen(NULL, RTLD_LAZY); 123 void* self = dlopen(NULL, RTLD_LAZY);
145 if (self) { 124 if (self) {
146 FT_Library_SetLcdFilterWeightsProc setLcdFilterWeights; 125 FT_Library_SetLcdFilterWeightsProc setLcdFilterWeights;
147 //The following cast is non-standard, but safe for POSIX. 126 //The following cast is non-standard, but safe for POSIX.
148 *reinterpret_cast<void**>(&setLcdFilterWeights) = dlsym(self, "FT_Li brary_SetLcdFilterWeights"); 127 *reinterpret_cast<void**>(&setLcdFilterWeights) = dlsym(self, "FT_Li brary_SetLcdFilterWeights");
149 dlclose(self); 128 dlclose(self);
150 129
151 if (setLcdFilterWeights) { 130 if (setLcdFilterWeights) {
152 err = setLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeights) ; 131 err = setLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeights) ;
153 } 132 }
154 } 133 }
155 #endif 134 #endif
156 #endif 135 #endif
157 } 136 }
158 #else
159 gLCDSupport = false;
160 #endif
161 gLCDSupportValid = true; 137 gLCDSupportValid = true;
162 138
163 return true; 139 return true;
164 } 140 }
165 141
166 // Called while holding gFTMutex. 142 // Called while holding gFTMutex.
167 static void determine_lcd_support(bool* lcdSupported) { 143 static void determine_lcd_support(bool* lcdSupported) {
168 if (!gLCDSupportValid) { 144 if (!gLCDSupportValid) {
169 // This will determine LCD support as a side effect. 145 // This will determine LCD support as a side effect.
170 InitFreetype(); 146 InitFreetype();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 sk_bzero(&fFTStream, sizeof(fFTStream)); 260 sk_bzero(&fFTStream, sizeof(fFTStream));
285 fFTStream.size = fSkStream->getLength(); 261 fFTStream.size = fSkStream->getLength();
286 fFTStream.descriptor.pointer = fSkStream; 262 fFTStream.descriptor.pointer = fSkStream;
287 fFTStream.read = sk_stream_read; 263 fFTStream.read = sk_stream_read;
288 fFTStream.close = sk_stream_close; 264 fFTStream.close = sk_stream_close;
289 } 265 }
290 266
291 // Will return 0 on failure 267 // Will return 0 on failure
292 // Caller must lock gFTMutex before calling this function. 268 // Caller must lock gFTMutex before calling this function.
293 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) { 269 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) {
270 SkDEBUGCODE(gFTMutex.assertHeld());
271
294 const SkFontID fontID = typeface->uniqueID(); 272 const SkFontID fontID = typeface->uniqueID();
295 SkFaceRec* rec = gFaceRecHead; 273 SkFaceRec* rec = gFaceRecHead;
296 while (rec) { 274 while (rec) {
297 if (rec->fFontID == fontID) { 275 if (rec->fFontID == fontID) {
298 SkASSERT(rec->fFace); 276 SkASSERT(rec->fFace);
299 rec->fRefCnt += 1; 277 rec->fRefCnt += 1;
300 return rec; 278 return rec;
301 } 279 }
302 rec = rec->fNext; 280 rec = rec->fNext;
303 } 281 }
304 282
305 int face_index; 283 int face_index;
306 SkStream* strm = typeface->openStream(&face_index); 284 SkStream* strm = typeface->openStream(&face_index);
307 if (NULL == strm) { 285 if (NULL == strm) {
308 return NULL; 286 return NULL;
309 } 287 }
310 288
311 // this passes ownership of strm to the rec 289 // this passes ownership of strm to the rec
312 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID)); 290 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID));
313 291
314 FT_Open_Args args; 292 FT_Open_Args args;
315 memset(&args, 0, sizeof(args)); 293 memset(&args, 0, sizeof(args));
316 const void* memoryBase = strm->getMemoryBase(); 294 const void* memoryBase = strm->getMemoryBase();
317 295
318 if (memoryBase) { 296 if (memoryBase) {
319 //printf("mmap(%s)\n", keyString.c_str());
320 args.flags = FT_OPEN_MEMORY; 297 args.flags = FT_OPEN_MEMORY;
321 args.memory_base = (const FT_Byte*)memoryBase; 298 args.memory_base = (const FT_Byte*)memoryBase;
322 args.memory_size = strm->getLength(); 299 args.memory_size = strm->getLength();
323 } else { 300 } else {
324 //printf("fopen(%s)\n", keyString.c_str());
325 args.flags = FT_OPEN_STREAM; 301 args.flags = FT_OPEN_STREAM;
326 args.stream = &rec->fFTStream; 302 args.stream = &rec->fFTStream;
327 } 303 }
328 304
329 FT_Error err = FT_Open_Face(gFTLibrary, &args, face_index, &rec->fFace); 305 FT_Error err = FT_Open_Face(gFTLibrary, &args, face_index, &rec->fFace);
330 if (err) { // bad filename, try the default font 306 if (err) { // bad filename, try the default font
331 fprintf(stderr, "ERROR: unable to open font '%x'\n", fontID); 307 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID));
332 SkDELETE(rec); 308 SkDELETE(rec);
333 return NULL; 309 return NULL;
334 } else { 310 } else {
335 SkASSERT(rec->fFace); 311 SkASSERT(rec->fFace);
336 //fprintf(stderr, "Opened font '%s'\n", filename.c_str());
337 rec->fNext = gFaceRecHead; 312 rec->fNext = gFaceRecHead;
338 gFaceRecHead = rec; 313 gFaceRecHead = rec;
339 return rec; 314 return rec;
340 } 315 }
341 } 316 }
342 317
343 // Caller must lock gFTMutex before calling this function. 318 // Caller must lock gFTMutex before calling this function.
344 static void unref_ft_face(FT_Face face) { 319 static void unref_ft_face(FT_Face face) {
320 SkDEBUGCODE(gFTMutex.assertHeld());
321
345 SkFaceRec* rec = gFaceRecHead; 322 SkFaceRec* rec = gFaceRecHead;
346 SkFaceRec* prev = NULL; 323 SkFaceRec* prev = NULL;
347 while (rec) { 324 while (rec) {
348 SkFaceRec* next = rec->fNext; 325 SkFaceRec* next = rec->fNext;
349 if (rec->fFace == face) { 326 if (rec->fFace == face) {
350 if (--rec->fRefCnt == 0) { 327 if (--rec->fRefCnt == 0) {
351 if (prev) { 328 if (prev) {
352 prev->fNext = next; 329 prev->fNext = next;
353 } else { 330 } else {
354 gFaceRecHead = next; 331 gFaceRecHead = next;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 SkFaceRec* rec() { return fRec; } 369 SkFaceRec* rec() { return fRec; }
393 FT_Face face() { return fFace; } 370 FT_Face face() { return fFace; }
394 371
395 private: 372 private:
396 SkFaceRec* fRec; 373 SkFaceRec* fRec;
397 FT_Face fFace; 374 FT_Face fFace;
398 }; 375 };
399 376
400 /////////////////////////////////////////////////////////////////////////// 377 ///////////////////////////////////////////////////////////////////////////
401 378
402 // Work around for old versions of freetype.
403 static FT_Error getAdvances(FT_Face face, FT_UInt start, FT_UInt count,
404 FT_Int32 loadFlags, FT_Fixed* advances) {
405 #ifdef FT_ADVANCES_H
406 return FT_Get_Advances(face, start, count, loadFlags, advances);
407 #else
408 if (!face || start >= face->num_glyphs ||
409 start + count > face->num_glyphs || loadFlags != FT_LOAD_NO_SCALE) {
410 return 6; // "Invalid argument."
411 }
412 if (count == 0)
413 return 0;
414
415 for (int i = 0; i < count; i++) {
416 FT_Error err = FT_Load_Glyph(face, start + i, FT_LOAD_NO_SCALE);
417 if (err)
418 return err;
419 advances[i] = face->glyph->advance.x;
420 }
421
422 return 0;
423 #endif
424 }
425
426 static bool canEmbed(FT_Face face) { 379 static bool canEmbed(FT_Face face) {
427 #ifdef FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING
428 FT_UShort fsType = FT_Get_FSType_Flags(face); 380 FT_UShort fsType = FT_Get_FSType_Flags(face);
429 return (fsType & (FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING | 381 return (fsType & (FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING |
430 FT_FSTYPE_BITMAP_EMBEDDING_ONLY)) == 0; 382 FT_FSTYPE_BITMAP_EMBEDDING_ONLY)) == 0;
431 #else
432 // No embedding is 0x2 and bitmap embedding only is 0x200.
433 TT_OS2* os2_table;
434 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) {
435 return (os2_table->fsType & 0x202) == 0;
436 }
437 return false; // We tried, fail safe.
438 #endif
439 } 383 }
440 384
441 static bool canSubset(FT_Face face) { 385 static bool canSubset(FT_Face face) {
442 #ifdef FT_FSTYPE_NO_SUBSETTING
443 FT_UShort fsType = FT_Get_FSType_Flags(face); 386 FT_UShort fsType = FT_Get_FSType_Flags(face);
444 return (fsType & FT_FSTYPE_NO_SUBSETTING) == 0; 387 return (fsType & FT_FSTYPE_NO_SUBSETTING) == 0;
445 #else
446 // No subset is 0x100.
447 TT_OS2* os2_table;
448 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) {
449 return (os2_table->fsType & 0x100) == 0;
450 }
451 return false; // We tried, fail safe.
452 #endif
453 } 388 }
454 389
455 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { 390 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) {
456 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); 391 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter);
457 if (!glyph_id) 392 if (!glyph_id)
458 return false; 393 return false;
459 if (FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE) != 0) 394 if (FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE) != 0)
460 return false; 395 return false;
461 FT_Outline_Get_CBox(&face->glyph->outline, bbox); 396 FT_Outline_Get_CBox(&face->glyph->outline, bbox);
462 return true; 397 return true;
463 } 398 }
464 399
465 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) { 400 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) {
466 FT_Fixed advance = 0; 401 FT_Fixed advance = 0;
467 if (getAdvances(face, gId, 1, FT_LOAD_NO_SCALE, &advance)) { 402 if (FT_Get_Advances(face, gId, 1, FT_LOAD_NO_SCALE, &advance)) {
468 return false; 403 return false;
469 } 404 }
470 SkASSERT(data); 405 SkASSERT(data);
471 *data = advance; 406 *data = advance;
472 return true; 407 return true;
473 } 408 }
474 409
475 static void populate_glyph_to_unicode(FT_Face& face, 410 static void populate_glyph_to_unicode(FT_Face& face, SkTDArray<SkUnichar>* glyph ToUnicode) {
476 SkTDArray<SkUnichar>* glyphToUnicode) {
477 // Check and see if we have Unicode cmaps. 411 // Check and see if we have Unicode cmaps.
478 for (int i = 0; i < face->num_charmaps; ++i) { 412 for (int i = 0; i < face->num_charmaps; ++i) {
479 // CMaps known to support Unicode: 413 // CMaps known to support Unicode:
480 // Platform ID Encoding ID Name 414 // Platform ID Encoding ID Name
481 // ----------- ----------- ----------------------------------- 415 // ----------- ----------- -----------------------------------
482 // 0 0,1 Apple Unicode 416 // 0 0,1 Apple Unicode
483 // 0 3 Apple Unicode 2.0 (preferred) 417 // 0 3 Apple Unicode 2.0 (preferred)
484 // 3 1 Microsoft Unicode UCS-2 418 // 3 1 Microsoft Unicode UCS-2
485 // 3 10 Microsoft Unicode UCS-4 (preferred) 419 // 3 10 Microsoft Unicode UCS-4 (preferred)
486 // 420 //
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 int16_t advance = face->max_advance_width; 593 int16_t advance = face->max_advance_width;
660 info->fGlyphWidths->fAdvance.append(1, &advance); 594 info->fGlyphWidths->fAdvance.append(1, &advance);
661 finishRange(info->fGlyphWidths.get(), 0, 595 finishRange(info->fGlyphWidths.get(), 0,
662 SkAdvancedTypefaceMetrics::WidthRange::kDefault); 596 SkAdvancedTypefaceMetrics::WidthRange::kDefault);
663 } else if (!cid) { 597 } else if (!cid) {
664 appendRange(&info->fGlyphWidths, 0); 598 appendRange(&info->fGlyphWidths, 0);
665 // So as to not blow out the stack, get advances in batches. 599 // So as to not blow out the stack, get advances in batches.
666 for (int gID = 0; gID < face->num_glyphs; gID += 128) { 600 for (int gID = 0; gID < face->num_glyphs; gID += 128) {
667 FT_Fixed advances[128]; 601 FT_Fixed advances[128];
668 int advanceCount = 128; 602 int advanceCount = 128;
669 if (gID + advanceCount > face->num_glyphs) 603 if (gID + advanceCount > face->num_glyphs) {
670 advanceCount = face->num_glyphs - gID; 604 advanceCount = face->num_glyphs - gID;
671 getAdvances(face, gID, advanceCount, FT_LOAD_NO_SCALE, 605 }
672 advances); 606 FT_Get_Advances(face, gID, advanceCount, FT_LOAD_NO_SCALE, advan ces);
673 for (int i = 0; i < advanceCount; i++) { 607 for (int i = 0; i < advanceCount; i++) {
674 int16_t advance = advances[i]; 608 int16_t advance = advances[i];
675 info->fGlyphWidths->fAdvance.append(1, &advance); 609 info->fGlyphWidths->fAdvance.append(1, &advance);
676 } 610 }
677 } 611 }
678 finishRange(info->fGlyphWidths.get(), face->num_glyphs - 1, 612 finishRange(info->fGlyphWidths.get(), face->num_glyphs - 1,
679 SkAdvancedTypefaceMetrics::WidthRange::kRange); 613 SkAdvancedTypefaceMetrics::WidthRange::kRange);
680 } else { 614 } else {
681 info->fGlyphWidths.reset( 615 info->fGlyphWidths.reset(
682 getAdvanceData(face, 616 getAdvanceData(face,
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 if (glyphIndex == glyph) { 1030 if (glyphIndex == glyph) {
1097 return charCode; 1031 return charCode;
1098 } 1032 }
1099 charCode = FT_Get_Next_Char( fFace, charCode, &glyphIndex ); 1033 charCode = FT_Get_Next_Char( fFace, charCode, &glyphIndex );
1100 } 1034 }
1101 1035
1102 return 0; 1036 return 0;
1103 } 1037 }
1104 1038
1105 void SkScalerContext_FreeType::generateAdvance(SkGlyph* glyph) { 1039 void SkScalerContext_FreeType::generateAdvance(SkGlyph* glyph) {
1106 #ifdef FT_ADVANCES_H
1107 /* unhinted and light hinted text have linearly scaled advances 1040 /* unhinted and light hinted text have linearly scaled advances
1108 * which are very cheap to compute with some font formats... 1041 * which are very cheap to compute with some font formats...
1109 */ 1042 */
1110 if (fDoLinearMetrics) { 1043 if (fDoLinearMetrics) {
1111 SkAutoMutexAcquire ac(gFTMutex); 1044 SkAutoMutexAcquire ac(gFTMutex);
1112 1045
1113 if (this->setupSize()) { 1046 if (this->setupSize()) {
1114 glyph->zeroMetrics(); 1047 glyph->zeroMetrics();
1115 return; 1048 return;
1116 } 1049 }
1117 1050
1118 FT_Error error; 1051 FT_Error error;
1119 FT_Fixed advance; 1052 FT_Fixed advance;
1120 1053
1121 error = FT_Get_Advance( fFace, glyph->getGlyphID(), 1054 error = FT_Get_Advance( fFace, glyph->getGlyphID(),
1122 fLoadGlyphFlags | FT_ADVANCE_FLAG_FAST_ONLY, 1055 fLoadGlyphFlags | FT_ADVANCE_FLAG_FAST_ONLY,
1123 &advance ); 1056 &advance );
1124 if (0 == error) { 1057 if (0 == error) {
1125 glyph->fRsbDelta = 0; 1058 glyph->fRsbDelta = 0;
1126 glyph->fLsbDelta = 0; 1059 glyph->fLsbDelta = 0;
1127 glyph->fAdvanceX = SkFixedMul(fMatrix22.xx, advance); 1060 glyph->fAdvanceX = SkFixedMul(fMatrix22.xx, advance);
1128 glyph->fAdvanceY = - SkFixedMul(fMatrix22.yx, advance); 1061 glyph->fAdvanceY = - SkFixedMul(fMatrix22.yx, advance);
1129 return; 1062 return;
1130 } 1063 }
1131 } 1064 }
1132 #endif /* FT_ADVANCES_H */ 1065
1133 /* otherwise, we need to load/hint the glyph, which is slower */ 1066 /* otherwise, we need to load/hint the glyph, which is slower */
1134 this->generateMetrics(glyph); 1067 this->generateMetrics(glyph);
1135 return; 1068 return;
1136 } 1069 }
1137 1070
1138 void SkScalerContext_FreeType::getBBoxForCurrentGlyph(SkGlyph* glyph, 1071 void SkScalerContext_FreeType::getBBoxForCurrentGlyph(SkGlyph* glyph,
1139 FT_BBox* bbox, 1072 FT_BBox* bbox,
1140 bool snapToPixelBoundary) { 1073 bool snapToPixelBoundary) {
1141 1074
1142 FT_Outline_Get_CBox(&fFace->glyph->outline, bbox); 1075 FT_Outline_Get_CBox(&fFace->glyph->outline, bbox);
(...skipping 26 matching lines...) Expand all
1169 FT_Vector_Transform(&vector, &fMatrix22); 1102 FT_Vector_Transform(&vector, &fMatrix22);
1170 bbox->xMin += vector.x; 1103 bbox->xMin += vector.x;
1171 bbox->xMax += vector.x; 1104 bbox->xMax += vector.x;
1172 bbox->yMin += vector.y; 1105 bbox->yMin += vector.y;
1173 bbox->yMax += vector.y; 1106 bbox->yMax += vector.y;
1174 } 1107 }
1175 } 1108 }
1176 1109
1177 bool SkScalerContext_FreeType::getCBoxForLetter(char letter, FT_BBox* bbox) { 1110 bool SkScalerContext_FreeType::getCBoxForLetter(char letter, FT_BBox* bbox) {
1178 const FT_UInt glyph_id = FT_Get_Char_Index(fFace, letter); 1111 const FT_UInt glyph_id = FT_Get_Char_Index(fFace, letter);
1179 if (!glyph_id) 1112 if (!glyph_id) {
1180 return false; 1113 return false;
1181 if (FT_Load_Glyph(fFace, glyph_id, fLoadGlyphFlags) != 0) 1114 }
1115 if (FT_Load_Glyph(fFace, glyph_id, fLoadGlyphFlags) != 0) {
1182 return false; 1116 return false;
1117 }
1183 emboldenIfNeeded(fFace, fFace->glyph); 1118 emboldenIfNeeded(fFace, fFace->glyph);
1184 FT_Outline_Get_CBox(&fFace->glyph->outline, bbox); 1119 FT_Outline_Get_CBox(&fFace->glyph->outline, bbox);
1185 return true; 1120 return true;
1186 } 1121 }
1187 1122
1188 void SkScalerContext_FreeType::updateGlyphIfLCD(SkGlyph* glyph) { 1123 void SkScalerContext_FreeType::updateGlyphIfLCD(SkGlyph* glyph) {
1189 if (isLCD(fRec)) { 1124 if (isLCD(fRec)) {
1190 if (fLCDIsVert) { 1125 if (fLCDIsVert) {
1191 glyph->fHeight += gLCDExtra; 1126 glyph->fHeight += gLCDExtra;
1192 glyph->fTop -= gLCDExtra >> 1; 1127 glyph->fTop -= gLCDExtra >> 1;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 scaleGlyphMetrics(*glyph, SkScalarDiv(SkFixedToScalar(fScaleY), 1242 scaleGlyphMetrics(*glyph, SkScalarDiv(SkFixedToScalar(fScaleY),
1308 SkIntToScalar(fFace->size->metrics .y_ppem))); 1243 SkIntToScalar(fFace->size->metrics .y_ppem)));
1309 } 1244 }
1310 1245
1311 #ifdef ENABLE_GLYPH_SPEW 1246 #ifdef ENABLE_GLYPH_SPEW
1312 SkDEBUGF(("FT_Set_Char_Size(this:%p sx:%x sy:%x ", this, fScaleX, fScaleY)); 1247 SkDEBUGF(("FT_Set_Char_Size(this:%p sx:%x sy:%x ", this, fScaleX, fScaleY));
1313 SkDEBUGF(("Metrics(glyph:%d flags:0x%x) w:%d\n", glyph->getGlyphID(), fLoadG lyphFlags, glyph->fWidth)); 1248 SkDEBUGF(("Metrics(glyph:%d flags:0x%x) w:%d\n", glyph->getGlyphID(), fLoadG lyphFlags, glyph->fWidth));
1314 #endif 1249 #endif
1315 } 1250 }
1316 1251
1252 static void clear_glyph_image(const SkGlyph& glyph) {
1253 memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight);
mtklein 2014/11/21 21:00:03 sk_bzero?
bungeman-skia 2014/11/21 21:07:43 Why not, I just copy-pasted this to get around the
1254 }
1317 1255
1318 void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) { 1256 void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) {
1319 SkAutoMutexAcquire ac(gFTMutex); 1257 SkAutoMutexAcquire ac(gFTMutex);
1320 1258
1321 FT_Error err;
1322
1323 if (this->setupSize()) { 1259 if (this->setupSize()) {
1324 goto ERROR; 1260 clear_glyph_image(glyph);
1325 }
1326
1327 err = FT_Load_Glyph( fFace, glyph.getGlyphID(), fLoadGlyphFlags);
1328 if (err != 0) {
1329 SkDEBUGF(("SkScalerContext_FreeType::generateImage: FT_Load_Glyph(glyph: %d width:%d height:%d rb:%d flags:%d) returned 0x%x\n",
1330 glyph.getGlyphID(), glyph.fWidth, glyph.fHeight, glyph.rowBy tes(), fLoadGlyphFlags, err));
1331 ERROR:
1332 memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight);
1333 return; 1261 return;
1334 } 1262 }
1335 1263
1264 FT_Error err = FT_Load_Glyph(fFace, glyph.getGlyphID(), fLoadGlyphFlags);
1265 if (err != 0) {
1266 SkDEBUGF(("SkScalerContext_FreeType::generateImage: FT_Load_Glyph(glyph: %d width:%d height:%d rb:%d flags:%d) returned 0x%x\n",
1267 glyph.getGlyphID(), glyph.fWidth, glyph.fHeight, glyph.rowByte s(), fLoadGlyphFlags, err));
1268 clear_glyph_image(glyph);
1269 return;
1270 }
1271
1336 emboldenIfNeeded(fFace, fFace->glyph); 1272 emboldenIfNeeded(fFace, fFace->glyph);
1337 generateGlyphImage(fFace, glyph); 1273 generateGlyphImage(fFace, glyph);
1338 } 1274 }
1339 1275
1340 1276
1341 void SkScalerContext_FreeType::generatePath(const SkGlyph& glyph, 1277 void SkScalerContext_FreeType::generatePath(const SkGlyph& glyph, SkPath* path) {
1342 SkPath* path) {
1343 SkAutoMutexAcquire ac(gFTMutex); 1278 SkAutoMutexAcquire ac(gFTMutex);
1344 1279
1345 SkASSERT(path); 1280 SkASSERT(path);
1346 1281
1347 if (this->setupSize()) { 1282 if (this->setupSize()) {
1348 path->reset(); 1283 path->reset();
1349 return; 1284 return;
1350 } 1285 }
1351 1286
1352 uint32_t flags = fLoadGlyphFlags; 1287 uint32_t flags = fLoadGlyphFlags;
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 if (style) { 1735 if (style) {
1801 *style = SkFontStyle(weight, width, slant); 1736 *style = SkFontStyle(weight, width, slant);
1802 } 1737 }
1803 if (isFixedPitch) { 1738 if (isFixedPitch) {
1804 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1739 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1805 } 1740 }
1806 1741
1807 FT_Done_Face(face); 1742 FT_Done_Face(face);
1808 return true; 1743 return true;
1809 } 1744 }
OLDNEW
« no previous file with comments | « gyp/freetype.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698