| 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 "core/include/fpdfapi/fpdf_serial.h" | 7 #include "core/include/fpdfapi/fpdf_serial.h" |
| 8 | 8 |
| 9 CFDF_Document::CFDF_Document() : CPDF_IndirectObjects(NULL) { | 9 CFDF_Document::CFDF_Document() : CPDF_IndirectObjects(NULL) { |
| 10 m_pRootDict = NULL; | 10 m_pRootDict = NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 CPDF_Dictionary* pFDFDict = new CPDF_Dictionary; | 23 CPDF_Dictionary* pFDFDict = new CPDF_Dictionary; |
| 24 pDoc->m_pRootDict->SetAt("FDF", pFDFDict); | 24 pDoc->m_pRootDict->SetAt("FDF", pFDFDict); |
| 25 return pDoc; | 25 return pDoc; |
| 26 } | 26 } |
| 27 CFDF_Document* CFDF_Document::ParseFile(IFX_FileRead* pFile, FX_BOOL bOwnFile) { | 27 CFDF_Document* CFDF_Document::ParseFile(IFX_FileRead* pFile, FX_BOOL bOwnFile) { |
| 28 if (!pFile) { | 28 if (!pFile) { |
| 29 return NULL; | 29 return NULL; |
| 30 } | 30 } |
| 31 CFDF_Document* pDoc = new CFDF_Document; | 31 CFDF_Document* pDoc = new CFDF_Document; |
| 32 pDoc->ParseStream(pFile, bOwnFile); | 32 pDoc->ParseStream(pFile, bOwnFile); |
| 33 if (pDoc->m_pRootDict == NULL) { | 33 if (!pDoc->m_pRootDict) { |
| 34 delete pDoc; | 34 delete pDoc; |
| 35 return NULL; | 35 return NULL; |
| 36 } | 36 } |
| 37 return pDoc; | 37 return pDoc; |
| 38 } | 38 } |
| 39 CFDF_Document* CFDF_Document::ParseMemory(const uint8_t* pData, FX_DWORD size) { | 39 CFDF_Document* CFDF_Document::ParseMemory(const uint8_t* pData, FX_DWORD size) { |
| 40 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size), | 40 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size), |
| 41 TRUE); | 41 TRUE); |
| 42 } | 42 } |
| 43 void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) { | 43 void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) { |
| 44 m_pFile = pFile; | 44 m_pFile = pFile; |
| 45 m_bOwnFile = bOwnFile; | 45 m_bOwnFile = bOwnFile; |
| 46 CPDF_SyntaxParser parser; | 46 CPDF_SyntaxParser parser; |
| 47 parser.InitParser(m_pFile, 0); | 47 parser.InitParser(m_pFile, 0); |
| 48 while (1) { | 48 while (1) { |
| 49 FX_BOOL bNumber; | 49 FX_BOOL bNumber; |
| 50 CFX_ByteString word = parser.GetNextWord(bNumber); | 50 CFX_ByteString word = parser.GetNextWord(bNumber); |
| 51 if (bNumber) { | 51 if (bNumber) { |
| 52 FX_DWORD objnum = FXSYS_atoi(word); | 52 FX_DWORD objnum = FXSYS_atoi(word); |
| 53 word = parser.GetNextWord(bNumber); | 53 word = parser.GetNextWord(bNumber); |
| 54 if (!bNumber) { | 54 if (!bNumber) { |
| 55 break; | 55 break; |
| 56 } | 56 } |
| 57 word = parser.GetNextWord(bNumber); | 57 word = parser.GetNextWord(bNumber); |
| 58 if (word != "obj") { | 58 if (word != "obj") { |
| 59 break; | 59 break; |
| 60 } | 60 } |
| 61 CPDF_Object* pObj = parser.GetObject(this, objnum, 0, 0); | 61 CPDF_Object* pObj = parser.GetObject(this, objnum, 0, 0); |
| 62 if (pObj == NULL) { | 62 if (!pObj) { |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 InsertIndirectObject(objnum, pObj); | 65 InsertIndirectObject(objnum, pObj); |
| 66 word = parser.GetNextWord(bNumber); | 66 word = parser.GetNextWord(bNumber); |
| 67 if (word != "endobj") { | 67 if (word != "endobj") { |
| 68 break; | 68 break; |
| 69 } | 69 } |
| 70 } else { | 70 } else { |
| 71 if (word != "trailer") { | 71 if (word != "trailer") { |
| 72 break; | 72 break; |
| 73 } | 73 } |
| 74 if (CPDF_Dictionary* pMainDict = | 74 if (CPDF_Dictionary* pMainDict = |
| 75 ToDictionary(parser.GetObject(this, 0, 0, 0))) { | 75 ToDictionary(parser.GetObject(this, 0, 0, 0))) { |
| 76 m_pRootDict = pMainDict->GetDict("Root"); | 76 m_pRootDict = pMainDict->GetDict("Root"); |
| 77 pMainDict->Release(); | 77 pMainDict->Release(); |
| 78 } | 78 } |
| 79 break; | 79 break; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const { | 83 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const { |
| 84 if (m_pRootDict == NULL) { | 84 if (!m_pRootDict) { |
| 85 return FALSE; | 85 return FALSE; |
| 86 } | 86 } |
| 87 buf << "%FDF-1.2\r\n"; | 87 buf << "%FDF-1.2\r\n"; |
| 88 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); | 88 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); |
| 89 while (pos) { | 89 while (pos) { |
| 90 size_t objnum; | 90 size_t objnum; |
| 91 CPDF_Object* pObj; | 91 CPDF_Object* pObj; |
| 92 m_IndirectObjs.GetNextAssoc(pos, (void*&)objnum, (void*&)pObj); | 92 m_IndirectObjs.GetNextAssoc(pos, (void*&)objnum, (void*&)pObj); |
| 93 buf << (FX_DWORD)objnum << " 0 obj\r\n" << pObj << "\r\nendobj\r\n\r\n"; | 93 buf << (FX_DWORD)objnum << " 0 obj\r\n" << pObj << "\r\nendobj\r\n\r\n"; |
| 94 } | 94 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 result += wsFileName[1]; | 170 result += wsFileName[1]; |
| 171 result += ':'; | 171 result += ':'; |
| 172 result += ChangeSlash(wsFileName.c_str() + 2); | 172 result += ChangeSlash(wsFileName.c_str() + 2); |
| 173 return result; | 173 return result; |
| 174 } | 174 } |
| 175 CFX_WideString result; | 175 CFX_WideString result; |
| 176 result += '\\'; | 176 result += '\\'; |
| 177 result += ChangeSlash(wsFileName.c_str()); | 177 result += ChangeSlash(wsFileName.c_str()); |
| 178 return result; | 178 return result; |
| 179 } | 179 } |
| OLD | NEW |