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_flatten.h" | 7 #include "public/fpdf_flatten.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 if (!pContentsObj) { | 195 if (!pContentsObj) { |
196 // Create a new contents dictionary | 196 // Create a new contents dictionary |
197 if (!key.IsEmpty()) { | 197 if (!key.IsEmpty()) { |
198 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 198 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
199 pPage->SetAtReference("Contents", pDocument, | 199 pPage->SetAtReference("Contents", pDocument, |
200 pDocument->AddIndirectObject(pNewContents)); | 200 pDocument->AddIndirectObject(pNewContents)); |
201 | 201 |
202 CFX_ByteString sStream; | 202 CFX_ByteString sStream; |
203 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 203 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
204 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 204 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, |
205 FALSE); | 205 FALSE); |
206 } | 206 } |
207 return; | 207 return; |
208 } | 208 } |
209 | 209 |
210 CPDF_Array* pContentsArray = NULL; | 210 CPDF_Array* pContentsArray = NULL; |
211 | 211 |
212 switch (pContentsObj->GetType()) { | 212 switch (pContentsObj->GetType()) { |
213 case CPDF_Object::STREAM: { | 213 case CPDF_Object::STREAM: { |
214 pContentsArray = new CPDF_Array; | 214 pContentsArray = new CPDF_Array; |
215 CPDF_Stream* pContents = pContentsObj->AsStream(); | 215 CPDF_Stream* pContents = pContentsObj->AsStream(); |
216 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); | 216 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); |
217 CPDF_StreamAcc acc; | 217 CPDF_StreamAcc acc; |
218 acc.LoadAllData(pContents); | 218 acc.LoadAllData(pContents); |
219 CFX_ByteString sStream = "q\n"; | 219 CFX_ByteString sStream = "q\n"; |
220 CFX_ByteString sBody = | 220 CFX_ByteString sBody = |
221 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); | 221 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); |
222 sStream = sStream + sBody + "\nQ"; | 222 sStream = sStream + sBody + "\nQ"; |
223 pContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 223 pContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
224 FALSE); | |
225 pContentsArray->AddReference(pDocument, dwObjNum); | 224 pContentsArray->AddReference(pDocument, dwObjNum); |
226 break; | 225 break; |
227 } | 226 } |
228 | 227 |
229 case CPDF_Object::ARRAY: { | 228 case CPDF_Object::ARRAY: { |
230 pContentsArray = pContentsObj->AsArray(); | 229 pContentsArray = pContentsObj->AsArray(); |
231 break; | 230 break; |
232 } | 231 } |
233 default: | 232 default: |
234 break; | 233 break; |
235 } | 234 } |
236 | 235 |
237 if (!pContentsArray) | 236 if (!pContentsArray) |
238 return; | 237 return; |
239 | 238 |
240 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); | 239 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); |
241 pPage->SetAtReference("Contents", pDocument, dwObjNum); | 240 pPage->SetAtReference("Contents", pDocument, dwObjNum); |
242 | 241 |
243 if (!key.IsEmpty()) { | 242 if (!key.IsEmpty()) { |
244 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 243 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
245 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 244 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
246 pContentsArray->AddReference(pDocument, dwObjNum); | 245 pContentsArray->AddReference(pDocument, dwObjNum); |
247 | 246 |
248 CFX_ByteString sStream; | 247 CFX_ByteString sStream; |
249 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 248 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
250 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 249 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
251 FALSE); | |
252 } | 250 } |
253 } | 251 } |
254 | 252 |
255 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, | 253 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, |
256 CFX_FloatRect rcStream, | 254 CFX_FloatRect rcStream, |
257 const CFX_Matrix& matrix) { | 255 const CFX_Matrix& matrix) { |
258 if (rcStream.IsEmpty()) | 256 if (rcStream.IsEmpty()) |
259 return CFX_Matrix(); | 257 return CFX_Matrix(); |
260 | 258 |
261 matrix.TransformRect(rcStream); | 259 matrix.TransformRect(rcStream); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 matrix.c = 0.0f; | 499 matrix.c = 0.0f; |
502 matrix.d = 1.0f; | 500 matrix.d = 1.0f; |
503 matrix.e = 0.0f; | 501 matrix.e = 0.0f; |
504 matrix.f = 0.0f; | 502 matrix.f = 0.0f; |
505 } | 503 } |
506 | 504 |
507 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); | 505 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); |
508 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, | 506 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, |
509 sFormName.c_str()); | 507 sFormName.c_str()); |
510 sStream += sTemp; | 508 sStream += sTemp; |
511 | 509 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
512 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | |
513 FALSE); | |
514 } | 510 } |
515 pPageDict->RemoveAt("Annots"); | 511 pPageDict->RemoveAt("Annots"); |
516 | 512 |
517 ObjectArray.RemoveAll(); | 513 ObjectArray.RemoveAll(); |
518 RectArray.RemoveAll(); | 514 RectArray.RemoveAll(); |
519 | 515 |
520 return FLATTEN_SUCCESS; | 516 return FLATTEN_SUCCESS; |
521 } | 517 } |
OLD | NEW |