| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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_edit/include/cpdf_pagecontentgenerator.h" | 7 #include "core/fpdfapi/fpdf_edit/include/cpdf_pagecontentgenerator.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" | 9 #include "core/fpdfapi/fpdf_edit/include/cpdf_creator.h" |
| 10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 CFX_ByteTextBuf buf; | 42 CFX_ByteTextBuf buf; |
| 43 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; | 43 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; |
| 44 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { | 44 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { |
| 45 CPDF_PageObject* pPageObj = m_pageObjects[i]; | 45 CPDF_PageObject* pPageObj = m_pageObjects[i]; |
| 46 if (!pPageObj || !pPageObj->IsImage()) { | 46 if (!pPageObj || !pPageObj->IsImage()) { |
| 47 continue; | 47 continue; |
| 48 } | 48 } |
| 49 ProcessImage(buf, pPageObj->AsImage()); | 49 ProcessImage(buf, pPageObj->AsImage()); |
| 50 } | 50 } |
| 51 CPDF_Object* pContent = | 51 CPDF_Object* pContent = |
| 52 pPageDict ? pPageDict->GetDirectObjectBy("Contents") : nullptr; | 52 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; |
| 53 if (pContent) { | 53 if (pContent) { |
| 54 pPageDict->RemoveAt("Contents"); | 54 pPageDict->RemoveFor("Contents"); |
| 55 } | 55 } |
| 56 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); | 56 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 57 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
| 58 m_pDocument->AddIndirectObject(pStream); | 58 m_pDocument->AddIndirectObject(pStream); |
| 59 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); | 59 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( | 62 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( |
| 63 CPDF_Object* pResourceObj, | 63 CPDF_Object* pResourceObj, |
| 64 const CFX_ByteString& bsType) { | 64 const CFX_ByteString& bsType) { |
| 65 if (!m_pPage->m_pResources) { | 65 if (!m_pPage->m_pResources) { |
| 66 m_pPage->m_pResources = new CPDF_Dictionary; | 66 m_pPage->m_pResources = new CPDF_Dictionary; |
| 67 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); | 67 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); |
| 68 m_pPage->m_pFormDict->SetAtReference("Resources", m_pDocument, objnum); | 68 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, objnum); |
| 69 } | 69 } |
| 70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictBy(bsType); | 70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); |
| 71 if (!pResList) { | 71 if (!pResList) { |
| 72 pResList = new CPDF_Dictionary; | 72 pResList = new CPDF_Dictionary; |
| 73 m_pPage->m_pResources->SetAt(bsType, pResList); | 73 m_pPage->m_pResources->SetFor(bsType, pResList); |
| 74 } | 74 } |
| 75 m_pDocument->AddIndirectObject(pResourceObj); | 75 m_pDocument->AddIndirectObject(pResourceObj); |
| 76 CFX_ByteString name; | 76 CFX_ByteString name; |
| 77 int idnum = 1; | 77 int idnum = 1; |
| 78 while (1) { | 78 while (1) { |
| 79 name.Format("FX%c%d", bsType[0], idnum); | 79 name.Format("FX%c%d", bsType[0], idnum); |
| 80 if (!pResList->KeyExist(name)) { | 80 if (!pResList->KeyExist(name)) { |
| 81 break; | 81 break; |
| 82 } | 82 } |
| 83 idnum++; | 83 idnum++; |
| 84 } | 84 } |
| 85 pResList->SetAtReference(name, m_pDocument, pResourceObj->GetObjNum()); | 85 pResList->SetReferenceFor(name, m_pDocument, pResourceObj->GetObjNum()); |
| 86 return name; | 86 return name; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, | 89 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, |
| 90 CPDF_ImageObject* pImageObj) { | 90 CPDF_ImageObject* pImageObj) { |
| 91 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || | 91 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || |
| 92 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { | 92 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 buf << "q " << pImageObj->m_Matrix << " cm "; | 95 buf << "q " << pImageObj->m_Matrix << " cm "; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 107 | 107 |
| 108 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, | 108 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, |
| 109 const uint8_t* data, | 109 const uint8_t* data, |
| 110 uint32_t size, | 110 uint32_t size, |
| 111 CFX_Matrix& matrix) { | 111 CFX_Matrix& matrix) { |
| 112 if (!data || !size) { | 112 if (!data || !size) { |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); | 115 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 116 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; | 116 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; |
| 117 pFormDict->SetAtName("Type", "XObject"); | 117 pFormDict->SetNameFor("Type", "XObject"); |
| 118 pFormDict->SetAtName("Subtype", "Form"); | 118 pFormDict->SetNameFor("Subtype", "Form"); |
| 119 CFX_FloatRect bbox = m_pPage->GetPageBBox(); | 119 CFX_FloatRect bbox = m_pPage->GetPageBBox(); |
| 120 matrix.TransformRect(bbox); | 120 matrix.TransformRect(bbox); |
| 121 pFormDict->SetAtRect("BBox", bbox); | 121 pFormDict->SetRectFor("BBox", bbox); |
| 122 pStream->InitStream(data, size, pFormDict); | 122 pStream->InitStream(data, size, pFormDict); |
| 123 buf << "q " << matrix << " cm "; | 123 buf << "q " << matrix << " cm "; |
| 124 CFX_ByteString name = RealizeResource(pStream, "XObject"); | 124 CFX_ByteString name = RealizeResource(pStream, "XObject"); |
| 125 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 125 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
| 126 } | 126 } |
| 127 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { | 127 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { |
| 128 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; | 128 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; |
| 129 CPDF_Object* pContent = | 129 CPDF_Object* pContent = |
| 130 pDict ? pDict->GetDirectObjectBy("Contents") : nullptr; | 130 pDict ? pDict->GetDirectObjectFor("Contents") : nullptr; |
| 131 if (!pContent) | 131 if (!pContent) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 CFX_ByteTextBuf buf; | 134 CFX_ByteTextBuf buf; |
| 135 if (CPDF_Array* pArray = pContent->AsArray()) { | 135 if (CPDF_Array* pArray = pContent->AsArray()) { |
| 136 size_t iCount = pArray->GetCount(); | 136 size_t iCount = pArray->GetCount(); |
| 137 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); | 137 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); |
| 138 size_t size = 0; | 138 size_t size = 0; |
| 139 for (size_t i = 0; i < iCount; ++i) { | 139 for (size_t i = 0; i < iCount; ++i) { |
| 140 pContent = pArray->GetObjectAt(i); | 140 pContent = pArray->GetObjectAt(i); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 160 FX_Free(pBuf); | 160 FX_Free(pBuf); |
| 161 FX_Free(pContentArray); | 161 FX_Free(pContentArray); |
| 162 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 162 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 163 CPDF_StreamAcc contentStream; | 163 CPDF_StreamAcc contentStream; |
| 164 contentStream.LoadAllData(pStream); | 164 contentStream.LoadAllData(pStream); |
| 165 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 165 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 166 } | 166 } |
| 167 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); | 167 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 168 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 168 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
| 169 m_pDocument->AddIndirectObject(pStream); | 169 m_pDocument->AddIndirectObject(pStream); |
| 170 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, | 170 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, |
| 171 pStream->GetObjNum()); | 171 pStream->GetObjNum()); |
| 172 } | 172 } |
| OLD | NEW |