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_streamcontentparser.h
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#ifndef CORE_FPDFAPI_PAGE_CPDF_STREAMCONTENTPARSER_H_
8#define CORE_FPDFAPI_PAGE_CPDF_STREAMCONTENTPARSER_H_
9
10#include <array>
11#include <memory>
12#include <stack>
13#include <vector>
14
15#include "core/fpdfapi/page/cpdf_contentmarks.h"
16#include "core/fpdfapi/page/cpdf_form.h"
17#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
18#include "core/fxcrt/bytestring.h"
19#include "core/fxcrt/fx_coordinates.h"
20#include "core/fxcrt/fx_number.h"
21#include "core/fxcrt/retain_ptr.h"
22#include "core/fxcrt/span.h"
23#include "core/fxcrt/unowned_ptr.h"
24#include "core/fxge/cfx_fillrenderoptions.h"
25#include "core/fxge/cfx_path.h"
26
27class CPDF_AllStates;
28class CPDF_ColorSpace;
29class CPDF_Dictionary;
30class CPDF_Document;
31class CPDF_Font;
32class CPDF_Image;
33class CPDF_ImageObject;
34class CPDF_Object;
35class CPDF_PageObject;
36class CPDF_Pattern;
37class CPDF_ShadingPattern;
38class CPDF_Stream;
40class CPDF_TextObject;
41
43 public:
44 static void InitializeGlobals();
45 static void DestroyGlobals();
46
48 RetainPtr<CPDF_Dictionary> pPageResources,
49 RetainPtr<CPDF_Dictionary> pParentResources,
50 const CFX_Matrix* pmtContentToUser,
51 CPDF_PageObjectHolder* pObjHolder,
52 RetainPtr<CPDF_Dictionary> pResources,
53 const CFX_FloatRect& rcBBox,
54 const CPDF_AllStates* pStates,
55 CPDF_Form::RecursionState* parse_state);
57
58 uint32_t Parse(pdfium::span<const uint8_t> pData,
59 uint32_t start_offset,
60 uint32_t max_cost,
61 const std::vector<uint32_t>& stream_start_offsets);
62 CPDF_PageObjectHolder* GetPageObjectHolder() const { return m_pObjectHolder; }
63 CPDF_AllStates* GetCurStates() const { return m_pCurStates.get(); }
64 bool IsColored() const { return m_bColored; }
65 pdfium::span<const float> GetType3Data() const { return m_Type3Data; }
68
71
72 private:
73 enum class RenderType : bool { kFill = false, kStroke = true };
74
75 struct ContentParam {
76 enum class Type : uint8_t { kObject = 0, kNumber, kName };
77
78 ContentParam();
79 ~ContentParam();
80
81 Type m_Type = Type::kObject;
82 FX_Number m_Number;
83 ByteString m_Name;
84 RetainPtr<CPDF_Object> m_pObject;
85 };
86
87 static constexpr int kParamBufSize = 16;
88
89 void AddNameParam(ByteStringView bsName);
90 void AddNumberParam(ByteStringView str);
91 void AddObjectParam(RetainPtr<CPDF_Object> pObj);
92 int GetNextParamPos();
93 void ClearAllParams();
94 RetainPtr<CPDF_Object> GetObject(uint32_t index);
95 ByteString GetString(uint32_t index) const;
96 float GetNumber(uint32_t index) const;
97 // Calls GetNumber() |count| times and returns the values in reverse order.
98 // e.g. for |count| = 3, returns [GetNumber(2), GetNumber(1), GetNumber(0)].
99 std::vector<float> GetNumbers(size_t count) const;
100 int GetInteger(uint32_t index) const {
101 return static_cast<int>(GetNumber(index));
102 }
103 // Makes a point from {GetNumber(index + 1), GetNumber(index)}.
104 CFX_PointF GetPoint(uint32_t index) const;
105 // Makes a matrix from {GetNumber(5), ..., GetNumber(0)}.
106 CFX_Matrix GetMatrix() const;
107 void OnOperator(ByteStringView op);
108 void AddTextObject(pdfium::span<const ByteString> strings,
109 pdfium::span<const float> kernings,
110 float initial_kerning);
111 float GetHorizontalTextSize(float fKerning) const;
112 float GetVerticalTextSize(float fKerning) const;
113
114 void OnChangeTextMatrix();
115 void ParsePathObject();
116 void AddPathPoint(const CFX_PointF& point, CFX_Path::Point::Type type);
117 void AddPathPointAndClose(const CFX_PointF& point,
118 CFX_Path::Point::Type type);
119 void AddPathRect(float x, float y, float w, float h);
120 void AddPathObject(CFX_FillRenderOptions::FillType fill_type,
121 RenderType render_type);
122 CPDF_ImageObject* AddImageFromStream(RetainPtr<CPDF_Stream> pStream,
123 const ByteString& name);
124 CPDF_ImageObject* AddImageFromStreamObjNum(uint32_t stream_obj_num,
125 const ByteString& name);
126 CPDF_ImageObject* AddLastImage();
127
128 void AddForm(RetainPtr<CPDF_Stream> pStream, const ByteString& name);
129 void SetGraphicStates(CPDF_PageObject* pObj,
130 bool bColor,
131 bool bText,
132 bool bGraph);
133 RetainPtr<CPDF_ColorSpace> FindColorSpace(const ByteString& name);
134 RetainPtr<CPDF_Pattern> FindPattern(const ByteString& name);
135 RetainPtr<CPDF_ShadingPattern> FindShading(const ByteString& name);
136 RetainPtr<CPDF_Dictionary> FindResourceHolder(const ByteString& type);
137 RetainPtr<CPDF_Object> FindResourceObj(const ByteString& type,
138 const ByteString& name);
139
140 // Takes ownership of |pImageObj|, returns unowned pointer to it.
141 CPDF_ImageObject* AddImageObject(std::unique_ptr<CPDF_ImageObject> pImageObj);
142
143 std::vector<float> GetColors() const;
144 std::vector<float> GetNamedColors() const;
145 int32_t GetCurrentStreamIndex();
146
147 void Handle_CloseFillStrokePath();
148 void Handle_FillStrokePath();
149 void Handle_CloseEOFillStrokePath();
150 void Handle_EOFillStrokePath();
151 void Handle_BeginMarkedContent_Dictionary();
152 void Handle_BeginImage();
153 void Handle_BeginMarkedContent();
154 void Handle_BeginText();
155 void Handle_CurveTo_123();
156 void Handle_ConcatMatrix();
157 void Handle_SetColorSpace_Fill();
158 void Handle_SetColorSpace_Stroke();
159 void Handle_SetDash();
160 void Handle_SetCharWidth();
161 void Handle_SetCachedDevice();
162 void Handle_ExecuteXObject();
163 void Handle_MarkPlace_Dictionary();
164 void Handle_EndImage();
165 void Handle_EndMarkedContent();
166 void Handle_EndText();
167 void Handle_FillPath();
168 void Handle_FillPathOld();
169 void Handle_EOFillPath();
170 void Handle_SetGray_Fill();
171 void Handle_SetGray_Stroke();
172 void Handle_SetExtendGraphState();
173 void Handle_ClosePath();
174 void Handle_SetFlat();
175 void Handle_BeginImageData();
176 void Handle_SetLineJoin();
177 void Handle_SetLineCap();
178 void Handle_SetCMYKColor_Fill();
179 void Handle_SetCMYKColor_Stroke();
180 void Handle_LineTo();
181 void Handle_MoveTo();
182 void Handle_SetMiterLimit();
183 void Handle_MarkPlace();
184 void Handle_EndPath();
185 void Handle_SaveGraphState();
186 void Handle_RestoreGraphState();
187 void Handle_Rectangle();
188 void Handle_SetRGBColor_Fill();
189 void Handle_SetRGBColor_Stroke();
190 void Handle_SetRenderIntent();
191 void Handle_CloseStrokePath();
192 void Handle_StrokePath();
193 void Handle_SetColor_Fill();
194 void Handle_SetColor_Stroke();
195 void Handle_SetColorPS_Fill();
196 void Handle_SetColorPS_Stroke();
197 void Handle_ShadeFill();
198 void Handle_SetCharSpace();
199 void Handle_MoveTextPoint();
200 void Handle_MoveTextPoint_SetLeading();
201 void Handle_SetFont();
202 void Handle_ShowText();
203 void Handle_ShowText_Positioning();
204 void Handle_SetTextLeading();
205 void Handle_SetTextMatrix();
206 void Handle_SetTextRenderMode();
207 void Handle_SetTextRise();
208 void Handle_SetWordSpace();
209 void Handle_SetHorzScale();
210 void Handle_MoveToNextLine();
211 void Handle_CurveTo_23();
212 void Handle_SetLineWidth();
213 void Handle_Clip();
214 void Handle_EOClip();
215 void Handle_CurveTo_13();
216 void Handle_NextLineShowText();
217 void Handle_NextLineShowText_Space();
218 void Handle_Invalid();
219
220 UnownedPtr<CPDF_Document> const m_pDocument;
221 RetainPtr<CPDF_Dictionary> const m_pPageResources;
222 RetainPtr<CPDF_Dictionary> const m_pParentResources;
223 RetainPtr<CPDF_Dictionary> const m_pResources;
224 UnownedPtr<CPDF_PageObjectHolder> const m_pObjectHolder;
225 UnownedPtr<CPDF_Form::RecursionState> const m_RecursionState;
226 CFX_Matrix m_mtContentToUser;
227 const CFX_FloatRect m_BBox;
228 uint32_t m_ParamStartPos = 0;
229 uint32_t m_ParamCount = 0;
230 std::unique_ptr<CPDF_StreamParser> m_pSyntax;
231 std::unique_ptr<CPDF_AllStates> m_pCurStates;
232 std::stack<std::unique_ptr<CPDF_ContentMarks>> m_ContentMarksStack;
233 std::vector<std::unique_ptr<CPDF_TextObject>> m_ClipTextList;
234 std::vector<CFX_Path::Point> m_PathPoints;
235 CFX_PointF m_PathStart;
236 CFX_PointF m_PathCurrent;
237 CFX_FillRenderOptions::FillType m_PathClipType =
239 ByteString m_LastImageName;
240 RetainPtr<CPDF_Image> m_pLastImage;
241 bool m_bColored = false;
242 std::vector<std::unique_ptr<CPDF_AllStates>> m_StateStack;
243 std::array<float, 6> m_Type3Data = {};
244 std::array<ContentParam, kParamBufSize> m_ParamBuf;
245 CPDF_PageObjectHolder::CTMMap m_AllCTMs;
246
247 // The merged stream offsets at which a content stream ends and another
248 // begins.
249 std::vector<uint32_t> m_StreamStartOffsets;
250
251 // The merged stream offset at which the last |m_pSyntax| started parsing.
252 uint32_t m_StartParseOffset = 0;
253};
254
255#endif // CORE_FPDFAPI_PAGE_CPDF_STREAMCONTENTPARSER_H_
fxcrt::ByteString ByteString
Definition bytestring.h:180
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_Matrix operator*(const CFX_Matrix &right) const
CPDF_TextState & mutable_text_state()
void IncrementTextPositionX(float value)
void set_current_transformation_matrix(const CFX_Matrix &matrix)
CFX_GraphState & mutable_graph_state()
void set_text_leading(float value)
const CFX_Matrix & text_matrix() const
void set_text_horz_scale(float value)
CPDF_ColorState & mutable_color_state()
void prepend_to_current_transformation_matrix(const CFX_Matrix &matrix)
void set_text_rise(float value)
void MoveTextPoint(const CFX_PointF &point)
void IncrementTextPositionY(float value)
void set_text_matrix(const CFX_Matrix &matrix)
float text_horz_scale() const
CFX_PointF GetTransformedTextPosition() const
const CPDF_GeneralState & general_state() const
CPDF_GeneralState & mutable_general_state()
CPDF_AllStates & operator=(const CPDF_AllStates &that)
const CFX_Matrix & parent_matrix() const
const CPDF_ClipPath & clip_path() const
void SetLineDash(const CPDF_Array *pArray, float phase, float scale)
CPDF_ClipPath & mutable_clip_path()
void set_parent_matrix(const CFX_Matrix &matrix)
const CPDF_ColorState & color_state() const
void ProcessExtGS(const CPDF_Dictionary *pGS, CPDF_StreamContentParser *pParser)
const CFX_GraphState & graph_state() const
const CPDF_TextState & text_state() const
const CPDF_GraphicStates & graphic_states() const
CPDF_AllStates(const CPDF_AllStates &that)
const CFX_Matrix & current_transformation_matrix() const
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
Definition cpdf_array.h:29
CPDF_DictionaryLocker(const CPDF_Dictionary *pDictionary)
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
CPDF_StreamContentParser(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pPageResources, RetainPtr< CPDF_Dictionary > pParentResources, const CFX_Matrix *pmtContentToUser, CPDF_PageObjectHolder *pObjHolder, RetainPtr< CPDF_Dictionary > pResources, const CFX_FloatRect &rcBBox, const CPDF_AllStates *pStates, CPDF_Form::RecursionState *parse_state)
CPDF_PageObjectHolder::CTMMap TakeAllCTMs()
uint32_t Parse(pdfium::span< const uint8_t > pData, uint32_t start_offset, uint32_t max_cost, const std::vector< uint32_t > &stream_start_offsets)
pdfium::span< const float > GetType3Data() const
CPDF_PageObjectHolder * GetPageObjectHolder() const
static ByteStringView FindValueAbbreviationForTesting(ByteStringView abbr)
CPDF_AllStates * GetCurStates() const
RetainPtr< CPDF_Font > FindFont(const ByteString &name)
static ByteStringView FindKeyAbbreviationForTesting(ByteStringView abbr)
CFX_PTemplate< float > CFX_PointF
fxcrt::ByteStringView ByteStringView