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_parser.h" | 7 #include "core/include/fpdfapi/fpdf_parser.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_serial.h" | 9 #include "core/include/fpdfapi/fpdf_serial.h" |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 word = parser.GetNextWord(nullptr); | 68 word = parser.GetNextWord(nullptr); |
69 if (word != "endobj") { | 69 if (word != "endobj") { |
70 break; | 70 break; |
71 } | 71 } |
72 } else { | 72 } else { |
73 if (word != "trailer") { | 73 if (word != "trailer") { |
74 break; | 74 break; |
75 } | 75 } |
76 if (CPDF_Dictionary* pMainDict = | 76 if (CPDF_Dictionary* pMainDict = |
77 ToDictionary(parser.GetObject(this, 0, 0, true))) { | 77 ToDictionary(parser.GetObject(this, 0, 0, true))) { |
78 m_pRootDict = pMainDict->GetDict("Root"); | 78 m_pRootDict = pMainDict->GetDictBy("Root"); |
79 pMainDict->Release(); | 79 pMainDict->Release(); |
80 } | 80 } |
81 break; | 81 break; |
82 } | 82 } |
83 } | 83 } |
84 } | 84 } |
85 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const { | 85 FX_BOOL CFDF_Document::WriteBuf(CFX_ByteTextBuf& buf) const { |
86 if (!m_pRootDict) { | 86 if (!m_pRootDict) { |
87 return FALSE; | 87 return FALSE; |
88 } | 88 } |
89 buf << "%FDF-1.2\r\n"; | 89 buf << "%FDF-1.2\r\n"; |
90 for (const auto& pair : m_IndirectObjs) { | 90 for (const auto& pair : m_IndirectObjs) { |
91 buf << pair.first << " 0 obj\r\n" << pair.second << "\r\nendobj\r\n\r\n"; | 91 buf << pair.first << " 0 obj\r\n" << pair.second << "\r\nendobj\r\n\r\n"; |
92 } | 92 } |
93 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() | 93 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() |
94 << " 0 R>>\r\n%%EOF\r\n"; | 94 << " 0 R>>\r\n%%EOF\r\n"; |
95 return TRUE; | 95 return TRUE; |
96 } | 96 } |
97 CFX_WideString CFDF_Document::GetWin32Path() const { | 97 CFX_WideString CFDF_Document::GetWin32Path() const { |
98 CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDict("FDF") : NULL; | 98 CPDF_Dictionary* pDict = m_pRootDict ? m_pRootDict->GetDictBy("FDF") : NULL; |
99 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue("F") : NULL; | 99 CPDF_Object* pFileSpec = pDict ? pDict->GetElementValue("F") : NULL; |
100 if (!pFileSpec) | 100 if (!pFileSpec) |
101 return CFX_WideString(); | 101 return CFX_WideString(); |
102 if (pFileSpec->IsString()) | 102 if (pFileSpec->IsString()) |
103 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDict("FDF")); | 103 return FPDF_FileSpec_GetWin32Path(m_pRootDict->GetDictBy("FDF")); |
104 return FPDF_FileSpec_GetWin32Path(pFileSpec); | 104 return FPDF_FileSpec_GetWin32Path(pFileSpec); |
105 } | 105 } |
106 static CFX_WideString ChangeSlash(const FX_WCHAR* str) { | 106 static CFX_WideString ChangeSlash(const FX_WCHAR* str) { |
107 CFX_WideString result; | 107 CFX_WideString result; |
108 while (*str) { | 108 while (*str) { |
109 if (*str == '\\') { | 109 if (*str == '\\') { |
110 result += '/'; | 110 result += '/'; |
111 } else if (*str == '/') { | 111 } else if (*str == '/') { |
112 result += '\\'; | 112 result += '\\'; |
113 } else { | 113 } else { |
(...skipping 26 matching lines...) Expand all Loading... |
140 pFileDict->SetAtString("F", CFX_ByteString::FromUnicode(result)); | 140 pFileDict->SetAtString("F", CFX_ByteString::FromUnicode(result)); |
141 pFileDict->SetAtString("UF", PDF_EncodeText(result)); | 141 pFileDict->SetAtString("UF", PDF_EncodeText(result)); |
142 pFileDict->RemoveAt("FS"); | 142 pFileDict->RemoveAt("FS"); |
143 } | 143 } |
144 } | 144 } |
145 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { | 145 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec) { |
146 CFX_WideString wsFileName; | 146 CFX_WideString wsFileName; |
147 if (!pFileSpec) { | 147 if (!pFileSpec) { |
148 wsFileName = CFX_WideString(); | 148 wsFileName = CFX_WideString(); |
149 } else if (const CPDF_Dictionary* pDict = pFileSpec->AsDictionary()) { | 149 } else if (const CPDF_Dictionary* pDict = pFileSpec->AsDictionary()) { |
150 wsFileName = pDict->GetUnicodeText("UF"); | 150 wsFileName = pDict->GetUnicodeTextBy("UF"); |
151 if (wsFileName.IsEmpty()) { | 151 if (wsFileName.IsEmpty()) { |
152 wsFileName = CFX_WideString::FromLocal(pDict->GetString("F")); | 152 wsFileName = CFX_WideString::FromLocal(pDict->GetStringBy("F")); |
153 } | 153 } |
154 if (pDict->GetString("FS") == "URL") { | 154 if (pDict->GetStringBy("FS") == "URL") { |
155 return wsFileName; | 155 return wsFileName; |
156 } | 156 } |
157 if (wsFileName.IsEmpty() && pDict->KeyExist("DOS")) { | 157 if (wsFileName.IsEmpty() && pDict->KeyExist("DOS")) { |
158 wsFileName = CFX_WideString::FromLocal(pDict->GetString("DOS")); | 158 wsFileName = CFX_WideString::FromLocal(pDict->GetStringBy("DOS")); |
159 } | 159 } |
160 } else { | 160 } else { |
161 wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString()); | 161 wsFileName = CFX_WideString::FromLocal(pFileSpec->GetString()); |
162 } | 162 } |
163 if (wsFileName[0] != '/') { | 163 if (wsFileName[0] != '/') { |
164 return ChangeSlash(wsFileName.c_str()); | 164 return ChangeSlash(wsFileName.c_str()); |
165 } | 165 } |
166 if (wsFileName[2] == '/') { | 166 if (wsFileName[2] == '/') { |
167 CFX_WideString result; | 167 CFX_WideString result; |
168 result += wsFileName[1]; | 168 result += wsFileName[1]; |
169 result += ':'; | 169 result += ':'; |
170 result += ChangeSlash(wsFileName.c_str() + 2); | 170 result += ChangeSlash(wsFileName.c_str() + 2); |
171 return result; | 171 return result; |
172 } | 172 } |
173 CFX_WideString result; | 173 CFX_WideString result; |
174 result += '\\'; | 174 result += '\\'; |
175 result += ChangeSlash(wsFileName.c_str()); | 175 result += ChangeSlash(wsFileName.c_str()); |
176 return result; | 176 return result; |
177 } | 177 } |
OLD | NEW |