OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfdoc/cpdf_filespec.h" | 7 #include "core/fpdfdoc/cpdf_filespec.h" |
8 | 8 |
9 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 9 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 10 #include "core/fpdfapi/parser/cpdf_name.h" |
10 #include "core/fpdfapi/parser/cpdf_object.h" | 11 #include "core/fpdfapi/parser/cpdf_object.h" |
| 12 #include "core/fpdfapi/parser/cpdf_string.h" |
11 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 13 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
12 #include "core/fxcrt/fx_system.h" | 14 #include "core/fxcrt/fx_system.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
17 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 19 _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
18 CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { | 20 CFX_WideString ChangeSlashToPlatform(const FX_WCHAR* str) { |
19 CFX_WideString result; | 21 CFX_WideString result; |
20 while (*str) { | 22 while (*str) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 *csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); | 107 *csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); |
106 } else { | 108 } else { |
107 return false; | 109 return false; |
108 } | 110 } |
109 *csFileName = DecodeFileName(csFileName->AsStringC()); | 111 *csFileName = DecodeFileName(csFileName->AsStringC()); |
110 return true; | 112 return true; |
111 } | 113 } |
112 | 114 |
113 CPDF_FileSpec::CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) { | 115 CPDF_FileSpec::CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) { |
114 m_pObj = new CPDF_Dictionary(pPool); | 116 m_pObj = new CPDF_Dictionary(pPool); |
115 m_pObj->AsDictionary()->SetNameFor("Type", "Filespec"); | 117 m_pObj->AsDictionary()->SetNewFor<CPDF_Name>("Type", "Filespec"); |
116 } | 118 } |
117 | 119 |
118 CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { | 120 CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { |
119 if (filepath.GetLength() <= 1) | 121 if (filepath.GetLength() <= 1) |
120 return CFX_WideString(); | 122 return CFX_WideString(); |
121 | 123 |
122 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 124 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
123 if (filepath.GetAt(1) == ':') { | 125 if (filepath.GetAt(1) == ':') { |
124 CFX_WideString result; | 126 CFX_WideString result; |
125 result = '/'; | 127 result = '/'; |
(...skipping 28 matching lines...) Expand all Loading... |
154 } | 156 } |
155 | 157 |
156 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName) { | 158 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName) { |
157 if (!m_pObj) | 159 if (!m_pObj) |
158 return; | 160 return; |
159 | 161 |
160 CFX_WideString wsStr = EncodeFileName(wsFileName); | 162 CFX_WideString wsStr = EncodeFileName(wsFileName); |
161 if (m_pObj->IsString()) { | 163 if (m_pObj->IsString()) { |
162 m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | 164 m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |
163 } else if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { | 165 } else if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |
164 pDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsStr)); | 166 pDict->SetNewFor<CPDF_String>("F", CFX_ByteString::FromUnicode(wsStr), |
165 pDict->SetStringFor("UF", PDF_EncodeText(wsStr)); | 167 false); |
| 168 pDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsStr), false); |
166 } | 169 } |
167 } | 170 } |
OLD | NEW |