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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->SetReferenceFor("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(m_pDocument); |
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->SetReferenceFor("Resources", m_pDocument, objnum); | 68 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, objnum); |
69 } | 69 } |
70 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(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(m_pDocument); |
73 m_pPage->m_pResources->SetFor(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 } |
(...skipping 23 matching lines...) Expand all Loading... |
106 } | 106 } |
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(m_pDocument); |
117 pFormDict->SetNameFor("Type", "XObject"); | 117 pFormDict->SetNameFor("Type", "XObject"); |
118 pFormDict->SetNameFor("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->SetRectFor("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 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->SetReferenceFor("Contents", m_pDocument, | 170 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, |
171 pStream->GetObjNum()); | 171 pStream->GetObjNum()); |
172 } | 172 } |
OLD | NEW |