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 m_pRootDict = NULL; | 9 m_pRootDict = NULL; |
10 m_pFile = NULL; | 10 m_pFile = NULL; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 InsertIndirectObject(objnum, pObj); | 64 InsertIndirectObject(objnum, pObj); |
65 word = parser.GetNextWord(bNumber); | 65 word = parser.GetNextWord(bNumber); |
66 if (word != FX_BSTRC("endobj")) { | 66 if (word != FX_BSTRC("endobj")) { |
67 break; | 67 break; |
68 } | 68 } |
69 } else { | 69 } else { |
70 if (word != FX_BSTRC("trailer")) { | 70 if (word != FX_BSTRC("trailer")) { |
71 break; | 71 break; |
72 } | 72 } |
73 CPDF_Dictionary* pMainDict = | 73 if (CPDF_Dictionary* pMainDict = |
74 (CPDF_Dictionary*)parser.GetObject(this, 0, 0, 0); | 74 ToDictionary(parser.GetObject(this, 0, 0, 0))) { |
75 if (pMainDict == NULL || pMainDict->GetType() != PDFOBJ_DICTIONARY) { | 75 m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root")); |
76 break; | 76 pMainDict->Release(); |
77 } | 77 } |
78 m_pRootDict = pMainDict->GetDict(FX_BSTRC("Root")); | |
79 pMainDict->Release(); | |
80 break; | 78 break; |
81 } | 79 } |
82 } | 80 } |
83 } | 81 } |
84 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const { | 82 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const { |
85 if (m_pRootDict == NULL) { | 83 if (m_pRootDict == NULL) { |
86 return FALSE; | 84 return FALSE; |
87 } | 85 } |
88 buf << FX_BSTRC("%FDF-1.2\r\n"); | 86 buf << FX_BSTRC("%FDF-1.2\r\n"); |
89 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); | 87 FX_POSITION pos = m_IndirectObjs.GetStartPosition(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 133 } |
136 result += ChangeSlash(filepath.c_str() + 2); | 134 result += ChangeSlash(filepath.c_str() + 2); |
137 } else if (filepath.GetLength() > 1 && filepath[0] == '\\' && | 135 } else if (filepath.GetLength() > 1 && filepath[0] == '\\' && |
138 filepath[1] == '\\') { | 136 filepath[1] == '\\') { |
139 result = ChangeSlash(filepath.c_str() + 1); | 137 result = ChangeSlash(filepath.c_str() + 1); |
140 } else { | 138 } else { |
141 result = ChangeSlash(filepath.c_str()); | 139 result = ChangeSlash(filepath.c_str()); |
142 } | 140 } |
143 if (pFileSpec->GetType() == PDFOBJ_STRING) { | 141 if (pFileSpec->GetType() == PDFOBJ_STRING) { |
144 pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); | 142 pFileSpec->SetString(CFX_ByteString::FromUnicode(result)); |
145 } else if (pFileSpec->GetType() == PDFOBJ_DICTIONARY) { | 143 } else if (CPDF_Dictionary* pFileDict = pFileSpec->AsDictionary()) { |
146 ((CPDF_Dictionary*)pFileSpec) | 144 pFileDict->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result)); |
147 ->SetAtString(FX_BSTRC("F"), CFX_ByteString::FromUnicode(result)); | 145 pFileDict->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(result)); |
148 ((CPDF_Dictionary*)pFileSpec) | 146 pFileDict->RemoveAt(FX_BSTRC("FS")); |
149 ->SetAtString(FX_BSTRC("UF"), PDF_EncodeText(result)); | |
150 ((CPDF_Dictionary*)pFileSpec)->RemoveAt(FX_BSTRC("FS")); | |
151 } | 147 } |
152 } | 148 } |
153 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { | 149 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { |
154 CFX_WideString wsFileName; | 150 CFX_WideString wsFileName; |
155 if (pFileSpec->GetType() == PDFOBJ_DICTIONARY) { | 151 if (!pFileSpec) { |
156 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFileSpec; | 152 wsFileName = CFX_WideString(); |
| 153 } else if (const CPDF_Dictionary* pDict = pFileSpec->AsDictionary()) { |
157 wsFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); | 154 wsFileName = pDict->GetUnicodeText(FX_BSTRC("UF")); |
158 if (wsFileName.IsEmpty()) { | 155 if (wsFileName.IsEmpty()) { |
159 wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"))); | 156 wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("F"))); |
160 } | 157 } |
161 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { | 158 if (pDict->GetString(FX_BSTRC("FS")) == FX_BSTRC("URL")) { |
162 return wsFileName; | 159 return wsFileName; |
163 } | 160 } |
164 if (wsFileName.IsEmpty() && pDict->KeyExist(FX_BSTRC("DOS"))) { | 161 if (wsFileName.IsEmpty() && pDict->KeyExist(FX_BSTRC("DOS"))) { |
165 wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS"))); | 162 wsFileName = CFX_WideString::FromLocal(pDict->GetString(FX_BSTRC("DOS"))); |
166 } | 163 } |
167 } else if (!pFileSpec) | 164 } else { |
168 wsFileName = CFX_WideString(); | |
169 else { | |
170 wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString()); | 165 wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString()); |
171 } | 166 } |
172 if (wsFileName[0] != '/') { | 167 if (wsFileName[0] != '/') { |
173 return ChangeSlash(wsFileName.c_str()); | 168 return ChangeSlash(wsFileName.c_str()); |
174 } | 169 } |
175 if (wsFileName[2] == '/') { | 170 if (wsFileName[2] == '/') { |
176 CFX_WideString result; | 171 CFX_WideString result; |
177 result += wsFileName[1]; | 172 result += wsFileName[1]; |
178 result += ':'; | 173 result += ':'; |
179 result += ChangeSlash(wsFileName.c_str() + 2); | 174 result += ChangeSlash(wsFileName.c_str() + 2); |
180 return result; | 175 return result; |
181 } | 176 } |
182 CFX_WideString result; | 177 CFX_WideString result; |
183 result += '\\'; | 178 result += '\\'; |
184 result += ChangeSlash(wsFileName.c_str()); | 179 result += ChangeSlash(wsFileName.c_str()); |
185 return result; | 180 return result; |
186 } | 181 } |
OLD | NEW |