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 29 matching lines...) Expand all Loading... |
40 CFX_ByteTextBuf buf; | 40 CFX_ByteTextBuf buf; |
41 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; | 41 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; |
42 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { | 42 for (int i = 0; i < m_pageObjects.GetSize(); ++i) { |
43 CPDF_PageObject* pPageObj = m_pageObjects[i]; | 43 CPDF_PageObject* pPageObj = m_pageObjects[i]; |
44 if (!pPageObj || !pPageObj->IsImage()) { | 44 if (!pPageObj || !pPageObj->IsImage()) { |
45 continue; | 45 continue; |
46 } | 46 } |
47 ProcessImage(buf, pPageObj->AsImage()); | 47 ProcessImage(buf, pPageObj->AsImage()); |
48 } | 48 } |
49 CPDF_Object* pContent = | 49 CPDF_Object* pContent = |
50 pPageDict ? pPageDict->GetDirectObjectBy("Contents") : NULL; | 50 pPageDict ? pPageDict->GetDirectObjectBy("Contents") : nullptr; |
51 if (pContent) { | 51 if (pContent) { |
52 pPageDict->RemoveAt("Contents"); | 52 pPageDict->RemoveAt("Contents"); |
53 } | 53 } |
54 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); | 54 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); |
55 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 55 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
56 m_pDocument->AddIndirectObject(pStream); | 56 m_pDocument->AddIndirectObject(pStream); |
57 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); | 57 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); |
58 } | 58 } |
59 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( | 59 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( |
60 CPDF_Object* pResourceObj, | 60 CPDF_Object* pResourceObj, |
61 const CFX_ByteString& bsType) { | 61 const CFX_ByteString& bsType) { |
62 if (!m_pPage->m_pResources) { | 62 if (!m_pPage->m_pResources) { |
63 m_pPage->m_pResources = new CPDF_Dictionary; | 63 m_pPage->m_pResources = new CPDF_Dictionary; |
64 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); | 64 int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 101 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
102 } | 102 } |
103 } | 103 } |
104 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, | 104 void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf, |
105 const uint8_t* data, | 105 const uint8_t* data, |
106 uint32_t size, | 106 uint32_t size, |
107 CFX_Matrix& matrix) { | 107 CFX_Matrix& matrix) { |
108 if (!data || !size) { | 108 if (!data || !size) { |
109 return; | 109 return; |
110 } | 110 } |
111 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); | 111 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); |
112 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; | 112 CPDF_Dictionary* pFormDict = new CPDF_Dictionary; |
113 pFormDict->SetAtName("Type", "XObject"); | 113 pFormDict->SetAtName("Type", "XObject"); |
114 pFormDict->SetAtName("Subtype", "Form"); | 114 pFormDict->SetAtName("Subtype", "Form"); |
115 CFX_FloatRect bbox = m_pPage->GetPageBBox(); | 115 CFX_FloatRect bbox = m_pPage->GetPageBBox(); |
116 matrix.TransformRect(bbox); | 116 matrix.TransformRect(bbox); |
117 pFormDict->SetAtRect("BBox", bbox); | 117 pFormDict->SetAtRect("BBox", bbox); |
118 pStream->InitStream((uint8_t*)data, size, pFormDict); | 118 pStream->InitStream((uint8_t*)data, size, pFormDict); |
119 buf << "q " << matrix << " cm "; | 119 buf << "q " << matrix << " cm "; |
120 CFX_ByteString name = RealizeResource(pStream, "XObject"); | 120 CFX_ByteString name = RealizeResource(pStream, "XObject"); |
121 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 121 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
122 } | 122 } |
123 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { | 123 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { |
124 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; | 124 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; |
125 CPDF_Object* pContent = pDict ? pDict->GetDirectObjectBy("Contents") : NULL; | 125 CPDF_Object* pContent = |
| 126 pDict ? pDict->GetDirectObjectBy("Contents") : nullptr; |
126 if (!pContent) | 127 if (!pContent) |
127 return; | 128 return; |
128 | 129 |
129 CFX_ByteTextBuf buf; | 130 CFX_ByteTextBuf buf; |
130 if (CPDF_Array* pArray = pContent->AsArray()) { | 131 if (CPDF_Array* pArray = pContent->AsArray()) { |
131 size_t iCount = pArray->GetCount(); | 132 size_t iCount = pArray->GetCount(); |
132 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); | 133 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); |
133 size_t size = 0; | 134 size_t size = 0; |
134 for (size_t i = 0; i < iCount; ++i) { | 135 for (size_t i = 0; i < iCount; ++i) { |
135 pContent = pArray->GetObjectAt(i); | 136 pContent = pArray->GetObjectAt(i); |
(...skipping 16 matching lines...) Expand all Loading... |
152 delete pContentArray[i]; | 153 delete pContentArray[i]; |
153 } | 154 } |
154 ProcessForm(buf, pBuf, size, matrix); | 155 ProcessForm(buf, pBuf, size, matrix); |
155 FX_Free(pBuf); | 156 FX_Free(pBuf); |
156 FX_Free(pContentArray); | 157 FX_Free(pContentArray); |
157 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 158 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
158 CPDF_StreamAcc contentStream; | 159 CPDF_StreamAcc contentStream; |
159 contentStream.LoadAllData(pStream); | 160 contentStream.LoadAllData(pStream); |
160 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 161 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
161 } | 162 } |
162 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); | 163 CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, nullptr); |
163 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 164 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
164 m_pDocument->AddIndirectObject(pStream); | 165 m_pDocument->AddIndirectObject(pStream); |
165 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, | 166 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, |
166 pStream->GetObjNum()); | 167 pStream->GetObjNum()); |
167 } | 168 } |
OLD | NEW |