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