diff options
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 426 | ||||
-rw-r--r-- | core/fpdfdoc/include/cpdf_interform.h | 84 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_interform.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_pageview.cpp | 7 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 7 |
5 files changed, 98 insertions, 434 deletions
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 574fa1b335..d2a842262e 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -96,68 +96,6 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { pFormDict->SetStringFor("DA", csDA); } -uint32_t CountFonts(CPDF_Dictionary* pFormDict) { - if (!pFormDict) - return 0; - - CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); - if (!pDR) - return 0; - - CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); - if (!pFonts) - return 0; - - uint32_t dwCount = 0; - for (const auto& it : *pFonts) { - CPDF_Object* pObj = it.second; - if (!pObj) - continue; - - if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { - if (pDirect->GetStringFor("Type") == "Font") - dwCount++; - } - } - return dwCount; -} - -CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, - CPDF_Document* pDocument, - uint32_t index, - CFX_ByteString& csNameTag) { - if (!pFormDict) - return nullptr; - - CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); - if (!pDR) - return nullptr; - - CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); - if (!pFonts) - return nullptr; - - uint32_t dwCount = 0; - for (const auto& it : *pFonts) { - const CFX_ByteString& csKey = it.first; - CPDF_Object* pObj = it.second; - if (!pObj) - continue; - - CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); - if (!pElement) - continue; - if (pElement->GetStringFor("Type") != "Font") - continue; - if (dwCount == index) { - csNameTag = csKey; - return pDocument->LoadFont(pElement); - } - dwCount++; - } - return nullptr; -} - CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csNameTag) { @@ -182,48 +120,6 @@ CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, return nullptr; } -CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, - CPDF_Document* pDocument, - CFX_ByteString csFontName, - CFX_ByteString& csNameTag) { - if (!pFormDict || csFontName.IsEmpty()) - return nullptr; - - CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); - if (!pDR) - return nullptr; - - CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); - if (!pFonts) - return nullptr; - - for (const auto& it : *pFonts) { - const CFX_ByteString& csKey = it.first; - CPDF_Object* pObj = it.second; - if (!pObj) - continue; - - CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); - if (!pElement) - continue; - if (pElement->GetStringFor("Type") != "Font") - continue; - - CPDF_Font* pFind = pDocument->LoadFont(pElement); - if (!pFind) - continue; - - CFX_ByteString csBaseFont; - csBaseFont = pFind->GetBaseFont(); - csBaseFont.Remove(' '); - if (csBaseFont == csFontName) { - csNameTag = csKey; - return pFind; - } - } - return nullptr; -} - CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, uint8_t charSet, @@ -266,18 +162,6 @@ CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, return nullptr; } -CPDF_Font* GetDefaultFont(CPDF_Dictionary* pFormDict, - CPDF_Document* pDocument) { - if (!pFormDict) - return nullptr; - - CPDF_DefaultAppearance cDA(pFormDict->GetStringFor("DA")); - CFX_ByteString csFontNameTag; - FX_FLOAT fFontSize; - cDA.GetFont(csFontNameTag, fFontSize); - return GetFont(pFormDict, pDocument, csFontNameTag); -} - FX_BOOL FindFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont, CFX_ByteString& csNameTag) { @@ -311,22 +195,6 @@ FX_BOOL FindFont(CPDF_Dictionary* pFormDict, return FALSE; } -CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, - CPDF_Document* pDocument, - CFX_ByteString& csNameTag) { - csNameTag.clear(); - uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); - CPDF_Font* pFont = GetDefaultFont(pFormDict, pDocument); - if (pFont) { - CFX_SubstFont* pSubst = pFont->GetSubstFont(); - if (pSubst && pSubst->m_Charset == (int)charSet) { - FindFont(pFormDict, pFont, csNameTag); - return pFont; - } - } - return GetNativeFont(pFormDict, pDocument, charSet, csNameTag); -} - FX_BOOL FindFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csFontName, @@ -422,7 +290,7 @@ CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, csNameTag = csTemp; return pFont; } - CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); + CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, nullptr); if (!csFontName.IsEmpty() && FindFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { return pFont; @@ -434,34 +302,6 @@ CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, return pFont; } -void RemoveFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { - if (!pFormDict || !pFont) - return; - - CFX_ByteString csTag; - if (!FindFont(pFormDict, pFont, csTag)) - return; - - CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); - CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); - pFonts->RemoveFor(csTag); -} - -void RemoveFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { - if (!pFormDict || csNameTag.IsEmpty()) - return; - - CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); - if (!pDR) - return; - - CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); - if (!pFonts) - return; - - pFonts->RemoveFor(csNameTag); -} - class CFieldNameExtractor { public: explicit CFieldNameExtractor(const CFX_WideString& full_name) @@ -533,6 +373,22 @@ FX_BOOL RetrieveSpecificFont(uint8_t charSet, } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +int CompareFieldName(const CFX_WideString& name1, const CFX_WideString& name2) { + const FX_WCHAR* ptr1 = name1.c_str(); + const FX_WCHAR* ptr2 = name2.c_str(); + if (name1.GetLength() == name2.GetLength()) + return name1 == name2 ? 1 : 0; + + int i = 0; + while (ptr1[i] == ptr2[i]) + i++; + if (i == name1.GetLength()) + return 2; + if (i == name2.GetLength()) + return 3; + return 0; +} + } // namespace class CFieldTree { @@ -551,12 +407,12 @@ class CFieldTree { Node* GetChildAt(size_t i) { return m_Children[i]; } const Node* GetChildAt(size_t i) const { return m_Children[i]; } - CPDF_FormField* GetFieldAtIndex(int index) { - int nFieldsToGo = index; + CPDF_FormField* GetFieldAtIndex(size_t index) { + size_t nFieldsToGo = index; return GetFieldInternal(&nFieldsToGo); } - int CountFields() const { return CountFieldsInternal(0); } + size_t CountFields() const { return CountFieldsInternal(0); } void SetField(CPDF_FormField* pField) { m_pField = pField; } @@ -566,7 +422,7 @@ class CFieldTree { const CFX_WideString& GetShortName() const { return m_ShortName; } private: - CPDF_FormField* GetFieldInternal(int* pFieldsToGo) { + CPDF_FormField* GetFieldInternal(size_t* pFieldsToGo) { if (m_pField) { if (*pFieldsToGo == 0) return m_pField; @@ -582,13 +438,13 @@ class CFieldTree { return nullptr; } - int CountFieldsInternal(int nLevel) const { + size_t CountFieldsInternal(int nLevel) const { if (nLevel > nMaxRecursion) return 0; if (m_pField) return 1; - int count = 0; + size_t count = 0; for (size_t i = 0; i < GetChildrenCount(); ++i) count += GetChildAt(i)->CountFieldsInternal(nLevel + 1); return count; @@ -810,26 +666,26 @@ CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) if (!pFields) return; - for (size_t i = 0; i < pFields->GetCount(); i++) - LoadField(pFields->GetDictAt(i)); + for (size_t i = 0; i < pFields->GetCount(); ++i) + LoadField(pFields->GetDictAt(i), 0); } CPDF_InterForm::~CPDF_InterForm() { for (auto it : m_ControlMap) delete it.second; - int nCount = m_pFieldTree->m_Root.CountFields(); - for (int i = 0; i < nCount; ++i) + size_t nCount = m_pFieldTree->m_Root.CountFields(); + for (size_t i = 0; i < nCount; ++i) delete m_pFieldTree->m_Root.GetFieldAtIndex(i); } -FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE; +bool CPDF_InterForm::s_bUpdateAP = true; -FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() { +bool CPDF_InterForm::IsUpdateAPEnabled() { return s_bUpdateAP; } -void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) { +void CPDF_InterForm::SetUpdateAP(bool bUpdateAP) { s_bUpdateAP = bUpdateAP; } @@ -941,14 +797,6 @@ CFX_ByteString CPDF_InterForm::GetNativeFont(uint8_t charSet, void* pLogFont) { return csFontName; } -CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - return GetNativeFont(GetNativeCharSet(), pLogFont); -#else - return CFX_ByteString(); -#endif -} - CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet, CPDF_Document* pDocument) { if (!pDocument) @@ -970,18 +818,18 @@ CPDF_Font* CPDF_InterForm::AddNativeFont(CPDF_Document* pDocument) { return pDocument ? AddNativeFont(GetNativeCharSet(), pDocument) : nullptr; } -FX_BOOL CPDF_InterForm::ValidateFieldName( +bool CPDF_InterForm::ValidateFieldName( CFX_WideString& csNewFieldName, int iType, const CPDF_FormField* pExcludedField, - const CPDF_FormControl* pExcludedControl) { + const CPDF_FormControl* pExcludedControl) const { if (csNewFieldName.IsEmpty()) - return FALSE; + return false; int iPos = 0; int iLength = csNewFieldName.GetLength(); CFX_WideString csSub; - while (TRUE) { + while (true) { while (iPos < iLength && (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { iPos++; @@ -991,113 +839,54 @@ FX_BOOL CPDF_InterForm::ValidateFieldName( while (iPos < iLength && csNewFieldName[iPos] != L'.') csSub += csNewFieldName[iPos++]; for (int i = csSub.GetLength() - 1; i > -1; i--) { - if (csSub[i] == L' ' || csSub[i] == L'.') - csSub.SetAt(i, L'\0'); - else + if (csSub[i] != L' ' && csSub[i] != L'.') break; + + csSub.SetAt(i, L'\0'); } - uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); - for (uint32_t m = 0; m < dwCount; m++) { + size_t dwCount = m_pFieldTree->m_Root.CountFields(); + for (size_t m = 0; m < dwCount; ++m) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); if (!pField) continue; if (pField == pExcludedField) { - if (pExcludedControl) { - if (pField->CountControls() < 2) - continue; - } else { + if (!pExcludedControl || pField->CountControls() < 2) continue; - } } CFX_WideString csFullName = pField->GetFullName(); int iRet = CompareFieldName(csSub, csFullName); if (iRet == 1) { if (pField->GetFieldType() != iType) - return FALSE; + return false; } else if (iRet == 2 && csSub == csNewFieldName) { if (csFullName[iPos] == L'.') - return FALSE; + return false; } else if (iRet == 3 && csSub == csNewFieldName) { if (csNewFieldName[csFullName.GetLength()] == L'.') - return FALSE; + return false; } } if (iPos >= iLength) break; } if (csSub.IsEmpty()) - return FALSE; + return false; csNewFieldName = csSub; - return TRUE; -} - -FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, - int iType) { - return ValidateFieldName(csNewFieldName, iType, nullptr, nullptr); -} - -FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, - CFX_WideString& csNewFieldName) { - return pField && !csNewFieldName.IsEmpty() && - ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, - nullptr); -} - -FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, - CFX_WideString& csNewFieldName) { - if (!pControl || csNewFieldName.IsEmpty()) - return FALSE; - - CPDF_FormField* pField = pControl->GetField(); - return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, - pControl); -} - -int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, - const CFX_ByteString& name2) { - if (name1.GetLength() == name2.GetLength()) - return name1 == name2 ? 1 : 0; - - const FX_CHAR* ptr1 = name1.c_str(); - const FX_CHAR* ptr2 = name2.c_str(); - int i = 0; - while (ptr1[i] == ptr2[i]) - i++; - if (i == name1.GetLength()) - return 2; - if (i == name2.GetLength()) - return 3; - return 0; -} - -int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, - const CFX_WideString& name2) { - const FX_WCHAR* ptr1 = name1.c_str(); - const FX_WCHAR* ptr2 = name2.c_str(); - if (name1.GetLength() == name2.GetLength()) - return name1 == name2 ? 1 : 0; - - int i = 0; - while (ptr1[i] == ptr2[i]) - i++; - if (i == name1.GetLength()) - return 2; - if (i == name2.GetLength()) - return 3; - return 0; + return true; } -uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { +size_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) const { if (csFieldName.IsEmpty()) - return (uint32_t)m_pFieldTree->m_Root.CountFields(); + return m_pFieldTree->m_Root.CountFields(); CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); return pNode ? pNode->CountFields() : 0; } -CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, - const CFX_WideString& csFieldName) { +CPDF_FormField* CPDF_InterForm::GetField( + uint32_t index, + const CFX_WideString& csFieldName) const { if (csFieldName.IsEmpty()) return m_pFieldTree->m_Root.GetFieldAtIndex(index); @@ -1190,77 +979,17 @@ int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { return -1; } -uint32_t CPDF_InterForm::CountFormFonts() { - return CountFonts(m_pFormDict); -} - -CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index, - CFX_ByteString& csNameTag) { - return GetFont(m_pFormDict, m_pDocument, index, csNameTag); -} - CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { return GetFont(m_pFormDict, m_pDocument, csNameTag); } -CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName, - CFX_ByteString& csNameTag) { - return GetFont(m_pFormDict, m_pDocument, csFontName, csNameTag); -} - -CPDF_Font* CPDF_InterForm::GetNativeFormFont(uint8_t charSet, - CFX_ByteString& csNameTag) { - return ::GetNativeFont(m_pFormDict, m_pDocument, charSet, csNameTag); -} - -CPDF_Font* CPDF_InterForm::GetNativeFormFont(CFX_ByteString& csNameTag) { - return ::GetNativeFont(m_pFormDict, m_pDocument, csNameTag); -} - -FX_BOOL CPDF_InterForm::FindFormFont(const CPDF_Font* pFont, - CFX_ByteString& csNameTag) { - return FindFont(m_pFormDict, pFont, csNameTag); -} - -FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, - CPDF_Font*& pFont, - CFX_ByteString& csNameTag) { - return FindFont(m_pFormDict, m_pDocument, csFontName, pFont, csNameTag); -} - -void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont, - CFX_ByteString& csNameTag) { - AddFont(m_pFormDict, m_pDocument, pFont, csNameTag); -} - -CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet, - CFX_ByteString& csNameTag) { - return ::AddNativeFont(m_pFormDict, m_pDocument, charSet, csNameTag); -} - -CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) { - return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); -} - -void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { - RemoveFont(m_pFormDict, pFont); -} - -void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { - RemoveFont(m_pFormDict, csNameTag); -} - -CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { +CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() const { if (!m_pFormDict) return CPDF_DefaultAppearance(); return CPDF_DefaultAppearance(m_pFormDict->GetStringFor("DA")); } -CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { - return GetDefaultFont(m_pFormDict, m_pDocument); -} - -int CPDF_InterForm::GetFormAlignment() { +int CPDF_InterForm::GetFormAlignment() const { return m_pFormDict ? m_pFormDict->GetIntegerFor("Q", 0) : 0; } @@ -1270,8 +999,8 @@ bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) return false; - int nCount = m_pFieldTree->m_Root.CountFields(); - for (int i = 0; i < nCount; ++i) { + size_t nCount = m_pFieldTree->m_Root.CountFields(); + for (size_t i = 0; i < nCount; ++i) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); if (!pField) continue; @@ -1288,8 +1017,8 @@ bool CPDF_InterForm::ResetForm(bool bNotify) { if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) return false; - int nCount = m_pFieldTree->m_Root.CountFields(); - for (int i = 0; i < nCount; ++i) { + size_t nCount = m_pFieldTree->m_Root.CountFields(); + for (size_t i = 0; i < nCount; ++i) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); if (!pField) continue; @@ -1347,7 +1076,7 @@ void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { for (size_t i = 0; i < pAnnots->GetCount(); i++) { CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); if (pAnnot && pAnnot->GetStringFor("Subtype") == "Widget") - LoadField(pAnnot); + LoadField(pAnnot, 0); } } @@ -1430,8 +1159,8 @@ CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, CPDF_FormField* CPDF_InterForm::CheckRequiredFields( const std::vector<CPDF_FormField*>* fields, bool bIncludeOrExclude) const { - int nCount = m_pFieldTree->m_Root.CountFields(); - for (int i = 0; i < nCount; ++i) { + size_t nCount = m_pFieldTree->m_Root.CountFields(); + for (size_t i = 0; i < nCount; ++i) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); if (!pField) continue; @@ -1461,8 +1190,8 @@ CPDF_FormField* CPDF_InterForm::CheckRequiredFields( CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, bool bSimpleFileSpec) const { std::vector<CPDF_FormField*> fields; - int nCount = m_pFieldTree->m_Root.CountFields(); - for (int i = 0; i < nCount; ++i) + size_t nCount = m_pFieldTree->m_Root.CountFields(); + for (size_t i = 0; i < nCount; ++i) fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); } @@ -1491,8 +1220,8 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( CPDF_Array* pFields = new CPDF_Array; pMainDict->SetFor("Fields", pFields); - int nCount = m_pFieldTree->m_Root.CountFields(); - for (int i = 0; i < nCount; i++) { + size_t nCount = m_pFieldTree->m_Root.CountFields(); + for (size_t i = 0; i < nCount; ++i) { CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); if (!pField || pField->GetType() == CPDF_FormField::PushButton) continue; @@ -1586,35 +1315,6 @@ void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, } } -FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, - FX_BOOL bNotify) { - if (!pFDF) - return FALSE; - - CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); - if (!pMainDict) - return FALSE; - - CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); - if (!pFields) - return FALSE; - - m_bsEncoding = pMainDict->GetStringFor("Encoding"); - if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) - return FALSE; - - for (size_t i = 0; i < pFields->GetCount(); i++) { - CPDF_Dictionary* pField = pFields->GetDictAt(i); - if (!pField) - continue; - - FDF_ImportField(pField, L"", bNotify); - } - if (bNotify && m_pFormNotify) - m_pFormNotify->AfterFormImportData(this); - return TRUE; -} - void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { m_pFormNotify = pNotify; } diff --git a/core/fpdfdoc/include/cpdf_interform.h b/core/fpdfdoc/include/cpdf_interform.h index 6d9d616c89..9c07ee996f 100644 --- a/core/fpdfdoc/include/cpdf_interform.h +++ b/core/fpdfdoc/include/cpdf_interform.h @@ -36,30 +36,22 @@ class CPDF_InterForm { explicit CPDF_InterForm(CPDF_Document* pDocument); ~CPDF_InterForm(); - static void SetUpdateAP(FX_BOOL bUpdateAP); - static FX_BOOL IsUpdateAPEnabled(); + static void SetUpdateAP(bool bUpdateAP); + static bool IsUpdateAPEnabled(); static CFX_ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, const FX_CHAR* csType, - int iMinLen = 2, - const FX_CHAR* csPrefix = ""); + int iMinLen, + const FX_CHAR* csPrefix); static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, CFX_ByteString csFontName); - static CFX_ByteString GetNativeFont(uint8_t iCharSet, - void* pLogFont = nullptr); - static CFX_ByteString GetNativeFont(void* pLogFont = nullptr); + static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont); static uint8_t GetNativeCharSet(); static CPDF_Font* AddNativeFont(uint8_t iCharSet, CPDF_Document* pDocument); static CPDF_Font* AddNativeFont(CPDF_Document* pDocument); - FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, int iType); - FX_BOOL ValidateFieldName(const CPDF_FormField* pField, - CFX_WideString& csNewFieldName); - FX_BOOL ValidateFieldName(const CPDF_FormControl* pControl, - CFX_WideString& csNewFieldName); - - uint32_t CountFields(const CFX_WideString& csFieldName = L""); + size_t CountFields(const CFX_WideString& csFieldName) const; CPDF_FormField* GetField(uint32_t index, - const CFX_WideString& csFieldName = L""); + const CFX_WideString& csFieldName) const; CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const; CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage, @@ -68,57 +60,30 @@ class CPDF_InterForm { int* z_order) const; CPDF_FormControl* GetControlByDict(const CPDF_Dictionary* pWidgetDict) const; - CPDF_Document* GetDocument() const { return m_pDocument; } - CPDF_Dictionary* GetFormDict() const { return m_pFormDict; } FX_BOOL NeedConstructAP() const; int CountFieldsInCalculationOrder(); CPDF_FormField* GetFieldInCalculationOrder(int index); int FindFieldInCalculationOrder(const CPDF_FormField* pField); - uint32_t CountFormFonts(); - CPDF_Font* GetFormFont(uint32_t index, CFX_ByteString& csNameTag); CPDF_Font* GetFormFont(CFX_ByteString csNameTag); - CPDF_Font* GetFormFont(CFX_ByteString csFontName, CFX_ByteString& csNameTag); - CPDF_Font* GetNativeFormFont(uint8_t iCharSet, CFX_ByteString& csNameTag); - CPDF_Font* GetNativeFormFont(CFX_ByteString& csNameTag); - FX_BOOL FindFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag); - FX_BOOL FindFormFont(CFX_ByteString csFontName, - CPDF_Font*& pFont, - CFX_ByteString& csNameTag); - - FX_BOOL FindFormFont(CFX_WideString csFontName, - CPDF_Font*& pFont, - CFX_ByteString& csNameTag) { - return FindFormFont(PDF_EncodeText(csFontName), pFont, csNameTag); - } - - void AddFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag); - CPDF_Font* AddNativeFormFont(uint8_t iCharSet, CFX_ByteString& csNameTag); - CPDF_Font* AddNativeFormFont(CFX_ByteString& csNameTag); - - void RemoveFormFont(const CPDF_Font* pFont); - void RemoveFormFont(CFX_ByteString csNameTag); - - CPDF_DefaultAppearance GetDefaultAppearance(); - CPDF_Font* GetDefaultFormFont(); - int GetFormAlignment(); + CPDF_DefaultAppearance GetDefaultAppearance() const; + int GetFormAlignment() const; CPDF_FormField* CheckRequiredFields( const std::vector<CPDF_FormField*>* fields, bool bIncludeOrExclude) const; CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, - bool bSimpleFileSpec = false) const; + bool bSimpleFileSpec) const; CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, const std::vector<CPDF_FormField*>& fields, - bool bIncludeOrExclude = true, - bool bSimpleFileSpec = false) const; - FX_BOOL ImportFromFDF(const CFDF_Document* pFDFDoc, FX_BOOL bNotify = FALSE); + bool bIncludeOrExclude, + bool bSimpleFileSpec) const; bool ResetForm(const std::vector<CPDF_FormField*>& fields, - bool bIncludeOrExclude = true, - bool bNotify = false); - bool ResetForm(bool bNotify = false); + bool bIncludeOrExclude, + bool bNotify); + bool ResetForm(bool bNotify); void SetFormNotify(IPDF_FormNotify* pNotify); FX_BOOL HasXFAForm() const; @@ -128,8 +93,7 @@ class CPDF_InterForm { friend class CPDF_FormControl; friend class CPDF_FormField; - void LoadField(CPDF_Dictionary* pFieldDict, int nLevel = 0); - CPDF_Object* GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name); + void LoadField(CPDF_Dictionary* pFieldDict, int nLevel); CPDF_FormField* AddTerminalField(CPDF_Dictionary* pFieldDict); CPDF_FormControl* AddControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict); @@ -137,16 +101,12 @@ class CPDF_InterForm { const CFX_WideString& parent_name, FX_BOOL bNotify = FALSE, int nLevel = 0); - FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, - int iType, - const CPDF_FormField* pExcludedField, - const CPDF_FormControl* pExcludedControl); - int CompareFieldName(const CFX_WideString& name1, - const CFX_WideString& name2); - int CompareFieldName(const CFX_ByteString& name1, - const CFX_ByteString& name2); - - static FX_BOOL s_bUpdateAP; + bool ValidateFieldName(CFX_WideString& csNewFieldName, + int iType, + const CPDF_FormField* pExcludedField, + const CPDF_FormControl* pExcludedControl) const; + + static bool s_bUpdateAP; CPDF_Document* const m_pDocument; CPDF_Dictionary* m_pFormDict; diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index ce6206a3f7..01889d5947 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -8,6 +8,7 @@ #include <algorithm> #include <memory> +#include <vector> #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" @@ -524,7 +525,7 @@ FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( bool bIncludeOrExclude, CFX_ByteTextBuf& textBuf) { std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( - m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude)); + m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude, false)); return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; } @@ -543,7 +544,8 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, CPDFSDK_Environment* pEnv = m_pDocument->GetEnv(); CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); - CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC()); + CFDF_Document* pFDFDoc = + m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); if (!pFDFDoc) return FALSE; @@ -569,7 +571,7 @@ FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { CFDF_Document* pFDF = - m_pInterForm->ExportToFDF(m_pDocument->GetPath().AsStringC()); + m_pInterForm->ExportToFDF(m_pDocument->GetPath().AsStringC(), false); if (!pFDF) return FALSE; diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index 900ea48670..f546e385e6 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -6,6 +6,9 @@ #include "fpdfsdk/include/cpdfsdk_pageview.h" +#include <memory> +#include <vector> + #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" #include "core/fpdfdoc/include/cpdf_annotlist.h" @@ -488,9 +491,9 @@ void CPDFSDK_PageView::LoadFXAnnots() { CPDF_Page* pPage = GetPDFPage(); ASSERT(pPage); - FX_BOOL bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); + bool bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); // Disable the default AP construction. - CPDF_InterForm::SetUpdateAP(FALSE); + CPDF_InterForm::SetUpdateAP(false); m_pAnnotList.reset(new CPDF_AnnotList(pPage)); CPDF_InterForm::SetUpdateAP(bUpdateAP); diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index ea225f095d..b7b03b2174 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -6,6 +6,7 @@ #include "fpdfsdk/javascript/Document.h" +#include <utility> #include <vector> #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" @@ -174,7 +175,7 @@ FX_BOOL Document::numFields(IJS_Context* cc, } CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - vp << (int)pPDFForm->CountFields(); + vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); return TRUE; } @@ -337,7 +338,7 @@ FX_BOOL Document::getNthFieldName(IJS_Context* cc, } CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - CPDF_FormField* pField = pPDFForm->GetField(nIndex); + CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); if (!pField) return FALSE; @@ -616,7 +617,6 @@ FX_BOOL Document::submitForm(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - int nSize = params.size(); if (nSize < 1) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); @@ -1234,7 +1234,6 @@ FX_BOOL Document::addIcon(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { - if (params.size() != 2) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return FALSE; |