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

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

Issue 1417933002: Add type cast definitions for CPDF_String. (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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
Lei Zhang 2015/10/21 16:55:56 This should still return 0 or 1, rather than true/
dsinclair 2015/10/21 17:08:05 Done.
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
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())
532 return (pValue->GetUnicodeText() == opt_value);
Tom Sepez 2015/10/21 17:12:50 nit: overparenthesized.
dsinclair 2015/10/21 17:40:01 Done.
533
534 if (pValue->IsNumber()) {
535 if (pValue->GetString().IsEmpty())
536 return FALSE;
537 if (pValue->GetInteger() == index)
Lei Zhang 2015/10/21 16:55:56 just return pValue->GetInteger() == index;
dsinclair 2015/10/21 17:08:05 Done.
540 return TRUE; 538 return TRUE;
541 }
542 return FALSE; 539 return FALSE;
543 } 540 }
544 if (pValue->IsNumber()) { 541
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) { 542 if (pValue->GetType() != PDFOBJ_ARRAY) {
554 return FALSE; 543 return FALSE;
555 } 544 }
556 CPDF_Array* pArray = (CPDF_Array*)pValue; 545 CPDF_Array* pArray = (CPDF_Array*)pValue;
557 int iPos = -1; 546 int iPos = -1;
558 for (int j = 0; j < CountSelectedOptions(); j++) { 547 for (int j = 0; j < CountSelectedOptions(); j++) {
559 if (GetSelectedOptionIndex(j) == index) { 548 if (GetSelectedOptionIndex(j) == index) {
560 iPos = j; 549 iPos = j;
561 break; 550 break;
562 } 551 }
(...skipping 23 matching lines...) Expand all
586 } 575 }
587 if (iRet < 0) { 576 if (iRet < 0) {
588 return FALSE; 577 return FALSE;
589 } 578 }
590 } 579 }
591 if (!bSelected) { 580 if (!bSelected) {
592 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 581 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
593 if (pValue != NULL) { 582 if (pValue != NULL) {
594 if (m_Type == ListBox) { 583 if (m_Type == ListBox) {
595 SelectOption(index, FALSE); 584 SelectOption(index, FALSE);
596 if (pValue->GetType() == PDFOBJ_STRING) { 585 if (pValue->IsString()) {
597 if (pValue->GetUnicodeText() == opt_value) { 586 if (pValue->GetUnicodeText() == opt_value) {
598 m_pDict->RemoveAt("V"); 587 m_pDict->RemoveAt("V");
599 } 588 }
600 } else if (pValue->GetType() == PDFOBJ_ARRAY) { 589 } else if (pValue->GetType() == PDFOBJ_ARRAY) {
601 CPDF_Array* pArray = CPDF_Array::Create(); 590 CPDF_Array* pArray = CPDF_Array::Create();
602 if (pArray == NULL) { 591 if (pArray == NULL) {
603 return FALSE; 592 return FALSE;
604 } 593 }
605 int iCount = CountOptions(); 594 int iCount = CountOptions();
606 for (int i = 0; i < iCount; i++) { 595 for (int i = 0; i < iCount; i++) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { 716 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
728 return CFX_WideString(); 717 return CFX_WideString();
729 } 718 }
730 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index); 719 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index);
731 if (pOption == NULL) { 720 if (pOption == NULL) {
732 return CFX_WideString(); 721 return CFX_WideString();
733 } 722 }
734 if (pOption->GetType() == PDFOBJ_ARRAY) { 723 if (pOption->GetType() == PDFOBJ_ARRAY) {
735 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index); 724 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index);
736 } 725 }
737 if (pOption == NULL || pOption->GetType() != PDFOBJ_STRING) { 726
738 return CFX_WideString(); 727 CPDF_String* pString = ToString(pOption);
739 } 728 return pString ? pString->GetUnicodeText() : CFX_WideString();
740 return ((CPDF_String*)pOption)->GetUnicodeText();
741 } 729 }
742 CFX_WideString CPDF_FormField::GetOptionLabel(int index) { 730 CFX_WideString CPDF_FormField::GetOptionLabel(int index) {
743 return GetOptionText(index, 1); 731 return GetOptionText(index, 1);
744 } 732 }
745 CFX_WideString CPDF_FormField::GetOptionValue(int index) { 733 CFX_WideString CPDF_FormField::GetOptionValue(int index) {
746 return GetOptionText(index, 0); 734 return GetOptionText(index, 0);
747 } 735 }
748 int CPDF_FormField::FindOption(CFX_WideString csOptLabel) { 736 int CPDF_FormField::FindOption(CFX_WideString csOptLabel) {
749 int iCount = CountOptions(); 737 int iCount = CountOptions();
750 for (int i = 0; i < iCount; i++) { 738 for (int i = 0; i < iCount; i++) {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) 1053 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font"))
1066 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( 1054 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(
1067 font_name); 1055 font_name);
1068 1056
1069 if (pFontDict == NULL) { 1057 if (pFontDict == NULL) {
1070 return; 1058 return;
1071 } 1059 }
1072 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 1060 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1073 m_FontSize = FX_atof(syntax.GetWord()); 1061 m_FontSize = FX_atof(syntax.GetWord());
1074 } 1062 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698