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

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

Issue 1420583003: Revert "Revert "Add type cast definitions for CPDF_Dictionary."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months 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
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 "../../../include/fpdfapi/fpdf_parser.h" 7 #include "../../../include/fpdfapi/fpdf_parser.h"
8 #include "../../../include/fxcrt/fx_string.h" 8 #include "../../../include/fxcrt/fx_string.h"
9 9
10 // static 10 // static
(...skipping 10 matching lines...) Expand all
21 case PDFOBJ_STRING: 21 case PDFOBJ_STRING:
22 delete (CPDF_String*)this; 22 delete (CPDF_String*)this;
23 break; 23 break;
24 case PDFOBJ_NAME: 24 case PDFOBJ_NAME:
25 delete (CPDF_Name*)this; 25 delete (CPDF_Name*)this;
26 break; 26 break;
27 case PDFOBJ_ARRAY: 27 case PDFOBJ_ARRAY:
28 delete (CPDF_Array*)this; 28 delete (CPDF_Array*)this;
29 break; 29 break;
30 case PDFOBJ_DICTIONARY: 30 case PDFOBJ_DICTIONARY:
31 delete (CPDF_Dictionary*)this; 31 delete this->AsDictionary();
32 break; 32 break;
33 case PDFOBJ_STREAM: 33 case PDFOBJ_STREAM:
34 delete (CPDF_Stream*)this; 34 delete (CPDF_Stream*)this;
35 break; 35 break;
36 default: 36 default:
37 delete this; 37 delete this;
38 } 38 }
39 } 39 }
40 CFX_ByteString CPDF_Object::GetString() const { 40 CFX_ByteString CPDF_Object::GetString() const {
41 switch (m_Type) { 41 switch (m_Type) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 return pObj->GetInteger(); 132 return pObj->GetInteger();
133 } 133 }
134 } 134 }
135 return 0; 135 return 0;
136 } 136 }
137 137
138 CPDF_Dictionary* CPDF_Object::GetDict() const { 138 CPDF_Dictionary* CPDF_Object::GetDict() const {
139 switch (m_Type) { 139 switch (m_Type) {
140 case PDFOBJ_DICTIONARY: 140 case PDFOBJ_DICTIONARY:
141 return (CPDF_Dictionary*)this; 141 // The method should be made non-const if we want to not be const.
142 // See bug #234.
143 return const_cast<CPDF_Dictionary*>(this->AsDictionary());
142 case PDFOBJ_STREAM: 144 case PDFOBJ_STREAM:
143 return ((CPDF_Stream*)this)->GetDict(); 145 return ((CPDF_Stream*)this)->GetDict();
144 case PDFOBJ_REFERENCE: { 146 case PDFOBJ_REFERENCE: {
145 CPDF_Reference* pRef = (CPDF_Reference*)this; 147 CPDF_Reference* pRef = (CPDF_Reference*)this;
146 CPDF_IndirectObjects* pIndirect = pRef->GetObjList(); 148 CPDF_IndirectObjects* pIndirect = pRef->GetObjList();
147 if (!pIndirect) 149 if (!pIndirect)
148 return nullptr; 150 return nullptr;
149 CPDF_Object* pObj = pIndirect->GetIndirectObject(pRef->GetRefObjNum()); 151 CPDF_Object* pObj = pIndirect->GetIndirectObject(pRef->GetRefObjNum());
150 if (!pObj || (pObj == this)) 152 if (!pObj || (pObj == this))
151 return nullptr; 153 return nullptr;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); 210 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther));
209 case PDFOBJ_NUMBER: 211 case PDFOBJ_NUMBER:
210 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther)); 212 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther));
211 case PDFOBJ_STRING: 213 case PDFOBJ_STRING:
212 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther)); 214 return (((CPDF_String*)this)->Identical((CPDF_String*)pOther));
213 case PDFOBJ_NAME: 215 case PDFOBJ_NAME:
214 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther)); 216 return (((CPDF_Name*)this)->Identical((CPDF_Name*)pOther));
215 case PDFOBJ_ARRAY: 217 case PDFOBJ_ARRAY:
216 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther)); 218 return (((CPDF_Array*)this)->Identical((CPDF_Array*)pOther));
217 case PDFOBJ_DICTIONARY: 219 case PDFOBJ_DICTIONARY:
218 return (((CPDF_Dictionary*)this)->Identical((CPDF_Dictionary*)pOther)); 220 return this->AsDictionary()->Identical(pOther->AsDictionary());
219 case PDFOBJ_NULL: 221 case PDFOBJ_NULL:
220 return TRUE; 222 return TRUE;
221 case PDFOBJ_STREAM: 223 case PDFOBJ_STREAM:
222 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther)); 224 return (((CPDF_Stream*)this)->Identical((CPDF_Stream*)pOther));
223 case PDFOBJ_REFERENCE: 225 case PDFOBJ_REFERENCE:
224 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther)); 226 return (((CPDF_Reference*)this)->Identical((CPDF_Reference*)pOther));
225 } 227 }
226 return FALSE; 228 return FALSE;
227 } 229 }
228 CPDF_Object* CPDF_Object::GetDirect() const { 230 CPDF_Object* CPDF_Object::GetDirect() const {
(...skipping 28 matching lines...) Expand all
257 CPDF_Array* pThis = (CPDF_Array*)this; 259 CPDF_Array* pThis = (CPDF_Array*)this;
258 int n = pThis->GetCount(); 260 int n = pThis->GetCount();
259 for (int i = 0; i < n; i++) { 261 for (int i = 0; i < n; i++) {
260 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i); 262 CPDF_Object* value = (CPDF_Object*)pThis->m_Objects.GetAt(i);
261 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited)); 263 pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited));
262 } 264 }
263 return pCopy; 265 return pCopy;
264 } 266 }
265 case PDFOBJ_DICTIONARY: { 267 case PDFOBJ_DICTIONARY: {
266 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); 268 CPDF_Dictionary* pCopy = new CPDF_Dictionary();
267 CPDF_Dictionary* pThis = (CPDF_Dictionary*)this; 269 const CPDF_Dictionary* pThis = this->AsDictionary();
268 FX_POSITION pos = pThis->m_Map.GetStartPosition(); 270 FX_POSITION pos = pThis->m_Map.GetStartPosition();
269 while (pos) { 271 while (pos) {
270 CFX_ByteString key; 272 CFX_ByteString key;
271 CPDF_Object* value; 273 CPDF_Object* value;
272 pThis->m_Map.GetNextAssoc(pos, key, (void*&)value); 274 pThis->m_Map.GetNextAssoc(pos, key, (void*&)value);
273 pCopy->m_Map.SetAt(key, value->CloneInternal(bDirect, visited)); 275 pCopy->m_Map.SetAt(key, value->CloneInternal(bDirect, visited));
274 } 276 }
275 return pCopy; 277 return pCopy;
276 } 278 }
277 case PDFOBJ_NULL: { 279 case PDFOBJ_NULL: {
278 return new CPDF_Null; 280 return new CPDF_Null;
279 } 281 }
280 case PDFOBJ_STREAM: { 282 case PDFOBJ_STREAM: {
281 CPDF_Stream* pThis = (CPDF_Stream*)this; 283 CPDF_Stream* pThis = (CPDF_Stream*)this;
282 CPDF_StreamAcc acc; 284 CPDF_StreamAcc acc;
283 acc.LoadAllData(pThis, TRUE); 285 acc.LoadAllData(pThis, TRUE);
284 FX_DWORD streamSize = acc.GetSize(); 286 FX_DWORD streamSize = acc.GetSize();
285 CPDF_Dictionary* pDict = pThis->GetDict(); 287 CPDF_Dictionary* pDict = pThis->GetDict();
286 if (pDict) 288 if (pDict) {
287 pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict) 289 pDict = ToDictionary(pDict->CloneInternal(bDirect, visited));
288 ->CloneInternal(bDirect, visited); 290 }
289 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); 291 return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
290 } 292 }
291 case PDFOBJ_REFERENCE: { 293 case PDFOBJ_REFERENCE: {
292 CPDF_Reference* pRef = (CPDF_Reference*)this; 294 CPDF_Reference* pRef = (CPDF_Reference*)this;
293 FX_DWORD obj_num = pRef->GetRefObjNum(); 295 FX_DWORD obj_num = pRef->GetRefObjNum();
294 if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) { 296 if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) {
295 visited->SetAt((void*)(uintptr_t)obj_num, (void*)1); 297 visited->SetAt((void*)(uintptr_t)obj_num, (void*)1);
296 if (!pRef->GetDirect()) 298 if (!pRef->GetDirect())
297 return nullptr; 299 return nullptr;
298 300
(...skipping 29 matching lines...) Expand all
328 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) { 330 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) {
329 if (m_Type == PDFOBJ_STRING) { 331 if (m_Type == PDFOBJ_STRING) {
330 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); 332 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len);
331 } else if (m_Type == PDFOBJ_STREAM) { 333 } else if (m_Type == PDFOBJ_STREAM) {
332 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); 334 CFX_ByteString result = PDF_EncodeText(pUnicodes, len);
333 ((CPDF_Stream*)this) 335 ((CPDF_Stream*)this)
334 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE); 336 ->SetData((uint8_t*)result.c_str(), result.GetLength(), FALSE, FALSE);
335 } 337 }
336 } 338 }
337 339
340 CPDF_Dictionary* CPDF_Object::AsDictionary() {
341 return IsDictionary() ? static_cast<CPDF_Dictionary*>(this) : nullptr;
342 }
343
344 const CPDF_Dictionary* CPDF_Object::AsDictionary() const {
345 return IsDictionary() ? static_cast<const CPDF_Dictionary*>(this) : nullptr;
346 }
347
338 CPDF_Number::CPDF_Number(int value) 348 CPDF_Number::CPDF_Number(int value)
339 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {} 349 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(TRUE), m_Integer(value) {}
340 350
341 CPDF_Number::CPDF_Number(FX_FLOAT value) 351 CPDF_Number::CPDF_Number(FX_FLOAT value)
342 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) {} 352 : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(FALSE), m_Float(value) {}
343 353
344 CPDF_Number::CPDF_Number(FX_BOOL bInteger, void* pData) 354 CPDF_Number::CPDF_Number(FX_BOOL bInteger, void* pData)
345 : CPDF_Object(PDFOBJ_NUMBER), 355 : CPDF_Object(PDFOBJ_NUMBER),
346 m_bInteger(bInteger), 356 m_bInteger(bInteger),
347 m_Integer(*(int*)pData) {} 357 m_Integer(*(int*)pData) {}
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 return 0; 445 return 0;
436 } 446 }
437 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); 447 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
438 return p->GetNumber(); 448 return p->GetNumber();
439 } 449 }
440 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const { 450 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const {
441 CPDF_Object* p = GetElementValue(i); 451 CPDF_Object* p = GetElementValue(i);
442 if (!p) { 452 if (!p) {
443 return NULL; 453 return NULL;
444 } 454 }
445 if (p->GetType() == PDFOBJ_DICTIONARY) { 455 if (CPDF_Dictionary* pDict = p->AsDictionary()) {
446 return (CPDF_Dictionary*)p; 456 return pDict;
447 } 457 }
448 if (p->GetType() == PDFOBJ_STREAM) { 458 if (p->GetType() == PDFOBJ_STREAM) {
449 return ((CPDF_Stream*)p)->GetDict(); 459 return ((CPDF_Stream*)p)->GetDict();
450 } 460 }
451 return NULL; 461 return NULL;
452 } 462 }
453 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const { 463 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const {
454 CPDF_Object* p = GetElementValue(i); 464 CPDF_Object* p = GetElementValue(i);
455 if (p == NULL || p->GetType() != PDFOBJ_STREAM) { 465 if (p == NULL || p->GetType() != PDFOBJ_STREAM) {
456 return NULL; 466 return NULL;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 if (p && p->GetType() == PDFOBJ_BOOLEAN) { 666 if (p && p->GetType() == PDFOBJ_BOOLEAN) {
657 return p->GetInteger(); 667 return p->GetInteger();
658 } 668 }
659 return bDefault; 669 return bDefault;
660 } 670 }
661 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const { 671 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const {
662 CPDF_Object* p = GetElementValue(key); 672 CPDF_Object* p = GetElementValue(key);
663 if (!p) { 673 if (!p) {
664 return nullptr; 674 return nullptr;
665 } 675 }
666 if (p->GetType() == PDFOBJ_DICTIONARY) { 676 if (CPDF_Dictionary* pDict = p->AsDictionary()) {
667 return (CPDF_Dictionary*)p; 677 return pDict;
668 } 678 }
669 if (p->GetType() == PDFOBJ_STREAM) { 679 if (p->GetType() == PDFOBJ_STREAM) {
670 return ((CPDF_Stream*)p)->GetDict(); 680 return ((CPDF_Stream*)p)->GetDict();
671 } 681 }
672 return nullptr; 682 return nullptr;
673 } 683 }
674 CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const { 684 CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const {
675 CPDF_Object* p = GetElementValue(key); 685 CPDF_Object* p = GetElementValue(key);
676 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { 686 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) {
677 return NULL; 687 return NULL;
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 } 1208 }
1199 pObj->m_ObjNum = objnum; 1209 pObj->m_ObjNum = objnum;
1200 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); 1210 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj);
1201 if (m_LastObjNum < objnum) { 1211 if (m_LastObjNum < objnum) {
1202 m_LastObjNum = objnum; 1212 m_LastObjNum = objnum;
1203 } 1213 }
1204 } 1214 }
1205 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const { 1215 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const {
1206 return m_LastObjNum; 1216 return m_LastObjNum;
1207 } 1217 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698