summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_filespec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc/cpdf_filespec.cpp')
-rw-r--r--core/fpdfdoc/cpdf_filespec.cpp49
1 files changed, 44 insertions, 5 deletions
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index 59915eaa05..7d1f0e68b9 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -6,9 +6,12 @@
#include "core/fpdfdoc/cpdf_filespec.h"
+#include <vector>
+
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_object.h"
+#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fxcrt/fx_system.h"
@@ -50,6 +53,12 @@ CFX_WideString ChangeSlashToPDF(const wchar_t* str) {
} // namespace
+CPDF_FileSpec::CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {
+ ASSERT(m_pObj);
+}
+
+CPDF_FileSpec::~CPDF_FileSpec() {}
+
CFX_WideString CPDF_FileSpec::DecodeFileName(const CFX_WideString& filepath) {
if (filepath.GetLength() <= 1)
return CFX_WideString();
@@ -112,9 +121,42 @@ bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const {
return true;
}
-CPDF_FileSpec::CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {}
+CPDF_Stream* CPDF_FileSpec::GetFileStream() const {
+ CPDF_Dictionary* pDict = m_pObj->AsDictionary();
+ if (!pDict)
+ return nullptr;
+
+ // Get the embedded files dictionary.
+ CPDF_Dictionary* pFiles = pDict->GetDictFor("EF");
+ if (!pFiles)
+ return nullptr;
+
+ // Get the file stream of the highest precedence with its file specification
+ // string available. Follows the same precedence order as GetFileName().
+ constexpr const char* keys[] = {"UF", "F", "DOS", "Mac", "Unix"};
+ size_t end = pDict->GetStringFor("FS") == "URL" ? 2 : FX_ArraySize(keys);
+ for (size_t i = 0; i < end; ++i) {
+ const CFX_ByteString& key = keys[i];
+ if (!pDict->GetUnicodeTextFor(key).IsEmpty()) {
+ CPDF_Stream* pStream = pFiles->GetStreamFor(key);
+ if (pStream)
+ return pStream;
+ }
+ }
+ return nullptr;
+}
-CPDF_FileSpec::~CPDF_FileSpec() {}
+CPDF_Dictionary* CPDF_FileSpec::GetParamsDict() const {
+ CPDF_Stream* pStream = GetFileStream();
+ if (!pStream)
+ return nullptr;
+
+ CPDF_Dictionary* pDict = pStream->GetDict();
+ if (!pDict)
+ return nullptr;
+
+ return pDict->GetDictFor("Params");
+}
CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideString& filepath) {
if (filepath.GetLength() <= 1)
@@ -146,9 +188,6 @@ CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideString& filepath) {
}
void CPDF_FileSpec::SetFileName(const CFX_WideString& wsFileName) {
- if (!m_pObj)
- return;
-
CFX_WideString wsStr = EncodeFileName(wsFileName);
if (m_pObj->IsString()) {
m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr));