| 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/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 if (type != CPDF_StreamParser::Name) { | 569 if (type != CPDF_StreamParser::Name) { |
| 570 break; | 570 break; |
| 571 } | 571 } |
| 572 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, | 572 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, |
| 573 m_pSyntax->GetWordSize() - 1); | 573 m_pSyntax->GetWordSize() - 1); |
| 574 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 574 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
| 575 m_pSyntax->ReadNextObject()); | 575 m_pSyntax->ReadNextObject()); |
| 576 if (!key.IsEmpty()) { | 576 if (!key.IsEmpty()) { |
| 577 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; | 577 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; |
| 578 if (dwObjNum) | 578 if (dwObjNum) |
| 579 pDict->SetAtReference(key, m_pDocument, dwObjNum); | 579 pDict->SetAtReference(key.AsByteStringC(), m_pDocument, dwObjNum); |
| 580 else | 580 else |
| 581 pDict->SetAt(key, pObj.release()); | 581 pDict->SetAt(key.AsByteStringC(), pObj.release()); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 PDF_ReplaceAbbr(pDict); | 584 PDF_ReplaceAbbr(pDict); |
| 585 CPDF_Object* pCSObj = NULL; | 585 CPDF_Object* pCSObj = NULL; |
| 586 if (pDict->KeyExist("ColorSpace")) { | 586 if (pDict->KeyExist("ColorSpace")) { |
| 587 pCSObj = pDict->GetDirectObjectBy("ColorSpace"); | 587 pCSObj = pDict->GetDirectObjectBy("ColorSpace"); |
| 588 if (pCSObj->IsName()) { | 588 if (pCSObj->IsName()) { |
| 589 CFX_ByteString name = pCSObj->GetString(); | 589 CFX_ByteString name = pCSObj->GetString(); |
| 590 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { | 590 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { |
| 591 pCSObj = FindResourceObj("ColorSpace", name); | 591 pCSObj = FindResourceObj("ColorSpace", name); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 724 |
| 725 if (m_Options.m_bTextOnly) { | 725 if (m_Options.m_bTextOnly) { |
| 726 if (!m_pResources) | 726 if (!m_pResources) |
| 727 return; | 727 return; |
| 728 | 728 |
| 729 CPDF_Dictionary* pList = m_pResources->GetDictBy("XObject"); | 729 CPDF_Dictionary* pList = m_pResources->GetDictBy("XObject"); |
| 730 if (!pList && m_pPageResources && m_pResources != m_pPageResources) | 730 if (!pList && m_pPageResources && m_pResources != m_pPageResources) |
| 731 pList = m_pPageResources->GetDictBy("XObject"); | 731 pList = m_pPageResources->GetDictBy("XObject"); |
| 732 if (!pList) | 732 if (!pList) |
| 733 return; | 733 return; |
| 734 CPDF_Reference* pRes = ToReference(pList->GetObjectBy(name)); | 734 CPDF_Reference* pRes = |
| 735 ToReference(pList->GetObjectBy(name.AsByteStringC())); |
| 735 if (!pRes) | 736 if (!pRes) |
| 736 return; | 737 return; |
| 737 | 738 |
| 738 FX_BOOL bForm; | 739 FX_BOOL bForm; |
| 739 if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm) | 740 if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm) |
| 740 return; | 741 return; |
| 741 } | 742 } |
| 742 | 743 |
| 743 CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name)); | 744 CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name)); |
| 744 if (!pXObject) { | 745 if (!pXObject) { |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 const CFX_ByteStringC& type, | 1261 const CFX_ByteStringC& type, |
| 1261 const CFX_ByteString& name) { | 1262 const CFX_ByteString& name) { |
| 1262 if (!m_pResources) { | 1263 if (!m_pResources) { |
| 1263 return NULL; | 1264 return NULL; |
| 1264 } | 1265 } |
| 1265 if (m_pResources == m_pPageResources) { | 1266 if (m_pResources == m_pPageResources) { |
| 1266 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); | 1267 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); |
| 1267 if (!pList) { | 1268 if (!pList) { |
| 1268 return NULL; | 1269 return NULL; |
| 1269 } | 1270 } |
| 1270 CPDF_Object* pRes = pList->GetDirectObjectBy(name); | 1271 CPDF_Object* pRes = pList->GetDirectObjectBy(name.AsByteStringC()); |
| 1271 return pRes; | 1272 return pRes; |
| 1272 } | 1273 } |
| 1273 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); | 1274 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); |
| 1274 if (!pList) { | 1275 if (!pList) { |
| 1275 if (!m_pPageResources) { | 1276 if (!m_pPageResources) { |
| 1276 return NULL; | 1277 return NULL; |
| 1277 } | 1278 } |
| 1278 CPDF_Dictionary* pList = m_pPageResources->GetDictBy(type); | 1279 CPDF_Dictionary* pList = m_pPageResources->GetDictBy(type); |
| 1279 if (!pList) { | 1280 if (!pList) { |
| 1280 return NULL; | 1281 return NULL; |
| 1281 } | 1282 } |
| 1282 CPDF_Object* pRes = pList->GetDirectObjectBy(name); | 1283 CPDF_Object* pRes = pList->GetDirectObjectBy(name.AsByteStringC()); |
| 1283 return pRes; | 1284 return pRes; |
| 1284 } | 1285 } |
| 1285 CPDF_Object* pRes = pList->GetDirectObjectBy(name); | 1286 CPDF_Object* pRes = pList->GetDirectObjectBy(name.AsByteStringC()); |
| 1286 return pRes; | 1287 return pRes; |
| 1287 } | 1288 } |
| 1288 | 1289 |
| 1289 CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) { | 1290 CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) { |
| 1290 CPDF_Dictionary* pFontDict = ToDictionary(FindResourceObj("Font", name)); | 1291 CPDF_Dictionary* pFontDict = ToDictionary(FindResourceObj("Font", name)); |
| 1291 if (!pFontDict) { | 1292 if (!pFontDict) { |
| 1292 m_bResourceMissing = TRUE; | 1293 m_bResourceMissing = TRUE; |
| 1293 return CPDF_Font::GetStockFont(m_pDocument, "Helvetica"); | 1294 return CPDF_Font::GetStockFont(m_pDocument, "Helvetica"); |
| 1294 } | 1295 } |
| 1295 | 1296 |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 } | 1767 } |
| 1767 | 1768 |
| 1768 void PDF_ReplaceAbbr(CPDF_Object* pObj) { | 1769 void PDF_ReplaceAbbr(CPDF_Object* pObj) { |
| 1769 switch (pObj->GetType()) { | 1770 switch (pObj->GetType()) { |
| 1770 case CPDF_Object::DICTIONARY: { | 1771 case CPDF_Object::DICTIONARY: { |
| 1771 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 1772 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 1772 std::vector<AbbrReplacementOp> replacements; | 1773 std::vector<AbbrReplacementOp> replacements; |
| 1773 for (const auto& it : *pDict) { | 1774 for (const auto& it : *pDict) { |
| 1774 CFX_ByteString key = it.first; | 1775 CFX_ByteString key = it.first; |
| 1775 CPDF_Object* value = it.second; | 1776 CPDF_Object* value = it.second; |
| 1776 CFX_ByteStringC fullname = PDF_FindFullName( | 1777 CFX_ByteStringC fullname = |
| 1777 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); | 1778 PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), |
| 1779 key.AsByteStringC()); |
| 1778 if (!fullname.IsEmpty()) { | 1780 if (!fullname.IsEmpty()) { |
| 1779 AbbrReplacementOp op; | 1781 AbbrReplacementOp op; |
| 1780 op.is_replace_key = true; | 1782 op.is_replace_key = true; |
| 1781 op.key = key; | 1783 op.key = key; |
| 1782 op.replacement = fullname; | 1784 op.replacement = fullname; |
| 1783 replacements.push_back(op); | 1785 replacements.push_back(op); |
| 1784 key = fullname; | 1786 key = fullname; |
| 1785 } | 1787 } |
| 1786 | 1788 |
| 1787 if (value->IsName()) { | 1789 if (value->IsName()) { |
| 1788 CFX_ByteString name = value->GetString(); | 1790 CFX_ByteString name = value->GetString(); |
| 1789 fullname = PDF_FindFullName(PDF_InlineValueAbbr, | 1791 fullname = PDF_FindFullName(PDF_InlineValueAbbr, |
| 1790 FX_ArraySize(PDF_InlineValueAbbr), name); | 1792 FX_ArraySize(PDF_InlineValueAbbr), |
| 1793 name.AsByteStringC()); |
| 1791 if (!fullname.IsEmpty()) { | 1794 if (!fullname.IsEmpty()) { |
| 1792 AbbrReplacementOp op; | 1795 AbbrReplacementOp op; |
| 1793 op.is_replace_key = false; | 1796 op.is_replace_key = false; |
| 1794 op.key = key; | 1797 op.key = key; |
| 1795 op.replacement = fullname; | 1798 op.replacement = fullname; |
| 1796 replacements.push_back(op); | 1799 replacements.push_back(op); |
| 1797 } | 1800 } |
| 1798 } else { | 1801 } else { |
| 1799 PDF_ReplaceAbbr(value); | 1802 PDF_ReplaceAbbr(value); |
| 1800 } | 1803 } |
| 1801 } | 1804 } |
| 1802 for (const auto& op : replacements) { | 1805 for (const auto& op : replacements) { |
| 1803 if (op.is_replace_key) | 1806 if (op.is_replace_key) |
| 1804 pDict->ReplaceKey(op.key, op.replacement); | 1807 pDict->ReplaceKey(op.key.AsByteStringC(), op.replacement); |
| 1805 else | 1808 else |
| 1806 pDict->SetAtName(op.key, op.replacement); | 1809 pDict->SetAtName(op.key.AsByteStringC(), op.replacement); |
| 1807 } | 1810 } |
| 1808 break; | 1811 break; |
| 1809 } | 1812 } |
| 1810 case CPDF_Object::ARRAY: { | 1813 case CPDF_Object::ARRAY: { |
| 1811 CPDF_Array* pArray = pObj->AsArray(); | 1814 CPDF_Array* pArray = pObj->AsArray(); |
| 1812 for (uint32_t i = 0; i < pArray->GetCount(); i++) { | 1815 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
| 1813 CPDF_Object* pElement = pArray->GetObjectAt(i); | 1816 CPDF_Object* pElement = pArray->GetObjectAt(i); |
| 1814 if (pElement->IsName()) { | 1817 if (pElement->IsName()) { |
| 1815 CFX_ByteString name = pElement->GetString(); | 1818 CFX_ByteString name = pElement->GetString(); |
| 1816 CFX_ByteStringC fullname = PDF_FindFullName( | 1819 CFX_ByteStringC fullname = PDF_FindFullName( |
| 1817 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); | 1820 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), |
| 1821 name.AsByteStringC()); |
| 1818 if (!fullname.IsEmpty()) { | 1822 if (!fullname.IsEmpty()) { |
| 1819 pArray->SetAt(i, new CPDF_Name(fullname)); | 1823 pArray->SetAt(i, new CPDF_Name(fullname)); |
| 1820 } | 1824 } |
| 1821 } else { | 1825 } else { |
| 1822 PDF_ReplaceAbbr(pElement); | 1826 PDF_ReplaceAbbr(pElement); |
| 1823 } | 1827 } |
| 1824 } | 1828 } |
| 1825 break; | 1829 break; |
| 1826 } | 1830 } |
| 1827 default: | 1831 default: |
| 1828 break; | 1832 break; |
| 1829 } | 1833 } |
| 1830 } | 1834 } |
| OLD | NEW |