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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; | 89 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; |
90 } | 90 } |
91 if (!csDA.IsEmpty()) | 91 if (!csDA.IsEmpty()) |
92 csDA += " "; | 92 csDA += " "; |
93 | 93 |
94 csDA += "0 g"; | 94 csDA += "0 g"; |
95 if (!pFormDict->KeyExist("DA")) | 95 if (!pFormDict->KeyExist("DA")) |
96 pFormDict->SetStringFor("DA", csDA); | 96 pFormDict->SetStringFor("DA", csDA); |
97 } | 97 } |
98 | 98 |
99 uint32_t CountFonts(CPDF_Dictionary* pFormDict) { | |
100 if (!pFormDict) | |
101 return 0; | |
102 | |
103 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | |
104 if (!pDR) | |
105 return 0; | |
106 | |
107 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | |
108 if (!pFonts) | |
109 return 0; | |
110 | |
111 uint32_t dwCount = 0; | |
112 for (const auto& it : *pFonts) { | |
113 CPDF_Object* pObj = it.second; | |
114 if (!pObj) | |
115 continue; | |
116 | |
117 if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { | |
118 if (pDirect->GetStringFor("Type") == "Font") | |
119 dwCount++; | |
120 } | |
121 } | |
122 return dwCount; | |
123 } | |
124 | |
125 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | |
126 CPDF_Document* pDocument, | |
127 uint32_t index, | |
128 CFX_ByteString& csNameTag) { | |
129 if (!pFormDict) | |
130 return nullptr; | |
131 | |
132 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | |
133 if (!pDR) | |
134 return nullptr; | |
135 | |
136 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | |
137 if (!pFonts) | |
138 return nullptr; | |
139 | |
140 uint32_t dwCount = 0; | |
141 for (const auto& it : *pFonts) { | |
142 const CFX_ByteString& csKey = it.first; | |
143 CPDF_Object* pObj = it.second; | |
144 if (!pObj) | |
145 continue; | |
146 | |
147 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | |
148 if (!pElement) | |
149 continue; | |
150 if (pElement->GetStringFor("Type") != "Font") | |
151 continue; | |
152 if (dwCount == index) { | |
153 csNameTag = csKey; | |
154 return pDocument->LoadFont(pElement); | |
155 } | |
156 dwCount++; | |
157 } | |
158 return nullptr; | |
159 } | |
160 | |
161 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | 99 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, |
162 CPDF_Document* pDocument, | 100 CPDF_Document* pDocument, |
163 CFX_ByteString csNameTag) { | 101 CFX_ByteString csNameTag) { |
164 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); | 102 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); |
165 if (!pFormDict || csAlias.IsEmpty()) | 103 if (!pFormDict || csAlias.IsEmpty()) |
166 return nullptr; | 104 return nullptr; |
167 | 105 |
168 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 106 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
169 if (!pDR) | 107 if (!pDR) |
170 return nullptr; | 108 return nullptr; |
171 | 109 |
172 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | 110 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
173 if (!pFonts) | 111 if (!pFonts) |
174 return nullptr; | 112 return nullptr; |
175 | 113 |
176 CPDF_Dictionary* pElement = pFonts->GetDictFor(csAlias); | 114 CPDF_Dictionary* pElement = pFonts->GetDictFor(csAlias); |
177 if (!pElement) | 115 if (!pElement) |
178 return nullptr; | 116 return nullptr; |
179 | 117 |
180 if (pElement->GetStringFor("Type") == "Font") | 118 if (pElement->GetStringFor("Type") == "Font") |
181 return pDocument->LoadFont(pElement); | 119 return pDocument->LoadFont(pElement); |
182 return nullptr; | 120 return nullptr; |
183 } | 121 } |
184 | 122 |
185 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, | |
186 CPDF_Document* pDocument, | |
187 CFX_ByteString csFontName, | |
188 CFX_ByteString& csNameTag) { | |
189 if (!pFormDict || csFontName.IsEmpty()) | |
190 return nullptr; | |
191 | |
192 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | |
193 if (!pDR) | |
194 return nullptr; | |
195 | |
196 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | |
197 if (!pFonts) | |
198 return nullptr; | |
199 | |
200 for (const auto& it : *pFonts) { | |
201 const CFX_ByteString& csKey = it.first; | |
202 CPDF_Object* pObj = it.second; | |
203 if (!pObj) | |
204 continue; | |
205 | |
206 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | |
207 if (!pElement) | |
208 continue; | |
209 if (pElement->GetStringFor("Type") != "Font") | |
210 continue; | |
211 | |
212 CPDF_Font* pFind = pDocument->LoadFont(pElement); | |
213 if (!pFind) | |
214 continue; | |
215 | |
216 CFX_ByteString csBaseFont; | |
217 csBaseFont = pFind->GetBaseFont(); | |
218 csBaseFont.Remove(' '); | |
219 if (csBaseFont == csFontName) { | |
220 csNameTag = csKey; | |
221 return pFind; | |
222 } | |
223 } | |
224 return nullptr; | |
225 } | |
226 | |
227 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, | 123 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, |
228 CPDF_Document* pDocument, | 124 CPDF_Document* pDocument, |
229 uint8_t charSet, | 125 uint8_t charSet, |
230 CFX_ByteString& csNameTag) { | 126 CFX_ByteString& csNameTag) { |
231 if (!pFormDict) | 127 if (!pFormDict) |
232 return nullptr; | 128 return nullptr; |
233 | 129 |
234 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 130 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
235 if (!pDR) | 131 if (!pDR) |
236 return nullptr; | 132 return nullptr; |
(...skipping 22 matching lines...) Expand all Loading... | |
259 continue; | 155 continue; |
260 | 156 |
261 if (pSubst->m_Charset == (int)charSet) { | 157 if (pSubst->m_Charset == (int)charSet) { |
262 csNameTag = csKey; | 158 csNameTag = csKey; |
263 return pFind; | 159 return pFind; |
264 } | 160 } |
265 } | 161 } |
266 return nullptr; | 162 return nullptr; |
267 } | 163 } |
268 | 164 |
269 CPDF_Font* GetDefaultFont(CPDF_Dictionary* pFormDict, | |
270 CPDF_Document* pDocument) { | |
271 if (!pFormDict) | |
272 return nullptr; | |
273 | |
274 CPDF_DefaultAppearance cDA(pFormDict->GetStringFor("DA")); | |
275 CFX_ByteString csFontNameTag; | |
276 FX_FLOAT fFontSize; | |
277 cDA.GetFont(csFontNameTag, fFontSize); | |
278 return GetFont(pFormDict, pDocument, csFontNameTag); | |
279 } | |
280 | |
281 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, | 165 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, |
282 const CPDF_Font* pFont, | 166 const CPDF_Font* pFont, |
283 CFX_ByteString& csNameTag) { | 167 CFX_ByteString& csNameTag) { |
284 if (!pFormDict || !pFont) | 168 if (!pFormDict || !pFont) |
285 return FALSE; | 169 return FALSE; |
286 | 170 |
287 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 171 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
288 if (!pDR) | 172 if (!pDR) |
289 return FALSE; | 173 return FALSE; |
290 | 174 |
(...skipping 13 matching lines...) Expand all Loading... | |
304 if (pElement->GetStringFor("Type") != "Font") | 188 if (pElement->GetStringFor("Type") != "Font") |
305 continue; | 189 continue; |
306 if (pFont->GetFontDict() == pElement) { | 190 if (pFont->GetFontDict() == pElement) { |
307 csNameTag = csKey; | 191 csNameTag = csKey; |
308 return TRUE; | 192 return TRUE; |
309 } | 193 } |
310 } | 194 } |
311 return FALSE; | 195 return FALSE; |
312 } | 196 } |
313 | 197 |
314 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, | |
315 CPDF_Document* pDocument, | |
316 CFX_ByteString& csNameTag) { | |
317 csNameTag.clear(); | |
318 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | |
319 CPDF_Font* pFont = GetDefaultFont(pFormDict, pDocument); | |
320 if (pFont) { | |
321 CFX_SubstFont* pSubst = pFont->GetSubstFont(); | |
322 if (pSubst && pSubst->m_Charset == (int)charSet) { | |
323 FindFont(pFormDict, pFont, csNameTag); | |
324 return pFont; | |
325 } | |
326 } | |
327 return GetNativeFont(pFormDict, pDocument, charSet, csNameTag); | |
328 } | |
329 | |
330 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, | 198 FX_BOOL FindFont(CPDF_Dictionary* pFormDict, |
331 CPDF_Document* pDocument, | 199 CPDF_Document* pDocument, |
332 CFX_ByteString csFontName, | 200 CFX_ByteString csFontName, |
333 CPDF_Font*& pFont, | 201 CPDF_Font*& pFont, |
334 CFX_ByteString& csNameTag) { | 202 CFX_ByteString& csNameTag) { |
335 if (!pFormDict) | 203 if (!pFormDict) |
336 return FALSE; | 204 return FALSE; |
337 | 205 |
338 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | 206 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
339 if (!pDR) | 207 if (!pDR) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 CFX_ByteString& csNameTag) { | 283 CFX_ByteString& csNameTag) { |
416 if (!pFormDict) | 284 if (!pFormDict) |
417 InitDict(pFormDict, pDocument); | 285 InitDict(pFormDict, pDocument); |
418 | 286 |
419 CFX_ByteString csTemp; | 287 CFX_ByteString csTemp; |
420 CPDF_Font* pFont = GetNativeFont(pFormDict, pDocument, charSet, csTemp); | 288 CPDF_Font* pFont = GetNativeFont(pFormDict, pDocument, charSet, csTemp); |
421 if (pFont) { | 289 if (pFont) { |
422 csNameTag = csTemp; | 290 csNameTag = csTemp; |
423 return pFont; | 291 return pFont; |
424 } | 292 } |
425 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); | 293 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, nullptr); |
426 if (!csFontName.IsEmpty() && | 294 if (!csFontName.IsEmpty() && |
427 FindFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { | 295 FindFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { |
428 return pFont; | 296 return pFont; |
429 } | 297 } |
430 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); | 298 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); |
431 if (pFont) | 299 if (pFont) |
432 AddFont(pFormDict, pDocument, pFont, csNameTag); | 300 AddFont(pFormDict, pDocument, pFont, csNameTag); |
433 | 301 |
434 return pFont; | 302 return pFont; |
435 } | 303 } |
436 | 304 |
437 void RemoveFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { | |
438 if (!pFormDict || !pFont) | |
439 return; | |
440 | |
441 CFX_ByteString csTag; | |
442 if (!FindFont(pFormDict, pFont, csTag)) | |
443 return; | |
444 | |
445 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | |
446 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | |
447 pFonts->RemoveFor(csTag); | |
448 } | |
449 | |
450 void RemoveFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { | |
451 if (!pFormDict || csNameTag.IsEmpty()) | |
452 return; | |
453 | |
454 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); | |
455 if (!pDR) | |
456 return; | |
457 | |
458 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); | |
459 if (!pFonts) | |
460 return; | |
461 | |
462 pFonts->RemoveFor(csNameTag); | |
463 } | |
464 | |
465 class CFieldNameExtractor { | 305 class CFieldNameExtractor { |
466 public: | 306 public: |
467 explicit CFieldNameExtractor(const CFX_WideString& full_name) | 307 explicit CFieldNameExtractor(const CFX_WideString& full_name) |
468 : m_FullName(full_name) { | 308 : m_FullName(full_name) { |
469 m_pCur = m_FullName.c_str(); | 309 m_pCur = m_FullName.c_str(); |
470 m_pEnd = m_pCur + m_FullName.GetLength(); | 310 m_pEnd = m_pCur + m_FullName.GetLength(); |
471 } | 311 } |
472 | 312 |
473 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { | 313 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { |
474 pSubName = m_pCur; | 314 pSubName = m_pCur; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 lf.lfCharSet = charSet; | 366 lf.lfCharSet = charSet; |
527 lf.lfPitchAndFamily = pitchAndFamily; | 367 lf.lfPitchAndFamily = pitchAndFamily; |
528 if (pcsFontName) { | 368 if (pcsFontName) { |
529 // TODO(dsinclair): Should this be strncpy? | 369 // TODO(dsinclair): Should this be strncpy? |
530 strcpy(lf.lfFaceName, pcsFontName); | 370 strcpy(lf.lfFaceName, pcsFontName); |
531 } | 371 } |
532 return RetrieveSpecificFont(lf); | 372 return RetrieveSpecificFont(lf); |
533 } | 373 } |
534 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 374 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
535 | 375 |
376 int CompareFieldName(const CFX_WideString& name1, const CFX_WideString& name2) { | |
377 const FX_WCHAR* ptr1 = name1.c_str(); | |
378 const FX_WCHAR* ptr2 = name2.c_str(); | |
379 if (name1.GetLength() == name2.GetLength()) | |
380 return name1 == name2 ? 1 : 0; | |
381 | |
382 int i = 0; | |
383 while (ptr1[i] == ptr2[i]) | |
384 i++; | |
385 if (i == name1.GetLength()) | |
386 return 2; | |
387 if (i == name2.GetLength()) | |
388 return 3; | |
389 return 0; | |
390 } | |
391 | |
536 } // namespace | 392 } // namespace |
537 | 393 |
538 class CFieldTree { | 394 class CFieldTree { |
539 public: | 395 public: |
540 class Node { | 396 class Node { |
541 public: | 397 public: |
542 Node() : m_pField(nullptr) {} | 398 Node() : m_pField(nullptr) {} |
543 Node(const CFX_WideString& short_name, CPDF_FormField* pField) | 399 Node(const CFX_WideString& short_name, CPDF_FormField* pField) |
544 : m_ShortName(short_name), m_pField(pField) {} | 400 : m_ShortName(short_name), m_pField(pField) {} |
545 ~Node() {} | 401 ~Node() {} |
546 | 402 |
547 void AddChildNode(Node* pNode) { m_Children.push_back(pNode); } | 403 void AddChildNode(Node* pNode) { m_Children.push_back(pNode); } |
548 | 404 |
549 size_t GetChildrenCount() const { return m_Children.size(); } | 405 size_t GetChildrenCount() const { return m_Children.size(); } |
550 | 406 |
551 Node* GetChildAt(size_t i) { return m_Children[i]; } | 407 Node* GetChildAt(size_t i) { return m_Children[i]; } |
552 const Node* GetChildAt(size_t i) const { return m_Children[i]; } | 408 const Node* GetChildAt(size_t i) const { return m_Children[i]; } |
553 | 409 |
554 CPDF_FormField* GetFieldAtIndex(int index) { | 410 CPDF_FormField* GetFieldAtIndex(size_t index) { |
555 int nFieldsToGo = index; | 411 size_t nFieldsToGo = index; |
556 return GetFieldInternal(&nFieldsToGo); | 412 return GetFieldInternal(&nFieldsToGo); |
557 } | 413 } |
558 | 414 |
559 int CountFields() const { return CountFieldsInternal(0); } | 415 size_t CountFields() const { return CountFieldsInternal(0); } |
560 | 416 |
561 void SetField(CPDF_FormField* pField) { m_pField = pField; } | 417 void SetField(CPDF_FormField* pField) { m_pField = pField; } |
562 | 418 |
563 CPDF_FormField* GetField() { return m_pField; } | 419 CPDF_FormField* GetField() { return m_pField; } |
564 const CPDF_FormField* GetField() const { return m_pField; } | 420 const CPDF_FormField* GetField() const { return m_pField; } |
565 | 421 |
566 const CFX_WideString& GetShortName() const { return m_ShortName; } | 422 const CFX_WideString& GetShortName() const { return m_ShortName; } |
567 | 423 |
568 private: | 424 private: |
569 CPDF_FormField* GetFieldInternal(int* pFieldsToGo) { | 425 CPDF_FormField* GetFieldInternal(size_t* pFieldsToGo) { |
570 if (m_pField) { | 426 if (m_pField) { |
571 if (*pFieldsToGo == 0) | 427 if (*pFieldsToGo == 0) |
572 return m_pField; | 428 return m_pField; |
573 | 429 |
574 --*pFieldsToGo; | 430 --*pFieldsToGo; |
575 return nullptr; | 431 return nullptr; |
576 } | 432 } |
577 for (size_t i = 0; i < GetChildrenCount(); ++i) { | 433 for (size_t i = 0; i < GetChildrenCount(); ++i) { |
578 CPDF_FormField* pField = GetChildAt(i)->GetFieldInternal(pFieldsToGo); | 434 CPDF_FormField* pField = GetChildAt(i)->GetFieldInternal(pFieldsToGo); |
579 if (pField) | 435 if (pField) |
580 return pField; | 436 return pField; |
581 } | 437 } |
582 return nullptr; | 438 return nullptr; |
583 } | 439 } |
584 | 440 |
585 int CountFieldsInternal(int nLevel) const { | 441 size_t CountFieldsInternal(int nLevel) const { |
586 if (nLevel > nMaxRecursion) | 442 if (nLevel > nMaxRecursion) |
587 return 0; | 443 return 0; |
588 if (m_pField) | 444 if (m_pField) |
589 return 1; | 445 return 1; |
590 | 446 |
591 int count = 0; | 447 size_t count = 0; |
592 for (size_t i = 0; i < GetChildrenCount(); ++i) | 448 for (size_t i = 0; i < GetChildrenCount(); ++i) |
593 count += GetChildAt(i)->CountFieldsInternal(nLevel + 1); | 449 count += GetChildAt(i)->CountFieldsInternal(nLevel + 1); |
594 return count; | 450 return count; |
595 } | 451 } |
596 | 452 |
597 std::vector<Node*> m_Children; | 453 std::vector<Node*> m_Children; |
598 CFX_WideString m_ShortName; | 454 CFX_WideString m_ShortName; |
599 CPDF_FormField* m_pField; | 455 CPDF_FormField* m_pField; |
600 }; | 456 }; |
601 | 457 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 return; | 659 return; |
804 | 660 |
805 m_pFormDict = pRoot->GetDictFor("AcroForm"); | 661 m_pFormDict = pRoot->GetDictFor("AcroForm"); |
806 if (!m_pFormDict) | 662 if (!m_pFormDict) |
807 return; | 663 return; |
808 | 664 |
809 CPDF_Array* pFields = m_pFormDict->GetArrayFor("Fields"); | 665 CPDF_Array* pFields = m_pFormDict->GetArrayFor("Fields"); |
810 if (!pFields) | 666 if (!pFields) |
811 return; | 667 return; |
812 | 668 |
813 for (size_t i = 0; i < pFields->GetCount(); i++) | 669 for (size_t i = 0; i < pFields->GetCount(); ++i) |
814 LoadField(pFields->GetDictAt(i)); | 670 LoadField(pFields->GetDictAt(i), 0); |
815 } | 671 } |
816 | 672 |
817 CPDF_InterForm::~CPDF_InterForm() { | 673 CPDF_InterForm::~CPDF_InterForm() { |
818 for (auto it : m_ControlMap) | 674 for (auto it : m_ControlMap) |
819 delete it.second; | 675 delete it.second; |
820 | 676 |
821 int nCount = m_pFieldTree->m_Root.CountFields(); | 677 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
822 for (int i = 0; i < nCount; ++i) | 678 for (size_t i = 0; i < nCount; ++i) |
823 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); | 679 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); |
824 } | 680 } |
825 | 681 |
826 FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE; | 682 bool CPDF_InterForm::s_bUpdateAP = true; |
827 | 683 |
828 FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() { | 684 bool CPDF_InterForm::IsUpdateAPEnabled() { |
829 return s_bUpdateAP; | 685 return s_bUpdateAP; |
830 } | 686 } |
831 | 687 |
832 void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) { | 688 void CPDF_InterForm::SetUpdateAP(bool bUpdateAP) { |
833 s_bUpdateAP = bUpdateAP; | 689 s_bUpdateAP = bUpdateAP; |
834 } | 690 } |
835 | 691 |
836 CFX_ByteString CPDF_InterForm::GenerateNewResourceName( | 692 CFX_ByteString CPDF_InterForm::GenerateNewResourceName( |
837 const CPDF_Dictionary* pResDict, | 693 const CPDF_Dictionary* pResDict, |
838 const FX_CHAR* csType, | 694 const FX_CHAR* csType, |
839 int iMinLen, | 695 int iMinLen, |
840 const FX_CHAR* csPrefix) { | 696 const FX_CHAR* csPrefix) { |
841 CFX_ByteString csStr = csPrefix; | 697 CFX_ByteString csStr = csPrefix; |
842 CFX_ByteString csBType = csType; | 698 CFX_ByteString csBType = csType; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 if (pLogFont) | 790 if (pLogFont) |
935 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); | 791 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); |
936 | 792 |
937 csFontName = lf.lfFaceName; | 793 csFontName = lf.lfFaceName; |
938 return csFontName; | 794 return csFontName; |
939 } | 795 } |
940 #endif | 796 #endif |
941 return csFontName; | 797 return csFontName; |
942 } | 798 } |
943 | 799 |
944 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) { | |
945 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
946 return GetNativeFont(GetNativeCharSet(), pLogFont); | |
947 #else | |
948 return CFX_ByteString(); | |
949 #endif | |
950 } | |
951 | |
952 CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet, | 800 CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet, |
953 CPDF_Document* pDocument) { | 801 CPDF_Document* pDocument) { |
954 if (!pDocument) | 802 if (!pDocument) |
955 return nullptr; | 803 return nullptr; |
956 | 804 |
957 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 805 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
958 LOGFONTA lf; | 806 LOGFONTA lf; |
959 CFX_ByteString csFontName = GetNativeFont(charSet, &lf); | 807 CFX_ByteString csFontName = GetNativeFont(charSet, &lf); |
960 if (!csFontName.IsEmpty()) { | 808 if (!csFontName.IsEmpty()) { |
961 if (csFontName == "Helvetica") | 809 if (csFontName == "Helvetica") |
962 return AddStandardFont(pDocument, csFontName); | 810 return AddStandardFont(pDocument, csFontName); |
963 return pDocument->AddWindowsFont(&lf, FALSE, TRUE); | 811 return pDocument->AddWindowsFont(&lf, FALSE, TRUE); |
964 } | 812 } |
965 #endif | 813 #endif |
966 return nullptr; | 814 return nullptr; |
967 } | 815 } |
968 | 816 |
969 CPDF_Font* CPDF_InterForm::AddNativeFont(CPDF_Document* pDocument) { | 817 CPDF_Font* CPDF_InterForm::AddNativeFont(CPDF_Document* pDocument) { |
970 return pDocument ? AddNativeFont(GetNativeCharSet(), pDocument) : nullptr; | 818 return pDocument ? AddNativeFont(GetNativeCharSet(), pDocument) : nullptr; |
971 } | 819 } |
972 | 820 |
973 FX_BOOL CPDF_InterForm::ValidateFieldName( | 821 bool CPDF_InterForm::ValidateFieldName( |
974 CFX_WideString& csNewFieldName, | 822 CFX_WideString& csNewFieldName, |
975 int iType, | 823 int iType, |
976 const CPDF_FormField* pExcludedField, | 824 const CPDF_FormField* pExcludedField, |
977 const CPDF_FormControl* pExcludedControl) { | 825 const CPDF_FormControl* pExcludedControl) const { |
978 if (csNewFieldName.IsEmpty()) | 826 if (csNewFieldName.IsEmpty()) |
979 return FALSE; | 827 return false; |
980 | 828 |
981 int iPos = 0; | 829 int iPos = 0; |
982 int iLength = csNewFieldName.GetLength(); | 830 int iLength = csNewFieldName.GetLength(); |
983 CFX_WideString csSub; | 831 CFX_WideString csSub; |
984 while (TRUE) { | 832 while (true) { |
985 while (iPos < iLength && | 833 while (iPos < iLength && |
986 (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { | 834 (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { |
987 iPos++; | 835 iPos++; |
988 } | 836 } |
989 if (iPos < iLength && !csSub.IsEmpty()) | 837 if (iPos < iLength && !csSub.IsEmpty()) |
990 csSub += L'.'; | 838 csSub += L'.'; |
991 while (iPos < iLength && csNewFieldName[iPos] != L'.') | 839 while (iPos < iLength && csNewFieldName[iPos] != L'.') |
992 csSub += csNewFieldName[iPos++]; | 840 csSub += csNewFieldName[iPos++]; |
993 for (int i = csSub.GetLength() - 1; i > -1; i--) { | 841 for (int i = csSub.GetLength() - 1; i > -1; i--) { |
994 if (csSub[i] == L' ' || csSub[i] == L'.') | 842 if (csSub[i] != L' ' && csSub[i] != L'.') |
995 csSub.SetAt(i, L'\0'); | |
996 else | |
997 break; | 843 break; |
844 | |
845 csSub.SetAt(i, L'\0'); | |
998 } | 846 } |
999 uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); | 847 size_t dwCount = m_pFieldTree->m_Root.CountFields(); |
1000 for (uint32_t m = 0; m < dwCount; m++) { | 848 for (size_t m = 0; m < dwCount; ++m) { |
1001 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); | 849 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); |
1002 if (!pField) | 850 if (!pField) |
1003 continue; | 851 continue; |
1004 if (pField == pExcludedField) { | 852 if (pField == pExcludedField) { |
1005 if (pExcludedControl) { | 853 if (!pExcludedControl) |
1006 if (pField->CountControls() < 2) | |
1007 continue; | |
1008 } else { | |
1009 continue; | 854 continue; |
1010 } | 855 if (pField->CountControls() < 2) |
Tom Sepez
2016/09/28 20:46:49
nit: combine with 853
Lei Zhang
2016/09/28 21:02:39
Done.
| |
856 continue; | |
1011 } | 857 } |
1012 CFX_WideString csFullName = pField->GetFullName(); | 858 CFX_WideString csFullName = pField->GetFullName(); |
1013 int iRet = CompareFieldName(csSub, csFullName); | 859 int iRet = CompareFieldName(csSub, csFullName); |
1014 if (iRet == 1) { | 860 if (iRet == 1) { |
1015 if (pField->GetFieldType() != iType) | 861 if (pField->GetFieldType() != iType) |
1016 return FALSE; | 862 return false; |
1017 } else if (iRet == 2 && csSub == csNewFieldName) { | 863 } else if (iRet == 2 && csSub == csNewFieldName) { |
1018 if (csFullName[iPos] == L'.') | 864 if (csFullName[iPos] == L'.') |
1019 return FALSE; | 865 return false; |
1020 } else if (iRet == 3 && csSub == csNewFieldName) { | 866 } else if (iRet == 3 && csSub == csNewFieldName) { |
1021 if (csNewFieldName[csFullName.GetLength()] == L'.') | 867 if (csNewFieldName[csFullName.GetLength()] == L'.') |
1022 return FALSE; | 868 return false; |
1023 } | 869 } |
1024 } | 870 } |
1025 if (iPos >= iLength) | 871 if (iPos >= iLength) |
1026 break; | 872 break; |
1027 } | 873 } |
1028 if (csSub.IsEmpty()) | 874 if (csSub.IsEmpty()) |
1029 return FALSE; | 875 return false; |
1030 | 876 |
1031 csNewFieldName = csSub; | 877 csNewFieldName = csSub; |
1032 return TRUE; | 878 return true; |
1033 } | 879 } |
1034 | 880 |
1035 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, | 881 size_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) const { |
1036 int iType) { | |
1037 return ValidateFieldName(csNewFieldName, iType, nullptr, nullptr); | |
1038 } | |
1039 | |
1040 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, | |
1041 CFX_WideString& csNewFieldName) { | |
1042 return pField && !csNewFieldName.IsEmpty() && | |
1043 ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, | |
1044 nullptr); | |
1045 } | |
1046 | |
1047 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, | |
1048 CFX_WideString& csNewFieldName) { | |
1049 if (!pControl || csNewFieldName.IsEmpty()) | |
1050 return FALSE; | |
1051 | |
1052 CPDF_FormField* pField = pControl->GetField(); | |
1053 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, | |
1054 pControl); | |
1055 } | |
1056 | |
1057 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, | |
1058 const CFX_ByteString& name2) { | |
1059 if (name1.GetLength() == name2.GetLength()) | |
1060 return name1 == name2 ? 1 : 0; | |
1061 | |
1062 const FX_CHAR* ptr1 = name1.c_str(); | |
1063 const FX_CHAR* ptr2 = name2.c_str(); | |
1064 int i = 0; | |
1065 while (ptr1[i] == ptr2[i]) | |
1066 i++; | |
1067 if (i == name1.GetLength()) | |
1068 return 2; | |
1069 if (i == name2.GetLength()) | |
1070 return 3; | |
1071 return 0; | |
1072 } | |
1073 | |
1074 int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, | |
1075 const CFX_WideString& name2) { | |
1076 const FX_WCHAR* ptr1 = name1.c_str(); | |
1077 const FX_WCHAR* ptr2 = name2.c_str(); | |
1078 if (name1.GetLength() == name2.GetLength()) | |
1079 return name1 == name2 ? 1 : 0; | |
1080 | |
1081 int i = 0; | |
1082 while (ptr1[i] == ptr2[i]) | |
1083 i++; | |
1084 if (i == name1.GetLength()) | |
1085 return 2; | |
1086 if (i == name2.GetLength()) | |
1087 return 3; | |
1088 return 0; | |
1089 } | |
1090 | |
1091 uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { | |
1092 if (csFieldName.IsEmpty()) | 882 if (csFieldName.IsEmpty()) |
1093 return (uint32_t)m_pFieldTree->m_Root.CountFields(); | 883 return m_pFieldTree->m_Root.CountFields(); |
1094 | 884 |
1095 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); | 885 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); |
1096 return pNode ? pNode->CountFields() : 0; | 886 return pNode ? pNode->CountFields() : 0; |
1097 } | 887 } |
1098 | 888 |
1099 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, | 889 CPDF_FormField* CPDF_InterForm::GetField( |
1100 const CFX_WideString& csFieldName) { | 890 uint32_t index, |
891 const CFX_WideString& csFieldName) const { | |
1101 if (csFieldName.IsEmpty()) | 892 if (csFieldName.IsEmpty()) |
1102 return m_pFieldTree->m_Root.GetFieldAtIndex(index); | 893 return m_pFieldTree->m_Root.GetFieldAtIndex(index); |
1103 | 894 |
1104 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); | 895 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); |
1105 return pNode ? pNode->GetFieldAtIndex(index) : nullptr; | 896 return pNode ? pNode->GetFieldAtIndex(index) : nullptr; |
1106 } | 897 } |
1107 | 898 |
1108 CPDF_FormField* CPDF_InterForm::GetFieldByDict( | 899 CPDF_FormField* CPDF_InterForm::GetFieldByDict( |
1109 CPDF_Dictionary* pFieldDict) const { | 900 CPDF_Dictionary* pFieldDict) const { |
1110 if (!pFieldDict) | 901 if (!pFieldDict) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 return -1; | 974 return -1; |
1184 | 975 |
1185 for (size_t i = 0; i < pArray->GetCount(); i++) { | 976 for (size_t i = 0; i < pArray->GetCount(); i++) { |
1186 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); | 977 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); |
1187 if (pElement == pField->m_pDict) | 978 if (pElement == pField->m_pDict) |
1188 return i; | 979 return i; |
1189 } | 980 } |
1190 return -1; | 981 return -1; |
1191 } | 982 } |
1192 | 983 |
1193 uint32_t CPDF_InterForm::CountFormFonts() { | |
1194 return CountFonts(m_pFormDict); | |
1195 } | |
1196 | |
1197 CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index, | |
1198 CFX_ByteString& csNameTag) { | |
1199 return GetFont(m_pFormDict, m_pDocument, index, csNameTag); | |
1200 } | |
1201 | |
1202 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { | 984 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { |
1203 return GetFont(m_pFormDict, m_pDocument, csNameTag); | 985 return GetFont(m_pFormDict, m_pDocument, csNameTag); |
1204 } | 986 } |
1205 | 987 |
1206 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName, | 988 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() const { |
1207 CFX_ByteString& csNameTag) { | |
1208 return GetFont(m_pFormDict, m_pDocument, csFontName, csNameTag); | |
1209 } | |
1210 | |
1211 CPDF_Font* CPDF_InterForm::GetNativeFormFont(uint8_t charSet, | |
1212 CFX_ByteString& csNameTag) { | |
1213 return ::GetNativeFont(m_pFormDict, m_pDocument, charSet, csNameTag); | |
1214 } | |
1215 | |
1216 CPDF_Font* CPDF_InterForm::GetNativeFormFont(CFX_ByteString& csNameTag) { | |
1217 return ::GetNativeFont(m_pFormDict, m_pDocument, csNameTag); | |
1218 } | |
1219 | |
1220 FX_BOOL CPDF_InterForm::FindFormFont(const CPDF_Font* pFont, | |
1221 CFX_ByteString& csNameTag) { | |
1222 return FindFont(m_pFormDict, pFont, csNameTag); | |
1223 } | |
1224 | |
1225 FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, | |
1226 CPDF_Font*& pFont, | |
1227 CFX_ByteString& csNameTag) { | |
1228 return FindFont(m_pFormDict, m_pDocument, csFontName, pFont, csNameTag); | |
1229 } | |
1230 | |
1231 void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont, | |
1232 CFX_ByteString& csNameTag) { | |
1233 AddFont(m_pFormDict, m_pDocument, pFont, csNameTag); | |
1234 } | |
1235 | |
1236 CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet, | |
1237 CFX_ByteString& csNameTag) { | |
1238 return ::AddNativeFont(m_pFormDict, m_pDocument, charSet, csNameTag); | |
1239 } | |
1240 | |
1241 CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) { | |
1242 return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); | |
1243 } | |
1244 | |
1245 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { | |
1246 RemoveFont(m_pFormDict, pFont); | |
1247 } | |
1248 | |
1249 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { | |
1250 RemoveFont(m_pFormDict, csNameTag); | |
1251 } | |
1252 | |
1253 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { | |
1254 if (!m_pFormDict) | 989 if (!m_pFormDict) |
1255 return CPDF_DefaultAppearance(); | 990 return CPDF_DefaultAppearance(); |
1256 return CPDF_DefaultAppearance(m_pFormDict->GetStringFor("DA")); | 991 return CPDF_DefaultAppearance(m_pFormDict->GetStringFor("DA")); |
1257 } | 992 } |
1258 | 993 |
1259 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { | 994 int CPDF_InterForm::GetFormAlignment() const { |
1260 return GetDefaultFont(m_pFormDict, m_pDocument); | |
1261 } | |
1262 | |
1263 int CPDF_InterForm::GetFormAlignment() { | |
1264 return m_pFormDict ? m_pFormDict->GetIntegerFor("Q", 0) : 0; | 995 return m_pFormDict ? m_pFormDict->GetIntegerFor("Q", 0) : 0; |
1265 } | 996 } |
1266 | 997 |
1267 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, | 998 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, |
1268 bool bIncludeOrExclude, | 999 bool bIncludeOrExclude, |
1269 bool bNotify) { | 1000 bool bNotify) { |
1270 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1001 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
1271 return false; | 1002 return false; |
1272 | 1003 |
1273 int nCount = m_pFieldTree->m_Root.CountFields(); | 1004 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
1274 for (int i = 0; i < nCount; ++i) { | 1005 for (size_t i = 0; i < nCount; ++i) { |
1275 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1006 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1276 if (!pField) | 1007 if (!pField) |
1277 continue; | 1008 continue; |
1278 | 1009 |
1279 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) | 1010 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) |
1280 pField->ResetField(bNotify); | 1011 pField->ResetField(bNotify); |
1281 } | 1012 } |
1282 if (bNotify && m_pFormNotify) | 1013 if (bNotify && m_pFormNotify) |
1283 m_pFormNotify->AfterFormReset(this); | 1014 m_pFormNotify->AfterFormReset(this); |
1284 return true; | 1015 return true; |
1285 } | 1016 } |
1286 | 1017 |
1287 bool CPDF_InterForm::ResetForm(bool bNotify) { | 1018 bool CPDF_InterForm::ResetForm(bool bNotify) { |
1288 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1019 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
1289 return false; | 1020 return false; |
1290 | 1021 |
1291 int nCount = m_pFieldTree->m_Root.CountFields(); | 1022 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
1292 for (int i = 0; i < nCount; ++i) { | 1023 for (size_t i = 0; i < nCount; ++i) { |
1293 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1024 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1294 if (!pField) | 1025 if (!pField) |
1295 continue; | 1026 continue; |
1296 | 1027 |
1297 pField->ResetField(bNotify); | 1028 pField->ResetField(bNotify); |
1298 } | 1029 } |
1299 if (bNotify && m_pFormNotify) | 1030 if (bNotify && m_pFormNotify) |
1300 m_pFormNotify->AfterFormReset(this); | 1031 m_pFormNotify->AfterFormReset(this); |
1301 return true; | 1032 return true; |
1302 } | 1033 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 if (!pPageDict) | 1071 if (!pPageDict) |
1341 return; | 1072 return; |
1342 | 1073 |
1343 CPDF_Array* pAnnots = pPageDict->GetArrayFor("Annots"); | 1074 CPDF_Array* pAnnots = pPageDict->GetArrayFor("Annots"); |
1344 if (!pAnnots) | 1075 if (!pAnnots) |
1345 return; | 1076 return; |
1346 | 1077 |
1347 for (size_t i = 0; i < pAnnots->GetCount(); i++) { | 1078 for (size_t i = 0; i < pAnnots->GetCount(); i++) { |
1348 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); | 1079 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); |
1349 if (pAnnot && pAnnot->GetStringFor("Subtype") == "Widget") | 1080 if (pAnnot && pAnnot->GetStringFor("Subtype") == "Widget") |
1350 LoadField(pAnnot); | 1081 LoadField(pAnnot, 0); |
1351 } | 1082 } |
1352 } | 1083 } |
1353 | 1084 |
1354 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { | 1085 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { |
1355 if (!pFieldDict->KeyExist("T")) | 1086 if (!pFieldDict->KeyExist("T")) |
1356 return nullptr; | 1087 return nullptr; |
1357 | 1088 |
1358 CPDF_Dictionary* pDict = pFieldDict; | 1089 CPDF_Dictionary* pDict = pFieldDict; |
1359 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); | 1090 CFX_WideString csWName = FPDF_GetFullName(pFieldDict); |
1360 if (csWName.IsEmpty()) | 1091 if (csWName.IsEmpty()) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1423 | 1154 |
1424 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); | 1155 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); |
1425 m_ControlMap[pWidgetDict] = pControl; | 1156 m_ControlMap[pWidgetDict] = pControl; |
1426 pField->m_ControlList.Add(pControl); | 1157 pField->m_ControlList.Add(pControl); |
1427 return pControl; | 1158 return pControl; |
1428 } | 1159 } |
1429 | 1160 |
1430 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( | 1161 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( |
1431 const std::vector<CPDF_FormField*>* fields, | 1162 const std::vector<CPDF_FormField*>* fields, |
1432 bool bIncludeOrExclude) const { | 1163 bool bIncludeOrExclude) const { |
1433 int nCount = m_pFieldTree->m_Root.CountFields(); | 1164 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
1434 for (int i = 0; i < nCount; ++i) { | 1165 for (size_t i = 0; i < nCount; ++i) { |
1435 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1166 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1436 if (!pField) | 1167 if (!pField) |
1437 continue; | 1168 continue; |
1438 | 1169 |
1439 int32_t iType = pField->GetType(); | 1170 int32_t iType = pField->GetType(); |
1440 if (iType == CPDF_FormField::PushButton || | 1171 if (iType == CPDF_FormField::PushButton || |
1441 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { | 1172 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { |
1442 continue; | 1173 continue; |
1443 } | 1174 } |
1444 uint32_t dwFlags = pField->GetFieldFlags(); | 1175 uint32_t dwFlags = pField->GetFieldFlags(); |
1445 // TODO(thestig): Look up these magic numbers and add constants for them. | 1176 // TODO(thestig): Look up these magic numbers and add constants for them. |
1446 if (dwFlags & 0x04) | 1177 if (dwFlags & 0x04) |
1447 continue; | 1178 continue; |
1448 | 1179 |
1449 bool bFind = true; | 1180 bool bFind = true; |
1450 if (fields) | 1181 if (fields) |
1451 bFind = pdfium::ContainsValue(*fields, pField); | 1182 bFind = pdfium::ContainsValue(*fields, pField); |
1452 if (bIncludeOrExclude == bFind) { | 1183 if (bIncludeOrExclude == bFind) { |
1453 CPDF_Dictionary* pFieldDict = pField->m_pDict; | 1184 CPDF_Dictionary* pFieldDict = pField->m_pDict; |
1454 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) | 1185 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) |
1455 return pField; | 1186 return pField; |
1456 } | 1187 } |
1457 } | 1188 } |
1458 return nullptr; | 1189 return nullptr; |
1459 } | 1190 } |
1460 | 1191 |
1461 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, | 1192 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
1462 bool bSimpleFileSpec) const { | 1193 bool bSimpleFileSpec) const { |
1463 std::vector<CPDF_FormField*> fields; | 1194 std::vector<CPDF_FormField*> fields; |
1464 int nCount = m_pFieldTree->m_Root.CountFields(); | 1195 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
1465 for (int i = 0; i < nCount; ++i) | 1196 for (size_t i = 0; i < nCount; ++i) |
1466 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); | 1197 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); |
1467 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); | 1198 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); |
1468 } | 1199 } |
1469 | 1200 |
1470 CFDF_Document* CPDF_InterForm::ExportToFDF( | 1201 CFDF_Document* CPDF_InterForm::ExportToFDF( |
1471 const CFX_WideStringC& pdf_path, | 1202 const CFX_WideStringC& pdf_path, |
1472 const std::vector<CPDF_FormField*>& fields, | 1203 const std::vector<CPDF_FormField*>& fields, |
1473 bool bIncludeOrExclude, | 1204 bool bIncludeOrExclude, |
1474 bool bSimpleFileSpec) const { | 1205 bool bSimpleFileSpec) const { |
1475 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); | 1206 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
1476 if (!pDoc) | 1207 if (!pDoc) |
1477 return nullptr; | 1208 return nullptr; |
1478 | 1209 |
1479 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); | 1210 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); |
1480 if (!pdf_path.IsEmpty()) { | 1211 if (!pdf_path.IsEmpty()) { |
1481 if (bSimpleFileSpec) { | 1212 if (bSimpleFileSpec) { |
1482 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); | 1213 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
1483 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1214 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); |
1484 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); | 1215 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); |
1485 } else { | 1216 } else { |
1486 CPDF_FileSpec filespec; | 1217 CPDF_FileSpec filespec; |
1487 filespec.SetFileName(pdf_path); | 1218 filespec.SetFileName(pdf_path); |
1488 pMainDict->SetFor("F", filespec.GetObj()); | 1219 pMainDict->SetFor("F", filespec.GetObj()); |
1489 } | 1220 } |
1490 } | 1221 } |
1491 | 1222 |
1492 CPDF_Array* pFields = new CPDF_Array; | 1223 CPDF_Array* pFields = new CPDF_Array; |
1493 pMainDict->SetFor("Fields", pFields); | 1224 pMainDict->SetFor("Fields", pFields); |
1494 int nCount = m_pFieldTree->m_Root.CountFields(); | 1225 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
1495 for (int i = 0; i < nCount; i++) { | 1226 for (size_t i = 0; i < nCount; ++i) { |
1496 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1227 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
1497 if (!pField || pField->GetType() == CPDF_FormField::PushButton) | 1228 if (!pField || pField->GetType() == CPDF_FormField::PushButton) |
1498 continue; | 1229 continue; |
1499 | 1230 |
1500 uint32_t dwFlags = pField->GetFieldFlags(); | 1231 uint32_t dwFlags = pField->GetFieldFlags(); |
1501 if (dwFlags & 0x04) | 1232 if (dwFlags & 0x04) |
1502 continue; | 1233 continue; |
1503 | 1234 |
1504 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1235 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
1505 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) | 1236 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 if (bNotify && m_pFormNotify) { | 1310 if (bNotify && m_pFormNotify) { |
1580 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) | 1311 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) |
1581 m_pFormNotify->AfterCheckedStatusChange(pField); | 1312 m_pFormNotify->AfterCheckedStatusChange(pField); |
1582 else if (iType == FIELDTYPE_LISTBOX) | 1313 else if (iType == FIELDTYPE_LISTBOX) |
1583 m_pFormNotify->AfterSelectionChange(pField); | 1314 m_pFormNotify->AfterSelectionChange(pField); |
1584 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) | 1315 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) |
1585 m_pFormNotify->AfterValueChange(pField); | 1316 m_pFormNotify->AfterValueChange(pField); |
1586 } | 1317 } |
1587 } | 1318 } |
1588 | 1319 |
1589 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, | |
1590 FX_BOOL bNotify) { | |
1591 if (!pFDF) | |
1592 return FALSE; | |
1593 | |
1594 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictFor("FDF"); | |
1595 if (!pMainDict) | |
1596 return FALSE; | |
1597 | |
1598 CPDF_Array* pFields = pMainDict->GetArrayFor("Fields"); | |
1599 if (!pFields) | |
1600 return FALSE; | |
1601 | |
1602 m_bsEncoding = pMainDict->GetStringFor("Encoding"); | |
1603 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) | |
1604 return FALSE; | |
1605 | |
1606 for (size_t i = 0; i < pFields->GetCount(); i++) { | |
1607 CPDF_Dictionary* pField = pFields->GetDictAt(i); | |
1608 if (!pField) | |
1609 continue; | |
1610 | |
1611 FDF_ImportField(pField, L"", bNotify); | |
1612 } | |
1613 if (bNotify && m_pFormNotify) | |
1614 m_pFormNotify->AfterFormImportData(this); | |
1615 return TRUE; | |
1616 } | |
1617 | |
1618 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { | 1320 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
1619 m_pFormNotify = pNotify; | 1321 m_pFormNotify = pNotify; |
1620 } | 1322 } |
OLD | NEW |