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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1540693002: Get rid of a few CPDF_Object Create() methods and just use new instead. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 5 years 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
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfdoc/doc_ap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "parser_int.h" 7 #include "parser_int.h"
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 if (nextword2 == "R") { 2026 if (nextword2 == "R") {
2027 FX_DWORD objnum = FXSYS_atoi(word); 2027 FX_DWORD objnum = FXSYS_atoi(word);
2028 if (bTypeOnly) 2028 if (bTypeOnly)
2029 return (CPDF_Object*)PDFOBJ_REFERENCE; 2029 return (CPDF_Object*)PDFOBJ_REFERENCE;
2030 return new CPDF_Reference(pObjList, objnum); 2030 return new CPDF_Reference(pObjList, objnum);
2031 } 2031 }
2032 } 2032 }
2033 m_Pos = SavedPos; 2033 m_Pos = SavedPos;
2034 if (bTypeOnly) 2034 if (bTypeOnly)
2035 return (CPDF_Object*)PDFOBJ_NUMBER; 2035 return (CPDF_Object*)PDFOBJ_NUMBER;
2036 return CPDF_Number::Create(word); 2036 return new CPDF_Number(word);
2037 } 2037 }
2038 if (word == "true" || word == "false") { 2038 if (word == "true" || word == "false") {
2039 if (bTypeOnly) 2039 if (bTypeOnly)
2040 return (CPDF_Object*)PDFOBJ_BOOLEAN; 2040 return (CPDF_Object*)PDFOBJ_BOOLEAN;
2041 return CPDF_Boolean::Create(word == "true"); 2041 return new CPDF_Boolean(word == "true");
2042 } 2042 }
2043 if (word == "null") { 2043 if (word == "null") {
2044 if (bTypeOnly) 2044 if (bTypeOnly)
2045 return (CPDF_Object*)PDFOBJ_NULL; 2045 return (CPDF_Object*)PDFOBJ_NULL;
2046 return CPDF_Null::Create(); 2046 return new CPDF_Null;
2047 } 2047 }
2048 if (word == "(") { 2048 if (word == "(") {
2049 if (bTypeOnly) 2049 if (bTypeOnly)
2050 return (CPDF_Object*)PDFOBJ_STRING; 2050 return (CPDF_Object*)PDFOBJ_STRING;
2051 CFX_ByteString str = ReadString(); 2051 CFX_ByteString str = ReadString();
2052 if (m_pCryptoHandler && bDecrypt) { 2052 if (m_pCryptoHandler && bDecrypt) {
2053 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2053 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2054 } 2054 }
2055 return CPDF_String::Create(str, FALSE); 2055 return new CPDF_String(str, FALSE);
2056 } 2056 }
2057 if (word == "<") { 2057 if (word == "<") {
2058 if (bTypeOnly) 2058 if (bTypeOnly)
2059 return (CPDF_Object*)PDFOBJ_STRING; 2059 return (CPDF_Object*)PDFOBJ_STRING;
2060 CFX_ByteString str = ReadHexString(); 2060 CFX_ByteString str = ReadHexString();
2061 if (m_pCryptoHandler && bDecrypt) { 2061 if (m_pCryptoHandler && bDecrypt) {
2062 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2062 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2063 } 2063 }
2064 return CPDF_String::Create(str, TRUE); 2064 return new CPDF_String(str, TRUE);
2065 } 2065 }
2066 if (word == "[") { 2066 if (word == "[") {
2067 if (bTypeOnly) 2067 if (bTypeOnly)
2068 return (CPDF_Object*)PDFOBJ_ARRAY; 2068 return (CPDF_Object*)PDFOBJ_ARRAY;
2069 CPDF_Array* pArray = CPDF_Array::Create(); 2069 CPDF_Array* pArray = new CPDF_Array;
2070 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum)) 2070 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum))
2071 pArray->Add(pObj); 2071 pArray->Add(pObj);
2072 2072
2073 return pArray; 2073 return pArray;
2074 } 2074 }
2075 if (word[0] == '/') { 2075 if (word[0] == '/') {
2076 if (bTypeOnly) 2076 if (bTypeOnly)
2077 return (CPDF_Object*)PDFOBJ_NAME; 2077 return (CPDF_Object*)PDFOBJ_NAME;
2078 return CPDF_Name::Create( 2078 return new CPDF_Name(
2079 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 2079 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
2080 } 2080 }
2081 if (word == "<<") { 2081 if (word == "<<") {
2082 if (bTypeOnly) 2082 if (bTypeOnly)
2083 return (CPDF_Object*)PDFOBJ_DICTIONARY; 2083 return (CPDF_Object*)PDFOBJ_DICTIONARY;
2084 2084
2085 if (pContext) 2085 if (pContext)
2086 pContext->m_DictStart = SavedPos; 2086 pContext->m_DictStart = SavedPos;
2087 2087
2088 int32_t nKeys = 0; 2088 int32_t nKeys = 0;
2089 FX_FILESIZE dwSignValuePos = 0; 2089 FX_FILESIZE dwSignValuePos = 0;
2090 nonstd::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 2090 nonstd::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
2091 CPDF_Dictionary::Create()); 2091 new CPDF_Dictionary);
2092 while (1) { 2092 while (1) {
2093 FX_BOOL bIsNumber; 2093 FX_BOOL bIsNumber;
2094 CFX_ByteString key = GetNextWord(bIsNumber); 2094 CFX_ByteString key = GetNextWord(bIsNumber);
2095 if (key.IsEmpty()) 2095 if (key.IsEmpty())
2096 return nullptr; 2096 return nullptr;
2097 2097
2098 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); 2098 FX_FILESIZE SavedPos = m_Pos - key.GetLength();
2099 if (key == ">>") 2099 if (key == ">>")
2100 break; 2100 break;
2101 2101
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 if (nextword2 == "R") { 2187 if (nextword2 == "R") {
2188 if (bTypeOnly) 2188 if (bTypeOnly)
2189 return (CPDF_Object*)PDFOBJ_REFERENCE; 2189 return (CPDF_Object*)PDFOBJ_REFERENCE;
2190 FX_DWORD objnum = FXSYS_atoi(word); 2190 FX_DWORD objnum = FXSYS_atoi(word);
2191 return new CPDF_Reference(pObjList, objnum); 2191 return new CPDF_Reference(pObjList, objnum);
2192 } 2192 }
2193 } 2193 }
2194 m_Pos = SavedPos; 2194 m_Pos = SavedPos;
2195 if (bTypeOnly) 2195 if (bTypeOnly)
2196 return (CPDF_Object*)PDFOBJ_NUMBER; 2196 return (CPDF_Object*)PDFOBJ_NUMBER;
2197 return CPDF_Number::Create(word); 2197 return new CPDF_Number(word);
2198 } 2198 }
2199 if (word == "true" || word == "false") { 2199 if (word == "true" || word == "false") {
2200 if (bTypeOnly) 2200 if (bTypeOnly)
2201 return (CPDF_Object*)PDFOBJ_BOOLEAN; 2201 return (CPDF_Object*)PDFOBJ_BOOLEAN;
2202 return CPDF_Boolean::Create(word == "true"); 2202 return new CPDF_Boolean(word == "true");
2203 } 2203 }
2204 if (word == "null") { 2204 if (word == "null") {
2205 if (bTypeOnly) 2205 if (bTypeOnly)
2206 return (CPDF_Object*)PDFOBJ_NULL; 2206 return (CPDF_Object*)PDFOBJ_NULL;
2207 return CPDF_Null::Create(); 2207 return new CPDF_Null;
2208 } 2208 }
2209 if (word == "(") { 2209 if (word == "(") {
2210 if (bTypeOnly) 2210 if (bTypeOnly)
2211 return (CPDF_Object*)PDFOBJ_STRING; 2211 return (CPDF_Object*)PDFOBJ_STRING;
2212 CFX_ByteString str = ReadString(); 2212 CFX_ByteString str = ReadString();
2213 if (m_pCryptoHandler) 2213 if (m_pCryptoHandler)
2214 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2214 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2215 return CPDF_String::Create(str, FALSE); 2215 return new CPDF_String(str, FALSE);
2216 } 2216 }
2217 if (word == "<") { 2217 if (word == "<") {
2218 if (bTypeOnly) 2218 if (bTypeOnly)
2219 return (CPDF_Object*)PDFOBJ_STRING; 2219 return (CPDF_Object*)PDFOBJ_STRING;
2220 CFX_ByteString str = ReadHexString(); 2220 CFX_ByteString str = ReadHexString();
2221 if (m_pCryptoHandler) 2221 if (m_pCryptoHandler)
2222 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2222 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2223 return CPDF_String::Create(str, TRUE); 2223 return new CPDF_String(str, TRUE);
2224 } 2224 }
2225 if (word == "[") { 2225 if (word == "[") {
2226 if (bTypeOnly) 2226 if (bTypeOnly)
2227 return (CPDF_Object*)PDFOBJ_ARRAY; 2227 return (CPDF_Object*)PDFOBJ_ARRAY;
2228 nonstd::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( 2228 nonstd::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray(
2229 CPDF_Array::Create()); 2229 new CPDF_Array);
2230 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum)) 2230 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum))
2231 pArray->Add(pObj); 2231 pArray->Add(pObj);
2232 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; 2232 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr;
2233 } 2233 }
2234 if (word[0] == '/') { 2234 if (word[0] == '/') {
2235 if (bTypeOnly) 2235 if (bTypeOnly)
2236 return (CPDF_Object*)PDFOBJ_NAME; 2236 return (CPDF_Object*)PDFOBJ_NAME;
2237 return CPDF_Name::Create( 2237 return new CPDF_Name(
2238 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 2238 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
2239 } 2239 }
2240 if (word == "<<") { 2240 if (word == "<<") {
2241 if (bTypeOnly) 2241 if (bTypeOnly)
2242 return (CPDF_Object*)PDFOBJ_DICTIONARY; 2242 return (CPDF_Object*)PDFOBJ_DICTIONARY;
2243 if (pContext) 2243 if (pContext)
2244 pContext->m_DictStart = SavedPos; 2244 pContext->m_DictStart = SavedPos;
2245 2245
2246 nonstd::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 2246 nonstd::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
2247 CPDF_Dictionary::Create()); 2247 new CPDF_Dictionary);
2248 while (1) { 2248 while (1) {
2249 FX_BOOL bIsNumber; 2249 FX_BOOL bIsNumber;
2250 FX_FILESIZE SavedPos = m_Pos; 2250 FX_FILESIZE SavedPos = m_Pos;
2251 CFX_ByteString key = GetNextWord(bIsNumber); 2251 CFX_ByteString key = GetNextWord(bIsNumber);
2252 if (key.IsEmpty()) 2252 if (key.IsEmpty())
2253 return nullptr; 2253 return nullptr;
2254 2254
2255 if (key == ">>") 2255 if (key == ">>")
2256 break; 2256 break;
2257 2257
(...skipping 2726 matching lines...) Expand 10 before | Expand all | Expand 10 after
4984 if (!m_pLinearizedDict) 4984 if (!m_pLinearizedDict)
4985 return -1; 4985 return -1;
4986 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); 4986 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H");
4987 if (!pRange) 4987 if (!pRange)
4988 return -1; 4988 return -1;
4989 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4989 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4990 if (!pStreamLen) 4990 if (!pStreamLen)
4991 return -1; 4991 return -1;
4992 return pStreamLen->GetInteger(); 4992 return pStreamLen->GetInteger();
4993 } 4993 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfdoc/doc_ap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698