Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: core/src/fxge/ge/fx_ge_font.cpp

Issue 1414463006: Merge to XFA: Make CFX_FontMgr member variables private. (try 2) (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fxge/fx_font.h ('k') | core/src/fxge/ge/fx_ge_fontmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
(...skipping 21 matching lines...) Expand all
32 FXFM_ENCODING_APPLE_ROMAN, 32 FXFM_ENCODING_APPLE_ROMAN,
33 }; 33 };
34 34
35 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont, 35 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
36 FX_DWORD nEncodingID) { 36 FX_DWORD nEncodingID) {
37 if (FXFT_Select_Charmap(pFont->m_Face, nEncodingID)) 37 if (FXFT_Select_Charmap(pFont->m_Face, nEncodingID))
38 return nullptr; 38 return nullptr;
39 return new CFX_UnicodeEncodingEx(pFont, nEncodingID); 39 return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
40 } 40 }
41 41
42 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
43 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
44 }
45
42 } // namespace 46 } // namespace
43 47
44 CFX_Font::CFX_Font() { 48 CFX_Font::CFX_Font() {
45 m_pSubstFont = NULL; 49 m_pSubstFont = NULL;
46 m_Face = NULL; 50 m_Face = NULL;
47 m_bEmbedded = FALSE; 51 m_bEmbedded = FALSE;
48 m_bVertical = FALSE; 52 m_bVertical = FALSE;
49 m_pFontData = NULL; 53 m_pFontData = NULL;
50 m_pFontDataAllocation = NULL; 54 m_pFontDataAllocation = NULL;
51 m_dwSize = 0; 55 m_dwSize = 0;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 args.stream = stream1; 178 args.stream = stream1;
175 if (FXFT_Open_Face(library, &args, faceIndex, Face)) { 179 if (FXFT_Open_Face(library, &args, faceIndex, Face)) {
176 FX_Free(stream1); 180 FX_Free(stream1);
177 return FALSE; 181 return FALSE;
178 } 182 }
179 if (stream) { 183 if (stream) {
180 *stream = stream1; 184 *stream = stream1;
181 } 185 }
182 return TRUE; 186 return TRUE;
183 } 187 }
188
184 FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile, 189 FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile,
185 int nFaceIndex, 190 int nFaceIndex,
186 int* pFaceCount) { 191 int* pFaceCount) {
187 m_bEmbedded = FALSE; 192 m_bEmbedded = FALSE;
188 FXFT_Library library; 193
189 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) 194 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
190 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary); 195 pFontMgr->InitFTLibrary();
191 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; 196 FXFT_Library library = pFontMgr->GetFTLibrary();
192 FXFT_Stream stream = NULL; 197
198 FXFT_Stream stream = nullptr;
193 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex)) 199 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex))
194 return FALSE; 200 return FALSE;
201
195 if (pFaceCount) 202 if (pFaceCount)
196 *pFaceCount = (int)m_Face->num_faces; 203 *pFaceCount = (int)m_Face->num_faces;
197 m_pOwnedStream = stream; 204 m_pOwnedStream = stream;
198 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); 205 FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
199 return TRUE; 206 return TRUE;
200 } 207 }
208
201 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) { 209 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) {
202 if (!m_Face) { 210 if (!m_Face) {
203 return 0; 211 return 0;
204 } 212 }
205 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { 213 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) {
206 AdjustMMParams(glyph_index, 0, 0); 214 AdjustMMParams(glyph_index, 0, 0);
207 } 215 }
208 int err = FXFT_Load_Glyph( 216 int err = FXFT_Load_Glyph(
209 m_Face, glyph_index, 217 m_Face, glyph_index,
210 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); 218 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
211 if (err) { 219 if (err) {
212 return 0; 220 return 0;
213 } 221 }
214 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), 222 int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
215 FXFT_Get_Glyph_HoriAdvance(m_Face)); 223 FXFT_Get_Glyph_HoriAdvance(m_Face));
216 return width; 224 return width;
217 } 225 }
218 static FXFT_Face FT_LoadFont(uint8_t* pData, int size) { 226
219 FXFT_Library library;
220 if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) {
221 FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary);
222 }
223 library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary;
224 FXFT_Face face = NULL;
225 int error = FXFT_New_Memory_Face(library, pData, size, 0, &face);
226 if (error) {
227 return NULL;
228 }
229 error = FXFT_Set_Pixel_Sizes(face, 64, 64);
230 if (error) {
231 return NULL;
232 }
233 return face;
234 }
235 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) { 227 FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) {
236 m_pFontDataAllocation = FX_Alloc(uint8_t, size); 228 m_pFontDataAllocation = FX_Alloc(uint8_t, size);
237 FXSYS_memcpy(m_pFontDataAllocation, data, size); 229 FXSYS_memcpy(m_pFontDataAllocation, data, size);
238 m_Face = FT_LoadFont((uint8_t*)m_pFontDataAllocation, size); 230 m_Face = FT_LoadFont(m_pFontDataAllocation, size);
239 m_pFontData = (uint8_t*)m_pFontDataAllocation; 231 m_pFontData = m_pFontDataAllocation;
240 m_bEmbedded = TRUE; 232 m_bEmbedded = TRUE;
241 m_dwSize = size; 233 m_dwSize = size;
242 return m_Face != NULL; 234 return m_Face != NULL;
243 } 235 }
244 FX_BOOL CFX_Font::IsTTFont() { 236 FX_BOOL CFX_Font::IsTTFont() {
245 if (m_Face == NULL) { 237 if (m_Face == NULL) {
246 return FALSE; 238 return FALSE;
247 } 239 }
248 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT; 240 return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT;
249 } 241 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 524
533 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { 525 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) {
534 CFX_UnicodeEncodingEx* pFontEncoding = 526 CFX_UnicodeEncodingEx* pFontEncoding =
535 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); 527 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]);
536 if (pFontEncoding) { 528 if (pFontEncoding) {
537 return pFontEncoding; 529 return pFontEncoding;
538 } 530 }
539 } 531 }
540 return NULL; 532 return NULL;
541 } 533 }
OLDNEW
« no previous file with comments | « core/include/fxge/fx_font.h ('k') | core/src/fxge/ge/fx_ge_fontmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698