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
cpdfsdk_helpers.h
Go to the documentation of this file.
1// Copyright 2014 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 FPDFSDK_CPDFSDK_HELPERS_H_
8#define FPDFSDK_CPDFSDK_HELPERS_H_
9
10#include <vector>
11
12#include "build/build_config.h"
13#include "core/fpdfapi/page/cpdf_page.h"
14#include "core/fpdfapi/parser/cpdf_parser.h"
15#include "core/fxcrt/retain_ptr.h"
16#include "core/fxge/cfx_path.h"
17#include "public/fpdf_doc.h"
18#include "public/fpdf_ext.h"
19#include "public/fpdfview.h"
20
21#ifdef PDF_ENABLE_XFA
22#include "core/fxcrt/fx_stream.h"
23#endif // PDF_ENABLE_XFA
24
25class CPDF_Annot;
27class CPDF_ClipPath;
28class CPDF_ContentMarkItem;
29class CPDF_Object;
30class CPDF_Font;
32class CPDF_PageObject;
34class CPDF_Stream;
35class CPDF_StructElement;
36class CPDF_StructTree;
37class CPDF_TextPage;
39class CPDFSDK_FormFillEnvironment;
40class CPDFSDK_InteractiveForm;
41class CFX_DIBitmap;
42struct CPDF_JavaScript;
43struct XObjectContext;
44
45// Conversions to/from underlying types.
46IPDF_Page* IPDFPageFromFPDFPage(FPDF_PAGE page);
47FPDF_PAGE FPDFPageFromIPDFPage(IPDF_Page* page);
48CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
51
52// Conversions to/from incomplete FPDF_ API types.
53inline FPDF_ACTION FPDFActionFromCPDFDictionary(const CPDF_Dictionary* action) {
54 return reinterpret_cast<FPDF_ACTION>(const_cast<CPDF_Dictionary*>(action));
55}
56inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
57 return reinterpret_cast<CPDF_Dictionary*>(action);
58}
59
61 CPDF_AnnotContext* annot) {
62 return reinterpret_cast<FPDF_ANNOTATION>(annot);
63}
65 FPDF_ANNOTATION annot) {
66 return reinterpret_cast<CPDF_AnnotContext*>(annot);
67}
68
69inline FPDF_ATTACHMENT FPDFAttachmentFromCPDFObject(CPDF_Object* attachment) {
70 return reinterpret_cast<FPDF_ATTACHMENT>(attachment);
71}
72inline CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) {
73 return reinterpret_cast<CPDF_Object*>(attachment);
74}
75
76inline FPDF_BITMAP FPDFBitmapFromCFXDIBitmap(CFX_DIBitmap* bitmap) {
77 return reinterpret_cast<FPDF_BITMAP>(bitmap);
78}
79inline CFX_DIBitmap* CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) {
80 return reinterpret_cast<CFX_DIBitmap*>(bitmap);
81}
82
83inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(
84 const CPDF_Dictionary* bookmark) {
85 return reinterpret_cast<FPDF_BOOKMARK>(
86 const_cast<CPDF_Dictionary*>(bookmark));
87}
88inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
89 return reinterpret_cast<CPDF_Dictionary*>(bookmark);
90}
91
92inline FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath* path) {
93 return reinterpret_cast<FPDF_CLIPPATH>(path);
94}
95inline CPDF_ClipPath* CPDFClipPathFromFPDFClipPath(FPDF_CLIPPATH path) {
96 return reinterpret_cast<CPDF_ClipPath*>(path);
97}
98
99inline FPDF_DEST FPDFDestFromCPDFArray(const CPDF_Array* dest) {
100 return reinterpret_cast<FPDF_DEST>(const_cast<CPDF_Array*>(dest));
101}
102inline CPDF_Array* CPDFArrayFromFPDFDest(FPDF_DEST dest) {
103 return reinterpret_cast<CPDF_Array*>(dest);
104}
105
106inline FPDF_FONT FPDFFontFromCPDFFont(CPDF_Font* font) {
107 return reinterpret_cast<FPDF_FONT>(font);
108}
109inline CPDF_Font* CPDFFontFromFPDFFont(FPDF_FONT font) {
110 return reinterpret_cast<CPDF_Font*>(font);
111}
112
114 CPDF_JavaScript* javascript) {
115 return reinterpret_cast<FPDF_JAVASCRIPT_ACTION>(javascript);
116}
118 FPDF_JAVASCRIPT_ACTION javascript) {
119 return reinterpret_cast<CPDF_JavaScript*>(javascript);
120}
121
122inline FPDF_LINK FPDFLinkFromCPDFDictionary(CPDF_Dictionary* link) {
123 return reinterpret_cast<FPDF_LINK>(link);
124}
125inline CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) {
126 return reinterpret_cast<CPDF_Dictionary*>(link);
127}
128
130 return reinterpret_cast<FPDF_PAGELINK>(link);
131}
133 return reinterpret_cast<CPDF_LinkExtract*>(link);
134}
135
136inline FPDF_PAGEOBJECT FPDFPageObjectFromCPDFPageObject(
137 CPDF_PageObject* page_object) {
138 return reinterpret_cast<FPDF_PAGEOBJECT>(page_object);
139}
141 FPDF_PAGEOBJECT page_object) {
142 return reinterpret_cast<CPDF_PageObject*>(page_object);
143}
144
146 CPDF_ContentMarkItem* mark) {
147 return reinterpret_cast<FPDF_PAGEOBJECTMARK>(mark);
148}
149inline CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
150 FPDF_PAGEOBJECTMARK mark) {
151 return reinterpret_cast<CPDF_ContentMarkItem*>(mark);
152}
153
154inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(const CPDF_Array* range) {
155 return reinterpret_cast<FPDF_PAGERANGE>(range);
156}
157inline const CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) {
158 return reinterpret_cast<const CPDF_Array*>(range);
159}
160
161inline FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint(
162 const CFX_Path::Point* segment) {
163 return reinterpret_cast<FPDF_PATHSEGMENT>(segment);
164}
166 FPDF_PATHSEGMENT segment) {
167 return reinterpret_cast<const CFX_Path::Point*>(segment);
168}
169
170inline FPDF_STRUCTTREE FPDFStructTreeFromCPDFStructTree(
171 CPDF_StructTree* struct_tree) {
172 return reinterpret_cast<FPDF_STRUCTTREE>(struct_tree);
173}
175 FPDF_STRUCTTREE struct_tree) {
176 return reinterpret_cast<CPDF_StructTree*>(struct_tree);
177}
178
180 CPDF_StructElement* struct_element) {
181 return reinterpret_cast<FPDF_STRUCTELEMENT>(struct_element);
182}
183inline CPDF_StructElement* CPDFStructElementFromFPDFStructElement(
184 FPDF_STRUCTELEMENT struct_element) {
185 return reinterpret_cast<CPDF_StructElement*>(struct_element);
186}
187
188inline FPDF_STRUCTELEMENT_ATTR FPDFStructElementAttrFromCPDFDictionary(
189 const CPDF_Dictionary* dictionary) {
190 return reinterpret_cast<FPDF_STRUCTELEMENT_ATTR>(dictionary);
191}
192inline const CPDF_Dictionary* CPDFDictionaryFromFPDFStructElementAttr(
193 FPDF_STRUCTELEMENT_ATTR struct_element_attr) {
194 return reinterpret_cast<const CPDF_Dictionary*>(struct_element_attr);
195}
196
197inline FPDF_TEXTPAGE FPDFTextPageFromCPDFTextPage(CPDF_TextPage* page) {
198 return reinterpret_cast<FPDF_TEXTPAGE>(page);
199}
200inline CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE page) {
201 return reinterpret_cast<CPDF_TextPage*>(page);
202}
203
205 CPDF_TextPageFind* handle) {
206 return reinterpret_cast<FPDF_SCHHANDLE>(handle);
207}
209 FPDF_SCHHANDLE handle) {
210 return reinterpret_cast<CPDF_TextPageFind*>(handle);
211}
212
214 CPDFSDK_FormFillEnvironment* handle) {
215 return reinterpret_cast<FPDF_FORMHANDLE>(handle);
216}
217inline CPDFSDK_FormFillEnvironment*
219 return reinterpret_cast<CPDFSDK_FormFillEnvironment*>(handle);
220}
221
223 const CPDF_Dictionary* dictionary) {
224 return reinterpret_cast<FPDF_SIGNATURE>(dictionary);
225}
226inline const CPDF_Dictionary* CPDFDictionaryFromFPDFSignature(
227 FPDF_SIGNATURE signature) {
228 return reinterpret_cast<const CPDF_Dictionary*>(signature);
229}
230
231inline FPDF_XOBJECT FPDFXObjectFromXObjectContext(XObjectContext* xobject) {
232 return reinterpret_cast<FPDF_XOBJECT>(xobject);
233}
234
235inline XObjectContext* XObjectContextFromFPDFXObject(FPDF_XOBJECT xobject) {
236 return reinterpret_cast<XObjectContext*>(xobject);
237}
238
239CPDFSDK_InteractiveForm* FormHandleToInteractiveForm(FPDF_FORMHANDLE hHandle);
240
241ByteString ByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
242WideString WideStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
243
244#ifdef PDF_ENABLE_XFA
245// Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't
246// be a static method of IFX_SeekableStream.
247RetainPtr<IFX_SeekableStream> MakeSeekableStream(
248 FPDF_FILEHANDLER* pFileHandler);
249#endif // PDF_ENABLE_XFA
250
252 const CPDF_Dictionary* dict);
254 CPDF_Dictionary* dict);
255RetainPtr<CPDF_Array> AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict);
256bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index);
257bool GetQuadPointsAtIndex(RetainPtr<const CPDF_Array> array,
258 size_t quad_index,
259 FS_QUADPOINTSF* quad_points);
260
261CFX_PointF CFXPointFFromFSPointF(const FS_POINTF& point);
262
263CFX_FloatRect CFXFloatRectFromFSRectF(const FS_RECTF& rect);
264FS_RECTF FSRectFFromCFXFloatRect(const CFX_FloatRect& rect);
265
266CFX_Matrix CFXMatrixFromFSMatrix(const FS_MATRIX& matrix);
267FS_MATRIX FSMatrixFromCFXMatrix(const CFX_Matrix& matrix);
268
269unsigned long NulTerminateMaybeCopyAndReturnLength(const ByteString& text,
270 void* buffer,
271 unsigned long buflen);
272
273unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text,
274 void* buffer,
275 unsigned long buflen);
276
277// Returns the length of the raw stream data from |stream|. The raw data is the
278// stream's data as stored in the PDF without applying any filters. If |buffer|
279// is non-empty and its length is large enough to contain the raw data, then
280// the raw data is copied into |buffer|.
282 RetainPtr<const CPDF_Stream> stream,
283 pdfium::span<uint8_t> buffer);
284
285// Return the length of the decoded stream data of |stream|. The decoded data is
286// the uncompressed stream data, i.e. the raw stream data after having all
287// filters applied. If |buffer| is non-empty and its length is large enough to
288// contain the decoded data, then the decoded data is copied into |buffer|.
290 RetainPtr<const CPDF_Stream> stream,
291 pdfium::span<uint8_t> buffer);
292
293void SetPDFSandboxPolicy(FPDF_DWORD policy, FPDF_BOOL enable);
294FPDF_BOOL IsPDFSandboxPolicyEnabled(FPDF_DWORD policy);
295
296void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info);
298void ReportUnsupportedXFA(const CPDF_Document* pDoc);
299void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot);
301void SetColorFromScheme(const FPDF_COLORSCHEME* pColorScheme,
302 CPDF_RenderOptions* pRenderOptions);
303
304// Returns a vector of page indices given a page range string.
305std::vector<uint32_t> ParsePageRangeString(const ByteString& bsPageRange,
306 uint32_t nCount);
307
308#endif // FPDFSDK_CPDFSDK_HELPERS_H_
void LoadSubst(const ByteString &face_name, bool bTrueType, uint32_t flags, int weight, int italic_angle, FX_CodePage code_page, bool bVertical)
Definition cfx_font.cpp:220
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Translate(int32_t x, int32_t y)
void AppendRect(float left, float bottom, float right, float top)
Definition cfx_path.cpp:309
bool DrawDeviceText(pdfium::span< const TextCharPos > pCharPos, CFX_Font *pFont, const CFX_Matrix &mtObject2Device, float font_size, uint32_t color, const CFX_TextRenderOptions &options) override
void SaveState() override
bool SetClip_PathFill(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_FillRenderOptions &fill_options) override
void RestoreState(bool bKeepSaved) override
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options, BlendMode blend_type) override
RenderContextClearer(CPDF_Page *pPage)
uint32_t m_GlyphIndex
const CPDF_Array * CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range)
WideString WideStringFromFPDFWideString(FPDF_WIDESTRING wide_string)
bool IsValidQuadPointsIndex(const CPDF_Array *array, size_t index)
FPDF_STRUCTTREE FPDFStructTreeFromCPDFStructTree(CPDF_StructTree *struct_tree)
std::vector< uint32_t > ParsePageRangeString(const ByteString &bsPageRange, uint32_t nCount)
FPDF_STRUCTELEMENT_ATTR FPDFStructElementAttrFromCPDFDictionary(const CPDF_Dictionary *dictionary)
unsigned long NulTerminateMaybeCopyAndReturnLength(const ByteString &text, void *buffer, unsigned long buflen)
ByteString ByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string)
FPDF_XOBJECT FPDFXObjectFromXObjectContext(XObjectContext *xobject)
CPDF_StructElement * CPDFStructElementFromFPDFStructElement(FPDF_STRUCTELEMENT struct_element)
FPDF_PAGELINK FPDFPageLinkFromCPDFLinkExtract(CPDF_LinkExtract *link)
FPDF_DEST FPDFDestFromCPDFArray(const CPDF_Array *dest)
IPDF_Page * IPDFPageFromFPDFPage(FPDF_PAGE page)
const CFX_Path::Point * FXPathPointFromFPDFPathSegment(FPDF_PATHSEGMENT segment)
CPDF_TextPageFind * CPDFTextPageFindFromFPDFSchHandle(FPDF_SCHHANDLE handle)
FPDF_JAVASCRIPT_ACTION FPDFJavaScriptActionFromCPDFJavaScriptAction(CPDF_JavaScript *javascript)
FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document *doc)
void ProcessParseError(CPDF_Parser::Error err)
XObjectContext * XObjectContextFromFPDFXObject(FPDF_XOBJECT xobject)
RetainPtr< CPDF_Array > AddQuadPointsArrayToDictionary(CPDF_Dictionary *dict)
CPDF_Array * CPDFArrayFromFPDFDest(FPDF_DEST dest)
unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString &text, void *buffer, unsigned long buflen)
FPDF_SCHHANDLE FPDFSchHandleFromCPDFTextPageFind(CPDF_TextPageFind *handle)
FPDF_BITMAP FPDFBitmapFromCFXDIBitmap(CFX_DIBitmap *bitmap)
CFX_DIBitmap * CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap)
FPDF_BOOL IsPDFSandboxPolicyEnabled(FPDF_DWORD policy)
CPDFSDK_FormFillEnvironment * CPDFSDKFormFillEnvironmentFromFPDFFormHandle(FPDF_FORMHANDLE handle)
FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext(CPDF_AnnotContext *annot)
FPDF_ACTION FPDFActionFromCPDFDictionary(const CPDF_Dictionary *action)
void SetPDFSandboxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
CPDF_Dictionary * CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark)
CPDF_ContentMarkItem * CPDFContentMarkItemFromFPDFPageObjectMark(FPDF_PAGEOBJECTMARK mark)
CPDF_Object * CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment)
RetainPtr< const CPDF_Array > GetQuadPointsArrayFromDictionary(const CPDF_Dictionary *dict)
FPDF_LINK FPDFLinkFromCPDFDictionary(CPDF_Dictionary *link)
const CPDF_Dictionary * CPDFDictionaryFromFPDFSignature(FPDF_SIGNATURE signature)
CPDF_AnnotContext * CPDFAnnotContextFromFPDFAnnotation(FPDF_ANNOTATION annot)
FPDF_PAGEOBJECT FPDFPageObjectFromCPDFPageObject(CPDF_PageObject *page_object)
bool GetQuadPointsAtIndex(RetainPtr< const CPDF_Array > array, size_t quad_index, FS_QUADPOINTSF *quad_points)
FPDF_PAGEOBJECTMARK FPDFPageObjectMarkFromCPDFContentMarkItem(CPDF_ContentMarkItem *mark)
FPDF_STRUCTELEMENT FPDFStructElementFromCPDFStructElement(CPDF_StructElement *struct_element)
CPDF_TextPage * CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE page)
void ReportUnsupportedXFA(const CPDF_Document *pDoc)
FPDF_FONT FPDFFontFromCPDFFont(CPDF_Font *font)
CPDF_Font * CPDFFontFromFPDFFont(FPDF_FONT font)
FS_RECTF FSRectFFromCFXFloatRect(const CFX_FloatRect &rect)
RetainPtr< CPDF_Array > GetMutableQuadPointsArrayFromDictionary(CPDF_Dictionary *dict)
CPDF_Dictionary * CPDFDictionaryFromFPDFLink(FPDF_LINK link)
void CheckForUnsupportedAnnot(const CPDF_Annot *pAnnot)
void ReportUnsupportedFeatures(const CPDF_Document *pDoc)
CPDF_ClipPath * CPDFClipPathFromFPDFClipPath(FPDF_CLIPPATH path)
FS_MATRIX FSMatrixFromCFXMatrix(const CFX_Matrix &matrix)
FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint(const CFX_Path::Point *segment)
void SetColorFromScheme(const FPDF_COLORSCHEME *pColorScheme, CPDF_RenderOptions *pRenderOptions)
CFX_FloatRect CFXFloatRectFromFSRectF(const FS_RECTF &rect)
FPDF_PAGE FPDFPageFromIPDFPage(IPDF_Page *page)
unsigned long GetRawStreamMaybeCopyAndReturnLength(RetainPtr< const CPDF_Stream > stream, pdfium::span< uint8_t > buffer)
CPDF_JavaScript * CPDFJavaScriptActionFromFPDFJavaScriptAction(FPDF_JAVASCRIPT_ACTION javascript)
FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath *path)
CFX_PointF CFXPointFFromFSPointF(const FS_POINTF &point)
CPDF_Page * CPDFPageFromFPDFPage(FPDF_PAGE page)
CPDF_Document * CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc)
FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(const CPDF_Dictionary *bookmark)
FPDF_SIGNATURE FPDFSignatureFromCPDFDictionary(const CPDF_Dictionary *dictionary)
CPDF_StructTree * CPDFStructTreeFromFPDFStructTree(FPDF_STRUCTTREE struct_tree)
unsigned long DecodeStreamMaybeCopyAndReturnLength(RetainPtr< const CPDF_Stream > stream, pdfium::span< uint8_t > buffer)
FPDF_TEXTPAGE FPDFTextPageFromCPDFTextPage(CPDF_TextPage *page)
FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(const CPDF_Array *range)
const CPDF_Dictionary * CPDFDictionaryFromFPDFStructElementAttr(FPDF_STRUCTELEMENT_ATTR struct_element_attr)
void SetPDFUnsupportInfo(UNSUPPORT_INFO *unsp_info)
CPDF_PageObject * CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object)
CPDF_Dictionary * CPDFDictionaryFromFPDFAction(FPDF_ACTION action)
FPDF_FORMHANDLE FPDFFormHandleFromCPDFSDKFormFillEnvironment(CPDFSDK_FormFillEnvironment *handle)
CFX_Matrix CFXMatrixFromFSMatrix(const FS_MATRIX &matrix)
CPDFSDK_InteractiveForm * FormHandleToInteractiveForm(FPDF_FORMHANDLE hHandle)
CPDF_LinkExtract * CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link)
FPDF_ATTACHMENT FPDFAttachmentFromCPDFObject(CPDF_Object *attachment)
void CPDFSDK_RenderPageWithContext(CPDF_PageRenderContext *pContext, CPDF_Page *pPage, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, const FPDF_COLORSCHEME *color_scheme, bool need_to_restore, CPDFSDK_PauseAdapter *pause)
TEST_F(FPDFParserDecodeEmbedderTest, Bug552046)
FX_CodePage
Definition fx_codepage.h:18
TEST(FXCRYPT, CryptToBase16)
BlendMode
Definition fx_dib.h:49
static constexpr CFX_FillRenderOptions WindingOptions()
constexpr CFX_TextRenderOptions(AliasingType type)