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/fpdfapi/fpdf_font/include/cpdf_font.h" | 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
8 #include "core/fxge/ge/fx_text_int.h" | 8 #include "core/fxge/ge/fx_text_int.h" |
9 #include "core/fxge/include/fx_freetype.h" | 9 #include "core/fxge/include/fx_freetype.h" |
10 #include "core/fxge/include/fx_ge.h" | 10 #include "core/fxge/include/fx_ge.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 #endif // PDF_ENABLE_XFA | 33 #endif // PDF_ENABLE_XFA |
34 | 34 |
35 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { | 35 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { |
36 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); | 36 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 CFX_Font::CFX_Font() { | 41 CFX_Font::CFX_Font() { |
42 m_pSubstFont = NULL; | 42 m_pSubstFont = nullptr; |
43 m_Face = NULL; | 43 m_Face = nullptr; |
44 m_bEmbedded = FALSE; | 44 m_bEmbedded = FALSE; |
45 m_bVertical = FALSE; | 45 m_bVertical = FALSE; |
46 m_pFontData = NULL; | 46 m_pFontData = nullptr; |
47 m_pFontDataAllocation = NULL; | 47 m_pFontDataAllocation = nullptr; |
48 m_dwSize = 0; | 48 m_dwSize = 0; |
49 m_pGsubData = NULL; | 49 m_pGsubData = nullptr; |
50 m_pPlatformFont = NULL; | 50 m_pPlatformFont = nullptr; |
51 m_pPlatformFontCollection = NULL; | 51 m_pPlatformFontCollection = nullptr; |
52 m_pDwFont = NULL; | 52 m_pDwFont = nullptr; |
53 m_hHandle = NULL; | 53 m_hHandle = nullptr; |
54 m_bDwLoaded = FALSE; | 54 m_bDwLoaded = FALSE; |
55 #ifdef PDF_ENABLE_XFA | 55 #ifdef PDF_ENABLE_XFA |
56 m_bLogic = FALSE; | 56 m_bLogic = FALSE; |
57 m_pOwnedStream = NULL; | 57 m_pOwnedStream = nullptr; |
58 #endif // PDF_ENABLE_XFA | 58 #endif // PDF_ENABLE_XFA |
59 } | 59 } |
60 | 60 |
61 #ifdef PDF_ENABLE_XFA | 61 #ifdef PDF_ENABLE_XFA |
62 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { | 62 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { |
63 if (pFont == NULL) { | 63 if (!pFont) |
64 return FALSE; | 64 return FALSE; |
65 } | 65 |
66 m_bLogic = TRUE; | 66 m_bLogic = TRUE; |
67 if (pFont->m_pSubstFont) { | 67 if (pFont->m_pSubstFont) { |
68 m_pSubstFont = new CFX_SubstFont; | 68 m_pSubstFont = new CFX_SubstFont; |
69 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; | 69 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; |
70 m_pSubstFont->m_ExtHandle = pFont->m_pSubstFont->m_ExtHandle; | 70 m_pSubstFont->m_ExtHandle = pFont->m_pSubstFont->m_ExtHandle; |
71 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; | 71 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; |
72 m_pSubstFont->m_Weight = pFont->m_pSubstFont->m_Weight; | 72 m_pSubstFont->m_Weight = pFont->m_pSubstFont->m_Weight; |
73 m_pSubstFont->m_Family = pFont->m_pSubstFont->m_Family; | 73 m_pSubstFont->m_Family = pFont->m_pSubstFont->m_Family; |
74 m_pSubstFont->m_ItalicAngle = pFont->m_pSubstFont->m_ItalicAngle; | 74 m_pSubstFont->m_ItalicAngle = pFont->m_pSubstFont->m_ItalicAngle; |
75 } | 75 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 #ifdef PDF_ENABLE_XFA | 117 #ifdef PDF_ENABLE_XFA |
118 FX_Free(m_pOwnedStream); | 118 FX_Free(m_pOwnedStream); |
119 #endif // PDF_ENABLE_XFA | 119 #endif // PDF_ENABLE_XFA |
120 FX_Free(m_pGsubData); | 120 FX_Free(m_pGsubData); |
121 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 121 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
122 ReleasePlatformResource(); | 122 ReleasePlatformResource(); |
123 #endif | 123 #endif |
124 } | 124 } |
125 void CFX_Font::DeleteFace() { | 125 void CFX_Font::DeleteFace() { |
126 FXFT_Done_Face(m_Face); | 126 FXFT_Done_Face(m_Face); |
127 m_Face = NULL; | 127 m_Face = nullptr; |
128 } | 128 } |
129 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, | 129 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, |
130 FX_BOOL bTrueType, | 130 FX_BOOL bTrueType, |
131 uint32_t flags, | 131 uint32_t flags, |
132 int weight, | 132 int weight, |
133 int italic_angle, | 133 int italic_angle, |
134 int CharsetCP, | 134 int CharsetCP, |
135 FX_BOOL bVertical) { | 135 FX_BOOL bVertical) { |
136 m_bEmbedded = FALSE; | 136 m_bEmbedded = FALSE; |
137 m_bVertical = bVertical; | 137 m_bVertical = bVertical; |
138 m_pSubstFont = new CFX_SubstFont; | 138 m_pSubstFont = new CFX_SubstFont; |
139 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( | 139 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( |
140 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, | 140 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, |
141 m_pSubstFont); | 141 m_pSubstFont); |
142 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 142 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
143 if (m_pSubstFont->m_ExtHandle) { | 143 if (m_pSubstFont->m_ExtHandle) { |
144 m_pPlatformFont = m_pSubstFont->m_ExtHandle; | 144 m_pPlatformFont = m_pSubstFont->m_ExtHandle; |
145 m_pSubstFont->m_ExtHandle = NULL; | 145 m_pSubstFont->m_ExtHandle = nullptr; |
146 } | 146 } |
147 #endif | 147 #endif |
148 if (m_Face) { | 148 if (m_Face) { |
149 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); | 149 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); |
150 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); | 150 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); |
151 } | 151 } |
152 } | 152 } |
153 #ifdef PDF_ENABLE_XFA | 153 #ifdef PDF_ENABLE_XFA |
154 extern "C" { | 154 extern "C" { |
155 unsigned long _FTStreamRead(FXFT_Stream stream, | 155 unsigned long _FTStreamRead(FXFT_Stream stream, |
(...skipping 11 matching lines...) Expand all Loading... |
167 return 0; | 167 return 0; |
168 } | 168 } |
169 void _FTStreamClose(FXFT_Stream stream) {} | 169 void _FTStreamClose(FXFT_Stream stream) {} |
170 }; | 170 }; |
171 FX_BOOL _LoadFile(FXFT_Library library, | 171 FX_BOOL _LoadFile(FXFT_Library library, |
172 FXFT_Face* Face, | 172 FXFT_Face* Face, |
173 IFX_FileRead* pFile, | 173 IFX_FileRead* pFile, |
174 FXFT_Stream* stream, | 174 FXFT_Stream* stream, |
175 int32_t faceIndex = 0) { | 175 int32_t faceIndex = 0) { |
176 FXFT_Stream stream1 = (FXFT_Stream)FX_Alloc(uint8_t, sizeof(FXFT_StreamRec)); | 176 FXFT_Stream stream1 = (FXFT_Stream)FX_Alloc(uint8_t, sizeof(FXFT_StreamRec)); |
177 stream1->base = NULL; | 177 stream1->base = nullptr; |
178 stream1->size = (unsigned long)pFile->GetSize(); | 178 stream1->size = (unsigned long)pFile->GetSize(); |
179 stream1->pos = 0; | 179 stream1->pos = 0; |
180 stream1->descriptor.pointer = pFile; | 180 stream1->descriptor.pointer = pFile; |
181 stream1->close = _FTStreamClose; | 181 stream1->close = _FTStreamClose; |
182 stream1->read = _FTStreamRead; | 182 stream1->read = _FTStreamRead; |
183 FXFT_Open_Args args; | 183 FXFT_Open_Args args; |
184 args.flags = FT_OPEN_STREAM; | 184 args.flags = FT_OPEN_STREAM; |
185 args.stream = stream1; | 185 args.stream = stream1; |
186 if (FXFT_Open_Face(library, &args, faceIndex, Face)) { | 186 if (FXFT_Open_Face(library, &args, faceIndex, Face)) { |
187 FX_Free(stream1); | 187 FX_Free(stream1); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return width; | 232 return width; |
233 } | 233 } |
234 | 234 |
235 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, uint32_t size) { | 235 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, uint32_t size) { |
236 m_pFontDataAllocation = FX_Alloc(uint8_t, size); | 236 m_pFontDataAllocation = FX_Alloc(uint8_t, size); |
237 FXSYS_memcpy(m_pFontDataAllocation, data, size); | 237 FXSYS_memcpy(m_pFontDataAllocation, data, size); |
238 m_Face = FT_LoadFont(m_pFontDataAllocation, size); | 238 m_Face = FT_LoadFont(m_pFontDataAllocation, size); |
239 m_pFontData = m_pFontDataAllocation; | 239 m_pFontData = m_pFontDataAllocation; |
240 m_bEmbedded = TRUE; | 240 m_bEmbedded = TRUE; |
241 m_dwSize = size; | 241 m_dwSize = size; |
242 return m_Face != NULL; | 242 return !!m_Face; |
243 } | 243 } |
244 | 244 |
245 FX_BOOL CFX_Font::IsTTFont() const { | 245 FX_BOOL CFX_Font::IsTTFont() const { |
246 if (!m_Face) | 246 if (!m_Face) |
247 return FALSE; | 247 return FALSE; |
248 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; | 248 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; |
249 } | 249 } |
250 | 250 |
251 int CFX_Font::GetAscent() const { | 251 int CFX_Font::GetAscent() const { |
252 if (!m_Face) | 252 if (!m_Face) |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 if (nEncodingID != FXFM_ENCODING_NONE) | 527 if (nEncodingID != FXFM_ENCODING_NONE) |
528 return _FXFM_CreateFontEncoding(pFont, nEncodingID); | 528 return _FXFM_CreateFontEncoding(pFont, nEncodingID); |
529 | 529 |
530 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { | 530 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { |
531 CFX_UnicodeEncodingEx* pFontEncoding = | 531 CFX_UnicodeEncodingEx* pFontEncoding = |
532 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); | 532 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); |
533 if (pFontEncoding) { | 533 if (pFontEncoding) { |
534 return pFontEncoding; | 534 return pFontEncoding; |
535 } | 535 } |
536 } | 536 } |
537 return NULL; | 537 return nullptr; |
538 } | 538 } |
539 #endif // PDF_ENABLE_XFA | 539 #endif // PDF_ENABLE_XFA |
OLD | NEW |