From d866ab0b44a571c884fdd8ba5a5319adaf607559 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 18 Dec 2015 16:26:45 -0800 Subject: 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 . --- core/include/fpdfapi/fpdf_objects.h | 60 ++++++---------------- core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp | 2 +- core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 6 +-- core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp | 4 +- core/src/fpdfapi/fpdf_font/fpdf_font.cpp | 19 +++---- core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 12 ++--- .../src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 50 +++++++++--------- .../fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 4 +- .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 32 ++++++------ core/src/fpdfdoc/doc_ap.cpp | 17 ++---- core/src/fpdfdoc/doc_basic.cpp | 2 +- core/src/fpdfdoc/doc_form.cpp | 17 ++---- core/src/fpdfdoc/doc_formfield.cpp | 24 +++------ core/src/fpdfdoc/doc_utils.cpp | 6 +-- fpdfsdk/src/fpdfeditpage.cpp | 4 +- fpdfsdk/src/fpdfppo.cpp | 12 ++--- 16 files changed, 102 insertions(+), 169 deletions(-) diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index c220a0cb1e..e80801c507 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -115,7 +115,8 @@ class CPDF_Object { const CPDF_String* AsString() const; protected: - CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) {} + explicit CPDF_Object(FX_DWORD type) + : m_Type(type), m_ObjNum(0), m_GenNum(0) {} ~CPDF_Object() {} void Destroy(); @@ -136,10 +137,9 @@ class CPDF_Object { }; class CPDF_Boolean : public CPDF_Object { public: - static CPDF_Boolean* Create(FX_BOOL value) { return new CPDF_Boolean(value); } - CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) {} - CPDF_Boolean(FX_BOOL value) : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) {} + explicit CPDF_Boolean(FX_BOOL value) + : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) {} FX_BOOL Identical(CPDF_Boolean* pOther) const { return m_bValue == pOther->m_bValue; @@ -158,21 +158,13 @@ inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { class CPDF_Number : public CPDF_Object { public: - static CPDF_Number* Create(int value) { return new CPDF_Number(value); } - - static CPDF_Number* Create(FX_FLOAT value) { return new CPDF_Number(value); } - - static CPDF_Number* Create(const CFX_ByteStringC& str) { - return new CPDF_Number(str); - } - CPDF_Number() : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(0) {} - CPDF_Number(int value); + explicit CPDF_Number(int value); - CPDF_Number(FX_FLOAT value); + explicit CPDF_Number(FX_FLOAT value); - CPDF_Number(const CFX_ByteStringC& str); + explicit CPDF_Number(const CFX_ByteStringC& str); FX_BOOL Identical(CPDF_Number* pOther) const; @@ -215,20 +207,12 @@ inline const CPDF_Number* ToNumber(const CPDF_Object* obj) { class CPDF_String : public CPDF_Object { public: - static CPDF_String* Create(const CFX_ByteString& str, FX_BOOL bHex = FALSE) { - return new CPDF_String(str, bHex); - } - - static CPDF_String* Create(const CFX_WideString& str) { - return new CPDF_String(str); - } - CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) {} - CPDF_String(const CFX_ByteString& str, FX_BOOL bHex = FALSE) + CPDF_String(const CFX_ByteString& str, FX_BOOL bHex) : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) {} - CPDF_String(const CFX_WideString& str); + explicit CPDF_String(const CFX_WideString& str); CFX_ByteString& GetString() { return m_String; } @@ -253,21 +237,12 @@ inline const CPDF_String* ToString(const CPDF_Object* obj) { class CPDF_Name : public CPDF_Object { public: - static CPDF_Name* Create(const CFX_ByteString& str) { - return new CPDF_Name(str); - } - - static CPDF_Name* Create(const CFX_ByteStringC& str) { - return new CPDF_Name(str); - } - - static CPDF_Name* Create(const FX_CHAR* str) { return new CPDF_Name(str); } - - CPDF_Name(const CFX_ByteString& str) + explicit CPDF_Name(const CFX_ByteString& str) + : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} + explicit CPDF_Name(const CFX_ByteStringC& str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} - CPDF_Name(const CFX_ByteStringC& str) + explicit CPDF_Name(const FX_CHAR* str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} - CPDF_Name(const FX_CHAR* str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} CFX_ByteString& GetString() { return m_Name; } @@ -288,8 +263,6 @@ inline const CPDF_Name* ToName(const CPDF_Object* obj) { class CPDF_Array : public CPDF_Object { public: - static CPDF_Array* Create() { return new CPDF_Array(); } - CPDF_Array() : CPDF_Object(PDFOBJ_ARRAY) {} FX_DWORD GetCount() const { return m_Objects.GetSize(); } @@ -365,8 +338,6 @@ inline const CPDF_Array* ToArray(const CPDF_Object* obj) { class CPDF_Dictionary : public CPDF_Object { public: - static CPDF_Dictionary* Create() { return new CPDF_Dictionary(); } - CPDF_Dictionary() : CPDF_Object(PDFOBJ_DICTIONARY) {} CPDF_Object* GetElement(const CFX_ByteStringC& key) const; @@ -565,10 +536,9 @@ class CPDF_StreamAcc { class CPDF_Null : public CPDF_Object { public: - static CPDF_Null* Create() { return new CPDF_Null(); } - CPDF_Null() : CPDF_Object(PDFOBJ_NULL) {} }; + class CPDF_Reference : public CPDF_Object { public: CPDF_Reference(CPDF_IndirectObjects* pDoc, int objnum) @@ -599,7 +569,7 @@ inline const CPDF_Reference* ToReference(const CPDF_Object* obj) { class CPDF_IndirectObjects { public: - CPDF_IndirectObjects(CPDF_Parser* pParser); + explicit CPDF_IndirectObjects(CPDF_Parser* pParser); ~CPDF_IndirectObjects(); diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp index 5810da572b..f00cf5f8f5 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp @@ -106,7 +106,7 @@ void CPDF_PageContentGenerate::ProcessForm(CFX_ByteTextBuf& buf, return; } CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); - CPDF_Dictionary* pFormDict = CPDF_Dictionary::Create(); + CPDF_Dictionary* pFormDict = new CPDF_Dictionary; pFormDict->SetAtName("Type", "XObject"); pFormDict->SetAtName("Subtype", "Form"); CFX_FloatRect bbox = m_pPage->GetPageBBox(); diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index b200b8d37d..328728ef24 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -2010,7 +2010,7 @@ void CPDF_Creator::InitID(FX_BOOL bDefault) { FX_BOOL bNewId = !m_pIDArray; if (!m_pIDArray) { FX_DWORD* pBuffer = NULL; - m_pIDArray = CPDF_Array::Create(); + m_pIDArray = new CPDF_Array; CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; if (pID1) { m_pIDArray->Add(pID1->Clone()); @@ -2018,7 +2018,7 @@ void CPDF_Creator::InitID(FX_BOOL bDefault) { pBuffer = FX_Alloc(FX_DWORD, 4); PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, pBuffer); CFX_ByteStringC bsBuffer((const uint8_t*)pBuffer, 4 * sizeof(FX_DWORD)); - m_pIDArray->Add(CPDF_String::Create(bsBuffer, TRUE), m_pDocument); + m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); } FX_Free(pBuffer); } @@ -2034,7 +2034,7 @@ void CPDF_Creator::InitID(FX_BOOL bDefault) { FX_DWORD* pBuffer = FX_Alloc(FX_DWORD, 4); PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, pBuffer); CFX_ByteStringC bsBuffer((const uint8_t*)pBuffer, 4 * sizeof(FX_DWORD)); - m_pIDArray->Add(CPDF_String::Create(bsBuffer, TRUE), m_pDocument); + m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); FX_Free(pBuffer); return; } diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp index 10b0272b52..2b68a0403f 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp @@ -33,7 +33,7 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size) { csname = "DeviceRGB"; } else if (num_comps == 4) { csname = "DeviceCMYK"; - CPDF_Array* pDecode = CPDF_Array::Create(); + CPDF_Array* pDecode = new CPDF_Array; for (int n = 0; n < 4; n++) { pDecode->AddInteger(1); pDecode->AddInteger(0); @@ -151,7 +151,7 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, pBuf[4] = (FX_CHAR)set_g; pBuf[5] = (FX_CHAR)set_b; ct.ReleaseBuffer(6); - pCS->Add(CPDF_String::Create(ct, TRUE)); + pCS->Add(new CPDF_String(ct, TRUE)); pDict->SetAt("ColorSpace", pCS); } pDict->SetAtInteger("BitsPerComponent", 1); diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp index 3170b55e20..7b3f8055fb 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp @@ -390,7 +390,7 @@ CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, if (pFont) { return pFont; } - CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); + CPDF_Dictionary* pDict = new CPDF_Dictionary; pDict->SetAtName("Type", "Font"); pDict->SetAtName("Subtype", "Type1"); pDict->SetAtName("BaseFont", fontname); @@ -1391,28 +1391,29 @@ CPDF_Object* CPDF_FontEncoding::Realize() { } if (predefined) { if (predefined == PDFFONT_ENCODING_WINANSI) { - return CPDF_Name::Create("WinAnsiEncoding"); + return new CPDF_Name("WinAnsiEncoding"); } if (predefined == PDFFONT_ENCODING_MACROMAN) { - return CPDF_Name::Create("MacRomanEncoding"); + return new CPDF_Name("MacRomanEncoding"); } if (predefined == PDFFONT_ENCODING_MACEXPERT) { - return CPDF_Name::Create("MacExpertEncoding"); + return new CPDF_Name("MacExpertEncoding"); } return NULL; } - CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); - pDict->SetAtName("BaseEncoding", "WinAnsiEncoding"); const FX_WORD* pStandard = PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI); - CPDF_Array* pDiff = CPDF_Array::Create(); + CPDF_Array* pDiff = new CPDF_Array; for (int i = 0; i < 256; i++) { if (pStandard[i] == m_Unicodes[i]) { continue; } - pDiff->Add(CPDF_Number::Create(i)); - pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); + pDiff->Add(new CPDF_Number(i)); + pDiff->Add(new CPDF_Name(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); } + + CPDF_Dictionary* pDict = new CPDF_Dictionary; + pDict->SetAtName("BaseEncoding", "WinAnsiEncoding"); pDict->SetAt("Differences", pDiff); return pDict; } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index e90c53c956..865c6b7116 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -114,7 +114,7 @@ void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) { if (len > 32) { m_ParamBuf1[index].m_Type = 0; m_ParamBuf1[index].m_pObject = - CPDF_Name::Create(PDF_NameDecode(CFX_ByteStringC(name, len))); + new CPDF_Name(PDF_NameDecode(CFX_ByteStringC(name, len))); } else { m_ParamBuf1[index].m_Type = PDFOBJ_NAME; if (!FXSYS_memchr(name, '#', len)) { @@ -165,15 +165,15 @@ CPDF_Object* CPDF_StreamContentParser::GetObject(FX_DWORD index) { _ContentParam& param = m_ParamBuf1[real_index]; if (param.m_Type == PDFOBJ_NUMBER) { CPDF_Number* pNumber = param.m_Number.m_bInteger - ? CPDF_Number::Create(param.m_Number.m_Integer) - : CPDF_Number::Create(param.m_Number.m_Float); + ? new CPDF_Number(param.m_Number.m_Integer) + : new CPDF_Number(param.m_Number.m_Float); param.m_Type = 0; param.m_pObject = pNumber; return pNumber; } if (param.m_Type == PDFOBJ_NAME) { - CPDF_Name* pName = CPDF_Name::Create( + CPDF_Name* pName = new CPDF_Name( CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len)); param.m_Type = 0; param.m_pObject = pName; @@ -524,7 +524,7 @@ void _PDF_ReplaceAbbr(CPDF_Object* pObj) { _PDF_InlineValueAbbr, sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name); if (!fullname.IsEmpty()) { - pArray->SetAt(i, CPDF_Name::Create(fullname)); + pArray->SetAt(i, new CPDF_Name(fullname)); } } else { _PDF_ReplaceAbbr(pElement); @@ -587,7 +587,7 @@ void _PDF_ReplaceFull(CPDF_Object* pObj) { _PDF_InlineValueAbbr, sizeof _PDF_InlineValueAbbr / sizeof(_FX_BSTR), name); if (!abbrName.IsEmpty()) { - pArray->SetAt(i, CPDF_Name::Create(abbrName)); + pArray->SetAt(i, new CPDF_Name(abbrName)); } } else { _PDF_ReplaceFull(pElement); diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 2f68d78808..02ac27ac0f 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -75,7 +75,7 @@ FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData, void _PDF_ReplaceAbbr(CPDF_Object* pObj); void CPDF_StreamContentParser::Handle_BeginImage() { FX_FILESIZE savePos = m_pSyntax->GetPos(); - CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); + CPDF_Dictionary* pDict = new CPDF_Dictionary; while (1) { CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); if (type == CPDF_StreamParser::Keyword) { @@ -516,16 +516,16 @@ CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { if (m_WordSize == 4) { if (*(FX_DWORD*)m_WordBuffer == FXDWORD_TRUE) { - m_pLastObj = CPDF_Boolean::Create(TRUE); + m_pLastObj = new CPDF_Boolean(TRUE); return Others; } if (*(FX_DWORD*)m_WordBuffer == FXDWORD_NULL) { - m_pLastObj = CPDF_Null::Create(); + m_pLastObj = new CPDF_Null; return Others; } } else if (m_WordSize == 5) { if (*(FX_DWORD*)m_WordBuffer == FXDWORD_FALS && m_WordBuffer[4] == 'e') { - m_pLastObj = CPDF_Boolean::Create(FALSE); + m_pLastObj = new CPDF_Boolean(FALSE); return Others; } } @@ -603,42 +603,40 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(FX_BOOL bAllowNestedArray, } if (bIsNumber) { m_WordBuffer[m_WordSize] = 0; - return CPDF_Number::Create(CFX_ByteStringC(m_WordBuffer, m_WordSize)); + return new CPDF_Number(CFX_ByteStringC(m_WordBuffer, m_WordSize)); } int first_char = m_WordBuffer[0]; if (first_char == '/') { - return CPDF_Name::Create( + return new CPDF_Name( PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); } if (first_char == '(') { - return CPDF_String::Create(ReadString()); + return new CPDF_String(ReadString(), FALSE); } if (first_char == '<') { if (m_WordSize == 1) { - return CPDF_String::Create(ReadHexString(), TRUE); + return new CPDF_String(ReadHexString(), TRUE); } - CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); + CPDF_Dictionary* pDict = new CPDF_Dictionary; while (1) { GetNextWord(bIsNumber); if (m_WordSize == 0) { pDict->Release(); - return NULL; + return nullptr; } if (m_WordSize == 2 && m_WordBuffer[0] == '>') { break; } if (m_WordBuffer[0] != '/') { pDict->Release(); - return NULL; + return nullptr; } CFX_ByteString key = PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); CPDF_Object* pObj = ReadNextObject(TRUE); if (!pObj) { - if (pDict) { - pDict->Release(); - } - return NULL; + pDict->Release(); + return nullptr; } if (!key.IsEmpty()) { pDict->SetAt(key, pObj); @@ -652,31 +650,29 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(FX_BOOL bAllowNestedArray, if (!bAllowNestedArray && bInArray) { return NULL; } - CPDF_Array* pArray = CPDF_Array::Create(); + CPDF_Array* pArray = new CPDF_Array; while (1) { CPDF_Object* pObj = ReadNextObject(bAllowNestedArray, TRUE); - if (!pObj) { - if (m_WordSize == 0 || m_WordBuffer[0] == ']') { - return pArray; - } - if (m_WordBuffer[0] == '[') { - continue; - } - } else { + if (pObj) { pArray->Add(pObj); + continue; } + + if (m_WordSize == 0 || m_WordBuffer[0] == ']') + break; } + return pArray; } if (m_WordSize == 4) { if (*(FX_DWORD*)m_WordBuffer == FXDWORD_TRUE) { - return CPDF_Boolean::Create(TRUE); + return new CPDF_Boolean(TRUE); } if (*(FX_DWORD*)m_WordBuffer == FXDWORD_NULL) { - return CPDF_Null::Create(); + return new CPDF_Null; } } else if (m_WordSize == 5) { if (*(FX_DWORD*)m_WordBuffer == FXDWORD_FALS && m_WordBuffer[4] == 'e') { - return CPDF_Boolean::Create(FALSE); + return new CPDF_Boolean(FALSE); } } return NULL; diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index c503277f87..1322864757 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -544,7 +544,7 @@ void CPDF_Array::AddName(const CFX_ByteString& str) { } void CPDF_Array::AddString(const CFX_ByteString& str) { ASSERT(IsArray()); - Add(new CPDF_String(str)); + Add(new CPDF_String(str, FALSE)); } void CPDF_Array::AddInteger(int i) { ASSERT(IsArray()); @@ -781,7 +781,7 @@ void CPDF_Dictionary::SetAtName(const CFX_ByteStringC& key, } void CPDF_Dictionary::SetAtString(const CFX_ByteStringC& key, const CFX_ByteString& str) { - SetAt(key, new CPDF_String(str)); + SetAt(key, new CPDF_String(str, FALSE)); } void CPDF_Dictionary::SetAtReference(const CFX_ByteStringC& key, CPDF_IndirectObjects* pDoc, diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 97f17032b4..1b341f8692 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2033,17 +2033,17 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, m_Pos = SavedPos; if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NUMBER; - return CPDF_Number::Create(word); + return new CPDF_Number(word); } if (word == "true" || word == "false") { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_BOOLEAN; - return CPDF_Boolean::Create(word == "true"); + return new CPDF_Boolean(word == "true"); } if (word == "null") { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NULL; - return CPDF_Null::Create(); + return new CPDF_Null; } if (word == "(") { if (bTypeOnly) @@ -2052,7 +2052,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, if (m_pCryptoHandler && bDecrypt) { m_pCryptoHandler->Decrypt(objnum, gennum, str); } - return CPDF_String::Create(str, FALSE); + return new CPDF_String(str, FALSE); } if (word == "<") { if (bTypeOnly) @@ -2061,12 +2061,12 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, if (m_pCryptoHandler && bDecrypt) { m_pCryptoHandler->Decrypt(objnum, gennum, str); } - return CPDF_String::Create(str, TRUE); + return new CPDF_String(str, TRUE); } if (word == "[") { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_ARRAY; - CPDF_Array* pArray = CPDF_Array::Create(); + CPDF_Array* pArray = new CPDF_Array; while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum)) pArray->Add(pObj); @@ -2075,7 +2075,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, if (word[0] == '/') { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NAME; - return CPDF_Name::Create( + return new CPDF_Name( PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); } if (word == "<<") { @@ -2088,7 +2088,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, int32_t nKeys = 0; FX_FILESIZE dwSignValuePos = 0; nonstd::unique_ptr> pDict( - CPDF_Dictionary::Create()); + new CPDF_Dictionary); while (1) { FX_BOOL bIsNumber; CFX_ByteString key = GetNextWord(bIsNumber); @@ -2194,17 +2194,17 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( m_Pos = SavedPos; if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NUMBER; - return CPDF_Number::Create(word); + return new CPDF_Number(word); } if (word == "true" || word == "false") { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_BOOLEAN; - return CPDF_Boolean::Create(word == "true"); + return new CPDF_Boolean(word == "true"); } if (word == "null") { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NULL; - return CPDF_Null::Create(); + return new CPDF_Null; } if (word == "(") { if (bTypeOnly) @@ -2212,7 +2212,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( CFX_ByteString str = ReadString(); if (m_pCryptoHandler) m_pCryptoHandler->Decrypt(objnum, gennum, str); - return CPDF_String::Create(str, FALSE); + return new CPDF_String(str, FALSE); } if (word == "<") { if (bTypeOnly) @@ -2220,13 +2220,13 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( CFX_ByteString str = ReadHexString(); if (m_pCryptoHandler) m_pCryptoHandler->Decrypt(objnum, gennum, str); - return CPDF_String::Create(str, TRUE); + return new CPDF_String(str, TRUE); } if (word == "[") { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_ARRAY; nonstd::unique_ptr> pArray( - CPDF_Array::Create()); + new CPDF_Array); while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum)) pArray->Add(pObj); return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; @@ -2234,7 +2234,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( if (word[0] == '/') { if (bTypeOnly) return (CPDF_Object*)PDFOBJ_NAME; - return CPDF_Name::Create( + return new CPDF_Name( PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); } if (word == "<<") { @@ -2244,7 +2244,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( pContext->m_DictStart = SavedPos; nonstd::unique_ptr> pDict( - CPDF_Dictionary::Create()); + new CPDF_Dictionary); while (1) { FX_BOOL bIsNumber; FX_FILESIZE SavedPos = m_Pos; 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 20b59cd498..9f949cc965 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -1048,10 +1048,7 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( pMainDict->SetAt("F", static_cast(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++) { @@ -1069,16 +1066,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 987dbd6b20..46ea01083d 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); } @@ -906,10 +900,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; @@ -952,10 +943,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()) { diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp index a5fff4562b..9f707b901f 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -37,7 +37,7 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { pInfoDict = pDoc->GetInfo(); if (pInfoDict) { if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) - pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr)); + pInfoDict->SetAt("CreationDate", new CPDF_String(DateStr, FALSE)); pInfoDict->SetAt("Creator", new CPDF_String(L"PDFium")); } @@ -273,7 +273,7 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, CPDF_Array* pRectArray = NULL; pRectArray = pAnnot->GetAnnotDict()->GetArray("Rect"); if (!pRectArray) - pRectArray = CPDF_Array::Create(); + pRectArray = new CPDF_Array; pRectArray->SetAt(0, new CPDF_Number(rect.left)); pRectArray->SetAt(1, new CPDF_Number(rect.bottom)); pRectArray->SetAt(2, new CPDF_Number(rect.right)); diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp index 513ffc4ade..2fce7adfc4 100644 --- a/fpdfsdk/src/fpdfppo.cpp +++ b/fpdfsdk/src/fpdfppo.cpp @@ -43,17 +43,16 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc, if (!pNewRoot) return FALSE; - // Set the document information//////////////////////////////////////////// - + // Set the document information CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); if (!DInfoDict) return FALSE; CFX_ByteString producerstr; producerstr.Format("PDFium"); - DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); + DInfoDict->SetAt("Producer", new CPDF_String(producerstr, FALSE)); - // Set type//////////////////////////////////////////////////////////////// + // Set type CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); if (cbRootType.Equal("")) { pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); @@ -100,7 +99,7 @@ FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, if (!pSrcPageDict || !pCurPageDict) return FALSE; - // Clone the page dictionary/////////// + // Clone the page dictionary FX_POSITION SrcPos = pSrcPageDict->GetStartPos(); while (SrcPos) { CFX_ByteString cbSrcKeyStr; @@ -112,7 +111,7 @@ FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, } } - // inheritable item/////////////////////// + // inheritable item CPDF_Object* pInheritable = nullptr; // 1 MediaBox //required if (!pCurPageDict->KeyExist("MediaBox")) { @@ -156,7 +155,6 @@ FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc, pCurPageDict->SetAt("Rotate", pInheritable->Clone()); } - ///////////////////////////////////////////// // Update the reference FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); -- cgit v1.2.3