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

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

Issue 2424533003: Revert "Update CPDF_IndirectObjectHolder APIs for unique objects." (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | core/fpdfapi/edit/fpdf_edit_create.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/edit/cpdf_pagecontentgenerator.h" 7 #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h"
8 8
9 #include "core/fpdfapi/edit/cpdf_creator.h" 9 #include "core/fpdfapi/edit/cpdf_creator.h"
10 #include "core/fpdfapi/page/cpdf_docpagedata.h" 10 #include "core/fpdfapi/page/cpdf_docpagedata.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 CPDF_ImageObject* pImageObject = pPageObj->AsImage(); 45 CPDF_ImageObject* pImageObject = pPageObj->AsImage();
46 if (pImageObject) 46 if (pImageObject)
47 ProcessImage(buf, pImageObject); 47 ProcessImage(buf, pImageObject);
48 } 48 }
49 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; 49 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict;
50 CPDF_Object* pContent = 50 CPDF_Object* pContent =
51 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; 51 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr;
52 if (pContent) 52 if (pContent)
53 pPageDict->RemoveFor("Contents"); 53 pPageDict->RemoveFor("Contents");
54 54
55 CPDF_Stream* pStream = m_pDocument->AddIndirectStream(); 55 CPDF_Stream* pStream = new CPDF_Stream;
56 pStream->SetData(buf.GetBuffer(), buf.GetLength()); 56 pStream->SetData(buf.GetBuffer(), buf.GetLength());
57 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream); 57 pPageDict->SetReferenceFor("Contents", m_pDocument,
58 m_pDocument->AddIndirectObject(pStream));
58 } 59 }
59 60
60 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( 61 CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
61 CPDF_Object* pResourceObj, 62 CPDF_Object* pResourceObj,
62 const CFX_ByteString& bsType) { 63 const CFX_ByteString& bsType) {
63 if (!m_pPage->m_pResources) { 64 if (!m_pPage->m_pResources) {
64 m_pPage->m_pResources = 65 m_pPage->m_pResources =
65 m_pDocument->AddIndirectDictionary(m_pDocument->GetByteStringPool()); 66 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
66 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, 67 m_pPage->m_pFormDict->SetReferenceFor(
67 m_pPage->m_pResources); 68 "Resources", m_pDocument,
69 m_pDocument->AddIndirectObject(m_pPage->m_pResources));
68 } 70 }
69 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); 71 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType);
70 if (!pResList) { 72 if (!pResList) {
71 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 73 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool());
72 m_pPage->m_pResources->SetFor(bsType, pResList); 74 m_pPage->m_pResources->SetFor(bsType, pResList);
73 } 75 }
74 CFX_ByteString name; 76 CFX_ByteString name;
75 int idnum = 1; 77 int idnum = 1;
76 while (1) { 78 while (1) {
77 name.Format("FX%c%d", bsType[0], idnum); 79 name.Format("FX%c%d", bsType[0], idnum);
78 if (!pResList->KeyExist(name)) { 80 if (!pResList->KeyExist(name)) {
79 break; 81 break;
80 } 82 }
81 idnum++; 83 idnum++;
82 } 84 }
83 // TODO(tsepez): check |pResourceObj| ownership. 85 pResList->SetReferenceFor(name, m_pDocument,
84 pResList->SetReferenceFor(name, m_pDocument, m_pDocument->AddIndirectObject( 86 m_pDocument->AddIndirectObject(pResourceObj));
85 UniqueObject(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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 delete pContentArray[i]; 163 delete pContentArray[i];
163 } 164 }
164 ProcessForm(buf, pBuf, size, matrix); 165 ProcessForm(buf, pBuf, size, matrix);
165 FX_Free(pBuf); 166 FX_Free(pBuf);
166 FX_Free(pContentArray); 167 FX_Free(pContentArray);
167 } else if (CPDF_Stream* pStream = pContent->AsStream()) { 168 } else if (CPDF_Stream* pStream = pContent->AsStream()) {
168 CPDF_StreamAcc contentStream; 169 CPDF_StreamAcc contentStream;
169 contentStream.LoadAllData(pStream); 170 contentStream.LoadAllData(pStream);
170 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 171 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
171 } 172 }
172 CPDF_Stream* pStream = m_pDocument->AddIndirectStream(); 173 CPDF_Stream* pStream = new CPDF_Stream;
173 pStream->SetData(buf.GetBuffer(), buf.GetLength()); 174 pStream->SetData(buf.GetBuffer(), buf.GetLength());
174 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream); 175 m_pPage->m_pFormDict->SetReferenceFor(
176 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream));
175 } 177 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/edit/fpdf_edit_create.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698