| 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 "core/src/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
| 8 | 8 |
| 9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
| 10 #include "core/include/fpdfapi/fpdf_page.h" | 10 #include "core/include/fpdfapi/fpdf_page.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 {_FX_BSTRC("Indexed"), _FX_BSTRC("I")}, | 43 {_FX_BSTRC("Indexed"), _FX_BSTRC("I")}, |
| 44 {_FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx")}, | 44 {_FX_BSTRC("ASCIIHexDecode"), _FX_BSTRC("AHx")}, |
| 45 {_FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85")}, | 45 {_FX_BSTRC("ASCII85Decode"), _FX_BSTRC("A85")}, |
| 46 {_FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW")}, | 46 {_FX_BSTRC("LZWDecode"), _FX_BSTRC("LZW")}, |
| 47 {_FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl")}, | 47 {_FX_BSTRC("FlateDecode"), _FX_BSTRC("Fl")}, |
| 48 {_FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL")}, | 48 {_FX_BSTRC("RunLengthDecode"), _FX_BSTRC("RL")}, |
| 49 {_FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF")}, | 49 {_FX_BSTRC("CCITTFaxDecode"), _FX_BSTRC("CCF")}, |
| 50 {_FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT")}, | 50 {_FX_BSTRC("DCTDecode"), _FX_BSTRC("DCT")}, |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 struct AbbrReplacementOp { |
| 54 bool is_replace_key; |
| 55 CFX_ByteString key; |
| 56 CFX_ByteStringC replacement; |
| 57 }; |
| 58 |
| 53 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPairs* table, | 59 CFX_ByteStringC PDF_FindFullName(const PDF_AbbrPairs* table, |
| 54 size_t count, | 60 size_t count, |
| 55 const CFX_ByteStringC& abbr) { | 61 const CFX_ByteStringC& abbr) { |
| 56 for (size_t i = 0; i < count; ++i) { | 62 for (size_t i = 0; i < count; ++i) { |
| 57 if (abbr.GetLength() != table[i].abbr.m_Size) | 63 if (abbr.GetLength() != table[i].abbr.m_Size) |
| 58 continue; | 64 continue; |
| 59 if (memcmp(abbr.GetPtr(), table[i].abbr.m_Ptr, abbr.GetLength())) | 65 if (memcmp(abbr.GetPtr(), table[i].abbr.m_Ptr, abbr.GetLength())) |
| 60 continue; | 66 continue; |
| 61 return CFX_ByteStringC(table[i].full_name.m_Ptr, table[i].full_name.m_Size); | 67 return CFX_ByteStringC(table[i].full_name.m_Ptr, table[i].full_name.m_Size); |
| 62 } | 68 } |
| 63 return CFX_ByteStringC(); | 69 return CFX_ByteStringC(); |
| 64 } | 70 } |
| 65 | 71 |
| 66 CFX_ByteStringC PDF_FindAbbrName(const PDF_AbbrPairs* table, | |
| 67 size_t count, | |
| 68 const CFX_ByteStringC& name) { | |
| 69 for (size_t i = 0; i < count; ++i) { | |
| 70 if (name.GetLength() != table[i].full_name.m_Size) | |
| 71 continue; | |
| 72 if (memcmp(name.GetPtr(), table[i].full_name.m_Ptr, name.GetLength())) | |
| 73 continue; | |
| 74 return CFX_ByteStringC(table[i].abbr.m_Ptr, table[i].abbr.m_Size); | |
| 75 } | |
| 76 return CFX_ByteStringC(); | |
| 77 } | |
| 78 | |
| 79 } // namespace | 72 } // namespace |
| 80 | 73 |
| 81 CPDF_StreamContentParser::CPDF_StreamContentParser( | 74 CPDF_StreamContentParser::CPDF_StreamContentParser( |
| 82 CPDF_Document* pDocument, | 75 CPDF_Document* pDocument, |
| 83 CPDF_Dictionary* pPageResources, | 76 CPDF_Dictionary* pPageResources, |
| 84 CPDF_Dictionary* pParentResources, | 77 CPDF_Dictionary* pParentResources, |
| 85 CFX_Matrix* pmtContentToUser, | 78 CFX_Matrix* pmtContentToUser, |
| 86 CPDF_PageObjects* pObjList, | 79 CPDF_PageObjects* pObjList, |
| 87 CPDF_Dictionary* pResources, | 80 CPDF_Dictionary* pResources, |
| 88 CPDF_Rect* pBBox, | 81 CPDF_Rect* pBBox, |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 return; | 482 return; |
| 490 } | 483 } |
| 491 CFX_ByteString tag = GetString(0); | 484 CFX_ByteString tag = GetString(0); |
| 492 m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE); | 485 m_CurContentMark.GetModify()->AddMark(tag, NULL, FALSE); |
| 493 } | 486 } |
| 494 | 487 |
| 495 void PDF_ReplaceAbbr(CPDF_Object* pObj) { | 488 void PDF_ReplaceAbbr(CPDF_Object* pObj) { |
| 496 switch (pObj->GetType()) { | 489 switch (pObj->GetType()) { |
| 497 case PDFOBJ_DICTIONARY: { | 490 case PDFOBJ_DICTIONARY: { |
| 498 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 491 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 492 std::vector<AbbrReplacementOp> replacements; |
| 499 for (const auto& it : *pDict) { | 493 for (const auto& it : *pDict) { |
| 500 CFX_ByteString key = it.first; | 494 CFX_ByteString key = it.first; |
| 501 CPDF_Object* value = it.second; | 495 CPDF_Object* value = it.second; |
| 502 CFX_ByteStringC fullname = PDF_FindFullName( | 496 CFX_ByteStringC fullname = PDF_FindFullName( |
| 503 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); | 497 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); |
| 504 if (!fullname.IsEmpty()) { | 498 if (!fullname.IsEmpty()) { |
| 505 pDict->ReplaceKey(key, fullname); | 499 AbbrReplacementOp op; |
| 500 op.is_replace_key = true; |
| 501 op.key = key; |
| 502 op.replacement = fullname; |
| 503 replacements.push_back(op); |
| 506 key = fullname; | 504 key = fullname; |
| 507 } | 505 } |
| 508 | 506 |
| 509 if (value->IsName()) { | 507 if (value->IsName()) { |
| 510 CFX_ByteString name = value->GetString(); | 508 CFX_ByteString name = value->GetString(); |
| 511 fullname = PDF_FindFullName(PDF_InlineValueAbbr, | 509 fullname = PDF_FindFullName(PDF_InlineValueAbbr, |
| 512 FX_ArraySize(PDF_InlineValueAbbr), name); | 510 FX_ArraySize(PDF_InlineValueAbbr), name); |
| 513 if (!fullname.IsEmpty()) { | 511 if (!fullname.IsEmpty()) { |
| 514 pDict->SetAtName(key, fullname); | 512 AbbrReplacementOp op; |
| 513 op.is_replace_key = false; |
| 514 op.key = key; |
| 515 op.replacement = fullname; |
| 516 replacements.push_back(op); |
| 515 } | 517 } |
| 516 } else { | 518 } else { |
| 517 PDF_ReplaceAbbr(value); | 519 PDF_ReplaceAbbr(value); |
| 518 } | 520 } |
| 519 } | 521 } |
| 522 for (const auto& op : replacements) { |
| 523 if (op.is_replace_key) |
| 524 pDict->ReplaceKey(op.key, op.replacement); |
| 525 else |
| 526 pDict->SetAtName(op.key, op.replacement); |
| 527 } |
| 520 break; | 528 break; |
| 521 } | 529 } |
| 522 case PDFOBJ_ARRAY: { | 530 case PDFOBJ_ARRAY: { |
| 523 CPDF_Array* pArray = pObj->AsArray(); | 531 CPDF_Array* pArray = pObj->AsArray(); |
| 524 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 532 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { |
| 525 CPDF_Object* pElement = pArray->GetElement(i); | 533 CPDF_Object* pElement = pArray->GetElement(i); |
| 526 if (pElement->IsName()) { | 534 if (pElement->IsName()) { |
| 527 CFX_ByteString name = pElement->GetString(); | 535 CFX_ByteString name = pElement->GetString(); |
| 528 CFX_ByteStringC fullname = PDF_FindFullName( | 536 CFX_ByteStringC fullname = PDF_FindFullName( |
| 529 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); | 537 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); |
| 530 if (!fullname.IsEmpty()) { | 538 if (!fullname.IsEmpty()) { |
| 531 pArray->SetAt(i, new CPDF_Name(fullname)); | 539 pArray->SetAt(i, new CPDF_Name(fullname)); |
| 532 } | 540 } |
| 533 } else { | 541 } else { |
| 534 PDF_ReplaceAbbr(pElement); | 542 PDF_ReplaceAbbr(pElement); |
| 535 } | 543 } |
| 536 } | 544 } |
| 537 break; | 545 break; |
| 538 } | 546 } |
| 539 } | 547 } |
| 540 } | 548 } |
| 541 | 549 |
| 542 void PDF_ReplaceFull(CPDF_Object* pObj) { | |
| 543 switch (pObj->GetType()) { | |
| 544 case PDFOBJ_DICTIONARY: { | |
| 545 CPDF_Dictionary* pDict = pObj->AsDictionary(); | |
| 546 for (const auto& it : *pDict) { | |
| 547 CFX_ByteString key = it.first; | |
| 548 CPDF_Object* value = it.second; | |
| 549 CFX_ByteStringC abbrName = PDF_FindAbbrName( | |
| 550 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); | |
| 551 if (!abbrName.IsEmpty()) { | |
| 552 pDict->ReplaceKey(key, abbrName); | |
| 553 key = abbrName; | |
| 554 } | |
| 555 if (value->IsName()) { | |
| 556 CFX_ByteString name = value->GetString(); | |
| 557 abbrName = PDF_FindAbbrName(PDF_InlineValueAbbr, | |
| 558 FX_ArraySize(PDF_InlineValueAbbr), name); | |
| 559 if (!abbrName.IsEmpty()) { | |
| 560 pDict->SetAtName(key, abbrName); | |
| 561 } | |
| 562 } else { | |
| 563 PDF_ReplaceFull(value); | |
| 564 } | |
| 565 } | |
| 566 break; | |
| 567 } | |
| 568 case PDFOBJ_ARRAY: { | |
| 569 CPDF_Array* pArray = pObj->AsArray(); | |
| 570 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | |
| 571 CPDF_Object* pElement = pArray->GetElement(i); | |
| 572 if (pElement->IsName()) { | |
| 573 CFX_ByteString name = pElement->GetString(); | |
| 574 CFX_ByteStringC abbrName = PDF_FindAbbrName( | |
| 575 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); | |
| 576 if (!abbrName.IsEmpty()) { | |
| 577 pArray->SetAt(i, new CPDF_Name(abbrName)); | |
| 578 } | |
| 579 } else { | |
| 580 PDF_ReplaceFull(pElement); | |
| 581 } | |
| 582 } | |
| 583 break; | |
| 584 } | |
| 585 } | |
| 586 } | |
| 587 void CPDF_StreamContentParser::Handle_BeginText() { | 550 void CPDF_StreamContentParser::Handle_BeginText() { |
| 588 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); | 551 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); |
| 589 OnChangeTextMatrix(); | 552 OnChangeTextMatrix(); |
| 590 m_pCurStates->m_TextX = 0; | 553 m_pCurStates->m_TextX = 0; |
| 591 m_pCurStates->m_TextY = 0; | 554 m_pCurStates->m_TextY = 0; |
| 592 m_pCurStates->m_TextLineX = 0; | 555 m_pCurStates->m_TextLineX = 0; |
| 593 m_pCurStates->m_TextLineY = 0; | 556 m_pCurStates->m_TextLineY = 0; |
| 594 } | 557 } |
| 595 void CPDF_StreamContentParser::Handle_BeginSectionUndefined() { | 558 void CPDF_StreamContentParser::Handle_BeginSectionUndefined() { |
| 596 m_CompatCount++; | 559 m_CompatCount++; |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 m_pObjectList->m_ObjectList.AddTail(pPathObj); | 1479 m_pObjectList->m_ObjectList.AddTail(pPathObj); |
| 1517 } | 1480 } |
| 1518 if (PathClipType) { | 1481 if (PathClipType) { |
| 1519 if (!matrix.IsIdentity()) { | 1482 if (!matrix.IsIdentity()) { |
| 1520 Path.Transform(&matrix); | 1483 Path.Transform(&matrix); |
| 1521 matrix.SetIdentity(); | 1484 matrix.SetIdentity(); |
| 1522 } | 1485 } |
| 1523 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); | 1486 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); |
| 1524 } | 1487 } |
| 1525 } | 1488 } |
| OLD | NEW |