Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
23bool 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
31bool FontData::operator<(const FontData& other) const {
32 if (baseFont != other.baseFont)
33 return baseFont < other.baseFont;
34 return type < other.type;
35}
36
48
50
52 return false;
53}
54
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
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
78 m_MaskBoundingBoxes.push_back(box);
79}
80
82 auto dirty_streams = std::move(m_DirtyStreams);
83 m_DirtyStreams.clear();
84 return dirty_streams;
85}
86
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
97 const ByteString& str) {
98 m_GraphicsMap[gd] = str;
99}
100
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
111 const ByteString& str) {
112 m_FontsMap[fd] = str;
113}
114
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
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
146 RetainPtr<const CPDF_Dictionary> pGroup = m_pDict->GetDictFor("Group");
147 if (!pGroup)
148 return;
149
150 if (pGroup->GetByteStringFor(pdfium::transparency::kGroupSubType) !=
152 return;
153 }
155 if (pGroup->GetIntegerFor(pdfium::transparency::kI))
157}
158
160 size_t index) const {
161 return fxcrt::IndexInBounds(m_PageObjectList, index)
162 ? m_PageObjectList[index].get()
163 : nullptr;
164}
165
167 std::unique_ptr<CPDF_PageObject> pPageObj) {
168 CHECK(pPageObj);
169 m_PageObjectList.push_back(std::move(pPageObj));
170}
171
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
190 if (index >= m_PageObjectList.size())
191 return false;
192
193 m_PageObjectList.erase(m_PageObjectList.begin() + index);
194 return true;
195}
fxcrt::ByteString ByteString
Definition bytestring.h:180
#define DCHECK
Definition check.h:33
#define CHECK_GE(x, y)
Definition check_op.h:15
#define DCHECK_EQ(x, y)
Definition check_op.h:17
constexpr CFX_Matrix()=default
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
void StartParse(std::unique_ptr< CPDF_ContentParser > pParser)
virtual bool IsPage() const
std::optional< ByteString > GraphicsMapSearch(const GraphicsData &gd)
virtual ~CPDF_PageObjectHolder()
void GraphicsMapInsert(const GraphicsData &gd, const ByteString &str)
void AddImageMaskBoundingBox(const CFX_FloatRect &box)
void AppendPageObject(std::unique_ptr< CPDF_PageObject > pPageObj)
void FontsMapInsert(const FontData &fd, const ByteString &str)
bool ErasePageObjectAtIndex(size_t index)
CPDF_PageObjectHolder(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pDict, RetainPtr< CPDF_Dictionary > pPageResources, RetainPtr< CPDF_Dictionary > pResources)
void ContinueParse(PauseIndicatorIface *pPause)
CPDF_PageObject * GetPageObjectByIndex(size_t index) const
std::unique_ptr< CPDF_PageObject > RemovePageObject(CPDF_PageObject *pPageObj)
CFX_Matrix GetCTMAtBeginningOfStream(int32_t stream)
CPDF_Transparency m_Transparency
CFX_Matrix GetCTMAtEndOfStream(int32_t stream)
std::optional< ByteString > FontsMapSearch(const FontData &fd)
std::set< int32_t > TakeDirtyStreams()
static constexpr int32_t kNoContentStream
int32_t GetContentStream() const
const char kTransparency[]
const char kGroupSubType[]
#define CHECK(cvref)
bool operator<(const FontData &other) const
bool operator<(const GraphicsData &other) const