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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 122 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
123 } | 123 } |
124 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { | 124 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { |
125 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; | 125 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; |
126 CPDF_Object* pContent = pDict ? pDict->GetDirectObjectBy("Contents") : NULL; | 126 CPDF_Object* pContent = pDict ? pDict->GetDirectObjectBy("Contents") : NULL; |
127 if (!pContent) | 127 if (!pContent) |
128 return; | 128 return; |
129 | 129 |
130 CFX_ByteTextBuf buf; | 130 CFX_ByteTextBuf buf; |
131 if (CPDF_Array* pArray = pContent->AsArray()) { | 131 if (CPDF_Array* pArray = pContent->AsArray()) { |
132 int iCount = pArray->GetCount(); | 132 size_t iCount = pArray->GetCount(); |
133 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); | 133 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); |
134 int size = 0; | 134 size_t size = 0; |
135 int i = 0; | 135 for (size_t i = 0; i < iCount; ++i) { |
136 for (i = 0; i < iCount; ++i) { | |
137 pContent = pArray->GetObjectAt(i); | 136 pContent = pArray->GetObjectAt(i); |
138 CPDF_Stream* pStream = ToStream(pContent); | 137 CPDF_Stream* pStream = ToStream(pContent); |
139 if (!pStream) | 138 if (!pStream) |
140 continue; | 139 continue; |
141 | 140 |
142 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc(); | 141 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc(); |
143 pStreamAcc->LoadAllData(pStream); | 142 pStreamAcc->LoadAllData(pStream); |
144 pContentArray[i] = pStreamAcc; | 143 pContentArray[i] = pStreamAcc; |
145 size += pContentArray[i]->GetSize() + 1; | 144 size += pContentArray[i]->GetSize() + 1; |
146 } | 145 } |
147 int pos = 0; | 146 int pos = 0; |
148 uint8_t* pBuf = FX_Alloc(uint8_t, size); | 147 uint8_t* pBuf = FX_Alloc(uint8_t, size); |
149 for (i = 0; i < iCount; ++i) { | 148 for (size_t i = 0; i < iCount; ++i) { |
150 FXSYS_memcpy(pBuf + pos, pContentArray[i]->GetData(), | 149 FXSYS_memcpy(pBuf + pos, pContentArray[i]->GetData(), |
151 pContentArray[i]->GetSize()); | 150 pContentArray[i]->GetSize()); |
152 pos += pContentArray[i]->GetSize() + 1; | 151 pos += pContentArray[i]->GetSize() + 1; |
153 pBuf[pos - 1] = ' '; | 152 pBuf[pos - 1] = ' '; |
154 delete pContentArray[i]; | 153 delete pContentArray[i]; |
155 } | 154 } |
156 ProcessForm(buf, pBuf, size, matrix); | 155 ProcessForm(buf, pBuf, size, matrix); |
157 FX_Free(pBuf); | 156 FX_Free(pBuf); |
158 FX_Free(pContentArray); | 157 FX_Free(pContentArray); |
159 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 158 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
160 CPDF_StreamAcc contentStream; | 159 CPDF_StreamAcc contentStream; |
161 contentStream.LoadAllData(pStream); | 160 contentStream.LoadAllData(pStream); |
162 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 161 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
163 } | 162 } |
164 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); | 163 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); |
165 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 164 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
166 m_pDocument->AddIndirectObject(pStream); | 165 m_pDocument->AddIndirectObject(pStream); |
167 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, | 166 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, |
168 pStream->GetObjNum()); | 167 pStream->GetObjNum()); |
169 } | 168 } |
OLD | NEW |