| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
| 8 #include "doc_utils.h" | 8 #include "doc_utils.h" |
| 9 | 9 |
| 10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { | 10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 return pObj->GetInteger(); | 418 return pObj->GetInteger(); |
| 419 } | 419 } |
| 420 int CPDF_FormField::CountSelectedItems() { | 420 int CPDF_FormField::CountSelectedItems() { |
| 421 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 421 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 422 if (pValue == NULL) { | 422 if (pValue == NULL) { |
| 423 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 423 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 424 if (pValue == NULL) { | 424 if (pValue == NULL) { |
| 425 return 0; | 425 return 0; |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 if (pValue->GetType() == PDFOBJ_STRING) { | 428 |
| 429 if (pValue->GetString().IsEmpty()) { | 429 if (pValue->IsString() || pValue->IsNumber()) |
| 430 return 0; | 430 return pValue->GetString().IsEmpty() ? 0 : 1; |
| 431 } | 431 |
| 432 return 1; | |
| 433 } | |
| 434 if (pValue->IsNumber()) { | |
| 435 if (pValue->GetString().IsEmpty()) { | |
| 436 return 0; | |
| 437 } | |
| 438 return 1; | |
| 439 } | |
| 440 if (pValue->GetType() != PDFOBJ_ARRAY) { | 432 if (pValue->GetType() != PDFOBJ_ARRAY) { |
| 441 return 0; | 433 return 0; |
| 442 } | 434 } |
| 443 return ((CPDF_Array*)pValue)->GetCount(); | 435 return ((CPDF_Array*)pValue)->GetCount(); |
| 444 } | 436 } |
| 445 int CPDF_FormField::GetSelectedIndex(int index) { | 437 int CPDF_FormField::GetSelectedIndex(int index) { |
| 446 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 438 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 447 if (pValue == NULL) { | 439 if (pValue == NULL) { |
| 448 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 440 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 449 if (pValue == NULL) { | 441 if (pValue == NULL) { |
| 450 return -1; | 442 return -1; |
| 451 } | 443 } |
| 452 } | 444 } |
| 453 if (pValue->IsNumber()) | 445 if (pValue->IsNumber()) |
| 454 return pValue->GetInteger(); | 446 return pValue->GetInteger(); |
| 455 | 447 |
| 456 CFX_WideString sel_value; | 448 CFX_WideString sel_value; |
| 457 if (pValue->GetType() == PDFOBJ_STRING) { | 449 if (pValue->IsString()) { |
| 458 if (index != 0) { | 450 if (index != 0) |
| 459 return -1; | 451 return -1; |
| 460 } | 452 |
| 461 sel_value = pValue->GetUnicodeText(); | 453 sel_value = pValue->GetUnicodeText(); |
| 462 } else { | 454 } else { |
| 463 if (pValue->GetType() != PDFOBJ_ARRAY) { | 455 if (pValue->GetType() != PDFOBJ_ARRAY) { |
| 464 return -1; | 456 return -1; |
| 465 } | 457 } |
| 466 if (index < 0) { | 458 if (index < 0) { |
| 467 return -1; | 459 return -1; |
| 468 } | 460 } |
| 469 CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index); | 461 CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index); |
| 470 sel_value = | 462 sel_value = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 return TRUE; | 520 return TRUE; |
| 529 } | 521 } |
| 530 CFX_WideString opt_value = GetOptionValue(index); | 522 CFX_WideString opt_value = GetOptionValue(index); |
| 531 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 523 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 532 if (pValue == NULL) { | 524 if (pValue == NULL) { |
| 533 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 525 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 534 if (pValue == NULL) { | 526 if (pValue == NULL) { |
| 535 return FALSE; | 527 return FALSE; |
| 536 } | 528 } |
| 537 } | 529 } |
| 538 if (pValue->GetType() == PDFOBJ_STRING) { | 530 |
| 539 if (pValue->GetUnicodeText() == opt_value) { | 531 if (pValue->IsString()) |
| 540 return TRUE; | 532 return (pValue->GetUnicodeText() == opt_value); |
| 541 } | 533 |
| 542 return FALSE; | 534 if (pValue->IsNumber()) { |
| 535 if (pValue->GetString().IsEmpty()) |
| 536 return FALSE; |
| 537 return (pValue->GetInteger() == index); |
| 543 } | 538 } |
| 544 if (pValue->IsNumber()) { | 539 |
| 545 if (pValue->GetString().IsEmpty()) { | |
| 546 return FALSE; | |
| 547 } | |
| 548 if (pValue->GetInteger() == index) { | |
| 549 return TRUE; | |
| 550 } | |
| 551 return FALSE; | |
| 552 } | |
| 553 if (pValue->GetType() != PDFOBJ_ARRAY) { | 540 if (pValue->GetType() != PDFOBJ_ARRAY) { |
| 554 return FALSE; | 541 return FALSE; |
| 555 } | 542 } |
| 556 CPDF_Array* pArray = (CPDF_Array*)pValue; | 543 CPDF_Array* pArray = (CPDF_Array*)pValue; |
| 557 int iPos = -1; | 544 int iPos = -1; |
| 558 for (int j = 0; j < CountSelectedOptions(); j++) { | 545 for (int j = 0; j < CountSelectedOptions(); j++) { |
| 559 if (GetSelectedOptionIndex(j) == index) { | 546 if (GetSelectedOptionIndex(j) == index) { |
| 560 iPos = j; | 547 iPos = j; |
| 561 break; | 548 break; |
| 562 } | 549 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 586 } | 573 } |
| 587 if (iRet < 0) { | 574 if (iRet < 0) { |
| 588 return FALSE; | 575 return FALSE; |
| 589 } | 576 } |
| 590 } | 577 } |
| 591 if (!bSelected) { | 578 if (!bSelected) { |
| 592 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 579 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 593 if (pValue != NULL) { | 580 if (pValue != NULL) { |
| 594 if (m_Type == ListBox) { | 581 if (m_Type == ListBox) { |
| 595 SelectOption(index, FALSE); | 582 SelectOption(index, FALSE); |
| 596 if (pValue->GetType() == PDFOBJ_STRING) { | 583 if (pValue->IsString()) { |
| 597 if (pValue->GetUnicodeText() == opt_value) { | 584 if (pValue->GetUnicodeText() == opt_value) { |
| 598 m_pDict->RemoveAt("V"); | 585 m_pDict->RemoveAt("V"); |
| 599 } | 586 } |
| 600 } else if (pValue->GetType() == PDFOBJ_ARRAY) { | 587 } else if (pValue->GetType() == PDFOBJ_ARRAY) { |
| 601 CPDF_Array* pArray = CPDF_Array::Create(); | 588 CPDF_Array* pArray = CPDF_Array::Create(); |
| 602 if (pArray == NULL) { | 589 if (pArray == NULL) { |
| 603 return FALSE; | 590 return FALSE; |
| 604 } | 591 } |
| 605 int iCount = CountOptions(); | 592 int iCount = CountOptions(); |
| 606 for (int i = 0; i < iCount; i++) { | 593 for (int i = 0; i < iCount; i++) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { | 714 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { |
| 728 return CFX_WideString(); | 715 return CFX_WideString(); |
| 729 } | 716 } |
| 730 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index); | 717 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index); |
| 731 if (pOption == NULL) { | 718 if (pOption == NULL) { |
| 732 return CFX_WideString(); | 719 return CFX_WideString(); |
| 733 } | 720 } |
| 734 if (pOption->GetType() == PDFOBJ_ARRAY) { | 721 if (pOption->GetType() == PDFOBJ_ARRAY) { |
| 735 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index); | 722 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index); |
| 736 } | 723 } |
| 737 if (pOption == NULL || pOption->GetType() != PDFOBJ_STRING) { | 724 |
| 738 return CFX_WideString(); | 725 CPDF_String* pString = ToString(pOption); |
| 739 } | 726 return pString ? pString->GetUnicodeText() : CFX_WideString(); |
| 740 return ((CPDF_String*)pOption)->GetUnicodeText(); | |
| 741 } | 727 } |
| 742 CFX_WideString CPDF_FormField::GetOptionLabel(int index) { | 728 CFX_WideString CPDF_FormField::GetOptionLabel(int index) { |
| 743 return GetOptionText(index, 1); | 729 return GetOptionText(index, 1); |
| 744 } | 730 } |
| 745 CFX_WideString CPDF_FormField::GetOptionValue(int index) { | 731 CFX_WideString CPDF_FormField::GetOptionValue(int index) { |
| 746 return GetOptionText(index, 0); | 732 return GetOptionText(index, 0); |
| 747 } | 733 } |
| 748 int CPDF_FormField::FindOption(CFX_WideString csOptLabel) { | 734 int CPDF_FormField::FindOption(CFX_WideString csOptLabel) { |
| 749 int iCount = CountOptions(); | 735 int iCount = CountOptions(); |
| 750 for (int i = 0; i < iCount; i++) { | 736 for (int i = 0; i < iCount; i++) { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) | 1051 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) |
| 1066 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( | 1052 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( |
| 1067 font_name); | 1053 font_name); |
| 1068 | 1054 |
| 1069 if (pFontDict == NULL) { | 1055 if (pFontDict == NULL) { |
| 1070 return; | 1056 return; |
| 1071 } | 1057 } |
| 1072 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 1058 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
| 1073 m_FontSize = FX_atof(syntax.GetWord()); | 1059 m_FontSize = FX_atof(syntax.GetWord()); |
| 1074 } | 1060 } |
| OLD | NEW |