| 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; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 return NULL; | 32 return NULL; |
| 33 } | 33 } |
| 34 CFDF_Document* pDoc = new CFDF_Document; | 34 CFDF_Document* pDoc = new CFDF_Document; |
| 35 pDoc->ParseStream(pFile, bOwnFile); | 35 pDoc->ParseStream(pFile, bOwnFile); |
| 36 if (pDoc->m_pRootDict == NULL) { | 36 if (pDoc->m_pRootDict == NULL) { |
| 37 delete pDoc; | 37 delete pDoc; |
| 38 return NULL; | 38 return NULL; |
| 39 } | 39 } |
| 40 return pDoc; | 40 return pDoc; |
| 41 } | 41 } |
| 42 CFDF_Document* CFDF_Document::ParseMemory(FX_LPCBYTE pData, FX_DWORD size) | 42 CFDF_Document* CFDF_Document::ParseMemory(const uint8_t* pData, FX_DWORD size) |
| 43 { | 43 { |
| 44 return CFDF_Document::ParseFile(FX_CreateMemoryStream((FX_LPBYTE)pData, size
), TRUE); | 44 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size)
, TRUE); |
| 45 } | 45 } |
| 46 void CFDF_Document::ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile) | 46 void CFDF_Document::ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile) |
| 47 { | 47 { |
| 48 m_pFile = pFile; | 48 m_pFile = pFile; |
| 49 m_bOwnFile = bOwnFile; | 49 m_bOwnFile = bOwnFile; |
| 50 CPDF_SyntaxParser parser; | 50 CPDF_SyntaxParser parser; |
| 51 parser.InitParser(m_pFile, 0); | 51 parser.InitParser(m_pFile, 0); |
| 52 while (1) { | 52 while (1) { |
| 53 FX_BOOL bNumber; | 53 FX_BOOL bNumber; |
| 54 CFX_ByteString word = parser.GetNextWord(bNumber); | 54 CFX_ByteString word = parser.GetNextWord(bNumber); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const | 88 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const |
| 89 { | 89 { |
| 90 if (m_pRootDict == NULL) { | 90 if (m_pRootDict == NULL) { |
| 91 return FALSE; | 91 return FALSE; |
| 92 } | 92 } |
| 93 buf << FX_BSTRC("%FDF-1.2\r\n"); | 93 buf << FX_BSTRC("%FDF-1.2\r\n"); |
| 94 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); | 94 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); |
| 95 while(pos) { | 95 while(pos) { |
| 96 size_t objnum; | 96 size_t objnum; |
| 97 CPDF_Object* pObj; | 97 CPDF_Object* pObj; |
| 98 m_IndirectObjs.GetNextAssoc(pos, (FX_LPVOID&)objnum, (FX_LPVOID&)pObj); | 98 m_IndirectObjs.GetNextAssoc(pos, (void*&)objnum, (void*&)pObj); |
| 99 buf << (FX_DWORD)objnum << FX_BSTRC(" 0 obj\r\n") << pObj << FX_BSTRC("\
r\nendobj\r\n\r\n"); | 99 buf << (FX_DWORD)objnum << FX_BSTRC(" 0 obj\r\n") << pObj << FX_BSTRC("\
r\nendobj\r\n\r\n"); |
| 100 } | 100 } |
| 101 buf << FX_BSTRC("trailer\r\n<</Root ") << m_pRootDict->GetObjNum() << FX_BST
RC(" 0 R>>\r\n%%EOF\r\n"); | 101 buf << FX_BSTRC("trailer\r\n<</Root ") << m_pRootDict->GetObjNum() << FX_BST
RC(" 0 R>>\r\n%%EOF\r\n"); |
| 102 return TRUE; | 102 return TRUE; |
| 103 } | 103 } |
| 104 CFX_WideString CFDF_Document::GetWin32Path() const | 104 CFX_WideString CFDF_Document::GetWin32Path() const |
| 105 { | 105 { |
| 106 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; |
| 107 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NUL
L; | 107 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue(FX_BSTRC("F")) : NUL
L; |
| 108 if (pFileSpec == NULL) { | 108 if (pFileSpec == NULL) { |
| 109 return CFX_WideString(); | 109 return CFX_WideString(); |
| 110 } | 110 } |
| 111 if (pFileSpec->GetType() == PDFOBJ_STRING) { | 111 if (pFileSpec->GetType() == PDFOBJ_STRING) { |
| 112 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF")))
; | 112 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict(FX_BSTRC("FDF")))
; |
| 113 } | 113 } |
| 114 return FPDF_FileSpec_GetWin32Path(pFileSpec); | 114 return FPDF_FileSpec_GetWin32Path(pFileSpec); |
| 115 } | 115 } |
| 116 static CFX_WideString ChangeSlash(FX_LPCWSTR str) | 116 static CFX_WideString ChangeSlash(const FX_WCHAR* str) |
| 117 { | 117 { |
| 118 CFX_WideString result; | 118 CFX_WideString result; |
| 119 while (*str) { | 119 while (*str) { |
| 120 if (*str == '\\') { | 120 if (*str == '\\') { |
| 121 result += '/'; | 121 result += '/'; |
| 122 } else if (*str == '/') { | 122 } else if (*str == '/') { |
| 123 result += '\\'; | 123 result += '\\'; |
| 124 } else { | 124 } else { |
| 125 result += *str; | 125 result += *str; |
| 126 } | 126 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 result += ':'; | 181 result += ':'; |
| 182 result += ChangeSlash(wsFileName.c_str() + 2); | 182 result += ChangeSlash(wsFileName.c_str() + 2); |
| 183 return result; | 183 return result; |
| 184 } else { | 184 } else { |
| 185 CFX_WideString result; | 185 CFX_WideString result; |
| 186 result += '\\'; | 186 result += '\\'; |
| 187 result += ChangeSlash(wsFileName.c_str()); | 187 result += ChangeSlash(wsFileName.c_str()); |
| 188 return result; | 188 return result; |
| 189 } | 189 } |
| 190 } | 190 } |
| OLD | NEW |