Chromium Code Reviews| 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 "xfa/fxfa/include/xfa_ffdoc.h" | 7 #include "xfa/fxfa/include/xfa_ffdoc.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 13 #include "core/fpdfdoc/include/fpdf_doc.h" | 13 #include "core/fpdfdoc/include/fpdf_doc.h" |
| 14 #include "core/fxcrt/include/fx_ext.h" | 14 #include "core/fxcrt/include/fx_ext.h" |
| 15 #include "core/fxcrt/include/fx_memory.h" | 15 #include "core/fxcrt/include/fx_memory.h" |
| 16 #include "xfa/fde/xml/fde_xml_imp.h" | 16 #include "xfa/fde/xml/fde_xml_imp.h" |
| 17 #include "xfa/fgas/crt/fgas_algorithm.h" | |
| 18 #include "xfa/fwl/core/fwl_noteimp.h" | 17 #include "xfa/fwl/core/fwl_noteimp.h" |
| 19 #include "xfa/fxfa/app/xfa_ffnotify.h" | 18 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 20 #include "xfa/fxfa/include/xfa_checksum.h" | 19 #include "xfa/fxfa/include/xfa_checksum.h" |
| 21 #include "xfa/fxfa/include/xfa_ffapp.h" | 20 #include "xfa/fxfa/include/xfa_ffapp.h" |
| 22 #include "xfa/fxfa/include/xfa_ffdocview.h" | 21 #include "xfa/fxfa/include/xfa_ffdocview.h" |
| 23 #include "xfa/fxfa/include/xfa_ffwidget.h" | 22 #include "xfa/fxfa/include/xfa_ffwidget.h" |
| 24 #include "xfa/fxfa/include/xfa_fontmgr.h" | 23 #include "xfa/fxfa/include/xfa_fontmgr.h" |
| 25 #include "xfa/fxfa/parser/xfa_document.h" | 24 #include "xfa/fxfa/parser/xfa_document.h" |
| 26 #include "xfa/fxfa/parser/xfa_document_serialize.h" | 25 #include "xfa/fxfa/parser/xfa_document_serialize.h" |
| 27 #include "xfa/fxfa/parser/xfa_parser.h" | 26 #include "xfa/fxfa/parser/xfa_parser.h" |
| 28 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 27 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
| 29 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 28 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
| 30 | 29 |
| 30 namespace { | |
| 31 | |
| 32 struct FX_BASE64DATA { | |
| 33 uint32_t data1 : 2; | |
| 34 uint32_t data2 : 6; | |
| 35 uint32_t data3 : 4; | |
| 36 uint32_t data4 : 4; | |
| 37 uint32_t data5 : 6; | |
| 38 uint32_t data6 : 2; | |
| 39 uint32_t data7 : 8; | |
| 40 }; | |
| 41 | |
| 42 const uint8_t kStartValuesRemoved = 43; | |
| 43 const uint8_t kDecoderMapSize = 80; | |
| 44 const uint8_t g_FXBase64DecoderMap[kDecoderMapSize] = { | |
| 45 0x3E, 0xFF, 0xFF, 0xFF, 0x3F, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, | |
| 46 0x3B, 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, | |
| 47 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, | |
| 48 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, | |
| 49 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, | |
| 50 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, | |
| 51 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, | |
| 52 }; | |
| 53 | |
| 54 uint8_t base64DecoderValue(uint8_t val) { | |
|
Tom Sepez
2016/05/19 21:23:42
The numbers look right, alternatively you might wa
dsinclair
2016/05/20 01:06:31
I think it's going to be strange either way. I thi
| |
| 55 if (val < kStartValuesRemoved || val >= kStartValuesRemoved + kDecoderMapSize) | |
| 56 return 0xFF; | |
| 57 return g_FXBase64DecoderMap[val - kStartValuesRemoved]; | |
| 58 } | |
| 59 | |
| 60 void Base64DecodePiece(const FX_CHAR src[4], | |
| 61 int32_t iChars, | |
| 62 FX_BASE64DATA& dst, | |
| 63 int32_t& iBytes) { | |
| 64 ASSERT(iChars > 0 && iChars < 5); | |
| 65 iBytes = 1; | |
| 66 dst.data2 = base64DecoderValue(static_cast<uint8_t>(src[0])); | |
| 67 if (iChars > 1) { | |
| 68 uint8_t b = base64DecoderValue(static_cast<uint8_t>(src[1])); | |
| 69 dst.data1 = b >> 4; | |
| 70 dst.data4 = b; | |
| 71 if (iChars > 2) { | |
| 72 iBytes = 2; | |
| 73 b = base64DecoderValue(static_cast<uint8_t>(src[2])); | |
| 74 dst.data3 = b >> 2; | |
| 75 dst.data6 = b; | |
| 76 if (iChars > 3) { | |
| 77 iBytes = 3; | |
| 78 dst.data5 = base64DecoderValue(static_cast<uint8_t>(src[3])); | |
| 79 } else { | |
| 80 dst.data5 = 0; | |
| 81 } | |
| 82 } else { | |
| 83 dst.data3 = 0; | |
| 84 } | |
| 85 } else { | |
| 86 dst.data1 = 0; | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 int32_t Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) { | |
| 91 ASSERT(pSrc); | |
| 92 if (iSrcLen < 1) { | |
| 93 return 0; | |
| 94 } | |
| 95 while (iSrcLen > 0 && pSrc[iSrcLen - 1] == '=') { | |
| 96 iSrcLen--; | |
| 97 } | |
| 98 if (iSrcLen < 1) { | |
| 99 return 0; | |
| 100 } | |
| 101 if (!pDst) { | |
| 102 int32_t iDstLen = iSrcLen / 4 * 3; | |
| 103 iSrcLen %= 4; | |
| 104 if (iSrcLen == 1) { | |
| 105 iDstLen += 1; | |
| 106 } else if (iSrcLen == 2) { | |
| 107 iDstLen += 1; | |
| 108 } else if (iSrcLen == 3) { | |
| 109 iDstLen += 2; | |
| 110 } | |
| 111 return iDstLen; | |
| 112 } | |
| 113 FX_CHAR srcData[4]; | |
| 114 FX_BASE64DATA dstData; | |
| 115 int32_t iChars = 4, iBytes; | |
| 116 uint8_t* pDstEnd = pDst; | |
| 117 while (iSrcLen > 0) { | |
| 118 if (iSrcLen > 3) { | |
| 119 srcData[0] = (FX_CHAR)*pSrc++; | |
| 120 srcData[1] = (FX_CHAR)*pSrc++; | |
| 121 srcData[2] = (FX_CHAR)*pSrc++; | |
| 122 srcData[3] = (FX_CHAR)*pSrc++; | |
| 123 iSrcLen -= 4; | |
| 124 } else { | |
| 125 *((uint32_t*)&dstData) = 0; | |
| 126 *((uint32_t*)srcData) = 0; | |
| 127 srcData[0] = (FX_CHAR)*pSrc++; | |
| 128 if (iSrcLen > 1) { | |
| 129 srcData[1] = (FX_CHAR)*pSrc++; | |
| 130 } | |
| 131 if (iSrcLen > 2) { | |
| 132 srcData[2] = (FX_CHAR)*pSrc++; | |
| 133 } | |
| 134 iChars = iSrcLen; | |
| 135 iSrcLen = 0; | |
| 136 } | |
| 137 Base64DecodePiece(srcData, iChars, dstData, iBytes); | |
| 138 *pDstEnd++ = ((uint8_t*)&dstData)[0]; | |
| 139 if (iBytes > 1) { | |
| 140 *pDstEnd++ = ((uint8_t*)&dstData)[1]; | |
| 141 } | |
| 142 if (iBytes > 2) { | |
| 143 *pDstEnd++ = ((uint8_t*)&dstData)[2]; | |
| 144 } | |
| 145 } | |
| 146 return pDstEnd - pDst; | |
| 147 } | |
| 148 | |
| 149 } // namespace | |
| 150 | |
| 31 CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocProvider* pDocProvider) | 151 CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocProvider* pDocProvider) |
| 32 : m_pDocProvider(pDocProvider), | 152 : m_pDocProvider(pDocProvider), |
| 33 m_pDocument(nullptr), | 153 m_pDocument(nullptr), |
| 34 m_pStream(nullptr), | 154 m_pStream(nullptr), |
| 35 m_pApp(pApp), | 155 m_pApp(pApp), |
| 36 m_pNotify(nullptr), | 156 m_pNotify(nullptr), |
| 37 m_pPDFDoc(nullptr), | 157 m_pPDFDoc(nullptr), |
| 38 m_dwDocType(XFA_DOCTYPE_Static), | 158 m_dwDocType(XFA_DOCTYPE_Static), |
| 39 m_bOwnStream(TRUE) {} | 159 m_bOwnStream(TRUE) {} |
| 40 CXFA_FFDoc::~CXFA_FFDoc() { | 160 CXFA_FFDoc::~CXFA_FFDoc() { |
| 41 CloseDoc(); | 161 CloseDoc(); |
| 42 } | 162 } |
| 43 uint32_t CXFA_FFDoc::GetDocType() { | 163 uint32_t CXFA_FFDoc::GetDocType() { |
| 44 return m_dwDocType; | 164 return m_dwDocType; |
| 45 } | 165 } |
| 46 int32_t CXFA_FFDoc::StartLoad() { | 166 int32_t CXFA_FFDoc::StartLoad() { |
| 47 m_pNotify = new CXFA_FFNotify(this); | 167 m_pNotify = new CXFA_FFNotify(this); |
| 48 CXFA_DocumentParser* pDocParser = new CXFA_DocumentParser(m_pNotify); | 168 CXFA_DocumentParser* pDocParser = new CXFA_DocumentParser(m_pNotify); |
| 49 int32_t iStatus = pDocParser->StartParse(m_pStream); | 169 int32_t iStatus = pDocParser->StartParse(m_pStream); |
| 50 m_pDocument = pDocParser->GetDocument(); | 170 m_pDocument = pDocParser->GetDocument(); |
| 51 return iStatus; | 171 return iStatus; |
| 52 } | 172 } |
| 53 FX_BOOL XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, | 173 FX_BOOL XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, |
| 54 uint8_t*& pByteBuffer, | 174 uint8_t*& pByteBuffer, |
| 55 int32_t& iBufferSize) { | 175 int32_t& iBufferSize) { |
| 56 CFDE_XMLElement* pDocumentElement = NULL; | 176 CFDE_XMLElement* pDocumentElement = nullptr; |
| 57 for (CFDE_XMLNode* pXMLNode = | 177 for (CFDE_XMLNode* pXMLNode = |
| 58 pPDFElement->GetNodeItem(CFDE_XMLNode::FirstChild); | 178 pPDFElement->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 59 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 179 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 60 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | 180 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 61 CFX_WideString wsTagName; | 181 CFX_WideString wsTagName; |
| 62 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); | 182 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 63 pXMLElement->GetTagName(wsTagName); | 183 pXMLElement->GetTagName(wsTagName); |
| 64 if (wsTagName == FX_WSTRC(L"document")) { | 184 if (wsTagName == FX_WSTRC(L"document")) { |
| 65 pDocumentElement = pXMLElement; | 185 pDocumentElement = pXMLElement; |
| 66 break; | 186 break; |
| 67 } | 187 } |
| 68 } | 188 } |
| 69 } | 189 } |
| 70 if (!pDocumentElement) { | 190 if (!pDocumentElement) { |
| 71 return FALSE; | 191 return FALSE; |
| 72 } | 192 } |
| 73 CFDE_XMLElement* pChunkElement = NULL; | 193 CFDE_XMLElement* pChunkElement = nullptr; |
| 74 for (CFDE_XMLNode* pXMLNode = | 194 for (CFDE_XMLNode* pXMLNode = |
| 75 pDocumentElement->GetNodeItem(CFDE_XMLNode::FirstChild); | 195 pDocumentElement->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 76 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 196 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 77 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | 197 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 78 CFX_WideString wsTagName; | 198 CFX_WideString wsTagName; |
| 79 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); | 199 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 80 pXMLElement->GetTagName(wsTagName); | 200 pXMLElement->GetTagName(wsTagName); |
| 81 if (wsTagName == FX_WSTRC(L"chunk")) { | 201 if (wsTagName == FX_WSTRC(L"chunk")) { |
| 82 pChunkElement = pXMLElement; | 202 pChunkElement = pXMLElement; |
| 83 break; | 203 break; |
| 84 } | 204 } |
| 85 } | 205 } |
| 86 } | 206 } |
| 87 if (!pChunkElement) { | 207 if (!pChunkElement) { |
| 88 return FALSE; | 208 return FALSE; |
| 89 } | 209 } |
| 90 CFX_WideString wsPDFContent; | 210 CFX_WideString wsPDFContent; |
| 91 pChunkElement->GetTextData(wsPDFContent); | 211 pChunkElement->GetTextData(wsPDFContent); |
| 92 iBufferSize = | 212 iBufferSize = |
| 93 FX_Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), NULL); | 213 Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), nullptr); |
| 94 pByteBuffer = FX_Alloc(uint8_t, iBufferSize + 1); | 214 pByteBuffer = FX_Alloc(uint8_t, iBufferSize + 1); |
| 95 pByteBuffer[iBufferSize] = '0'; // FIXME: I bet this is wrong. | 215 pByteBuffer[iBufferSize] = '0'; // FIXME: I bet this is wrong. |
| 96 FX_Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), pByteBuffer); | 216 Base64DecodeW(wsPDFContent.c_str(), wsPDFContent.GetLength(), pByteBuffer); |
| 97 return TRUE; | 217 return TRUE; |
| 98 } | 218 } |
| 99 void XFA_XPDPacket_MergeRootNode(CXFA_Node* pOriginRoot, CXFA_Node* pNewRoot) { | 219 void XFA_XPDPacket_MergeRootNode(CXFA_Node* pOriginRoot, CXFA_Node* pNewRoot) { |
| 100 CXFA_Node* pChildNode = pNewRoot->GetNodeItem(XFA_NODEITEM_FirstChild); | 220 CXFA_Node* pChildNode = pNewRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 101 while (pChildNode) { | 221 while (pChildNode) { |
| 102 CXFA_Node* pOriginChild = | 222 CXFA_Node* pOriginChild = |
| 103 pOriginRoot->GetFirstChildByName(pChildNode->GetNameHash()); | 223 pOriginRoot->GetFirstChildByName(pChildNode->GetNameHash()); |
| 104 if (pOriginChild) { | 224 if (pOriginChild) { |
| 105 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); | 225 pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 106 } else { | 226 } else { |
| 107 CXFA_Node* pNextSibling = | 227 CXFA_Node* pNextSibling = |
| 108 pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); | 228 pChildNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 109 pNewRoot->RemoveChild(pChildNode); | 229 pNewRoot->RemoveChild(pChildNode); |
| 110 pOriginRoot->InsertChild(pChildNode); | 230 pOriginRoot->InsertChild(pChildNode); |
| 111 pChildNode = pNextSibling; | 231 pChildNode = pNextSibling; |
| 112 pNextSibling = NULL; | 232 pNextSibling = nullptr; |
| 113 } | 233 } |
| 114 } | 234 } |
| 115 } | 235 } |
| 116 int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { | 236 int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { |
| 117 int32_t iStatus = m_pDocument->GetParser()->DoParse(pPause); | 237 int32_t iStatus = m_pDocument->GetParser()->DoParse(pPause); |
| 118 if (iStatus == XFA_PARSESTATUS_Done && !m_pPDFDoc) { | 238 if (iStatus == XFA_PARSESTATUS_Done && !m_pPDFDoc) { |
| 119 CXFA_Node* pPDFNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Pdf)); | 239 CXFA_Node* pPDFNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Pdf)); |
| 120 if (!pPDFNode) { | 240 if (!pPDFNode) { |
| 121 return XFA_PARSESTATUS_SyntaxErr; | 241 return XFA_PARSESTATUS_SyntaxErr; |
| 122 } | 242 } |
| 123 CFDE_XMLNode* pPDFXML = pPDFNode->GetXMLMappingNode(); | 243 CFDE_XMLNode* pPDFXML = pPDFNode->GetXMLMappingNode(); |
| 124 if (pPDFXML->GetType() != FDE_XMLNODE_Element) { | 244 if (pPDFXML->GetType() != FDE_XMLNODE_Element) { |
| 125 return XFA_PARSESTATUS_SyntaxErr; | 245 return XFA_PARSESTATUS_SyntaxErr; |
| 126 } | 246 } |
| 127 int32_t iBufferSize = 0; | 247 int32_t iBufferSize = 0; |
| 128 uint8_t* pByteBuffer = NULL; | 248 uint8_t* pByteBuffer = nullptr; |
| 129 IFX_FileRead* pXFAReader = NULL; | 249 IFX_FileRead* pXFAReader = nullptr; |
| 130 if (XFA_GetPDFContentsFromPDFXML(pPDFXML, pByteBuffer, iBufferSize)) { | 250 if (XFA_GetPDFContentsFromPDFXML(pPDFXML, pByteBuffer, iBufferSize)) { |
| 131 pXFAReader = FX_CreateMemoryStream(pByteBuffer, iBufferSize, TRUE); | 251 pXFAReader = FX_CreateMemoryStream(pByteBuffer, iBufferSize, TRUE); |
| 132 } else { | 252 } else { |
| 133 CFX_WideString wsHref; | 253 CFX_WideString wsHref; |
| 134 static_cast<CFDE_XMLElement*>(pPDFXML)->GetString(L"href", wsHref); | 254 static_cast<CFDE_XMLElement*>(pPDFXML)->GetString(L"href", wsHref); |
| 135 if (!wsHref.IsEmpty()) { | 255 if (!wsHref.IsEmpty()) { |
| 136 pXFAReader = GetDocProvider()->OpenLinkedFile(this, wsHref); | 256 pXFAReader = GetDocProvider()->OpenLinkedFile(this, wsHref); |
| 137 } | 257 } |
| 138 } | 258 } |
| 139 if (!pXFAReader) { | 259 if (!pXFAReader) { |
| 140 return XFA_PARSESTATUS_SyntaxErr; | 260 return XFA_PARSESTATUS_SyntaxErr; |
| 141 } | 261 } |
| 142 CPDF_Document* pPDFDocument = | 262 CPDF_Document* pPDFDocument = |
| 143 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); | 263 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); |
| 144 ASSERT(!m_pPDFDoc); | 264 ASSERT(!m_pPDFDoc); |
| 145 if (!OpenDoc(pPDFDocument)) { | 265 if (!OpenDoc(pPDFDocument)) { |
| 146 return XFA_PARSESTATUS_SyntaxErr; | 266 return XFA_PARSESTATUS_SyntaxErr; |
| 147 } | 267 } |
| 148 IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument, TRUE); | 268 IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument, TRUE); |
| 149 if (!pParser) { | 269 if (!pParser) { |
| 150 return XFA_PARSESTATUS_SyntaxErr; | 270 return XFA_PARSESTATUS_SyntaxErr; |
| 151 } | 271 } |
| 152 CXFA_Node* pRootNode = NULL; | 272 CXFA_Node* pRootNode = nullptr; |
| 153 if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && | 273 if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && |
| 154 pParser->DoParse(NULL) == XFA_PARSESTATUS_Done) { | 274 pParser->DoParse(nullptr) == XFA_PARSESTATUS_Done) { |
| 155 pRootNode = pParser->GetRootNode(); | 275 pRootNode = pParser->GetRootNode(); |
| 156 } | 276 } |
| 157 if (pRootNode && m_pDocument->GetRoot()) { | 277 if (pRootNode && m_pDocument->GetRoot()) { |
| 158 XFA_XPDPacket_MergeRootNode(m_pDocument->GetRoot(), pRootNode); | 278 XFA_XPDPacket_MergeRootNode(m_pDocument->GetRoot(), pRootNode); |
| 159 iStatus = XFA_PARSESTATUS_Done; | 279 iStatus = XFA_PARSESTATUS_Done; |
| 160 } else { | 280 } else { |
| 161 iStatus = XFA_PARSESTATUS_StatusErr; | 281 iStatus = XFA_PARSESTATUS_StatusErr; |
| 162 } | 282 } |
| 163 pParser->Release(); | 283 pParser->Release(); |
| 164 pParser = NULL; | 284 pParser = nullptr; |
| 165 } | 285 } |
| 166 return iStatus; | 286 return iStatus; |
| 167 } | 287 } |
| 168 void CXFA_FFDoc::StopLoad() { | 288 void CXFA_FFDoc::StopLoad() { |
| 169 m_pApp->GetXFAFontMgr()->LoadDocFonts(this); | 289 m_pApp->GetXFAFontMgr()->LoadDocFonts(this); |
| 170 m_dwDocType = XFA_DOCTYPE_Static; | 290 m_dwDocType = XFA_DOCTYPE_Static; |
| 171 CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); | 291 CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 172 if (!pConfig) { | 292 if (!pConfig) { |
| 173 return; | 293 return; |
| 174 } | 294 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 auto it = m_TypeToDocViewMap.begin(); | 330 auto it = m_TypeToDocViewMap.begin(); |
| 211 return it != m_TypeToDocViewMap.end() ? it->second.get() : nullptr; | 331 return it != m_TypeToDocViewMap.end() ? it->second.get() : nullptr; |
| 212 } | 332 } |
| 213 | 333 |
| 214 FX_BOOL CXFA_FFDoc::OpenDoc(IFX_FileRead* pStream, FX_BOOL bTakeOverFile) { | 334 FX_BOOL CXFA_FFDoc::OpenDoc(IFX_FileRead* pStream, FX_BOOL bTakeOverFile) { |
| 215 m_bOwnStream = bTakeOverFile; | 335 m_bOwnStream = bTakeOverFile; |
| 216 m_pStream = pStream; | 336 m_pStream = pStream; |
| 217 return TRUE; | 337 return TRUE; |
| 218 } | 338 } |
| 219 FX_BOOL CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { | 339 FX_BOOL CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { |
| 220 if (pPDFDoc == NULL) { | 340 if (!pPDFDoc) |
| 221 return FALSE; | 341 return FALSE; |
| 222 } | 342 |
| 223 CPDF_Dictionary* pRoot = pPDFDoc->GetRoot(); | 343 CPDF_Dictionary* pRoot = pPDFDoc->GetRoot(); |
| 224 if (pRoot == NULL) { | 344 if (!pRoot) |
| 225 return FALSE; | 345 return FALSE; |
| 226 } | 346 |
| 227 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 347 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
| 228 if (pAcroForm == NULL) { | 348 if (!pAcroForm) |
| 229 return FALSE; | 349 return FALSE; |
| 230 } | 350 |
| 231 CPDF_Object* pElementXFA = pAcroForm->GetDirectObjectBy("XFA"); | 351 CPDF_Object* pElementXFA = pAcroForm->GetDirectObjectBy("XFA"); |
| 232 if (pElementXFA == NULL) { | 352 if (!pElementXFA) |
| 233 return FALSE; | 353 return FALSE; |
| 234 } | 354 |
| 235 CFX_ArrayTemplate<CPDF_Stream*> xfaStreams; | 355 CFX_ArrayTemplate<CPDF_Stream*> xfaStreams; |
| 236 if (pElementXFA->IsArray()) { | 356 if (pElementXFA->IsArray()) { |
| 237 CPDF_Array* pXFAArray = (CPDF_Array*)pElementXFA; | 357 CPDF_Array* pXFAArray = (CPDF_Array*)pElementXFA; |
| 238 for (size_t i = 0; i < pXFAArray->GetCount() / 2; i++) { | 358 for (size_t i = 0; i < pXFAArray->GetCount() / 2; i++) { |
| 239 if (CPDF_Stream* pStream = pXFAArray->GetStreamAt(i * 2 + 1)) | 359 if (CPDF_Stream* pStream = pXFAArray->GetStreamAt(i * 2 + 1)) |
| 240 xfaStreams.Add(pStream); | 360 xfaStreams.Add(pStream); |
| 241 } | 361 } |
| 242 } else if (pElementXFA->IsStream()) { | 362 } else if (pElementXFA->IsStream()) { |
| 243 xfaStreams.Add((CPDF_Stream*)pElementXFA); | 363 xfaStreams.Add((CPDF_Stream*)pElementXFA); |
| 244 } | 364 } |
| 245 if (xfaStreams.GetSize() < 1) { | 365 if (xfaStreams.GetSize() < 1) { |
| 246 return FALSE; | 366 return FALSE; |
| 247 } | 367 } |
| 248 IFX_FileRead* pFileRead = new CXFA_FileRead(xfaStreams); | 368 IFX_FileRead* pFileRead = new CXFA_FileRead(xfaStreams); |
| 249 m_pPDFDoc = pPDFDoc; | 369 m_pPDFDoc = pPDFDoc; |
| 250 if (m_pStream) { | 370 if (m_pStream) { |
| 251 m_pStream->Release(); | 371 m_pStream->Release(); |
| 252 m_pStream = NULL; | 372 m_pStream = nullptr; |
| 253 } | 373 } |
| 254 m_pStream = pFileRead; | 374 m_pStream = pFileRead; |
| 255 m_bOwnStream = TRUE; | 375 m_bOwnStream = TRUE; |
| 256 return TRUE; | 376 return TRUE; |
| 257 } | 377 } |
| 258 FX_BOOL CXFA_FFDoc::CloseDoc() { | 378 FX_BOOL CXFA_FFDoc::CloseDoc() { |
| 259 for (const auto& pair : m_TypeToDocViewMap) | 379 for (const auto& pair : m_TypeToDocViewMap) |
| 260 pair.second->RunDocClose(); | 380 pair.second->RunDocClose(); |
| 261 | 381 |
| 262 if (m_pDocument) | 382 if (m_pDocument) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 | 488 |
| 369 return !!pExport->Export( | 489 return !!pExport->Export( |
| 370 pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); | 490 pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); |
| 371 } | 491 } |
| 372 | 492 |
| 373 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { | 493 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { |
| 374 std::unique_ptr<CXFA_DataImporter> importer( | 494 std::unique_ptr<CXFA_DataImporter> importer( |
| 375 new CXFA_DataImporter(m_pDocument)); | 495 new CXFA_DataImporter(m_pDocument)); |
| 376 return importer->ImportData(pStream); | 496 return importer->ImportData(pStream); |
| 377 } | 497 } |
| OLD | NEW |