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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 name_extractor.GetNext(pName, nLength); | 253 name_extractor.GetNext(pName, nLength); |
254 _Node *pNode = &m_Root, *pLast = NULL; | 254 _Node *pNode = &m_Root, *pLast = NULL; |
255 while (nLength > 0 && pNode) { | 255 while (nLength > 0 && pNode) { |
256 pLast = pNode; | 256 pLast = pNode; |
257 CFX_WideString name = CFX_WideString(pName, nLength); | 257 CFX_WideString name = CFX_WideString(pName, nLength); |
258 pNode = _Lookup(pLast, name); | 258 pNode = _Lookup(pLast, name); |
259 name_extractor.GetNext(pName, nLength); | 259 name_extractor.GetNext(pName, nLength); |
260 } | 260 } |
261 return pNode; | 261 return pNode; |
262 } | 262 } |
263 CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument, FX_BOOL bGenerateAP) | 263 |
| 264 CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) |
264 : CFX_PrivateData(), | 265 : CFX_PrivateData(), |
265 m_pDocument(pDocument), | 266 m_pDocument(pDocument), |
266 m_bGenerateAP(bGenerateAP), | |
267 m_pFormDict(nullptr), | 267 m_pFormDict(nullptr), |
268 m_pFieldTree(new CFieldTree), | 268 m_pFieldTree(new CFieldTree), |
269 m_pFormNotify(nullptr), | 269 m_pFormNotify(nullptr) { |
270 m_bUpdated(FALSE) { | |
271 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 270 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
272 if (!pRoot) | 271 if (!pRoot) |
273 return; | 272 return; |
274 | 273 |
275 m_pFormDict = pRoot->GetDictBy("AcroForm"); | 274 m_pFormDict = pRoot->GetDictBy("AcroForm"); |
276 if (!m_pFormDict) | 275 if (!m_pFormDict) |
277 return; | 276 return; |
278 | 277 |
279 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); | 278 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); |
280 if (!pFields) | 279 if (!pFields) |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 } | 724 } |
726 return nullptr; | 725 return nullptr; |
727 } | 726 } |
728 | 727 |
729 CPDF_FormControl* CPDF_InterForm::GetControlByDict( | 728 CPDF_FormControl* CPDF_InterForm::GetControlByDict( |
730 const CPDF_Dictionary* pWidgetDict) const { | 729 const CPDF_Dictionary* pWidgetDict) const { |
731 const auto it = m_ControlMap.find(pWidgetDict); | 730 const auto it = m_ControlMap.find(pWidgetDict); |
732 return it != m_ControlMap.end() ? it->second : nullptr; | 731 return it != m_ControlMap.end() ? it->second : nullptr; |
733 } | 732 } |
734 | 733 |
735 FX_BOOL CPDF_InterForm::NeedConstructAP() { | 734 FX_BOOL CPDF_InterForm::NeedConstructAP() const { |
736 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); | 735 return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); |
737 } | 736 } |
738 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { | |
739 if (!m_pFormDict) { | |
740 InitInterFormDict(m_pFormDict, m_pDocument); | |
741 } | |
742 m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); | |
743 m_bGenerateAP = bNeedAP; | |
744 } | |
745 | 737 |
746 int CPDF_InterForm::CountFieldsInCalculationOrder() { | 738 int CPDF_InterForm::CountFieldsInCalculationOrder() { |
747 if (!m_pFormDict) { | 739 if (!m_pFormDict) |
748 return 0; | 740 return 0; |
749 } | 741 |
750 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 742 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
751 return pArray ? pArray->GetCount() : 0; | 743 return pArray ? pArray->GetCount() : 0; |
752 } | 744 } |
753 | 745 |
754 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { | 746 CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { |
755 if (!m_pFormDict || index < 0) { | 747 if (!m_pFormDict || index < 0) |
756 return NULL; | 748 return nullptr; |
757 } | 749 |
758 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 750 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
759 if (!pArray) { | 751 if (!pArray) |
760 return NULL; | 752 return nullptr; |
761 } | 753 |
762 if (CPDF_Dictionary* pElement = | 754 CPDF_Dictionary* pElement = ToDictionary(pArray->GetDirectObjectAt(index)); |
763 ToDictionary(pArray->GetDirectObjectAt(index))) { | 755 return pElement ? GetFieldByDict(pElement) : nullptr; |
764 return GetFieldByDict(pElement); | |
765 } | |
766 return NULL; | |
767 } | 756 } |
| 757 |
768 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { | 758 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { |
769 if (!m_pFormDict || !pField) { | 759 if (!m_pFormDict || !pField) |
770 return -1; | 760 return -1; |
771 } | 761 |
772 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); | 762 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); |
773 if (!pArray) { | 763 if (!pArray) |
774 return -1; | 764 return -1; |
775 } | 765 |
776 for (size_t i = 0; i < pArray->GetCount(); i++) { | 766 for (size_t i = 0; i < pArray->GetCount(); i++) { |
777 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); | 767 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); |
778 if (pElement == pField->m_pDict) { | 768 if (pElement == pField->m_pDict) { |
779 return i; | 769 return i; |
780 } | 770 } |
781 } | 771 } |
782 return -1; | 772 return -1; |
783 } | 773 } |
| 774 |
784 uint32_t CPDF_InterForm::CountFormFonts() { | 775 uint32_t CPDF_InterForm::CountFormFonts() { |
785 return CountInterFormFonts(m_pFormDict); | 776 return CountInterFormFonts(m_pFormDict); |
786 } | 777 } |
| 778 |
787 CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index, | 779 CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index, |
788 CFX_ByteString& csNameTag) { | 780 CFX_ByteString& csNameTag) { |
789 return GetInterFormFont(m_pFormDict, m_pDocument, index, csNameTag); | 781 return GetInterFormFont(m_pFormDict, m_pDocument, index, csNameTag); |
790 } | 782 } |
791 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { | 783 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { |
792 return GetInterFormFont(m_pFormDict, m_pDocument, csNameTag); | 784 return GetInterFormFont(m_pFormDict, m_pDocument, csNameTag); |
793 } | 785 } |
794 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName, | 786 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName, |
795 CFX_ByteString& csNameTag) { | 787 CFX_ByteString& csNameTag) { |
796 return GetInterFormFont(m_pFormDict, m_pDocument, csFontName, csNameTag); | 788 return GetInterFormFont(m_pFormDict, m_pDocument, csFontName, csNameTag); |
(...skipping 11 matching lines...) Expand all Loading... |
808 } | 800 } |
809 FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, | 801 FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, |
810 CPDF_Font*& pFont, | 802 CPDF_Font*& pFont, |
811 CFX_ByteString& csNameTag) { | 803 CFX_ByteString& csNameTag) { |
812 return FindInterFormFont(m_pFormDict, m_pDocument, csFontName, pFont, | 804 return FindInterFormFont(m_pFormDict, m_pDocument, csFontName, pFont, |
813 csNameTag); | 805 csNameTag); |
814 } | 806 } |
815 void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont, | 807 void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont, |
816 CFX_ByteString& csNameTag) { | 808 CFX_ByteString& csNameTag) { |
817 AddInterFormFont(m_pFormDict, m_pDocument, pFont, csNameTag); | 809 AddInterFormFont(m_pFormDict, m_pDocument, pFont, csNameTag); |
818 m_bUpdated = TRUE; | |
819 } | 810 } |
| 811 |
820 CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet, | 812 CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet, |
821 CFX_ByteString& csNameTag) { | 813 CFX_ByteString& csNameTag) { |
822 m_bUpdated = TRUE; | |
823 return AddNativeInterFormFont(m_pFormDict, m_pDocument, charSet, csNameTag); | 814 return AddNativeInterFormFont(m_pFormDict, m_pDocument, charSet, csNameTag); |
824 } | 815 } |
| 816 |
825 CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) { | 817 CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) { |
826 m_bUpdated = TRUE; | |
827 return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); | 818 return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); |
828 } | 819 } |
| 820 |
829 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { | 821 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { |
830 m_bUpdated = TRUE; | |
831 RemoveInterFormFont(m_pFormDict, pFont); | 822 RemoveInterFormFont(m_pFormDict, pFont); |
832 } | 823 } |
| 824 |
833 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { | 825 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { |
834 m_bUpdated = TRUE; | |
835 RemoveInterFormFont(m_pFormDict, csNameTag); | 826 RemoveInterFormFont(m_pFormDict, csNameTag); |
836 } | 827 } |
837 | 828 |
838 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { | 829 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { |
839 if (!m_pFormDict) | 830 if (!m_pFormDict) |
840 return CPDF_DefaultAppearance(); | 831 return CPDF_DefaultAppearance(); |
841 return CPDF_DefaultAppearance(m_pFormDict->GetStringBy("DA")); | 832 return CPDF_DefaultAppearance(m_pFormDict->GetStringBy("DA")); |
842 } | 833 } |
843 | 834 |
844 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { | 835 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 } | 1155 } |
1165 if (bNotify && m_pFormNotify) { | 1156 if (bNotify && m_pFormNotify) { |
1166 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { | 1157 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { |
1167 m_pFormNotify->AfterCheckedStatusChange(pField); | 1158 m_pFormNotify->AfterCheckedStatusChange(pField); |
1168 } else if (iType == FIELDTYPE_LISTBOX) { | 1159 } else if (iType == FIELDTYPE_LISTBOX) { |
1169 m_pFormNotify->AfterSelectionChange(pField); | 1160 m_pFormNotify->AfterSelectionChange(pField); |
1170 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { | 1161 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { |
1171 m_pFormNotify->AfterValueChange(pField); | 1162 m_pFormNotify->AfterValueChange(pField); |
1172 } | 1163 } |
1173 } | 1164 } |
1174 if (CPDF_InterForm::m_bUpdateAP) { | |
1175 pField->UpdateAP(NULL); | |
1176 } | |
1177 } | 1165 } |
| 1166 |
1178 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, | 1167 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, |
1179 FX_BOOL bNotify) { | 1168 FX_BOOL bNotify) { |
1180 if (!pFDF) { | 1169 if (!pFDF) |
1181 return FALSE; | 1170 return FALSE; |
1182 } | 1171 |
1183 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); | 1172 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
1184 if (!pMainDict) { | 1173 if (!pMainDict) |
1185 return FALSE; | 1174 return FALSE; |
1186 } | 1175 |
1187 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); | 1176 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
1188 if (!pFields) { | 1177 if (!pFields) |
1189 return FALSE; | 1178 return FALSE; |
1190 } | 1179 |
1191 m_bsEncoding = pMainDict->GetStringBy("Encoding"); | 1180 m_bsEncoding = pMainDict->GetStringBy("Encoding"); |
1192 if (bNotify && m_pFormNotify) { | 1181 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) |
1193 int iRet = m_pFormNotify->BeforeFormImportData(this); | 1182 return FALSE; |
1194 if (iRet < 0) { | 1183 |
1195 return FALSE; | |
1196 } | |
1197 } | |
1198 for (size_t i = 0; i < pFields->GetCount(); i++) { | 1184 for (size_t i = 0; i < pFields->GetCount(); i++) { |
1199 CPDF_Dictionary* pField = pFields->GetDictAt(i); | 1185 CPDF_Dictionary* pField = pFields->GetDictAt(i); |
1200 if (!pField) { | 1186 if (!pField) |
1201 continue; | 1187 continue; |
1202 } | 1188 |
1203 FDF_ImportField(pField, L"", bNotify); | 1189 FDF_ImportField(pField, L"", bNotify); |
1204 } | 1190 } |
1205 if (bNotify && m_pFormNotify) { | 1191 if (bNotify && m_pFormNotify) |
1206 m_pFormNotify->AfterFormImportData(this); | 1192 m_pFormNotify->AfterFormImportData(this); |
1207 } | |
1208 return TRUE; | 1193 return TRUE; |
1209 } | 1194 } |
1210 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { | 1195 |
1211 m_pFormNotify = (CPDF_FormNotify*)pNotify; | 1196 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
| 1197 m_pFormNotify = pNotify; |
1212 } | 1198 } |
OLD | NEW |