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 "public/fpdf_save.h" | 7 #include "public/fpdf_save.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_serial.h" | 9 #include "core/include/fpdfapi/fpdf_serial.h" |
10 #include "fpdfsdk/include/fsdk_define.h" | 10 #include "fpdfsdk/include/fsdk_define.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); | 87 CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); |
88 if (pRoot == NULL) | 88 if (pRoot == NULL) |
89 return FALSE; | 89 return FALSE; |
90 CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); | 90 CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); |
91 if (NULL == pAcroForm) | 91 if (NULL == pAcroForm) |
92 return FALSE; | 92 return FALSE; |
93 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); | 93 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); |
94 if (pXFA == NULL) | 94 if (pXFA == NULL) |
95 return TRUE; | 95 return TRUE; |
96 if (pXFA->GetType() != PDFOBJ_ARRAY) | 96 if (!pXFA->IsArray()) |
97 return FALSE; | 97 return FALSE; |
98 CPDF_Array* pArray = pXFA->GetArray(); | 98 CPDF_Array* pArray = pXFA->GetArray(); |
99 if (NULL == pArray) | 99 if (NULL == pArray) |
100 return FALSE; | 100 return FALSE; |
101 int size = pArray->GetCount(); | 101 int size = pArray->GetCount(); |
102 int iFormIndex = -1; | 102 int iFormIndex = -1; |
103 int iDataSetsIndex = -1; | 103 int iDataSetsIndex = -1; |
104 int iTemplate = -1; | 104 int iTemplate = -1; |
105 int iLast = size - 2; | 105 int iLast = size - 2; |
106 for (int i = 0; i < size - 1; i++) { | 106 for (int i = 0; i < size - 1; i++) { |
107 CPDF_Object* pPDFObj = pArray->GetElement(i); | 107 CPDF_Object* pPDFObj = pArray->GetElement(i); |
108 if (pPDFObj->GetType() != PDFOBJ_STRING) | 108 if (!pPDFObj->IsString()) |
109 continue; | 109 continue; |
110 if (pPDFObj->GetString() == "form") | 110 if (pPDFObj->GetString() == "form") |
111 iFormIndex = i + 1; | 111 iFormIndex = i + 1; |
112 else if (pPDFObj->GetString() == "datasets") | 112 else if (pPDFObj->GetString() == "datasets") |
113 iDataSetsIndex = i + 1; | 113 iDataSetsIndex = i + 1; |
114 else if (pPDFObj->GetString() == "template") | 114 else if (pPDFObj->GetString() == "template") |
115 iTemplate = i + 1; | 115 iTemplate = i + 1; |
116 } | 116 } |
117 IXFA_ChecksumContext* pContext = NULL; | 117 IXFA_ChecksumContext* pContext = NULL; |
118 // Checksum | 118 // Checksum |
(...skipping 10 matching lines...) Expand all Loading... |
129 FX_DWORD dwSize2 = streamAcc.GetSize(); | 129 FX_DWORD dwSize2 = streamAcc.GetSize(); |
130 IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); | 130 IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); |
131 pContext->UpdateChecksum((IFX_FileRead*)pTemplate); | 131 pContext->UpdateChecksum((IFX_FileRead*)pTemplate); |
132 pTemplate->Release(); | 132 pTemplate->Release(); |
133 } | 133 } |
134 CPDF_Stream* pFormStream = NULL; | 134 CPDF_Stream* pFormStream = NULL; |
135 CPDF_Stream* pDataSetsStream = NULL; | 135 CPDF_Stream* pDataSetsStream = NULL; |
136 if (iFormIndex != -1) { | 136 if (iFormIndex != -1) { |
137 // Get form CPDF_Stream | 137 // Get form CPDF_Stream |
138 CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); | 138 CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); |
139 if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE) { | 139 if (pFormPDFObj->IsReference()) { |
140 CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect(); | 140 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); |
141 if (NULL != pFormDircetObj && | 141 if (pFormDirectObj && pFormDirectObj->IsStream()) { |
142 pFormDircetObj->GetType() == PDFOBJ_STREAM) { | 142 pFormStream = (CPDF_Stream*)pFormDirectObj; |
143 pFormStream = (CPDF_Stream*)pFormDircetObj; | |
144 } | 143 } |
145 } else if (pFormPDFObj->GetType() == PDFOBJ_STREAM) { | 144 } else if (pFormPDFObj->IsStream()) { |
146 pFormStream = (CPDF_Stream*)pFormPDFObj; | 145 pFormStream = (CPDF_Stream*)pFormPDFObj; |
147 } | 146 } |
148 } | 147 } |
149 | 148 |
150 if (iDataSetsIndex != -1) { | 149 if (iDataSetsIndex != -1) { |
151 // Get datasets CPDF_Stream | 150 // Get datasets CPDF_Stream |
152 CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex); | 151 CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex); |
153 if (pDataSetsPDFObj->GetType() == PDFOBJ_REFERENCE) { | 152 if (pDataSetsPDFObj->IsReference()) { |
154 CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; | 153 CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; |
155 CPDF_Object* pDataSetsDircetObj = pDataSetsRefObj->GetDirect(); | 154 CPDF_Object* pDataSetsDirectObj = pDataSetsRefObj->GetDirect(); |
156 if (NULL != pDataSetsDircetObj && | 155 if (pDataSetsDirectObj && pDataSetsDirectObj->IsStream()) { |
157 pDataSetsDircetObj->GetType() == PDFOBJ_STREAM) { | 156 pDataSetsStream = (CPDF_Stream*)pDataSetsDirectObj; |
158 pDataSetsStream = (CPDF_Stream*)pDataSetsDircetObj; | |
159 } | 157 } |
160 } else if (pDataSetsPDFObj->GetType() == PDFOBJ_STREAM) { | 158 } else if (pDataSetsPDFObj->IsStream()) { |
161 pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; | 159 pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; |
162 } | 160 } |
163 } | 161 } |
164 // end | 162 // end |
165 // L"datasets" | 163 // L"datasets" |
166 { | 164 { |
167 IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); | 165 IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); |
168 if (NULL == pDsfileWrite) { | 166 if (NULL == pDsfileWrite) { |
169 pContext->Release(); | 167 pContext->Release(); |
170 pDsfileWrite->Release(); | 168 pDsfileWrite->Release(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 FPDF_DWORD flags) { | 324 FPDF_DWORD flags) { |
327 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); | 325 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
328 } | 326 } |
329 | 327 |
330 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 328 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
331 FPDF_FILEWRITE* pFileWrite, | 329 FPDF_FILEWRITE* pFileWrite, |
332 FPDF_DWORD flags, | 330 FPDF_DWORD flags, |
333 int fileVersion) { | 331 int fileVersion) { |
334 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); | 332 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
335 } | 333 } |
OLD | NEW |