| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 CPDF_RectArray* pRectArray) { | 48 CPDF_RectArray* pRectArray) { |
| 49 std::unique_ptr<CPDF_Page> pPDFPage(new CPDF_Page(pDoc, pDict, false)); | 49 std::unique_ptr<CPDF_Page> pPDFPage(new CPDF_Page(pDoc, pDict, false)); |
| 50 pPDFPage->ParseContent(); | 50 pPDFPage->ParseContent(); |
| 51 | 51 |
| 52 for (const auto& pPageObject : *pPDFPage->GetPageObjectList()) { | 52 for (const auto& pPageObject : *pPDFPage->GetPageObjectList()) { |
| 53 CFX_FloatRect rc; | 53 CFX_FloatRect rc; |
| 54 rc.left = pPageObject->m_Left; | 54 rc.left = pPageObject->m_Left; |
| 55 rc.right = pPageObject->m_Right; | 55 rc.right = pPageObject->m_Right; |
| 56 rc.bottom = pPageObject->m_Bottom; | 56 rc.bottom = pPageObject->m_Bottom; |
| 57 rc.top = pPageObject->m_Top; | 57 rc.top = pPageObject->m_Top; |
| 58 if (IsValiableRect(rc, pDict->GetRectBy("MediaBox"))) | 58 if (IsValiableRect(rc, pDict->GetRectFor("MediaBox"))) |
| 59 pRectArray->Add(rc); | 59 pRectArray->Add(rc); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ParserStream(CPDF_Dictionary* pPageDic, | 63 void ParserStream(CPDF_Dictionary* pPageDic, |
| 64 CPDF_Dictionary* pStream, | 64 CPDF_Dictionary* pStream, |
| 65 CPDF_RectArray* pRectArray, | 65 CPDF_RectArray* pRectArray, |
| 66 CPDF_ObjectArray* pObjectArray) { | 66 CPDF_ObjectArray* pObjectArray) { |
| 67 if (!pStream) | 67 if (!pStream) |
| 68 return; | 68 return; |
| 69 CFX_FloatRect rect; | 69 CFX_FloatRect rect; |
| 70 if (pStream->KeyExist("Rect")) | 70 if (pStream->KeyExist("Rect")) |
| 71 rect = pStream->GetRectBy("Rect"); | 71 rect = pStream->GetRectFor("Rect"); |
| 72 else if (pStream->KeyExist("BBox")) | 72 else if (pStream->KeyExist("BBox")) |
| 73 rect = pStream->GetRectBy("BBox"); | 73 rect = pStream->GetRectFor("BBox"); |
| 74 | 74 |
| 75 if (IsValiableRect(rect, pPageDic->GetRectBy("MediaBox"))) | 75 if (IsValiableRect(rect, pPageDic->GetRectFor("MediaBox"))) |
| 76 pRectArray->Add(rect); | 76 pRectArray->Add(rect); |
| 77 | 77 |
| 78 pObjectArray->Add(pStream); | 78 pObjectArray->Add(pStream); |
| 79 } | 79 } |
| 80 | 80 |
| 81 int ParserAnnots(CPDF_Document* pSourceDoc, | 81 int ParserAnnots(CPDF_Document* pSourceDoc, |
| 82 CPDF_Dictionary* pPageDic, | 82 CPDF_Dictionary* pPageDic, |
| 83 CPDF_RectArray* pRectArray, | 83 CPDF_RectArray* pRectArray, |
| 84 CPDF_ObjectArray* pObjectArray, | 84 CPDF_ObjectArray* pObjectArray, |
| 85 int nUsage) { | 85 int nUsage) { |
| 86 if (!pSourceDoc || !pPageDic) | 86 if (!pSourceDoc || !pPageDic) |
| 87 return FLATTEN_FAIL; | 87 return FLATTEN_FAIL; |
| 88 | 88 |
| 89 GetContentsRect(pSourceDoc, pPageDic, pRectArray); | 89 GetContentsRect(pSourceDoc, pPageDic, pRectArray); |
| 90 CPDF_Array* pAnnots = pPageDic->GetArrayBy("Annots"); | 90 CPDF_Array* pAnnots = pPageDic->GetArrayFor("Annots"); |
| 91 if (!pAnnots) | 91 if (!pAnnots) |
| 92 return FLATTEN_NOTHINGTODO; | 92 return FLATTEN_NOTHINGTODO; |
| 93 | 93 |
| 94 uint32_t dwSize = pAnnots->GetCount(); | 94 uint32_t dwSize = pAnnots->GetCount(); |
| 95 for (int i = 0; i < (int)dwSize; i++) { | 95 for (int i = 0; i < (int)dwSize; i++) { |
| 96 CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetDirectObjectAt(i)); | 96 CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetDirectObjectAt(i)); |
| 97 if (!pAnnotDic) | 97 if (!pAnnotDic) |
| 98 continue; | 98 continue; |
| 99 | 99 |
| 100 CFX_ByteString sSubtype = pAnnotDic->GetStringBy("Subtype"); | 100 CFX_ByteString sSubtype = pAnnotDic->GetStringFor("Subtype"); |
| 101 if (sSubtype == "Popup") | 101 if (sSubtype == "Popup") |
| 102 continue; | 102 continue; |
| 103 | 103 |
| 104 int nAnnotFlag = pAnnotDic->GetIntegerBy("F"); | 104 int nAnnotFlag = pAnnotDic->GetIntegerFor("F"); |
| 105 if (nAnnotFlag & ANNOTFLAG_HIDDEN) | 105 if (nAnnotFlag & ANNOTFLAG_HIDDEN) |
| 106 continue; | 106 continue; |
| 107 | 107 |
| 108 if (nUsage == FLAT_NORMALDISPLAY) { | 108 if (nUsage == FLAT_NORMALDISPLAY) { |
| 109 if (nAnnotFlag & ANNOTFLAG_INVISIBLE) | 109 if (nAnnotFlag & ANNOTFLAG_INVISIBLE) |
| 110 continue; | 110 continue; |
| 111 | 111 |
| 112 ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); | 112 ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); |
| 113 } else { | 113 } else { |
| 114 if (nAnnotFlag & ANNOTFLAG_PRINT) | 114 if (nAnnotFlag & ANNOTFLAG_PRINT) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP); | 178 rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP); |
| 179 rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT); | 179 rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT); |
| 180 rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM); | 180 rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM); |
| 181 | 181 |
| 182 return rcRet; | 182 return rcRet; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void SetPageContents(CFX_ByteString key, | 185 void SetPageContents(CFX_ByteString key, |
| 186 CPDF_Dictionary* pPage, | 186 CPDF_Dictionary* pPage, |
| 187 CPDF_Document* pDocument) { | 187 CPDF_Document* pDocument) { |
| 188 CPDF_Object* pContentsObj = pPage->GetStreamBy("Contents"); | 188 CPDF_Object* pContentsObj = pPage->GetStreamFor("Contents"); |
| 189 if (!pContentsObj) { | 189 if (!pContentsObj) { |
| 190 pContentsObj = pPage->GetArrayBy("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 = |
| 197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); | 197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); |
| 198 pPage->SetAtReference("Contents", pDocument, | 198 pPage->SetReferenceFor("Contents", pDocument, |
| 199 pDocument->AddIndirectObject(pNewContents)); | 199 pDocument->AddIndirectObject(pNewContents)); |
| 200 | 200 |
| 201 CFX_ByteString sStream; | 201 CFX_ByteString sStream; |
| 202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
| 203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, | 203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, |
| 204 FALSE); | 204 FALSE); |
| 205 } | 205 } |
| 206 return; | 206 return; |
| 207 } | 207 } |
| 208 | 208 |
| 209 CPDF_Array* pContentsArray = nullptr; | 209 CPDF_Array* pContentsArray = nullptr; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 229 break; | 229 break; |
| 230 } | 230 } |
| 231 default: | 231 default: |
| 232 break; | 232 break; |
| 233 } | 233 } |
| 234 | 234 |
| 235 if (!pContentsArray) | 235 if (!pContentsArray) |
| 236 return; | 236 return; |
| 237 | 237 |
| 238 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); | 238 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); |
| 239 pPage->SetAtReference("Contents", pDocument, dwObjNum); | 239 pPage->SetReferenceFor("Contents", pDocument, dwObjNum); |
| 240 | 240 |
| 241 if (!key.IsEmpty()) { | 241 if (!key.IsEmpty()) { |
| 242 CPDF_Stream* pNewContents = | 242 CPDF_Stream* pNewContents = |
| 243 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); | 243 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); |
| 244 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 244 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
| 245 pContentsArray->AddReference(pDocument, dwObjNum); | 245 pContentsArray->AddReference(pDocument, dwObjNum); |
| 246 | 246 |
| 247 CFX_ByteString sStream; | 247 CFX_ByteString sStream; |
| 248 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()); |
| 249 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); | 249 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 CPDF_ObjectArray ObjectArray; | 323 CPDF_ObjectArray ObjectArray; |
| 324 CPDF_RectArray RectArray; | 324 CPDF_RectArray RectArray; |
| 325 | 325 |
| 326 int iRet = FLATTEN_FAIL; | 326 int iRet = FLATTEN_FAIL; |
| 327 iRet = ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag); | 327 iRet = ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag); |
| 328 if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) | 328 if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) |
| 329 return iRet; | 329 return iRet; |
| 330 | 330 |
| 331 CFX_FloatRect rcOriginalCB; | 331 CFX_FloatRect rcOriginalCB; |
| 332 CFX_FloatRect rcMerger = CalculateRect(&RectArray); | 332 CFX_FloatRect rcMerger = CalculateRect(&RectArray); |
| 333 CFX_FloatRect rcOriginalMB = pPageDict->GetRectBy("MediaBox"); | 333 CFX_FloatRect rcOriginalMB = pPageDict->GetRectFor("MediaBox"); |
| 334 | 334 |
| 335 if (pPageDict->KeyExist("CropBox")) | 335 if (pPageDict->KeyExist("CropBox")) |
| 336 rcOriginalMB = pPageDict->GetRectBy("CropBox"); | 336 rcOriginalMB = pPageDict->GetRectFor("CropBox"); |
| 337 | 337 |
| 338 if (rcOriginalMB.IsEmpty()) { | 338 if (rcOriginalMB.IsEmpty()) { |
| 339 rcOriginalMB = CFX_FloatRect(0.0f, 0.0f, 612.0f, 792.0f); | 339 rcOriginalMB = CFX_FloatRect(0.0f, 0.0f, 612.0f, 792.0f); |
| 340 } | 340 } |
| 341 | 341 |
| 342 rcMerger.left = | 342 rcMerger.left = |
| 343 rcMerger.left < rcOriginalMB.left ? rcOriginalMB.left : rcMerger.left; | 343 rcMerger.left < rcOriginalMB.left ? rcOriginalMB.left : rcMerger.left; |
| 344 rcMerger.right = | 344 rcMerger.right = |
| 345 rcMerger.right > rcOriginalMB.right ? rcOriginalMB.right : rcMerger.right; | 345 rcMerger.right > rcOriginalMB.right ? rcOriginalMB.right : rcMerger.right; |
| 346 rcMerger.top = | 346 rcMerger.top = |
| 347 rcMerger.top > rcOriginalMB.top ? rcOriginalMB.top : rcMerger.top; | 347 rcMerger.top > rcOriginalMB.top ? rcOriginalMB.top : rcMerger.top; |
| 348 rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom ? rcOriginalMB.bottom | 348 rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom ? rcOriginalMB.bottom |
| 349 : rcMerger.bottom; | 349 : rcMerger.bottom; |
| 350 | 350 |
| 351 if (pPageDict->KeyExist("ArtBox")) | 351 if (pPageDict->KeyExist("ArtBox")) |
| 352 rcOriginalCB = pPageDict->GetRectBy("ArtBox"); | 352 rcOriginalCB = pPageDict->GetRectFor("ArtBox"); |
| 353 else | 353 else |
| 354 rcOriginalCB = rcOriginalMB; | 354 rcOriginalCB = rcOriginalMB; |
| 355 | 355 |
| 356 if (!rcOriginalMB.IsEmpty()) { | 356 if (!rcOriginalMB.IsEmpty()) { |
| 357 CPDF_Array* pMediaBox = new CPDF_Array(); | 357 CPDF_Array* pMediaBox = new CPDF_Array(); |
| 358 pMediaBox->Add(new CPDF_Number(rcOriginalMB.left)); | 358 pMediaBox->Add(new CPDF_Number(rcOriginalMB.left)); |
| 359 pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom)); | 359 pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom)); |
| 360 pMediaBox->Add(new CPDF_Number(rcOriginalMB.right)); | 360 pMediaBox->Add(new CPDF_Number(rcOriginalMB.right)); |
| 361 pMediaBox->Add(new CPDF_Number(rcOriginalMB.top)); | 361 pMediaBox->Add(new CPDF_Number(rcOriginalMB.top)); |
| 362 pPageDict->SetAt("MediaBox", pMediaBox); | 362 pPageDict->SetFor("MediaBox", pMediaBox); |
| 363 } | 363 } |
| 364 | 364 |
| 365 if (!rcOriginalCB.IsEmpty()) { | 365 if (!rcOriginalCB.IsEmpty()) { |
| 366 CPDF_Array* pCropBox = new CPDF_Array(); | 366 CPDF_Array* pCropBox = new CPDF_Array(); |
| 367 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); | 367 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); |
| 368 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); | 368 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); |
| 369 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); | 369 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); |
| 370 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); | 370 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); |
| 371 pPageDict->SetAt("ArtBox", pCropBox); | 371 pPageDict->SetFor("ArtBox", pCropBox); |
| 372 } | 372 } |
| 373 | 373 |
| 374 CPDF_Dictionary* pRes = pPageDict->GetDictBy("Resources"); | 374 CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); |
| 375 if (!pRes) { | 375 if (!pRes) { |
| 376 pRes = new CPDF_Dictionary; | 376 pRes = new CPDF_Dictionary; |
| 377 pPageDict->SetAt("Resources", pRes); | 377 pPageDict->SetFor("Resources", pRes); |
| 378 } | 378 } |
| 379 | 379 |
| 380 CPDF_Stream* pNewXObject = new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); | 380 CPDF_Stream* pNewXObject = new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); |
| 381 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); | 381 uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); |
| 382 CPDF_Dictionary* pPageXObject = pRes->GetDictBy("XObject"); | 382 CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); |
| 383 if (!pPageXObject) { | 383 if (!pPageXObject) { |
| 384 pPageXObject = new CPDF_Dictionary; | 384 pPageXObject = new CPDF_Dictionary; |
| 385 pRes->SetAt("XObject", pPageXObject); | 385 pRes->SetFor("XObject", pPageXObject); |
| 386 } | 386 } |
| 387 | 387 |
| 388 CFX_ByteString key = ""; | 388 CFX_ByteString key = ""; |
| 389 int nStreams = ObjectArray.GetSize(); | 389 int nStreams = ObjectArray.GetSize(); |
| 390 | 390 |
| 391 if (nStreams > 0) { | 391 if (nStreams > 0) { |
| 392 for (int iKey = 0; /*iKey < 100*/; iKey++) { | 392 for (int iKey = 0; /*iKey < 100*/; iKey++) { |
| 393 char sExtend[5] = {}; | 393 char sExtend[5] = {}; |
| 394 FXSYS_itoa(iKey, sExtend, 10); | 394 FXSYS_itoa(iKey, sExtend, 10); |
| 395 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); | 395 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); |
| 396 if (!pPageXObject->KeyExist(key)) | 396 if (!pPageXObject->KeyExist(key)) |
| 397 break; | 397 break; |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 SetPageContents(key, pPageDict, pDocument); | 401 SetPageContents(key, pPageDict, pDocument); |
| 402 | 402 |
| 403 CPDF_Dictionary* pNewXORes = nullptr; | 403 CPDF_Dictionary* pNewXORes = nullptr; |
| 404 | 404 |
| 405 if (!key.IsEmpty()) { | 405 if (!key.IsEmpty()) { |
| 406 pPageXObject->SetAtReference(key, pDocument, dwObjNum); | 406 pPageXObject->SetReferenceFor(key, pDocument, dwObjNum); |
| 407 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); | 407 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); |
| 408 pNewXORes = new CPDF_Dictionary; | 408 pNewXORes = new CPDF_Dictionary; |
| 409 pNewOXbjectDic->SetAt("Resources", pNewXORes); | 409 pNewOXbjectDic->SetFor("Resources", pNewXORes); |
| 410 pNewOXbjectDic->SetAtName("Type", "XObject"); | 410 pNewOXbjectDic->SetNameFor("Type", "XObject"); |
| 411 pNewOXbjectDic->SetAtName("Subtype", "Form"); | 411 pNewOXbjectDic->SetNameFor("Subtype", "Form"); |
| 412 pNewOXbjectDic->SetAtInteger("FormType", 1); | 412 pNewOXbjectDic->SetIntegerFor("FormType", 1); |
| 413 pNewOXbjectDic->SetAtName("Name", "FRM"); | 413 pNewOXbjectDic->SetNameFor("Name", "FRM"); |
| 414 CFX_FloatRect rcBBox = pPageDict->GetRectBy("ArtBox"); | 414 CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); |
| 415 pNewOXbjectDic->SetAtRect("BBox", rcBBox); | 415 pNewOXbjectDic->SetRectFor("BBox", rcBBox); |
| 416 } | 416 } |
| 417 | 417 |
| 418 for (int i = 0; i < nStreams; i++) { | 418 for (int i = 0; i < nStreams; i++) { |
| 419 CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i); | 419 CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i); |
| 420 if (!pAnnotDic) | 420 if (!pAnnotDic) |
| 421 continue; | 421 continue; |
| 422 | 422 |
| 423 CFX_FloatRect rcAnnot = pAnnotDic->GetRectBy("Rect"); | 423 CFX_FloatRect rcAnnot = pAnnotDic->GetRectFor("Rect"); |
| 424 rcAnnot.Normalize(); | 424 rcAnnot.Normalize(); |
| 425 | 425 |
| 426 CFX_ByteString sAnnotState = pAnnotDic->GetStringBy("AS"); | 426 CFX_ByteString sAnnotState = pAnnotDic->GetStringFor("AS"); |
| 427 CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDictBy("AP"); | 427 CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDictFor("AP"); |
| 428 if (!pAnnotAP) | 428 if (!pAnnotAP) |
| 429 continue; | 429 continue; |
| 430 | 430 |
| 431 CPDF_Stream* pAPStream = pAnnotAP->GetStreamBy("N"); | 431 CPDF_Stream* pAPStream = pAnnotAP->GetStreamFor("N"); |
| 432 if (!pAPStream) { | 432 if (!pAPStream) { |
| 433 CPDF_Dictionary* pAPDic = pAnnotAP->GetDictBy("N"); | 433 CPDF_Dictionary* pAPDic = pAnnotAP->GetDictFor("N"); |
| 434 if (!pAPDic) | 434 if (!pAPDic) |
| 435 continue; | 435 continue; |
| 436 | 436 |
| 437 if (!sAnnotState.IsEmpty()) { | 437 if (!sAnnotState.IsEmpty()) { |
| 438 pAPStream = pAPDic->GetStreamBy(sAnnotState); | 438 pAPStream = pAPDic->GetStreamFor(sAnnotState); |
| 439 } else { | 439 } else { |
| 440 auto it = pAPDic->begin(); | 440 auto it = pAPDic->begin(); |
| 441 if (it != pAPDic->end()) { | 441 if (it != pAPDic->end()) { |
| 442 CPDF_Object* pFirstObj = it->second; | 442 CPDF_Object* pFirstObj = it->second; |
| 443 if (pFirstObj) { | 443 if (pFirstObj) { |
| 444 if (pFirstObj->IsReference()) | 444 if (pFirstObj->IsReference()) |
| 445 pFirstObj = pFirstObj->GetDirect(); | 445 pFirstObj = pFirstObj->GetDirect(); |
| 446 if (!pFirstObj->IsStream()) | 446 if (!pFirstObj->IsStream()) |
| 447 continue; | 447 continue; |
| 448 pAPStream = pFirstObj->AsStream(); | 448 pAPStream = pFirstObj->AsStream(); |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 if (!pAPStream) | 453 if (!pAPStream) |
| 454 continue; | 454 continue; |
| 455 | 455 |
| 456 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); | 456 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); |
| 457 CFX_Matrix matrix = pAPDic->GetMatrixBy("Matrix"); | 457 CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix"); |
| 458 | 458 |
| 459 CFX_FloatRect rcStream; | 459 CFX_FloatRect rcStream; |
| 460 if (pAPDic->KeyExist("Rect")) | 460 if (pAPDic->KeyExist("Rect")) |
| 461 rcStream = pAPDic->GetRectBy("Rect"); | 461 rcStream = pAPDic->GetRectFor("Rect"); |
| 462 else if (pAPDic->KeyExist("BBox")) | 462 else if (pAPDic->KeyExist("BBox")) |
| 463 rcStream = pAPDic->GetRectBy("BBox"); | 463 rcStream = pAPDic->GetRectFor("BBox"); |
| 464 | 464 |
| 465 if (rcStream.IsEmpty()) | 465 if (rcStream.IsEmpty()) |
| 466 continue; | 466 continue; |
| 467 | 467 |
| 468 CPDF_Object* pObj = pAPStream; | 468 CPDF_Object* pObj = pAPStream; |
| 469 | 469 |
| 470 if (pObj) { | 470 if (pObj) { |
| 471 CPDF_Dictionary* pObjDic = pObj->GetDict(); | 471 CPDF_Dictionary* pObjDic = pObj->GetDict(); |
| 472 if (pObjDic) { | 472 if (pObjDic) { |
| 473 pObjDic->SetAtName("Type", "XObject"); | 473 pObjDic->SetNameFor("Type", "XObject"); |
| 474 pObjDic->SetAtName("Subtype", "Form"); | 474 pObjDic->SetNameFor("Subtype", "Form"); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 | 477 |
| 478 CPDF_Dictionary* pXObject = pNewXORes->GetDictBy("XObject"); | 478 CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); |
| 479 if (!pXObject) { | 479 if (!pXObject) { |
| 480 pXObject = new CPDF_Dictionary; | 480 pXObject = new CPDF_Dictionary; |
| 481 pNewXORes->SetAt("XObject", pXObject); | 481 pNewXORes->SetFor("XObject", pXObject); |
| 482 } | 482 } |
| 483 | 483 |
| 484 CFX_ByteString sFormName; | 484 CFX_ByteString sFormName; |
| 485 sFormName.Format("F%d", i); | 485 sFormName.Format("F%d", i); |
| 486 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj); | 486 uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj); |
| 487 pXObject->SetAtReference(sFormName, pDocument, dwStreamObjNum); | 487 pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum); |
| 488 | 488 |
| 489 CPDF_StreamAcc acc; | 489 CPDF_StreamAcc acc; |
| 490 acc.LoadAllData(pNewXObject); | 490 acc.LoadAllData(pNewXObject); |
| 491 | 491 |
| 492 const uint8_t* pData = acc.GetData(); | 492 const uint8_t* pData = acc.GetData(); |
| 493 CFX_ByteString sStream(pData, acc.GetSize()); | 493 CFX_ByteString sStream(pData, acc.GetSize()); |
| 494 CFX_ByteString sTemp; | 494 CFX_ByteString sTemp; |
| 495 | 495 |
| 496 if (matrix.IsIdentity()) { | 496 if (matrix.IsIdentity()) { |
| 497 matrix.a = 1.0f; | 497 matrix.a = 1.0f; |
| 498 matrix.b = 0.0f; | 498 matrix.b = 0.0f; |
| 499 matrix.c = 0.0f; | 499 matrix.c = 0.0f; |
| 500 matrix.d = 1.0f; | 500 matrix.d = 1.0f; |
| 501 matrix.e = 0.0f; | 501 matrix.e = 0.0f; |
| 502 matrix.f = 0.0f; | 502 matrix.f = 0.0f; |
| 503 } | 503 } |
| 504 | 504 |
| 505 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); | 505 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); |
| 506 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, |
| 507 sFormName.c_str()); | 507 sFormName.c_str()); |
| 508 sStream += sTemp; | 508 sStream += sTemp; |
| 509 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); | 509 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); |
| 510 } | 510 } |
| 511 pPageDict->RemoveAt("Annots"); | 511 pPageDict->RemoveFor("Annots"); |
| 512 | 512 |
| 513 ObjectArray.RemoveAll(); | 513 ObjectArray.RemoveAll(); |
| 514 RectArray.RemoveAll(); | 514 RectArray.RemoveAll(); |
| 515 | 515 |
| 516 return FLATTEN_SUCCESS; | 516 return FLATTEN_SUCCESS; |
| 517 } | 517 } |
| OLD | NEW |