OLD | NEW |
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 #ifdef SK_FONTHOST_FREETYPE_USE_NORMAL_LCD_FILTER | 136 #ifdef SK_FONTHOST_FREETYPE_USE_NORMAL_LCD_FILTER |
137 // This also adds to 0x110 simulating ink spread, but provides better re
sults than default. | 137 // This also adds to 0x110 simulating ink spread, but provides better re
sults than default. |
138 static unsigned char gGaussianLikeHeavyWeights[] = { 0x1A, 0x43, 0x56, 0
x43, 0x1A, }; | 138 static unsigned char gGaussianLikeHeavyWeights[] = { 0x1A, 0x43, 0x56, 0
x43, 0x1A, }; |
139 | 139 |
140 #if defined(SK_FONTHOST_FREETYPE_RUNTIME_VERSION) && \ | 140 #if defined(SK_FONTHOST_FREETYPE_RUNTIME_VERSION) && \ |
141 SK_FONTHOST_FREETYPE_RUNTIME_VERSION > 0x020400 | 141 SK_FONTHOST_FREETYPE_RUNTIME_VERSION > 0x020400 |
142 err = FT_Library_SetLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeigh
ts); | 142 err = FT_Library_SetLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeigh
ts); |
143 #elif defined(SK_CAN_USE_DLOPEN) && SK_CAN_USE_DLOPEN == 1 | 143 #elif defined(SK_CAN_USE_DLOPEN) && SK_CAN_USE_DLOPEN == 1 |
144 //The FreeType library is already loaded, so symbols are available in pr
ocess. | 144 //The FreeType library is already loaded, so symbols are available in pr
ocess. |
145 void* self = dlopen(NULL, RTLD_LAZY); | 145 void* self = dlopen(NULL, RTLD_LAZY); |
146 if (NULL != self) { | 146 if (self) { |
147 FT_Library_SetLcdFilterWeightsProc setLcdFilterWeights; | 147 FT_Library_SetLcdFilterWeightsProc setLcdFilterWeights; |
148 //The following cast is non-standard, but safe for POSIX. | 148 //The following cast is non-standard, but safe for POSIX. |
149 *reinterpret_cast<void**>(&setLcdFilterWeights) = dlsym(self, "FT_Li
brary_SetLcdFilterWeights"); | 149 *reinterpret_cast<void**>(&setLcdFilterWeights) = dlsym(self, "FT_Li
brary_SetLcdFilterWeights"); |
150 dlclose(self); | 150 dlclose(self); |
151 | 151 |
152 if (NULL != setLcdFilterWeights) { | 152 if (setLcdFilterWeights) { |
153 err = setLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeights)
; | 153 err = setLcdFilterWeights(gFTLibrary, gGaussianLikeHeavyWeights)
; |
154 } | 154 } |
155 } | 155 } |
156 #endif | 156 #endif |
157 #endif | 157 #endif |
158 } | 158 } |
159 #else | 159 #else |
160 gLCDSupport = false; | 160 gLCDSupport = false; |
161 #endif | 161 #endif |
162 gLCDSupportValid = true; | 162 gLCDSupportValid = true; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return NULL; | 309 return NULL; |
310 } | 310 } |
311 | 311 |
312 // this passes ownership of strm to the rec | 312 // this passes ownership of strm to the rec |
313 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID)); | 313 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID)); |
314 | 314 |
315 FT_Open_Args args; | 315 FT_Open_Args args; |
316 memset(&args, 0, sizeof(args)); | 316 memset(&args, 0, sizeof(args)); |
317 const void* memoryBase = strm->getMemoryBase(); | 317 const void* memoryBase = strm->getMemoryBase(); |
318 | 318 |
319 if (NULL != memoryBase) { | 319 if (memoryBase) { |
320 //printf("mmap(%s)\n", keyString.c_str()); | 320 //printf("mmap(%s)\n", keyString.c_str()); |
321 args.flags = FT_OPEN_MEMORY; | 321 args.flags = FT_OPEN_MEMORY; |
322 args.memory_base = (const FT_Byte*)memoryBase; | 322 args.memory_base = (const FT_Byte*)memoryBase; |
323 args.memory_size = strm->getLength(); | 323 args.memory_size = strm->getLength(); |
324 } else { | 324 } else { |
325 //printf("fopen(%s)\n", keyString.c_str()); | 325 //printf("fopen(%s)\n", keyString.c_str()); |
326 args.flags = FT_OPEN_STREAM; | 326 args.flags = FT_OPEN_STREAM; |
327 args.stream = &rec->fFTStream; | 327 args.stream = &rec->fFTStream; |
328 } | 328 } |
329 | 329 |
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 // When 'length' is 0 it is overwritten with the full table length; 'offset'
is ignored. | 1647 // When 'length' is 0 it is overwritten with the full table length; 'offset'
is ignored. |
1648 error = FT_Load_Sfnt_Table(face, tag, 0, NULL, &tableLength); | 1648 error = FT_Load_Sfnt_Table(face, tag, 0, NULL, &tableLength); |
1649 if (error) { | 1649 if (error) { |
1650 return 0; | 1650 return 0; |
1651 } | 1651 } |
1652 | 1652 |
1653 if (offset > tableLength) { | 1653 if (offset > tableLength) { |
1654 return 0; | 1654 return 0; |
1655 } | 1655 } |
1656 FT_ULong size = SkTMin((FT_ULong)length, tableLength - (FT_ULong)offset); | 1656 FT_ULong size = SkTMin((FT_ULong)length, tableLength - (FT_ULong)offset); |
1657 if (NULL != data) { | 1657 if (data) { |
1658 error = FT_Load_Sfnt_Table(face, tag, offset, reinterpret_cast<FT_Byte*>
(data), &size); | 1658 error = FT_Load_Sfnt_Table(face, tag, offset, reinterpret_cast<FT_Byte*>
(data), &size); |
1659 if (error) { | 1659 if (error) { |
1660 return 0; | 1660 return 0; |
1661 } | 1661 } |
1662 } | 1662 } |
1663 | 1663 |
1664 return size; | 1664 return size; |
1665 } | 1665 } |
1666 | 1666 |
1667 /////////////////////////////////////////////////////////////////////////////// | 1667 /////////////////////////////////////////////////////////////////////////////// |
1668 /////////////////////////////////////////////////////////////////////////////// | 1668 /////////////////////////////////////////////////////////////////////////////// |
1669 | 1669 |
1670 /*static*/ bool SkTypeface_FreeType::ScanFont( | 1670 /*static*/ bool SkTypeface_FreeType::ScanFont( |
1671 SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bo
ol* isFixedPitch) | 1671 SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bo
ol* isFixedPitch) |
1672 { | 1672 { |
1673 FT_Library library; | 1673 FT_Library library; |
1674 if (FT_Init_FreeType(&library)) { | 1674 if (FT_Init_FreeType(&library)) { |
1675 return false; | 1675 return false; |
1676 } | 1676 } |
1677 | 1677 |
1678 FT_Open_Args args; | 1678 FT_Open_Args args; |
1679 memset(&args, 0, sizeof(args)); | 1679 memset(&args, 0, sizeof(args)); |
1680 | 1680 |
1681 const void* memoryBase = stream->getMemoryBase(); | 1681 const void* memoryBase = stream->getMemoryBase(); |
1682 FT_StreamRec streamRec; | 1682 FT_StreamRec streamRec; |
1683 | 1683 |
1684 if (NULL != memoryBase) { | 1684 if (memoryBase) { |
1685 args.flags = FT_OPEN_MEMORY; | 1685 args.flags = FT_OPEN_MEMORY; |
1686 args.memory_base = (const FT_Byte*)memoryBase; | 1686 args.memory_base = (const FT_Byte*)memoryBase; |
1687 args.memory_size = stream->getLength(); | 1687 args.memory_size = stream->getLength(); |
1688 } else { | 1688 } else { |
1689 memset(&streamRec, 0, sizeof(streamRec)); | 1689 memset(&streamRec, 0, sizeof(streamRec)); |
1690 streamRec.size = stream->getLength(); | 1690 streamRec.size = stream->getLength(); |
1691 streamRec.descriptor.pointer = stream; | 1691 streamRec.descriptor.pointer = stream; |
1692 streamRec.read = sk_stream_read; | 1692 streamRec.read = sk_stream_read; |
1693 streamRec.close = sk_stream_close; | 1693 streamRec.close = sk_stream_close; |
1694 | 1694 |
(...skipping 22 matching lines...) Expand all Loading... |
1717 *style = (SkTypeface::Style) tempStyle; | 1717 *style = (SkTypeface::Style) tempStyle; |
1718 } | 1718 } |
1719 if (isFixedPitch) { | 1719 if (isFixedPitch) { |
1720 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1720 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
1721 } | 1721 } |
1722 | 1722 |
1723 FT_Done_Face(face); | 1723 FT_Done_Face(face); |
1724 FT_Done_FreeType(library); | 1724 FT_Done_FreeType(library); |
1725 return true; | 1725 return true; |
1726 } | 1726 } |
OLD | NEW |