Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cpdf_action.cpp
Go to the documentation of this file.
1
// Copyright 2016 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fpdfdoc/cpdf_action.h"
8
9
#
include
<
array
>
10
#
include
<
iterator
>
11
#
include
<
utility
>
12
13
#
include
"constants/stream_dict_common.h"
14
#
include
"core/fpdfapi/parser/cpdf_array.h"
15
#
include
"core/fpdfapi/parser/cpdf_dictionary.h"
16
#
include
"core/fpdfapi/parser/cpdf_document.h"
17
#
include
"core/fpdfapi/parser/cpdf_name.h"
18
#
include
"core/fpdfapi/parser/fpdf_parser_utility.h"
19
#
include
"core/fpdfdoc/cpdf_filespec.h"
20
#
include
"core/fxcrt/stl_util.h"
21
22
namespace
{
23
24
constexpr
auto
kActionTypeStrings =
fxcrt
::ToArray<
const
char
*>({
25
"GoTo"
,
26
"GoToR"
,
27
"GoToE"
,
28
"Launch"
,
29
"Thread"
,
30
"URI"
,
31
"Sound"
,
32
"Movie"
,
33
"Hide"
,
34
"Named"
,
35
"SubmitForm"
,
36
"ResetForm"
,
37
"ImportData"
,
38
"JavaScript"
,
39
"SetOCGState"
,
40
"Rendition"
,
41
"Trans"
,
42
"GoTo3DView"
,
43
});
44
45
}
// namespace
46
47
CPDF_Action
::
CPDF_Action
(
RetainPtr
<
const
CPDF_Dictionary
> pDict)
48
:
m_pDict
(
std
::
move
(
pDict
)) {}
49
50
CPDF_Action
::
CPDF_Action
(
const
CPDF_Action
& that) =
default
;
51
52
CPDF_Action
::~
CPDF_Action
() =
default
;
53
54
CPDF_Action
::
Type
CPDF_Action
::
GetType
()
const
{
55
// See ISO 32000-1:2008 spec, table 193.
56
if
(!ValidateDictOptionalType(m_pDict.Get(),
"Action"
))
57
return
Type
::
kUnknown
;
58
59
ByteString
csType = m_pDict->GetNameFor(
"S"
);
60
if
(csType.IsEmpty())
61
return
Type
::
kUnknown
;
62
63
static_assert
(
64
std
::size(kActionTypeStrings) ==
static_cast
<size_t>(
Type
::
kLast
),
65
"Type mismatch"
);
66
for
(size_t i = 0; i <
std
::size(kActionTypeStrings); ++i) {
67
if
(csType == kActionTypeStrings[i])
68
return
static_cast
<
Type
>(i + 1);
69
}
70
return
Type
::
kUnknown
;
71
}
72
73
CPDF_Dest
CPDF_Action
::
GetDest
(
CPDF_Document
* pDoc)
const
{
74
Type
type =
GetType
(
)
;
75
if
(type !=
Type
::
kGoTo
&& type !=
Type
::
kGoToR
&& type !=
Type
::
kGoToE
) {
76
return
CPDF_Dest(
nullptr
);
77
}
78
return
CPDF_Dest
::
Create
(pDoc, m_pDict->GetDirectObjectFor(
"D"
));
79
}
80
81
WideString
CPDF_Action
::
GetFilePath
()
const
{
82
Type
type =
GetType
(
)
;
83
if
(type !=
Type
::
kGoToR
&& type !=
Type
::
kGoToE
&& type !=
Type
::
kLaunch
&&
84
type !=
Type
::
kSubmitForm
&& type !=
Type
::
kImportData
) {
85
return
WideString
(
)
;
86
}
87
88
RetainPtr
<
const
CPDF_Object
> pFile =
89
m_pDict->GetDirectObjectFor(pdfium::stream::kF);
90
if
(pFile)
91
return
CPDF_FileSpec
(
std
::move(pFile))
.
GetFileName
(
)
;
92
93
if
(type !=
Type
::
kLaunch
)
94
return
WideString
(
)
;
95
96
RetainPtr
<
const
CPDF_Dictionary
> pWinDict = m_pDict->GetDictFor(
"Win"
);
97
if
(!pWinDict)
98
return
WideString
(
)
;
99
100
return
WideString
::
FromDefANSI
(
101
pWinDict->GetByteStringFor(
pdfium
::
stream
::
kF
).AsStringView()
)
;
102
}
103
104
ByteString
CPDF_Action
::
GetURI
(
const
CPDF_Document
* pDoc)
const
{
105
if
(
GetType
(
)
!=
Type
::
kURI
)
106
return
ByteString
(
)
;
107
108
ByteString
csURI = m_pDict->GetByteStringFor(
"URI"
);
109
RetainPtr
<
const
CPDF_Dictionary
> pURI = pDoc->GetRoot()->GetDictFor(
"URI"
);
110
if
(pURI) {
111
auto
result = csURI.Find(
":"
);
112
if
(!result.has_value() || result.value() == 0) {
113
RetainPtr
<
const
CPDF_Object
> pBase = pURI->GetDirectObjectFor(
"Base"
);
114
if
(pBase && (pBase->IsString() || pBase->IsStream()))
115
csURI = pBase->GetString() + csURI;
116
}
117
}
118
return
csURI;
119
}
120
121
bool
CPDF_Action
::
GetHideStatus
()
const
{
122
return
m_pDict->GetBooleanFor(
"H"
,
true
);
123
}
124
125
ByteString
CPDF_Action
::
GetNamedAction
()
const
{
126
return
m_pDict->GetByteStringFor(
"N"
);
127
}
128
129
uint32_t
CPDF_Action
::
GetFlags
()
const
{
130
return
m_pDict->GetIntegerFor(
"Flags"
);
131
}
132
133
bool
CPDF_Action
::
HasFields
()
const
{
134
return
m_pDict->KeyExist(
"Fields"
);
135
}
136
137
std
::
vector
<
RetainPtr
<
const
CPDF_Object
>>
CPDF_Action
::
GetAllFields
()
const
{
138
std::vector<RetainPtr<
const
CPDF_Object>> result;
139
if
(!m_pDict)
140
return
result;
141
142
ByteString
csType = m_pDict->GetByteStringFor(
"S"
);
143
RetainPtr
<
const
CPDF_Object
> pFields = csType ==
"Hide"
144
? m_pDict->GetDirectObjectFor(
"T"
)
145
: m_pDict->GetArrayFor(
"Fields"
);
146
if
(!pFields)
147
return
result;
148
149
if
(pFields->IsDictionary() || pFields->IsString()) {
150
result.push_back(
std
::move(pFields));
151
return
result;
152
}
153
154
const
CPDF_Array
* pArray = pFields->AsArray();
155
if
(!pArray)
156
return
result;
157
158
for
(size_t i = 0; i < pArray->size(); ++i) {
159
RetainPtr
<
const
CPDF_Object
> pObj = pArray->GetDirectObjectAt(i);
160
if
(pObj)
161
result.push_back(
std
::move(pObj));
162
}
163
return
result;
164
}
165
166
std
::optional<
WideString
>
CPDF_Action
::
MaybeGetJavaScript
()
const
{
167
RetainPtr
<
const
CPDF_Object
> pObject = GetJavaScriptObject();
168
if
(!pObject)
169
return
std
::nullopt;
170
return
pObject->GetUnicodeText();
171
}
172
173
WideString
CPDF_Action
::
GetJavaScript
()
const
{
174
RetainPtr
<
const
CPDF_Object
> pObject = GetJavaScriptObject();
175
return
pObject ? pObject->GetUnicodeText() :
WideString
(
)
;
176
}
177
178
size_t
CPDF_Action
::
GetSubActionsCount
()
const
{
179
if
(!m_pDict || !m_pDict->KeyExist(
"Next"
))
180
return
0;
181
182
RetainPtr
<
const
CPDF_Object
> pNext = m_pDict->GetDirectObjectFor(
"Next"
);
183
if
(!pNext)
184
return
0;
185
if
(pNext->IsDictionary())
186
return
1;
187
const
CPDF_Array
* pArray = pNext->AsArray();
188
return
pArray ? pArray->size() : 0;
189
}
190
191
CPDF_Action
CPDF_Action
::
GetSubAction
(size_t iIndex)
const
{
192
if
(!m_pDict || !m_pDict->KeyExist(
"Next"
))
193
return
CPDF_Action(
nullptr
);
194
195
RetainPtr
<
const
CPDF_Object
> pNext = m_pDict->GetDirectObjectFor(
"Next"
);
196
if
(!pNext)
197
return
CPDF_Action(
nullptr
);
198
199
if
(
const
CPDF_Array
* pArray = pNext->AsArray())
200
return
CPDF_Action
(pArray->GetDictAt(iIndex));
201
202
if
(
const
CPDF_Dictionary
* pDict = pNext->AsDictionary()) {
203
if
(iIndex == 0)
204
return
CPDF_Action
(
pdfium
::WrapRetain(pDict));
205
}
206
return
CPDF_Action(
nullptr
);
207
}
208
209
RetainPtr
<
const
CPDF_Object
>
CPDF_Action
::GetJavaScriptObject()
const
{
210
if
(!m_pDict)
211
return
nullptr
;
212
213
RetainPtr
<
const
CPDF_Object
> pJS = m_pDict->GetDirectObjectFor(
"JS"
);
214
return
(pJS && (pJS->IsString() || pJS->IsStream())) ? pJS :
nullptr
;
215
}
ByteString
fxcrt::ByteString ByteString
Definition
bytestring.h:180
CPDF_Action
Definition
cpdf_action.h:21
CPDF_Action::CPDF_Action
CPDF_Action(RetainPtr< const CPDF_Dictionary > pDict)
Definition
cpdf_action.cpp:47
CPDF_Action::GetSubActionsCount
size_t GetSubActionsCount() const
Definition
cpdf_action.cpp:178
CPDF_Action::GetDest
CPDF_Dest GetDest(CPDF_Document *pDoc) const
Definition
cpdf_action.cpp:73
CPDF_Action::GetSubAction
CPDF_Action GetSubAction(size_t iIndex) const
Definition
cpdf_action.cpp:191
CPDF_Action::CPDF_Action
CPDF_Action(const CPDF_Action &that)
CPDF_Action::GetFilePath
WideString GetFilePath() const
Definition
cpdf_action.cpp:81
CPDF_Action::MaybeGetJavaScript
std::optional< WideString > MaybeGetJavaScript() const
Definition
cpdf_action.cpp:166
CPDF_Action::GetAllFields
std::vector< RetainPtr< const CPDF_Object > > GetAllFields() const
Definition
cpdf_action.cpp:137
CPDF_Action::Type
Type
Definition
cpdf_action.h:23
CPDF_Action::Type::kGoToR
@ kGoToR
Definition
cpdf_action.h:26
CPDF_Action::Type::kURI
@ kURI
Definition
cpdf_action.h:30
CPDF_Action::Type::kUnknown
@ kUnknown
Definition
cpdf_action.h:24
CPDF_Action::Type::kGoTo
@ kGoTo
Definition
cpdf_action.h:25
CPDF_Action::Type::kLast
@ kLast
Definition
cpdf_action.h:43
CPDF_Action::Type::kImportData
@ kImportData
Definition
cpdf_action.h:37
CPDF_Action::Type::kSubmitForm
@ kSubmitForm
Definition
cpdf_action.h:35
CPDF_Action::Type::kLaunch
@ kLaunch
Definition
cpdf_action.h:28
CPDF_Action::Type::kGoToE
@ kGoToE
Definition
cpdf_action.h:27
CPDF_Action::GetType
Type GetType() const
Definition
cpdf_action.cpp:54
CPDF_Action::GetURI
ByteString GetURI(const CPDF_Document *pDoc) const
Definition
cpdf_action.cpp:104
CPDF_Action::GetFlags
uint32_t GetFlags() const
Definition
cpdf_action.cpp:129
CPDF_Action::GetHideStatus
bool GetHideStatus() const
Definition
cpdf_action.cpp:121
CPDF_Action::~CPDF_Action
~CPDF_Action()
CPDF_Action::GetJavaScript
WideString GetJavaScript() const
Definition
cpdf_action.cpp:173
CPDF_Action::GetNamedAction
ByteString GetNamedAction() const
Definition
cpdf_action.cpp:125
CPDF_Action::HasFields
bool HasFields() const
Definition
cpdf_action.cpp:133
CPDF_Array::const_iterator
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
Definition
cpdf_array.h:29
CPDF_Dest
Definition
cpdf_dest.h:18
CPDF_Dest::Create
static CPDF_Dest Create(CPDF_Document *pDoc, RetainPtr< const CPDF_Object > pDest)
Definition
cpdf_dest.cpp:41
CPDF_Dictionary::DictMap
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
Definition
cpdf_dictionary.h:31
CPDF_Document
Definition
cpdf_document.h:29
CPDF_FileSpec
Definition
cpdf_filespec.h:19
CPDF_FileSpec::GetFileName
WideString GetFileName() const
Definition
cpdf_filespec.cpp:101
CPDF_Object
Definition
cpdf_object.h:50
fxcrt::ByteString::ByteString
ByteString()=default
fxcrt::RetainPtr
Definition
retain_ptr.h:28
fxcrt::WideString::WideString
WideString()=default
fxcrt::WideString::FromDefANSI
static WideString FromDefANSI(ByteStringView str)
Definition
widestring.cpp:722
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
fxcrt
Definition
stl_util.h:17
pdfium::stream
Definition
stream_dict_common.cpp:7
pdfium::stream::kF
const char kF[]
Definition
stream_dict_common.cpp:17
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfdoc
cpdf_action.cpp
Generated on
for Qt by
1.18.0