7#include "core/fpdfdoc/cpdf_filespec.h"
12#include "build/build_config.h"
13#include "constants/stream_dict_common.h"
14#include "core/fpdfapi/parser/cpdf_dictionary.h"
15#include "core/fpdfapi/parser/cpdf_name.h"
16#include "core/fpdfapi/parser/cpdf_object.h"
17#include "core/fpdfapi/parser/cpdf_stream.h"
18#include "core/fpdfapi/parser/cpdf_string.h"
19#include "core/fpdfapi/parser/fpdf_parser_decode.h"
20#include "core/fxcrt/fx_system.h"
21#include "third_party/base/check.h"
22#include "third_party/base/notreached.h"
26#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_WIN)
27WideString ChangeSlashToPlatform(
const wchar_t* str) {
31#if BUILDFLAG(IS_APPLE)
44WideString ChangeSlashToPDF(
const wchar_t* str) {
47 if (*str ==
'\\' || *str ==
':')
68 if (filepath.GetLength() <= 1)
71#if BUILDFLAG(IS_APPLE)
72 if (filepath.First(
sizeof(
"/Mac") - 1) == WideStringView(L"/Mac"))
73 return ChangeSlashToPlatform(filepath.c_str() + 1);
74 return ChangeSlashToPlatform(filepath.c_str());
75#elif BUILDFLAG(IS_WIN)
77 if (filepath[0] != L'/')
78 return ChangeSlashToPlatform(filepath.c_str());
79 if (filepath[1] == L'/')
80 return ChangeSlashToPlatform(filepath.c_str() + 1);
81 if (filepath[2] == L'/') {
83 result += filepath[1];
85 result += ChangeSlashToPlatform(filepath.c_str() + 2);
90 result += ChangeSlashToPlatform(filepath.c_str());
93 return WideString
(filepath
);
98 WideString csFileName;
99 if (
const CPDF_Dictionary* pDict = m_pObj->AsDictionary()) {
101 ToString(pDict->GetDirectObjectFor(
"UF"));
103 csFileName = pUF->GetUnicodeText();
106 ToString(pDict->GetDirectObjectFor(pdfium::stream::kF));
114 for (
const auto* key : {
"DOS",
"Mac",
"Unix"}) {
115 RetainPtr<
const CPDF_String> pValue =
116 ToString(pDict->GetDirectObjectFor(key));
119 WideString::FromDefANSI(pValue->GetString().AsStringView());
124 }
else if (
const CPDF_String* pString = m_pObj->AsString()) {
131 const CPDF_Dictionary* pDict = m_pObj->AsDictionary();
136 RetainPtr<
const CPDF_Dictionary> pFiles = pDict->GetDictFor(
"EF");
142 static constexpr const char* kKeys[] = {
"UF",
"F",
"DOS",
"Mac",
"Unix"};
143 size_t end = pDict->GetByteStringFor(
"FS") ==
"URL" ? 2 : std::size(kKeys);
144 for (size_t i = 0; i < end; ++i) {
145 ByteString key = kKeys[i];
147 RetainPtr<
const CPDF_Stream> pStream = pFiles->GetStreamFor(key);
156 RetainPtr<
const CPDF_Stream> pStream = GetFileStream();
160 RetainPtr<
const CPDF_Dictionary> pDict = pStream->GetDict();
161 return pDict ? pDict->GetDictFor(
"Params") :
nullptr;
165 return pdfium::WrapRetain(
166 const_cast<CPDF_Dictionary*>(GetParamsDict().Get()));
170 if (filepath.GetLength() <= 1)
174 if (filepath[1] == L':') {
175 WideString result(L'/');
176 result += filepath[0];
177 if (filepath[2] != L'\\')
180 result += ChangeSlashToPDF(filepath.c_str() + 2);
183 if (filepath[0] == L'\\' && filepath[1] == L'\\')
184 return ChangeSlashToPDF(filepath.c_str() + 1);
186 if (filepath[0] == L'\\')
187 return L'/' + ChangeSlashToPDF(filepath.c_str());
188 return ChangeSlashToPDF(filepath.c_str());
189#elif BUILDFLAG(IS_APPLE)
190 if (filepath.First(
sizeof(
"Mac") - 1).EqualsASCII(
"Mac"))
191 return L'/' + ChangeSlashToPDF(filepath.c_str());
192 return ChangeSlashToPDF(filepath.c_str());
194 return WideString
(filepath
);
WideString GetUnicodeTextFor(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
RetainPtr< CPDF_Dictionary > GetMutableParamsDict()
RetainPtr< const CPDF_Dictionary > GetParamsDict() const
WideString GetFileName() const
static WideString DecodeFileName(const WideString &filepath)
CPDF_FileSpec(RetainPtr< const CPDF_Object > pObj)
RetainPtr< const CPDF_Stream > GetFileStream() const
static WideString EncodeFileName(const WideString &filepath)
ByteString GetString() const override
bool operator==(const char *ptr) const
static WideString FromDefANSI(ByteStringView str)
WideString(const WideString &other)