| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 void AddFont(CPDF_Dictionary*& pFormDict, | 51 void AddFont(CPDF_Dictionary*& pFormDict, |
| 52 CPDF_Document* pDocument, | 52 CPDF_Document* pDocument, |
| 53 const CPDF_Font* pFont, | 53 const CPDF_Font* pFont, |
| 54 CFX_ByteString& csNameTag); | 54 CFX_ByteString& csNameTag); |
| 55 | 55 |
| 56 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { | 56 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
| 57 if (!pDocument) | 57 if (!pDocument) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 if (!pFormDict) { | 60 if (!pFormDict) { |
| 61 pFormDict = new CPDF_Dictionary; | 61 pFormDict = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 62 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); | 62 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); |
| 63 CPDF_Dictionary* pRoot = pDocument->GetRoot(); | 63 CPDF_Dictionary* pRoot = pDocument->GetRoot(); |
| 64 pRoot->SetReferenceFor("AcroForm", pDocument, dwObjNum); | 64 pRoot->SetReferenceFor("AcroForm", pDocument, dwObjNum); |
| 65 } | 65 } |
| 66 | 66 |
| 67 CFX_ByteString csDA; | 67 CFX_ByteString csDA; |
| 68 if (!pFormDict->KeyExist("DR")) { | 68 if (!pFormDict->KeyExist("DR")) { |
| 69 CFX_ByteString csBaseName; | 69 CFX_ByteString csBaseName; |
| 70 CFX_ByteString csDefault; | 70 CFX_ByteString csDefault; |
| 71 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 71 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 CFX_ByteString csTag; | 385 CFX_ByteString csTag; |
| 386 if (FindFont(pFormDict, pFont, csTag)) { | 386 if (FindFont(pFormDict, pFont, csTag)) { |
| 387 csNameTag = csTag; | 387 csNameTag = csTag; |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 if (!pFormDict) | 390 if (!pFormDict) |
| 391 InitDict(pFormDict, pDocument); | 391 InitDict(pFormDict, pDocument); |
| 392 | 392 |
| 393 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 393 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
| 394 if (!pDR) { | 394 if (!pDR) { |
| 395 pDR = new CPDF_Dictionary; | 395 pDR = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 396 pFormDict->SetFor("DR", pDR); | 396 pFormDict->SetFor("DR", pDR); |
| 397 } | 397 } |
| 398 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | 398 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
| 399 if (!pFonts) { | 399 if (!pFonts) { |
| 400 pFonts = new CPDF_Dictionary; | 400 pFonts = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 401 pDR->SetFor("Font", pFonts); | 401 pDR->SetFor("Font", pFonts); |
| 402 } | 402 } |
| 403 if (csNameTag.IsEmpty()) | 403 if (csNameTag.IsEmpty()) |
| 404 csNameTag = pFont->GetBaseFont(); | 404 csNameTag = pFont->GetBaseFont(); |
| 405 | 405 |
| 406 csNameTag.Remove(' '); | 406 csNameTag.Remove(' '); |
| 407 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, | 407 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, |
| 408 csNameTag.c_str()); | 408 csNameTag.c_str()); |
| 409 pFonts->SetReferenceFor(csNameTag, pDocument, pFont->GetFontDict()); | 409 pFonts->SetReferenceFor(csNameTag, pDocument, pFont->GetFontDict()); |
| 410 } | 410 } |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 if (!pDoc) | 1489 if (!pDoc) |
| 1490 return nullptr; | 1490 return nullptr; |
| 1491 | 1491 |
| 1492 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); | 1492 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); |
| 1493 if (!pdf_path.IsEmpty()) { | 1493 if (!pdf_path.IsEmpty()) { |
| 1494 if (bSimpleFileSpec) { | 1494 if (bSimpleFileSpec) { |
| 1495 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); | 1495 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
| 1496 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1496 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); |
| 1497 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); | 1497 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); |
| 1498 } else { | 1498 } else { |
| 1499 CPDF_FileSpec filespec; | 1499 CPDF_FileSpec filespec(pDoc->GetByteStringPool()); |
| 1500 filespec.SetFileName(pdf_path); | 1500 filespec.SetFileName(pdf_path); |
| 1501 pMainDict->SetFor("F", filespec.GetObj()); | 1501 pMainDict->SetFor("F", filespec.GetObj()); |
| 1502 } | 1502 } |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 CPDF_Array* pFields = new CPDF_Array; | 1505 CPDF_Array* pFields = new CPDF_Array; |
| 1506 pMainDict->SetFor("Fields", pFields); | 1506 pMainDict->SetFor("Fields", pFields); |
| 1507 int nCount = m_pFieldTree->m_Root.CountFields(); | 1507 int nCount = m_pFieldTree->m_Root.CountFields(); |
| 1508 for (int i = 0; i < nCount; i++) { | 1508 for (int i = 0; i < nCount; i++) { |
| 1509 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1509 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
| 1510 if (!pField || pField->GetType() == CPDF_FormField::PushButton) | 1510 if (!pField || pField->GetType() == CPDF_FormField::PushButton) |
| 1511 continue; | 1511 continue; |
| 1512 | 1512 |
| 1513 uint32_t dwFlags = pField->GetFieldFlags(); | 1513 uint32_t dwFlags = pField->GetFieldFlags(); |
| 1514 if (dwFlags & 0x04) | 1514 if (dwFlags & 0x04) |
| 1515 continue; | 1515 continue; |
| 1516 | 1516 |
| 1517 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1517 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
| 1518 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) | 1518 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) |
| 1519 continue; | 1519 continue; |
| 1520 | 1520 |
| 1521 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); | 1521 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); |
| 1522 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; | 1522 CPDF_Dictionary* pFieldDict = |
| 1523 new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 1523 pFieldDict->SetFor("T", new CPDF_String(fullname)); | 1524 pFieldDict->SetFor("T", new CPDF_String(fullname)); |
| 1524 if (pField->GetType() == CPDF_FormField::CheckBox || | 1525 if (pField->GetType() == CPDF_FormField::CheckBox || |
| 1525 pField->GetType() == CPDF_FormField::RadioButton) { | 1526 pField->GetType() == CPDF_FormField::RadioButton) { |
| 1526 CFX_WideString csExport = pField->GetCheckValue(FALSE); | 1527 CFX_WideString csExport = pField->GetCheckValue(FALSE); |
| 1527 CFX_ByteString csBExport = PDF_EncodeText(csExport); | 1528 CFX_ByteString csBExport = PDF_EncodeText(csExport); |
| 1528 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); | 1529 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); |
| 1529 if (pOpt) | 1530 if (pOpt) |
| 1530 pFieldDict->SetStringFor("V", csBExport); | 1531 pFieldDict->SetStringFor("V", csBExport); |
| 1531 else | 1532 else |
| 1532 pFieldDict->SetNameFor("V", csBExport); | 1533 pFieldDict->SetNameFor("V", csBExport); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 FDF_ImportField(pField, L"", bNotify); | 1625 FDF_ImportField(pField, L"", bNotify); |
| 1625 } | 1626 } |
| 1626 if (bNotify && m_pFormNotify) | 1627 if (bNotify && m_pFormNotify) |
| 1627 m_pFormNotify->AfterFormImportData(this); | 1628 m_pFormNotify->AfterFormImportData(this); |
| 1628 return TRUE; | 1629 return TRUE; |
| 1629 } | 1630 } |
| 1630 | 1631 |
| 1631 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { | 1632 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
| 1632 m_pFormNotify = pNotify; | 1633 m_pFormNotify = pNotify; |
| 1633 } | 1634 } |
| OLD | NEW |