| 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 "core/include/fxge/fx_freetype.h" | 7 #include "core/include/fxge/fx_freetype.h" |
| 8 #include "core/include/fxge/fx_ge.h" | 8 #include "core/include/fxge/fx_ge.h" |
| 9 #include "text_int.h" | 9 #include "text_int.h" |
| 10 | 10 |
| 11 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) | 11 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) |
| 12 | 12 |
| 13 #ifdef PDF_ENABLE_XFA | 13 #ifdef PDF_ENABLE_XFA |
| 14 extern void _FPDFAPI_GetInternalFontData(int id1, | 14 extern void _FPDFAPI_GetInternalFontData(int id1, |
| 15 const uint8_t*& data, | 15 const uint8_t*& data, |
| 16 FX_DWORD& size); | 16 FX_DWORD& size); |
| 17 #endif // PDF_ENABLE_XFA |
| 17 | 18 |
| 18 #endif | |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 #ifdef PDF_ENABLE_XFA | 21 #ifdef PDF_ENABLE_XFA |
| 22 const FX_DWORD g_EncodingID[] = { | 22 const FX_DWORD g_EncodingID[] = { |
| 23 FXFM_ENCODING_MS_SYMBOL, | 23 FXFM_ENCODING_MS_SYMBOL, |
| 24 FXFM_ENCODING_UNICODE, | 24 FXFM_ENCODING_UNICODE, |
| 25 FXFM_ENCODING_MS_SJIS, | 25 FXFM_ENCODING_MS_SJIS, |
| 26 FXFM_ENCODING_MS_GB2312, | 26 FXFM_ENCODING_MS_GB2312, |
| 27 FXFM_ENCODING_MS_BIG5, | 27 FXFM_ENCODING_MS_BIG5, |
| 28 FXFM_ENCODING_MS_WANSUNG, | 28 FXFM_ENCODING_MS_WANSUNG, |
| 29 FXFM_ENCODING_MS_JOHAB, | 29 FXFM_ENCODING_MS_JOHAB, |
| 30 FXFM_ENCODING_ADOBE_STANDARD, | 30 FXFM_ENCODING_ADOBE_STANDARD, |
| 31 FXFM_ENCODING_ADOBE_EXPERT, | 31 FXFM_ENCODING_ADOBE_EXPERT, |
| 32 FXFM_ENCODING_ADOBE_CUSTOM, | 32 FXFM_ENCODING_ADOBE_CUSTOM, |
| 33 FXFM_ENCODING_ADOBE_LATIN_1, | 33 FXFM_ENCODING_ADOBE_LATIN_1, |
| 34 FXFM_ENCODING_OLD_LATIN_2, | 34 FXFM_ENCODING_OLD_LATIN_2, |
| 35 FXFM_ENCODING_APPLE_ROMAN, | 35 FXFM_ENCODING_APPLE_ROMAN, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont, | 38 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont, |
| 39 FX_DWORD nEncodingID) { | 39 FX_DWORD nEncodingID) { |
| 40 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID)) | 40 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID)) |
| 41 return nullptr; | 41 return nullptr; |
| 42 return new CFX_UnicodeEncodingEx(pFont, nEncodingID); | 42 return new CFX_UnicodeEncodingEx(pFont, nEncodingID); |
| 43 } | 43 } |
| 44 #endif // PDF_ENABLE_XFA |
| 44 | 45 |
| 45 #endif | |
| 46 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { | 46 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { |
| 47 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); | 47 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 CFX_Font::CFX_Font() { | 52 CFX_Font::CFX_Font() { |
| 53 m_pSubstFont = NULL; | 53 m_pSubstFont = NULL; |
| 54 m_Face = NULL; | 54 m_Face = NULL; |
| 55 m_bEmbedded = FALSE; | 55 m_bEmbedded = FALSE; |
| 56 m_bVertical = FALSE; | 56 m_bVertical = FALSE; |
| 57 m_pFontData = NULL; | 57 m_pFontData = NULL; |
| 58 m_pFontDataAllocation = NULL; | 58 m_pFontDataAllocation = NULL; |
| 59 m_dwSize = 0; | 59 m_dwSize = 0; |
| 60 #ifdef PDF_ENABLE_XFA | |
| 61 m_pOwnedStream = NULL; | |
| 62 #endif | |
| 63 m_pGsubData = NULL; | 60 m_pGsubData = NULL; |
| 64 m_pPlatformFont = NULL; | 61 m_pPlatformFont = NULL; |
| 65 m_pPlatformFontCollection = NULL; | 62 m_pPlatformFontCollection = NULL; |
| 66 m_pDwFont = NULL; | 63 m_pDwFont = NULL; |
| 67 m_hHandle = NULL; | 64 m_hHandle = NULL; |
| 68 m_bDwLoaded = FALSE; | 65 m_bDwLoaded = FALSE; |
| 69 #ifdef PDF_ENABLE_XFA | 66 #ifdef PDF_ENABLE_XFA |
| 70 m_bLogic = FALSE; | 67 m_bLogic = FALSE; |
| 68 m_pOwnedStream = NULL; |
| 69 #endif // PDF_ENABLE_XFA |
| 71 } | 70 } |
| 71 |
| 72 #ifdef PDF_ENABLE_XFA |
| 72 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { | 73 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { |
| 73 if (pFont == NULL) { | 74 if (pFont == NULL) { |
| 74 return FALSE; | 75 return FALSE; |
| 75 } | 76 } |
| 76 m_bLogic = TRUE; | 77 m_bLogic = TRUE; |
| 77 if (pFont->m_pSubstFont) { | 78 if (pFont->m_pSubstFont) { |
| 78 m_pSubstFont = new CFX_SubstFont; | 79 m_pSubstFont = new CFX_SubstFont; |
| 79 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; | 80 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; |
| 80 m_pSubstFont->m_ExtHandle = pFont->m_pSubstFont->m_ExtHandle; | 81 m_pSubstFont->m_ExtHandle = pFont->m_pSubstFont->m_ExtHandle; |
| 81 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; | 82 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 m_dwSize = pFont->m_dwSize; | 94 m_dwSize = pFont->m_dwSize; |
| 94 m_pFontData = pFont->m_pFontData; | 95 m_pFontData = pFont->m_pFontData; |
| 95 m_pGsubData = pFont->m_pGsubData; | 96 m_pGsubData = pFont->m_pGsubData; |
| 96 m_pPlatformFont = pFont->m_pPlatformFont; | 97 m_pPlatformFont = pFont->m_pPlatformFont; |
| 97 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection; | 98 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection; |
| 98 m_pDwFont = pFont->m_pDwFont; | 99 m_pDwFont = pFont->m_pDwFont; |
| 99 m_hHandle = pFont->m_hHandle; | 100 m_hHandle = pFont->m_hHandle; |
| 100 m_bDwLoaded = pFont->m_bDwLoaded; | 101 m_bDwLoaded = pFont->m_bDwLoaded; |
| 101 m_pOwnedStream = pFont->m_pOwnedStream; | 102 m_pOwnedStream = pFont->m_pOwnedStream; |
| 102 return TRUE; | 103 return TRUE; |
| 103 #endif | 104 #endif // PDF_ENABLE_XFA |
| 104 } | 105 } |
| 105 CFX_Font::~CFX_Font() { | 106 CFX_Font::~CFX_Font() { |
| 106 delete m_pSubstFont; | 107 delete m_pSubstFont; |
| 107 m_pSubstFont = NULL; | 108 m_pSubstFont = NULL; |
| 108 #ifndef PDF_ENABLE_XFA | 109 #ifndef PDF_ENABLE_XFA |
| 109 FX_Free(m_pFontDataAllocation); | 110 FX_Free(m_pFontDataAllocation); |
| 110 m_pFontDataAllocation = NULL; | 111 m_pFontDataAllocation = NULL; |
| 111 #else | 112 #else |
| 112 if (m_bLogic) { | 113 if (m_bLogic) { |
| 113 m_OtfFontData.DetachBuffer(); | 114 m_OtfFontData.DetachBuffer(); |
| 114 return; | 115 return; |
| 115 } | 116 } |
| 116 #endif | 117 #endif // PDF_ENABLE_XFA |
| 117 if (m_Face) { | 118 if (m_Face) { |
| 118 #ifndef PDF_ENABLE_XFA | 119 #ifndef PDF_ENABLE_XFA |
| 119 if (FXFT_Get_Face_External_Stream(m_Face)) { | 120 if (FXFT_Get_Face_External_Stream(m_Face)) { |
| 120 FXFT_Clear_Face_External_Stream(m_Face); | 121 FXFT_Clear_Face_External_Stream(m_Face); |
| 121 } | 122 } |
| 122 #endif | 123 #endif // PDF_ENABLE_XFA |
| 123 if (m_bEmbedded) { | 124 if (m_bEmbedded) { |
| 124 DeleteFace(); | 125 DeleteFace(); |
| 125 } else { | 126 } else { |
| 126 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | 127 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 #ifdef PDF_ENABLE_XFA | 130 #ifdef PDF_ENABLE_XFA |
| 130 FX_Free(m_pOwnedStream); | 131 FX_Free(m_pOwnedStream); |
| 131 m_pOwnedStream = NULL; | 132 m_pOwnedStream = NULL; |
| 132 #endif | 133 #endif // PDF_ENABLE_XFA |
| 133 FX_Free(m_pGsubData); | 134 FX_Free(m_pGsubData); |
| 134 m_pGsubData = NULL; | 135 m_pGsubData = NULL; |
| 135 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 136 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 136 ReleasePlatformResource(); | 137 ReleasePlatformResource(); |
| 137 #endif | 138 #endif |
| 138 } | 139 } |
| 139 void CFX_Font::DeleteFace() { | 140 void CFX_Font::DeleteFace() { |
| 140 FXFT_Done_Face(m_Face); | 141 FXFT_Done_Face(m_Face); |
| 141 m_Face = NULL; | 142 m_Face = NULL; |
| 142 } | 143 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 FXFT_Stream stream = nullptr; | 220 FXFT_Stream stream = nullptr; |
| 220 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex)) | 221 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex)) |
| 221 return FALSE; | 222 return FALSE; |
| 222 | 223 |
| 223 if (pFaceCount) | 224 if (pFaceCount) |
| 224 *pFaceCount = (int)m_Face->num_faces; | 225 *pFaceCount = (int)m_Face->num_faces; |
| 225 m_pOwnedStream = stream; | 226 m_pOwnedStream = stream; |
| 226 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 227 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
| 227 return TRUE; | 228 return TRUE; |
| 228 } | 229 } |
| 229 #endif | 230 #endif // PDF_ENABLE_XFA |
| 230 | 231 |
| 231 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) { | 232 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) { |
| 232 if (!m_Face) { | 233 if (!m_Face) { |
| 233 return 0; | 234 return 0; |
| 234 } | 235 } |
| 235 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { | 236 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { |
| 236 AdjustMMParams(glyph_index, 0, 0); | 237 AdjustMMParams(glyph_index, 0, 0); |
| 237 } | 238 } |
| 238 int err = FXFT_Load_Glyph( | 239 int err = FXFT_Load_Glyph( |
| 239 m_Face, glyph_index, | 240 m_Face, glyph_index, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 476 |
| 476 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) { | 477 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) { |
| 477 FX_DWORD index = 0; | 478 FX_DWORD index = 0; |
| 478 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) | 479 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) |
| 479 index = FXFT_Get_Char_Index(face, charcode); | 480 index = FXFT_Get_Char_Index(face, charcode); |
| 480 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) | 481 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) |
| 481 return FXFT_Get_Char_Index(face, charcode); | 482 return FXFT_Get_Char_Index(face, charcode); |
| 482 } | 483 } |
| 483 return charcode; | 484 return charcode; |
| 484 } | 485 } |
| 486 |
| 485 #ifdef PDF_ENABLE_XFA | 487 #ifdef PDF_ENABLE_XFA |
| 486 | |
| 487 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont, | 488 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont, |
| 488 FX_DWORD EncodingID) | 489 FX_DWORD EncodingID) |
| 489 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) { | 490 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) { |
| 490 } | 491 } |
| 491 | 492 |
| 492 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() { | 493 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() { |
| 493 } | 494 } |
| 494 | 495 |
| 495 FX_DWORD CFX_UnicodeEncodingEx::GlyphFromCharCode(FX_DWORD charcode) { | 496 FX_DWORD CFX_UnicodeEncodingEx::GlyphFromCharCode(FX_DWORD charcode) { |
| 496 FXFT_Face face = m_pFont->GetFace(); | 497 FXFT_Face face = m_pFont->GetFace(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 549 |
| 549 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { | 550 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { |
| 550 CFX_UnicodeEncodingEx* pFontEncoding = | 551 CFX_UnicodeEncodingEx* pFontEncoding = |
| 551 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); | 552 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); |
| 552 if (pFontEncoding) { | 553 if (pFontEncoding) { |
| 553 return pFontEncoding; | 554 return pFontEncoding; |
| 554 } | 555 } |
| 555 } | 556 } |
| 556 return NULL; | 557 return NULL; |
| 557 } | 558 } |
| 558 #endif | 559 #endif // PDF_ENABLE_XFA |
| OLD | NEW |