| 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 "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
| 8 #include "doc_utils.h" | 8 #include "doc_utils.h" |
| 9 | 9 |
| 10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; | 10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); | 240 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); |
| 241 CPDF_Dictionary* pRoot = pDocument->GetRoot(); | 241 CPDF_Dictionary* pRoot = pDocument->GetRoot(); |
| 242 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); | 242 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); |
| 243 } | 243 } |
| 244 CFX_ByteString csDA; | 244 CFX_ByteString csDA; |
| 245 if (!pFormDict->KeyExist("DR")) { | 245 if (!pFormDict->KeyExist("DR")) { |
| 246 CPDF_Font* pFont = NULL; | 246 CPDF_Font* pFont = NULL; |
| 247 CFX_ByteString csBaseName, csDefault; | 247 CFX_ByteString csBaseName, csDefault; |
| 248 FX_BYTE charSet = CPDF_InterForm::GetNativeCharSet(); | 248 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 249 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); | 249 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); |
| 250 if (pFont != NULL) { | 250 if (pFont != NULL) { |
| 251 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 251 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
| 252 csDefault = csBaseName; | 252 csDefault = csBaseName; |
| 253 } | 253 } |
| 254 if (charSet != 0) { | 254 if (charSet != 0) { |
| 255 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, N
ULL); | 255 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, N
ULL); |
| 256 if (pFont == NULL || csFontName != "Helvetica") { | 256 if (pFont == NULL || csFontName != "Helvetica") { |
| 257 pFont = CPDF_InterForm::AddNativeFont(pDocument); | 257 pFont = CPDF_InterForm::AddNativeFont(pDocument); |
| 258 if (pFont != NULL) { | 258 if (pFont != NULL) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 CFX_ByteString csBaseFont; | 402 CFX_ByteString csBaseFont; |
| 403 csBaseFont = pFind->GetBaseFont(); | 403 csBaseFont = pFind->GetBaseFont(); |
| 404 csBaseFont.Remove(' '); | 404 csBaseFont.Remove(' '); |
| 405 if (csBaseFont == csFontName) { | 405 if (csBaseFont == csFontName) { |
| 406 csNameTag = csKey; | 406 csNameTag = csKey; |
| 407 return pFind; | 407 return pFind; |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 return NULL; | 410 return NULL; |
| 411 } | 411 } |
| 412 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDo
cument, FX_BYTE charSet, CFX_ByteString& csNameTag) | 412 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDo
cument, uint8_t charSet, CFX_ByteString& csNameTag) |
| 413 { | 413 { |
| 414 if (pFormDict == NULL) { | 414 if (pFormDict == NULL) { |
| 415 return NULL; | 415 return NULL; |
| 416 } | 416 } |
| 417 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 417 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 418 if (pDR == NULL) { | 418 if (pDR == NULL) { |
| 419 return NULL; | 419 return NULL; |
| 420 } | 420 } |
| 421 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 421 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 422 if (pFonts == NULL) { | 422 if (pFonts == NULL) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 449 if (pSubst->m_Charset == (int)charSet) { | 449 if (pSubst->m_Charset == (int)charSet) { |
| 450 csNameTag = csKey; | 450 csNameTag = csKey; |
| 451 return pFind; | 451 return pFind; |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 return NULL; | 454 return NULL; |
| 455 } | 455 } |
| 456 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDo
cument, CFX_ByteString& csNameTag) | 456 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDo
cument, CFX_ByteString& csNameTag) |
| 457 { | 457 { |
| 458 csNameTag = ""; | 458 csNameTag = ""; |
| 459 FX_BYTE charSet = CPDF_InterForm::GetNativeCharSet(); | 459 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 460 CFX_SubstFont* pSubst; | 460 CFX_SubstFont* pSubst; |
| 461 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); | 461 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); |
| 462 if (pFont != NULL) { | 462 if (pFont != NULL) { |
| 463 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); | 463 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); |
| 464 if (pSubst != NULL && pSubst->m_Charset == (int)charSet) { | 464 if (pSubst != NULL && pSubst->m_Charset == (int)charSet) { |
| 465 FindInterFormFont(pFormDict, pFont, csNameTag); | 465 FindInterFormFont(pFormDict, pFont, csNameTag); |
| 466 return pFont; | 466 return pFont; |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); | 469 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 pFonts = CPDF_Dictionary::Create(); | 579 pFonts = CPDF_Dictionary::Create(); |
| 580 pDR->SetAt("Font", pFonts); | 580 pDR->SetAt("Font", pFonts); |
| 581 } | 581 } |
| 582 if (csNameTag.IsEmpty()) { | 582 if (csNameTag.IsEmpty()) { |
| 583 csNameTag = pFont->GetBaseFont(); | 583 csNameTag = pFont->GetBaseFont(); |
| 584 } | 584 } |
| 585 csNameTag.Remove(' '); | 585 csNameTag.Remove(' '); |
| 586 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, csNameTa
g); | 586 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, csNameTa
g); |
| 587 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); | 587 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); |
| 588 } | 588 } |
| 589 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pD
ocument, FX_BYTE charSet, CFX_ByteString& csNameTag) | 589 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pD
ocument, uint8_t charSet, CFX_ByteString& csNameTag) |
| 590 { | 590 { |
| 591 if (pFormDict == NULL) { | 591 if (pFormDict == NULL) { |
| 592 InitInterFormDict(pFormDict, pDocument); | 592 InitInterFormDict(pFormDict, pDocument); |
| 593 } | 593 } |
| 594 CFX_ByteString csTemp; | 594 CFX_ByteString csTemp; |
| 595 CPDF_Font* pFont = GetNativeInterFormFont(pFormDict, pDocument, charSet, csT
emp); | 595 CPDF_Font* pFont = GetNativeInterFormFont(pFormDict, pDocument, charSet, csT
emp); |
| 596 if (pFont != NULL) { | 596 if (pFont != NULL) { |
| 597 csNameTag = csTemp; | 597 csNameTag = csTemp; |
| 598 return pFont; | 598 return pFont; |
| 599 } | 599 } |
| 600 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); | 600 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); |
| 601 if (!csFontName.IsEmpty()) { | 601 if (!csFontName.IsEmpty()) { |
| 602 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag
)) { | 602 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag
)) { |
| 603 return pFont; | 603 return pFont; |
| 604 } | 604 } |
| 605 } | 605 } |
| 606 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); | 606 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); |
| 607 if (pFont != NULL) { | 607 if (pFont != NULL) { |
| 608 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); | 608 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); |
| 609 } | 609 } |
| 610 return pFont; | 610 return pFont; |
| 611 } | 611 } |
| 612 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pD
ocument, CFX_ByteString& csNameTag) | 612 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pD
ocument, CFX_ByteString& csNameTag) |
| 613 { | 613 { |
| 614 FX_BYTE charSet = CPDF_InterForm::GetNativeCharSet(); | 614 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 615 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); | 615 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); |
| 616 } | 616 } |
| 617 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) | 617 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) |
| 618 { | 618 { |
| 619 if (pFormDict == NULL || pFont == NULL) { | 619 if (pFormDict == NULL || pFont == NULL) { |
| 620 return; | 620 return; |
| 621 } | 621 } |
| 622 CFX_ByteString csTag; | 622 CFX_ByteString csTag; |
| 623 if (!FindInterFormFont(pFormDict, pFont, csTag)) { | 623 if (!FindInterFormFont(pFormDict, pFont, csTag)) { |
| 624 return; | 624 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); | 721 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); |
| 722 if (pAttr) { | 722 if (pAttr) { |
| 723 return pAttr; | 723 return pAttr; |
| 724 } | 724 } |
| 725 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); | 725 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); |
| 726 if (pParent == NULL) { | 726 if (pParent == NULL) { |
| 727 return NULL; | 727 return NULL; |
| 728 } | 728 } |
| 729 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); | 729 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
| 730 } | 730 } |
| OLD | NEW |