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/fpdf_font/include/cpdf_font.h" | 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 uint32_t CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { | 158 uint32_t CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { |
159 if (!m_bToUnicodeLoaded) | 159 if (!m_bToUnicodeLoaded) |
160 LoadUnicodeMap(); | 160 LoadUnicodeMap(); |
161 | 161 |
162 return m_pToUnicodeMap ? m_pToUnicodeMap->ReverseLookup(unicode) : 0; | 162 return m_pToUnicodeMap ? m_pToUnicodeMap->ReverseLookup(unicode) : 0; |
163 } | 163 } |
164 | 164 |
165 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { | 165 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { |
166 m_Flags = pFontDesc->GetIntegerBy("Flags", PDFFONT_NONSYMBOLIC); | 166 m_Flags = pFontDesc->GetIntegerFor("Flags", PDFFONT_NONSYMBOLIC); |
167 int ItalicAngle = 0; | 167 int ItalicAngle = 0; |
168 FX_BOOL bExistItalicAngle = FALSE; | 168 FX_BOOL bExistItalicAngle = FALSE; |
169 if (pFontDesc->KeyExist("ItalicAngle")) { | 169 if (pFontDesc->KeyExist("ItalicAngle")) { |
170 ItalicAngle = pFontDesc->GetIntegerBy("ItalicAngle"); | 170 ItalicAngle = pFontDesc->GetIntegerFor("ItalicAngle"); |
171 bExistItalicAngle = TRUE; | 171 bExistItalicAngle = TRUE; |
172 } | 172 } |
173 if (ItalicAngle < 0) { | 173 if (ItalicAngle < 0) { |
174 m_Flags |= PDFFONT_ITALIC; | 174 m_Flags |= PDFFONT_ITALIC; |
175 m_ItalicAngle = ItalicAngle; | 175 m_ItalicAngle = ItalicAngle; |
176 } | 176 } |
177 FX_BOOL bExistStemV = FALSE; | 177 FX_BOOL bExistStemV = FALSE; |
178 if (pFontDesc->KeyExist("StemV")) { | 178 if (pFontDesc->KeyExist("StemV")) { |
179 m_StemV = pFontDesc->GetIntegerBy("StemV"); | 179 m_StemV = pFontDesc->GetIntegerFor("StemV"); |
180 bExistStemV = TRUE; | 180 bExistStemV = TRUE; |
181 } | 181 } |
182 FX_BOOL bExistAscent = FALSE; | 182 FX_BOOL bExistAscent = FALSE; |
183 if (pFontDesc->KeyExist("Ascent")) { | 183 if (pFontDesc->KeyExist("Ascent")) { |
184 m_Ascent = pFontDesc->GetIntegerBy("Ascent"); | 184 m_Ascent = pFontDesc->GetIntegerFor("Ascent"); |
185 bExistAscent = TRUE; | 185 bExistAscent = TRUE; |
186 } | 186 } |
187 FX_BOOL bExistDescent = FALSE; | 187 FX_BOOL bExistDescent = FALSE; |
188 if (pFontDesc->KeyExist("Descent")) { | 188 if (pFontDesc->KeyExist("Descent")) { |
189 m_Descent = pFontDesc->GetIntegerBy("Descent"); | 189 m_Descent = pFontDesc->GetIntegerFor("Descent"); |
190 bExistDescent = TRUE; | 190 bExistDescent = TRUE; |
191 } | 191 } |
192 FX_BOOL bExistCapHeight = FALSE; | 192 FX_BOOL bExistCapHeight = FALSE; |
193 if (pFontDesc->KeyExist("CapHeight")) { | 193 if (pFontDesc->KeyExist("CapHeight")) { |
194 bExistCapHeight = TRUE; | 194 bExistCapHeight = TRUE; |
195 } | 195 } |
196 if (bExistItalicAngle && bExistAscent && bExistCapHeight && bExistDescent && | 196 if (bExistItalicAngle && bExistAscent && bExistCapHeight && bExistDescent && |
197 bExistStemV) { | 197 bExistStemV) { |
198 m_Flags |= PDFFONT_USEEXTERNATTR; | 198 m_Flags |= PDFFONT_USEEXTERNATTR; |
199 } | 199 } |
200 if (m_Descent > 10) { | 200 if (m_Descent > 10) { |
201 m_Descent = -m_Descent; | 201 m_Descent = -m_Descent; |
202 } | 202 } |
203 CPDF_Array* pBBox = pFontDesc->GetArrayBy("FontBBox"); | 203 CPDF_Array* pBBox = pFontDesc->GetArrayFor("FontBBox"); |
204 if (pBBox) { | 204 if (pBBox) { |
205 m_FontBBox.left = pBBox->GetIntegerAt(0); | 205 m_FontBBox.left = pBBox->GetIntegerAt(0); |
206 m_FontBBox.bottom = pBBox->GetIntegerAt(1); | 206 m_FontBBox.bottom = pBBox->GetIntegerAt(1); |
207 m_FontBBox.right = pBBox->GetIntegerAt(2); | 207 m_FontBBox.right = pBBox->GetIntegerAt(2); |
208 m_FontBBox.top = pBBox->GetIntegerAt(3); | 208 m_FontBBox.top = pBBox->GetIntegerAt(3); |
209 } | 209 } |
210 | 210 |
211 CPDF_Stream* pFontFile = pFontDesc->GetStreamBy("FontFile"); | 211 CPDF_Stream* pFontFile = pFontDesc->GetStreamFor("FontFile"); |
212 if (!pFontFile) | 212 if (!pFontFile) |
213 pFontFile = pFontDesc->GetStreamBy("FontFile2"); | 213 pFontFile = pFontDesc->GetStreamFor("FontFile2"); |
214 if (!pFontFile) | 214 if (!pFontFile) |
215 pFontFile = pFontDesc->GetStreamBy("FontFile3"); | 215 pFontFile = pFontDesc->GetStreamFor("FontFile3"); |
216 if (!pFontFile) | 216 if (!pFontFile) |
217 return; | 217 return; |
218 | 218 |
219 m_pFontFile = m_pDocument->LoadFontFile(pFontFile); | 219 m_pFontFile = m_pDocument->LoadFontFile(pFontFile); |
220 if (!m_pFontFile) | 220 if (!m_pFontFile) |
221 return; | 221 return; |
222 | 222 |
223 const uint8_t* pFontData = m_pFontFile->GetData(); | 223 const uint8_t* pFontData = m_pFontFile->GetData(); |
224 uint32_t dwFontSize = m_pFontFile->GetSize(); | 224 uint32_t dwFontSize = m_pFontFile->GetSize(); |
225 if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) { | 225 if (!m_Font.LoadEmbedded(pFontData, dwFontSize)) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (m_Ascent == 0 && m_Descent == 0) { | 270 if (m_Ascent == 0 && m_Descent == 0) { |
271 FX_RECT rect = GetCharBBox('A'); | 271 FX_RECT rect = GetCharBBox('A'); |
272 m_Ascent = rect.bottom == rect.top ? m_FontBBox.top : rect.top; | 272 m_Ascent = rect.bottom == rect.top ? m_FontBBox.top : rect.top; |
273 rect = GetCharBBox('g'); | 273 rect = GetCharBBox('g'); |
274 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom; | 274 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom; |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 void CPDF_Font::LoadUnicodeMap() const { | 278 void CPDF_Font::LoadUnicodeMap() const { |
279 m_bToUnicodeLoaded = TRUE; | 279 m_bToUnicodeLoaded = TRUE; |
280 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode"); | 280 CPDF_Stream* pStream = m_pFontDict->GetStreamFor("ToUnicode"); |
281 if (!pStream) { | 281 if (!pStream) { |
282 return; | 282 return; |
283 } | 283 } |
284 m_pToUnicodeMap.reset(new CPDF_ToUnicodeMap); | 284 m_pToUnicodeMap.reset(new CPDF_ToUnicodeMap); |
285 m_pToUnicodeMap->Load(pStream); | 285 m_pToUnicodeMap->Load(pStream); |
286 } | 286 } |
287 | 287 |
288 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { | 288 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { |
289 int offset = 0; | 289 int offset = 0; |
290 int width = 0; | 290 int width = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
302 if (font_id < 0) { | 302 if (font_id < 0) { |
303 return nullptr; | 303 return nullptr; |
304 } | 304 } |
305 CPDF_FontGlobals* pFontGlobals = | 305 CPDF_FontGlobals* pFontGlobals = |
306 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); | 306 CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals(); |
307 CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id); | 307 CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id); |
308 if (pFont) { | 308 if (pFont) { |
309 return pFont; | 309 return pFont; |
310 } | 310 } |
311 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 311 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
312 pDict->SetAtName("Type", "Font"); | 312 pDict->SetNameFor("Type", "Font"); |
313 pDict->SetAtName("Subtype", "Type1"); | 313 pDict->SetNameFor("Subtype", "Type1"); |
314 pDict->SetAtName("BaseFont", fontname); | 314 pDict->SetNameFor("BaseFont", fontname); |
315 pDict->SetAtName("Encoding", "WinAnsiEncoding"); | 315 pDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
316 pFont = CPDF_Font::CreateFontF(nullptr, pDict); | 316 pFont = CPDF_Font::CreateFontF(nullptr, pDict); |
317 pFontGlobals->Set(pDoc, font_id, pFont); | 317 pFontGlobals->Set(pDoc, font_id, pFont); |
318 return pFont; | 318 return pFont; |
319 } | 319 } |
320 | 320 |
321 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, | 321 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, |
322 CPDF_Dictionary* pFontDict) { | 322 CPDF_Dictionary* pFontDict) { |
323 CFX_ByteString type = pFontDict->GetStringBy("Subtype"); | 323 CFX_ByteString type = pFontDict->GetStringFor("Subtype"); |
324 std::unique_ptr<CPDF_Font> pFont; | 324 std::unique_ptr<CPDF_Font> pFont; |
325 if (type == "TrueType") { | 325 if (type == "TrueType") { |
326 CFX_ByteString tag = pFontDict->GetStringBy("BaseFont").Left(4); | 326 CFX_ByteString tag = pFontDict->GetStringFor("BaseFont").Left(4); |
327 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) { | 327 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) { |
328 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) { | 328 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) { |
329 CPDF_Dictionary* pFontDesc = pFontDict->GetDictBy("FontDescriptor"); | 329 CPDF_Dictionary* pFontDesc = pFontDict->GetDictFor("FontDescriptor"); |
330 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) | 330 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) |
331 pFont.reset(new CPDF_CIDFont); | 331 pFont.reset(new CPDF_CIDFont); |
332 break; | 332 break; |
333 } | 333 } |
334 } | 334 } |
335 if (!pFont) | 335 if (!pFont) |
336 pFont.reset(new CPDF_TrueTypeFont); | 336 pFont.reset(new CPDF_TrueTypeFont); |
337 } else if (type == "Type3") { | 337 } else if (type == "Type3") { |
338 pFont.reset(new CPDF_Type3Font); | 338 pFont.reset(new CPDF_Type3Font); |
339 } else if (type == "Type0") { | 339 } else if (type == "Type0") { |
340 pFont.reset(new CPDF_CIDFont); | 340 pFont.reset(new CPDF_CIDFont); |
341 } else { | 341 } else { |
342 pFont.reset(new CPDF_Type1Font); | 342 pFont.reset(new CPDF_Type1Font); |
343 } | 343 } |
344 pFont->m_pFontDict = pFontDict; | 344 pFont->m_pFontDict = pFontDict; |
345 pFont->m_pDocument = pDoc; | 345 pFont->m_pDocument = pDoc; |
346 pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont"); | 346 pFont->m_BaseFont = pFontDict->GetStringFor("BaseFont"); |
347 return pFont->Load() ? pFont.release() : nullptr; | 347 return pFont->Load() ? pFont.release() : nullptr; |
348 } | 348 } |
349 | 349 |
350 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, | 350 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, |
351 int nStrLen, | 351 int nStrLen, |
352 int& offset) const { | 352 int& offset) const { |
353 if (offset < 0 || nStrLen < 1) { | 353 if (offset < 0 || nStrLen < 1) { |
354 return 0; | 354 return 0; |
355 } | 355 } |
356 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; | 356 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 GetPredefinedEncoding(bsEncoding, &iBaseEncoding); | 389 GetPredefinedEncoding(bsEncoding, &iBaseEncoding); |
390 return; | 390 return; |
391 } | 391 } |
392 | 392 |
393 CPDF_Dictionary* pDict = pEncoding->AsDictionary(); | 393 CPDF_Dictionary* pDict = pEncoding->AsDictionary(); |
394 if (!pDict) | 394 if (!pDict) |
395 return; | 395 return; |
396 | 396 |
397 if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && | 397 if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && |
398 iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) { | 398 iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) { |
399 CFX_ByteString bsEncoding = pDict->GetStringBy("BaseEncoding"); | 399 CFX_ByteString bsEncoding = pDict->GetStringFor("BaseEncoding"); |
400 if (bsEncoding.Compare("MacExpertEncoding") == 0 && bTrueType) { | 400 if (bsEncoding.Compare("MacExpertEncoding") == 0 && bTrueType) { |
401 bsEncoding = "WinAnsiEncoding"; | 401 bsEncoding = "WinAnsiEncoding"; |
402 } | 402 } |
403 GetPredefinedEncoding(bsEncoding, &iBaseEncoding); | 403 GetPredefinedEncoding(bsEncoding, &iBaseEncoding); |
404 } | 404 } |
405 if ((!bEmbedded || bTrueType) && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) | 405 if ((!bEmbedded || bTrueType) && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) |
406 iBaseEncoding = PDFFONT_ENCODING_STANDARD; | 406 iBaseEncoding = PDFFONT_ENCODING_STANDARD; |
407 | 407 |
408 CPDF_Array* pDiffs = pDict->GetArrayBy("Differences"); | 408 CPDF_Array* pDiffs = pDict->GetArrayFor("Differences"); |
409 if (!pDiffs) | 409 if (!pDiffs) |
410 return; | 410 return; |
411 | 411 |
412 pCharNames->resize(256); | 412 pCharNames->resize(256); |
413 uint32_t cur_code = 0; | 413 uint32_t cur_code = 0; |
414 for (uint32_t i = 0; i < pDiffs->GetCount(); i++) { | 414 for (uint32_t i = 0; i < pDiffs->GetCount(); i++) { |
415 CPDF_Object* pElement = pDiffs->GetDirectObjectAt(i); | 415 CPDF_Object* pElement = pDiffs->GetDirectObjectAt(i); |
416 if (!pElement) | 416 if (!pElement) |
417 continue; | 417 continue; |
418 | 418 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 if (fallbackFont < 0 || | 468 if (fallbackFont < 0 || |
469 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { | 469 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { |
470 return -1; | 470 return -1; |
471 } | 471 } |
472 int glyph = | 472 int glyph = |
473 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); | 473 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); |
474 if (glyph == 0 || glyph == 0xffff) | 474 if (glyph == 0 || glyph == 0xffff) |
475 return -1; | 475 return -1; |
476 return glyph; | 476 return glyph; |
477 } | 477 } |
OLD | NEW |