| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/font/cpdf_type1font.h" | 7 #include "core/fpdfapi/font/cpdf_type1font.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/font/font_int.h" | 9 #include "core/fpdfapi/font/font_int.h" |
| 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) { | 133 if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) { |
| 134 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) { | 134 if (FT_UseTTCharmap(m_Font.GetFace(), 3, 0)) { |
| 135 bool bGotOne = false; | 135 bool bGotOne = false; |
| 136 for (int charcode = 0; charcode < 256; charcode++) { | 136 for (int charcode = 0; charcode < 256; charcode++) { |
| 137 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; | 137 const uint8_t prefix[4] = {0x00, 0xf0, 0xf1, 0xf2}; |
| 138 for (int j = 0; j < 4; j++) { | 138 for (int j = 0; j < 4; j++) { |
| 139 uint16_t unicode = prefix[j] * 256 + charcode; | 139 uint16_t unicode = prefix[j] * 256 + charcode; |
| 140 m_GlyphIndex[charcode] = | 140 m_GlyphIndex[charcode] = |
| 141 FXFT_Get_Char_Index(m_Font.GetFace(), unicode); | 141 FXFT_Get_Char_Index(m_Font.GetFace(), unicode); |
| 142 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 142 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 143 FX_CHAR name_glyph[256]; | 143 CalcExtGID(charcode); |
| 144 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], | |
| 145 name_glyph, 256); | |
| 146 name_glyph[255] = 0; | |
| 147 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | |
| 148 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, | |
| 149 kCFAllocatorNull); | |
| 150 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 151 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 152 if (name_ct) { | |
| 153 CFRelease(name_ct); | |
| 154 } | |
| 155 #endif | 144 #endif |
| 156 if (m_GlyphIndex[charcode]) { | 145 if (m_GlyphIndex[charcode]) { |
| 157 bGotOne = true; | 146 bGotOne = true; |
| 158 break; | 147 break; |
| 159 } | 148 } |
| 160 } | 149 } |
| 161 } | 150 } |
| 162 if (bGotOne) { | 151 if (bGotOne) { |
| 163 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 152 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 164 if (!bCoreText) | 153 if (!bCoreText) |
| 165 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); | 154 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); |
| 166 #endif | 155 #endif |
| 167 return; | 156 return; |
| 168 } | 157 } |
| 169 } | 158 } |
| 170 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); | 159 FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE); |
| 171 if (m_BaseEncoding == 0) { | 160 if (m_BaseEncoding == 0) { |
| 172 m_BaseEncoding = PDFFONT_ENCODING_STANDARD; | 161 m_BaseEncoding = PDFFONT_ENCODING_STANDARD; |
| 173 } | 162 } |
| 174 for (int charcode = 0; charcode < 256; charcode++) { | 163 for (int charcode = 0; charcode < 256; charcode++) { |
| 175 const FX_CHAR* name = | 164 const FX_CHAR* name = |
| 176 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); | 165 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); |
| 177 if (!name) | 166 if (!name) |
| 178 continue; | 167 continue; |
| 179 | 168 |
| 180 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); | 169 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); |
| 181 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( | 170 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( |
| 182 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]); | 171 m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]); |
| 183 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 172 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 184 FX_CHAR name_glyph[256]; | 173 CalcExtGID(charcode); |
| 185 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], name_glyph, | |
| 186 256); | |
| 187 name_glyph[255] = 0; | |
| 188 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | |
| 189 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, | |
| 190 kCFAllocatorNull); | |
| 191 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 192 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 193 if (name_ct) { | |
| 194 CFRelease(name_ct); | |
| 195 } | |
| 196 #endif | 174 #endif |
| 197 if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) { | 175 if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) { |
| 198 m_Encoding.m_Unicodes[charcode] = 0x20; | 176 m_Encoding.m_Unicodes[charcode] = 0x20; |
| 199 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), 0x20); | 177 m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), 0x20); |
| 200 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 178 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 201 FX_CHAR name_glyph[256]; | 179 CalcExtGID(charcode); |
| 202 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], | |
| 203 name_glyph, 256); | |
| 204 name_glyph[255] = 0; | |
| 205 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | |
| 206 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, | |
| 207 kCFAllocatorNull); | |
| 208 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 209 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 210 if (name_ct) { | |
| 211 CFRelease(name_ct); | |
| 212 } | |
| 213 #endif | 180 #endif |
| 214 } | 181 } |
| 215 } | 182 } |
| 216 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 183 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 217 if (!bCoreText) | 184 if (!bCoreText) |
| 218 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); | 185 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); |
| 219 #endif | 186 #endif |
| 220 return; | 187 return; |
| 221 } | 188 } |
| 222 FT_UseType1Charmap(m_Font.GetFace()); | 189 FT_UseType1Charmap(m_Font.GetFace()); |
| 223 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 190 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 224 if (bCoreText) { | 191 if (bCoreText) { |
| 225 if (m_Flags & PDFFONT_SYMBOLIC) { | 192 if (m_Flags & PDFFONT_SYMBOLIC) { |
| 226 for (int charcode = 0; charcode < 256; charcode++) { | 193 for (int charcode = 0; charcode < 256; charcode++) { |
| 227 const FX_CHAR* name = | 194 const FX_CHAR* name = |
| 228 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); | 195 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); |
| 229 if (name) { | 196 if (name) { |
| 230 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); | 197 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); |
| 231 m_GlyphIndex[charcode] = | 198 m_GlyphIndex[charcode] = |
| 232 FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); | 199 FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); |
| 233 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | 200 SetExtGID(name, charcode); |
| 234 kCFAllocatorDefault, name, kCFStringEncodingASCII, | |
| 235 kCFAllocatorNull); | |
| 236 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 237 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 238 if (name_ct) { | |
| 239 CFRelease(name_ct); | |
| 240 } | |
| 241 } else { | 201 } else { |
| 242 m_GlyphIndex[charcode] = | 202 m_GlyphIndex[charcode] = |
| 243 FXFT_Get_Char_Index(m_Font.GetFace(), charcode); | 203 FXFT_Get_Char_Index(m_Font.GetFace(), charcode); |
| 244 FX_WCHAR unicode = 0; | 204 FX_WCHAR unicode = 0; |
| 245 if (m_GlyphIndex[charcode]) { | 205 if (m_GlyphIndex[charcode]) { |
| 246 unicode = | 206 unicode = |
| 247 FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode); | 207 FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode); |
| 248 } | 208 } |
| 249 FX_CHAR name_glyph[256]; | 209 FX_CHAR name_glyph[256]; |
| 250 FXSYS_memset(name_glyph, 0, sizeof(name_glyph)); | 210 FXSYS_memset(name_glyph, 0, sizeof(name_glyph)); |
| 251 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], | 211 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], |
| 252 name_glyph, 256); | 212 name_glyph, 256); |
| 253 name_glyph[255] = 0; | 213 name_glyph[255] = 0; |
| 254 if (unicode == 0 && name_glyph[0] != 0) { | 214 if (unicode == 0 && name_glyph[0] != 0) { |
| 255 unicode = PDF_UnicodeFromAdobeName(name_glyph); | 215 unicode = PDF_UnicodeFromAdobeName(name_glyph); |
| 256 } | 216 } |
| 257 m_Encoding.m_Unicodes[charcode] = unicode; | 217 m_Encoding.m_Unicodes[charcode] = unicode; |
| 258 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | 218 SetExtGID(name_glyph, charcode); |
| 259 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, | |
| 260 kCFAllocatorNull); | |
| 261 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 262 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 263 if (name_ct) { | |
| 264 CFRelease(name_ct); | |
| 265 } | |
| 266 } | 219 } |
| 267 } | 220 } |
| 268 return; | 221 return; |
| 269 } | 222 } |
| 270 bool bUnicode = false; | 223 bool bUnicode = false; |
| 271 if (0 == FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE)) { | 224 if (0 == FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE)) { |
| 272 bUnicode = true; | 225 bUnicode = true; |
| 273 } | 226 } |
| 274 for (int charcode = 0; charcode < 256; charcode++) { | 227 for (int charcode = 0; charcode < 256; charcode++) { |
| 275 const FX_CHAR* name = | 228 const FX_CHAR* name = |
| 276 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); | 229 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); |
| 277 if (!name) { | 230 if (!name) { |
| 278 continue; | 231 continue; |
| 279 } | 232 } |
| 280 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); | 233 m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); |
| 281 const FX_CHAR* pStrUnicode = GlyphNameRemap(name); | 234 const FX_CHAR* pStrUnicode = GlyphNameRemap(name); |
| 282 if (pStrUnicode && | 235 if (pStrUnicode && |
| 283 0 == FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name)) { | 236 0 == FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name)) { |
| 284 name = pStrUnicode; | 237 name = pStrUnicode; |
| 285 } | 238 } |
| 286 m_GlyphIndex[charcode] = | 239 m_GlyphIndex[charcode] = |
| 287 FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); | 240 FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); |
| 288 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | 241 SetExtGID(name, charcode); |
| 289 kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull); | |
| 290 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 291 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 292 if (name_ct) { | |
| 293 CFRelease(name_ct); | |
| 294 } | |
| 295 if (m_GlyphIndex[charcode] == 0) { | 242 if (m_GlyphIndex[charcode] == 0) { |
| 296 if (FXSYS_strcmp(name, ".notdef") != 0 && | 243 if (FXSYS_strcmp(name, ".notdef") != 0 && |
| 297 FXSYS_strcmp(name, "space") != 0) { | 244 FXSYS_strcmp(name, "space") != 0) { |
| 298 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( | 245 m_GlyphIndex[charcode] = FXFT_Get_Char_Index( |
| 299 m_Font.GetFace(), | 246 m_Font.GetFace(), |
| 300 bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode); | 247 bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode); |
| 301 FX_CHAR name_glyph[256]; | 248 CalcExtGID(charcode); |
| 302 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], | |
| 303 name_glyph, 256); | |
| 304 name_glyph[255] = 0; | |
| 305 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | |
| 306 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, | |
| 307 kCFAllocatorNull); | |
| 308 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 309 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 310 if (name_ct) { | |
| 311 CFRelease(name_ct); | |
| 312 } | |
| 313 } else { | 249 } else { |
| 314 m_Encoding.m_Unicodes[charcode] = 0x20; | 250 m_Encoding.m_Unicodes[charcode] = 0x20; |
| 315 m_GlyphIndex[charcode] = | 251 m_GlyphIndex[charcode] = |
| 316 bUnicode ? FXFT_Get_Char_Index(m_Font.GetFace(), 0x20) : 0xffff; | 252 bUnicode ? FXFT_Get_Char_Index(m_Font.GetFace(), 0x20) : 0xffff; |
| 317 FX_CHAR name_glyph[256]; | 253 CalcExtGID(charcode); |
| 318 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], | |
| 319 name_glyph, 256); | |
| 320 name_glyph[255] = 0; | |
| 321 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( | |
| 322 kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, | |
| 323 kCFAllocatorNull); | |
| 324 m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName( | |
| 325 (CGFontRef)m_Font.GetPlatformFont(), name_ct); | |
| 326 if (name_ct) { | |
| 327 CFRelease(name_ct); | |
| 328 } | |
| 329 } | 254 } |
| 330 } | 255 } |
| 331 } | 256 } |
| 332 return; | 257 return; |
| 333 } | 258 } |
| 334 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 259 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 335 if (m_Flags & PDFFONT_SYMBOLIC) { | 260 if (m_Flags & PDFFONT_SYMBOLIC) { |
| 336 for (int charcode = 0; charcode < 256; charcode++) { | 261 for (int charcode = 0; charcode < 256; charcode++) { |
| 337 const FX_CHAR* name = | 262 const FX_CHAR* name = |
| 338 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); | 263 GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 m_Encoding.m_Unicodes[charcode] = 0x20; | 314 m_Encoding.m_Unicodes[charcode] = 0x20; |
| 390 m_GlyphIndex[charcode] = 0xffff; | 315 m_GlyphIndex[charcode] = 0xffff; |
| 391 } | 316 } |
| 392 } | 317 } |
| 393 } | 318 } |
| 394 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 319 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 395 if (!bCoreText) | 320 if (!bCoreText) |
| 396 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); | 321 FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256); |
| 397 #endif | 322 #endif |
| 398 } | 323 } |
| 324 |
| 325 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 326 void CPDF_Type1Font::SetExtGID(const FX_CHAR* name, int charcode) { |
| 327 CFStringRef name_ct = CFStringCreateWithCStringNoCopy( |
| 328 kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull); |
| 329 m_ExtGID[charcode] = |
| 330 CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.GetPlatformFont(), name_ct); |
| 331 if (name_ct) |
| 332 CFRelease(name_ct); |
| 333 } |
| 334 |
| 335 void CPDF_Type1Font::CalcExtGID(int charcode) { |
| 336 FX_CHAR name_glyph[256]; |
| 337 FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], name_glyph, |
| 338 256); |
| 339 name_glyph[255] = 0; |
| 340 SetExtGID(name_glyph, charcode); |
| 341 } |
| 342 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| OLD | NEW |