OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
14 #include "core/fpdfdoc/doc_utils.h" | 14 #include "core/fpdfdoc/doc_utils.h" |
15 #include "core/fpdfdoc/include/fpdf_doc.h" | 15 #include "core/fpdfdoc/include/fpdf_doc.h" |
16 #include "core/fxge/include/fx_font.h" | 16 #include "core/fxge/include/fx_font.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const int FPDFDOC_UTILS_MAXRECURSION = 32; | 20 const int FPDFDOC_UTILS_MAXRECURSION = 32; |
21 | 21 |
22 CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { | 22 CPDF_Object* SearchNumberNode(const CPDF_Dictionary* pNode, int num) { |
23 CPDF_Array* pLimits = pNode->GetArrayBy("Limits"); | 23 CPDF_Array* pLimits = pNode->GetArrayBy("Limits"); |
24 if (pLimits && | 24 if (pLimits && |
25 (num < pLimits->GetIntegerAt(0) || num > pLimits->GetIntegerAt(1))) { | 25 (num < pLimits->GetIntegerAt(0) || num > pLimits->GetIntegerAt(1))) { |
26 return NULL; | 26 return nullptr; |
27 } | 27 } |
28 CPDF_Array* pNumbers = pNode->GetArrayBy("Nums"); | 28 CPDF_Array* pNumbers = pNode->GetArrayBy("Nums"); |
29 if (pNumbers) { | 29 if (pNumbers) { |
30 for (size_t i = 0; i < pNumbers->GetCount() / 2; i++) { | 30 for (size_t i = 0; i < pNumbers->GetCount() / 2; i++) { |
31 int index = pNumbers->GetIntegerAt(i * 2); | 31 int index = pNumbers->GetIntegerAt(i * 2); |
32 if (num == index) { | 32 if (num == index) { |
33 return pNumbers->GetDirectObjectAt(i * 2 + 1); | 33 return pNumbers->GetDirectObjectAt(i * 2 + 1); |
34 } | 34 } |
35 if (index > num) { | 35 if (index > num) { |
36 break; | 36 break; |
37 } | 37 } |
38 } | 38 } |
39 return NULL; | 39 return nullptr; |
40 } | 40 } |
41 CPDF_Array* pKids = pNode->GetArrayBy("Kids"); | 41 CPDF_Array* pKids = pNode->GetArrayBy("Kids"); |
42 if (!pKids) { | 42 if (!pKids) { |
43 return NULL; | 43 return nullptr; |
44 } | 44 } |
45 for (size_t i = 0; i < pKids->GetCount(); i++) { | 45 for (size_t i = 0; i < pKids->GetCount(); i++) { |
46 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 46 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
47 if (!pKid) { | 47 if (!pKid) { |
48 continue; | 48 continue; |
49 } | 49 } |
50 CPDF_Object* pFound = SearchNumberNode(pKid, num); | 50 CPDF_Object* pFound = SearchNumberNode(pKid, num); |
51 if (pFound) { | 51 if (pFound) { |
52 return pFound; | 52 return pFound; |
53 } | 53 } |
54 } | 54 } |
55 return NULL; | 55 return nullptr; |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 CPDF_Object* CPDF_NumberTree::LookupValue(int num) const { | 60 CPDF_Object* CPDF_NumberTree::LookupValue(int num) const { |
61 return SearchNumberNode(m_pRoot, num); | 61 return SearchNumberNode(m_pRoot, num); |
62 } | 62 } |
63 | 63 |
64 CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict) { | 64 CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict) { |
65 CFX_WideString full_name; | 65 CFX_WideString full_name; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 return; | 272 return; |
273 } | 273 } |
274 if (!pFormDict) { | 274 if (!pFormDict) { |
275 pFormDict = new CPDF_Dictionary; | 275 pFormDict = new CPDF_Dictionary; |
276 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); | 276 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); |
277 CPDF_Dictionary* pRoot = pDocument->GetRoot(); | 277 CPDF_Dictionary* pRoot = pDocument->GetRoot(); |
278 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); | 278 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); |
279 } | 279 } |
280 CFX_ByteString csDA; | 280 CFX_ByteString csDA; |
281 if (!pFormDict->KeyExist("DR")) { | 281 if (!pFormDict->KeyExist("DR")) { |
282 CPDF_Font* pFont = NULL; | 282 CFX_ByteString csBaseName; |
283 CFX_ByteString csBaseName, csDefault; | 283 CFX_ByteString csDefault; |
284 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 284 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
285 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); | 285 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); |
286 if (pFont) { | 286 if (pFont) { |
287 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 287 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
288 csDefault = csBaseName; | 288 csDefault = csBaseName; |
289 } | 289 } |
290 if (charSet != 0) { | 290 if (charSet != 0) { |
291 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL); | 291 CFX_ByteString csFontName = |
| 292 CPDF_InterForm::GetNativeFont(charSet, nullptr); |
292 if (!pFont || csFontName != "Helvetica") { | 293 if (!pFont || csFontName != "Helvetica") { |
293 pFont = CPDF_InterForm::AddNativeFont(pDocument); | 294 pFont = CPDF_InterForm::AddNativeFont(pDocument); |
294 if (pFont) { | 295 if (pFont) { |
295 csBaseName = ""; | 296 csBaseName = ""; |
296 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 297 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
297 csDefault = csBaseName; | 298 csDefault = csBaseName; |
298 } | 299 } |
299 } | 300 } |
300 } | 301 } |
301 if (pFont) { | 302 if (pFont) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 335 } |
335 } | 336 } |
336 } | 337 } |
337 return dwCount; | 338 return dwCount; |
338 } | 339 } |
339 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, | 340 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
340 CPDF_Document* pDocument, | 341 CPDF_Document* pDocument, |
341 uint32_t index, | 342 uint32_t index, |
342 CFX_ByteString& csNameTag) { | 343 CFX_ByteString& csNameTag) { |
343 if (!pFormDict) { | 344 if (!pFormDict) { |
344 return NULL; | 345 return nullptr; |
345 } | 346 } |
346 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 347 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); |
347 if (!pDR) { | 348 if (!pDR) { |
348 return NULL; | 349 return nullptr; |
349 } | 350 } |
350 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 351 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); |
351 if (!pFonts) { | 352 if (!pFonts) { |
352 return NULL; | 353 return nullptr; |
353 } | 354 } |
354 uint32_t dwCount = 0; | 355 uint32_t dwCount = 0; |
355 for (const auto& it : *pFonts) { | 356 for (const auto& it : *pFonts) { |
356 const CFX_ByteString& csKey = it.first; | 357 const CFX_ByteString& csKey = it.first; |
357 CPDF_Object* pObj = it.second; | 358 CPDF_Object* pObj = it.second; |
358 if (!pObj) { | 359 if (!pObj) { |
359 continue; | 360 continue; |
360 } | 361 } |
361 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 362 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
362 if (!pElement) | 363 if (!pElement) |
363 continue; | 364 continue; |
364 if (pElement->GetStringBy("Type") != "Font") | 365 if (pElement->GetStringBy("Type") != "Font") |
365 continue; | 366 continue; |
366 if (dwCount == index) { | 367 if (dwCount == index) { |
367 csNameTag = csKey; | 368 csNameTag = csKey; |
368 return pDocument->LoadFont(pElement); | 369 return pDocument->LoadFont(pElement); |
369 } | 370 } |
370 dwCount++; | 371 dwCount++; |
371 } | 372 } |
372 return NULL; | 373 return nullptr; |
373 } | 374 } |
374 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, | 375 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
375 CPDF_Document* pDocument, | 376 CPDF_Document* pDocument, |
376 CFX_ByteString csNameTag) { | 377 CFX_ByteString csNameTag) { |
377 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); | 378 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); |
378 if (!pFormDict || csAlias.IsEmpty()) { | 379 if (!pFormDict || csAlias.IsEmpty()) { |
379 return NULL; | 380 return nullptr; |
380 } | 381 } |
381 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 382 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); |
382 if (!pDR) { | 383 if (!pDR) { |
383 return NULL; | 384 return nullptr; |
384 } | 385 } |
385 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 386 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); |
386 if (!pFonts) { | 387 if (!pFonts) { |
387 return NULL; | 388 return nullptr; |
388 } | 389 } |
389 CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias); | 390 CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias); |
390 if (!pElement) { | 391 if (!pElement) { |
391 return NULL; | 392 return nullptr; |
392 } | 393 } |
393 if (pElement->GetStringBy("Type") == "Font") { | 394 if (pElement->GetStringBy("Type") == "Font") { |
394 return pDocument->LoadFont(pElement); | 395 return pDocument->LoadFont(pElement); |
395 } | 396 } |
396 return NULL; | 397 return nullptr; |
397 } | 398 } |
398 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, | 399 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
399 CPDF_Document* pDocument, | 400 CPDF_Document* pDocument, |
400 CFX_ByteString csFontName, | 401 CFX_ByteString csFontName, |
401 CFX_ByteString& csNameTag) { | 402 CFX_ByteString& csNameTag) { |
402 if (!pFormDict || csFontName.IsEmpty()) { | 403 if (!pFormDict || csFontName.IsEmpty()) { |
403 return NULL; | 404 return nullptr; |
404 } | 405 } |
405 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 406 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); |
406 if (!pDR) { | 407 if (!pDR) { |
407 return NULL; | 408 return nullptr; |
408 } | 409 } |
409 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 410 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); |
410 if (!pFonts) { | 411 if (!pFonts) { |
411 return NULL; | 412 return nullptr; |
412 } | 413 } |
413 for (const auto& it : *pFonts) { | 414 for (const auto& it : *pFonts) { |
414 const CFX_ByteString& csKey = it.first; | 415 const CFX_ByteString& csKey = it.first; |
415 CPDF_Object* pObj = it.second; | 416 CPDF_Object* pObj = it.second; |
416 if (!pObj) { | 417 if (!pObj) { |
417 continue; | 418 continue; |
418 } | 419 } |
419 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 420 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
420 if (!pElement) | 421 if (!pElement) |
421 continue; | 422 continue; |
422 if (pElement->GetStringBy("Type") != "Font") | 423 if (pElement->GetStringBy("Type") != "Font") |
423 continue; | 424 continue; |
424 | 425 |
425 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 426 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
426 if (!pFind) | 427 if (!pFind) |
427 continue; | 428 continue; |
428 | 429 |
429 CFX_ByteString csBaseFont; | 430 CFX_ByteString csBaseFont; |
430 csBaseFont = pFind->GetBaseFont(); | 431 csBaseFont = pFind->GetBaseFont(); |
431 csBaseFont.Remove(' '); | 432 csBaseFont.Remove(' '); |
432 if (csBaseFont == csFontName) { | 433 if (csBaseFont == csFontName) { |
433 csNameTag = csKey; | 434 csNameTag = csKey; |
434 return pFind; | 435 return pFind; |
435 } | 436 } |
436 } | 437 } |
437 return NULL; | 438 return nullptr; |
438 } | 439 } |
439 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, | 440 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, |
440 CPDF_Document* pDocument, | 441 CPDF_Document* pDocument, |
441 uint8_t charSet, | 442 uint8_t charSet, |
442 CFX_ByteString& csNameTag) { | 443 CFX_ByteString& csNameTag) { |
443 if (!pFormDict) { | 444 if (!pFormDict) { |
444 return NULL; | 445 return nullptr; |
445 } | 446 } |
446 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); | 447 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); |
447 if (!pDR) { | 448 if (!pDR) { |
448 return NULL; | 449 return nullptr; |
449 } | 450 } |
450 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 451 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); |
451 if (!pFonts) { | 452 if (!pFonts) { |
452 return NULL; | 453 return nullptr; |
453 } | 454 } |
454 for (const auto& it : *pFonts) { | 455 for (const auto& it : *pFonts) { |
455 const CFX_ByteString& csKey = it.first; | 456 const CFX_ByteString& csKey = it.first; |
456 CPDF_Object* pObj = it.second; | 457 CPDF_Object* pObj = it.second; |
457 if (!pObj) { | 458 if (!pObj) { |
458 continue; | 459 continue; |
459 } | 460 } |
460 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 461 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
461 if (!pElement) | 462 if (!pElement) |
462 continue; | 463 continue; |
463 if (pElement->GetStringBy("Type") != "Font") | 464 if (pElement->GetStringBy("Type") != "Font") |
464 continue; | 465 continue; |
465 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 466 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
466 if (!pFind) { | 467 if (!pFind) { |
467 continue; | 468 continue; |
468 } | 469 } |
469 CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); | 470 CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); |
470 if (!pSubst) { | 471 if (!pSubst) { |
471 continue; | 472 continue; |
472 } | 473 } |
473 if (pSubst->m_Charset == (int)charSet) { | 474 if (pSubst->m_Charset == (int)charSet) { |
474 csNameTag = csKey; | 475 csNameTag = csKey; |
475 return pFind; | 476 return pFind; |
476 } | 477 } |
477 } | 478 } |
478 return NULL; | 479 return nullptr; |
479 } | 480 } |
480 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, | 481 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, |
481 CPDF_Document* pDocument, | 482 CPDF_Document* pDocument, |
482 CFX_ByteString& csNameTag) { | 483 CFX_ByteString& csNameTag) { |
483 csNameTag = ""; | 484 csNameTag = ""; |
484 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 485 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
485 CFX_SubstFont* pSubst; | 486 CFX_SubstFont* pSubst; |
486 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); | 487 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); |
487 if (pFont) { | 488 if (pFont) { |
488 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); | 489 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); | 663 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); |
663 if (!pFonts) { | 664 if (!pFonts) { |
664 return; | 665 return; |
665 } | 666 } |
666 pFonts->RemoveAt(csNameTag); | 667 pFonts->RemoveAt(csNameTag); |
667 } | 668 } |
668 | 669 |
669 CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, | 670 CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, |
670 CPDF_Document* pDocument) { | 671 CPDF_Document* pDocument) { |
671 if (!pFormDict) { | 672 if (!pFormDict) { |
672 return NULL; | 673 return nullptr; |
673 } | 674 } |
674 CPDF_DefaultAppearance cDA(pFormDict->GetStringBy("DA")); | 675 CPDF_DefaultAppearance cDA(pFormDict->GetStringBy("DA")); |
675 CFX_ByteString csFontNameTag; | 676 CFX_ByteString csFontNameTag; |
676 FX_FLOAT fFontSize; | 677 FX_FLOAT fFontSize; |
677 cDA.GetFont(csFontNameTag, fFontSize); | 678 cDA.GetFont(csFontNameTag, fFontSize); |
678 return GetInterFormFont(pFormDict, pDocument, csFontNameTag); | 679 return GetInterFormFont(pFormDict, pDocument, csFontNameTag); |
679 } | 680 } |
680 | 681 |
681 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() { | 682 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() { |
682 if (!m_pDict) { | 683 if (!m_pDict) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 if (CPDF_FormControl* pControl = pField->GetControl(i)) | 729 if (CPDF_FormControl* pControl = pField->GetControl(i)) |
729 result.push_back(pControl->IsChecked()); | 730 result.push_back(pControl->IsChecked()); |
730 } | 731 } |
731 return result; | 732 return result; |
732 } | 733 } |
733 | 734 |
734 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, | 735 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, |
735 const FX_CHAR* name, | 736 const FX_CHAR* name, |
736 int nLevel) { | 737 int nLevel) { |
737 if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { | 738 if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { |
738 return NULL; | 739 return nullptr; |
739 } | 740 } |
740 if (!pFieldDict) { | 741 if (!pFieldDict) { |
741 return NULL; | 742 return nullptr; |
742 } | 743 } |
743 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); | 744 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); |
744 if (pAttr) { | 745 if (pAttr) { |
745 return pAttr; | 746 return pAttr; |
746 } | 747 } |
747 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); | 748 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); |
748 if (!pParent) { | 749 if (!pParent) { |
749 return NULL; | 750 return nullptr; |
750 } | 751 } |
751 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); | 752 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
752 } | 753 } |
OLD | NEW |