OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "public/fpdf_transformpage.h" | 7 #include "public/fpdf_transformpage.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h" |
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (!pDoc) | 131 if (!pDoc) |
132 return FALSE; | 132 return FALSE; |
133 pDoc->AddIndirectObject(pStream); | 133 pDoc->AddIndirectObject(pStream); |
134 | 134 |
135 pDic = new CPDF_Dictionary; | 135 pDic = new CPDF_Dictionary; |
136 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); | 136 CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); |
137 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); | 137 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); |
138 pDoc->AddIndirectObject(pEndStream); | 138 pDoc->AddIndirectObject(pEndStream); |
139 | 139 |
140 CPDF_Array* pContentArray = nullptr; | 140 CPDF_Array* pContentArray = nullptr; |
141 if (CPDF_Array* pArray = ToArray(pContentObj)) { | 141 CPDF_Array* pArray = ToArray(pContentObj); |
| 142 if (pArray) { |
142 pContentArray = pArray; | 143 pContentArray = pArray; |
143 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 144 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
144 pContentArray->InsertAt(0, pRef); | 145 pContentArray->InsertAt(0, pRef); |
145 pContentArray->AddReference(pDoc, pEndStream); | 146 pContentArray->AddReference(pDoc, pEndStream); |
146 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { | 147 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { |
147 CPDF_Object* pDirectObj = pReference->GetDirect(); | 148 CPDF_Object* pDirectObj = pReference->GetDirect(); |
148 if (pDirectObj) { | 149 if (pDirectObj) { |
149 if (CPDF_Array* pArray = pDirectObj->AsArray()) { | 150 CPDF_Array* pObjArray = pDirectObj->AsArray(); |
150 pContentArray = pArray; | 151 if (pObjArray) { |
| 152 pContentArray = pObjArray; |
151 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 153 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
152 pContentArray->InsertAt(0, pRef); | 154 pContentArray->InsertAt(0, pRef); |
153 pContentArray->AddReference(pDoc, pEndStream); | 155 pContentArray->AddReference(pDoc, pEndStream); |
154 } else if (pDirectObj->IsStream()) { | 156 } else if (pDirectObj->IsStream()) { |
155 pContentArray = new CPDF_Array(); | 157 pContentArray = new CPDF_Array(); |
156 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 158 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
157 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 159 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
158 pContentArray->AddReference(pDoc, pEndStream); | 160 pContentArray->AddReference(pDoc, pEndStream); |
159 pPageDic->SetAtReference("Contents", pDoc, | 161 pPageDic->SetAtReference("Contents", pDoc, |
160 pDoc->AddIndirectObject(pContentArray)); | 162 pDoc->AddIndirectObject(pContentArray)); |
161 } | 163 } |
162 } | 164 } |
163 } | 165 } |
164 | 166 |
165 // Need to transform the patterns as well. | 167 // Need to transform the patterns as well. |
166 CPDF_Dictionary* pRes = pPageDic->GetDictBy("Resources"); | 168 CPDF_Dictionary* pRes = pPageDic->GetDictBy("Resources"); |
167 if (pRes) { | 169 if (pRes) { |
168 CPDF_Dictionary* pPattenDict = pRes->GetDictBy("Pattern"); | 170 CPDF_Dictionary* pPattenDict = pRes->GetDictBy("Pattern"); |
169 if (pPattenDict) { | 171 if (pPattenDict) { |
170 for (const auto& it : *pPattenDict) { | 172 for (const auto& it : *pPattenDict) { |
171 CPDF_Object* pObj = it.second; | 173 CPDF_Object* pObj = it.second; |
172 if (pObj->IsReference()) | 174 if (pObj->IsReference()) |
173 pObj = pObj->GetDirect(); | 175 pObj = pObj->GetDirect(); |
174 | 176 |
175 CPDF_Dictionary* pDict = nullptr; | 177 CPDF_Dictionary* pDict = nullptr; |
176 if (pObj->IsDictionary()) | 178 if (pObj->IsDictionary()) |
177 pDict = pObj->AsDictionary(); | 179 pDict = pObj->AsDictionary(); |
178 else if (CPDF_Stream* pStream = pObj->AsStream()) | 180 else if (CPDF_Stream* pObjStream = pObj->AsStream()) |
179 pDict = pStream->GetDict(); | 181 pDict = pObjStream->GetDict(); |
180 else | 182 else |
181 continue; | 183 continue; |
182 | 184 |
183 CFX_Matrix m = pDict->GetMatrixBy("Matrix"); | 185 CFX_Matrix m = pDict->GetMatrixBy("Matrix"); |
184 CFX_Matrix t = *(CFX_Matrix*)matrix; | 186 CFX_Matrix t = *(CFX_Matrix*)matrix; |
185 m.Concat(t); | 187 m.Concat(t); |
186 pDict->SetAtMatrix("Matrix", m); | 188 pDict->SetAtMatrix("Matrix", m); |
187 } | 189 } |
188 } | 190 } |
189 } | 191 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 302 } |
301 CPDF_Dictionary* pDic = new CPDF_Dictionary; | 303 CPDF_Dictionary* pDic = new CPDF_Dictionary; |
302 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); | 304 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); |
303 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); | 305 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); |
304 CPDF_Document* pDoc = pPage->m_pDocument; | 306 CPDF_Document* pDoc = pPage->m_pDocument; |
305 if (!pDoc) | 307 if (!pDoc) |
306 return; | 308 return; |
307 pDoc->AddIndirectObject(pStream); | 309 pDoc->AddIndirectObject(pStream); |
308 | 310 |
309 CPDF_Array* pContentArray = nullptr; | 311 CPDF_Array* pContentArray = nullptr; |
310 if (CPDF_Array* pArray = ToArray(pContentObj)) { | 312 CPDF_Array* pArray = ToArray(pContentObj); |
| 313 if (pArray) { |
311 pContentArray = pArray; | 314 pContentArray = pArray; |
312 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 315 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
313 pContentArray->InsertAt(0, pRef); | 316 pContentArray->InsertAt(0, pRef); |
314 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { | 317 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) { |
315 CPDF_Object* pDirectObj = pReference->GetDirect(); | 318 CPDF_Object* pDirectObj = pReference->GetDirect(); |
316 if (pDirectObj) { | 319 if (pDirectObj) { |
317 if (CPDF_Array* pArray = pDirectObj->AsArray()) { | 320 CPDF_Array* pObjArray = pDirectObj->AsArray(); |
318 pContentArray = pArray; | 321 if (pObjArray) { |
| 322 pContentArray = pObjArray; |
319 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); | 323 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
320 pContentArray->InsertAt(0, pRef); | 324 pContentArray->InsertAt(0, pRef); |
321 } else if (pDirectObj->IsStream()) { | 325 } else if (pDirectObj->IsStream()) { |
322 pContentArray = new CPDF_Array(); | 326 pContentArray = new CPDF_Array(); |
323 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 327 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
324 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 328 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
325 pPageDic->SetAtReference("Contents", pDoc, | 329 pPageDic->SetAtReference("Contents", pDoc, |
326 pDoc->AddIndirectObject(pContentArray)); | 330 pDoc->AddIndirectObject(pContentArray)); |
327 } | 331 } |
328 } | 332 } |
329 } | 333 } |
330 } | 334 } |
OLD | NEW |