diff options
author | Lei Zhang <thestig@chromium.org> | 2015-12-18 17:05:11 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-12-18 17:05:11 -0800 |
commit | 4880d1a168729d42be736293fb93b514802e4f12 (patch) | |
tree | 9cfe5aa73113301487dce8bcef5139fb7295536a /core/src/fpdfdoc | |
parent | aedd4555ec1a80121f176586cb72180337e4ccd8 (diff) | |
download | pdfium-4880d1a168729d42be736293fb93b514802e4f12.tar.xz |
Merge to XFA: Get rid of a few CPDF_Object Create() methods and just use new instead.
R=ochang@chromium.org
Review URL: https://codereview.chromium.org/1540693002 .
(cherry picked from commit d866ab0b44a571c884fdd8ba5a5319adaf607559)
Review URL: https://codereview.chromium.org/1541563002 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r-- | core/src/fpdfdoc/doc_ap.cpp | 17 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_basic.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 17 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_formfield.cpp | 48 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_utils.cpp | 6 |
5 files changed, 27 insertions, 63 deletions
diff --git a/core/src/fpdfdoc/doc_ap.cpp b/core/src/fpdfdoc/doc_ap.cpp index 0efaa8caa5..d0adc06691 100644 --- a/core/src/fpdfdoc/doc_ap.cpp +++ b/core/src/fpdfdoc/doc_ap.cpp @@ -311,10 +311,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, return FALSE; } if (!pFontDict) { - pFontDict = CPDF_Dictionary::Create(); - if (!pFontDict) { - return FALSE; - } + pFontDict = new CPDF_Dictionary; pFontDict->SetAtName("Type", "Font"); pFontDict->SetAtName("Subtype", "Type1"); pFontDict->SetAtName("BaseFont", "Helvetica"); @@ -419,7 +416,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, rcBody.Normalize(); CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); if (!pAPDict) { - pAPDict = CPDF_Dictionary::Create(); + pAPDict = new CPDF_Dictionary; pAnnotDict->SetAt("AP", pAPDict); } CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); @@ -436,10 +433,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, if (pStreamResList) { CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); if (!pStreamResFontList) { - pStreamResFontList = CPDF_Dictionary::Create(); - if (!pStreamResFontList) { - return FALSE; - } + pStreamResFontList = new CPDF_Dictionary; pStreamResList->SetAt("Font", pStreamResFontList); } if (!pStreamResFontList->KeyExist(sFontName)) { @@ -684,10 +678,7 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, if (pStreamResList) { CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); if (!pStreamResFontList) { - pStreamResFontList = CPDF_Dictionary::Create(); - if (!pStreamResFontList) { - return FALSE; - } + pStreamResFontList = new CPDF_Dictionary; pStreamResList->SetAt("Font", pStreamResFontList); } if (!pStreamResFontList->KeyExist(sFontName)) { diff --git a/core/src/fpdfdoc/doc_basic.cpp b/core/src/fpdfdoc/doc_basic.cpp index d976650ae0..3fb997878b 100644 --- a/core/src/fpdfdoc/doc_basic.cpp +++ b/core/src/fpdfdoc/doc_basic.cpp @@ -329,7 +329,7 @@ FX_BOOL CPDF_FileSpec::GetFileName(CFX_WideString& csFileName) const { return TRUE; } CPDF_FileSpec::CPDF_FileSpec() { - m_pObj = CPDF_Dictionary::Create(); + m_pObj = new CPDF_Dictionary; if (CPDF_Dictionary* pDict = ToDictionary(m_pObj)) { pDict->SetAtName("Type", "Filespec"); } diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index dfdd7225b2..1d10f68f71 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -1063,10 +1063,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( pMainDict->SetAt("F", static_cast<CPDF_Object*>(filespec)); } } - CPDF_Array* pFields = CPDF_Array::Create(); - if (!pFields) { - return NULL; - } + CPDF_Array* pFields = new CPDF_Array; pMainDict->SetAt("Fields", pFields); int nCount = m_pFieldTree->m_Root.CountFields(); for (int i = 0; i < nCount; i++) { @@ -1084,16 +1081,8 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( continue; CFX_WideString fullname = GetFullName(pField->GetFieldDict()); - CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create(); - if (!pFieldDict) - return nullptr; - - CPDF_String* pString = CPDF_String::Create(fullname); - if (!pString) { - pFieldDict->Release(); - return nullptr; - } - pFieldDict->SetAt("T", pString); + CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; + pFieldDict->SetAt("T", new CPDF_String(fullname)); if (pField->GetType() == CPDF_FormField::CheckBox || pField->GetType() == CPDF_FormField::RadioButton) { CFX_WideString csExport = pField->GetCheckValue(FALSE); diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp index c6428157e5..b62f8ba0b1 100644 --- a/core/src/fpdfdoc/doc_formfield.cpp +++ b/core/src/fpdfdoc/doc_formfield.cpp @@ -571,7 +571,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, m_pDict->RemoveAt("V"); } } else if (pValue->IsArray()) { - CPDF_Array* pArray = CPDF_Array::Create(); + CPDF_Array* pArray = new CPDF_Array; int iCount = CountOptions(); for (int i = 0; i < iCount; i++) { if (i != index) { @@ -598,13 +598,10 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, if (!(m_Flags & FORMLIST_MULTISELECT)) { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); } else { - CPDF_Array* pArray = CPDF_Array::Create(); - if (!pArray) { - return FALSE; - } - FX_BOOL bSelected; + CPDF_Array* pArray = new CPDF_Array; int iCount = CountOptions(); for (int i = 0; i < iCount; i++) { + FX_BOOL bSelected; if (i != index) { bSelected = IsItemSelected(i); } else { @@ -619,10 +616,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, } } else if (m_Type == ComboBox) { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); - CPDF_Array* pI = CPDF_Array::Create(); - if (!pI) { - return FALSE; - } + CPDF_Array* pI = new CPDF_Array; pI->AddInteger(index); m_pDict->SetAt("I", pI); } @@ -740,7 +734,7 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, if (csOptLabel.IsEmpty()) return -1; - if (bNotify && m_pForm->m_pFormNotify != NULL) { + if (bNotify && m_pForm->m_pFormNotify) { int iRet = 0; if (GetType() == ListBox) iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel); @@ -751,27 +745,23 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, } CFX_ByteString csStr = PDF_EncodeText(csOptLabel, csOptLabel.GetLength()); - CPDF_Array* pOpt = NULL; CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); - if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { - pOpt = CPDF_Array::Create(); - if (pOpt == NULL) - return -1; + CPDF_Array* pOpt = ToArray(pValue); + if (!pOpt) { + pOpt = new CPDF_Array; m_pDict->SetAt("Opt", pOpt); - } else - pOpt = (CPDF_Array*)pValue; + } + int iCount = (int)pOpt->GetCount(); if (index < 0 || index >= iCount) { pOpt->AddString(csStr); index = iCount; } else { - CPDF_String* pString = CPDF_String::Create(csStr); - if (pString == NULL) - return -1; + CPDF_String* pString = new CPDF_String(csStr, FALSE); pOpt->InsertAt(index, pString); } - if (bNotify && m_pForm->m_pFormNotify != NULL) { + if (bNotify && m_pForm->m_pFormNotify) { if (GetType() == ListBox) m_pForm->m_pFormNotify->AfterSelectionChange(this); if (GetType() == ComboBox) @@ -781,7 +771,7 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, return index; } FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { - if (bNotify && m_pForm->m_pFormNotify != NULL) { + if (bNotify && m_pForm->m_pFormNotify) { int iRet = 0; CFX_WideString csValue; int iIndex = GetSelectedIndex(0); @@ -801,7 +791,7 @@ FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { m_pDict->RemoveAt("I"); m_pDict->RemoveAt("TI"); - if (bNotify && m_pForm->m_pFormNotify != NULL) { + if (bNotify && m_pForm->m_pFormNotify) { if (GetType() == ListBox) m_pForm->m_pFormNotify->AfterSelectionChange(this); if (GetType() == ComboBox) @@ -985,10 +975,7 @@ FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, if (!bSelected) { return TRUE; } - pArray = CPDF_Array::Create(); - if (!pArray) { - return FALSE; - } + pArray = new CPDF_Array; m_pDict->SetAt("I", pArray); } FX_BOOL bReturn = FALSE; @@ -1031,10 +1018,7 @@ FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, return FALSE; } } - CPDF_Number* pNum = CPDF_Number::Create(iOptIndex); - if (!pNum) { - return FALSE; - } + CPDF_Number* pNum = new CPDF_Number(iOptIndex); pArray->InsertAt(i, pNum); bReturn = TRUE; break; diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp index b0705ea556..01a7470ef0 100644 --- a/core/src/fpdfdoc/doc_utils.cpp +++ b/core/src/fpdfdoc/doc_utils.cpp @@ -228,7 +228,7 @@ void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { return; } if (!pFormDict) { - pFormDict = CPDF_Dictionary::Create(); + pFormDict = new CPDF_Dictionary; FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); CPDF_Dictionary* pRoot = pDocument->GetRoot(); pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); @@ -560,12 +560,12 @@ void AddInterFormFont(CPDF_Dictionary*& pFormDict, } CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); if (!pDR) { - pDR = CPDF_Dictionary::Create(); + pDR = new CPDF_Dictionary; pFormDict->SetAt("DR", pDR); } CPDF_Dictionary* pFonts = pDR->GetDict("Font"); if (!pFonts) { - pFonts = CPDF_Dictionary::Create(); + pFonts = new CPDF_Dictionary; pDR->SetAt("Font", pFonts); } if (csNameTag.IsEmpty()) { |