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 "core/fpdfdoc/cpdf_interform.h" |
| 8 |
| 9 #include <utility> |
7 #include <vector> | 10 #include <vector> |
8 | 11 |
9 #include "core/fpdfapi/font/cpdf_font.h" | 12 #include "core/fpdfapi/font/cpdf_font.h" |
10 #include "core/fpdfapi/font/cpdf_fontencoding.h" | 13 #include "core/fpdfapi/font/cpdf_fontencoding.h" |
11 #include "core/fpdfapi/page/cpdf_page.h" | 14 #include "core/fpdfapi/page/cpdf_page.h" |
12 #include "core/fpdfapi/parser/cfdf_document.h" | 15 #include "core/fpdfapi/parser/cfdf_document.h" |
13 #include "core/fpdfapi/parser/cpdf_array.h" | 16 #include "core/fpdfapi/parser/cpdf_array.h" |
14 #include "core/fpdfapi/parser/cpdf_document.h" | 17 #include "core/fpdfapi/parser/cpdf_document.h" |
| 18 #include "core/fpdfapi/parser/cpdf_name.h" |
15 #include "core/fpdfapi/parser/cpdf_reference.h" | 19 #include "core/fpdfapi/parser/cpdf_reference.h" |
16 #include "core/fpdfapi/parser/cpdf_string.h" | 20 #include "core/fpdfapi/parser/cpdf_string.h" |
17 #include "core/fpdfdoc/cpdf_filespec.h" | 21 #include "core/fpdfdoc/cpdf_filespec.h" |
18 #include "core/fpdfdoc/cpdf_formcontrol.h" | 22 #include "core/fpdfdoc/cpdf_formcontrol.h" |
19 #include "core/fpdfdoc/cpdf_interform.h" | |
20 #include "core/fxge/cfx_substfont.h" | 23 #include "core/fxge/cfx_substfont.h" |
21 #include "core/fxge/fx_font.h" | 24 #include "core/fxge/fx_font.h" |
22 #include "third_party/base/stl_util.h" | 25 #include "third_party/base/stl_util.h" |
23 | 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 const int nMaxRecursion = 32; | 29 const int nMaxRecursion = 32; |
27 | 30 |
28 const struct SupportFieldEncoding { | 31 const struct SupportFieldEncoding { |
29 const FX_CHAR* m_name; | 32 const FX_CHAR* m_name; |
(...skipping 23 matching lines...) Expand all Loading... |
53 CPDF_Document* pDocument, | 56 CPDF_Document* pDocument, |
54 const CPDF_Font* pFont, | 57 const CPDF_Font* pFont, |
55 CFX_ByteString& csNameTag); | 58 CFX_ByteString& csNameTag); |
56 | 59 |
57 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { | 60 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
58 if (!pDocument) | 61 if (!pDocument) |
59 return; | 62 return; |
60 | 63 |
61 if (!pFormDict) { | 64 if (!pFormDict) { |
62 pFormDict = pDocument->NewIndirect<CPDF_Dictionary>(); | 65 pFormDict = pDocument->NewIndirect<CPDF_Dictionary>(); |
63 pDocument->GetRoot()->SetReferenceFor("AcroForm", pDocument, | 66 pDocument->GetRoot()->SetNewFor<CPDF_Reference>("AcroForm", pDocument, |
64 pFormDict->GetObjNum()); | 67 pFormDict->GetObjNum()); |
65 } | 68 } |
66 | 69 |
67 CFX_ByteString csDA; | 70 CFX_ByteString csDA; |
68 if (!pFormDict->KeyExist("DR")) { | 71 if (!pFormDict->KeyExist("DR")) { |
69 CFX_ByteString csBaseName; | 72 CFX_ByteString csBaseName; |
70 CFX_ByteString csDefault; | 73 CFX_ByteString csDefault; |
71 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 74 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
72 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); | 75 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); |
73 if (pFont) { | 76 if (pFont) { |
74 AddFont(pFormDict, pDocument, pFont, csBaseName); | 77 AddFont(pFormDict, pDocument, pFont, csBaseName); |
(...skipping 12 matching lines...) Expand all Loading... |
87 } | 90 } |
88 } | 91 } |
89 if (pFont) | 92 if (pFont) |
90 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; | 93 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; |
91 } | 94 } |
92 if (!csDA.IsEmpty()) | 95 if (!csDA.IsEmpty()) |
93 csDA += " "; | 96 csDA += " "; |
94 | 97 |
95 csDA += "0 g"; | 98 csDA += "0 g"; |
96 if (!pFormDict->KeyExist("DA")) | 99 if (!pFormDict->KeyExist("DA")) |
97 pFormDict->SetStringFor("DA", csDA); | 100 pFormDict->SetNewFor<CPDF_String>("DA", csDA, false); |
98 } | 101 } |
99 | 102 |
100 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | 103 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, |
101 CPDF_Document* pDocument, | 104 CPDF_Document* pDocument, |
102 CFX_ByteString csNameTag) { | 105 CFX_ByteString csNameTag) { |
103 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); | 106 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); |
104 if (!pFormDict || csAlias.IsEmpty()) | 107 if (!pFormDict || csAlias.IsEmpty()) |
105 return nullptr; | 108 return nullptr; |
106 | 109 |
107 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 110 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
(...skipping 23 matching lines...) Expand all Loading... |
131 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 134 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
132 if (!pDR) | 135 if (!pDR) |
133 return nullptr; | 136 return nullptr; |
134 | 137 |
135 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | 138 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
136 if (!pFonts) | 139 if (!pFonts) |
137 return nullptr; | 140 return nullptr; |
138 | 141 |
139 for (const auto& it : *pFonts) { | 142 for (const auto& it : *pFonts) { |
140 const CFX_ByteString& csKey = it.first; | 143 const CFX_ByteString& csKey = it.first; |
141 CPDF_Object* pObj = it.second; | 144 if (!it.second) |
142 if (!pObj) | |
143 continue; | 145 continue; |
144 | 146 |
145 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 147 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
146 if (!pElement) | 148 if (!pElement) |
147 continue; | 149 continue; |
148 if (pElement->GetStringFor("Type") != "Font") | 150 if (pElement->GetStringFor("Type") != "Font") |
149 continue; | 151 continue; |
150 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 152 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
151 if (!pFind) | 153 if (!pFind) |
152 continue; | 154 continue; |
153 | 155 |
154 CFX_SubstFont* pSubst = pFind->GetSubstFont(); | 156 CFX_SubstFont* pSubst = pFind->GetSubstFont(); |
155 if (!pSubst) | 157 if (!pSubst) |
(...skipping 16 matching lines...) Expand all Loading... |
172 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 174 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
173 if (!pDR) | 175 if (!pDR) |
174 return false; | 176 return false; |
175 | 177 |
176 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | 178 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
177 if (!pFonts) | 179 if (!pFonts) |
178 return false; | 180 return false; |
179 | 181 |
180 for (const auto& it : *pFonts) { | 182 for (const auto& it : *pFonts) { |
181 const CFX_ByteString& csKey = it.first; | 183 const CFX_ByteString& csKey = it.first; |
182 CPDF_Object* pObj = it.second; | 184 if (!it.second) |
183 if (!pObj) | |
184 continue; | 185 continue; |
185 | 186 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
186 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | |
187 if (!pElement) | 187 if (!pElement) |
188 continue; | 188 continue; |
189 if (pElement->GetStringFor("Type") != "Font") | 189 if (pElement->GetStringFor("Type") != "Font") |
190 continue; | 190 continue; |
191 if (pFont->GetFontDict() == pElement) { | 191 if (pFont->GetFontDict() == pElement) { |
192 csNameTag = csKey; | 192 csNameTag = csKey; |
193 return true; | 193 return true; |
194 } | 194 } |
195 } | 195 } |
196 return false; | 196 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
209 return false; | 209 return false; |
210 | 210 |
211 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | 211 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
212 if (!pFonts) | 212 if (!pFonts) |
213 return false; | 213 return false; |
214 if (csFontName.GetLength() > 0) | 214 if (csFontName.GetLength() > 0) |
215 csFontName.Remove(' '); | 215 csFontName.Remove(' '); |
216 | 216 |
217 for (const auto& it : *pFonts) { | 217 for (const auto& it : *pFonts) { |
218 const CFX_ByteString& csKey = it.first; | 218 const CFX_ByteString& csKey = it.first; |
219 CPDF_Object* pObj = it.second; | 219 if (!it.second) |
220 if (!pObj) | |
221 continue; | 220 continue; |
222 | 221 |
223 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 222 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
224 if (!pElement) | 223 if (!pElement) |
225 continue; | 224 continue; |
226 if (pElement->GetStringFor("Type") != "Font") | 225 if (pElement->GetStringFor("Type") != "Font") |
227 continue; | 226 continue; |
228 | |
229 pFont = pDocument->LoadFont(pElement); | 227 pFont = pDocument->LoadFont(pElement); |
230 if (!pFont) | 228 if (!pFont) |
231 continue; | 229 continue; |
232 | 230 |
233 CFX_ByteString csBaseFont; | 231 CFX_ByteString csBaseFont; |
234 csBaseFont = pFont->GetBaseFont(); | 232 csBaseFont = pFont->GetBaseFont(); |
235 csBaseFont.Remove(' '); | 233 csBaseFont.Remove(' '); |
236 if (csBaseFont == csFontName) { | 234 if (csBaseFont == csFontName) { |
237 csNameTag = csKey; | 235 csNameTag = csKey; |
238 return true; | 236 return true; |
(...skipping 13 matching lines...) Expand all Loading... |
252 | 250 |
253 CFX_ByteString csTag; | 251 CFX_ByteString csTag; |
254 if (FindFont(pFormDict, pFont, csTag)) { | 252 if (FindFont(pFormDict, pFont, csTag)) { |
255 csNameTag = csTag; | 253 csNameTag = csTag; |
256 return; | 254 return; |
257 } | 255 } |
258 if (!pFormDict) | 256 if (!pFormDict) |
259 InitDict(pFormDict, pDocument); | 257 InitDict(pFormDict, pDocument); |
260 | 258 |
261 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 259 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
262 if (!pDR) { | 260 if (!pDR) |
263 pDR = new CPDF_Dictionary(pDocument->GetByteStringPool()); | 261 pDR = pFormDict->SetNewFor<CPDF_Dictionary>("DR"); |
264 pFormDict->SetFor("DR", pDR); | 262 |
265 } | |
266 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | 263 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
267 if (!pFonts) { | 264 if (!pFonts) |
268 pFonts = new CPDF_Dictionary(pDocument->GetByteStringPool()); | 265 pFonts = pDR->SetNewFor<CPDF_Dictionary>("Font"); |
269 pDR->SetFor("Font", pFonts); | 266 |
270 } | |
271 if (csNameTag.IsEmpty()) | 267 if (csNameTag.IsEmpty()) |
272 csNameTag = pFont->GetBaseFont(); | 268 csNameTag = pFont->GetBaseFont(); |
273 | 269 |
274 csNameTag.Remove(' '); | 270 csNameTag.Remove(' '); |
275 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, | 271 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, |
276 csNameTag.c_str()); | 272 csNameTag.c_str()); |
277 pFonts->SetReferenceFor(csNameTag, pDocument, | 273 pFonts->SetNewFor<CPDF_Reference>(csNameTag, pDocument, |
278 pFont->GetFontDict()->GetObjNum()); | 274 pFont->GetFontDict()->GetObjNum()); |
279 } | 275 } |
280 | 276 |
281 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, | 277 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, |
282 CPDF_Document* pDocument, | 278 CPDF_Document* pDocument, |
283 uint8_t charSet, | 279 uint8_t charSet, |
284 CFX_ByteString& csNameTag) { | 280 CFX_ByteString& csNameTag) { |
285 if (!pFormDict) | 281 if (!pFormDict) |
286 InitDict(pFormDict, pDocument); | 282 InitDict(pFormDict, pDocument); |
287 | 283 |
288 CFX_ByteString csTemp; | 284 CFX_ByteString csTemp; |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 pFieldDict->GetStringFor("Subtype") == "Widget") { | 1094 pFieldDict->GetStringFor("Subtype") == "Widget") { |
1099 pParent = pFieldDict->GetDictFor("Parent"); | 1095 pParent = pFieldDict->GetDictFor("Parent"); |
1100 if (!pParent) | 1096 if (!pParent) |
1101 pParent = pFieldDict; | 1097 pParent = pFieldDict; |
1102 } | 1098 } |
1103 | 1099 |
1104 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { | 1100 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { |
1105 if (pFieldDict->KeyExist("FT")) { | 1101 if (pFieldDict->KeyExist("FT")) { |
1106 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT"); | 1102 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT"); |
1107 if (pFTValue) | 1103 if (pFTValue) |
1108 pParent->SetFor("FT", pFTValue->Clone().release()); | 1104 pParent->SetFor("FT", pFTValue->Clone()); |
1109 } | 1105 } |
1110 | 1106 |
1111 if (pFieldDict->KeyExist("Ff")) { | 1107 if (pFieldDict->KeyExist("Ff")) { |
1112 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff"); | 1108 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff"); |
1113 if (pFfValue) | 1109 if (pFfValue) |
1114 pParent->SetFor("Ff", pFfValue->Clone().release()); | 1110 pParent->SetFor("Ff", pFfValue->Clone()); |
1115 } | 1111 } |
1116 } | 1112 } |
1117 | 1113 |
1118 pField = new CPDF_FormField(this, pParent); | 1114 pField = new CPDF_FormField(this, pParent); |
1119 CPDF_Object* pTObj = pDict->GetObjectFor("T"); | 1115 CPDF_Object* pTObj = pDict->GetObjectFor("T"); |
1120 if (ToReference(pTObj)) { | 1116 if (ToReference(pTObj)) { |
1121 std::unique_ptr<CPDF_Object> pClone = pTObj->CloneDirectObject(); | 1117 std::unique_ptr<CPDF_Object> pClone = pTObj->CloneDirectObject(); |
1122 if (pClone) | 1118 if (pClone) |
1123 pDict->SetFor("T", pClone.release()); | 1119 pDict->SetFor("T", std::move(pClone)); |
1124 else | 1120 else |
1125 pDict->SetNameFor("T", ""); | 1121 pDict->SetNewFor<CPDF_Name>("T", ""); |
1126 } | 1122 } |
1127 m_pFieldTree->SetField(csWName, pField); | 1123 m_pFieldTree->SetField(csWName, pField); |
1128 } | 1124 } |
1129 | 1125 |
1130 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); | 1126 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); |
1131 if (pKids) { | 1127 if (pKids) { |
1132 for (size_t i = 0; i < pKids->GetCount(); i++) { | 1128 for (size_t i = 0; i < pKids->GetCount(); i++) { |
1133 CPDF_Dictionary* pKid = pKids->GetDictAt(i); | 1129 CPDF_Dictionary* pKid = pKids->GetDictAt(i); |
1134 if (!pKid) | 1130 if (!pKid) |
1135 continue; | 1131 continue; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 bool bIncludeOrExclude, | 1199 bool bIncludeOrExclude, |
1204 bool bSimpleFileSpec) const { | 1200 bool bSimpleFileSpec) const { |
1205 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); | 1201 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
1206 if (!pDoc) | 1202 if (!pDoc) |
1207 return nullptr; | 1203 return nullptr; |
1208 | 1204 |
1209 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); | 1205 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); |
1210 if (!pdf_path.IsEmpty()) { | 1206 if (!pdf_path.IsEmpty()) { |
1211 if (bSimpleFileSpec) { | 1207 if (bSimpleFileSpec) { |
1212 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); | 1208 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
1213 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1209 pMainDict->SetNewFor<CPDF_String>( |
1214 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); | 1210 "F", CFX_ByteString::FromUnicode(wsFilePath), false); |
| 1211 pMainDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsFilePath), |
| 1212 false); |
1215 } else { | 1213 } else { |
1216 CPDF_FileSpec filespec(pDoc->GetByteStringPool()); | 1214 CPDF_FileSpec filespec(pDoc->GetByteStringPool()); |
1217 filespec.SetFileName(pdf_path); | 1215 filespec.SetFileName(pdf_path); |
1218 pMainDict->SetFor("F", filespec.GetObj()); | 1216 pMainDict->SetFor("F", pdfium::WrapUnique(filespec.GetObj())); |
1219 } | 1217 } |
1220 } | 1218 } |
1221 | 1219 |
1222 CPDF_Array* pFields = new CPDF_Array; | 1220 CPDF_Array* pFields = pMainDict->SetNewFor<CPDF_Array>("Fields"); |
1223 pMainDict->SetFor("Fields", pFields); | |
1224 size_t nCount = m_pFieldTree->m_Root.CountFields(); | 1221 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
1225 for (size_t i = 0; i < nCount; ++i) { | 1222 for (size_t i = 0; i < nCount; ++i) { |
1226 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1223 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1227 if (!pField || pField->GetType() == CPDF_FormField::PushButton) | 1224 if (!pField || pField->GetType() == CPDF_FormField::PushButton) |
1228 continue; | 1225 continue; |
1229 | 1226 |
1230 uint32_t dwFlags = pField->GetFieldFlags(); | 1227 uint32_t dwFlags = pField->GetFieldFlags(); |
1231 if (dwFlags & 0x04) | 1228 if (dwFlags & 0x04) |
1232 continue; | 1229 continue; |
1233 | 1230 |
1234 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1231 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
1235 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) | 1232 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) |
1236 continue; | 1233 continue; |
1237 | 1234 |
1238 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); | 1235 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); |
1239 auto pFieldDict = | 1236 auto pFieldDict = |
1240 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 1237 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
1241 pFieldDict->SetFor("T", new CPDF_String(fullname)); | 1238 pFieldDict->SetNewFor<CPDF_String>("T", fullname); |
1242 if (pField->GetType() == CPDF_FormField::CheckBox || | 1239 if (pField->GetType() == CPDF_FormField::CheckBox || |
1243 pField->GetType() == CPDF_FormField::RadioButton) { | 1240 pField->GetType() == CPDF_FormField::RadioButton) { |
1244 CFX_WideString csExport = pField->GetCheckValue(false); | 1241 CFX_WideString csExport = pField->GetCheckValue(false); |
1245 CFX_ByteString csBExport = PDF_EncodeText(csExport); | 1242 CFX_ByteString csBExport = PDF_EncodeText(csExport); |
1246 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); | 1243 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); |
1247 if (pOpt) | 1244 if (pOpt) |
1248 pFieldDict->SetStringFor("V", csBExport); | 1245 pFieldDict->SetNewFor<CPDF_String>("V", csBExport, false); |
1249 else | 1246 else |
1250 pFieldDict->SetNameFor("V", csBExport); | 1247 pFieldDict->SetNewFor<CPDF_Name>("V", csBExport); |
1251 } else { | 1248 } else { |
1252 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); | 1249 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); |
1253 if (pV) | 1250 if (pV) |
1254 pFieldDict->SetFor("V", pV->CloneDirectObject().release()); | 1251 pFieldDict->SetFor("V", pV->CloneDirectObject()); |
1255 } | 1252 } |
1256 pFields->Add(std::move(pFieldDict)); | 1253 pFields->Add(std::move(pFieldDict)); |
1257 } | 1254 } |
1258 } | 1255 } |
1259 return pDoc; | 1256 return pDoc; |
1260 } | 1257 } |
1261 | 1258 |
1262 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, | 1259 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, |
1263 const CFX_WideString& parent_name, | 1260 const CFX_WideString& parent_name, |
1264 bool bNotify, | 1261 bool bNotify, |
(...skipping 17 matching lines...) Expand all Loading... |
1282 if (!pFieldDict->KeyExist("V")) | 1279 if (!pFieldDict->KeyExist("V")) |
1283 return; | 1280 return; |
1284 | 1281 |
1285 CPDF_FormField* pField = m_pFieldTree->GetField(name); | 1282 CPDF_FormField* pField = m_pFieldTree->GetField(name); |
1286 if (!pField) | 1283 if (!pField) |
1287 return; | 1284 return; |
1288 | 1285 |
1289 CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding); | 1286 CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding); |
1290 int iType = pField->GetFieldType(); | 1287 int iType = pField->GetFieldType(); |
1291 if (bNotify && m_pFormNotify) { | 1288 if (bNotify && m_pFormNotify) { |
1292 int iRet = 0; | 1289 if (iType == FIELDTYPE_LISTBOX) { |
1293 if (iType == FIELDTYPE_LISTBOX) | 1290 if (m_pFormNotify->BeforeSelectionChange(pField, csWValue) < 0) |
1294 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); | 1291 return; |
1295 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) | 1292 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { |
1296 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); | 1293 if (m_pFormNotify->BeforeValueChange(pField, csWValue) < 0) |
1297 | 1294 return; |
1298 if (iRet < 0) | 1295 } |
1299 return; | |
1300 } | 1296 } |
1301 | |
1302 pField->SetValue(csWValue); | 1297 pField->SetValue(csWValue); |
1303 CPDF_FormField::Type eType = pField->GetType(); | 1298 CPDF_FormField::Type eType = pField->GetType(); |
1304 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && | 1299 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && |
1305 pFieldDict->KeyExist("Opt")) { | 1300 pFieldDict->KeyExist("Opt")) { |
1306 pField->m_pDict->SetFor( | 1301 pField->m_pDict->SetFor( |
1307 "Opt", | 1302 "Opt", pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject()); |
1308 pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject().release()); | |
1309 } | 1303 } |
1310 | 1304 |
1311 if (bNotify && m_pFormNotify) { | 1305 if (bNotify && m_pFormNotify) { |
1312 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) | 1306 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) |
1313 m_pFormNotify->AfterCheckedStatusChange(pField); | 1307 m_pFormNotify->AfterCheckedStatusChange(pField); |
1314 else if (iType == FIELDTYPE_LISTBOX) | 1308 else if (iType == FIELDTYPE_LISTBOX) |
1315 m_pFormNotify->AfterSelectionChange(pField); | 1309 m_pFormNotify->AfterSelectionChange(pField); |
1316 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) | 1310 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) |
1317 m_pFormNotify->AfterValueChange(pField); | 1311 m_pFormNotify->AfterValueChange(pField); |
1318 } | 1312 } |
1319 } | 1313 } |
1320 | 1314 |
1321 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { | 1315 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
1322 m_pFormNotify = pNotify; | 1316 m_pFormNotify = pNotify; |
1323 } | 1317 } |
OLD | NEW |