| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 : m_ShortName(short_name), m_pField(pField) {} | 384 : m_ShortName(short_name), m_pField(pField) {} |
| 545 ~Node() {} | 385 ~Node() {} |
| 546 | 386 |
| 547 void AddChildNode(Node* pNode) { m_Children.push_back(pNode); } | 387 void AddChildNode(Node* pNode) { m_Children.push_back(pNode); } |
| 548 | 388 |
| 549 size_t GetChildrenCount() const { return m_Children.size(); } | 389 size_t GetChildrenCount() const { return m_Children.size(); } |
| 550 | 390 |
| 551 Node* GetChildAt(size_t i) { return m_Children[i]; } | 391 Node* GetChildAt(size_t i) { return m_Children[i]; } |
| 552 const Node* GetChildAt(size_t i) const { return m_Children[i]; } | 392 const Node* GetChildAt(size_t i) const { return m_Children[i]; } |
| 553 | 393 |
| 554 CPDF_FormField* GetFieldAtIndex(int index) { | 394 CPDF_FormField* GetFieldAtIndex(size_t index) { |
| 555 int nFieldsToGo = index; | 395 size_t nFieldsToGo = index; |
| 556 return GetFieldInternal(&nFieldsToGo); | 396 return GetFieldInternal(&nFieldsToGo); |
| 557 } | 397 } |
| 558 | 398 |
| 559 int CountFields() const { return CountFieldsInternal(0); } | 399 size_t CountFields() const { return CountFieldsInternal(0); } |
| 560 | 400 |
| 561 void SetField(CPDF_FormField* pField) { m_pField = pField; } | 401 void SetField(CPDF_FormField* pField) { m_pField = pField; } |
| 562 | 402 |
| 563 CPDF_FormField* GetField() { return m_pField; } | 403 CPDF_FormField* GetField() { return m_pField; } |
| 564 const CPDF_FormField* GetField() const { return m_pField; } | 404 const CPDF_FormField* GetField() const { return m_pField; } |
| 565 | 405 |
| 566 const CFX_WideString& GetShortName() const { return m_ShortName; } | 406 const CFX_WideString& GetShortName() const { return m_ShortName; } |
| 567 | 407 |
| 568 private: | 408 private: |
| 569 CPDF_FormField* GetFieldInternal(int* pFieldsToGo) { | 409 CPDF_FormField* GetFieldInternal(size_t* pFieldsToGo) { |
| 570 if (m_pField) { | 410 if (m_pField) { |
| 571 if (*pFieldsToGo == 0) | 411 if (*pFieldsToGo == 0) |
| 572 return m_pField; | 412 return m_pField; |
| 573 | 413 |
| 574 --*pFieldsToGo; | 414 --*pFieldsToGo; |
| 575 return nullptr; | 415 return nullptr; |
| 576 } | 416 } |
| 577 for (size_t i = 0; i < GetChildrenCount(); ++i) { | 417 for (size_t i = 0; i < GetChildrenCount(); ++i) { |
| 578 CPDF_FormField* pField = GetChildAt(i)->GetFieldInternal(pFieldsToGo); | 418 CPDF_FormField* pField = GetChildAt(i)->GetFieldInternal(pFieldsToGo); |
| 579 if (pField) | 419 if (pField) |
| 580 return pField; | 420 return pField; |
| 581 } | 421 } |
| 582 return nullptr; | 422 return nullptr; |
| 583 } | 423 } |
| 584 | 424 |
| 585 int CountFieldsInternal(int nLevel) const { | 425 size_t CountFieldsInternal(int nLevel) const { |
| 586 if (nLevel > nMaxRecursion) | 426 if (nLevel > nMaxRecursion) |
| 587 return 0; | 427 return 0; |
| 588 if (m_pField) | 428 if (m_pField) |
| 589 return 1; | 429 return 1; |
| 590 | 430 |
| 591 int count = 0; | 431 size_t count = 0; |
| 592 for (size_t i = 0; i < GetChildrenCount(); ++i) | 432 for (size_t i = 0; i < GetChildrenCount(); ++i) |
| 593 count += GetChildAt(i)->CountFieldsInternal(nLevel + 1); | 433 count += GetChildAt(i)->CountFieldsInternal(nLevel + 1); |
| 594 return count; | 434 return count; |
| 595 } | 435 } |
| 596 | 436 |
| 597 std::vector<Node*> m_Children; | 437 std::vector<Node*> m_Children; |
| 598 CFX_WideString m_ShortName; | 438 CFX_WideString m_ShortName; |
| 599 CPDF_FormField* m_pField; | 439 CPDF_FormField* m_pField; |
| 600 }; | 440 }; |
| 601 | 441 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 return; | 651 return; |
| 812 | 652 |
| 813 for (size_t i = 0; i < pFields->GetCount(); i++) | 653 for (size_t i = 0; i < pFields->GetCount(); i++) |
| 814 LoadField(pFields->GetDictAt(i)); | 654 LoadField(pFields->GetDictAt(i)); |
| 815 } | 655 } |
| 816 | 656 |
| 817 CPDF_InterForm::~CPDF_InterForm() { | 657 CPDF_InterForm::~CPDF_InterForm() { |
| 818 for (auto it : m_ControlMap) | 658 for (auto it : m_ControlMap) |
| 819 delete it.second; | 659 delete it.second; |
| 820 | 660 |
| 821 int nCount = m_pFieldTree->m_Root.CountFields(); | 661 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 822 for (int i = 0; i < nCount; ++i) | 662 for (size_t i = 0; i < nCount; ++i) |
| 823 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); | 663 delete m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 824 } | 664 } |
| 825 | 665 |
| 826 FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE; | 666 bool CPDF_InterForm::s_bUpdateAP = true; |
| 827 | 667 |
| 828 FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() { | 668 bool CPDF_InterForm::IsUpdateAPEnabled() { |
| 829 return s_bUpdateAP; | 669 return s_bUpdateAP; |
| 830 } | 670 } |
| 831 | 671 |
| 832 void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) { | 672 void CPDF_InterForm::SetUpdateAP(bool bUpdateAP) { |
| 833 s_bUpdateAP = bUpdateAP; | 673 s_bUpdateAP = bUpdateAP; |
| 834 } | 674 } |
| 835 | 675 |
| 836 CFX_ByteString CPDF_InterForm::GenerateNewResourceName( | 676 CFX_ByteString CPDF_InterForm::GenerateNewResourceName( |
| 837 const CPDF_Dictionary* pResDict, | 677 const CPDF_Dictionary* pResDict, |
| 838 const FX_CHAR* csType, | 678 const FX_CHAR* csType, |
| 839 int iMinLen, | 679 int iMinLen, |
| 840 const FX_CHAR* csPrefix) { | 680 const FX_CHAR* csPrefix) { |
| 841 CFX_ByteString csStr = csPrefix; | 681 CFX_ByteString csStr = csPrefix; |
| 842 CFX_ByteString csBType = csType; | 682 CFX_ByteString csBType = csType; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 if (pLogFont) | 774 if (pLogFont) |
| 935 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); | 775 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); |
| 936 | 776 |
| 937 csFontName = lf.lfFaceName; | 777 csFontName = lf.lfFaceName; |
| 938 return csFontName; | 778 return csFontName; |
| 939 } | 779 } |
| 940 #endif | 780 #endif |
| 941 return csFontName; | 781 return csFontName; |
| 942 } | 782 } |
| 943 | 783 |
| 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, | 784 CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet, |
| 953 CPDF_Document* pDocument) { | 785 CPDF_Document* pDocument) { |
| 954 if (!pDocument) | 786 if (!pDocument) |
| 955 return nullptr; | 787 return nullptr; |
| 956 | 788 |
| 957 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 789 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 958 LOGFONTA lf; | 790 LOGFONTA lf; |
| 959 CFX_ByteString csFontName = GetNativeFont(charSet, &lf); | 791 CFX_ByteString csFontName = GetNativeFont(charSet, &lf); |
| 960 if (!csFontName.IsEmpty()) { | 792 if (!csFontName.IsEmpty()) { |
| 961 if (csFontName == "Helvetica") | 793 if (csFontName == "Helvetica") |
| (...skipping 27 matching lines...) Expand all Loading... |
| 989 if (iPos < iLength && !csSub.IsEmpty()) | 821 if (iPos < iLength && !csSub.IsEmpty()) |
| 990 csSub += L'.'; | 822 csSub += L'.'; |
| 991 while (iPos < iLength && csNewFieldName[iPos] != L'.') | 823 while (iPos < iLength && csNewFieldName[iPos] != L'.') |
| 992 csSub += csNewFieldName[iPos++]; | 824 csSub += csNewFieldName[iPos++]; |
| 993 for (int i = csSub.GetLength() - 1; i > -1; i--) { | 825 for (int i = csSub.GetLength() - 1; i > -1; i--) { |
| 994 if (csSub[i] == L' ' || csSub[i] == L'.') | 826 if (csSub[i] == L' ' || csSub[i] == L'.') |
| 995 csSub.SetAt(i, L'\0'); | 827 csSub.SetAt(i, L'\0'); |
| 996 else | 828 else |
| 997 break; | 829 break; |
| 998 } | 830 } |
| 999 uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); | 831 size_t dwCount = m_pFieldTree->m_Root.CountFields(); |
| 1000 for (uint32_t m = 0; m < dwCount; m++) { | 832 for (size_t m = 0; m < dwCount; ++m) { |
| 1001 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); | 833 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(m); |
| 1002 if (!pField) | 834 if (!pField) |
| 1003 continue; | 835 continue; |
| 1004 if (pField == pExcludedField) { | 836 if (pField == pExcludedField) { |
| 1005 if (pExcludedControl) { | 837 if (pExcludedControl) { |
| 1006 if (pField->CountControls() < 2) | 838 if (pField->CountControls() < 2) |
| 1007 continue; | 839 continue; |
| 1008 } else { | 840 } else { |
| 1009 continue; | 841 continue; |
| 1010 } | 842 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1025 if (iPos >= iLength) | 857 if (iPos >= iLength) |
| 1026 break; | 858 break; |
| 1027 } | 859 } |
| 1028 if (csSub.IsEmpty()) | 860 if (csSub.IsEmpty()) |
| 1029 return FALSE; | 861 return FALSE; |
| 1030 | 862 |
| 1031 csNewFieldName = csSub; | 863 csNewFieldName = csSub; |
| 1032 return TRUE; | 864 return TRUE; |
| 1033 } | 865 } |
| 1034 | 866 |
| 1035 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, | |
| 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, | 867 int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, |
| 1075 const CFX_WideString& name2) { | 868 const CFX_WideString& name2) { |
| 1076 const FX_WCHAR* ptr1 = name1.c_str(); | 869 const FX_WCHAR* ptr1 = name1.c_str(); |
| 1077 const FX_WCHAR* ptr2 = name2.c_str(); | 870 const FX_WCHAR* ptr2 = name2.c_str(); |
| 1078 if (name1.GetLength() == name2.GetLength()) | 871 if (name1.GetLength() == name2.GetLength()) |
| 1079 return name1 == name2 ? 1 : 0; | 872 return name1 == name2 ? 1 : 0; |
| 1080 | 873 |
| 1081 int i = 0; | 874 int i = 0; |
| 1082 while (ptr1[i] == ptr2[i]) | 875 while (ptr1[i] == ptr2[i]) |
| 1083 i++; | 876 i++; |
| 1084 if (i == name1.GetLength()) | 877 if (i == name1.GetLength()) |
| 1085 return 2; | 878 return 2; |
| 1086 if (i == name2.GetLength()) | 879 if (i == name2.GetLength()) |
| 1087 return 3; | 880 return 3; |
| 1088 return 0; | 881 return 0; |
| 1089 } | 882 } |
| 1090 | 883 |
| 1091 uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { | 884 size_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { |
| 1092 if (csFieldName.IsEmpty()) | 885 if (csFieldName.IsEmpty()) |
| 1093 return (uint32_t)m_pFieldTree->m_Root.CountFields(); | 886 return m_pFieldTree->m_Root.CountFields(); |
| 1094 | 887 |
| 1095 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); | 888 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName); |
| 1096 return pNode ? pNode->CountFields() : 0; | 889 return pNode ? pNode->CountFields() : 0; |
| 1097 } | 890 } |
| 1098 | 891 |
| 1099 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, | 892 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, |
| 1100 const CFX_WideString& csFieldName) { | 893 const CFX_WideString& csFieldName) { |
| 1101 if (csFieldName.IsEmpty()) | 894 if (csFieldName.IsEmpty()) |
| 1102 return m_pFieldTree->m_Root.GetFieldAtIndex(index); | 895 return m_pFieldTree->m_Root.GetFieldAtIndex(index); |
| 1103 | 896 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 return -1; | 976 return -1; |
| 1184 | 977 |
| 1185 for (size_t i = 0; i < pArray->GetCount(); i++) { | 978 for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 1186 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); | 979 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); |
| 1187 if (pElement == pField->m_pDict) | 980 if (pElement == pField->m_pDict) |
| 1188 return i; | 981 return i; |
| 1189 } | 982 } |
| 1190 return -1; | 983 return -1; |
| 1191 } | 984 } |
| 1192 | 985 |
| 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) { | 986 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { |
| 1203 return GetFont(m_pFormDict, m_pDocument, csNameTag); | 987 return GetFont(m_pFormDict, m_pDocument, csNameTag); |
| 1204 } | 988 } |
| 1205 | 989 |
| 1206 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName, | |
| 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, | 990 FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, |
| 1226 CPDF_Font*& pFont, | 991 CPDF_Font*& pFont, |
| 1227 CFX_ByteString& csNameTag) { | 992 CFX_ByteString& csNameTag) { |
| 1228 return FindFont(m_pFormDict, m_pDocument, csFontName, pFont, csNameTag); | 993 return FindFont(m_pFormDict, m_pDocument, csFontName, pFont, csNameTag); |
| 1229 } | 994 } |
| 1230 | 995 |
| 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() { | 996 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { |
| 1254 if (!m_pFormDict) | 997 if (!m_pFormDict) |
| 1255 return CPDF_DefaultAppearance(); | 998 return CPDF_DefaultAppearance(); |
| 1256 return CPDF_DefaultAppearance(m_pFormDict->GetStringFor("DA")); | 999 return CPDF_DefaultAppearance(m_pFormDict->GetStringFor("DA")); |
| 1257 } | 1000 } |
| 1258 | 1001 |
| 1259 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { | |
| 1260 return GetDefaultFont(m_pFormDict, m_pDocument); | |
| 1261 } | |
| 1262 | |
| 1263 int CPDF_InterForm::GetFormAlignment() { | 1002 int CPDF_InterForm::GetFormAlignment() { |
| 1264 return m_pFormDict ? m_pFormDict->GetIntegerFor("Q", 0) : 0; | 1003 return m_pFormDict ? m_pFormDict->GetIntegerFor("Q", 0) : 0; |
| 1265 } | 1004 } |
| 1266 | 1005 |
| 1267 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, | 1006 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, |
| 1268 bool bIncludeOrExclude, | 1007 bool bIncludeOrExclude, |
| 1269 bool bNotify) { | 1008 bool bNotify) { |
| 1270 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1009 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
| 1271 return false; | 1010 return false; |
| 1272 | 1011 |
| 1273 int nCount = m_pFieldTree->m_Root.CountFields(); | 1012 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 1274 for (int i = 0; i < nCount; ++i) { | 1013 for (size_t i = 0; i < nCount; ++i) { |
| 1275 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1014 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 1276 if (!pField) | 1015 if (!pField) |
| 1277 continue; | 1016 continue; |
| 1278 | 1017 |
| 1279 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) | 1018 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) |
| 1280 pField->ResetField(bNotify); | 1019 pField->ResetField(bNotify); |
| 1281 } | 1020 } |
| 1282 if (bNotify && m_pFormNotify) | 1021 if (bNotify && m_pFormNotify) |
| 1283 m_pFormNotify->AfterFormReset(this); | 1022 m_pFormNotify->AfterFormReset(this); |
| 1284 return true; | 1023 return true; |
| 1285 } | 1024 } |
| 1286 | 1025 |
| 1287 bool CPDF_InterForm::ResetForm(bool bNotify) { | 1026 bool CPDF_InterForm::ResetForm(bool bNotify) { |
| 1288 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 1027 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
| 1289 return false; | 1028 return false; |
| 1290 | 1029 |
| 1291 int nCount = m_pFieldTree->m_Root.CountFields(); | 1030 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 1292 for (int i = 0; i < nCount; ++i) { | 1031 for (size_t i = 0; i < nCount; ++i) { |
| 1293 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1032 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 1294 if (!pField) | 1033 if (!pField) |
| 1295 continue; | 1034 continue; |
| 1296 | 1035 |
| 1297 pField->ResetField(bNotify); | 1036 pField->ResetField(bNotify); |
| 1298 } | 1037 } |
| 1299 if (bNotify && m_pFormNotify) | 1038 if (bNotify && m_pFormNotify) |
| 1300 m_pFormNotify->AfterFormReset(this); | 1039 m_pFormNotify->AfterFormReset(this); |
| 1301 return true; | 1040 return true; |
| 1302 } | 1041 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 | 1162 |
| 1424 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); | 1163 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); |
| 1425 m_ControlMap[pWidgetDict] = pControl; | 1164 m_ControlMap[pWidgetDict] = pControl; |
| 1426 pField->m_ControlList.Add(pControl); | 1165 pField->m_ControlList.Add(pControl); |
| 1427 return pControl; | 1166 return pControl; |
| 1428 } | 1167 } |
| 1429 | 1168 |
| 1430 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( | 1169 CPDF_FormField* CPDF_InterForm::CheckRequiredFields( |
| 1431 const std::vector<CPDF_FormField*>* fields, | 1170 const std::vector<CPDF_FormField*>* fields, |
| 1432 bool bIncludeOrExclude) const { | 1171 bool bIncludeOrExclude) const { |
| 1433 int nCount = m_pFieldTree->m_Root.CountFields(); | 1172 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 1434 for (int i = 0; i < nCount; ++i) { | 1173 for (size_t i = 0; i < nCount; ++i) { |
| 1435 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1174 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 1436 if (!pField) | 1175 if (!pField) |
| 1437 continue; | 1176 continue; |
| 1438 | 1177 |
| 1439 int32_t iType = pField->GetType(); | 1178 int32_t iType = pField->GetType(); |
| 1440 if (iType == CPDF_FormField::PushButton || | 1179 if (iType == CPDF_FormField::PushButton || |
| 1441 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { | 1180 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { |
| 1442 continue; | 1181 continue; |
| 1443 } | 1182 } |
| 1444 uint32_t dwFlags = pField->GetFieldFlags(); | 1183 uint32_t dwFlags = pField->GetFieldFlags(); |
| 1445 // TODO(thestig): Look up these magic numbers and add constants for them. | 1184 // TODO(thestig): Look up these magic numbers and add constants for them. |
| 1446 if (dwFlags & 0x04) | 1185 if (dwFlags & 0x04) |
| 1447 continue; | 1186 continue; |
| 1448 | 1187 |
| 1449 bool bFind = true; | 1188 bool bFind = true; |
| 1450 if (fields) | 1189 if (fields) |
| 1451 bFind = pdfium::ContainsValue(*fields, pField); | 1190 bFind = pdfium::ContainsValue(*fields, pField); |
| 1452 if (bIncludeOrExclude == bFind) { | 1191 if (bIncludeOrExclude == bFind) { |
| 1453 CPDF_Dictionary* pFieldDict = pField->m_pDict; | 1192 CPDF_Dictionary* pFieldDict = pField->m_pDict; |
| 1454 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) | 1193 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) |
| 1455 return pField; | 1194 return pField; |
| 1456 } | 1195 } |
| 1457 } | 1196 } |
| 1458 return nullptr; | 1197 return nullptr; |
| 1459 } | 1198 } |
| 1460 | 1199 |
| 1461 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, | 1200 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
| 1462 bool bSimpleFileSpec) const { | 1201 bool bSimpleFileSpec) const { |
| 1463 std::vector<CPDF_FormField*> fields; | 1202 std::vector<CPDF_FormField*> fields; |
| 1464 int nCount = m_pFieldTree->m_Root.CountFields(); | 1203 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 1465 for (int i = 0; i < nCount; ++i) | 1204 for (size_t i = 0; i < nCount; ++i) |
| 1466 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); | 1205 fields.push_back(m_pFieldTree->m_Root.GetFieldAtIndex(i)); |
| 1467 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); | 1206 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); |
| 1468 } | 1207 } |
| 1469 | 1208 |
| 1470 CFDF_Document* CPDF_InterForm::ExportToFDF( | 1209 CFDF_Document* CPDF_InterForm::ExportToFDF( |
| 1471 const CFX_WideStringC& pdf_path, | 1210 const CFX_WideStringC& pdf_path, |
| 1472 const std::vector<CPDF_FormField*>& fields, | 1211 const std::vector<CPDF_FormField*>& fields, |
| 1473 bool bIncludeOrExclude, | 1212 bool bIncludeOrExclude, |
| 1474 bool bSimpleFileSpec) const { | 1213 bool bSimpleFileSpec) const { |
| 1475 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); | 1214 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
| 1476 if (!pDoc) | 1215 if (!pDoc) |
| 1477 return nullptr; | 1216 return nullptr; |
| 1478 | 1217 |
| 1479 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); | 1218 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); |
| 1480 if (!pdf_path.IsEmpty()) { | 1219 if (!pdf_path.IsEmpty()) { |
| 1481 if (bSimpleFileSpec) { | 1220 if (bSimpleFileSpec) { |
| 1482 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); | 1221 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
| 1483 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); | 1222 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); |
| 1484 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); | 1223 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); |
| 1485 } else { | 1224 } else { |
| 1486 CPDF_FileSpec filespec; | 1225 CPDF_FileSpec filespec; |
| 1487 filespec.SetFileName(pdf_path); | 1226 filespec.SetFileName(pdf_path); |
| 1488 pMainDict->SetFor("F", filespec.GetObj()); | 1227 pMainDict->SetFor("F", filespec.GetObj()); |
| 1489 } | 1228 } |
| 1490 } | 1229 } |
| 1491 | 1230 |
| 1492 CPDF_Array* pFields = new CPDF_Array; | 1231 CPDF_Array* pFields = new CPDF_Array; |
| 1493 pMainDict->SetFor("Fields", pFields); | 1232 pMainDict->SetFor("Fields", pFields); |
| 1494 int nCount = m_pFieldTree->m_Root.CountFields(); | 1233 size_t nCount = m_pFieldTree->m_Root.CountFields(); |
| 1495 for (int i = 0; i < nCount; i++) { | 1234 for (size_t i = 0; i < nCount; ++i) { |
| 1496 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); | 1235 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
| 1497 if (!pField || pField->GetType() == CPDF_FormField::PushButton) | 1236 if (!pField || pField->GetType() == CPDF_FormField::PushButton) |
| 1498 continue; | 1237 continue; |
| 1499 | 1238 |
| 1500 uint32_t dwFlags = pField->GetFieldFlags(); | 1239 uint32_t dwFlags = pField->GetFieldFlags(); |
| 1501 if (dwFlags & 0x04) | 1240 if (dwFlags & 0x04) |
| 1502 continue; | 1241 continue; |
| 1503 | 1242 |
| 1504 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { | 1243 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
| 1505 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) | 1244 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) { | 1318 if (bNotify && m_pFormNotify) { |
| 1580 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) | 1319 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) |
| 1581 m_pFormNotify->AfterCheckedStatusChange(pField); | 1320 m_pFormNotify->AfterCheckedStatusChange(pField); |
| 1582 else if (iType == FIELDTYPE_LISTBOX) | 1321 else if (iType == FIELDTYPE_LISTBOX) |
| 1583 m_pFormNotify->AfterSelectionChange(pField); | 1322 m_pFormNotify->AfterSelectionChange(pField); |
| 1584 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) | 1323 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) |
| 1585 m_pFormNotify->AfterValueChange(pField); | 1324 m_pFormNotify->AfterValueChange(pField); |
| 1586 } | 1325 } |
| 1587 } | 1326 } |
| 1588 | 1327 |
| 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) { | 1328 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { |
| 1619 m_pFormNotify = pNotify; | 1329 m_pFormNotify = pNotify; |
| 1620 } | 1330 } |
| OLD | NEW |