summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-12-18 16:26:45 -0800
committerLei Zhang <thestig@chromium.org>2015-12-18 16:26:45 -0800
commitd866ab0b44a571c884fdd8ba5a5319adaf607559 (patch)
treece18ed89550cf563dbdf2e421f8ff08bc6526f27 /core/src/fpdfapi
parent20c8a9a66ea710b96493c9048fb65753e68b48fc (diff)
downloadpdfium-d866ab0b44a571c884fdd8ba5a5319adaf607559.tar.xz
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 .
Diffstat (limited to 'core/src/fpdfapi')
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp2
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp6
-rw-r--r--core/src/fpdfapi/fpdf_edit/fpdf_edit_image.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp19
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp12
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp50
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp32
8 files changed, 63 insertions, 66 deletions
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<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> 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<CPDF_Array, ReleaseDeleter<CPDF_Array>> 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<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
- CPDF_Dictionary::Create());
+ new CPDF_Dictionary);
while (1) {
FX_BOOL bIsNumber;
FX_FILESIZE SavedPos = m_Pos;