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

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

Issue 1398383002: core/ difference with XFA (for information only). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 2015-11-24 version 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
« no previous file with comments | « core/src/fxge/dib/fx_dib_convert.cpp ('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 "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
14 extern void _FPDFAPI_GetInternalFontData(int id1,
15 const uint8_t*& data,
16 FX_DWORD& size);
17
18 #endif
13 namespace { 19 namespace {
14 20
21 #ifdef PDF_ENABLE_XFA
22 const FX_DWORD g_EncodingID[] = {
23 FXFM_ENCODING_MS_SYMBOL,
24 FXFM_ENCODING_UNICODE,
25 FXFM_ENCODING_MS_SJIS,
26 FXFM_ENCODING_MS_GB2312,
27 FXFM_ENCODING_MS_BIG5,
28 FXFM_ENCODING_MS_WANSUNG,
29 FXFM_ENCODING_MS_JOHAB,
30 FXFM_ENCODING_ADOBE_STANDARD,
31 FXFM_ENCODING_ADOBE_EXPERT,
32 FXFM_ENCODING_ADOBE_CUSTOM,
33 FXFM_ENCODING_ADOBE_LATIN_1,
34 FXFM_ENCODING_OLD_LATIN_2,
35 FXFM_ENCODING_APPLE_ROMAN,
36 };
37
38 CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
39 FX_DWORD nEncodingID) {
40 if (FXFT_Select_Charmap(pFont->GetFace(), nEncodingID))
41 return nullptr;
42 return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
43 }
44
45 #endif
15 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) { 46 FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
16 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0); 47 return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
17 } 48 }
18 49
19 } // namespace 50 } // namespace
20 51
21 CFX_Font::CFX_Font() { 52 CFX_Font::CFX_Font() {
22 m_pSubstFont = NULL; 53 m_pSubstFont = NULL;
23 m_Face = NULL; 54 m_Face = NULL;
24 m_bEmbedded = FALSE; 55 m_bEmbedded = FALSE;
25 m_bVertical = FALSE; 56 m_bVertical = FALSE;
26 m_pFontData = NULL; 57 m_pFontData = NULL;
27 m_pFontDataAllocation = NULL; 58 m_pFontDataAllocation = NULL;
28 m_dwSize = 0; 59 m_dwSize = 0;
60 #ifdef PDF_ENABLE_XFA
61 m_pOwnedStream = NULL;
62 #endif
29 m_pGsubData = NULL; 63 m_pGsubData = NULL;
30 m_pPlatformFont = NULL; 64 m_pPlatformFont = NULL;
31 m_pPlatformFontCollection = NULL; 65 m_pPlatformFontCollection = NULL;
32 m_pDwFont = NULL; 66 m_pDwFont = NULL;
33 m_hHandle = NULL; 67 m_hHandle = NULL;
34 m_bDwLoaded = FALSE; 68 m_bDwLoaded = FALSE;
69 #ifdef PDF_ENABLE_XFA
70 m_bLogic = FALSE;
71 }
72 FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) {
73 if (pFont == NULL) {
74 return FALSE;
75 }
76 m_bLogic = TRUE;
77 if (pFont->m_pSubstFont) {
78 m_pSubstFont = new CFX_SubstFont;
79 m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset;
80 m_pSubstFont->m_ExtHandle = pFont->m_pSubstFont->m_ExtHandle;
81 m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags;
82 m_pSubstFont->m_Weight = pFont->m_pSubstFont->m_Weight;
83 m_pSubstFont->m_Family = pFont->m_pSubstFont->m_Family;
84 m_pSubstFont->m_ItalicAngle = pFont->m_pSubstFont->m_ItalicAngle;
85 }
86 if (pFont->m_OtfFontData.GetSize()) {
87 m_OtfFontData.AttachData(pFont->m_OtfFontData.GetBuffer(),
88 pFont->m_OtfFontData.GetSize());
89 }
90 m_Face = pFont->m_Face;
91 m_bEmbedded = pFont->m_bEmbedded;
92 m_bVertical = pFont->m_bVertical;
93 m_dwSize = pFont->m_dwSize;
94 m_pFontData = pFont->m_pFontData;
95 m_pGsubData = pFont->m_pGsubData;
96 m_pPlatformFont = pFont->m_pPlatformFont;
97 m_pPlatformFontCollection = pFont->m_pPlatformFontCollection;
98 m_pDwFont = pFont->m_pDwFont;
99 m_hHandle = pFont->m_hHandle;
100 m_bDwLoaded = pFont->m_bDwLoaded;
101 m_pOwnedStream = pFont->m_pOwnedStream;
102 return TRUE;
103 #endif
35 } 104 }
36 CFX_Font::~CFX_Font() { 105 CFX_Font::~CFX_Font() {
37 delete m_pSubstFont; 106 delete m_pSubstFont;
38 m_pSubstFont = NULL; 107 m_pSubstFont = NULL;
108 #ifndef PDF_ENABLE_XFA
39 FX_Free(m_pFontDataAllocation); 109 FX_Free(m_pFontDataAllocation);
40 m_pFontDataAllocation = NULL; 110 m_pFontDataAllocation = NULL;
111 #else
112 if (m_bLogic) {
113 m_OtfFontData.DetachBuffer();
114 return;
115 }
116 #endif
41 if (m_Face) { 117 if (m_Face) {
118 #ifndef PDF_ENABLE_XFA
42 if (FXFT_Get_Face_External_Stream(m_Face)) { 119 if (FXFT_Get_Face_External_Stream(m_Face)) {
43 FXFT_Clear_Face_External_Stream(m_Face); 120 FXFT_Clear_Face_External_Stream(m_Face);
44 } 121 }
122 #endif
45 if (m_bEmbedded) { 123 if (m_bEmbedded) {
46 DeleteFace(); 124 DeleteFace();
47 } else { 125 } else {
48 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); 126 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
49 } 127 }
50 } 128 }
129 #ifdef PDF_ENABLE_XFA
130 FX_Free(m_pOwnedStream);
131 m_pOwnedStream = NULL;
132 #endif
51 FX_Free(m_pGsubData); 133 FX_Free(m_pGsubData);
52 m_pGsubData = NULL; 134 m_pGsubData = NULL;
53 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 135 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
54 ReleasePlatformResource(); 136 ReleasePlatformResource();
55 #endif 137 #endif
56 } 138 }
57 void CFX_Font::DeleteFace() { 139 void CFX_Font::DeleteFace() {
58 FXFT_Done_Face(m_Face); 140 FXFT_Done_Face(m_Face);
59 m_Face = NULL; 141 m_Face = NULL;
60 } 142 }
(...skipping 14 matching lines...) Expand all
75 if (m_pSubstFont->m_ExtHandle) { 157 if (m_pSubstFont->m_ExtHandle) {
76 m_pPlatformFont = m_pSubstFont->m_ExtHandle; 158 m_pPlatformFont = m_pSubstFont->m_ExtHandle;
77 m_pSubstFont->m_ExtHandle = NULL; 159 m_pSubstFont->m_ExtHandle = NULL;
78 } 160 }
79 #endif 161 #endif
80 if (m_Face) { 162 if (m_Face) {
81 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); 163 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face);
82 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); 164 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face);
83 } 165 }
84 } 166 }
167 #ifdef PDF_ENABLE_XFA
168 extern "C" {
169 unsigned long _FTStreamRead(FXFT_Stream stream,
170 unsigned long offset,
171 unsigned char* buffer,
172 unsigned long count) {
173 if (count == 0) {
174 return 0;
175 }
176 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer;
177 int res = pFile->ReadBlock(buffer, offset, count);
178 if (res) {
179 return count;
180 }
181 return 0;
182 }
183 void _FTStreamClose(FXFT_Stream stream) {}
184 };
185 FX_BOOL _LoadFile(FXFT_Library library,
186 FXFT_Face* Face,
187 IFX_FileRead* pFile,
188 FXFT_Stream* stream,
189 int32_t faceIndex = 0) {
190 FXFT_Stream stream1 = (FXFT_Stream)FX_Alloc(uint8_t, sizeof(FXFT_StreamRec));
191 stream1->base = NULL;
192 stream1->size = (unsigned long)pFile->GetSize();
193 stream1->pos = 0;
194 stream1->descriptor.pointer = pFile;
195 stream1->close = _FTStreamClose;
196 stream1->read = _FTStreamRead;
197 FXFT_Open_Args args;
198 args.flags = FT_OPEN_STREAM;
199 args.stream = stream1;
200 if (FXFT_Open_Face(library, &args, faceIndex, Face)) {
201 FX_Free(stream1);
202 return FALSE;
203 }
204 if (stream) {
205 *stream = stream1;
206 }
207 return TRUE;
208 }
209
210 FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile,
211 int nFaceIndex,
212 int* pFaceCount) {
213 m_bEmbedded = FALSE;
214
215 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
216 pFontMgr->InitFTLibrary();
217 FXFT_Library library = pFontMgr->GetFTLibrary();
218
219 FXFT_Stream stream = nullptr;
220 if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex))
221 return FALSE;
222
223 if (pFaceCount)
224 *pFaceCount = (int)m_Face->num_faces;
225 m_pOwnedStream = stream;
226 FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
227 return TRUE;
228 }
229 #endif
85 230
86 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) { 231 int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) {
87 if (!m_Face) { 232 if (!m_Face) {
88 return 0; 233 return 0;
89 } 234 }
90 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) { 235 if (m_pSubstFont && (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)) {
91 AdjustMMParams(glyph_index, 0, 0); 236 AdjustMMParams(glyph_index, 0, 0);
92 } 237 }
93 int err = FXFT_Load_Glyph( 238 int err = FXFT_Load_Glyph(
94 m_Face, glyph_index, 239 m_Face, glyph_index,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 475
331 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) { 476 if (m_pFont->GetSubstFont() && m_pFont->GetSubstFont()->m_Charset == 2) {
332 FX_DWORD index = 0; 477 FX_DWORD index = 0;
333 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) 478 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0)
334 index = FXFT_Get_Char_Index(face, charcode); 479 index = FXFT_Get_Char_Index(face, charcode);
335 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) 480 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN))
336 return FXFT_Get_Char_Index(face, charcode); 481 return FXFT_Get_Char_Index(face, charcode);
337 } 482 }
338 return charcode; 483 return charcode;
339 } 484 }
485 #ifdef PDF_ENABLE_XFA
486
487 CFX_UnicodeEncodingEx::CFX_UnicodeEncodingEx(CFX_Font* pFont,
488 FX_DWORD EncodingID)
489 : CFX_UnicodeEncoding(pFont), m_nEncodingID(EncodingID) {
490 }
491
492 CFX_UnicodeEncodingEx::~CFX_UnicodeEncodingEx() {
493 }
494
495 FX_DWORD CFX_UnicodeEncodingEx::GlyphFromCharCode(FX_DWORD charcode) {
496 FXFT_Face face = m_pFont->GetFace();
497 FT_UInt nIndex = FXFT_Get_Char_Index(face, charcode);
498 if (nIndex > 0) {
499 return nIndex;
500 }
501 int nmaps = FXFT_Get_Face_CharmapCount(face);
502 int m = 0;
503 while (m < nmaps) {
504 int nEncodingID =
505 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[m++]);
506 if (m_nEncodingID == nEncodingID) {
507 continue;
508 }
509 int error = FXFT_Select_Charmap(face, nEncodingID);
510 if (error) {
511 continue;
512 }
513 nIndex = FXFT_Get_Char_Index(face, charcode);
514 if (nIndex > 0) {
515 m_nEncodingID = nEncodingID;
516 return nIndex;
517 }
518 }
519 FXFT_Select_Charmap(face, m_nEncodingID);
520 return 0;
521 }
522
523 FX_DWORD CFX_UnicodeEncodingEx::CharCodeFromUnicode(FX_WCHAR Unicode) const {
524 if (m_nEncodingID == FXFM_ENCODING_UNICODE ||
525 m_nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
526 return Unicode;
527 }
528 FXFT_Face face = m_pFont->GetFace();
529 int nmaps = FXFT_Get_Face_CharmapCount(face);
530 for (int i = 0; i < nmaps; i++) {
531 int nEncodingID =
532 FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i]);
533 if (nEncodingID == FXFM_ENCODING_UNICODE ||
534 nEncodingID == FXFM_ENCODING_MS_SYMBOL) {
535 return Unicode;
536 }
537 }
538 return -1;
539 }
540
541 CFX_UnicodeEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont,
542 FX_DWORD nEncodingID) {
543 if (!pFont || !pFont->GetFace())
544 return nullptr;
545
546 if (nEncodingID != FXFM_ENCODING_NONE)
547 return _FXFM_CreateFontEncoding(pFont, nEncodingID);
548
549 for (size_t i = 0; i < FX_ArraySize(g_EncodingID); ++i) {
550 CFX_UnicodeEncodingEx* pFontEncoding =
551 _FXFM_CreateFontEncoding(pFont, g_EncodingID[i]);
552 if (pFontEncoding) {
553 return pFontEncoding;
554 }
555 }
556 return NULL;
557 }
558 #endif
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_convert.cpp ('k') | core/src/fxge/ge/fx_ge_fontmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698