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

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

Issue 2489423002: Make CPDF_PageContentGenerator methods take object numbers (Closed)
Patch Set: Rebase past fix in separate CL Created 4 years, 1 month 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 | « core/fpdfapi/edit/cpdf_pagecontentgenerator.h ('k') | core/fpdfapi/page/cpdf_docpagedata.h » ('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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (pContent) 52 if (pContent)
53 pPageDict->RemoveFor("Contents"); 53 pPageDict->RemoveFor("Contents");
54 54
55 CPDF_Stream* pStream = new CPDF_Stream; 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, 57 pPageDict->SetReferenceFor("Contents", m_pDocument,
58 m_pDocument->AddIndirectObject(pStream)); 58 m_pDocument->AddIndirectObject(pStream));
59 } 59 }
60 60
61 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( 61 CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
62 CPDF_Object* pResourceObj, 62 uint32_t dwResourceObjNum,
63 const CFX_ByteString& bsType) { 63 const CFX_ByteString& bsType) {
64 ASSERT(dwResourceObjNum);
64 if (!m_pPage->m_pResources) { 65 if (!m_pPage->m_pResources) {
65 m_pPage->m_pResources = 66 m_pPage->m_pResources =
66 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 67 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
67 m_pPage->m_pFormDict->SetReferenceFor( 68 m_pPage->m_pFormDict->SetReferenceFor(
68 "Resources", m_pDocument, 69 "Resources", m_pDocument,
69 m_pDocument->AddIndirectObject(m_pPage->m_pResources)); 70 m_pDocument->AddIndirectObject(m_pPage->m_pResources));
70 } 71 }
71 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); 72 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType);
72 if (!pResList) { 73 if (!pResList) {
73 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 74 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool());
74 m_pPage->m_pResources->SetFor(bsType, pResList); 75 m_pPage->m_pResources->SetFor(bsType, pResList);
75 } 76 }
76 CFX_ByteString name; 77 CFX_ByteString name;
77 int idnum = 1; 78 int idnum = 1;
78 while (1) { 79 while (1) {
79 name.Format("FX%c%d", bsType[0], idnum); 80 name.Format("FX%c%d", bsType[0], idnum);
80 if (!pResList->KeyExist(name)) { 81 if (!pResList->KeyExist(name)) {
81 break; 82 break;
82 } 83 }
83 idnum++; 84 idnum++;
84 } 85 }
85 pResList->SetReferenceFor(name, m_pDocument, 86 pResList->SetReferenceFor(name, m_pDocument, dwResourceObjNum);
86 m_pDocument->AddIndirectObject(pResourceObj));
87 return name; 87 return name;
88 } 88 }
89 89
90 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, 90 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf,
91 CPDF_ImageObject* pImageObj) { 91 CPDF_ImageObject* pImageObj) {
92 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || 92 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) ||
93 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { 93 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) {
94 return; 94 return;
95 } 95 }
96 buf << "q " << pImageObj->m_Matrix << " cm "; 96 buf << "q " << pImageObj->m_Matrix << " cm ";
97 97
98 CPDF_Image* pImage = pImageObj->GetImage(); 98 CPDF_Image* pImage = pImageObj->GetImage();
99 if (pImage->IsInline()) 99 if (pImage->IsInline())
100 return; 100 return;
101 101
102 CPDF_Stream* pStream = pImage->GetStream(); 102 CPDF_Stream* pStream = pImage->GetStream();
103 if (!pStream) 103 if (!pStream)
104 return; 104 return;
105 105
106 bool bWasInline = pStream->IsInline(); 106 bool bWasInline = pStream->IsInline();
107 CFX_ByteString name = RealizeResource(pStream, "XObject");
108 if (bWasInline) 107 if (bWasInline)
109 pImageObj->SetUnownedImage(m_pDocument->GetPageData()->GetImage(pStream)); 108 pImage->ConvertStreamToIndirectObject();
109
110 uint32_t dwObjNum = pStream->GetObjNum();
111 CFX_ByteString name = RealizeResource(dwObjNum, "XObject");
112 if (bWasInline)
113 pImageObj->SetUnownedImage(m_pDocument->GetPageData()->GetImage(dwObjNum));
110 114
111 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 115 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
112 } 116 }
113 117
114 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, 118 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf,
115 const uint8_t* data, 119 const uint8_t* data,
116 uint32_t size, 120 uint32_t size,
117 CFX_Matrix& matrix) { 121 CFX_Matrix& matrix) {
118 if (!data || !size) 122 if (!data || !size)
119 return; 123 return;
120 124
125 buf << "q " << matrix << " cm ";
126
127 CFX_FloatRect bbox = m_pPage->GetPageBBox();
128 matrix.TransformRect(bbox);
129
121 CPDF_Dictionary* pFormDict = 130 CPDF_Dictionary* pFormDict =
122 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 131 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
123 pFormDict->SetNameFor("Type", "XObject"); 132 pFormDict->SetNameFor("Type", "XObject");
124 pFormDict->SetNameFor("Subtype", "Form"); 133 pFormDict->SetNameFor("Subtype", "Form");
125
126 CFX_FloatRect bbox = m_pPage->GetPageBBox();
127 matrix.TransformRect(bbox);
128 pFormDict->SetRectFor("BBox", bbox); 134 pFormDict->SetRectFor("BBox", bbox);
129 135
130 CPDF_Stream* pStream = new CPDF_Stream; 136 CPDF_Stream* pStream = new CPDF_Stream;
131 pStream->InitStream(data, size, pFormDict); 137 pStream->InitStream(data, size, pFormDict);
132 buf << "q " << matrix << " cm ";
133 138
134 CFX_ByteString name = RealizeResource(pStream, "XObject"); 139 CFX_ByteString name =
140 RealizeResource(m_pDocument->AddIndirectObject(pStream), "XObject");
135 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; 141 buf << "/" << PDF_NameEncode(name) << " Do Q\n";
136 } 142 }
137 143
138 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { 144 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) {
139 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; 145 CPDF_Dictionary* pDict = m_pPage->m_pFormDict;
140 CPDF_Object* pContent = 146 CPDF_Object* pContent =
141 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr; 147 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr;
142 if (!pContent) 148 if (!pContent)
143 return; 149 return;
144 150
(...skipping 28 matching lines...) Expand all
173 } else if (CPDF_Stream* pStream = pContent->AsStream()) { 179 } else if (CPDF_Stream* pStream = pContent->AsStream()) {
174 CPDF_StreamAcc contentStream; 180 CPDF_StreamAcc contentStream;
175 contentStream.LoadAllData(pStream); 181 contentStream.LoadAllData(pStream);
176 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); 182 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix);
177 } 183 }
178 CPDF_Stream* pStream = new CPDF_Stream; 184 CPDF_Stream* pStream = new CPDF_Stream;
179 pStream->SetData(buf.GetBuffer(), buf.GetLength()); 185 pStream->SetData(buf.GetBuffer(), buf.GetLength());
180 m_pPage->m_pFormDict->SetReferenceFor( 186 m_pPage->m_pFormDict->SetReferenceFor(
181 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream)); 187 "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream));
182 } 188 }
OLDNEW
« no previous file with comments | « core/fpdfapi/edit/cpdf_pagecontentgenerator.h ('k') | core/fpdfapi/page/cpdf_docpagedata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698