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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp

Issue 2277433003: Move parser out of IndirectObjectHolder (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@private_objs
Patch Set: Fix merge Created 4 years, 3 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h"
11 11
12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder() : m_LastObjNum(0) {}
13 : m_pParser(pParser), m_LastObjNum(0) {
14 if (pParser)
15 m_LastObjNum = m_pParser->GetLastObjNum();
16 }
17 13
18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { 14 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
19 for (const auto& pair : m_IndirectObjs) 15 for (const auto& pair : m_IndirectObjs)
20 pair.second->Destroy(); 16 pair.second->Destroy();
21 } 17 }
22 18
23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject( 19 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(
24 uint32_t objnum) const { 20 uint32_t objnum) const {
25 auto it = m_IndirectObjs.find(objnum); 21 auto it = m_IndirectObjs.find(objnum);
26 return it != m_IndirectObjs.end() ? it->second : nullptr; 22 return it != m_IndirectObjs.end() ? it->second : nullptr;
27 } 23 }
28 24
29 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject( 25 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject(
30 uint32_t objnum) { 26 uint32_t objnum) {
31 if (objnum == 0) 27 if (objnum == 0)
32 return nullptr; 28 return nullptr;
33 29
34 CPDF_Object* pObj = GetIndirectObject(objnum); 30 CPDF_Object* pObj = GetIndirectObject(objnum);
35 if (pObj) 31 if (pObj)
36 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr; 32 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr;
37 33
38 if (!m_pParser) 34 pObj = ParseIndirectObject(objnum);
39 return nullptr;
40
41 pObj = m_pParser->ParseIndirectObject(this, objnum);
42 if (!pObj) 35 if (!pObj)
43 return nullptr; 36 return nullptr;
44 37
45 pObj->m_ObjNum = objnum; 38 pObj->m_ObjNum = objnum;
46 m_LastObjNum = std::max(m_LastObjNum, objnum); 39 m_LastObjNum = std::max(m_LastObjNum, objnum);
47 if (m_IndirectObjs[objnum]) 40 if (m_IndirectObjs[objnum])
48 m_IndirectObjs[objnum]->Destroy(); 41 m_IndirectObjs[objnum]->Destroy();
49 42
50 m_IndirectObjs[objnum] = pObj; 43 m_IndirectObjs[objnum] = pObj;
51 return pObj; 44 return pObj;
52 } 45 }
53 46
47 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) {
48 return nullptr;
49 }
50
54 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { 51 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
55 if (pObj->m_ObjNum) 52 if (pObj->m_ObjNum)
56 return pObj->m_ObjNum; 53 return pObj->m_ObjNum;
57 54
58 m_LastObjNum++; 55 m_LastObjNum++;
59 m_IndirectObjs[m_LastObjNum] = pObj; 56 m_IndirectObjs[m_LastObjNum] = pObj;
60 pObj->m_ObjNum = m_LastObjNum; 57 pObj->m_ObjNum = m_LastObjNum;
61 return m_LastObjNum; 58 return m_LastObjNum;
62 } 59 }
63 60
(...skipping 18 matching lines...) Expand all
82 } 79 }
83 80
84 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { 81 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) {
85 CPDF_Object* pObj = GetIndirectObject(objnum); 82 CPDF_Object* pObj = GetIndirectObject(objnum);
86 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) 83 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
87 return; 84 return;
88 85
89 pObj->Destroy(); 86 pObj->Destroy();
90 m_IndirectObjs.erase(objnum); 87 m_IndirectObjs.erase(objnum);
91 } 88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698