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

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

Issue 1471323004: Inflict PPDF_ENABLE_XFA ifdefs on XFA core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years 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
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 "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 extern void _FPDFAPI_GetInternalFontData(int id1, 14 extern void _FPDFAPI_GetInternalFontData(int id1,
14 const uint8_t*& data, 15 const uint8_t*& data,
15 FX_DWORD& size); 16 FX_DWORD& size);
16 17
18 #endif
17 namespace { 19 namespace {
18 20
21 #ifdef PDF_ENABLE_XFA
19 const FX_DWORD g_EncodingID[] = { 22 const FX_DWORD g_EncodingID[] = {
20 FXFM_ENCODING_MS_SYMBOL, 23 FXFM_ENCODING_MS_SYMBOL,
21 FXFM_ENCODING_UNICODE, 24 FXFM_ENCODING_UNICODE,
22 FXFM_ENCODING_MS_SJIS, 25 FXFM_ENCODING_MS_SJIS,
23 FXFM_ENCODING_MS_GB2312, 26 FXFM_ENCODING_MS_GB2312,
24 FXFM_ENCODING_MS_BIG5, 27 FXFM_ENCODING_MS_BIG5,
25 FXFM_ENCODING_MS_WANSUNG, 28 FXFM_ENCODING_MS_WANSUNG,
26 FXFM_ENCODING_MS_JOHAB, 29 FXFM_ENCODING_MS_JOHAB,
27 FXFM_ENCODING_ADOBE_STANDARD, 30 FXFM_ENCODING_ADOBE_STANDARD,
28 FXFM_ENCODING_ADOBE_EXPERT, 31 FXFM_ENCODING_ADOBE_EXPERT,
29 FXFM_ENCODING_ADOBE_CUSTOM, 32 FXFM_ENCODING_ADOBE_CUSTOM,
30 FXFM_ENCODING_ADOBE_LATIN_1, 33 FXFM_ENCODING_ADOBE_LATIN_1,
31 FXFM_ENCODING_OLD_LATIN_2, 34 FXFM_ENCODING_OLD_LATIN_2,
32 FXFM_ENCODING_APPLE_ROMAN, 35 FXFM_ENCODING_APPLE_ROMAN,
33 }; 36 };
34 37
35 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont, 38 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
36 FX_DWORD nEncodingID) { 39 FX_DWORD nEncodingID) {
37 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID)) 40 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID))
38 return nullptr; 41 return nullptr;
39 return new CFX_UnicodeEncodingEx(pFont, nEncodingID); 42 return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
40 } 43 }
41 44
45 #endif
42 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { 46 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
43 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); 47 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
44 } 48 }
45 49
46 } // namespace 50 } // namespace
47 51
48 CFX_Font::CFX_Font() { 52 CFX_Font::CFX_Font() {
49 m_pSubstFont = NULL; 53 m_pSubstFont = NULL;
50 m_Face = NULL; 54 m_Face = NULL;
51 m_bEmbedded = FALSE; 55 m_bEmbedded = FALSE;
52 m_bVertical = FALSE; 56 m_bVertical = FALSE;
53 m_pFontData = NULL; 57 m_pFontData = NULL;
54 m_pFontDataAllocation = NULL; 58 m_pFontDataAllocation = NULL;
55 m_dwSize = 0; 59 m_dwSize = 0;
60 #ifdef PDF_ENABLE_XFA
56 m_pOwnedStream = NULL; 61 m_pOwnedStream = NULL;
62 #endif
57 m_pGsubData = NULL; 63 m_pGsubData = NULL;
58 m_pPlatformFont = NULL; 64 m_pPlatformFont = NULL;
59 m_pPlatformFontCollection = NULL; 65 m_pPlatformFontCollection = NULL;
60 m_pDwFont = NULL; 66 m_pDwFont = NULL;
61 m_hHandle = NULL; 67 m_hHandle = NULL;
62 m_bDwLoaded = FALSE; 68 m_bDwLoaded = FALSE;
69 #ifdef PDF_ENABLE_XFA
63 m_bLogic = FALSE; 70 m_bLogic = FALSE;
64 } 71 }
65 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { 72 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) {
66 if (pFont == NULL) { 73 if (pFont == NULL) {
67 return FALSE; 74 return FALSE;
68 } 75 }
69 m_bLogic = TRUE; 76 m_bLogic = TRUE;
70 if (pFont->m_pSubstFont) { 77 if (pFont->m_pSubstFont) {
71 m_pSubstFont = new CFX_SubstFont; 78 m_pSubstFont = new CFX_SubstFont;
72 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; 79 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset;
(...skipping 13 matching lines...) Expand all
86 m_dwSize = pFont->m_dwSize; 93 m_dwSize = pFont->m_dwSize;
87 m_pFontData = pFont->m_pFontData; 94 m_pFontData = pFont->m_pFontData;
88 m_pGsubData = pFont->m_pGsubData; 95 m_pGsubData = pFont->m_pGsubData;
89 m_pPlatformFont = pFont->m_pPlatformFont; 96 m_pPlatformFont = pFont->m_pPlatformFont;
90 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection; 97 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection;
91 m_pDwFont = pFont->m_pDwFont; 98 m_pDwFont = pFont->m_pDwFont;
92 m_hHandle = pFont->m_hHandle; 99 m_hHandle = pFont->m_hHandle;
93 m_bDwLoaded = pFont->m_bDwLoaded; 100 m_bDwLoaded = pFont->m_bDwLoaded;
94 m_pOwnedStream = pFont->m_pOwnedStream; 101 m_pOwnedStream = pFont->m_pOwnedStream;
95 return TRUE; 102 return TRUE;
103 #endif
96 } 104 }
97 CFX_Font::~CFX_Font() { 105 CFX_Font::~CFX_Font() {
98 delete m_pSubstFont; 106 delete m_pSubstFont;
99 m_pSubstFont = NULL; 107 m_pSubstFont = NULL;
108 #ifndef PDF_ENABLE_XFA
109 FX_Free(m_pFontDataAllocation);
110 m_pFontDataAllocation = NULL;
111 #else
100 if (m_bLogic) { 112 if (m_bLogic) {
101 m_OtfFontData.DetachBuffer(); 113 m_OtfFontData.DetachBuffer();
102 return; 114 return;
103 } 115 }
116 #endif
104 if (m_Face) { 117 if (m_Face) {
118 #ifndef PDF_ENABLE_XFA
119 if (FXFT_Get_Face_External_Stream(m_Face)) {
120 FXFT_Clear_Face_External_Stream(m_Face);
121 }
122 #endif
105 if (m_bEmbedded) { 123 if (m_bEmbedded) {
106 DeleteFace(); 124 DeleteFace();
107 } else { 125 } else {
108 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); 126 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
109 } 127 }
110 } 128 }
129 #ifdef PDF_ENABLE_XFA
111 FX_Free(m_pOwnedStream); 130 FX_Free(m_pOwnedStream);
112 m_pOwnedStream = NULL; 131 m_pOwnedStream = NULL;
132 #endif
113 FX_Free(m_pGsubData); 133 FX_Free(m_pGsubData);
114 m_pGsubData = NULL; 134 m_pGsubData = NULL;
115 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 135 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
116 ReleasePlatformResource(); 136 ReleasePlatformResource();
117 #endif 137 #endif
118 } 138 }
119 void CFX_Font::DeleteFace() { 139 void CFX_Font::DeleteFace() {
120 FXFT_Done_Face(m_Face); 140 FXFT_Done_Face(m_Face);
121 m_Face = NULL; 141 m_Face = NULL;
122 } 142 }
(...skipping 14 matching lines...) Expand all
137 if (m_pSubstFont->m_ExtHandle) { 157 if (m_pSubstFont->m_ExtHandle) {
138 m_pPlatformFont = m_pSubstFont->m_ExtHandle; 158 m_pPlatformFont = m_pSubstFont->m_ExtHandle;
139 m_pSubstFont->m_ExtHandle = NULL; 159 m_pSubstFont->m_ExtHandle = NULL;
140 } 160 }
141 #endif 161 #endif
142 if (m_Face) { 162 if (m_Face) {
143 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); 163 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face);
144 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); 164 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face);
145 } 165 }
146 } 166 }
167 #ifdef PDF_ENABLE_XFA
147 extern "C" { 168 extern "C" {
148 unsigned long _FTStreamRead(FXFT_Stream stream, 169 unsigned long _FTStreamRead(FXFT_Stream stream,
149 unsigned long offset, 170 unsigned long offset,
150 unsigned char* buffer, 171 unsigned char* buffer,
151 unsigned long count) { 172 unsigned long count) {
152 if (count == 0) { 173 if (count == 0) {
153 return 0; 174 return 0;
154 } 175 }
155 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; 176 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer;
156 int res = pFile->ReadBlock(buffer, offset, count); 177 int res = pFile->ReadBlock(buffer, offset, count);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 FXFT_Stream stream = nullptr; 219 FXFT_Stream stream = nullptr;
199 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex)) 220 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex))
200 return FALSE; 221 return FALSE;
201 222
202 if (pFaceCount) 223 if (pFaceCount)
203 *pFaceCount = (int)m_Face->num_faces; 224 *pFaceCount = (int)m_Face->num_faces;
204 m_pOwnedStream = stream; 225 m_pOwnedStream = stream;
205 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); 226 FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
206 return TRUE; 227 return TRUE;
207 } 228 }
229 #endif
208 230
209 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) { 231 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) {
210 if (!m_Face) { 232 if (!m_Face) {
211 return 0; 233 return 0;
212 } 234 }
213 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { 235 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) {
214 AdjustMMParams(glyph_index, 0, 0); 236 AdjustMMParams(glyph_index, 0, 0);
215 } 237 }
216 int err = FXFT_Load_Glyph( 238 int err = FXFT_Load_Glyph(
217 m_Face, glyph_index, 239 m_Face, glyph_index,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 475
454 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) { 476 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) {
455 FX_DWORD index = 0; 477 FX_DWORD index = 0;
456 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) 478 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0)
457 index = FXFT_Get_Char_Index(face, charcode); 479 index = FXFT_Get_Char_Index(face, charcode);
458 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) 480 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN))
459 return FXFT_Get_Char_Index(face, charcode); 481 return FXFT_Get_Char_Index(face, charcode);
460 } 482 }
461 return charcode; 483 return charcode;
462 } 484 }
485 #ifdef PDF_ENABLE_XFA
463 486
464 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont, 487 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont,
465 FX_DWORD EncodingID) 488 FX_DWORD EncodingID)
466 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) { 489 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) {
467 } 490 }
468 491
469 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() { 492 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() {
470 } 493 }
471 494
472 FX_DWORD CFX_UnicodeEncodingEx::GlyphFromCharCode(FX_DWORD charcode) { 495 FX_DWORD CFX_UnicodeEncodingEx::GlyphFromCharCode(FX_DWORD charcode) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 548
526 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) { 549 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) {
527 CFX_UnicodeEncodingEx* pFontEncoding = 550 CFX_UnicodeEncodingEx* pFontEncoding =
528 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]); 551 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]);
529 if (pFontEncoding) { 552 if (pFontEncoding) {
530 return pFontEncoding; 553 return pFontEncoding;
531 } 554 }
532 } 555 }
533 return NULL; 556 return NULL;
534 } 557 }
558 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698