Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 = new CFDF_Document; 22 CFDF_Document* pDoc = new CFDF_Document;
23 pDoc->m_pRootDict = new CPDF_Dictionary; 23 pDoc->m_pRootDict = new CPDF_Dictionary;
24 pDoc->AddIndirectObject(pDoc->m_pRootDict); 24 pDoc->AddIndirectObject(pDoc->m_pRootDict);
25 CPDF_Dictionary* pFDFDict = new CPDF_Dictionary; 25 CPDF_Dictionary* pFDFDict = 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(IFX_FileRead *pFile, FX_BOOL bOwnFile) 29 CFDF_Document* CFDF_Document::ParseFile(IFX_FileRead *pFile, bool bOwnFile)
30 { 30 {
31 if (!pFile) { 31 if (!pFile) {
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(const uint8_t* 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((uint8_t*)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, 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 bool bNumber;
54 CFX_ByteString word = parser.GetNextWord(bNumber); 54 CFX_ByteString word = parser.GetNextWord(bNumber);
55 if (bNumber) { 55 if (bNumber) {
56 FX_DWORD objnum = FXSYS_atoi(word); 56 FX_DWORD objnum = FXSYS_atoi(word);
57 word = parser.GetNextWord(bNumber); 57 word = parser.GetNextWord(bNumber);
58 if (!bNumber) { 58 if (!bNumber) {
59 break; 59 break;
60 } 60 }
61 word = parser.GetNextWord(bNumber); 61 word = parser.GetNextWord(bNumber);
62 if (word != FX_BSTRC("obj")) { 62 if (word != FX_BSTRC("obj")) {
63 break; 63 break;
64 } 64 }
65 CPDF_Object* pObj = parser.GetObject(this, objnum, 0, FALSE); 65 CPDF_Object* pObj = parser.GetObject(this, objnum, 0, 0);
66 if (pObj == NULL) { 66 if (pObj == NULL) {
67 break; 67 break;
68 } 68 }
69 InsertIndirectObject(objnum, pObj); 69 InsertIndirectObject(objnum, pObj);
70 word = parser.GetNextWord(bNumber); 70 word = parser.GetNextWord(bNumber);
71 if (word != FX_BSTRC("endobj")) { 71 if (word != FX_BSTRC("endobj")) {
72 break; 72 break;
73 } 73 }
74 } else { 74 } else {
75 if (word != FX_BSTRC("trailer")) { 75 if (word != FX_BSTRC("trailer")) {
76 break; 76 break;
77 } 77 }
78 CPDF_Dictionary* pMainDict = (CPDF_Dictionary*)parser.GetObject(this , 0, 0, 0); 78 CPDF_Dictionary* pMainDict = (CPDF_Dictionary*)parser.GetObject(this , 0, 0, 0);
79 if (pMainDict == NULL || pMainDict->GetType() != PDFOBJ_DICTIONARY) { 79 if (pMainDict == NULL || pMainDict->GetType() != PDFOBJ_DICTIONARY) {
80 break; 80 break;
81 } 81 }
82 m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root")); 82 m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root"));
83 pMainDict->Release(); 83 pMainDict->Release();
84 break; 84 break;
85 } 85 }
86 } 86 }
87 } 87 }
88 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const 88 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, (void*&)objnum, (void*&)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"))) ;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_encrypt.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_filters.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698