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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 if (type != CPDF_StreamParser::Name) { | 559 if (type != CPDF_StreamParser::Name) { |
560 break; | 560 break; |
561 } | 561 } |
562 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, | 562 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, |
563 m_pSyntax->GetWordSize() - 1); | 563 m_pSyntax->GetWordSize() - 1); |
564 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 564 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
565 m_pSyntax->ReadNextObject()); | 565 m_pSyntax->ReadNextObject()); |
566 if (!key.IsEmpty()) { | 566 if (!key.IsEmpty()) { |
567 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; | 567 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; |
568 if (dwObjNum) | 568 if (dwObjNum) |
569 pDict->SetAtReference(key, m_pDocument, dwObjNum); | 569 pDict->SetAtReference(key.AsByteStringC(), m_pDocument, dwObjNum); |
570 else | 570 else |
571 pDict->SetAt(key, pObj.release()); | 571 pDict->SetAt(key.AsByteStringC(), pObj.release()); |
572 } | 572 } |
573 } | 573 } |
574 PDF_ReplaceAbbr(pDict); | 574 PDF_ReplaceAbbr(pDict); |
575 CPDF_Object* pCSObj = NULL; | 575 CPDF_Object* pCSObj = NULL; |
576 if (pDict->KeyExist("ColorSpace")) { | 576 if (pDict->KeyExist("ColorSpace")) { |
577 pCSObj = pDict->GetDirectObjectBy("ColorSpace"); | 577 pCSObj = pDict->GetDirectObjectBy("ColorSpace"); |
578 if (pCSObj->IsName()) { | 578 if (pCSObj->IsName()) { |
579 CFX_ByteString name = pCSObj->GetString(); | 579 CFX_ByteString name = pCSObj->GetString(); |
580 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { | 580 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { |
581 pCSObj = FindResourceObj("ColorSpace", name); | 581 pCSObj = FindResourceObj("ColorSpace", name); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 714 |
715 if (m_Options.m_bTextOnly) { | 715 if (m_Options.m_bTextOnly) { |
716 if (!m_pResources) | 716 if (!m_pResources) |
717 return; | 717 return; |
718 | 718 |
719 CPDF_Dictionary* pList = m_pResources->GetDictBy("XObject"); | 719 CPDF_Dictionary* pList = m_pResources->GetDictBy("XObject"); |
720 if (!pList && m_pPageResources && m_pResources != m_pPageResources) | 720 if (!pList && m_pPageResources && m_pResources != m_pPageResources) |
721 pList = m_pPageResources->GetDictBy("XObject"); | 721 pList = m_pPageResources->GetDictBy("XObject"); |
722 if (!pList) | 722 if (!pList) |
723 return; | 723 return; |
724 CPDF_Reference* pRes = ToReference(pList->GetObjectBy(name)); | 724 CPDF_Reference* pRes = |
| 725 ToReference(pList->GetObjectBy(name.AsByteStringC())); |
725 if (!pRes) | 726 if (!pRes) |
726 return; | 727 return; |
727 | 728 |
728 FX_BOOL bForm; | 729 FX_BOOL bForm; |
729 if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm) | 730 if (m_pDocument->IsFormStream(pRes->GetRefObjNum(), bForm) && !bForm) |
730 return; | 731 return; |
731 } | 732 } |
732 | 733 |
733 CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name)); | 734 CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name)); |
734 if (!pXObject) { | 735 if (!pXObject) { |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 const CFX_ByteStringC& type, | 1251 const CFX_ByteStringC& type, |
1251 const CFX_ByteString& name) { | 1252 const CFX_ByteString& name) { |
1252 if (!m_pResources) { | 1253 if (!m_pResources) { |
1253 return NULL; | 1254 return NULL; |
1254 } | 1255 } |
1255 if (m_pResources == m_pPageResources) { | 1256 if (m_pResources == m_pPageResources) { |
1256 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); | 1257 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); |
1257 if (!pList) { | 1258 if (!pList) { |
1258 return NULL; | 1259 return NULL; |
1259 } | 1260 } |
1260 CPDF_Object* pRes = pList->GetDirectObjectBy(name); | 1261 CPDF_Object* pRes = pList->GetDirectObjectBy(name.AsByteStringC()); |
1261 return pRes; | 1262 return pRes; |
1262 } | 1263 } |
1263 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); | 1264 CPDF_Dictionary* pList = m_pResources->GetDictBy(type); |
1264 if (!pList) { | 1265 if (!pList) { |
1265 if (!m_pPageResources) { | 1266 if (!m_pPageResources) { |
1266 return NULL; | 1267 return NULL; |
1267 } | 1268 } |
1268 CPDF_Dictionary* pList = m_pPageResources->GetDictBy(type); | 1269 CPDF_Dictionary* pList = m_pPageResources->GetDictBy(type); |
1269 if (!pList) { | 1270 if (!pList) { |
1270 return NULL; | 1271 return NULL; |
1271 } | 1272 } |
1272 CPDF_Object* pRes = pList->GetDirectObjectBy(name); | 1273 CPDF_Object* pRes = pList->GetDirectObjectBy(name.AsByteStringC()); |
1273 return pRes; | 1274 return pRes; |
1274 } | 1275 } |
1275 CPDF_Object* pRes = pList->GetDirectObjectBy(name); | 1276 CPDF_Object* pRes = pList->GetDirectObjectBy(name.AsByteStringC()); |
1276 return pRes; | 1277 return pRes; |
1277 } | 1278 } |
1278 | 1279 |
1279 CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) { | 1280 CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) { |
1280 CPDF_Dictionary* pFontDict = ToDictionary(FindResourceObj("Font", name)); | 1281 CPDF_Dictionary* pFontDict = ToDictionary(FindResourceObj("Font", name)); |
1281 if (!pFontDict) { | 1282 if (!pFontDict) { |
1282 m_bResourceMissing = TRUE; | 1283 m_bResourceMissing = TRUE; |
1283 return CPDF_Font::GetStockFont(m_pDocument, "Helvetica"); | 1284 return CPDF_Font::GetStockFont(m_pDocument, "Helvetica"); |
1284 } | 1285 } |
1285 | 1286 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 } | 1757 } |
1757 | 1758 |
1758 void PDF_ReplaceAbbr(CPDF_Object* pObj) { | 1759 void PDF_ReplaceAbbr(CPDF_Object* pObj) { |
1759 switch (pObj->GetType()) { | 1760 switch (pObj->GetType()) { |
1760 case CPDF_Object::DICTIONARY: { | 1761 case CPDF_Object::DICTIONARY: { |
1761 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 1762 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
1762 std::vector<AbbrReplacementOp> replacements; | 1763 std::vector<AbbrReplacementOp> replacements; |
1763 for (const auto& it : *pDict) { | 1764 for (const auto& it : *pDict) { |
1764 CFX_ByteString key = it.first; | 1765 CFX_ByteString key = it.first; |
1765 CPDF_Object* value = it.second; | 1766 CPDF_Object* value = it.second; |
1766 CFX_ByteStringC fullname = PDF_FindFullName( | 1767 CFX_ByteStringC fullname = |
1767 PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); | 1768 PDF_FindFullName(PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), |
| 1769 key.AsByteStringC()); |
1768 if (!fullname.IsEmpty()) { | 1770 if (!fullname.IsEmpty()) { |
1769 AbbrReplacementOp op; | 1771 AbbrReplacementOp op; |
1770 op.is_replace_key = true; | 1772 op.is_replace_key = true; |
1771 op.key = key; | 1773 op.key = key; |
1772 op.replacement = fullname; | 1774 op.replacement = fullname; |
1773 replacements.push_back(op); | 1775 replacements.push_back(op); |
1774 key = fullname; | 1776 key = fullname; |
1775 } | 1777 } |
1776 | 1778 |
1777 if (value->IsName()) { | 1779 if (value->IsName()) { |
1778 CFX_ByteString name = value->GetString(); | 1780 CFX_ByteString name = value->GetString(); |
1779 fullname = PDF_FindFullName(PDF_InlineValueAbbr, | 1781 fullname = PDF_FindFullName(PDF_InlineValueAbbr, |
1780 FX_ArraySize(PDF_InlineValueAbbr), name); | 1782 FX_ArraySize(PDF_InlineValueAbbr), |
| 1783 name.AsByteStringC()); |
1781 if (!fullname.IsEmpty()) { | 1784 if (!fullname.IsEmpty()) { |
1782 AbbrReplacementOp op; | 1785 AbbrReplacementOp op; |
1783 op.is_replace_key = false; | 1786 op.is_replace_key = false; |
1784 op.key = key; | 1787 op.key = key; |
1785 op.replacement = fullname; | 1788 op.replacement = fullname; |
1786 replacements.push_back(op); | 1789 replacements.push_back(op); |
1787 } | 1790 } |
1788 } else { | 1791 } else { |
1789 PDF_ReplaceAbbr(value); | 1792 PDF_ReplaceAbbr(value); |
1790 } | 1793 } |
1791 } | 1794 } |
1792 for (const auto& op : replacements) { | 1795 for (const auto& op : replacements) { |
1793 if (op.is_replace_key) | 1796 if (op.is_replace_key) |
1794 pDict->ReplaceKey(op.key, op.replacement); | 1797 pDict->ReplaceKey(op.key.AsByteStringC(), op.replacement); |
1795 else | 1798 else |
1796 pDict->SetAtName(op.key, op.replacement); | 1799 pDict->SetAtName(op.key.AsByteStringC(), op.replacement); |
1797 } | 1800 } |
1798 break; | 1801 break; |
1799 } | 1802 } |
1800 case CPDF_Object::ARRAY: { | 1803 case CPDF_Object::ARRAY: { |
1801 CPDF_Array* pArray = pObj->AsArray(); | 1804 CPDF_Array* pArray = pObj->AsArray(); |
1802 for (uint32_t i = 0; i < pArray->GetCount(); i++) { | 1805 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
1803 CPDF_Object* pElement = pArray->GetObjectAt(i); | 1806 CPDF_Object* pElement = pArray->GetObjectAt(i); |
1804 if (pElement->IsName()) { | 1807 if (pElement->IsName()) { |
1805 CFX_ByteString name = pElement->GetString(); | 1808 CFX_ByteString name = pElement->GetString(); |
1806 CFX_ByteStringC fullname = PDF_FindFullName( | 1809 CFX_ByteStringC fullname = PDF_FindFullName( |
1807 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name); | 1810 PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), |
| 1811 name.AsByteStringC()); |
1808 if (!fullname.IsEmpty()) { | 1812 if (!fullname.IsEmpty()) { |
1809 pArray->SetAt(i, new CPDF_Name(fullname)); | 1813 pArray->SetAt(i, new CPDF_Name(fullname)); |
1810 } | 1814 } |
1811 } else { | 1815 } else { |
1812 PDF_ReplaceAbbr(pElement); | 1816 PDF_ReplaceAbbr(pElement); |
1813 } | 1817 } |
1814 } | 1818 } |
1815 break; | 1819 break; |
1816 } | 1820 } |
1817 default: | 1821 default: |
1818 break; | 1822 break; |
1819 } | 1823 } |
1820 } | 1824 } |
OLD | NEW |