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 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 | 9 |
10 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray; | 10 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 if (!pContentsObj) | 210 if (!pContentsObj) |
211 { | 211 { |
212 //Create a new contents dictionary | 212 //Create a new contents dictionary |
213 if (!key.IsEmpty()) | 213 if (!key.IsEmpty()) |
214 { | 214 { |
215 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new
CPDF_Dictionary); | 215 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new
CPDF_Dictionary); |
216 pPage->SetAtReference("Contents", pDocument, pDocument->
AddIndirectObject(pNewContents)); | 216 pPage->SetAtReference("Contents", pDocument, pDocument->
AddIndirectObject(pNewContents)); |
217 | 217 |
218 CFX_ByteString sStream; | 218 CFX_ByteString sStream; |
219 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str())
; | 219 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str())
; |
220 » » » pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLe
ngth(), FALSE, FALSE); | 220 » » » pNewContents->SetData((const uint8_t*)sStream, sStream.G
etLength(), FALSE, FALSE); |
221 } | 221 } |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 int iType = pContentsObj->GetType(); | 225 int iType = pContentsObj->GetType(); |
226 CPDF_Array* pContentsArray = NULL; | 226 CPDF_Array* pContentsArray = NULL; |
227 | 227 |
228 switch(iType) | 228 switch(iType) |
229 { | 229 { |
230 case PDFOBJ_STREAM: | 230 case PDFOBJ_STREAM: |
231 { | 231 { |
232 pContentsArray = new CPDF_Array; | 232 pContentsArray = new CPDF_Array; |
233 CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj; | 233 CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj; |
234 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pConten
ts); | 234 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pConten
ts); |
235 CPDF_StreamAcc acc; | 235 CPDF_StreamAcc acc; |
236 acc.LoadAllData(pContents); | 236 acc.LoadAllData(pContents); |
237 CFX_ByteString sStream = "q\n"; | 237 CFX_ByteString sStream = "q\n"; |
238 » » » CFX_ByteString sBody = CFX_ByteString((FX_LPCSTR)acc.Get
Data(), acc.GetSize()); | 238 » » » CFX_ByteString sBody = CFX_ByteString((const FX_CHAR*)ac
c.GetData(), acc.GetSize()); |
239 sStream = sStream + sBody + "\nQ"; | 239 sStream = sStream + sBody + "\nQ"; |
240 » » » pContents->SetData((FX_LPCBYTE)sStream, sStream.GetLengt
h(), FALSE, FALSE); | 240 » » » pContents->SetData((const uint8_t*)sStream, sStream.GetL
ength(), FALSE, FALSE); |
241 pContentsArray->AddReference(pDocument, dwObjNum); | 241 pContentsArray->AddReference(pDocument, dwObjNum); |
242 break; | 242 break; |
243 } | 243 } |
244 | 244 |
245 case PDFOBJ_ARRAY: | 245 case PDFOBJ_ARRAY: |
246 { | 246 { |
247 pContentsArray = (CPDF_Array*)pContentsObj; | 247 pContentsArray = (CPDF_Array*)pContentsObj; |
248 break; | 248 break; |
249 } | 249 } |
250 default: | 250 default: |
251 break; | 251 break; |
252 } | 252 } |
253 | 253 |
254 if (!pContentsArray)return; | 254 if (!pContentsArray)return; |
255 | 255 |
256 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); | 256 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); |
257 pPage->SetAtReference("Contents", pDocument, dwObjNum); | 257 pPage->SetAtReference("Contents", pDocument, dwObjNum); |
258 | 258 |
259 if (!key.IsEmpty()) | 259 if (!key.IsEmpty()) |
260 { | 260 { |
261 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Di
ctionary); | 261 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Di
ctionary); |
262 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 262 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
263 pContentsArray->AddReference(pDocument, dwObjNum); | 263 pContentsArray->AddReference(pDocument, dwObjNum); |
264 | 264 |
265 CFX_ByteString sStream; | 265 CFX_ByteString sStream; |
266 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 266 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
267 » » pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(),
FALSE, FALSE); | 267 » » pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength
(), FALSE, FALSE); |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatr
ix matrix) | 271 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatr
ix matrix) |
272 { | 272 { |
273 if(rcStream.IsEmpty()) | 273 if(rcStream.IsEmpty()) |
274 return CFX_AffineMatrix(); | 274 return CFX_AffineMatrix(); |
275 | 275 |
276 matrix.TransformRect(rcStream); | 276 matrix.TransformRect(rcStream); |
277 rcStream.Normalize(); | 277 rcStream.Normalize(); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } | 513 } |
514 | 514 |
515 CFX_ByteString sFormName; | 515 CFX_ByteString sFormName; |
516 sFormName.Format("F%d", i); | 516 sFormName.Format("F%d", i); |
517 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj); | 517 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj); |
518 pXObject->SetAtReference(sFormName, pDocument, dwObjNum); | 518 pXObject->SetAtReference(sFormName, pDocument, dwObjNum); |
519 | 519 |
520 CPDF_StreamAcc acc; | 520 CPDF_StreamAcc acc; |
521 acc.LoadAllData(pNewXObject); | 521 acc.LoadAllData(pNewXObject); |
522 | 522 |
523 » » FX_LPCBYTE pData = acc.GetData(); | 523 » » const uint8_t* pData = acc.GetData(); |
524 CFX_ByteString sStream(pData, acc.GetSize()); | 524 CFX_ByteString sStream(pData, acc.GetSize()); |
525 CFX_ByteString sTemp; | 525 CFX_ByteString sTemp; |
526 | 526 |
527 if (matrix.IsIdentity()) | 527 if (matrix.IsIdentity()) |
528 { | 528 { |
529 matrix.a = 1.0f; | 529 matrix.a = 1.0f; |
530 matrix.b = 0.0f; | 530 matrix.b = 0.0f; |
531 matrix.c = 0.0f; | 531 matrix.c = 0.0f; |
532 matrix.d = 1.0f; | 532 matrix.d = 1.0f; |
533 matrix.e = 0.0f; | 533 matrix.e = 0.0f; |
534 matrix.f = 0.0f; | 534 matrix.f = 0.0f; |
535 } | 535 } |
536 | 536 |
537 CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix); | 537 CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix); |
538 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m
.f, sFormName.c_str()); | 538 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m
.f, sFormName.c_str()); |
539 sStream += sTemp; | 539 sStream += sTemp; |
540 | 540 |
541 » » pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), F
ALSE, FALSE); | 541 » » pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(
), FALSE, FALSE); |
542 } | 542 } |
543 pPageDict->RemoveAt( "Annots" ); | 543 pPageDict->RemoveAt( "Annots" ); |
544 | 544 |
545 ObjectArray.RemoveAll(); | 545 ObjectArray.RemoveAll(); |
546 RectArray.RemoveAll(); | 546 RectArray.RemoveAll(); |
547 | 547 |
548 return FLATTEN_SUCCESS; | 548 return FLATTEN_SUCCESS; |
549 } | 549 } |
OLD | NEW |