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 "../../../include/fxcodec/fx_codec.h" | 10 #include "../../../include/fxcodec/fx_codec.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 { | 41 { |
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 = (CPDF_PageObject*)m_pageObjects[i]; | 45 CPDF_PageObject* pPageObj = (CPDF_PageObject*)m_pageObjects[i]; |
46 if (!pPageObj || pPageObj->m_Type != PDFPAGE_IMAGE) { | 46 if (!pPageObj || pPageObj->m_Type != PDFPAGE_IMAGE) { |
47 continue; | 47 continue; |
48 } | 48 } |
49 ProcessImage(buf, (CPDF_ImageObject*)pPageObj); | 49 ProcessImage(buf, (CPDF_ImageObject*)pPageObj); |
50 } | 50 } |
51 CPDF_Object* pContent = pPageDict->GetElementValue("Contents"); | 51 CPDF_Object* pContent = pPageDict ? pPageDict->GetElementValue("Contents") :
NULL; |
52 if (pContent != NULL) { | 52 if (pContent != NULL) { |
53 pPageDict->RemoveAt("Contents"); | 53 pPageDict->RemoveAt("Contents"); |
54 } | 54 } |
55 CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); | 55 CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); |
56 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 56 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
57 m_pDocument->AddIndirectObject(pStream); | 57 m_pDocument->AddIndirectObject(pStream); |
58 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); | 58 pPageDict->SetAtReference("Contents", m_pDocument, pStream->GetObjNum()); |
59 } | 59 } |
60 CFX_ByteString CPDF_PageContentGenerate::RealizeResource(CPDF_Object* pResourceO
bj, const FX_CHAR* szType) | 60 CFX_ByteString CPDF_PageContentGenerate::RealizeResource(CPDF_Object* pResourceO
bj, const FX_CHAR* szType) |
61 { | 61 { |
(...skipping 25 matching lines...) Expand all Loading... |
87 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || | 87 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || |
88 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { | 88 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { |
89 return; | 89 return; |
90 } | 90 } |
91 buf << "q " << pImageObj->m_Matrix << " cm "; | 91 buf << "q " << pImageObj->m_Matrix << " cm "; |
92 if (!pImageObj->m_pImage->IsInline()) { | 92 if (!pImageObj->m_pImage->IsInline()) { |
93 CPDF_Stream* pStream = pImageObj->m_pImage->GetStream(); | 93 CPDF_Stream* pStream = pImageObj->m_pImage->GetStream(); |
94 FX_DWORD dwSavedObjNum = pStream->GetObjNum(); | 94 FX_DWORD dwSavedObjNum = pStream->GetObjNum(); |
95 CFX_ByteString name = RealizeResource(pStream, "XObject"); | 95 CFX_ByteString name = RealizeResource(pStream, "XObject"); |
96 if (dwSavedObjNum == 0) { | 96 if (dwSavedObjNum == 0) { |
97 pImageObj->m_pImage->Release(); | 97 if (pImageObj->m_pImage) |
| 98 pImageObj->m_pImage->Release(); |
98 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream); | 99 pImageObj->m_pImage = m_pDocument->GetPageData()->GetImage(pStream); |
99 } | 100 } |
100 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 101 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
101 } | 102 } |
102 } | 103 } |
103 void CPDF_PageContentGenerate::ProcessForm(CFX_ByteTextBuf& buf, FX_LPCBYTE data
, FX_DWORD size, CFX_Matrix& matrix) | 104 void CPDF_PageContentGenerate::ProcessForm(CFX_ByteTextBuf& buf, FX_LPCBYTE data
, FX_DWORD size, CFX_Matrix& matrix) |
104 { | 105 { |
105 if (!data || !size) { | 106 if (!data || !size) { |
106 return; | 107 return; |
107 } | 108 } |
108 CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); | 109 CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); |
109 CPDF_Dictionary* pFormDict = CPDF_Dictionary::Create(); | 110 CPDF_Dictionary* pFormDict = CPDF_Dictionary::Create(); |
110 pFormDict->SetAtName(FX_BSTR("Type"), FX_BSTR("XObject")); | 111 pFormDict->SetAtName(FX_BSTR("Type"), FX_BSTR("XObject")); |
111 pFormDict->SetAtName(FX_BSTR("Subtype"), FX_BSTR("Form")); | 112 pFormDict->SetAtName(FX_BSTR("Subtype"), FX_BSTR("Form")); |
112 CFX_FloatRect bbox = m_pPage->GetPageBBox(); | 113 CFX_FloatRect bbox = m_pPage->GetPageBBox(); |
113 matrix.TransformRect(bbox); | 114 matrix.TransformRect(bbox); |
114 pFormDict->SetAtRect(FX_BSTR("BBox"), bbox); | 115 pFormDict->SetAtRect(FX_BSTR("BBox"), bbox); |
115 pStream->InitStream((FX_LPBYTE)data, size, pFormDict); | 116 pStream->InitStream((FX_LPBYTE)data, size, pFormDict); |
116 buf << "q " << matrix << " cm "; | 117 buf << "q " << matrix << " cm "; |
117 CFX_ByteString name = RealizeResource(pStream, "XObject"); | 118 CFX_ByteString name = RealizeResource(pStream, "XObject"); |
118 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 119 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
119 } | 120 } |
120 void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) | 121 void CPDF_PageContentGenerate::TransformContent(CFX_Matrix& matrix) |
121 { | 122 { |
122 CPDF_Object* pContent = m_pPage->m_pFormDict->GetElementValue("Contents"); | 123 CPDF_Dictionary* pDict = m_pPage->m_pFormDict; |
| 124 CPDF_Object* pContent = pDict ? pDict->GetElementValue("Contents") : NULL; |
123 if (!pContent) { | 125 if (!pContent) { |
124 return; | 126 return; |
125 } | 127 } |
126 CFX_ByteTextBuf buf; | 128 CFX_ByteTextBuf buf; |
127 int type = pContent->GetType(); | 129 int type = pContent->GetType(); |
128 if (type == PDFOBJ_ARRAY) { | 130 if (type == PDFOBJ_ARRAY) { |
129 CPDF_Array* pArray = (CPDF_Array*)pContent; | 131 CPDF_Array* pArray = (CPDF_Array*)pContent; |
130 int iCount = pArray->GetCount(); | 132 int iCount = pArray->GetCount(); |
131 CPDF_StreamAcc** pContentArray = (CPDF_StreamAcc**)FX_Alloc(CPDF_StreamA
cc*, iCount); | 133 CPDF_StreamAcc** pContentArray = (CPDF_StreamAcc**)FX_Alloc(CPDF_StreamA
cc*, iCount); |
132 int size = 0; | 134 int size = 0; |
(...skipping 22 matching lines...) Expand all Loading... |
155 } else if (type == PDFOBJ_STREAM) { | 157 } else if (type == PDFOBJ_STREAM) { |
156 CPDF_StreamAcc contentStream; | 158 CPDF_StreamAcc contentStream; |
157 contentStream.LoadAllData((CPDF_Stream*)pContent); | 159 contentStream.LoadAllData((CPDF_Stream*)pContent); |
158 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matri
x); | 160 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matri
x); |
159 } | 161 } |
160 CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); | 162 CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); |
161 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); | 163 pStream->SetData(buf.GetBuffer(), buf.GetLength(), FALSE, FALSE); |
162 m_pDocument->AddIndirectObject(pStream); | 164 m_pDocument->AddIndirectObject(pStream); |
163 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, pStream->GetOb
jNum()); | 165 m_pPage->m_pFormDict->SetAtReference("Contents", m_pDocument, pStream->GetOb
jNum()); |
164 } | 166 } |
OLD | NEW |