| 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/app/xfa_ffdoc.h" | 7 #include "xfa/fxfa/app/xfa_ffdoc.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 11 #include "core/fxcrt/include/fx_ext.h" | 11 #include "core/fxcrt/include/fx_ext.h" |
| 12 #include "core/include/fpdfdoc/fpdf_doc.h" | 12 #include "core/include/fpdfdoc/fpdf_doc.h" |
| 13 #include "xfa/fde/xml/fde_xml_imp.h" |
| 13 #include "xfa/fgas/crt/fgas_algorithm.h" | 14 #include "xfa/fgas/crt/fgas_algorithm.h" |
| 14 #include "xfa/fwl/core/ifwl_notedriver.h" | 15 #include "xfa/fwl/core/ifwl_notedriver.h" |
| 15 #include "xfa/fxfa/app/xfa_ffapp.h" | 16 #include "xfa/fxfa/app/xfa_ffapp.h" |
| 16 #include "xfa/fxfa/app/xfa_ffdocview.h" | 17 #include "xfa/fxfa/app/xfa_ffdocview.h" |
| 17 #include "xfa/fxfa/app/xfa_ffnotify.h" | 18 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 18 #include "xfa/fxfa/app/xfa_ffwidget.h" | 19 #include "xfa/fxfa/app/xfa_ffwidget.h" |
| 19 #include "xfa/fxfa/app/xfa_fontmgr.h" | 20 #include "xfa/fxfa/app/xfa_fontmgr.h" |
| 20 #include "xfa/fxfa/parser/xfa_docdata.h" | 21 #include "xfa/fxfa/parser/xfa_docdata.h" |
| 21 #include "xfa/fxfa/parser/xfa_parser.h" | 22 #include "xfa/fxfa/parser/xfa_parser.h" |
| 22 | 23 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 uint32_t CXFA_FFDoc::GetDocType() { | 36 uint32_t CXFA_FFDoc::GetDocType() { |
| 36 return m_dwDocType; | 37 return m_dwDocType; |
| 37 } | 38 } |
| 38 int32_t CXFA_FFDoc::StartLoad() { | 39 int32_t CXFA_FFDoc::StartLoad() { |
| 39 m_pNotify = new CXFA_FFNotify(this); | 40 m_pNotify = new CXFA_FFNotify(this); |
| 40 IXFA_DocParser* pDocParser = IXFA_DocParser::Create(m_pNotify); | 41 IXFA_DocParser* pDocParser = IXFA_DocParser::Create(m_pNotify); |
| 41 int32_t iStatus = pDocParser->StartParse(m_pStream); | 42 int32_t iStatus = pDocParser->StartParse(m_pStream); |
| 42 m_pDocument = pDocParser->GetDocument(); | 43 m_pDocument = pDocParser->GetDocument(); |
| 43 return iStatus; | 44 return iStatus; |
| 44 } | 45 } |
| 45 FX_BOOL XFA_GetPDFContentsFromPDFXML(IFDE_XMLNode* pPDFElement, | 46 FX_BOOL XFA_GetPDFContentsFromPDFXML(CFDE_XMLNode* pPDFElement, |
| 46 uint8_t*& pByteBuffer, | 47 uint8_t*& pByteBuffer, |
| 47 int32_t& iBufferSize) { | 48 int32_t& iBufferSize) { |
| 48 IFDE_XMLElement* pDocumentElement = NULL; | 49 CFDE_XMLElement* pDocumentElement = NULL; |
| 49 for (IFDE_XMLNode* pXMLNode = | 50 for (CFDE_XMLNode* pXMLNode = |
| 50 pPDFElement->GetNodeItem(IFDE_XMLNode::FirstChild); | 51 pPDFElement->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 51 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(IFDE_XMLNode::NextSibling)) { | 52 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 52 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | 53 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 53 CFX_WideString wsTagName; | 54 CFX_WideString wsTagName; |
| 54 IFDE_XMLElement* pXMLElement = (IFDE_XMLElement*)pXMLNode; | 55 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 55 pXMLElement->GetTagName(wsTagName); | 56 pXMLElement->GetTagName(wsTagName); |
| 56 if (wsTagName.Equal(FX_WSTRC(L"document"))) { | 57 if (wsTagName.Equal(FX_WSTRC(L"document"))) { |
| 57 pDocumentElement = pXMLElement; | 58 pDocumentElement = pXMLElement; |
| 58 break; | 59 break; |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 if (!pDocumentElement) { | 63 if (!pDocumentElement) { |
| 63 return FALSE; | 64 return FALSE; |
| 64 } | 65 } |
| 65 IFDE_XMLElement* pChunkElement = NULL; | 66 CFDE_XMLElement* pChunkElement = NULL; |
| 66 for (IFDE_XMLNode* pXMLNode = | 67 for (CFDE_XMLNode* pXMLNode = |
| 67 pDocumentElement->GetNodeItem(IFDE_XMLNode::FirstChild); | 68 pDocumentElement->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 68 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(IFDE_XMLNode::NextSibling)) { | 69 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 69 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | 70 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 70 CFX_WideString wsTagName; | 71 CFX_WideString wsTagName; |
| 71 IFDE_XMLElement* pXMLElement = (IFDE_XMLElement*)pXMLNode; | 72 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 72 pXMLElement->GetTagName(wsTagName); | 73 pXMLElement->GetTagName(wsTagName); |
| 73 if (wsTagName.Equal(FX_WSTRC(L"chunk"))) { | 74 if (wsTagName.Equal(FX_WSTRC(L"chunk"))) { |
| 74 pChunkElement = pXMLElement; | 75 pChunkElement = pXMLElement; |
| 75 break; | 76 break; |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 if (!pChunkElement) { | 80 if (!pChunkElement) { |
| 80 return FALSE; | 81 return FALSE; |
| 81 } | 82 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { | 108 int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { |
| 108 int32_t iStatus = m_pDocument->GetParser()->DoParse(pPause); | 109 int32_t iStatus = m_pDocument->GetParser()->DoParse(pPause); |
| 109 if (iStatus == XFA_PARSESTATUS_Done && !m_pPDFDoc) { | 110 if (iStatus == XFA_PARSESTATUS_Done && !m_pPDFDoc) { |
| 110 CXFA_Node* pPDFNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Pdf)); | 111 CXFA_Node* pPDFNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Pdf)); |
| 111 if (!pPDFNode) { | 112 if (!pPDFNode) { |
| 112 return XFA_PARSESTATUS_SyntaxErr; | 113 return XFA_PARSESTATUS_SyntaxErr; |
| 113 } | 114 } |
| 114 IFDE_XMLNode* pPDFXML = pPDFNode->GetXMLMappingNode(); | 115 CFDE_XMLNode* pPDFXML = pPDFNode->GetXMLMappingNode(); |
| 115 if (pPDFXML->GetType() != FDE_XMLNODE_Element) { | 116 if (pPDFXML->GetType() != FDE_XMLNODE_Element) { |
| 116 return XFA_PARSESTATUS_SyntaxErr; | 117 return XFA_PARSESTATUS_SyntaxErr; |
| 117 } | 118 } |
| 118 int32_t iBufferSize = 0; | 119 int32_t iBufferSize = 0; |
| 119 uint8_t* pByteBuffer = NULL; | 120 uint8_t* pByteBuffer = NULL; |
| 120 IFX_FileRead* pXFAReader = NULL; | 121 IFX_FileRead* pXFAReader = NULL; |
| 121 if (XFA_GetPDFContentsFromPDFXML(pPDFXML, pByteBuffer, iBufferSize)) { | 122 if (XFA_GetPDFContentsFromPDFXML(pPDFXML, pByteBuffer, iBufferSize)) { |
| 122 pXFAReader = FX_CreateMemoryStream(pByteBuffer, iBufferSize, TRUE); | 123 pXFAReader = FX_CreateMemoryStream(pByteBuffer, iBufferSize, TRUE); |
| 123 } else { | 124 } else { |
| 124 CFX_WideString wsHref; | 125 CFX_WideString wsHref; |
| 125 ((IFDE_XMLElement*)pPDFXML)->GetString(L"href", wsHref); | 126 static_cast<CFDE_XMLElement*>(pPDFXML)->GetString(L"href", wsHref); |
| 126 if (!wsHref.IsEmpty()) { | 127 if (!wsHref.IsEmpty()) { |
| 127 pXFAReader = GetDocProvider()->OpenLinkedFile(this, wsHref); | 128 pXFAReader = GetDocProvider()->OpenLinkedFile(this, wsHref); |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 if (!pXFAReader) { | 131 if (!pXFAReader) { |
| 131 return XFA_PARSESTATUS_SyntaxErr; | 132 return XFA_PARSESTATUS_SyntaxErr; |
| 132 } | 133 } |
| 133 CPDF_Document* pPDFDocument = | 134 CPDF_Document* pPDFDocument = |
| 134 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); | 135 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); |
| 135 FXSYS_assert(!m_pPDFDoc); | 136 FXSYS_assert(!m_pPDFDoc); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 imageDIBDpi->pDibSource = XFA_LoadImageFromBuffer( | 372 imageDIBDpi->pDibSource = XFA_LoadImageFromBuffer( |
| 372 pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); | 373 pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); |
| 373 imageDIBDpi->iImageXDpi = iImageXDpi; | 374 imageDIBDpi->iImageXDpi = iImageXDpi; |
| 374 imageDIBDpi->iImageYDpi = iImageYDpi; | 375 imageDIBDpi->iImageYDpi = iImageYDpi; |
| 375 pImageFileRead->Release(); | 376 pImageFileRead->Release(); |
| 376 } | 377 } |
| 377 m_mapNamedImages.SetAt((void*)(uintptr_t)dwHash, imageDIBDpi); | 378 m_mapNamedImages.SetAt((void*)(uintptr_t)dwHash, imageDIBDpi); |
| 378 return (CFX_DIBitmap*)imageDIBDpi->pDibSource; | 379 return (CFX_DIBitmap*)imageDIBDpi->pDibSource; |
| 379 } | 380 } |
| 380 | 381 |
| 381 IFDE_XMLElement* CXFA_FFDoc::GetPackageData(const CFX_WideStringC& wsPackage) { | 382 CFDE_XMLElement* CXFA_FFDoc::GetPackageData(const CFX_WideStringC& wsPackage) { |
| 382 uint32_t packetHash = | 383 uint32_t packetHash = |
| 383 FX_HashCode_String_GetW(wsPackage.GetPtr(), wsPackage.GetLength()); | 384 FX_HashCode_String_GetW(wsPackage.GetPtr(), wsPackage.GetLength()); |
| 384 CXFA_Node* pNode = ToNode(m_pDocument->GetXFAObject(packetHash)); | 385 CXFA_Node* pNode = ToNode(m_pDocument->GetXFAObject(packetHash)); |
| 385 if (!pNode) { | 386 if (!pNode) { |
| 386 return NULL; | 387 return NULL; |
| 387 } | 388 } |
| 388 IFDE_XMLNode* pXMLNode = pNode->GetXMLMappingNode(); | 389 CFDE_XMLNode* pXMLNode = pNode->GetXMLMappingNode(); |
| 389 return (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) | 390 return (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) |
| 390 ? (IFDE_XMLElement*)pXMLNode | 391 ? static_cast<CFDE_XMLElement*>(pXMLNode) |
| 391 : NULL; | 392 : NULL; |
| 392 } | 393 } |
| 393 FX_BOOL CXFA_FFDoc::SavePackage(const CFX_WideStringC& wsPackage, | 394 FX_BOOL CXFA_FFDoc::SavePackage(const CFX_WideStringC& wsPackage, |
| 394 IFX_FileWrite* pFile, | 395 IFX_FileWrite* pFile, |
| 395 IXFA_ChecksumContext* pCSContext) { | 396 IXFA_ChecksumContext* pCSContext) { |
| 396 IXFA_PacketExport* pExport = IXFA_PacketExport::Create(m_pDocument); | 397 IXFA_PacketExport* pExport = IXFA_PacketExport::Create(m_pDocument); |
| 397 if (!pExport) { | 398 if (!pExport) { |
| 398 return FALSE; | 399 return FALSE; |
| 399 } | 400 } |
| 400 uint32_t packetHash = | 401 uint32_t packetHash = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 422 } | 423 } |
| 423 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { | 424 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { |
| 424 FX_BOOL bRet = FALSE; | 425 FX_BOOL bRet = FALSE; |
| 425 IXFA_PacketImport* pImport = IXFA_PacketImport::Create(m_pDocument); | 426 IXFA_PacketImport* pImport = IXFA_PacketImport::Create(m_pDocument); |
| 426 if (pImport) { | 427 if (pImport) { |
| 427 bRet = pImport->ImportData(pStream); | 428 bRet = pImport->ImportData(pStream); |
| 428 pImport->Release(); | 429 pImport->Release(); |
| 429 } | 430 } |
| 430 return bRet; | 431 return bRet; |
| 431 } | 432 } |
| OLD | NEW |