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

Side by Side Diff: core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp

Issue 2361713002: Remove some objnum locals with AddIndirectObject (Closed)
Patch Set: Same treatment for arrays 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
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_image.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 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_edit/include/cpdf_pagecontentgenerator.h" 7 #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h"
8 8
9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" 9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; 43 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict;
44 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { 44 for (int i = 0; i < m_pageObjects.GetSize(); ++i) {
45 CPDF_PageObject* pPageObj = m_pageObjects[i]; 45 CPDF_PageObject* pPageObj = m_pageObjects[i];
46 if (!pPageObj || !pPageObj->IsImage()) { 46 if (!pPageObj || !pPageObj->IsImage()) {
47 continue; 47 continue;
48 } 48 }
49 ProcessImage(buf, pPageObj->AsImage()); 49 ProcessImage(buf, pPageObj->AsImage());
50 } 50 }
51 CPDF_Object* pContent = 51 CPDF_Object* pContent =
52 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; 52 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr;
53 if (pContent) { 53 if (pContent)
54 pPageDict->RemoveFor("Contents"); 54 pPageDict->RemoveFor("Contents");
55 } 55
56 CPDF_Stream* pStream = new CPDF_Stream; 56 CPDF_Stream* pStream = new CPDF_Stream;
57 pStream->SetData(buf.GetBuffer(), buf.GetLength()); 57 pStream->SetData(buf.GetBuffer(), buf.GetLength());
58 m_pDocument->AddIndirectObject(pStream); 58 pPageDict->SetReferenceFor("Contents", m_pDocument,
59 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum()); 59 m_pDocument->AddIndirectObject(pStream));
60 } 60 }
61 61
62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( 62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
63 CPDF_Object* pResourceObj, 63 CPDF_Object* pResourceObj,
64 const CFX_ByteString& bsType) { 64 const CFX_ByteString& bsType) {
65 if (!m_pPage->m_pResources) { 65 if (!m_pPage->m_pResources) {
66 m_pPage->m_pResources = new CPDF_Dictionary; 66 m_pPage->m_pResources = new CPDF_Dictionary;
67 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); 67 m_pPage->m_pFormDict->SetReferenceFor(
68 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, objnum); 68 "Resources", m_pDocument,
69 m_pDocument->AddIndirectObject(m_pPage->m_pResources));
69 } 70 }
70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); 71 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType);
71 if (!pResList) { 72 if (!pResList) {
72 pResList = new CPDF_Dictionary; 73 pResList = new CPDF_Dictionary;
73 m_pPage->m_pResources->SetFor(bsType, pResList); 74 m_pPage->m_pResources->SetFor(bsType, pResList);
74 } 75 }
75 m_pDocument->AddIndirectObject(pResourceObj);
76 CFX_ByteString name; 76 CFX_ByteString name;
77 int idnum = 1; 77 int idnum = 1;
78 while (1) { 78 while (1) {
79 name.Format("FX%c%d", bsType[0], idnum); 79 name.Format("FX%c%d", bsType[0], idnum);
80 if (!pResList->KeyExist(name)) { 80 if (!pResList->KeyExist(name)) {
81 break; 81 break;
82 } 82 }
83 idnum++; 83 idnum++;
84 } 84 }
85 pResList->SetReferenceFor(name, m_pDocument, pResourceObj->GetObjNum()); 85 pResList->SetReferenceFor(name, m_pDocument,
86 m_pDocument->AddIndirectObject(pResourceObj));
86 return name; 87 return name;
87 } 88 }
88 89
89 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, 90 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf,
90 CPDF_ImageObject* pImageObj) { 91 CPDF_ImageObject* pImageObj) {
91 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || 92 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) ||
92 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { 93 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) {
93 return; 94 return;
94 } 95 }
95 buf << "q " << pImageObj->m_Matrix << " cm "; 96 buf << "q " << pImageObj->m_Matrix << " cm ";
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ProcessForm(buf, pBuf, size, matrix); 164 ProcessForm(buf, pBuf, size, matrix);
164 FX_Free(pBuf); 165 FX_Free(pBuf);
165 FX_Free(pContentArray); 166 FX_Free(pContentArray);
166 } else if (CPDF_Stream* pStream = pContent->AsStream()) { 167 } else if (CPDF_Stream* pStream = pContent->AsStream()) {
167 CPDF_StreamAcc contentStream; 168 CPDF_StreamAcc contentStream;
168 contentStream.LoadAllData(pStream); 169 contentStream.LoadAllData(pStream);
169 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 170 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
170 } 171 }
171 CPDF_Stream* pStream = new CPDF_Stream; 172 CPDF_Stream* pStream = new CPDF_Stream;
172 pStream->SetData(buf.GetBuffer(), buf.GetLength()); 173 pStream->SetData(buf.GetBuffer(), buf.GetLength());
173 m_pDocument->AddIndirectObject(pStream); 174 m_pPage->m_pFormDict->SetReferenceFor(
174 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, 175 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream));
175 pStream->GetObjNum());
176 } 176 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698