diff options
author | thestig <thestig@chromium.org> | 2016-05-21 21:08:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-21 21:08:05 -0700 |
commit | b8bf55f73390a9460ec13dbffcf5d22819f9aa12 (patch) | |
tree | 15d20bce541b38f44e5defe642236d7f5ba4266c /core/fpdfdoc | |
parent | 4cafdefd77e29c9d38ad99c266a60ce296137a35 (diff) | |
download | pdfium-b8bf55f73390a9460ec13dbffcf5d22819f9aa12.tar.xz |
Get rid of CPDF_Object::GetArray().
BUG=pdfium:234
Review-Url: https://codereview.chromium.org/2001783003
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 22 | ||||
-rw-r--r-- | core/fpdfdoc/doc_formfield.cpp | 51 |
2 files changed, 24 insertions, 49 deletions
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index aa49f79c12..db2ee6c01d 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -344,15 +344,10 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, pDefFont, sFontName.Right(sFontName.GetLength() - 1)); CPDF_VariableText::Provider prd(&map); - CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") - ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() - : nullptr; - CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") - ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() - : nullptr; - int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") - ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() - : 0; + CPDF_Array* pOpts = ToArray(FPDF_GetFieldAttr(pAnnotDict, "Opt")); + CPDF_Array* pSels = ToArray(FPDF_GetFieldAttr(pAnnotDict, "I")); + CPDF_Object* pTi = FPDF_GetFieldAttr(pAnnotDict, "TI"); + int32_t nTop = pTi ? pTi->GetInteger() : 0; CFX_ByteTextBuf sBody; if (pOpts) { FX_FLOAT fy = rcBody.top; @@ -415,11 +410,10 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, } } if (sBody.GetSize() > 0) { - sAppStream << "/Tx BMC\n" - << "q\n"; - sAppStream << rcBody.left << " " << rcBody.bottom << " " - << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n"; - sAppStream << sBody.AsStringC() << "Q\nEMC\n"; + sAppStream << "/Tx BMC\nq\n" + << rcBody.left << " " << rcBody.bottom << " " + << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" + << sBody.AsStringC() << "Q\nEMC\n"; } } break; } diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp index 84d9a52dac..9849fa1e35 100644 --- a/core/fpdfdoc/doc_formfield.cpp +++ b/core/fpdfdoc/doc_formfield.cpp @@ -893,56 +893,37 @@ FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, int CPDF_FormField::GetTopVisibleIndex() { CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); - if (!pObj) { - return 0; - } - return pObj->GetInteger(); + return pObj ? pObj->GetInteger() : 0; } int CPDF_FormField::CountSelectedOptions() { - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); - if (!pObj) { - return 0; - } - CPDF_Array* pArray = pObj->GetArray(); - if (!pArray) { - return 0; - } - return static_cast<int>(pArray->GetCount()); + CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); + return pArray ? pArray->GetCount() : 0; } int CPDF_FormField::GetSelectedOptionIndex(int index) { - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); - if (!pObj) { + CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); + if (!pArray) return -1; - } - CPDF_Array* pArray = pObj->GetArray(); - if (!pArray) { + + int iCount = pArray->GetCount(); + if (iCount < 0 || index >= iCount) return -1; - } - int iCount = static_cast<int>(pArray->GetCount()); - if (iCount > 0 && index < iCount) { - return pArray->GetIntegerAt(index); - } - return -1; + return pArray->GetIntegerAt(index); } + FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) { - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); - if (!pObj) { - return FALSE; - } - CPDF_Array* pArray = pObj->GetArray(); - if (!pArray) { + CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); + if (!pArray) return FALSE; - } - size_t iCount = pArray->GetCount(); - for (size_t i = 0; i < iCount; i++) { - if (pArray->GetIntegerAt(i) == iOptIndex) { + + for (CPDF_Object* pObj : *pArray) { + if (pObj->GetInteger() == iOptIndex) return TRUE; - } } return FALSE; } + FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, FX_BOOL bSelected, FX_BOOL bNotify) { |