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_pageobjectholder.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/fpdfapi/page/cpdf_pageobjectholder.h"
8
9
#
include
<
algorithm
>
10
#
include
<
utility
>
11
12
#
include
"constants/transparency.h"
13
#
include
"core/fpdfapi/page/cpdf_allstates.h"
14
#
include
"core/fpdfapi/page/cpdf_contentparser.h"
15
#
include
"core/fpdfapi/page/cpdf_pageobject.h"
16
#
include
"core/fpdfapi/parser/cpdf_dictionary.h"
17
#
include
"core/fpdfapi/parser/cpdf_document.h"
18
#
include
"core/fxcrt/check.h"
19
#
include
"core/fxcrt/check_op.h"
20
#
include
"core/fxcrt/fx_extension.h"
21
#
include
"core/fxcrt/stl_util.h"
22
23
bool
GraphicsData
::
operator
<(
const
GraphicsData
& other)
const
{
24
if
(!FXSYS_SafeEQ(
fillAlpha
, other
.
fillAlpha
))
25
return
FXSYS_SafeLT(
fillAlpha
, other
.
fillAlpha
);
26
if
(!FXSYS_SafeEQ(
strokeAlpha
, other
.
strokeAlpha
))
27
return
FXSYS_SafeLT(
strokeAlpha
, other
.
strokeAlpha
);
28
return
blendType
< other
.
blendType
;
29
}
30
31
bool
FontData
::
operator
<(
const
FontData
& other)
const
{
32
if
(baseFont != other.baseFont)
33
return
baseFont < other.baseFont;
34
return
type < other.type;
35
}
36
37
CPDF_PageObjectHolder
::
CPDF_PageObjectHolder
(
38
CPDF_Document
* pDoc,
39
RetainPtr
<
CPDF_Dictionary
> pDict,
40
RetainPtr
<
CPDF_Dictionary
> pPageResources,
41
RetainPtr
<
CPDF_Dictionary
> pResources)
42
:
m_pPageResources
(
std
::
move
(
pPageResources
)),
43
m_pResources
(
std
::
move
(
pResources
)),
44
m_pDict
(
std
::
move
(
pDict
)),
45
m_pDocument
(
pDoc
) {
46
DCHECK
(m_pDict);
47
}
48
49
CPDF_PageObjectHolder
::~
CPDF_PageObjectHolder
() =
default
;
50
51
bool
CPDF_PageObjectHolder
::
IsPage
()
const
{
52
return
false
;
53
}
54
55
void
CPDF_PageObjectHolder
::
StartParse
(
56
std::unique_ptr<CPDF_ContentParser> pParser) {
57
DCHECK_EQ
(m_ParseState,
ParseState
::
kNotParsed
);
58
m_pParser = std::move(pParser);
59
m_ParseState =
ParseState
::
kParsing
;
60
}
61
62
void
CPDF_PageObjectHolder
::
ContinueParse
(
PauseIndicatorIface
* pPause) {
63
if
(m_ParseState ==
ParseState
::
kParsed
)
64
return
;
65
66
DCHECK_EQ
(m_ParseState,
ParseState
::
kParsing
);
67
if
(m_pParser->Continue(pPause))
68
return
;
69
70
m_ParseState =
ParseState
::
kParsed
;
71
m_pDocument->IncrementParsedPageCount();
72
m_AllCTMs = m_pParser->TakeAllCTMs();
73
74
m_pParser.reset();
75
}
76
77
void
CPDF_PageObjectHolder
::
AddImageMaskBoundingBox
(
const
CFX_FloatRect
& box) {
78
m_MaskBoundingBoxes.push_back(box);
79
}
80
81
std
::
set
<
int32_t
>
CPDF_PageObjectHolder
::
TakeDirtyStreams
() {
82
auto
dirty_streams =
std
::move(m_DirtyStreams);
83
m_DirtyStreams.clear();
84
return
dirty_streams;
85
}
86
87
std
::optional<
ByteString
>
CPDF_PageObjectHolder
::
GraphicsMapSearch
(
88
const
GraphicsData
& gd) {
89
auto
it = m_GraphicsMap.find(gd);
90
if
(it == m_GraphicsMap.end())
91
return
std
::nullopt;
92
93
return
it->second;
94
}
95
96
void
CPDF_PageObjectHolder
::
GraphicsMapInsert
(
const
GraphicsData
& gd,
97
const
ByteString
& str) {
98
m_GraphicsMap[gd] = str;
99
}
100
101
std
::optional<
ByteString
>
CPDF_PageObjectHolder
::
FontsMapSearch
(
102
const
FontData
& fd) {
103
auto
it = m_FontsMap.find(fd);
104
if
(it == m_FontsMap.end())
105
return
std
::nullopt;
106
107
return
it->second;
108
}
109
110
void
CPDF_PageObjectHolder
::
FontsMapInsert
(
const
FontData
& fd,
111
const
ByteString
& str) {
112
m_FontsMap[fd] = str;
113
}
114
115
CFX_Matrix
CPDF_PageObjectHolder
::
GetCTMAtBeginningOfStream
(int32_t stream) {
116
CHECK
(stream >= 0 || stream ==
CPDF_PageObject
::
kNoContentStream
);
117
118
if
(stream == 0 || m_AllCTMs.empty()) {
119
return
CFX_Matrix
(
)
;
120
}
121
122
if
(stream ==
CPDF_PageObject
::
kNoContentStream
) {
123
return
m_AllCTMs.rbegin()->second;
124
}
125
126
// For all other cases, CTM at beginning of `stream` is the same value as CTM
127
// at the end of the previous stream.
128
return
GetCTMAtEndOfStream
(
stream - 1
)
;
129
}
130
131
CFX_Matrix
CPDF_PageObjectHolder
::
GetCTMAtEndOfStream
(int32_t stream) {
132
// This code should never need to calculate the CTM for the end of
133
// `CPDF_PageObject::kNoContentStream`, which uses a negative sentinel value.
134
// All other streams have a non-negative index.
135
CHECK_GE
(stream, 0);
136
137
if
(m_AllCTMs.empty()) {
138
return
CFX_Matrix
(
)
;
139
}
140
141
const
auto
it = m_AllCTMs.lower_bound(stream);
142
return
it != m_AllCTMs.end() ? it->second : m_AllCTMs.rbegin()->second;
143
}
144
145
void
CPDF_PageObjectHolder
::
LoadTransparencyInfo
() {
146
RetainPtr
<
const
CPDF_Dictionary
> pGroup = m_pDict->GetDictFor(
"Group"
);
147
if
(!pGroup)
148
return
;
149
150
if
(pGroup->GetByteStringFor(
pdfium
::
transparency
::
kGroupSubType
) !=
151
pdfium
::
transparency
::
kTransparency
) {
152
return
;
153
}
154
m_Transparency
.
SetGroup
(
)
;
155
if
(pGroup->GetIntegerFor(
pdfium
::
transparency
::
kI
))
156
m_Transparency
.
SetIsolated
(
)
;
157
}
158
159
CPDF_PageObject
*
CPDF_PageObjectHolder
::
GetPageObjectByIndex
(
160
size_t index)
const
{
161
return
fxcrt::IndexInBounds(m_PageObjectList, index)
162
? m_PageObjectList[index].get()
163
:
nullptr
;
164
}
165
166
void
CPDF_PageObjectHolder
::
AppendPageObject
(
167
std::unique_ptr<CPDF_PageObject> pPageObj) {
168
CHECK
(pPageObj);
169
m_PageObjectList.push_back(std::move(pPageObj));
170
}
171
172
std
::
unique_ptr
<
CPDF_PageObject
>
CPDF_PageObjectHolder
::
RemovePageObject
(
173
CPDF_PageObject
* pPageObj) {
174
auto
it =
std
::find(
std
::begin(m_PageObjectList),
std
::end(m_PageObjectList),
175
fxcrt
::MakeFakeUniquePtr(pPageObj));
176
if
(it ==
std
::end(m_PageObjectList))
177
return
nullptr
;
178
179
std::unique_ptr<CPDF_PageObject> result =
std
::move(*it);
180
m_PageObjectList.erase(it);
181
182
int32_t content_stream = pPageObj
->
GetContentStream
(
)
;
183
if
(content_stream >= 0)
184
m_DirtyStreams.insert(content_stream);
185
186
return
result;
187
}
188
189
bool
CPDF_PageObjectHolder
::
ErasePageObjectAtIndex
(size_t index) {
190
if
(index >= m_PageObjectList.size())
191
return
false
;
192
193
m_PageObjectList.erase(m_PageObjectList.begin() + index);
194
return
true
;
195
}
ByteString
fxcrt::ByteString ByteString
Definition
bytestring.h:180
DCHECK
#define DCHECK
Definition
check.h:33
CHECK_GE
#define CHECK_GE(x, y)
Definition
check_op.h:15
DCHECK_EQ
#define DCHECK_EQ(x, y)
Definition
check_op.h:17
CFX_FloatRect
Definition
fx_coordinates.h:185
CFX_Matrix
Definition
fx_coordinates.h:440
CFX_Matrix::CFX_Matrix
constexpr CFX_Matrix()=default
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_PageObjectHolder
Definition
cpdf_pageobjectholder.h:51
CPDF_PageObjectHolder::StartParse
void StartParse(std::unique_ptr< CPDF_ContentParser > pParser)
Definition
cpdf_pageobjectholder.cpp:55
CPDF_PageObjectHolder::IsPage
virtual bool IsPage() const
Definition
cpdf_pageobjectholder.cpp:51
CPDF_PageObjectHolder::GraphicsMapSearch
std::optional< ByteString > GraphicsMapSearch(const GraphicsData &gd)
Definition
cpdf_pageobjectholder.cpp:87
CPDF_PageObjectHolder::~CPDF_PageObjectHolder
virtual ~CPDF_PageObjectHolder()
CPDF_PageObjectHolder::GraphicsMapInsert
void GraphicsMapInsert(const GraphicsData &gd, const ByteString &str)
Definition
cpdf_pageobjectholder.cpp:96
CPDF_PageObjectHolder::AddImageMaskBoundingBox
void AddImageMaskBoundingBox(const CFX_FloatRect &box)
Definition
cpdf_pageobjectholder.cpp:77
CPDF_PageObjectHolder::LoadTransparencyInfo
void LoadTransparencyInfo()
Definition
cpdf_pageobjectholder.cpp:145
CPDF_PageObjectHolder::AppendPageObject
void AppendPageObject(std::unique_ptr< CPDF_PageObject > pPageObj)
Definition
cpdf_pageobjectholder.cpp:166
CPDF_PageObjectHolder::FontsMapInsert
void FontsMapInsert(const FontData &fd, const ByteString &str)
Definition
cpdf_pageobjectholder.cpp:110
CPDF_PageObjectHolder::ErasePageObjectAtIndex
bool ErasePageObjectAtIndex(size_t index)
Definition
cpdf_pageobjectholder.cpp:189
CPDF_PageObjectHolder::CPDF_PageObjectHolder
CPDF_PageObjectHolder(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pDict, RetainPtr< CPDF_Dictionary > pPageResources, RetainPtr< CPDF_Dictionary > pResources)
Definition
cpdf_pageobjectholder.cpp:37
CPDF_PageObjectHolder::ContinueParse
void ContinueParse(PauseIndicatorIface *pPause)
Definition
cpdf_pageobjectholder.cpp:62
CPDF_PageObjectHolder::GetPageObjectByIndex
CPDF_PageObject * GetPageObjectByIndex(size_t index) const
Definition
cpdf_pageobjectholder.cpp:159
CPDF_PageObjectHolder::RemovePageObject
std::unique_ptr< CPDF_PageObject > RemovePageObject(CPDF_PageObject *pPageObj)
Definition
cpdf_pageobjectholder.cpp:172
CPDF_PageObjectHolder::ParseState
ParseState
Definition
cpdf_pageobjectholder.h:53
CPDF_PageObjectHolder::ParseState::kNotParsed
@ kNotParsed
Definition
cpdf_pageobjectholder.h:53
CPDF_PageObjectHolder::ParseState::kParsing
@ kParsing
Definition
cpdf_pageobjectholder.h:53
CPDF_PageObjectHolder::ParseState::kParsed
@ kParsed
Definition
cpdf_pageobjectholder.h:53
CPDF_PageObjectHolder::GetCTMAtBeginningOfStream
CFX_Matrix GetCTMAtBeginningOfStream(int32_t stream)
Definition
cpdf_pageobjectholder.cpp:115
CPDF_PageObjectHolder::m_Transparency
CPDF_Transparency m_Transparency
Definition
cpdf_pageobjectholder.h:139
CPDF_PageObjectHolder::GetCTMAtEndOfStream
CFX_Matrix GetCTMAtEndOfStream(int32_t stream)
Definition
cpdf_pageobjectholder.cpp:131
CPDF_PageObjectHolder::FontsMapSearch
std::optional< ByteString > FontsMapSearch(const FontData &fd)
Definition
cpdf_pageobjectholder.cpp:101
CPDF_PageObjectHolder::TakeDirtyStreams
std::set< int32_t > TakeDirtyStreams()
Definition
cpdf_pageobjectholder.cpp:81
CPDF_PageObject
Definition
cpdf_pageobject.h:27
CPDF_PageObject::kNoContentStream
static constexpr int32_t kNoContentStream
Definition
cpdf_pageobject.h:38
CPDF_PageObject::GetContentStream
int32_t GetContentStream() const
Definition
cpdf_pageobject.h:87
CPDF_Transparency::SetIsolated
void SetIsolated()
Definition
cpdf_transparency.h:19
CPDF_Transparency::SetGroup
void SetGroup()
Definition
cpdf_transparency.h:18
PauseIndicatorIface
Definition
pauseindicator_iface.h:10
fxcrt::RetainPtr
Definition
retain_ptr.h:28
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
fxcrt
Definition
stl_util.h:17
pdfium::transparency
Definition
transparency.cpp:7
pdfium::transparency::kI
const char kI[]
Definition
transparency.cpp:44
pdfium::transparency::kTransparency
const char kTransparency[]
Definition
transparency.cpp:42
pdfium::transparency::kGroupSubType
const char kGroupSubType[]
Definition
transparency.cpp:41
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
CHECK
#define CHECK(cvref)
Definition
q23utility.cpp:15
FontData
Definition
cpdf_pageobjectholder.h:44
FontData::operator<
bool operator<(const FontData &other) const
Definition
cpdf_pageobjectholder.cpp:31
GraphicsData
Definition
cpdf_pageobjectholder.h:36
GraphicsData::blendType
BlendMode blendType
Definition
cpdf_pageobjectholder.h:39
GraphicsData::strokeAlpha
float strokeAlpha
Definition
cpdf_pageobjectholder.h:38
GraphicsData::fillAlpha
float fillAlpha
Definition
cpdf_pageobjectholder.h:37
GraphicsData::operator<
bool operator<(const GraphicsData &other) const
Definition
cpdf_pageobjectholder.cpp:23
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfapi
page
cpdf_pageobjectholder.cpp
Generated on
for Qt by
1.18.0