| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 CPDF_Dictionary* pPage, | 186 CPDF_Dictionary* pPage, |
| 187 CPDF_Document* pDocument) { | 187 CPDF_Document* pDocument) { |
| 188 CPDF_Object* pContentsObj = pPage->GetStreamFor("Contents"); | 188 CPDF_Object* pContentsObj = pPage->GetStreamFor("Contents"); |
| 189 if (!pContentsObj) { | 189 if (!pContentsObj) { |
| 190 pContentsObj = pPage->GetArrayFor("Contents"); | 190 pContentsObj = pPage->GetArrayFor("Contents"); |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (!pContentsObj) { | 193 if (!pContentsObj) { |
| 194 // Create a new contents dictionary | 194 // Create a new contents dictionary |
| 195 if (!key.IsEmpty()) { | 195 if (!key.IsEmpty()) { |
| 196 CPDF_Stream* pNewContents = | 196 CPDF_Stream* pNewContents = new CPDF_Stream( |
| 197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); | 197 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool())); |
| 198 CFX_ByteString sStream; | 198 CFX_ByteString sStream; |
| 199 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 199 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
| 200 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); | 200 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); |
| 201 pPage->SetReferenceFor("Contents", pDocument, | 201 pPage->SetReferenceFor("Contents", pDocument, |
| 202 pDocument->AddIndirectObject(pNewContents)); | 202 pDocument->AddIndirectObject(pNewContents)); |
| 203 } | 203 } |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 CPDF_Array* pContentsArray = nullptr; | 207 CPDF_Array* pContentsArray = nullptr; |
| 208 | |
| 209 switch (pContentsObj->GetType()) { | 208 switch (pContentsObj->GetType()) { |
| 210 case CPDF_Object::STREAM: { | 209 case CPDF_Object::STREAM: { |
| 211 pContentsArray = new CPDF_Array; | 210 pContentsArray = new CPDF_Array; |
| 212 CPDF_Stream* pContents = pContentsObj->AsStream(); | 211 CPDF_Stream* pContents = pContentsObj->AsStream(); |
| 213 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); | 212 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); |
| 214 CPDF_StreamAcc acc; | 213 CPDF_StreamAcc acc; |
| 215 acc.LoadAllData(pContents); | 214 acc.LoadAllData(pContents); |
| 216 CFX_ByteString sStream = "q\n"; | 215 CFX_ByteString sStream = "q\n"; |
| 217 CFX_ByteString sBody = | 216 CFX_ByteString sBody = |
| 218 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); | 217 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 230 break; | 229 break; |
| 231 } | 230 } |
| 232 | 231 |
| 233 if (!pContentsArray) | 232 if (!pContentsArray) |
| 234 return; | 233 return; |
| 235 | 234 |
| 236 pPage->SetReferenceFor("Contents", pDocument, | 235 pPage->SetReferenceFor("Contents", pDocument, |
| 237 pDocument->AddIndirectObject(pContentsArray)); | 236 pDocument->AddIndirectObject(pContentsArray)); |
| 238 | 237 |
| 239 if (!key.IsEmpty()) { | 238 if (!key.IsEmpty()) { |
| 240 CPDF_Stream* pNewContents = | 239 CPDF_Stream* pNewContents = new CPDF_Stream( |
| 241 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); | 240 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool())); |
| 242 CFX_ByteString sStream; | 241 CFX_ByteString sStream; |
| 243 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 242 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
| 244 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); | 243 pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); |
| 245 pContentsArray->AddReference(pDocument, | 244 pContentsArray->AddReference(pDocument, |
| 246 pDocument->AddIndirectObject(pNewContents)); | 245 pDocument->AddIndirectObject(pNewContents)); |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 | 248 |
| 250 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, | 249 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, |
| 251 CFX_FloatRect rcStream, | 250 CFX_FloatRect rcStream, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 CPDF_Array* pCropBox = new CPDF_Array(); | 362 CPDF_Array* pCropBox = new CPDF_Array(); |
| 364 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); | 363 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); |
| 365 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); | 364 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); |
| 366 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); | 365 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); |
| 367 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); | 366 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); |
| 368 pPageDict->SetFor("ArtBox", pCropBox); | 367 pPageDict->SetFor("ArtBox", pCropBox); |
| 369 } | 368 } |
| 370 | 369 |
| 371 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); | 370 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); |
| 372 if (!pRes) { | 371 if (!pRes) { |
| 373 pRes = new CPDF_Dictionary; | 372 pRes = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 374 pPageDict->SetFor("Resources", pRes); | 373 pPageDict->SetFor("Resources", pRes); |
| 375 } | 374 } |
| 376 | 375 |
| 377 CPDF_Stream* pNewXObject = new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); | 376 CPDF_Stream* pNewXObject = new CPDF_Stream( |
| 377 nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool())); |
| 378 |
| 378 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); | 379 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); |
| 379 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); | 380 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); |
| 380 if (!pPageXObject) { | 381 if (!pPageXObject) { |
| 381 pPageXObject = new CPDF_Dictionary; | 382 pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 382 pRes->SetFor("XObject", pPageXObject); | 383 pRes->SetFor("XObject", pPageXObject); |
| 383 } | 384 } |
| 384 | 385 |
| 385 CFX_ByteString key = ""; | 386 CFX_ByteString key = ""; |
| 386 int nStreams = ObjectArray.GetSize(); | 387 int nStreams = ObjectArray.GetSize(); |
| 387 | 388 |
| 388 if (nStreams > 0) { | 389 if (nStreams > 0) { |
| 389 for (int iKey = 0; /*iKey < 100*/; iKey++) { | 390 for (int iKey = 0; /*iKey < 100*/; iKey++) { |
| 390 char sExtend[5] = {}; | 391 char sExtend[5] = {}; |
| 391 FXSYS_itoa(iKey, sExtend, 10); | 392 FXSYS_itoa(iKey, sExtend, 10); |
| 392 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); | 393 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); |
| 393 if (!pPageXObject->KeyExist(key)) | 394 if (!pPageXObject->KeyExist(key)) |
| 394 break; | 395 break; |
| 395 } | 396 } |
| 396 } | 397 } |
| 397 | 398 |
| 398 SetPageContents(key, pPageDict, pDocument); | 399 SetPageContents(key, pPageDict, pDocument); |
| 399 | 400 |
| 400 CPDF_Dictionary* pNewXORes = nullptr; | 401 CPDF_Dictionary* pNewXORes = nullptr; |
| 401 | 402 |
| 402 if (!key.IsEmpty()) { | 403 if (!key.IsEmpty()) { |
| 403 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum); | 404 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum); |
| 404 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); | 405 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); |
| 405 pNewXORes = new CPDF_Dictionary; | 406 pNewXORes = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 406 pNewOXbjectDic->SetFor("Resources", pNewXORes); | 407 pNewOXbjectDic->SetFor("Resources", pNewXORes); |
| 407 pNewOXbjectDic->SetNameFor("Type", "XObject"); | 408 pNewOXbjectDic->SetNameFor("Type", "XObject"); |
| 408 pNewOXbjectDic->SetNameFor("Subtype", "Form"); | 409 pNewOXbjectDic->SetNameFor("Subtype", "Form"); |
| 409 pNewOXbjectDic->SetIntegerFor("FormType", 1); | 410 pNewOXbjectDic->SetIntegerFor("FormType", 1); |
| 410 pNewOXbjectDic->SetNameFor("Name", "FRM"); | 411 pNewOXbjectDic->SetNameFor("Name", "FRM"); |
| 411 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); | 412 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); |
| 412 pNewOXbjectDic->SetRectFor("BBox", rcBBox); | 413 pNewOXbjectDic->SetRectFor("BBox", rcBBox); |
| 413 } | 414 } |
| 414 | 415 |
| 415 for (int i = 0; i < nStreams; i++) { | 416 for (int i = 0; i < nStreams; i++) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if (pObj) { | 468 if (pObj) { |
| 468 CPDF_Dictionary* pObjDic = pObj->GetDict(); | 469 CPDF_Dictionary* pObjDic = pObj->GetDict(); |
| 469 if (pObjDic) { | 470 if (pObjDic) { |
| 470 pObjDic->SetNameFor("Type", "XObject"); | 471 pObjDic->SetNameFor("Type", "XObject"); |
| 471 pObjDic->SetNameFor("Subtype", "Form"); | 472 pObjDic->SetNameFor("Subtype", "Form"); |
| 472 } | 473 } |
| 473 } | 474 } |
| 474 | 475 |
| 475 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); | 476 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); |
| 476 if (!pXObject) { | 477 if (!pXObject) { |
| 477 pXObject = new CPDF_Dictionary; | 478 pXObject = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
| 478 pNewXORes->SetFor("XObject", pXObject); | 479 pNewXORes->SetFor("XObject", pXObject); |
| 479 } | 480 } |
| 480 | 481 |
| 481 CFX_ByteString sFormName; | 482 CFX_ByteString sFormName; |
| 482 sFormName.Format("F%d", i); | 483 sFormName.Format("F%d", i); |
| 483 pXObject->SetReferenceFor(sFormName, pDocument, | 484 pXObject->SetReferenceFor(sFormName, pDocument, |
| 484 pDocument->AddIndirectObject(pObj)); | 485 pDocument->AddIndirectObject(pObj)); |
| 485 | 486 |
| 486 CPDF_StreamAcc acc; | 487 CPDF_StreamAcc acc; |
| 487 acc.LoadAllData(pNewXObject); | 488 acc.LoadAllData(pNewXObject); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 505 sStream += sTemp; | 506 sStream += sTemp; |
| 506 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); | 507 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); |
| 507 } | 508 } |
| 508 pPageDict->RemoveFor("Annots"); | 509 pPageDict->RemoveFor("Annots"); |
| 509 | 510 |
| 510 ObjectArray.RemoveAll(); | 511 ObjectArray.RemoveAll(); |
| 511 RectArray.RemoveAll(); | 512 RectArray.RemoveAll(); |
| 512 | 513 |
| 513 return FLATTEN_SUCCESS; | 514 return FLATTEN_SUCCESS; |
| 514 } | 515 } |
| OLD | NEW |