| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 CPDF_ObjectArray* pObjectArray, | 87 CPDF_ObjectArray* pObjectArray, |
| 88 int nUsage) { | 88 int nUsage) { |
| 89 if (!pSourceDoc || !pPageDic) | 89 if (!pSourceDoc || !pPageDic) |
| 90 return FLATTEN_FAIL; | 90 return FLATTEN_FAIL; |
| 91 | 91 |
| 92 GetContentsRect(pSourceDoc, pPageDic, pRectArray); | 92 GetContentsRect(pSourceDoc, pPageDic, pRectArray); |
| 93 CPDF_Array* pAnnots = pPageDic->GetArrayBy("Annots"); | 93 CPDF_Array* pAnnots = pPageDic->GetArrayBy("Annots"); |
| 94 if (!pAnnots) | 94 if (!pAnnots) |
| 95 return FLATTEN_NOTHINGTODO; | 95 return FLATTEN_NOTHINGTODO; |
| 96 | 96 |
| 97 FX_DWORD dwSize = pAnnots->GetCount(); | 97 uint32_t dwSize = pAnnots->GetCount(); |
| 98 for (int i = 0; i < (int)dwSize; i++) { | 98 for (int i = 0; i < (int)dwSize; i++) { |
| 99 CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetElementValue(i)); | 99 CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetElementValue(i)); |
| 100 if (!pAnnotDic) | 100 if (!pAnnotDic) |
| 101 continue; | 101 continue; |
| 102 | 102 |
| 103 CFX_ByteString sSubtype = pAnnotDic->GetStringBy("Subtype"); | 103 CFX_ByteString sSubtype = pAnnotDic->GetStringBy("Subtype"); |
| 104 if (sSubtype == "Popup") | 104 if (sSubtype == "Popup") |
| 105 continue; | 105 continue; |
| 106 | 106 |
| 107 int nAnnotFlag = pAnnotDic->GetIntegerBy("F"); | 107 int nAnnotFlag = pAnnotDic->GetIntegerBy("F"); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 FX_DWORD 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((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
| 224 FALSE); | 224 FALSE); |
| 225 pContentsArray->AddReference(pDocument, dwObjNum); | 225 pContentsArray->AddReference(pDocument, dwObjNum); |
| 226 break; | 226 break; |
| 227 } | 227 } |
| 228 | 228 |
| 229 case CPDF_Object::ARRAY: { | 229 case CPDF_Object::ARRAY: { |
| 230 pContentsArray = pContentsObj->AsArray(); | 230 pContentsArray = pContentsObj->AsArray(); |
| 231 break; | 231 break; |
| 232 } | 232 } |
| 233 default: | 233 default: |
| 234 break; | 234 break; |
| 235 } | 235 } |
| 236 | 236 |
| 237 if (!pContentsArray) | 237 if (!pContentsArray) |
| 238 return; | 238 return; |
| 239 | 239 |
| 240 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); | 240 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); |
| 241 pPage->SetAtReference("Contents", pDocument, dwObjNum); | 241 pPage->SetAtReference("Contents", pDocument, dwObjNum); |
| 242 | 242 |
| 243 if (!key.IsEmpty()) { | 243 if (!key.IsEmpty()) { |
| 244 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 244 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
| 245 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 245 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
| 246 pContentsArray->AddReference(pDocument, dwObjNum); | 246 pContentsArray->AddReference(pDocument, dwObjNum); |
| 247 | 247 |
| 248 CFX_ByteString sStream; | 248 CFX_ByteString sStream; |
| 249 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 249 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, | 250 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 pPageDict->SetAt("ArtBox", pCropBox); | 373 pPageDict->SetAt("ArtBox", pCropBox); |
| 374 } | 374 } |
| 375 | 375 |
| 376 CPDF_Dictionary* pRes = pPageDict->GetDictBy("Resources"); | 376 CPDF_Dictionary* pRes = pPageDict->GetDictBy("Resources"); |
| 377 if (!pRes) { | 377 if (!pRes) { |
| 378 pRes = new CPDF_Dictionary; | 378 pRes = new CPDF_Dictionary; |
| 379 pPageDict->SetAt("Resources", pRes); | 379 pPageDict->SetAt("Resources", pRes); |
| 380 } | 380 } |
| 381 | 381 |
| 382 CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); | 382 CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); |
| 383 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject); | 383 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); |
| 384 CPDF_Dictionary* pPageXObject = pRes->GetDictBy("XObject"); | 384 CPDF_Dictionary* pPageXObject = pRes->GetDictBy("XObject"); |
| 385 if (!pPageXObject) { | 385 if (!pPageXObject) { |
| 386 pPageXObject = new CPDF_Dictionary; | 386 pPageXObject = new CPDF_Dictionary; |
| 387 pRes->SetAt("XObject", pPageXObject); | 387 pRes->SetAt("XObject", pPageXObject); |
| 388 } | 388 } |
| 389 | 389 |
| 390 CFX_ByteString key = ""; | 390 CFX_ByteString key = ""; |
| 391 int nStreams = ObjectArray.GetSize(); | 391 int nStreams = ObjectArray.GetSize(); |
| 392 | 392 |
| 393 if (nStreams > 0) { | 393 if (nStreams > 0) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 479 } |
| 480 | 480 |
| 481 CPDF_Dictionary* pXObject = pNewXORes->GetDictBy("XObject"); | 481 CPDF_Dictionary* pXObject = pNewXORes->GetDictBy("XObject"); |
| 482 if (!pXObject) { | 482 if (!pXObject) { |
| 483 pXObject = new CPDF_Dictionary; | 483 pXObject = new CPDF_Dictionary; |
| 484 pNewXORes->SetAt("XObject", pXObject); | 484 pNewXORes->SetAt("XObject", pXObject); |
| 485 } | 485 } |
| 486 | 486 |
| 487 CFX_ByteString sFormName; | 487 CFX_ByteString sFormName; |
| 488 sFormName.Format("F%d", i); | 488 sFormName.Format("F%d", i); |
| 489 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj); | 489 uint32_t dwObjNum = pDocument->AddIndirectObject(pObj); |
| 490 pXObject->SetAtReference(sFormName, pDocument, dwObjNum); | 490 pXObject->SetAtReference(sFormName, pDocument, dwObjNum); |
| 491 | 491 |
| 492 CPDF_StreamAcc acc; | 492 CPDF_StreamAcc acc; |
| 493 acc.LoadAllData(pNewXObject); | 493 acc.LoadAllData(pNewXObject); |
| 494 | 494 |
| 495 const uint8_t* pData = acc.GetData(); | 495 const uint8_t* pData = acc.GetData(); |
| 496 CFX_ByteString sStream(pData, acc.GetSize()); | 496 CFX_ByteString sStream(pData, acc.GetSize()); |
| 497 CFX_ByteString sTemp; | 497 CFX_ByteString sTemp; |
| 498 | 498 |
| 499 if (matrix.IsIdentity()) { | 499 if (matrix.IsIdentity()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 513 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 513 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
| 514 FALSE); | 514 FALSE); |
| 515 } | 515 } |
| 516 pPageDict->RemoveAt("Annots"); | 516 pPageDict->RemoveAt("Annots"); |
| 517 | 517 |
| 518 ObjectArray.RemoveAll(); | 518 ObjectArray.RemoveAll(); |
| 519 RectArray.RemoveAll(); | 519 RectArray.RemoveAll(); |
| 520 | 520 |
| 521 return FLATTEN_SUCCESS; | 521 return FLATTEN_SUCCESS; |
| 522 } | 522 } |
| OLD | NEW |