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

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font.cpp

Issue 1293973002: Cleanup CFX_Font a bit. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Remove LoadFile() Created 5 years, 4 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
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/fpdfapi/fpdf_module.h" 7 #include "../../../include/fpdfapi/fpdf_module.h"
8 #include "../../../include/fpdfapi/fpdf_page.h" 8 #include "../../../include/fpdfapi/fpdf_page.h"
9 #include "../../../include/fpdfapi/fpdf_pageobj.h" 9 #include "../../../include/fpdfapi/fpdf_pageobj.h"
10 #include "../../../include/fpdfapi/fpdf_resource.h" 10 #include "../../../include/fpdfapi/fpdf_resource.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 FX_CHAR* dest_buf = result.GetBuffer(src_len * 2); 205 FX_CHAR* dest_buf = result.GetBuffer(src_len * 2);
206 const FX_WCHAR* src_buf = str.c_str(); 206 const FX_WCHAR* src_buf = str.c_str();
207 int dest_pos = 0; 207 int dest_pos = 0;
208 for (int src_pos = 0; src_pos < src_len; src_pos++) { 208 for (int src_pos = 0; src_pos < src_len; src_pos++) {
209 FX_DWORD charcode = CharCodeFromUnicode(src_buf[src_pos]); 209 FX_DWORD charcode = CharCodeFromUnicode(src_buf[src_pos]);
210 dest_pos += AppendChar(dest_buf + dest_pos, charcode); 210 dest_pos += AppendChar(dest_buf + dest_pos, charcode);
211 } 211 }
212 result.ReleaseBuffer(dest_pos); 212 result.ReleaseBuffer(dest_pos);
213 return result; 213 return result;
214 } 214 }
215
215 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { 216 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) {
216 m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags"), PDFFONT_NONSYMBOLIC); 217 m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags"), PDFFONT_NONSYMBOLIC);
217 int ItalicAngle = 0; 218 int ItalicAngle = 0;
218 FX_BOOL bExistItalicAngle = FALSE; 219 FX_BOOL bExistItalicAngle = FALSE;
219 if (pFontDesc->KeyExist(FX_BSTRC("ItalicAngle"))) { 220 if (pFontDesc->KeyExist(FX_BSTRC("ItalicAngle"))) {
220 ItalicAngle = pFontDesc->GetInteger(FX_BSTRC("ItalicAngle")); 221 ItalicAngle = pFontDesc->GetInteger(FX_BSTRC("ItalicAngle"));
221 bExistItalicAngle = TRUE; 222 bExistItalicAngle = TRUE;
222 } 223 }
223 if (ItalicAngle < 0) { 224 if (ItalicAngle < 0) {
224 m_Flags |= PDFFONT_ITALIC; 225 m_Flags |= PDFFONT_ITALIC;
(...skipping 25 matching lines...) Expand all
250 if (m_Descent > 10) { 251 if (m_Descent > 10) {
251 m_Descent = -m_Descent; 252 m_Descent = -m_Descent;
252 } 253 }
253 CPDF_Array* pBBox = pFontDesc->GetArray(FX_BSTRC("FontBBox")); 254 CPDF_Array* pBBox = pFontDesc->GetArray(FX_BSTRC("FontBBox"));
254 if (pBBox) { 255 if (pBBox) {
255 m_FontBBox.left = pBBox->GetInteger(0); 256 m_FontBBox.left = pBBox->GetInteger(0);
256 m_FontBBox.bottom = pBBox->GetInteger(1); 257 m_FontBBox.bottom = pBBox->GetInteger(1);
257 m_FontBBox.right = pBBox->GetInteger(2); 258 m_FontBBox.right = pBBox->GetInteger(2);
258 m_FontBBox.top = pBBox->GetInteger(3); 259 m_FontBBox.top = pBBox->GetInteger(3);
259 } 260 }
261
260 CPDF_Stream* pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile")); 262 CPDF_Stream* pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile"));
261 if (pFontFile == NULL) { 263 if (!pFontFile)
262 pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile2")); 264 pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile2"));
263 } 265 if (!pFontFile)
264 if (pFontFile == NULL) {
265 pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile3")); 266 pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile3"));
266 } 267 if (!pFontFile)
267 if (pFontFile) { 268 return;
268 m_pFontFile = m_pDocument->LoadFontFile(pFontFile); 269
269 if (m_pFontFile == NULL) { 270 m_pFontFile = m_pDocument->LoadFontFile(pFontFile);
270 return; 271 if (!m_pFontFile)
271 } 272 return;
272 const uint8_t* pFontData = m_pFontFile->GetData(); 273
273 FX_DWORD dwFontSize = m_pFontFile->GetSize(); 274 const uint8_t* pFontData = m_pFontFile->GetData();
274 m_Font.LoadEmbedded(pFontData, dwFontSize); 275 FX_DWORD dwFontSize = m_pFontFile->GetSize();
275 if (m_Font.m_Face == NULL) { 276 m_Font.LoadEmbedded(pFontData, dwFontSize);
276 m_pFontFile = NULL; 277 if (!m_Font.GetFace()) {
277 } 278 m_pFontFile = nullptr;
Tom Sepez 2015/08/17 18:38:01 is this a leak?
Lei Zhang 2015/08/18 06:10:53 Probably. Also weird that it doesn't check the Loa
278 } 279 }
279 } 280 }
281
280 short TT2PDF(int m, FXFT_Face face) { 282 short TT2PDF(int m, FXFT_Face face) {
281 int upm = FXFT_Get_Face_UnitsPerEM(face); 283 int upm = FXFT_Get_Face_UnitsPerEM(face);
282 if (upm == 0) { 284 if (upm == 0) {
283 return (short)m; 285 return (short)m;
284 } 286 }
285 return (m * 1000 + upm / 2) / upm; 287 return (m * 1000 + upm / 2) / upm;
286 } 288 }
287 void CPDF_Font::CheckFontMetrics() { 289 void CPDF_Font::CheckFontMetrics() {
288 if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 && 290 if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 &&
289 m_FontBBox.right == 0) { 291 m_FontBBox.right == 0) {
290 if (m_Font.m_Face) { 292 FXFT_Face face = m_Font.GetFace();
291 m_FontBBox.left = 293 if (face) {
292 TT2PDF(FXFT_Get_Face_xMin(m_Font.m_Face), m_Font.m_Face); 294 m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(face), face);
293 m_FontBBox.bottom = 295 m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(face), face);
294 TT2PDF(FXFT_Get_Face_yMin(m_Font.m_Face), m_Font.m_Face); 296 m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(face), face);
295 m_FontBBox.right = 297 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(face), face);
296 TT2PDF(FXFT_Get_Face_xMax(m_Font.m_Face), m_Font.m_Face); 298 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(face), face);
297 m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(m_Font.m_Face), m_Font.m_Face); 299 m_Descent = TT2PDF(FXFT_Get_Face_Descender(face), face);
298 m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(m_Font.m_Face), m_Font.m_Face);
299 m_Descent = TT2PDF(FXFT_Get_Face_Descender(m_Font.m_Face), m_Font.m_Face);
300 } else { 300 } else {
301 FX_BOOL bFirst = TRUE; 301 FX_BOOL bFirst = TRUE;
302 for (int i = 0; i < 256; i++) { 302 for (int i = 0; i < 256; i++) {
303 FX_RECT rect; 303 FX_RECT rect;
304 GetCharBBox(i, rect); 304 GetCharBBox(i, rect);
305 if (rect.left == rect.right) { 305 if (rect.left == rect.right) {
306 continue; 306 continue;
307 } 307 }
308 if (bFirst) { 308 if (bFirst) {
309 m_FontBBox = rect; 309 m_FontBBox = rect;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { 353 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) {
354 int offset = 0; 354 int offset = 0;
355 int width = 0; 355 int width = 0;
356 while (offset < size) { 356 while (offset < size) {
357 FX_DWORD charcode = GetNextChar(pString, size, offset); 357 FX_DWORD charcode = GetNextChar(pString, size, offset);
358 width += GetCharWidthF(charcode); 358 width += GetCharWidthF(charcode);
359 } 359 }
360 return width; 360 return width;
361 } 361 }
362 int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode) { 362 int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode) {
363 if (m_Font.m_Face == NULL) { 363 if (!m_Font.GetFace())
364 return 0; 364 return 0;
365 } 365
366 int glyph_index = GlyphFromCharCode(charcode); 366 int glyph_index = GlyphFromCharCode(charcode);
367 if (glyph_index == 0xffff) { 367 if (glyph_index == 0xffff) {
368 return 0; 368 return 0;
369 } 369 }
370 return m_Font.GetGlyphWidth(glyph_index); 370 return m_Font.GetGlyphWidth(glyph_index);
371 } 371 }
372 int _PDF_GetStandardFontName(CFX_ByteString& name); 372 int _PDF_GetStandardFontName(CFX_ByteString& name);
373 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, 373 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc,
374 const CFX_ByteStringC& name) { 374 const CFX_ByteStringC& name) {
375 CFX_ByteString fontname(name); 375 CFX_ByteString fontname(name);
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 if (charcode > 0xff) { 815 if (charcode > 0xff) {
816 return -1; 816 return -1;
817 } 817 }
818 int index = m_GlyphIndex[(uint8_t)charcode]; 818 int index = m_GlyphIndex[(uint8_t)charcode];
819 if (index == 0xffff) { 819 if (index == 0xffff) {
820 return -1; 820 return -1;
821 } 821 }
822 return index; 822 return index;
823 } 823 }
824 void CPDF_SimpleFont::LoadCharMetrics(int charcode) { 824 void CPDF_SimpleFont::LoadCharMetrics(int charcode) {
825 if (m_Font.m_Face == NULL) { 825 if (!m_Font.GetFace())
826 return; 826 return;
827 } 827
828 if (charcode < 0 || charcode > 0xff) { 828 if (charcode < 0 || charcode > 0xff) {
829 return; 829 return;
830 } 830 }
831 int glyph_index = m_GlyphIndex[charcode]; 831 int glyph_index = m_GlyphIndex[charcode];
832 if (glyph_index == 0xffff) { 832 if (glyph_index == 0xffff) {
833 if (m_pFontFile == NULL && charcode != 32) { 833 if (m_pFontFile == NULL && charcode != 32) {
834 LoadCharMetrics(32); 834 LoadCharMetrics(32);
835 m_CharBBox[charcode] = m_CharBBox[32]; 835 m_CharBBox[charcode] = m_CharBBox[32];
836 if (m_bUseFontWidth) { 836 if (m_bUseFontWidth) {
837 m_CharWidth[charcode] = m_CharWidth[32]; 837 m_CharWidth[charcode] = m_CharWidth[32];
838 } 838 }
839 } 839 }
840 return; 840 return;
841 } 841 }
842 FXFT_Face face = m_Font.GetFace();
842 int err = FXFT_Load_Glyph( 843 int err = FXFT_Load_Glyph(
843 m_Font.m_Face, glyph_index, 844 face, glyph_index,
844 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); 845 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
845 if (err) { 846 if (err) {
846 return; 847 return;
847 } 848 }
848 m_CharBBox[charcode].Left = 849 m_CharBBox[charcode].Left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face);
849 TT2PDF(FXFT_Get_Glyph_HoriBearingX(m_Font.m_Face), m_Font.m_Face); 850 m_CharBBox[charcode].Right = TT2PDF(
850 m_CharBBox[charcode].Right = 851 FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), face);
851 TT2PDF(FXFT_Get_Glyph_HoriBearingX(m_Font.m_Face) + 852 m_CharBBox[charcode].Top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face);
852 FXFT_Get_Glyph_Width(m_Font.m_Face), 853 m_CharBBox[charcode].Bottom = TT2PDF(
853 m_Font.m_Face); 854 FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), face);
854 m_CharBBox[charcode].Top =
855 TT2PDF(FXFT_Get_Glyph_HoriBearingY(m_Font.m_Face), m_Font.m_Face);
856 m_CharBBox[charcode].Bottom =
857 TT2PDF(FXFT_Get_Glyph_HoriBearingY(m_Font.m_Face) -
858 FXFT_Get_Glyph_Height(m_Font.m_Face),
859 m_Font.m_Face);
860 if (m_bUseFontWidth) { 855 if (m_bUseFontWidth) {
861 int TT_Width = 856 int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face);
862 TT2PDF(FXFT_Get_Glyph_HoriAdvance(m_Font.m_Face), m_Font.m_Face);
863 if (m_CharWidth[charcode] == 0xffff) { 857 if (m_CharWidth[charcode] == 0xffff) {
864 m_CharWidth[charcode] = TT_Width; 858 m_CharWidth[charcode] = TT_Width;
865 } else if (TT_Width && !IsEmbedded()) { 859 } else if (TT_Width && !IsEmbedded()) {
866 m_CharBBox[charcode].Right = 860 m_CharBBox[charcode].Right =
867 m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width; 861 m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width;
868 m_CharBBox[charcode].Left = 862 m_CharBBox[charcode].Left =
869 m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width; 863 m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width;
870 } 864 }
871 } 865 }
872 } 866 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 } 947 }
954 if (!(m_Flags & PDFFONT_SYMBOLIC)) { 948 if (!(m_Flags & PDFFONT_SYMBOLIC)) {
955 m_BaseEncoding = PDFFONT_ENCODING_STANDARD; 949 m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
956 } 950 }
957 CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding")); 951 CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
958 LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, m_pFontFile != NULL, 952 LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, m_pFontFile != NULL,
959 m_Font.IsTTFont()); 953 m_Font.IsTTFont());
960 LoadGlyphMap(); 954 LoadGlyphMap();
961 delete[] m_pCharNames; 955 delete[] m_pCharNames;
962 m_pCharNames = NULL; 956 m_pCharNames = NULL;
963 if (m_Font.m_Face == NULL) { 957 if (!m_Font.GetFace())
964 return TRUE; 958 return TRUE;
965 } 959
966 if (m_Flags & PDFFONT_ALLCAP) { 960 if (m_Flags & PDFFONT_ALLCAP) {
967 unsigned char lowercases[] = {'a', 'z', 0xe0, 0xf6, 0xf8, 0xfd}; 961 unsigned char lowercases[] = {'a', 'z', 0xe0, 0xf6, 0xf8, 0xfd};
968 for (size_t range = 0; range < sizeof lowercases / 2; range++) { 962 for (size_t range = 0; range < sizeof lowercases / 2; range++) {
969 for (int i = lowercases[range * 2]; i <= lowercases[range * 2 + 1]; i++) { 963 for (int i = lowercases[range * 2]; i <= lowercases[range * 2 + 1]; i++) {
970 if (m_GlyphIndex[i] != 0xffff && m_pFontFile != NULL) { 964 if (m_GlyphIndex[i] != 0xffff && m_pFontFile != NULL) {
971 continue; 965 continue;
972 } 966 }
973 m_GlyphIndex[i] = m_GlyphIndex[i - 32]; 967 m_GlyphIndex[i] = m_GlyphIndex[i - 32];
974 if (m_CharWidth[i - 32]) { 968 if (m_CharWidth[i - 32]) {
975 m_CharWidth[i] = m_CharWidth[i - 32]; 969 m_CharWidth[i] = m_CharWidth[i - 32];
(...skipping 18 matching lines...) Expand all
994 break; 988 break;
995 } 989 }
996 } 990 }
997 if (i == 256 && width) { 991 if (i == 256 && width) {
998 m_Flags |= PDFFONT_FIXEDPITCH; 992 m_Flags |= PDFFONT_FIXEDPITCH;
999 } 993 }
1000 } 994 }
1001 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); 995 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140);
1002 m_Font.LoadSubst(m_BaseFont, IsFontType(PDFFONT_TRUETYPE), m_Flags, weight, 996 m_Font.LoadSubst(m_BaseFont, IsFontType(PDFFONT_TRUETYPE), m_Flags, weight,
1003 m_ItalicAngle, 0); 997 m_ItalicAngle, 0);
1004 if (m_Font.m_pSubstFont->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { 998 if (m_Font.GetSubstFont()->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) {
1005 } 999 }
1006 } 1000 }
1007 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const { 1001 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const {
1008 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && 1002 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN &&
1009 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && 1003 m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
1010 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; 1004 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS;
1011 } 1005 }
1012 CPDF_Type1Font::CPDF_Type1Font() : CPDF_SimpleFont(PDFFONT_TYPE1) { 1006 CPDF_Type1Font::CPDF_Type1Font() : CPDF_SimpleFont(PDFFONT_TYPE1) {
1013 m_Base14Font = -1; 1007 m_Base14Font = -1;
1014 } 1008 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 pStrAdobe, g_GlyphNameSubsts, 1082 pStrAdobe, g_GlyphNameSubsts,
1089 sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap), 1083 sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap),
1090 compareString); 1084 compareString);
1091 if (found) { 1085 if (found) {
1092 return found->m_pStrUnicode; 1086 return found->m_pStrUnicode;
1093 } 1087 }
1094 return NULL; 1088 return NULL;
1095 } 1089 }
1096 #endif 1090 #endif
1097 void CPDF_Type1Font::LoadGlyphMap() { 1091 void CPDF_Type1Font::LoadGlyphMap() {
1098 if (m_Font.m_Face == NULL) { 1092 FXFT_Face face = m_Font.GetFace();
Tom Sepez 2015/08/17 18:38:01 We're sure no other methods change this value?
Lei Zhang 2015/08/18 06:10:53 I'll just change it back to GetFace() to be on the
1093 if (!face)
1099 return; 1094 return;
1100 } 1095
1101 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1096 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1102 FX_BOOL bCoreText = TRUE; 1097 FX_BOOL bCoreText = TRUE;
1103 CQuartz2D& quartz2d = 1098 CQuartz2D& quartz2d =
1104 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d; 1099 ((CApplePlatform*)CFX_GEModule::Get()->GetPlatformData())->_quartz2d;
1105 if (!m_Font.m_pPlatformFont) { 1100 if (!m_Font.m_pPlatformFont) {
1106 if (m_Font.GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) { 1101 if (m_Font.GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) {
1107 bCoreText = FALSE; 1102 bCoreText = FALSE;
1108 } 1103 }
1109 m_Font.m_pPlatformFont = 1104 m_Font.m_pPlatformFont =
1110 quartz2d.CreateFont(m_Font.m_pFontData, m_Font.m_dwSize); 1105 quartz2d.CreateFont(m_Font.m_pFontData, m_Font.m_dwSize);
1111 if (NULL == m_Font.m_pPlatformFont) { 1106 if (NULL == m_Font.m_pPlatformFont) {
1112 bCoreText = FALSE; 1107 bCoreText = FALSE;
1113 } 1108 }
1114 } 1109 }
1115 #endif 1110 #endif
1116 if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) { 1111 if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) {
1117 if (FT_UseTTCharmap(m_Font.m_Face, 3, 0)) { 1112 if (FT_UseTTCharmap(face, 3, 0)) {
1118 FX_BOOL bGotOne = FALSE; 1113 FX_BOOL bGotOne = FALSE;
1119 for (int charcode = 0; charcode < 256; charcode++) { 1114 for (int charcode = 0; charcode < 256; charcode++) {
1120 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 1115 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
1121 for (int j = 0; j < 4; j++) { 1116 for (int j = 0; j < 4; j++) {
1122 FX_WORD unicode = prefix[j] * 256 + charcode; 1117 FX_WORD unicode = prefix[j] * 256 + charcode;
1123 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode); 1118 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, unicode);
1124 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1119 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1125 FX_CHAR name_glyph[256]; 1120 FX_CHAR name_glyph[256];
1126 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 1121 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1127 256);
1128 name_glyph[255] = 0; 1122 name_glyph[255] = 0;
1129 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1123 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1130 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1124 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1131 kCFAllocatorNull); 1125 kCFAllocatorNull);
1132 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1126 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1133 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1127 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1134 if (name_ct) { 1128 if (name_ct) {
1135 CFRelease(name_ct); 1129 CFRelease(name_ct);
1136 } 1130 }
1137 #endif 1131 #endif
1138 if (m_GlyphIndex[charcode]) { 1132 if (m_GlyphIndex[charcode]) {
1139 bGotOne = TRUE; 1133 bGotOne = TRUE;
1140 break; 1134 break;
1141 } 1135 }
1142 } 1136 }
1143 } 1137 }
1144 if (bGotOne) { 1138 if (bGotOne) {
1145 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1139 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1146 if (!bCoreText) { 1140 if (!bCoreText) {
1147 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); 1141 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256);
1148 } 1142 }
1149 #endif 1143 #endif
1150 return; 1144 return;
1151 } 1145 }
1152 } 1146 }
1153 FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE); 1147 FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
1154 if (m_BaseEncoding == 0) { 1148 if (m_BaseEncoding == 0) {
1155 m_BaseEncoding = PDFFONT_ENCODING_STANDARD; 1149 m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
1156 } 1150 }
1157 for (int charcode = 0; charcode < 256; charcode++) { 1151 for (int charcode = 0; charcode < 256; charcode++) {
1158 const FX_CHAR* name = 1152 const FX_CHAR* name =
1159 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); 1153 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
1160 if (name == NULL) { 1154 if (name == NULL) {
1161 continue; 1155 continue;
1162 } 1156 }
1163 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1157 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1164 m_GlyphIndex[charcode] = 1158 m_GlyphIndex[charcode] =
1165 FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]); 1159 FXFT_Get_Char_Index(face, m_Encoding.m_Unicodes[charcode]);
1166 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1160 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1167 FX_CHAR name_glyph[256]; 1161 FX_CHAR name_glyph[256];
1168 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 1162 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1169 256);
1170 name_glyph[255] = 0; 1163 name_glyph[255] = 0;
1171 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1164 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1172 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1165 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1173 kCFAllocatorNull); 1166 kCFAllocatorNull);
1174 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1167 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1175 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1168 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1176 if (name_ct) { 1169 if (name_ct) {
1177 CFRelease(name_ct); 1170 CFRelease(name_ct);
1178 } 1171 }
1179 #endif 1172 #endif
1180 if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) { 1173 if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) {
1181 m_Encoding.m_Unicodes[charcode] = 0x20; 1174 m_Encoding.m_Unicodes[charcode] = 0x20;
1182 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, 0x20); 1175 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, 0x20);
1183 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1176 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1184 FX_CHAR name_glyph[256]; 1177 FX_CHAR name_glyph[256];
1185 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 1178 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1186 256);
1187 name_glyph[255] = 0; 1179 name_glyph[255] = 0;
1188 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1180 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1189 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1181 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1190 kCFAllocatorNull); 1182 kCFAllocatorNull);
1191 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1183 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1192 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1184 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1193 if (name_ct) { 1185 if (name_ct) {
1194 CFRelease(name_ct); 1186 CFRelease(name_ct);
1195 } 1187 }
1196 #endif 1188 #endif
1197 } 1189 }
1198 } 1190 }
1199 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1191 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1200 if (!bCoreText) { 1192 if (!bCoreText) {
1201 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); 1193 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256);
1202 } 1194 }
1203 #endif 1195 #endif
1204 return; 1196 return;
1205 } 1197 }
1206 FT_UseType1Charmap(m_Font.m_Face); 1198 FT_UseType1Charmap(face);
1207 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1199 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1208 if (bCoreText) { 1200 if (bCoreText) {
1209 if (m_Flags & PDFFONT_SYMBOLIC) { 1201 if (m_Flags & PDFFONT_SYMBOLIC) {
1210 for (int charcode = 0; charcode < 256; charcode++) { 1202 for (int charcode = 0; charcode < 256; charcode++) {
1211 const FX_CHAR* name = 1203 const FX_CHAR* name =
1212 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); 1204 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
1213 if (name) { 1205 if (name) {
1214 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1206 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1215 m_GlyphIndex[charcode] = 1207 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(face, (char*)name);
1216 FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
1217 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1208 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1218 kCFAllocatorDefault, name, kCFStringEncodingASCII, 1209 kCFAllocatorDefault, name, kCFStringEncodingASCII,
1219 kCFAllocatorNull); 1210 kCFAllocatorNull);
1220 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1211 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1221 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1212 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1222 if (name_ct) { 1213 if (name_ct) {
1223 CFRelease(name_ct); 1214 CFRelease(name_ct);
1224 } 1215 }
1225 } else { 1216 } else {
1226 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode); 1217 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, charcode);
1227 FX_WCHAR unicode = 0; 1218 FX_WCHAR unicode = 0;
1228 if (m_GlyphIndex[charcode]) { 1219 if (m_GlyphIndex[charcode]) {
1229 unicode = 1220 unicode =
1230 FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode); 1221 FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
1231 } 1222 }
1232 FX_CHAR name_glyph[256]; 1223 FX_CHAR name_glyph[256];
1233 FXSYS_memset(name_glyph, 0, sizeof(name_glyph)); 1224 FXSYS_memset(name_glyph, 0, sizeof(name_glyph));
1234 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 1225 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1235 256);
1236 name_glyph[255] = 0; 1226 name_glyph[255] = 0;
1237 if (unicode == 0 && name_glyph[0] != 0) { 1227 if (unicode == 0 && name_glyph[0] != 0) {
1238 unicode = PDF_UnicodeFromAdobeName(name_glyph); 1228 unicode = PDF_UnicodeFromAdobeName(name_glyph);
1239 } 1229 }
1240 m_Encoding.m_Unicodes[charcode] = unicode; 1230 m_Encoding.m_Unicodes[charcode] = unicode;
1241 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1231 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1242 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1232 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1243 kCFAllocatorNull); 1233 kCFAllocatorNull);
1244 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1234 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1245 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1235 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1246 if (name_ct) { 1236 if (name_ct) {
1247 CFRelease(name_ct); 1237 CFRelease(name_ct);
1248 } 1238 }
1249 } 1239 }
1250 } 1240 }
1251 return; 1241 return;
1252 } 1242 }
1253 FX_BOOL bUnicode = FALSE; 1243 FX_BOOL bUnicode = FALSE;
1254 if (0 == FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE)) { 1244 if (0 == FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE)) {
1255 bUnicode = TRUE; 1245 bUnicode = TRUE;
1256 } 1246 }
1257 for (int charcode = 0; charcode < 256; charcode++) { 1247 for (int charcode = 0; charcode < 256; charcode++) {
1258 const FX_CHAR* name = 1248 const FX_CHAR* name =
1259 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); 1249 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
1260 if (name == NULL) { 1250 if (name == NULL) {
1261 continue; 1251 continue;
1262 } 1252 }
1263 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1253 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1264 const FX_CHAR* pStrUnicode = _GlyphNameRemap(name); 1254 const FX_CHAR* pStrUnicode = _GlyphNameRemap(name);
1265 if (pStrUnicode && 0 == FXFT_Get_Name_Index(m_Font.m_Face, (char*)name)) { 1255 if (pStrUnicode && 0 == FXFT_Get_Name_Index(face, (char*)name)) {
1266 name = pStrUnicode; 1256 name = pStrUnicode;
1267 } 1257 }
1268 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name); 1258 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(face, (char*)name);
1269 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1259 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1270 kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull); 1260 kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
1271 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1261 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1272 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1262 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1273 if (name_ct) { 1263 if (name_ct) {
1274 CFRelease(name_ct); 1264 CFRelease(name_ct);
1275 } 1265 }
1276 if (m_GlyphIndex[charcode] == 0) { 1266 if (m_GlyphIndex[charcode] == 0) {
1277 if (FXSYS_strcmp(name, ".notdef") != 0 && 1267 if (FXSYS_strcmp(name, ".notdef") != 0 &&
1278 FXSYS_strcmp(name, "space") != 0) { 1268 FXSYS_strcmp(name, "space") != 0) {
1279 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( 1269 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
1280 m_Font.m_Face, 1270 face, bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
1281 bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
1282 FX_CHAR name_glyph[256]; 1271 FX_CHAR name_glyph[256];
1283 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 1272 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1284 256);
1285 name_glyph[255] = 0; 1273 name_glyph[255] = 0;
1286 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1274 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1287 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1275 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1288 kCFAllocatorNull); 1276 kCFAllocatorNull);
1289 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1277 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1290 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1278 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1291 if (name_ct) { 1279 if (name_ct) {
1292 CFRelease(name_ct); 1280 CFRelease(name_ct);
1293 } 1281 }
1294 } else { 1282 } else {
1295 m_Encoding.m_Unicodes[charcode] = 0x20; 1283 m_Encoding.m_Unicodes[charcode] = 0x20;
1296 m_GlyphIndex[charcode] = 1284 m_GlyphIndex[charcode] =
1297 bUnicode ? FXFT_Get_Char_Index(m_Font.m_Face, 0x20) : 0xffff; 1285 bUnicode ? FXFT_Get_Char_Index(face, 0x20) : 0xffff;
1298 FX_CHAR name_glyph[256]; 1286 FX_CHAR name_glyph[256];
1299 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 1287 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1300 256);
1301 name_glyph[255] = 0; 1288 name_glyph[255] = 0;
1302 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( 1289 CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
1303 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, 1290 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
1304 kCFAllocatorNull); 1291 kCFAllocatorNull);
1305 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( 1292 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
1306 (CGFontRef)m_Font.m_pPlatformFont, name_ct); 1293 (CGFontRef)m_Font.m_pPlatformFont, name_ct);
1307 if (name_ct) { 1294 if (name_ct) {
1308 CFRelease(name_ct); 1295 CFRelease(name_ct);
1309 } 1296 }
1310 } 1297 }
1311 } 1298 }
1312 } 1299 }
1313 return; 1300 return;
1314 } 1301 }
1315 #endif 1302 #endif
1316 if (m_Flags & PDFFONT_SYMBOLIC) { 1303 if (m_Flags & PDFFONT_SYMBOLIC) {
1317 for (int charcode = 0; charcode < 256; charcode++) { 1304 for (int charcode = 0; charcode < 256; charcode++) {
1318 const FX_CHAR* name = 1305 const FX_CHAR* name =
1319 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); 1306 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
1320 if (name) { 1307 if (name) {
1321 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1308 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1322 m_GlyphIndex[charcode] = 1309 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(face, (char*)name);
1323 FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
1324 } else { 1310 } else {
1325 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode); 1311 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, charcode);
1326 if (m_GlyphIndex[charcode]) { 1312 if (m_GlyphIndex[charcode]) {
1327 FX_WCHAR unicode = 1313 FX_WCHAR unicode =
1328 FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode); 1314 FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
1329 if (unicode == 0) { 1315 if (unicode == 0) {
1330 FX_CHAR name_glyph[256]; 1316 FX_CHAR name_glyph[256];
1331 FXSYS_memset(name_glyph, 0, sizeof(name_glyph)); 1317 FXSYS_memset(name_glyph, 0, sizeof(name_glyph));
1332 FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], 1318 FXFT_Get_Glyph_Name(face, m_GlyphIndex[charcode], name_glyph, 256);
1333 name_glyph, 256);
1334 name_glyph[255] = 0; 1319 name_glyph[255] = 0;
1335 if (name_glyph[0] != 0) { 1320 if (name_glyph[0] != 0) {
1336 unicode = PDF_UnicodeFromAdobeName(name_glyph); 1321 unicode = PDF_UnicodeFromAdobeName(name_glyph);
1337 } 1322 }
1338 } 1323 }
1339 m_Encoding.m_Unicodes[charcode] = unicode; 1324 m_Encoding.m_Unicodes[charcode] = unicode;
1340 } 1325 }
1341 } 1326 }
1342 } 1327 }
1343 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1328 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1344 if (!bCoreText) { 1329 if (!bCoreText) {
1345 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); 1330 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256);
1346 } 1331 }
1347 #endif 1332 #endif
1348 return; 1333 return;
1349 } 1334 }
1350 FX_BOOL bUnicode = FALSE; 1335 FX_BOOL bUnicode = FALSE;
1351 if (0 == FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE)) { 1336 if (0 == FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE)) {
1352 bUnicode = TRUE; 1337 bUnicode = TRUE;
1353 } 1338 }
1354 for (int charcode = 0; charcode < 256; charcode++) { 1339 for (int charcode = 0; charcode < 256; charcode++) {
1355 const FX_CHAR* name = 1340 const FX_CHAR* name =
1356 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode); 1341 GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
1357 if (name == NULL) { 1342 if (name == NULL) {
1358 continue; 1343 continue;
1359 } 1344 }
1360 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1345 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1361 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name); 1346 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(face, (char*)name);
1362 if (m_GlyphIndex[charcode] == 0) { 1347 if (m_GlyphIndex[charcode] == 0) {
1363 if (FXSYS_strcmp(name, ".notdef") != 0 && 1348 if (FXSYS_strcmp(name, ".notdef") != 0 &&
1364 FXSYS_strcmp(name, "space") != 0) { 1349 FXSYS_strcmp(name, "space") != 0) {
1365 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( 1350 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
1366 m_Font.m_Face, 1351 face, bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
1367 bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
1368 } else { 1352 } else {
1369 m_Encoding.m_Unicodes[charcode] = 0x20; 1353 m_Encoding.m_Unicodes[charcode] = 0x20;
1370 m_GlyphIndex[charcode] = 0xffff; 1354 m_GlyphIndex[charcode] = 0xffff;
1371 } 1355 }
1372 } 1356 }
1373 } 1357 }
1374 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1358 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
1375 if (!bCoreText) { 1359 if (!bCoreText) {
1376 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); 1360 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256);
1377 } 1361 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); 1426 pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i])));
1443 } 1427 }
1444 pDict->SetAt(FX_BSTRC("Differences"), pDiff); 1428 pDict->SetAt(FX_BSTRC("Differences"), pDiff);
1445 return pDict; 1429 return pDict;
1446 } 1430 }
1447 CPDF_TrueTypeFont::CPDF_TrueTypeFont() : CPDF_SimpleFont(PDFFONT_TRUETYPE) {} 1431 CPDF_TrueTypeFont::CPDF_TrueTypeFont() : CPDF_SimpleFont(PDFFONT_TRUETYPE) {}
1448 FX_BOOL CPDF_TrueTypeFont::_Load() { 1432 FX_BOOL CPDF_TrueTypeFont::_Load() {
1449 return LoadCommon(); 1433 return LoadCommon();
1450 } 1434 }
1451 void CPDF_TrueTypeFont::LoadGlyphMap() { 1435 void CPDF_TrueTypeFont::LoadGlyphMap() {
1452 if (m_Font.m_Face == NULL) { 1436 FXFT_Face face = m_Font.GetFace();
Tom Sepez 2015/08/17 18:38:01 ditto
Lei Zhang 2015/08/18 06:10:53 ditto ditto
1437 if (!face)
1453 return; 1438 return;
1454 } 1439
1455 int baseEncoding = m_BaseEncoding; 1440 int baseEncoding = m_BaseEncoding;
1456 if (m_pFontFile && m_Font.m_Face->num_charmaps > 0 && 1441 if (m_pFontFile && face->num_charmaps > 0 &&
1457 (baseEncoding == PDFFONT_ENCODING_MACROMAN || 1442 (baseEncoding == PDFFONT_ENCODING_MACROMAN ||
1458 baseEncoding == PDFFONT_ENCODING_WINANSI) && 1443 baseEncoding == PDFFONT_ENCODING_WINANSI) &&
1459 (m_Flags & PDFFONT_SYMBOLIC)) { 1444 (m_Flags & PDFFONT_SYMBOLIC)) {
1460 FX_BOOL bSupportWin = FALSE; 1445 FX_BOOL bSupportWin = FALSE;
1461 FX_BOOL bSupportMac = FALSE; 1446 FX_BOOL bSupportMac = FALSE;
1462 for (int i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.m_Face); i++) { 1447 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
1463 int platform_id = 1448 int platform_id =
1464 FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]); 1449 FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]);
1465 if (platform_id == 0 || platform_id == 3) { 1450 if (platform_id == 0 || platform_id == 3) {
1466 bSupportWin = TRUE; 1451 bSupportWin = TRUE;
1467 } else if (platform_id == 0 || platform_id == 1) { 1452 } else if (platform_id == 0 || platform_id == 1) {
1468 bSupportMac = TRUE; 1453 bSupportMac = TRUE;
1469 } 1454 }
1470 } 1455 }
1471 if (baseEncoding == PDFFONT_ENCODING_WINANSI && !bSupportWin) { 1456 if (baseEncoding == PDFFONT_ENCODING_WINANSI && !bSupportWin) {
1472 baseEncoding = 1457 baseEncoding =
1473 bSupportMac ? PDFFONT_ENCODING_MACROMAN : PDFFONT_ENCODING_BUILTIN; 1458 bSupportMac ? PDFFONT_ENCODING_MACROMAN : PDFFONT_ENCODING_BUILTIN;
1474 } else if (baseEncoding == PDFFONT_ENCODING_MACROMAN && !bSupportMac) { 1459 } else if (baseEncoding == PDFFONT_ENCODING_MACROMAN && !bSupportMac) {
1475 baseEncoding = 1460 baseEncoding =
1476 bSupportWin ? PDFFONT_ENCODING_WINANSI : PDFFONT_ENCODING_BUILTIN; 1461 bSupportWin ? PDFFONT_ENCODING_WINANSI : PDFFONT_ENCODING_BUILTIN;
1477 } 1462 }
1478 } 1463 }
1479 if (((baseEncoding == PDFFONT_ENCODING_MACROMAN || 1464 if (((baseEncoding == PDFFONT_ENCODING_MACROMAN ||
1480 baseEncoding == PDFFONT_ENCODING_WINANSI) && 1465 baseEncoding == PDFFONT_ENCODING_WINANSI) &&
1481 m_pCharNames == NULL) || 1466 m_pCharNames == NULL) ||
1482 (m_Flags & PDFFONT_NONSYMBOLIC)) { 1467 (m_Flags & PDFFONT_NONSYMBOLIC)) {
1483 if (!FXFT_Has_Glyph_Names(m_Font.m_Face) && 1468 if (!FXFT_Has_Glyph_Names(face) &&
1484 (!m_Font.m_Face->num_charmaps || !m_Font.m_Face->charmaps)) { 1469 (!face->num_charmaps || !face->charmaps)) {
1485 int nStartChar = m_pFontDict->GetInteger(FX_BSTRC("FirstChar")); 1470 int nStartChar = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"));
1486 if (nStartChar < 0 || nStartChar > 255) 1471 if (nStartChar < 0 || nStartChar > 255)
1487 return; 1472 return;
1488 1473
1489 int charcode = 0; 1474 int charcode = 0;
1490 for (; charcode < nStartChar; charcode++) { 1475 for (; charcode < nStartChar; charcode++) {
1491 m_GlyphIndex[charcode] = 0; 1476 m_GlyphIndex[charcode] = 0;
1492 } 1477 }
1493 FX_WORD nGlyph = charcode - nStartChar + 3; 1478 FX_WORD nGlyph = charcode - nStartChar + 3;
1494 for (; charcode < 256; charcode++, nGlyph++) { 1479 for (; charcode < 256; charcode++, nGlyph++) {
1495 m_GlyphIndex[charcode] = nGlyph; 1480 m_GlyphIndex[charcode] = nGlyph;
1496 } 1481 }
1497 return; 1482 return;
1498 } 1483 }
1499 FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1); 1484 FX_BOOL bMSUnicode = FT_UseTTCharmap(face, 3, 1);
1500 FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE; 1485 FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE;
1501 if (!bMSUnicode) { 1486 if (!bMSUnicode) {
1502 if (m_Flags & PDFFONT_NONSYMBOLIC) { 1487 if (m_Flags & PDFFONT_NONSYMBOLIC) {
1503 bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0); 1488 bMacRoman = FT_UseTTCharmap(face, 1, 0);
1504 bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.m_Face, 3, 0); 1489 bMSSymbol = !bMacRoman && FT_UseTTCharmap(face, 3, 0);
1505 } else { 1490 } else {
1506 bMSSymbol = FT_UseTTCharmap(m_Font.m_Face, 3, 0); 1491 bMSSymbol = FT_UseTTCharmap(face, 3, 0);
1507 bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.m_Face, 1, 0); 1492 bMacRoman = !bMSSymbol && FT_UseTTCharmap(face, 1, 0);
1508 } 1493 }
1509 } 1494 }
1510 FX_BOOL bToUnicode = m_pFontDict->KeyExist(FX_BSTRC("ToUnicode")); 1495 FX_BOOL bToUnicode = m_pFontDict->KeyExist(FX_BSTRC("ToUnicode"));
1511 for (int charcode = 0; charcode < 256; charcode++) { 1496 for (int charcode = 0; charcode < 256; charcode++) {
1512 const FX_CHAR* name = 1497 const FX_CHAR* name =
1513 GetAdobeCharName(baseEncoding, m_pCharNames, charcode); 1498 GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
1514 if (name == NULL) { 1499 if (name == NULL) {
1515 m_GlyphIndex[charcode] = 1500 m_GlyphIndex[charcode] =
1516 m_pFontFile ? FXFT_Get_Char_Index(m_Font.m_Face, charcode) : -1; 1501 m_pFontFile ? FXFT_Get_Char_Index(face, charcode) : -1;
1517 continue; 1502 continue;
1518 } 1503 }
1519 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1504 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1520 if (bMSSymbol) { 1505 if (bMSSymbol) {
1521 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 1506 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
1522 for (int j = 0; j < 4; j++) { 1507 for (int j = 0; j < 4; j++) {
1523 FX_WORD unicode = prefix[j] * 256 + charcode; 1508 FX_WORD unicode = prefix[j] * 256 + charcode;
1524 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode); 1509 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, unicode);
1525 if (m_GlyphIndex[charcode]) { 1510 if (m_GlyphIndex[charcode]) {
1526 break; 1511 break;
1527 } 1512 }
1528 } 1513 }
1529 } else if (m_Encoding.m_Unicodes[charcode]) { 1514 } else if (m_Encoding.m_Unicodes[charcode]) {
1530 if (bMSUnicode) { 1515 if (bMSUnicode) {
1531 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( 1516 m_GlyphIndex[charcode] =
1532 m_Font.m_Face, m_Encoding.m_Unicodes[charcode]); 1517 FXFT_Get_Char_Index(face, m_Encoding.m_Unicodes[charcode]);
1533 } else if (bMacRoman) { 1518 } else if (bMacRoman) {
1534 FX_DWORD maccode = FT_CharCodeFromUnicode( 1519 FX_DWORD maccode = FT_CharCodeFromUnicode(
1535 FXFT_ENCODING_APPLE_ROMAN, m_Encoding.m_Unicodes[charcode]); 1520 FXFT_ENCODING_APPLE_ROMAN, m_Encoding.m_Unicodes[charcode]);
1536 if (!maccode) { 1521 if (!maccode) {
1537 m_GlyphIndex[charcode] = 1522 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(face, (char*)name);
1538 FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
1539 } else { 1523 } else {
1540 m_GlyphIndex[charcode] = 1524 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, maccode);
1541 FXFT_Get_Char_Index(m_Font.m_Face, maccode);
1542 } 1525 }
1543 } 1526 }
1544 } 1527 }
1545 if ((m_GlyphIndex[charcode] == 0 || m_GlyphIndex[charcode] == 0xffff) && 1528 if ((m_GlyphIndex[charcode] == 0 || m_GlyphIndex[charcode] == 0xffff) &&
1546 name != NULL) { 1529 name != NULL) {
1547 if (name[0] == '.' && FXSYS_strcmp(name, ".notdef") == 0) { 1530 if (name[0] == '.' && FXSYS_strcmp(name, ".notdef") == 0) {
1548 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, 32); 1531 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, 32);
1549 } else { 1532 } else {
1550 m_GlyphIndex[charcode] = 1533 m_GlyphIndex[charcode] = FXFT_Get_Name_Index(face, (char*)name);
1551 FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
1552 if (m_GlyphIndex[charcode] == 0) { 1534 if (m_GlyphIndex[charcode] == 0) {
1553 if (bToUnicode) { 1535 if (bToUnicode) {
1554 CFX_WideString wsUnicode = UnicodeFromCharCode(charcode); 1536 CFX_WideString wsUnicode = UnicodeFromCharCode(charcode);
1555 if (!wsUnicode.IsEmpty()) { 1537 if (!wsUnicode.IsEmpty()) {
1556 m_GlyphIndex[charcode] = 1538 m_GlyphIndex[charcode] =
1557 FXFT_Get_Char_Index(m_Font.m_Face, wsUnicode[0]); 1539 FXFT_Get_Char_Index(face, wsUnicode[0]);
1558 m_Encoding.m_Unicodes[charcode] = wsUnicode[0]; 1540 m_Encoding.m_Unicodes[charcode] = wsUnicode[0];
1559 } 1541 }
1560 } 1542 }
1561 if (m_GlyphIndex[charcode] == 0) { 1543 if (m_GlyphIndex[charcode] == 0) {
1562 m_GlyphIndex[charcode] = 1544 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, charcode);
1563 FXFT_Get_Char_Index(m_Font.m_Face, charcode);
1564 } 1545 }
1565 } 1546 }
1566 } 1547 }
1567 } 1548 }
1568 } 1549 }
1569 return; 1550 return;
1570 } 1551 }
1571 if (FT_UseTTCharmap(m_Font.m_Face, 3, 0)) { 1552 if (FT_UseTTCharmap(face, 3, 0)) {
1572 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; 1553 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
1573 FX_BOOL bGotOne = FALSE; 1554 FX_BOOL bGotOne = FALSE;
1574 for (int charcode = 0; charcode < 256; charcode++) { 1555 for (int charcode = 0; charcode < 256; charcode++) {
1575 for (int j = 0; j < 4; j++) { 1556 for (int j = 0; j < 4; j++) {
1576 FX_WORD unicode = prefix[j] * 256 + charcode; 1557 FX_WORD unicode = prefix[j] * 256 + charcode;
1577 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode); 1558 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, unicode);
1578 if (m_GlyphIndex[charcode]) { 1559 if (m_GlyphIndex[charcode]) {
1579 bGotOne = TRUE; 1560 bGotOne = TRUE;
1580 break; 1561 break;
1581 } 1562 }
1582 } 1563 }
1583 } 1564 }
1584 if (bGotOne) { 1565 if (bGotOne) {
1585 if (baseEncoding != PDFFONT_ENCODING_BUILTIN) { 1566 if (baseEncoding != PDFFONT_ENCODING_BUILTIN) {
1586 for (int charcode = 0; charcode < 256; charcode++) { 1567 for (int charcode = 0; charcode < 256; charcode++) {
1587 const FX_CHAR* name = 1568 const FX_CHAR* name =
1588 GetAdobeCharName(baseEncoding, m_pCharNames, charcode); 1569 GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
1589 if (name == NULL) { 1570 if (name == NULL) {
1590 continue; 1571 continue;
1591 } 1572 }
1592 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1573 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1593 } 1574 }
1594 } else if (FT_UseTTCharmap(m_Font.m_Face, 1, 0)) { 1575 } else if (FT_UseTTCharmap(face, 1, 0)) {
1595 for (int charcode = 0; charcode < 256; charcode++) { 1576 for (int charcode = 0; charcode < 256; charcode++) {
1596 m_Encoding.m_Unicodes[charcode] = 1577 m_Encoding.m_Unicodes[charcode] =
1597 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode); 1578 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
1598 } 1579 }
1599 } 1580 }
1600 return; 1581 return;
1601 } 1582 }
1602 } 1583 }
1603 if (FT_UseTTCharmap(m_Font.m_Face, 1, 0)) { 1584 if (FT_UseTTCharmap(face, 1, 0)) {
1604 FX_BOOL bGotOne = FALSE; 1585 FX_BOOL bGotOne = FALSE;
1605 for (int charcode = 0; charcode < 256; charcode++) { 1586 for (int charcode = 0; charcode < 256; charcode++) {
1606 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode); 1587 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(face, charcode);
1607 m_Encoding.m_Unicodes[charcode] = 1588 m_Encoding.m_Unicodes[charcode] =
1608 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode); 1589 FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
1609 if (m_GlyphIndex[charcode]) { 1590 if (m_GlyphIndex[charcode]) {
1610 bGotOne = TRUE; 1591 bGotOne = TRUE;
1611 } 1592 }
1612 } 1593 }
1613 if (m_pFontFile || bGotOne) { 1594 if (m_pFontFile || bGotOne) {
1614 return; 1595 return;
1615 } 1596 }
1616 } 1597 }
1617 if (FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE) == 0) { 1598 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) {
1618 FX_BOOL bGotOne = FALSE; 1599 FX_BOOL bGotOne = FALSE;
1619 const FX_WORD* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding); 1600 const FX_WORD* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding);
1620 for (int charcode = 0; charcode < 256; charcode++) { 1601 for (int charcode = 0; charcode < 256; charcode++) {
1621 if (m_pFontFile == NULL) { 1602 if (m_pFontFile == NULL) {
1622 const FX_CHAR* name = GetAdobeCharName(0, m_pCharNames, charcode); 1603 const FX_CHAR* name = GetAdobeCharName(0, m_pCharNames, charcode);
1623 if (name != NULL) { 1604 if (name != NULL) {
1624 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); 1605 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
1625 } else if (pUnicodes) { 1606 } else if (pUnicodes) {
1626 m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode]; 1607 m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode];
1627 } 1608 }
1628 } else { 1609 } else {
1629 m_Encoding.m_Unicodes[charcode] = charcode; 1610 m_Encoding.m_Unicodes[charcode] = charcode;
1630 } 1611 }
1631 m_GlyphIndex[charcode] = 1612 m_GlyphIndex[charcode] =
1632 FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]); 1613 FXFT_Get_Char_Index(face, m_Encoding.m_Unicodes[charcode]);
1633 if (m_GlyphIndex[charcode]) { 1614 if (m_GlyphIndex[charcode]) {
1634 bGotOne = TRUE; 1615 bGotOne = TRUE;
1635 } 1616 }
1636 } 1617 }
1637 if (bGotOne) { 1618 if (bGotOne) {
1638 return; 1619 return;
1639 } 1620 }
1640 } 1621 }
1641 for (int charcode = 0; charcode < 256; charcode++) { 1622 for (int charcode = 0; charcode < 256; charcode++) {
1642 m_GlyphIndex[charcode] = charcode; 1623 m_GlyphIndex[charcode] = charcode;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 CPDF_Type3Char::CPDF_Type3Char() { 1767 CPDF_Type3Char::CPDF_Type3Char() {
1787 m_pForm = NULL; 1768 m_pForm = NULL;
1788 m_pBitmap = NULL; 1769 m_pBitmap = NULL;
1789 m_bPageRequired = FALSE; 1770 m_bPageRequired = FALSE;
1790 m_bColored = FALSE; 1771 m_bColored = FALSE;
1791 } 1772 }
1792 CPDF_Type3Char::~CPDF_Type3Char() { 1773 CPDF_Type3Char::~CPDF_Type3Char() {
1793 delete m_pForm; 1774 delete m_pForm;
1794 delete m_pBitmap; 1775 delete m_pBitmap;
1795 } 1776 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698