| 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_serial.h" | 7 #include "../../../include/fpdfapi/fpdf_serial.h" |
| 8 CFDF_Document::CFDF_Document() : CPDF_IndirectObjects(NULL) | 8 CFDF_Document::CFDF_Document() : CPDF_IndirectObjects(NULL) |
| 9 { | 9 { |
| 10 m_pRootDict = NULL; | 10 m_pRootDict = NULL; |
| 11 m_pFile = NULL; | 11 m_pFile = NULL; |
| 12 m_bOwnFile = FALSE; | 12 m_bOwnFile = FALSE; |
| 13 } | 13 } |
| 14 CFDF_Document::~CFDF_Document() | 14 CFDF_Document::~CFDF_Document() |
| 15 { | 15 { |
| 16 if (m_bOwnFile && m_pFile) { | 16 if (m_bOwnFile && m_pFile) { |
| 17 m_pFile->Release(); | 17 m_pFile->Release(); |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 CFDF_Document* CFDF_Document::CreateNewDoc() | 20 CFDF_Document* CFDF_Document::CreateNewDoc() |
| 21 { | 21 { |
| 22 CFDF_Document* pDoc = FX_NEW CFDF_Document; | 22 CFDF_Document* pDoc = FX_NEW CFDF_Document; |
| 23 pDoc->m_pRootDict = FX_NEW CPDF_Dictionary; | 23 pDoc->m_pRootDict = FX_NEW CPDF_Dictionary; |
| 24 pDoc->AddIndirectObject(pDoc->m_pRootDict); | 24 pDoc->AddIndirectObject(pDoc->m_pRootDict); |
| 25 CPDF_Dictionary* pFDFDict = FX_NEW CPDF_Dictionary; | 25 CPDF_Dictionary* pFDFDict = FX_NEW CPDF_Dictionary; |
| 26 pDoc->m_pRootDict->SetAt(FX_BSTRC("FDF"), pFDFDict); | 26 pDoc->m_pRootDict->SetAt(FX_BSTRC("FDF"), pFDFDict); |
| 27 return pDoc; | 27 return pDoc; |
| 28 } | 28 } |
| 29 CFDF_Document* CFDF_Document::ParseFile(FX_LPCSTR file_path) | |
| 30 { | |
| 31 return CFDF_Document::ParseFile(FX_CreateFileRead(file_path), TRUE); | |
| 32 } | |
| 33 CFDF_Document* CFDF_Document::ParseFile(FX_LPCWSTR file_path) | |
| 34 { | |
| 35 return CFDF_Document::ParseFile(FX_CreateFileRead(file_path), TRUE); | |
| 36 } | |
| 37 CFDF_Document* CFDF_Document::ParseFile(IFX_FileRead *pFile, FX_BOOL bOwnFile) | 29 CFDF_Document* CFDF_Document::ParseFile(IFX_FileRead *pFile, FX_BOOL bOwnFile) |
| 38 { | 30 { |
| 39 if (!pFile) { | 31 if (!pFile) { |
| 40 return NULL; | 32 return NULL; |
| 41 } | 33 } |
| 42 CFDF_Document* pDoc = FX_NEW CFDF_Document; | 34 CFDF_Document* pDoc = FX_NEW CFDF_Document; |
| 43 pDoc->ParseStream(pFile, bOwnFile); | 35 pDoc->ParseStream(pFile, bOwnFile); |
| 44 if (pDoc->m_pRootDict == NULL) { | 36 if (pDoc->m_pRootDict == NULL) { |
| 45 delete pDoc; | 37 delete pDoc; |
| 46 return NULL; | 38 return NULL; |
| 47 } | 39 } |
| 48 return pDoc; | 40 return pDoc; |
| 49 } | 41 } |
| 50 CFDF_Document* CFDF_Document::ParseMemory(FX_LPCBYTE pData, FX_DWORD size) | 42 CFDF_Document* CFDF_Document::ParseMemory(FX_LPCBYTE pData, FX_DWORD size) |
| 51 { | 43 { |
| 52 return CFDF_Document::ParseFile(FX_CreateMemoryStream((FX_LPBYTE)pData, size
), TRUE); | 44 return CFDF_Document::ParseFile(FX_CreateMemoryStream((FX_LPBYTE)pData, size
), TRUE); |
| 53 } | 45 } |
| 54 void CFDF_Document::ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile) | 46 void CFDF_Document::ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile) |
| 55 { | 47 { |
| 56 m_pFile = pFile; | 48 m_pFile = pFile; |
| 57 m_bOwnFile = bOwnFile; | 49 m_bOwnFile = bOwnFile; |
| 58 CPDF_SyntaxParser parser; | 50 CPDF_SyntaxParser parser; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF"))
: NULL; | 106 CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDict(FX_BSTRC("FDF"))
: NULL; |
| 115 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NUL
L; | 107 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NUL
L; |
| 116 if (pFileSpec == NULL) { | 108 if (pFileSpec == NULL) { |
| 117 return CFX_WideString(); | 109 return CFX_WideString(); |
| 118 } | 110 } |
| 119 if (pFileSpec->GetType() == PDFOBJ_STRING) { | 111 if (pFileSpec->GetType() == PDFOBJ_STRING) { |
| 120 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF")))
; | 112 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF")))
; |
| 121 } | 113 } |
| 122 return FPDF_FileSpec_GetWin32Path(pFileSpec); | 114 return FPDF_FileSpec_GetWin32Path(pFileSpec); |
| 123 } | 115 } |
| 124 FX_BOOL CFDF_Document::WriteFile(FX_LPCSTR file_path) const | |
| 125 { | |
| 126 IFX_FileWrite *pFile = FX_CreateFileWrite(file_path); | |
| 127 if (!pFile) { | |
| 128 return FALSE; | |
| 129 } | |
| 130 FX_BOOL bRet = WriteFile(pFile); | |
| 131 pFile->Release(); | |
| 132 return bRet; | |
| 133 } | |
| 134 FX_BOOL CFDF_Document::WriteFile(FX_LPCWSTR file_path) const | |
| 135 { | |
| 136 IFX_FileWrite *pFile = FX_CreateFileWrite(file_path); | |
| 137 if (!pFile) { | |
| 138 return FALSE; | |
| 139 } | |
| 140 FX_BOOL bRet = WriteFile(pFile); | |
| 141 pFile->Release(); | |
| 142 return bRet; | |
| 143 } | |
| 144 FX_BOOL CFDF_Document::WriteFile(IFX_FileWrite *pFile) const | |
| 145 { | |
| 146 CFX_ByteTextBuf buf; | |
| 147 WriteBuf(buf); | |
| 148 FX_BOOL bRet = pFile->WriteBlock(buf.GetBuffer(), buf.GetSize()); | |
| 149 if (bRet) { | |
| 150 pFile->Flush(); | |
| 151 } | |
| 152 return bRet; | |
| 153 } | |
| 154 static CFX_WideString ChangeSlash(FX_LPCWSTR str) | 116 static CFX_WideString ChangeSlash(FX_LPCWSTR str) |
| 155 { | 117 { |
| 156 CFX_WideString result; | 118 CFX_WideString result; |
| 157 while (*str) { | 119 while (*str) { |
| 158 if (*str == '\\') { | 120 if (*str == '\\') { |
| 159 result += '/'; | 121 result += '/'; |
| 160 } else if (*str == '/') { | 122 } else if (*str == '/') { |
| 161 result += '\\'; | 123 result += '\\'; |
| 162 } else { | 124 } else { |
| 163 result += *str; | 125 result += *str; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 result += ':'; | 181 result += ':'; |
| 220 result += ChangeSlash(wsFileName.c_str() + 2); | 182 result += ChangeSlash(wsFileName.c_str() + 2); |
| 221 return result; | 183 return result; |
| 222 } else { | 184 } else { |
| 223 CFX_WideString result; | 185 CFX_WideString result; |
| 224 result += '\\'; | 186 result += '\\'; |
| 225 result += ChangeSlash(wsFileName); | 187 result += ChangeSlash(wsFileName); |
| 226 return result; | 188 return result; |
| 227 } | 189 } |
| 228 } | 190 } |
| OLD | NEW |