| 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 "../../../include/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
| 8 #include "../../../include/fpdfapi/fpdf_serial.h" | 8 #include "../../../include/fpdfapi/fpdf_serial.h" |
| 9 #include "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
| 10 #include "../fpdf_page/pageint.h" | 10 #include "../fpdf_page/pageint.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 matrix.TransformRect(bbox); | 113 matrix.TransformRect(bbox); |
| 114 pFormDict->SetAtRect("BBox", bbox); | 114 pFormDict->SetAtRect("BBox", bbox); |
| 115 pStream->InitStream((uint8_t*)data, size, pFormDict); | 115 pStream->InitStream((uint8_t*)data, size, pFormDict); |
| 116 buf << "q " << matrix << " cm "; | 116 buf << "q " << matrix << " cm "; |
| 117 CFX_ByteString name = RealizeResource(pStream, "XObject"); | 117 CFX_ByteString name = RealizeResource(pStream, "XObject"); |
| 118 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 118 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
| 119 } | 119 } |
| 120 void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) { | 120 void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) { |
| 121 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; | 121 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; |
| 122 CPDF_Object* pContent = pDict ? pDict->GetElementValue("Contents") : NULL; | 122 CPDF_Object* pContent = pDict ? pDict->GetElementValue("Contents") : NULL; |
| 123 if (!pContent) { | 123 if (!pContent) |
| 124 return; | 124 return; |
| 125 } | 125 |
| 126 CFX_ByteTextBuf buf; | 126 CFX_ByteTextBuf buf; |
| 127 int type = pContent->GetType(); | 127 if (CPDF_Array* pArray = pContent->AsArray()) { |
| 128 if (type == PDFOBJ_ARRAY) { | |
| 129 CPDF_Array* pArray = (CPDF_Array*)pContent; | |
| 130 int iCount = pArray->GetCount(); | 128 int iCount = pArray->GetCount(); |
| 131 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); | 129 CPDF_StreamAcc** pContentArray = FX_Alloc(CPDF_StreamAcc*, iCount); |
| 132 int size = 0; | 130 int size = 0; |
| 133 int i = 0; | 131 int i = 0; |
| 134 for (i = 0; i < iCount; ++i) { | 132 for (i = 0; i < iCount; ++i) { |
| 135 pContent = pArray->GetElement(i); | 133 pContent = pArray->GetElement(i); |
| 136 if (!pContent || pContent->GetType() != PDFOBJ_STREAM) { | 134 if (!pContent || pContent->GetType() != PDFOBJ_STREAM) { |
| 137 continue; | 135 continue; |
| 138 } | 136 } |
| 139 CPDF_StreamAcc* pStream = new CPDF_StreamAcc(); | 137 CPDF_StreamAcc* pStream = new CPDF_StreamAcc(); |
| 140 pStream->LoadAllData((CPDF_Stream*)pContent); | 138 pStream->LoadAllData((CPDF_Stream*)pContent); |
| 141 pContentArray[i] = pStream; | 139 pContentArray[i] = pStream; |
| 142 size += pContentArray[i]->GetSize() + 1; | 140 size += pContentArray[i]->GetSize() + 1; |
| 143 } | 141 } |
| 144 int pos = 0; | 142 int pos = 0; |
| 145 uint8_t* pBuf = FX_Alloc(uint8_t, size); | 143 uint8_t* pBuf = FX_Alloc(uint8_t, size); |
| 146 for (i = 0; i < iCount; ++i) { | 144 for (i = 0; i < iCount; ++i) { |
| 147 FXSYS_memcpy(pBuf + pos, pContentArray[i]->GetData(), | 145 FXSYS_memcpy(pBuf + pos, pContentArray[i]->GetData(), |
| 148 pContentArray[i]->GetSize()); | 146 pContentArray[i]->GetSize()); |
| 149 pos += pContentArray[i]->GetSize() + 1; | 147 pos += pContentArray[i]->GetSize() + 1; |
| 150 pBuf[pos - 1] = ' '; | 148 pBuf[pos - 1] = ' '; |
| 151 delete pContentArray[i]; | 149 delete pContentArray[i]; |
| 152 } | 150 } |
| 153 ProcessForm(buf, pBuf, size, matrix); | 151 ProcessForm(buf, pBuf, size, matrix); |
| 154 FX_Free(pBuf); | 152 FX_Free(pBuf); |
| 155 FX_Free(pContentArray); | 153 FX_Free(pContentArray); |
| 156 } else if (type == PDFOBJ_STREAM) { | 154 } else if (pContent->GetType() == PDFOBJ_STREAM) { |
| 157 CPDF_StreamAcc contentStream; | 155 CPDF_StreamAcc contentStream; |
| 158 contentStream.LoadAllData((CPDF_Stream*)pContent); | 156 contentStream.LoadAllData((CPDF_Stream*)pContent); |
| 159 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 157 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 160 } | 158 } |
| 161 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); | 159 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, NULL); |
| 162 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 160 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
| 163 m_pDocument->AddIndirectObject(pStream); | 161 m_pDocument->AddIndirectObject(pStream); |
| 164 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, | 162 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, |
| 165 pStream->GetObjNum()); | 163 pStream->GetObjNum()); |
| 166 } | 164 } |
| OLD | NEW |