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

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

Issue 2347993002: Clean up CPDF_Stream. (Closed)
Patch Set: ctor 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_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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(nullptr, 0, nullptr); 56 CPDF_Stream* pStream = new CPDF_Stream;
57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 57 pStream->SetData(buf.GetBuffer(), buf.GetLength());
58 m_pDocument->AddIndirectObject(pStream); 58 m_pDocument->AddIndirectObject(pStream);
59 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum()); 59 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum());
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 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 pImageObj->SetUnownedImage(m_pDocument->GetPageData()->GetImage(pStream)); 102 pImageObj->SetUnownedImage(m_pDocument->GetPageData()->GetImage(pStream));
103 } 103 }
104 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 104 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
105 } 105 }
106 } 106 }
107 107
108 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, 108 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf,
109 const uint8_t* data, 109 const uint8_t* data,
110 uint32_t size, 110 uint32_t size,
111 CFX_Matrix& matrix) { 111 CFX_Matrix& matrix) {
112 if (!data || !size) { 112 if (!data || !size)
113 return; 113 return;
114 } 114
115 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr);
116 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; 115 CPDF_Dictionary* pFormDict = new CPDF_Dictionary;
117 pFormDict->SetNameFor("Type", "XObject"); 116 pFormDict->SetNameFor("Type", "XObject");
118 pFormDict->SetNameFor("Subtype", "Form"); 117 pFormDict->SetNameFor("Subtype", "Form");
118
119 CFX_FloatRect bbox = m_pPage->GetPageBBox(); 119 CFX_FloatRect bbox = m_pPage->GetPageBBox();
120 matrix.TransformRect(bbox); 120 matrix.TransformRect(bbox);
121 pFormDict->SetRectFor("BBox", bbox); 121 pFormDict->SetRectFor("BBox", bbox);
122
123 CPDF_Stream* pStream = new CPDF_Stream;
122 pStream->InitStream(data, size, pFormDict); 124 pStream->InitStream(data, size, pFormDict);
123 buf << "q " << matrix << " cm "; 125 buf << "q " << matrix << " cm ";
126
124 CFX_ByteString name = RealizeResource(pStream, "XObject"); 127 CFX_ByteString name = RealizeResource(pStream, "XObject");
125 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 128 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
126 } 129 }
130
127 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { 131 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) {
128 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; 132 CPDF_Dictionary* pDict = m_pPage->m_pFormDict;
129 CPDF_Object* pContent = 133 CPDF_Object* pContent =
130 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr; 134 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr;
131 if (!pContent) 135 if (!pContent)
132 return; 136 return;
133 137
134 CFX_ByteTextBuf buf; 138 CFX_ByteTextBuf buf;
135 if (CPDF_Array* pArray = pContent->AsArray()) { 139 if (CPDF_Array* pArray = pContent->AsArray()) {
136 size_t iCount = pArray->GetCount(); 140 size_t iCount = pArray->GetCount();
(...skipping 20 matching lines...) Expand all
157 delete pContentArray[i]; 161 delete pContentArray[i];
158 } 162 }
159 ProcessForm(buf, pBuf, size, matrix); 163 ProcessForm(buf, pBuf, size, matrix);
160 FX_Free(pBuf); 164 FX_Free(pBuf);
161 FX_Free(pContentArray); 165 FX_Free(pContentArray);
162 } else if (CPDF_Stream* pStream = pContent->AsStream()) { 166 } else if (CPDF_Stream* pStream = pContent->AsStream()) {
163 CPDF_StreamAcc contentStream; 167 CPDF_StreamAcc contentStream;
164 contentStream.LoadAllData(pStream); 168 contentStream.LoadAllData(pStream);
165 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 169 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
166 } 170 }
167 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); 171 CPDF_Stream* pStream = new CPDF_Stream;
168 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); 172 pStream->SetData(buf.GetBuffer(), buf.GetLength());
169 m_pDocument->AddIndirectObject(pStream); 173 m_pDocument->AddIndirectObject(pStream);
170 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, 174 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument,
171 pStream->GetObjNum()); 175 pStream->GetObjNum());
172 } 176 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_image.cpp » ('j') | core/fpdfapi/fpdf_parser/include/cpdf_stream.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698