Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: core/src/fpdfdoc/doc_formfield.cpp

Issue 1417893003: Add type cast definitions for CPDF_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 if (pValue == NULL) { 301 if (pValue == NULL) {
302 return CFX_WideString(); 302 return CFX_WideString();
303 } 303 }
304 } 304 }
305 switch (pValue->GetType()) { 305 switch (pValue->GetType()) {
306 case PDFOBJ_STRING: 306 case PDFOBJ_STRING:
307 case PDFOBJ_STREAM: 307 case PDFOBJ_STREAM:
308 return pValue->GetUnicodeText(); 308 return pValue->GetUnicodeText();
309 case PDFOBJ_ARRAY: 309 case PDFOBJ_ARRAY:
310 pValue = ((CPDF_Array*)pValue)->GetElementValue(0); 310 pValue = pValue->AsArray()->GetElementValue(0);
311 if (pValue) { 311 if (pValue)
312 return pValue->GetUnicodeText(); 312 return pValue->GetUnicodeText();
313 }
314 break; 313 break;
315 } 314 }
316 return CFX_WideString(); 315 return CFX_WideString();
317 } 316 }
318 CFX_WideString CPDF_FormField::GetValue() { 317 CFX_WideString CPDF_FormField::GetValue() {
319 return GetValue(FALSE); 318 return GetValue(FALSE);
320 } 319 }
321 CFX_WideString CPDF_FormField::GetDefaultValue() { 320 CFX_WideString CPDF_FormField::GetDefaultValue() {
322 return GetValue(TRUE); 321 return GetValue(TRUE);
323 } 322 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (pWidgetDict->KeyExist("MaxLen")) { 411 if (pWidgetDict->KeyExist("MaxLen")) {
413 return pWidgetDict->GetInteger("MaxLen"); 412 return pWidgetDict->GetInteger("MaxLen");
414 } 413 }
415 } 414 }
416 return 0; 415 return 0;
417 } 416 }
418 return pObj->GetInteger(); 417 return pObj->GetInteger();
419 } 418 }
420 int CPDF_FormField::CountSelectedItems() { 419 int CPDF_FormField::CountSelectedItems() {
421 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 420 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
422 if (pValue == NULL) { 421 if (!pValue) {
423 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 422 pValue = FPDF_GetFieldAttr(m_pDict, "I");
424 if (pValue == NULL) { 423 if (!pValue)
425 return 0; 424 return 0;
426 }
427 } 425 }
428 426
429 if (pValue->IsString() || pValue->IsNumber()) 427 if (pValue->IsString() || pValue->IsNumber())
430 return pValue->GetString().IsEmpty() ? 0 : 1; 428 return pValue->GetString().IsEmpty() ? 0 : 1;
431 429 if (CPDF_Array* pArray = pValue->AsArray())
432 if (pValue->GetType() != PDFOBJ_ARRAY) { 430 return pArray->GetCount();
433 return 0; 431 return 0;
434 }
435 return ((CPDF_Array*)pValue)->GetCount();
436 } 432 }
437 int CPDF_FormField::GetSelectedIndex(int index) { 433 int CPDF_FormField::GetSelectedIndex(int index) {
438 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 434 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
Lei Zhang 2015/10/21 21:44:09 FYI, this block is the same as the start of CPDF_F
dsinclair 2015/10/22 13:31:12 Almost, the return values are different. I'm going
439 if (pValue == NULL) { 435 if (!pValue) {
440 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 436 pValue = FPDF_GetFieldAttr(m_pDict, "I");
441 if (pValue == NULL) { 437 if (!pValue)
442 return -1; 438 return -1;
443 }
444 } 439 }
445 if (pValue->IsNumber()) 440 if (pValue->IsNumber())
446 return pValue->GetInteger(); 441 return pValue->GetInteger();
447 442
448 CFX_WideString sel_value; 443 CFX_WideString sel_value;
449 if (pValue->IsString()) { 444 if (pValue->IsString()) {
450 if (index != 0) 445 if (index != 0)
451 return -1; 446 return -1;
452
453 sel_value = pValue->GetUnicodeText(); 447 sel_value = pValue->GetUnicodeText();
454 } else { 448 } else {
455 if (pValue->GetType() != PDFOBJ_ARRAY) { 449 CPDF_Array* pArray = pValue->AsArray();
450 if (!pArray || index < 0)
456 return -1; 451 return -1;
457 } 452
458 if (index < 0) { 453 CPDF_Object* elementValue = pArray->GetElementValue(index);
459 return -1;
460 }
461 CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index);
462 sel_value = 454 sel_value =
463 elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); 455 elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
464 } 456 }
465 if (index < CountSelectedOptions()) { 457 if (index < CountSelectedOptions()) {
466 int iOptIndex = GetSelectedOptionIndex(index); 458 int iOptIndex = GetSelectedOptionIndex(index);
467 CFX_WideString csOpt = GetOptionValue(iOptIndex); 459 CFX_WideString csOpt = GetOptionValue(iOptIndex);
468 if (csOpt == sel_value) { 460 if (csOpt == sel_value) {
469 return iOptIndex; 461 return iOptIndex;
470 } 462 }
471 } 463 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 522
531 if (pValue->IsString()) 523 if (pValue->IsString())
532 return pValue->GetUnicodeText() == opt_value; 524 return pValue->GetUnicodeText() == opt_value;
533 525
534 if (pValue->IsNumber()) { 526 if (pValue->IsNumber()) {
535 if (pValue->GetString().IsEmpty()) 527 if (pValue->GetString().IsEmpty())
536 return FALSE; 528 return FALSE;
537 return (pValue->GetInteger() == index); 529 return (pValue->GetInteger() == index);
538 } 530 }
539 531
540 if (pValue->GetType() != PDFOBJ_ARRAY) { 532 CPDF_Array* pArray = pValue->AsArray();
533 if (!pArray)
541 return FALSE; 534 return FALSE;
542 } 535
543 CPDF_Array* pArray = (CPDF_Array*)pValue;
544 int iPos = -1; 536 int iPos = -1;
545 for (int j = 0; j < CountSelectedOptions(); j++) { 537 for (int j = 0; j < CountSelectedOptions(); j++) {
546 if (GetSelectedOptionIndex(j) == index) { 538 if (GetSelectedOptionIndex(j) == index) {
547 iPos = j; 539 iPos = j;
548 break; 540 break;
549 } 541 }
550 } 542 }
551 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) 543 for (FX_DWORD i = 0; i < pArray->GetCount(); i++)
552 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && 544 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value &&
553 (int)i == iPos) { 545 (int)i == iPos) {
(...skipping 23 matching lines...) Expand all
577 } 569 }
578 if (!bSelected) { 570 if (!bSelected) {
579 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 571 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
580 if (pValue != NULL) { 572 if (pValue != NULL) {
581 if (m_Type == ListBox) { 573 if (m_Type == ListBox) {
582 SelectOption(index, FALSE); 574 SelectOption(index, FALSE);
583 if (pValue->IsString()) { 575 if (pValue->IsString()) {
584 if (pValue->GetUnicodeText() == opt_value) { 576 if (pValue->GetUnicodeText() == opt_value) {
585 m_pDict->RemoveAt("V"); 577 m_pDict->RemoveAt("V");
586 } 578 }
587 } else if (pValue->GetType() == PDFOBJ_ARRAY) { 579 } else if (pValue->IsArray()) {
588 CPDF_Array* pArray = CPDF_Array::Create(); 580 CPDF_Array* pArray = CPDF_Array::Create();
589 if (pArray == NULL) { 581 if (!pArray)
Tom Sepez 2015/10/21 21:07:01 CPDF_Array::Create() can't fail.
dsinclair 2015/10/21 21:15:14 Done.
590 return FALSE; 582 return FALSE;
591 } 583
592 int iCount = CountOptions(); 584 int iCount = CountOptions();
593 for (int i = 0; i < iCount; i++) { 585 for (int i = 0; i < iCount; i++) {
594 if (i != index) { 586 if (i != index) {
595 if (IsItemSelected(i)) { 587 if (IsItemSelected(i)) {
596 opt_value = GetOptionValue(i); 588 opt_value = GetOptionValue(i);
597 pArray->AddString(PDF_EncodeText(opt_value)); 589 pArray->AddString(PDF_EncodeText(opt_value));
598 } 590 }
599 } 591 }
600 } 592 }
601 if (pArray->GetCount() < 1) { 593 if (pArray->GetCount() < 1) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 688 }
697 if (!m_pForm->m_bGenerateAP) { 689 if (!m_pForm->m_bGenerateAP) {
698 return; 690 return;
699 } 691 }
700 for (int i = 0; i < CountControls(); i++) { 692 for (int i = 0; i < CountControls(); i++) {
701 CPDF_FormControl* pControl = GetControl(i); 693 CPDF_FormControl* pControl = GetControl(i);
702 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict); 694 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict);
703 } 695 }
704 } 696 }
705 int CPDF_FormField::CountOptions() { 697 int CPDF_FormField::CountOptions() {
706 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 698 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
707 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { 699 return pArray ? pArray->GetCount() : 0;
708 return 0;
709 }
710 return ((CPDF_Array*)pValue)->GetCount();
711 } 700 }
712 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { 701 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
713 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 702 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
714 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { 703 if (!pArray)
715 return CFX_WideString(); 704 return CFX_WideString();
716 } 705
717 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index); 706 CPDF_Object* pOption = pArray->GetElementValue(index);
718 if (pOption == NULL) { 707 if (!pOption)
719 return CFX_WideString(); 708 return CFX_WideString();
720 } 709 if (CPDF_Array* pOptionArray = pOption->AsArray())
721 if (pOption->GetType() == PDFOBJ_ARRAY) { 710 pOption = pOptionArray->GetElementValue(sub_index);
722 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index);
723 }
724 711
725 CPDF_String* pString = ToString(pOption); 712 CPDF_String* pString = ToString(pOption);
726 return pString ? pString->GetUnicodeText() : CFX_WideString(); 713 return pString ? pString->GetUnicodeText() : CFX_WideString();
727 } 714 }
728 CFX_WideString CPDF_FormField::GetOptionLabel(int index) { 715 CFX_WideString CPDF_FormField::GetOptionLabel(int index) {
729 return GetOptionText(index, 1); 716 return GetOptionText(index, 1);
730 } 717 }
731 CFX_WideString CPDF_FormField::GetOptionValue(int index) { 718 CFX_WideString CPDF_FormField::GetOptionValue(int index) {
732 return GetOptionText(index, 0); 719 return GetOptionText(index, 0);
733 } 720 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 776 }
790 } else { 777 } else {
791 if (i == iControlIndex) { 778 if (i == iControlIndex) {
792 pCtrl->CheckControl(bChecked); 779 pCtrl->CheckControl(bChecked);
793 } else if (bChecked) { 780 } else if (bChecked) {
794 pCtrl->CheckControl(FALSE); 781 pCtrl->CheckControl(FALSE);
795 } 782 }
796 } 783 }
797 } 784 }
798 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 785 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
799 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) { 786 if (!pOpt || !pOpt->IsArray()) {
Tom Sepez 2015/10/21 21:07:01 nit: maybe !ToArray(pOpt)
dsinclair 2015/10/21 21:15:14 Done.
800 if (bChecked) { 787 if (bChecked) {
801 m_pDict->SetAtName("V", csBExport); 788 m_pDict->SetAtName("V", csBExport);
802 } else { 789 } else {
803 CFX_ByteString csV; 790 CFX_ByteString csV;
804 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 791 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
805 if (pV != NULL) { 792 if (pV != NULL) {
806 csV = pV->GetString(); 793 csV = pV->GetString();
807 } 794 }
808 if (csV == csBExport) { 795 if (csV == csBExport) {
809 m_pDict->SetAtName("V", "Off"); 796 m_pDict->SetAtName("V", "Off");
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) 1038 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font"))
1052 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( 1039 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(
1053 font_name); 1040 font_name);
1054 1041
1055 if (pFontDict == NULL) { 1042 if (pFontDict == NULL) {
1056 return; 1043 return;
1057 } 1044 }
1058 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 1045 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1059 m_FontSize = FX_atof(syntax.GetWord()); 1046 m_FontSize = FX_atof(syntax.GetWord());
1060 } 1047 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698