| 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/include/cpdf_filespec.h" |    7 #include "core/fpdfdoc/include/cpdf_filespec.h" | 
|    8  |    8  | 
|    9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |    9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 
|   10 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |   10 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   73   result += '\\'; |   73   result += '\\'; | 
|   74   result += ChangeSlashToPlatform(filepath.c_str()); |   74   result += ChangeSlashToPlatform(filepath.c_str()); | 
|   75   return result; |   75   return result; | 
|   76 #else |   76 #else | 
|   77   return CFX_WideString(filepath); |   77   return CFX_WideString(filepath); | 
|   78 #endif |   78 #endif | 
|   79 } |   79 } | 
|   80  |   80  | 
|   81 bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { |   81 bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { | 
|   82   if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |   82   if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { | 
|   83     *csFileName = pDict->GetUnicodeTextBy("UF"); |   83     *csFileName = pDict->GetUnicodeTextFor("UF"); | 
|   84     if (csFileName->IsEmpty()) { |   84     if (csFileName->IsEmpty()) { | 
|   85       *csFileName = |   85       *csFileName = | 
|   86           CFX_WideString::FromLocal(pDict->GetStringBy("F").AsStringC()); |   86           CFX_WideString::FromLocal(pDict->GetStringFor("F").AsStringC()); | 
|   87     } |   87     } | 
|   88     if (pDict->GetStringBy("FS") == "URL") |   88     if (pDict->GetStringFor("FS") == "URL") | 
|   89       return true; |   89       return true; | 
|   90     if (csFileName->IsEmpty()) { |   90     if (csFileName->IsEmpty()) { | 
|   91       if (pDict->KeyExist("DOS")) { |   91       if (pDict->KeyExist("DOS")) { | 
|   92         *csFileName = |   92         *csFileName = | 
|   93             CFX_WideString::FromLocal(pDict->GetStringBy("DOS").AsStringC()); |   93             CFX_WideString::FromLocal(pDict->GetStringFor("DOS").AsStringC()); | 
|   94       } else if (pDict->KeyExist("Mac")) { |   94       } else if (pDict->KeyExist("Mac")) { | 
|   95         *csFileName = |   95         *csFileName = | 
|   96             CFX_WideString::FromLocal(pDict->GetStringBy("Mac").AsStringC()); |   96             CFX_WideString::FromLocal(pDict->GetStringFor("Mac").AsStringC()); | 
|   97       } else if (pDict->KeyExist("Unix")) { |   97       } else if (pDict->KeyExist("Unix")) { | 
|   98         *csFileName = |   98         *csFileName = | 
|   99             CFX_WideString::FromLocal(pDict->GetStringBy("Unix").AsStringC()); |   99             CFX_WideString::FromLocal(pDict->GetStringFor("Unix").AsStringC()); | 
|  100       } else { |  100       } else { | 
|  101         return false; |  101         return false; | 
|  102       } |  102       } | 
|  103     } |  103     } | 
|  104   } else if (m_pObj->IsString()) { |  104   } else if (m_pObj->IsString()) { | 
|  105     *csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); |  105     *csFileName = CFX_WideString::FromLocal(m_pObj->GetString().AsStringC()); | 
|  106   } else { |  106   } else { | 
|  107     return false; |  107     return false; | 
|  108   } |  108   } | 
|  109   *csFileName = DecodeFileName(csFileName->AsStringC()); |  109   *csFileName = DecodeFileName(csFileName->AsStringC()); | 
|  110   return true; |  110   return true; | 
|  111 } |  111 } | 
|  112  |  112  | 
|  113 CPDF_FileSpec::CPDF_FileSpec() { |  113 CPDF_FileSpec::CPDF_FileSpec() { | 
|  114   m_pObj = new CPDF_Dictionary; |  114   m_pObj = new CPDF_Dictionary; | 
|  115   m_pObj->AsDictionary()->SetAtName("Type", "Filespec"); |  115   m_pObj->AsDictionary()->SetNameFor("Type", "Filespec"); | 
|  116 } |  116 } | 
|  117  |  117  | 
|  118 CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { |  118 CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { | 
|  119   if (filepath.GetLength() <= 1) |  119   if (filepath.GetLength() <= 1) | 
|  120     return CFX_WideString(); |  120     return CFX_WideString(); | 
|  121  |  121  | 
|  122 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |  122 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 
|  123   if (filepath.GetAt(1) == ':') { |  123   if (filepath.GetAt(1) == ':') { | 
|  124     CFX_WideString result; |  124     CFX_WideString result; | 
|  125     result = '/'; |  125     result = '/'; | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|  154 } |  154 } | 
|  155  |  155  | 
|  156 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName) { |  156 void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName) { | 
|  157   if (!m_pObj) |  157   if (!m_pObj) | 
|  158     return; |  158     return; | 
|  159  |  159  | 
|  160   CFX_WideString wsStr = EncodeFileName(wsFileName); |  160   CFX_WideString wsStr = EncodeFileName(wsFileName); | 
|  161   if (m_pObj->IsString()) { |  161   if (m_pObj->IsString()) { | 
|  162     m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); |  162     m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr)); | 
|  163   } else if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { |  163   } else if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) { | 
|  164     pDict->SetAtString("F", CFX_ByteString::FromUnicode(wsStr)); |  164     pDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsStr)); | 
|  165     pDict->SetAtString("UF", PDF_EncodeText(wsStr)); |  165     pDict->SetStringFor("UF", PDF_EncodeText(wsStr)); | 
|  166   } |  166   } | 
|  167 } |  167 } | 
| OLD | NEW |