OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include FT_LCD_FILTER_H | 35 #include FT_LCD_FILTER_H |
36 #include FT_MODULE_H | 36 #include FT_MODULE_H |
37 #include FT_MULTIPLE_MASTERS_H | 37 #include FT_MULTIPLE_MASTERS_H |
38 #include FT_OUTLINE_H | 38 #include FT_OUTLINE_H |
39 #include FT_SIZES_H | 39 #include FT_SIZES_H |
40 #include FT_SYSTEM_H | 40 #include FT_SYSTEM_H |
41 #include FT_TRUETYPE_TABLES_H | 41 #include FT_TRUETYPE_TABLES_H |
42 #include FT_TYPE1_TABLES_H | 42 #include FT_TYPE1_TABLES_H |
43 #include FT_XFREE86_H | 43 #include FT_XFREE86_H |
44 | 44 |
| 45 #if !defined(SK_BUILD_FOR_ANDROID) || defined(SK_ANDROID_FREETYPE_HAS_MM) |
| 46 # define SK_FREETYPE_HAS_MM 1 |
| 47 #endif |
| 48 |
45 // FT_LOAD_COLOR and the corresponding FT_Pixel_Mode::FT_PIXEL_MODE_BGRA | 49 // FT_LOAD_COLOR and the corresponding FT_Pixel_Mode::FT_PIXEL_MODE_BGRA |
46 // were introduced in FreeType 2.5.0. | 50 // were introduced in FreeType 2.5.0. |
47 // The following may be removed once FreeType 2.5.0 is required to build. | 51 // The following may be removed once FreeType 2.5.0 is required to build. |
48 #ifndef FT_LOAD_COLOR | 52 #ifndef FT_LOAD_COLOR |
49 # define FT_LOAD_COLOR ( 1L << 20 ) | 53 # define FT_LOAD_COLOR ( 1L << 20 ) |
50 # define FT_PIXEL_MODE_BGRA 7 | 54 # define FT_PIXEL_MODE_BGRA 7 |
51 #endif | 55 #endif |
52 | 56 |
53 // FT_HAS_COLOR and the corresponding FT_FACE_FLAG_COLOR | 57 // FT_HAS_COLOR and the corresponding FT_FACE_FLAG_COLOR |
54 // were introduced in FreeType 2.5.1 | 58 // were introduced in FreeType 2.5.1 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID) | 272 SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID) |
269 : fNext(NULL), fSkStream(stream), fRefCnt(1), fFontID(fontID) | 273 : fNext(NULL), fSkStream(stream), fRefCnt(1), fFontID(fontID) |
270 { | 274 { |
271 sk_bzero(&fFTStream, sizeof(fFTStream)); | 275 sk_bzero(&fFTStream, sizeof(fFTStream)); |
272 fFTStream.size = fSkStream->getLength(); | 276 fFTStream.size = fSkStream->getLength(); |
273 fFTStream.descriptor.pointer = fSkStream; | 277 fFTStream.descriptor.pointer = fSkStream; |
274 fFTStream.read = sk_ft_stream_io; | 278 fFTStream.read = sk_ft_stream_io; |
275 fFTStream.close = sk_ft_stream_close; | 279 fFTStream.close = sk_ft_stream_close; |
276 } | 280 } |
277 | 281 |
| 282 #if SK_FREETYPE_HAS_MM |
278 static void ft_face_setup_axes(FT_Face face, const SkFontData& data) { | 283 static void ft_face_setup_axes(FT_Face face, const SkFontData& data) { |
279 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) { | 284 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) { |
280 return; | 285 return; |
281 } | 286 } |
282 | 287 |
283 SkDEBUGCODE( | 288 SkDEBUGCODE( |
284 FT_MM_Var* variations = NULL; | 289 FT_MM_Var* variations = NULL; |
285 if (FT_Get_MM_Var(face, &variations)) { | 290 if (FT_Get_MM_Var(face, &variations)) { |
286 SkDEBUGF(("INFO: font %s claims variations, but none found.\n", face
->family_name)); | 291 SkDEBUGF(("INFO: font %s claims variations, but none found.\n", face
->family_name)); |
287 return; | 292 return; |
(...skipping 10 matching lines...) Expand all Loading... |
298 SkAutoSTMalloc<4, FT_Fixed> coords(data.getAxisCount()); | 303 SkAutoSTMalloc<4, FT_Fixed> coords(data.getAxisCount()); |
299 for (int i = 0; i < data.getAxisCount(); ++i) { | 304 for (int i = 0; i < data.getAxisCount(); ++i) { |
300 coords[i] = data.getAxis()[i]; | 305 coords[i] = data.getAxis()[i]; |
301 } | 306 } |
302 if (FT_Set_Var_Design_Coordinates(face, data.getAxisCount(), coords.get()))
{ | 307 if (FT_Set_Var_Design_Coordinates(face, data.getAxisCount(), coords.get()))
{ |
303 SkDEBUGF(("INFO: font %s has variations, but specified variations could
not be set.\n", | 308 SkDEBUGF(("INFO: font %s has variations, but specified variations could
not be set.\n", |
304 face->family_name)); | 309 face->family_name)); |
305 return; | 310 return; |
306 } | 311 } |
307 } | 312 } |
| 313 #endif |
308 | 314 |
309 // Will return 0 on failure | 315 // Will return 0 on failure |
310 // Caller must lock gFTMutex before calling this function. | 316 // Caller must lock gFTMutex before calling this function. |
311 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) { | 317 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) { |
312 gFTMutex.assertHeld(); | 318 gFTMutex.assertHeld(); |
313 | 319 |
314 const SkFontID fontID = typeface->uniqueID(); | 320 const SkFontID fontID = typeface->uniqueID(); |
315 SkFaceRec* rec = gFaceRecHead; | 321 SkFaceRec* rec = gFaceRecHead; |
316 while (rec) { | 322 while (rec) { |
317 if (rec->fFontID == fontID) { | 323 if (rec->fFontID == fontID) { |
(...skipping 25 matching lines...) Expand all Loading... |
343 } | 349 } |
344 | 350 |
345 FT_Error err = FT_Open_Face(gFTLibrary->library(), &args, data->getIndex(),
&rec->fFace); | 351 FT_Error err = FT_Open_Face(gFTLibrary->library(), &args, data->getIndex(),
&rec->fFace); |
346 if (err) { | 352 if (err) { |
347 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID)); | 353 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID)); |
348 SkDELETE(rec); | 354 SkDELETE(rec); |
349 return NULL; | 355 return NULL; |
350 } | 356 } |
351 SkASSERT(rec->fFace); | 357 SkASSERT(rec->fFace); |
352 | 358 |
| 359 #if SK_FREETYPE_HAS_MM |
353 ft_face_setup_axes(rec->fFace, *data); | 360 ft_face_setup_axes(rec->fFace, *data); |
| 361 #endif |
354 | 362 |
355 rec->fNext = gFaceRecHead; | 363 rec->fNext = gFaceRecHead; |
356 gFaceRecHead = rec; | 364 gFaceRecHead = rec; |
357 return rec; | 365 return rec; |
358 } | 366 } |
359 | 367 |
360 // Caller must lock gFTMutex before calling this function. | 368 // Caller must lock gFTMutex before calling this function. |
361 static void unref_ft_face(FT_Face face) { | 369 static void unref_ft_face(FT_Face face) { |
362 gFTMutex.assertHeld(); | 370 gFTMutex.assertHeld(); |
363 | 371 |
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 if (name) { | 1762 if (name) { |
1755 name->set(face->family_name); | 1763 name->set(face->family_name); |
1756 } | 1764 } |
1757 if (style) { | 1765 if (style) { |
1758 *style = SkFontStyle(weight, width, slant); | 1766 *style = SkFontStyle(weight, width, slant); |
1759 } | 1767 } |
1760 if (isFixedPitch) { | 1768 if (isFixedPitch) { |
1761 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1769 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
1762 } | 1770 } |
1763 | 1771 |
| 1772 #if SK_FREETYPE_HAS_MM |
1764 if (axes && face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) { | 1773 if (axes && face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS) { |
1765 FT_MM_Var* variations = NULL; | 1774 FT_MM_Var* variations = NULL; |
1766 FT_Error err = FT_Get_MM_Var(face, &variations); | 1775 FT_Error err = FT_Get_MM_Var(face, &variations); |
1767 if (err) { | 1776 if (err) { |
1768 SkDEBUGF(("INFO: font %s claims to have variations, but none found.\
n", | 1777 SkDEBUGF(("INFO: font %s claims to have variations, but none found.\
n", |
1769 face->family_name)); | 1778 face->family_name)); |
1770 return false; | 1779 return false; |
1771 } | 1780 } |
1772 SkAutoFree autoFreeVariations(variations); | 1781 SkAutoFree autoFreeVariations(variations); |
1773 | 1782 |
1774 axes->reset(variations->num_axis); | 1783 axes->reset(variations->num_axis); |
1775 for (FT_UInt i = 0; i < variations->num_axis; ++i) { | 1784 for (FT_UInt i = 0; i < variations->num_axis; ++i) { |
1776 const FT_Var_Axis& ftAxis = variations->axis[i]; | 1785 const FT_Var_Axis& ftAxis = variations->axis[i]; |
1777 (*axes)[i].fTag = ftAxis.tag; | 1786 (*axes)[i].fTag = ftAxis.tag; |
1778 (*axes)[i].fMinimum = ftAxis.minimum; | 1787 (*axes)[i].fMinimum = ftAxis.minimum; |
1779 (*axes)[i].fDefault = ftAxis.def; | 1788 (*axes)[i].fDefault = ftAxis.def; |
1780 (*axes)[i].fMaximum = ftAxis.maximum; | 1789 (*axes)[i].fMaximum = ftAxis.maximum; |
1781 } | 1790 } |
1782 } | 1791 } |
| 1792 #endif |
1783 | 1793 |
1784 FT_Done_Face(face); | 1794 FT_Done_Face(face); |
1785 return true; | 1795 return true; |
1786 } | 1796 } |
OLD | NEW |