| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "../../../include/fxge/fx_freetype.h" | 8 #include "../../../include/fxge/fx_freetype.h" |
| 9 #include "text_int.h" | 9 #include "text_int.h" |
| 10 #define EM_ADJUST(em, a) (em == 0?(a): (a)*1000/em) | 10 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) |
| 11 extern void _FPDFAPI_GetInternalFontData(int id1, const uint8_t*& data, FX_DWORD
& size); | 11 extern void _FPDFAPI_GetInternalFontData(int id1, |
| 12 CFX_Font::CFX_Font() | 12 const uint8_t*& data, |
| 13 { | 13 FX_DWORD& size); |
| 14 m_pSubstFont = NULL; | 14 CFX_Font::CFX_Font() { |
| 15 m_Face = NULL; | 15 m_pSubstFont = NULL; |
| 16 m_bEmbedded = FALSE; | 16 m_Face = NULL; |
| 17 m_bVertical = FALSE; | 17 m_bEmbedded = FALSE; |
| 18 m_pFontData = NULL; | 18 m_bVertical = FALSE; |
| 19 m_pFontData = NULL; |
| 20 m_pFontDataAllocation = NULL; |
| 21 m_dwSize = 0; |
| 22 m_pOwnedStream = NULL; |
| 23 m_pGsubData = NULL; |
| 24 m_pPlatformFont = NULL; |
| 25 m_pPlatformFontCollection = NULL; |
| 26 m_pDwFont = NULL; |
| 27 m_hHandle = NULL; |
| 28 m_bDwLoaded = FALSE; |
| 29 } |
| 30 CFX_Font::~CFX_Font() { |
| 31 delete m_pSubstFont; |
| 32 m_pSubstFont = NULL; |
| 33 if (m_pFontDataAllocation) { |
| 34 FX_Free(m_pFontDataAllocation); |
| 19 m_pFontDataAllocation = NULL; | 35 m_pFontDataAllocation = NULL; |
| 20 m_dwSize = 0; | 36 } |
| 37 if (m_Face) { |
| 38 if (FXFT_Get_Face_External_Stream(m_Face)) { |
| 39 FXFT_Clear_Face_External_Stream(m_Face); |
| 40 } |
| 41 if (m_bEmbedded) { |
| 42 DeleteFace(); |
| 43 } else { |
| 44 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); |
| 45 } |
| 46 } |
| 47 if (m_pOwnedStream) { |
| 48 FX_Free(m_pOwnedStream); |
| 21 m_pOwnedStream = NULL; | 49 m_pOwnedStream = NULL; |
| 50 } |
| 51 if (m_pGsubData) { |
| 52 FX_Free(m_pGsubData); |
| 22 m_pGsubData = NULL; | 53 m_pGsubData = NULL; |
| 23 m_pPlatformFont = NULL; | 54 } |
| 24 m_pPlatformFontCollection = NULL; | 55 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 25 m_pDwFont = NULL; | 56 ReleasePlatformResource(); |
| 26 m_hHandle = NULL; | |
| 27 m_bDwLoaded = FALSE; | |
| 28 } | |
| 29 CFX_Font::~CFX_Font() | |
| 30 { | |
| 31 delete m_pSubstFont; | |
| 32 m_pSubstFont = NULL; | |
| 33 if (m_pFontDataAllocation) { | |
| 34 FX_Free(m_pFontDataAllocation); | |
| 35 m_pFontDataAllocation = NULL; | |
| 36 } | |
| 37 if (m_Face) { | |
| 38 if (FXFT_Get_Face_External_Stream(m_Face)) { | |
| 39 FXFT_Clear_Face_External_Stream(m_Face); | |
| 40 } | |
| 41 if(m_bEmbedded) { | |
| 42 DeleteFace(); | |
| 43 } else { | |
| 44 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | |
| 45 } | |
| 46 } | |
| 47 if (m_pOwnedStream) { | |
| 48 FX_Free(m_pOwnedStream); | |
| 49 m_pOwnedStream = NULL; | |
| 50 } | |
| 51 if (m_pGsubData) { | |
| 52 FX_Free(m_pGsubData); | |
| 53 m_pGsubData = NULL; | |
| 54 } | |
| 55 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | |
| 56 ReleasePlatformResource(); | |
| 57 #endif | 57 #endif |
| 58 } | 58 } |
| 59 void CFX_Font::DeleteFace() | 59 void CFX_Font::DeleteFace() { |
| 60 { | 60 FXFT_Done_Face(m_Face); |
| 61 FXFT_Done_Face(m_Face); | 61 m_Face = NULL; |
| 62 m_Face = NULL; | 62 } |
| 63 } | 63 FX_BOOL CFX_Font::LoadSubst(const CFX_ByteString& face_name, |
| 64 FX_BOOL CFX_Font::LoadSubst(const CFX_ByteString& face_name, FX_BOOL bTrueType,
FX_DWORD flags, | 64 FX_BOOL bTrueType, |
| 65 int weight, int italic_angle, int CharsetCP, FX_BOOL
bVertical) | 65 FX_DWORD flags, |
| 66 { | 66 int weight, |
| 67 m_bEmbedded = FALSE; | 67 int italic_angle, |
| 68 m_bVertical = bVertical; | 68 int CharsetCP, |
| 69 m_pSubstFont = new CFX_SubstFont; | 69 FX_BOOL bVertical) { |
| 70 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont(face_name, bTrueTy
pe, flags, weight, italic_angle, | 70 m_bEmbedded = FALSE; |
| 71 CharsetCP, m_pSubstFont); | 71 m_bVertical = bVertical; |
| 72 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 72 m_pSubstFont = new CFX_SubstFont; |
| 73 if(m_pSubstFont->m_ExtHandle) { | 73 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( |
| 74 m_pPlatformFont = m_pSubstFont->m_ExtHandle; | 74 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, |
| 75 m_pSubstFont->m_ExtHandle = NULL; | 75 m_pSubstFont); |
| 76 } | 76 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 77 if (m_pSubstFont->m_ExtHandle) { |
| 78 m_pPlatformFont = m_pSubstFont->m_ExtHandle; |
| 79 m_pSubstFont->m_ExtHandle = NULL; |
| 80 } |
| 77 #endif | 81 #endif |
| 78 if (m_Face) { | 82 if (m_Face) { |
| 79 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); | 83 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); |
| 80 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); | 84 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); |
| 81 } | 85 } |
| 82 return TRUE; | 86 return TRUE; |
| 83 } | 87 } |
| 84 extern "C" { | 88 extern "C" { |
| 85 unsigned long _FTStreamRead(FXFT_Stream stream, unsigned long offset, | 89 unsigned long _FTStreamRead(FXFT_Stream stream, |
| 86 unsigned char* buffer, unsigned long count) | 90 unsigned long offset, |
| 87 { | 91 unsigned char* buffer, |
| 88 if (count == 0) { | 92 unsigned long count) { |
| 89 return 0; | 93 if (count == 0) { |
| 90 } | 94 return 0; |
| 91 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; | 95 } |
| 92 int res = pFile->ReadBlock(buffer, offset, count); | 96 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; |
| 93 if (res) { | 97 int res = pFile->ReadBlock(buffer, offset, count); |
| 94 return count; | 98 if (res) { |
| 95 } | 99 return count; |
| 96 return 0; | 100 } |
| 97 } | 101 return 0; |
| 98 void _FTStreamClose(FXFT_Stream stream) | 102 } |
| 99 { | 103 void _FTStreamClose(FXFT_Stream stream) {} |
| 100 } | |
| 101 }; | 104 }; |
| 102 FX_BOOL _LoadFile(FXFT_Library library, FXFT_Face* Face, IFX_FileRead* pFile, FX
FT_Stream* stream) | 105 FX_BOOL _LoadFile(FXFT_Library library, |
| 103 { | 106 FXFT_Face* Face, |
| 104 FXFT_Stream stream1 = (FXFT_Stream)FX_Alloc(uint8_t, sizeof (FXFT_StreamRec)
); | 107 IFX_FileRead* pFile, |
| 105 stream1->base = NULL; | 108 FXFT_Stream* stream) { |
| 106 stream1->size = (unsigned long)pFile->GetSize(); | 109 FXFT_Stream stream1 = (FXFT_Stream)FX_Alloc(uint8_t, sizeof(FXFT_StreamRec)); |
| 107 stream1->pos = 0; | 110 stream1->base = NULL; |
| 108 stream1->descriptor.pointer = pFile; | 111 stream1->size = (unsigned long)pFile->GetSize(); |
| 109 stream1->close = _FTStreamClose; | 112 stream1->pos = 0; |
| 110 stream1->read = _FTStreamRead; | 113 stream1->descriptor.pointer = pFile; |
| 111 FXFT_Open_Args args; | 114 stream1->close = _FTStreamClose; |
| 112 args.flags = FT_OPEN_STREAM; | 115 stream1->read = _FTStreamRead; |
| 113 args.stream = stream1; | 116 FXFT_Open_Args args; |
| 114 if (FXFT_Open_Face(library, &args, 0, Face)) { | 117 args.flags = FT_OPEN_STREAM; |
| 115 FX_Free(stream1); | 118 args.stream = stream1; |
| 116 return FALSE; | 119 if (FXFT_Open_Face(library, &args, 0, Face)) { |
| 117 } | 120 FX_Free(stream1); |
| 118 if (stream) { | 121 return FALSE; |
| 119 *stream = stream1; | 122 } |
| 120 } | 123 if (stream) { |
| 121 return TRUE; | 124 *stream = stream1; |
| 122 } | 125 } |
| 123 FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile) | 126 return TRUE; |
| 124 { | 127 } |
| 125 m_bEmbedded = FALSE; | 128 FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile) { |
| 126 FXFT_Library library; | 129 m_bEmbedded = FALSE; |
| 127 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) { | 130 FXFT_Library library; |
| 128 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); | 131 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) { |
| 129 } | 132 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); |
| 130 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; | 133 } |
| 131 FXFT_Stream stream = NULL; | 134 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; |
| 132 if (!_LoadFile(library, &m_Face, pFile, &stream)) { | 135 FXFT_Stream stream = NULL; |
| 133 return FALSE; | 136 if (!_LoadFile(library, &m_Face, pFile, &stream)) { |
| 134 } | 137 return FALSE; |
| 135 m_pOwnedStream = stream; | 138 } |
| 136 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 139 m_pOwnedStream = stream; |
| 137 return TRUE; | 140 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
| 138 } | 141 return TRUE; |
| 139 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) | 142 } |
| 140 { | 143 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) { |
| 141 if (!m_Face) { | 144 if (!m_Face) { |
| 142 return 0; | 145 return 0; |
| 143 } | 146 } |
| 144 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { | 147 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { |
| 145 AdjustMMParams(glyph_index, 0, 0); | 148 AdjustMMParams(glyph_index, 0, 0); |
| 146 } | 149 } |
| 147 int err = FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOA
D_IGNORE_GLOBAL_ADVANCE_WIDTH); | 150 int err = FXFT_Load_Glyph( |
| 148 if (err) { | 151 m_Face, glyph_index, |
| 149 return 0; | 152 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); |
| 150 } | 153 if (err) { |
| 151 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriA
dvance(m_Face)); | 154 return 0; |
| 152 return width; | 155 } |
| 153 } | 156 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 154 static FXFT_Face FT_LoadFont(uint8_t* pData, int size) | 157 FXFT_Get_Glyph_HoriAdvance(m_Face)); |
| 155 { | 158 return width; |
| 156 FXFT_Library library; | 159 } |
| 157 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) { | 160 static FXFT_Face FT_LoadFont(uint8_t* pData, int size) { |
| 158 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); | 161 FXFT_Library library; |
| 159 } | 162 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) { |
| 160 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; | 163 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); |
| 161 FXFT_Face face = NULL; | 164 } |
| 162 int error = FXFT_New_Memory_Face(library, pData, size, 0, &face); | 165 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; |
| 166 FXFT_Face face = NULL; |
| 167 int error = FXFT_New_Memory_Face(library, pData, size, 0, &face); |
| 168 if (error) { |
| 169 return NULL; |
| 170 } |
| 171 error = FXFT_Set_Pixel_Sizes(face, 64, 64); |
| 172 if (error) { |
| 173 return NULL; |
| 174 } |
| 175 return face; |
| 176 } |
| 177 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) { |
| 178 m_pFontDataAllocation = FX_Alloc(uint8_t, size); |
| 179 FXSYS_memcpy(m_pFontDataAllocation, data, size); |
| 180 m_Face = FT_LoadFont((uint8_t*)m_pFontDataAllocation, size); |
| 181 m_pFontData = (uint8_t*)m_pFontDataAllocation; |
| 182 m_bEmbedded = TRUE; |
| 183 m_dwSize = size; |
| 184 return m_Face != NULL; |
| 185 } |
| 186 FX_BOOL CFX_Font::IsTTFont() { |
| 187 if (m_Face == NULL) { |
| 188 return FALSE; |
| 189 } |
| 190 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; |
| 191 } |
| 192 int CFX_Font::GetAscent() const { |
| 193 if (m_Face == NULL) { |
| 194 return 0; |
| 195 } |
| 196 int ascent = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 197 FXFT_Get_Face_Ascender(m_Face)); |
| 198 return ascent; |
| 199 } |
| 200 int CFX_Font::GetDescent() const { |
| 201 if (m_Face == NULL) { |
| 202 return 0; |
| 203 } |
| 204 int descent = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 205 FXFT_Get_Face_Descender(m_Face)); |
| 206 return descent; |
| 207 } |
| 208 FX_BOOL CFX_Font::GetGlyphBBox(FX_DWORD glyph_index, FX_RECT& bbox) { |
| 209 if (m_Face == NULL) { |
| 210 return FALSE; |
| 211 } |
| 212 if (FXFT_Is_Face_Tricky(m_Face)) { |
| 213 int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72); |
| 163 if (error) { | 214 if (error) { |
| 164 return NULL; | 215 return FALSE; |
| 165 } | 216 } |
| 166 error = FXFT_Set_Pixel_Sizes(face, 64, 64); | 217 error = FXFT_Load_Glyph(m_Face, glyph_index, |
| 218 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); |
| 167 if (error) { | 219 if (error) { |
| 168 return NULL; | 220 return FALSE; |
| 169 } | 221 } |
| 170 return face; | 222 FXFT_BBox cbox; |
| 171 } | 223 FT_Glyph glyph; |
| 172 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) | 224 error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph); |
| 173 { | 225 if (error) { |
| 174 m_pFontDataAllocation = FX_Alloc(uint8_t, size); | 226 return FALSE; |
| 175 FXSYS_memcpy(m_pFontDataAllocation, data, size); | 227 } |
| 176 m_Face = FT_LoadFont((uint8_t*)m_pFontDataAllocation, size); | 228 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); |
| 177 m_pFontData = (uint8_t*)m_pFontDataAllocation; | 229 int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem, |
| 178 m_bEmbedded = TRUE; | 230 pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem; |
| 179 m_dwSize = size; | 231 if (pixel_size_x == 0 || pixel_size_y == 0) { |
| 180 return m_Face != NULL; | 232 bbox.left = cbox.xMin; |
| 181 } | 233 bbox.right = cbox.xMax; |
| 182 FX_BOOL CFX_Font::IsTTFont() | 234 bbox.top = cbox.yMax; |
| 183 { | 235 bbox.bottom = cbox.yMin; |
| 184 if (m_Face == NULL) { | |
| 185 return FALSE; | |
| 186 } | |
| 187 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; | |
| 188 } | |
| 189 int CFX_Font::GetAscent() const | |
| 190 { | |
| 191 if (m_Face == NULL) { | |
| 192 return 0; | |
| 193 } | |
| 194 int ascent = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Ascen
der(m_Face)); | |
| 195 return ascent; | |
| 196 } | |
| 197 int CFX_Font::GetDescent() const | |
| 198 { | |
| 199 if (m_Face == NULL) { | |
| 200 return 0; | |
| 201 } | |
| 202 int descent = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Desc
ender(m_Face)); | |
| 203 return descent; | |
| 204 } | |
| 205 FX_BOOL CFX_Font::GetGlyphBBox(FX_DWORD glyph_index, FX_RECT &bbox) | |
| 206 { | |
| 207 if (m_Face == NULL) { | |
| 208 return FALSE; | |
| 209 } | |
| 210 if (FXFT_Is_Face_Tricky(m_Face)) { | |
| 211 int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72); | |
| 212 if (error) { | |
| 213 return FALSE; | |
| 214 } | |
| 215 error = FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL_ADV
ANCE_WIDTH); | |
| 216 if (error) { | |
| 217 return FALSE; | |
| 218 } | |
| 219 FXFT_BBox cbox; | |
| 220 FT_Glyph glyph; | |
| 221 error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph); | |
| 222 if (error) { | |
| 223 return FALSE; | |
| 224 } | |
| 225 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); | |
| 226 int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem, | |
| 227 pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem; | |
| 228 if (pixel_size_x == 0 || pixel_size_y == 0) { | |
| 229 bbox.left = cbox.xMin; | |
| 230 bbox.right = cbox.xMax; | |
| 231 bbox.top = cbox.yMax; | |
| 232 bbox.bottom = cbox.yMin; | |
| 233 } else { | |
| 234 bbox.left = cbox.xMin * 1000 / pixel_size_x; | |
| 235 bbox.right = cbox.xMax * 1000 / pixel_size_x; | |
| 236 bbox.top = cbox.yMax * 1000 / pixel_size_y; | |
| 237 bbox.bottom = cbox.yMin * 1000 / pixel_size_y; | |
| 238 } | |
| 239 if (bbox.top > FXFT_Get_Face_Ascender(m_Face)) { | |
| 240 bbox.top = FXFT_Get_Face_Ascender(m_Face); | |
| 241 } | |
| 242 if (bbox.bottom < FXFT_Get_Face_Descender(m_Face)) { | |
| 243 bbox.bottom = FXFT_Get_Face_Descender(m_Face); | |
| 244 } | |
| 245 FT_Done_Glyph(glyph); | |
| 246 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; | |
| 247 } | |
| 248 if (FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO
RE_GLOBAL_ADVANCE_WIDTH)) { | |
| 249 return FALSE; | |
| 250 } | |
| 251 int em = FXFT_Get_Face_UnitsPerEM(m_Face); | |
| 252 if (em == 0) { | |
| 253 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face); | |
| 254 bbox.bottom = FXFT_Get_Glyph_HoriBearingY(m_Face); | |
| 255 bbox.top = bbox.bottom - FXFT_Get_Glyph_Height(m_Face); | |
| 256 bbox.right = bbox.left + FXFT_Get_Glyph_Width(m_Face); | |
| 257 } else { | 236 } else { |
| 258 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face) * 1000 / em; | 237 bbox.left = cbox.xMin * 1000 / pixel_size_x; |
| 259 bbox.top = (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(
m_Face)) * 1000 / em; | 238 bbox.right = cbox.xMax * 1000 / pixel_size_x; |
| 260 bbox.right = (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width
(m_Face)) * 1000 / em; | 239 bbox.top = cbox.yMax * 1000 / pixel_size_y; |
| 261 bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em; | 240 bbox.bottom = cbox.yMin * 1000 / pixel_size_y; |
| 262 } | 241 } |
| 263 return TRUE; | 242 if (bbox.top > FXFT_Get_Face_Ascender(m_Face)) { |
| 264 } | 243 bbox.top = FXFT_Get_Face_Ascender(m_Face); |
| 265 FX_BOOL CFX_Font::IsItalic() | 244 } |
| 266 { | 245 if (bbox.bottom < FXFT_Get_Face_Descender(m_Face)) { |
| 267 if (m_Face == NULL) { | 246 bbox.bottom = FXFT_Get_Face_Descender(m_Face); |
| 268 return FALSE; | 247 } |
| 269 } | 248 FT_Done_Glyph(glyph); |
| 270 FX_BOOL ret = FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC; | 249 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; |
| 271 if (!ret) { | 250 } |
| 272 CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face)); | 251 if (FXFT_Load_Glyph( |
| 273 str.MakeLower(); | 252 m_Face, glyph_index, |
| 274 if (str.Find("italic") != -1) { | 253 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { |
| 275 ret = TRUE; | 254 return FALSE; |
| 276 } | 255 } |
| 277 } | 256 int em = FXFT_Get_Face_UnitsPerEM(m_Face); |
| 278 return ret; | 257 if (em == 0) { |
| 279 } | 258 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face); |
| 280 FX_BOOL CFX_Font::IsBold() | 259 bbox.bottom = FXFT_Get_Glyph_HoriBearingY(m_Face); |
| 281 { | 260 bbox.top = bbox.bottom - FXFT_Get_Glyph_Height(m_Face); |
| 282 if (m_Face == NULL) { | 261 bbox.right = bbox.left + FXFT_Get_Glyph_Width(m_Face); |
| 283 return FALSE; | 262 } else { |
| 284 } | 263 bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face) * 1000 / em; |
| 285 return FXFT_Is_Face_Bold(m_Face) == FXFT_STYLE_FLAG_BOLD; | 264 bbox.top = |
| 286 } | 265 (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)) * |
| 287 FX_BOOL CFX_Font::IsFixedWidth() | 266 1000 / em; |
| 288 { | 267 bbox.right = |
| 289 if (m_Face == NULL) { | 268 (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)) * |
| 290 return FALSE; | 269 1000 / em; |
| 291 } | 270 bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em; |
| 292 return FXFT_Is_Face_fixedwidth(m_Face); | 271 } |
| 293 } | 272 return TRUE; |
| 294 CFX_WideString CFX_Font::GetPsName() const | 273 } |
| 295 { | 274 FX_BOOL CFX_Font::IsItalic() { |
| 296 if (m_Face == NULL) { | 275 if (m_Face == NULL) { |
| 297 return CFX_WideString(); | 276 return FALSE; |
| 298 } | 277 } |
| 299 CFX_WideString psName = CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m
_Face)); | 278 FX_BOOL ret = FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC; |
| 300 if (psName.IsEmpty()) { | 279 if (!ret) { |
| 301 psName = CFX_WideString::FromLocal("Untitled"); | 280 CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face)); |
| 302 } | 281 str.MakeLower(); |
| 303 return psName; | 282 if (str.Find("italic") != -1) { |
| 304 } | 283 ret = TRUE; |
| 305 CFX_ByteString CFX_Font::GetFamilyName() const | 284 } |
| 306 { | 285 } |
| 307 if (m_Face == NULL && m_pSubstFont == NULL) { | 286 return ret; |
| 308 return CFX_ByteString(); | 287 } |
| 309 } | 288 FX_BOOL CFX_Font::IsBold() { |
| 310 if (m_Face) { | 289 if (m_Face == NULL) { |
| 311 return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); | 290 return FALSE; |
| 312 } | 291 } |
| 313 return m_pSubstFont->m_Family; | 292 return FXFT_Is_Face_Bold(m_Face) == FXFT_STYLE_FLAG_BOLD; |
| 314 } | 293 } |
| 315 CFX_ByteString CFX_Font::GetFaceName() const | 294 FX_BOOL CFX_Font::IsFixedWidth() { |
| 316 { | 295 if (m_Face == NULL) { |
| 317 if (m_Face == NULL && m_pSubstFont == NULL) { | 296 return FALSE; |
| 318 return CFX_ByteString(); | 297 } |
| 319 } | 298 return FXFT_Is_Face_fixedwidth(m_Face); |
| 320 if (m_Face) { | 299 } |
| 321 CFX_ByteString facename; | 300 CFX_WideString CFX_Font::GetPsName() const { |
| 322 CFX_ByteString style = CFX_ByteString(FXFT_Get_Face_Style_Name(m_Face)); | 301 if (m_Face == NULL) { |
| 323 facename = GetFamilyName(); | 302 return CFX_WideString(); |
| 324 if (facename.IsEmpty()) { | 303 } |
| 325 facename = "Untitled"; | 304 CFX_WideString psName = |
| 326 } | 305 CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face)); |
| 327 if (!style.IsEmpty() && style != "Regular") { | 306 if (psName.IsEmpty()) { |
| 328 facename += " " + style; | 307 psName = CFX_WideString::FromLocal("Untitled"); |
| 329 } | 308 } |
| 330 return facename; | 309 return psName; |
| 331 } | 310 } |
| 332 return m_pSubstFont->m_Family; | 311 CFX_ByteString CFX_Font::GetFamilyName() const { |
| 333 } | 312 if (m_Face == NULL && m_pSubstFont == NULL) { |
| 334 FX_BOOL CFX_Font::GetBBox(FX_RECT &bbox) | 313 return CFX_ByteString(); |
| 335 { | 314 } |
| 336 if (m_Face == NULL) { | 315 if (m_Face) { |
| 337 return FALSE; | 316 return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); |
| 338 } | 317 } |
| 339 int em = FXFT_Get_Face_UnitsPerEM(m_Face); | 318 return m_pSubstFont->m_Family; |
| 340 if (em == 0) { | 319 } |
| 341 bbox.left = FXFT_Get_Face_xMin(m_Face); | 320 CFX_ByteString CFX_Font::GetFaceName() const { |
| 342 bbox.bottom = FXFT_Get_Face_yMax(m_Face); | 321 if (m_Face == NULL && m_pSubstFont == NULL) { |
| 343 bbox.top = FXFT_Get_Face_yMin(m_Face); | 322 return CFX_ByteString(); |
| 344 bbox.right = FXFT_Get_Face_xMax(m_Face); | 323 } |
| 345 } else { | 324 if (m_Face) { |
| 346 bbox.left = FXFT_Get_Face_xMin(m_Face) * 1000 / em; | 325 CFX_ByteString facename; |
| 347 bbox.top = FXFT_Get_Face_yMin(m_Face) * 1000 / em; | 326 CFX_ByteString style = CFX_ByteString(FXFT_Get_Face_Style_Name(m_Face)); |
| 348 bbox.right = FXFT_Get_Face_xMax(m_Face) * 1000 / em; | 327 facename = GetFamilyName(); |
| 349 bbox.bottom = FXFT_Get_Face_yMax(m_Face) * 1000 / em; | 328 if (facename.IsEmpty()) { |
| 350 } | 329 facename = "Untitled"; |
| 351 return TRUE; | 330 } |
| 352 } | 331 if (!style.IsEmpty() && style != "Regular") { |
| 353 int CFX_Font::GetHeight() | 332 facename += " " + style; |
| 354 { | 333 } |
| 355 if (m_Face == NULL) { | 334 return facename; |
| 356 return 0; | 335 } |
| 357 } | 336 return m_pSubstFont->m_Family; |
| 358 int height = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Heigh
t(m_Face)); | 337 } |
| 359 return height; | 338 FX_BOOL CFX_Font::GetBBox(FX_RECT& bbox) { |
| 360 } | 339 if (m_Face == NULL) { |
| 361 int CFX_Font::GetMaxAdvanceWidth() | 340 return FALSE; |
| 362 { | 341 } |
| 363 if (m_Face == NULL) { | 342 int em = FXFT_Get_Face_UnitsPerEM(m_Face); |
| 364 return 0; | 343 if (em == 0) { |
| 365 } | 344 bbox.left = FXFT_Get_Face_xMin(m_Face); |
| 366 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_MaxAdv
anceWidth(m_Face)); | 345 bbox.bottom = FXFT_Get_Face_yMax(m_Face); |
| 367 return width; | 346 bbox.top = FXFT_Get_Face_yMin(m_Face); |
| 368 } | 347 bbox.right = FXFT_Get_Face_xMax(m_Face); |
| 369 int CFX_Font::GetULPos() | 348 } else { |
| 370 { | 349 bbox.left = FXFT_Get_Face_xMin(m_Face) * 1000 / em; |
| 371 if (m_Face == NULL) { | 350 bbox.top = FXFT_Get_Face_yMin(m_Face) * 1000 / em; |
| 372 return 0; | 351 bbox.right = FXFT_Get_Face_xMax(m_Face) * 1000 / em; |
| 373 } | 352 bbox.bottom = FXFT_Get_Face_yMax(m_Face) * 1000 / em; |
| 374 int pos = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_UnderLin
ePosition(m_Face)); | 353 } |
| 375 return pos; | 354 return TRUE; |
| 376 } | 355 } |
| 377 int CFX_Font::GetULthickness() | 356 int CFX_Font::GetHeight() { |
| 378 { | 357 if (m_Face == NULL) { |
| 379 if (m_Face == NULL) { | 358 return 0; |
| 380 return 0; | 359 } |
| 381 } | 360 int height = |
| 382 int thickness = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Un
derLineThickness(m_Face)); | 361 EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Height(m_Face)); |
| 383 return thickness; | 362 return height; |
| 384 } | 363 } |
| 385 CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) | 364 int CFX_Font::GetMaxAdvanceWidth() { |
| 386 { | 365 if (m_Face == NULL) { |
| 387 m_pFont = pFont; | 366 return 0; |
| 388 } | 367 } |
| 389 FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCode(FX_DWORD charcode) | 368 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 390 { | 369 FXFT_Get_Face_MaxAdvanceWidth(m_Face)); |
| 391 FXFT_Face face = m_pFont->GetFace(); | 370 return width; |
| 392 if (!face) { | 371 } |
| 393 return charcode; | 372 int CFX_Font::GetULPos() { |
| 394 } | 373 if (m_Face == NULL) { |
| 395 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) { | 374 return 0; |
| 396 return FXFT_Get_Char_Index(face, charcode); | 375 } |
| 397 } | 376 int pos = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 398 if (m_pFont->m_pSubstFont && m_pFont->m_pSubstFont->m_Charset == 2) { | 377 FXFT_Get_Face_UnderLinePosition(m_Face)); |
| 399 FX_DWORD index = 0; | 378 return pos; |
| 400 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) { | 379 } |
| 401 index = FXFT_Get_Char_Index(face, charcode); | 380 int CFX_Font::GetULthickness() { |
| 402 } | 381 if (m_Face == NULL) { |
| 403 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) { | 382 return 0; |
| 404 return FXFT_Get_Char_Index(face, charcode); | 383 } |
| 405 } | 384 int thickness = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 406 } | 385 FXFT_Get_Face_UnderLineThickness(m_Face)); |
| 386 return thickness; |
| 387 } |
| 388 CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) { |
| 389 m_pFont = pFont; |
| 390 } |
| 391 FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCode(FX_DWORD charcode) { |
| 392 FXFT_Face face = m_pFont->GetFace(); |
| 393 if (!face) { |
| 407 return charcode; | 394 return charcode; |
| 408 } | 395 } |
| 409 FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCodeEx(FX_DWORD charcode, int encodin
g) | 396 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) { |
| 410 { | |
| 411 FXFT_Face face = m_pFont->GetFace(); | |
| 412 if (!face) { | |
| 413 return charcode; | |
| 414 } | |
| 415 if (encoding == ENCODING_UNICODE) { | |
| 416 return GlyphFromCharCode(charcode); | |
| 417 } | |
| 418 int nmaps = FXFT_Get_Face_CharmapCount(m_pFont->m_Face); | |
| 419 int i = 0; | |
| 420 while (i < nmaps) { | |
| 421 int encoding = FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i+
+]); | |
| 422 if (encoding != FXFT_ENCODING_UNICODE) { | |
| 423 FXFT_Select_Charmap(face, encoding); | |
| 424 break; | |
| 425 } | |
| 426 } | |
| 427 return FXFT_Get_Char_Index(face, charcode); | 397 return FXFT_Get_Char_Index(face, charcode); |
| 428 } | 398 } |
| 429 IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont) | 399 if (m_pFont->m_pSubstFont && m_pFont->m_pSubstFont->m_Charset == 2) { |
| 430 { | 400 FX_DWORD index = 0; |
| 431 return new CFX_UnicodeEncoding(pFont); | 401 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) { |
| 432 } | 402 index = FXFT_Get_Char_Index(face, charcode); |
| 403 } |
| 404 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) { |
| 405 return FXFT_Get_Char_Index(face, charcode); |
| 406 } |
| 407 } |
| 408 return charcode; |
| 409 } |
| 410 FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCodeEx(FX_DWORD charcode, |
| 411 int encoding) { |
| 412 FXFT_Face face = m_pFont->GetFace(); |
| 413 if (!face) { |
| 414 return charcode; |
| 415 } |
| 416 if (encoding == ENCODING_UNICODE) { |
| 417 return GlyphFromCharCode(charcode); |
| 418 } |
| 419 int nmaps = FXFT_Get_Face_CharmapCount(m_pFont->m_Face); |
| 420 int i = 0; |
| 421 while (i < nmaps) { |
| 422 int encoding = FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i++]); |
| 423 if (encoding != FXFT_ENCODING_UNICODE) { |
| 424 FXFT_Select_Charmap(face, encoding); |
| 425 break; |
| 426 } |
| 427 } |
| 428 return FXFT_Get_Char_Index(face, charcode); |
| 429 } |
| 430 IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont) { |
| 431 return new CFX_UnicodeEncoding(pFont); |
| 432 } |
| OLD | NEW |