7#include "core/fpdfdoc/cpdf_filespec.h"
13#include "build/build_config.h"
14#include "constants/stream_dict_common.h"
15#include "core/fpdfapi/parser/cpdf_dictionary.h"
16#include "core/fpdfapi/parser/cpdf_name.h"
17#include "core/fpdfapi/parser/cpdf_object.h"
18#include "core/fpdfapi/parser/cpdf_stream.h"
19#include "core/fpdfapi/parser/cpdf_string.h"
20#include "core/fpdfapi/parser/fpdf_parser_decode.h"
21#include "core/fxcrt/check.h"
22#include "core/fxcrt/compiler_specific.h"
23#include "core/fxcrt/fx_system.h"
24#include "core/fxcrt/notreached.h"
28#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_WIN)
29WideString ChangeSlashToPlatform(WideStringView str) {
31 for (
auto wch : str) {
33#if BUILDFLAG(IS_APPLE)
45WideString ChangeSlashToPDF(WideStringView str) {
47 for (
auto wch : str) {
48 if (wch ==
'\\' || wch ==
':') {
68 if (filepath.IsEmpty()) {
71#if BUILDFLAG(IS_APPLE)
72 WideStringView view = filepath.AsStringView();
73 if (view.First(
sizeof(
"/Mac") - 1) == WideStringView(L"/Mac")) {
74 return ChangeSlashToPlatform(view.Substr(1));
76 return ChangeSlashToPlatform(view);
77#elif BUILDFLAG(IS_WIN)
78 WideStringView view = filepath.AsStringView();
79 if (view[0] != L'/') {
80 return ChangeSlashToPlatform(view);
82 if (view[1] == L'/') {
83 return ChangeSlashToPlatform(view.Substr(1));
85 if (view[2] == L'/') {
89 result += ChangeSlashToPlatform(view.Substr(2));
94 result += ChangeSlashToPlatform(view);
105 ToString(pDict->GetDirectObjectFor(
"UF"));
107 csFileName = pUF->GetUnicodeText();
108 if (csFileName.IsEmpty()) {
110 ToString(pDict->GetDirectObjectFor(pdfium::stream::kF));
117 if (csFileName.IsEmpty()) {
118 for (
const auto* key : {
"DOS",
"Mac",
"Unix"}) {
119 RetainPtr<
const CPDF_String> pValue =
120 ToString(pDict->GetDirectObjectFor(key));
123 WideString::FromDefANSI(pValue->GetString().AsStringView());
128 }
else if (
const CPDF_String* pString = m_pObj->AsString()) {
146 static constexpr std::array<
const char*, 5> kKeys = {
147 {
"UF",
"F",
"DOS",
"Mac",
"Unix"}};
149 for (size_t i = 0; i < end; ++i) {
152 RetainPtr<
const CPDF_Stream> pStream = pFiles->GetStreamFor(key);
161 RetainPtr<
const CPDF_Stream> pStream = GetFileStream();
162 return pStream ? pStream->GetDict()->GetDictFor(
"Params") :
nullptr;
166 return pdfium::WrapRetain(
167 const_cast<CPDF_Dictionary*>(GetParamsDict().Get()));
171 if (filepath.IsEmpty()) {
175 WideStringView view = filepath.AsStringView();
176 if (view[1] == L':') {
177 WideString result(L'/');
179 if (view[2] != L'\\') {
182 result += ChangeSlashToPDF(view.Substr(2));
185 if (view[0] == L'\\' && view[1] == L'\\') {
186 return ChangeSlashToPDF(view.Substr(1));
188 if (view[0] == L'\\') {
189 return L'/' + ChangeSlashToPDF(view);
191 return ChangeSlashToPDF(view);
192#elif BUILDFLAG(IS_APPLE)
193 WideStringView view = filepath.AsStringView();
194 if (view.First(
sizeof(
"Mac") - 1).EqualsASCII(
"Mac")) {
195 return L'/' + ChangeSlashToPDF(view);
197 return ChangeSlashToPDF(view);
fxcrt::ByteString ByteString
WideString GetUnicodeTextFor(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
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)
fxcrt::WideString WideString