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) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 if (pFont->m_OtfFontData.GetSize()) { | 48 if (pFont->m_OtfFontData.GetSize()) { |
49 m_OtfFontData.AttachData(pFont->m_OtfFontData.GetBuffer(), pFont->m_OtfF
ontData.GetSize()); | 49 m_OtfFontData.AttachData(pFont->m_OtfFontData.GetBuffer(), pFont->m_OtfF
ontData.GetSize()); |
50 } | 50 } |
51 m_Face = pFont->m_Face; | 51 m_Face = pFont->m_Face; |
52 m_bEmbedded = pFont->m_bEmbedded; | 52 m_bEmbedded = pFont->m_bEmbedded; |
53 m_bVertical = pFont->m_bVertical; | 53 m_bVertical = pFont->m_bVertical; |
54 m_dwSize = pFont->m_dwSize; | 54 m_dwSize = pFont->m_dwSize; |
55 m_pFontData = pFont->m_pFontData; | 55 m_pFontData = pFont->m_pFontData; |
56 m_pGsubData = pFont->m_pGsubData; | 56 m_pGsubData = pFont->m_pGsubData; |
57 #ifdef FOXIT_CHROME_BUILD | |
58 if (pFont->m_pFontDataAllocation) { | |
59 m_pFontDataAllocation = FX_Alloc(FX_BYTE, m_dwSize); | |
60 if (!m_pFontDataAllocation) { | |
61 return FALSE; | |
62 } | |
63 m_pFontData = m_pFontDataAllocation; | |
64 FXSYS_memcpy32(m_pFontDataAllocation, pFont->m_pFontDataAllocation, m_dw
Size); | |
65 } | |
66 #endif | |
67 m_pPlatformFont = pFont->m_pPlatformFont; | 57 m_pPlatformFont = pFont->m_pPlatformFont; |
68 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection; | 58 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection; |
69 m_pDwFont = pFont->m_pDwFont; | 59 m_pDwFont = pFont->m_pDwFont; |
70 m_hHandle = pFont->m_hHandle; | 60 m_hHandle = pFont->m_hHandle; |
71 m_bDwLoaded = pFont->m_bDwLoaded; | 61 m_bDwLoaded = pFont->m_bDwLoaded; |
72 m_pOwnedStream = pFont->m_pOwnedStream; | 62 m_pOwnedStream = pFont->m_pOwnedStream; |
73 return TRUE; | 63 return TRUE; |
74 } | 64 } |
75 CFX_Font::~CFX_Font() | 65 CFX_Font::~CFX_Font() |
76 { | 66 { |
77 if (m_pSubstFont) { | 67 if (m_pSubstFont) { |
78 delete m_pSubstFont; | 68 delete m_pSubstFont; |
79 m_pSubstFont = NULL; | 69 m_pSubstFont = NULL; |
80 } | 70 } |
81 #ifdef FOXIT_CHROME_BUILD | |
82 if (m_pFontDataAllocation) { | |
83 FX_Free(m_pFontDataAllocation); | |
84 m_pFontDataAllocation = NULL; | |
85 } | |
86 #endif | |
87 if (m_bLogic) { | 71 if (m_bLogic) { |
88 m_OtfFontData.DetachBuffer(); | 72 m_OtfFontData.DetachBuffer(); |
89 return; | 73 return; |
90 } | 74 } |
91 if (m_Face) { | 75 if (m_Face) { |
92 #ifdef FOXIT_CHROME_BUILD | |
93 if (FXFT_Get_Face_External_Stream(m_Face)) { | |
94 FXFT_Clear_Face_External_Stream(m_Face); | |
95 } | |
96 #endif | |
97 if(m_bEmbedded) { | 76 if(m_bEmbedded) { |
98 DeleteFace(); | 77 DeleteFace(); |
99 } else { | 78 } else { |
100 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | 79 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); |
101 } | 80 } |
102 } | 81 } |
103 if (m_pOwnedStream) { | 82 if (m_pOwnedStream) { |
104 FX_Free(m_pOwnedStream); | 83 FX_Free(m_pOwnedStream); |
105 m_pOwnedStream = NULL; | 84 m_pOwnedStream = NULL; |
106 } | 85 } |
107 if (m_pGsubData) { | 86 if (m_pGsubData) { |
108 FX_Free(m_pGsubData); | 87 FX_Free(m_pGsubData); |
109 m_pGsubData = NULL; | 88 m_pGsubData = NULL; |
110 } | 89 } |
111 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && (!defined(_FPDFAPI_MINI_))) | 90 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
112 ReleasePlatformResource(); | 91 ReleasePlatformResource(); |
113 #endif | 92 #endif |
114 } | 93 } |
115 void CFX_Font::DeleteFace() | 94 void CFX_Font::DeleteFace() |
116 { | 95 { |
117 FXFT_Done_Face(m_Face); | 96 FXFT_Done_Face(m_Face); |
118 m_Face = NULL; | 97 m_Face = NULL; |
119 } | 98 } |
120 FX_BOOL CFX_Font::LoadSubst(const CFX_ByteString& face_name, FX_BOOL bTrueType,
FX_DWORD flags, | 99 FX_BOOL CFX_Font::LoadSubst(const CFX_ByteString& face_name, FX_BOOL bTrueType,
FX_DWORD flags, |
121 int weight, int italic_angle, int CharsetCP, FX_BOOL
bVertical) | 100 int weight, int italic_angle, int CharsetCP, FX_BOOL
bVertical) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 m_bEmbedded = FALSE; | 166 m_bEmbedded = FALSE; |
188 FXFT_Library library; | 167 FXFT_Library library; |
189 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) | 168 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) |
190 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); | 169 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); |
191 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; | 170 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; |
192 FXFT_Stream stream = NULL; | 171 FXFT_Stream stream = NULL; |
193 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex)) | 172 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex)) |
194 return FALSE; | 173 return FALSE; |
195 if (pFaceCount) | 174 if (pFaceCount) |
196 *pFaceCount = (int)m_Face->num_faces; | 175 *pFaceCount = (int)m_Face->num_faces; |
197 #ifndef FOXIT_CHROME_BUILD | |
198 m_pOwnedStream = stream; | 176 m_pOwnedStream = stream; |
199 #endif | |
200 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 177 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
201 return TRUE; | 178 return TRUE; |
202 } | 179 } |
203 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) | 180 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) |
204 { | 181 { |
205 if (!m_Face) { | 182 if (!m_Face) { |
206 return 0; | 183 return 0; |
207 } | 184 } |
208 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { | 185 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { |
209 AdjustMMParams(glyph_index, 0, 0); | 186 AdjustMMParams(glyph_index, 0, 0); |
(...skipping 18 matching lines...) Expand all Loading... |
228 return NULL; | 205 return NULL; |
229 } | 206 } |
230 error = FXFT_Set_Pixel_Sizes(face, 64, 64); | 207 error = FXFT_Set_Pixel_Sizes(face, 64, 64); |
231 if (error) { | 208 if (error) { |
232 return NULL; | 209 return NULL; |
233 } | 210 } |
234 return face; | 211 return face; |
235 } | 212 } |
236 FX_BOOL CFX_Font::LoadEmbedded(FX_LPCBYTE data, FX_DWORD size) | 213 FX_BOOL CFX_Font::LoadEmbedded(FX_LPCBYTE data, FX_DWORD size) |
237 { | 214 { |
238 #ifdef FOXIT_CHROME_BUILD | |
239 m_pFontDataAllocation = FX_Alloc(FX_BYTE, size); | 215 m_pFontDataAllocation = FX_Alloc(FX_BYTE, size); |
240 if (!m_pFontDataAllocation) { | 216 if (!m_pFontDataAllocation) { |
241 return FALSE; | 217 return FALSE; |
242 } | 218 } |
243 FXSYS_memcpy32(m_pFontDataAllocation, data, size); | 219 FXSYS_memcpy32(m_pFontDataAllocation, data, size); |
244 m_Face = FT_LoadFont((FX_LPBYTE)m_pFontDataAllocation, size); | 220 m_Face = FT_LoadFont((FX_LPBYTE)m_pFontDataAllocation, size); |
245 m_pFontData = (FX_LPBYTE)m_pFontDataAllocation; | 221 m_pFontData = (FX_LPBYTE)m_pFontDataAllocation; |
246 #else | |
247 m_Face = FT_LoadFont((FX_LPBYTE)data, size); | |
248 m_pFontData = (FX_LPBYTE)data; | |
249 #endif | |
250 m_bEmbedded = TRUE; | 222 m_bEmbedded = TRUE; |
251 m_dwSize = size; | 223 m_dwSize = size; |
252 return m_Face != NULL; | 224 return m_Face != NULL; |
253 } | 225 } |
254 FX_BOOL CFX_Font::IsTTFont() | 226 FX_BOOL CFX_Font::IsTTFont() |
255 { | 227 { |
256 if (m_Face == NULL) { | 228 if (m_Face == NULL) { |
257 return FALSE; | 229 return FALSE; |
258 } | 230 } |
259 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; | 231 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 637 } |
666 static int s_count = sizeof(gs_EncodingID) / sizeof(FX_DWORD); | 638 static int s_count = sizeof(gs_EncodingID) / sizeof(FX_DWORD); |
667 for (int i = 0; i < s_count; i++) { | 639 for (int i = 0; i < s_count; i++) { |
668 IFX_FontEncodingEx* pFontEncoding = _FXFM_CreateFontEncoding(pFont, gs_E
ncodingID[i]); | 640 IFX_FontEncodingEx* pFontEncoding = _FXFM_CreateFontEncoding(pFont, gs_E
ncodingID[i]); |
669 if (pFontEncoding) { | 641 if (pFontEncoding) { |
670 return pFontEncoding; | 642 return pFontEncoding; |
671 } | 643 } |
672 } | 644 } |
673 return NULL; | 645 return NULL; |
674 } | 646 } |
OLD | NEW |