blob: 4b843958126db3169b88b521965640d98acf7679 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclair00d47a62018-03-28 18:39:04 +00007#ifndef FPDFSDK_CPDFSDK_HELPERS_H_
8#define FPDFSDK_CPDFSDK_HELPERS_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Lei Zhangbc106482019-05-30 23:55:19 +000010#include "build/build_config.h"
Tom Sepez101535f2018-06-12 13:36:05 +000011#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070012#include "core/fpdfapi/parser/cpdf_parser.h"
Nicolas Pena37cc5fb2017-04-04 12:12:49 -040013#include "core/fxge/dib/cfx_dibitmap.h"
Lei Zhangaaed6982018-03-22 18:39:05 +000014#include "public/fpdf_doc.h"
Tom Sepez20c946f2019-07-31 19:33:21 +000015#include "public/fpdf_ext.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080016#include "public/fpdfview.h"
17
Tom Sepez51da0932015-11-25 16:05:49 -080018#ifdef PDF_ENABLE_XFA
Tom Sepeza1d34422018-04-24 20:54:41 +000019#include "core/fxcrt/fx_stream.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080020#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
Lei Zhangbc106482019-05-30 23:55:19 +000022#if defined(OS_WIN)
Tom Sepez75f43c42015-07-15 16:35:53 -070023#include <math.h>
Dan Sinclair61046b92016-02-18 14:48:48 -050024#include <tchar.h>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025#endif
26
dsinclaircac704d2016-07-28 12:59:09 -070027class CPDF_Annot;
Tom Sepez525147a2018-05-03 17:19:53 +000028class CPDF_AnnotContext;
29class CPDF_ClipPath;
30class CPDF_ContentMarkItem;
31class CPDF_Object;
32class CPDF_Font;
33class CPDF_LinkExtract;
Jane Liubaa7ff42017-06-29 19:18:23 -040034class CPDF_PageObject;
weili9f515bc2016-07-24 08:08:24 -070035class CPDF_PageRenderContext;
Jane Liu548334e2017-08-03 16:33:40 -040036class CPDF_Stream;
Tom Sepez525147a2018-05-03 17:19:53 +000037class CPDF_StructElement;
38class CPDF_StructTree;
39class CPDF_TextPage;
40class CPDF_TextPageFind;
Tom Sepez2563fc32018-08-01 19:13:06 +000041class CPDFSDK_FormFillEnvironment;
Lei Zhange6fcdfa2019-02-14 04:07:09 +000042class CPDFSDK_InteractiveForm;
Tom Sepez269f2ae2019-08-20 19:31:17 +000043class CPDFSDK_PauseAdapter;
Miklos Vajna36eed872017-09-20 22:52:43 +020044class FX_PATHPOINT;
Lei Zhang25661d12019-08-01 21:57:23 +000045struct CPDF_JavaScript;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046
Tom Sepez50d12ad2015-11-24 09:50:51 -080047// Conversions to/from underlying types.
Tom Sepez101535f2018-06-12 13:36:05 +000048IPDF_Page* IPDFPageFromFPDFPage(FPDF_PAGE page);
49FPDF_PAGE FPDFPageFromIPDFPage(IPDF_Page* page);
Tom Sepezdb0be962015-10-16 14:00:21 -070050CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
Tom Sepez525147a2018-05-03 17:19:53 +000051FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc);
52CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
53
54// Conversions to/from incomplete FPDF_ API types.
Tom Sepez92f98b82019-07-26 20:32:35 +000055inline FPDF_ACTION FPDFActionFromCPDFDictionary(const CPDF_Dictionary* action) {
56 return reinterpret_cast<FPDF_ACTION>(const_cast<CPDF_Dictionary*>(action));
Tom Sepez525147a2018-05-03 17:19:53 +000057}
Tom Sepez22923602019-07-15 21:33:35 +000058inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
59 return reinterpret_cast<CPDF_Dictionary*>(action);
Tom Sepez525147a2018-05-03 17:19:53 +000060}
61
62inline FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext(
63 CPDF_AnnotContext* annot) {
64 return reinterpret_cast<FPDF_ANNOTATION>(annot);
65}
66inline CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation(
67 FPDF_ANNOTATION annot) {
68 return reinterpret_cast<CPDF_AnnotContext*>(annot);
69}
70
71inline FPDF_ATTACHMENT FPDFAttachmentFromCPDFObject(CPDF_Object* attachment) {
72 return reinterpret_cast<FPDF_ATTACHMENT>(attachment);
73}
74inline CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) {
75 return reinterpret_cast<CPDF_Object*>(attachment);
76}
77
78inline FPDF_BITMAP FPDFBitmapFromCFXDIBitmap(CFX_DIBitmap* bitmap) {
79 return reinterpret_cast<FPDF_BITMAP>(bitmap);
80}
81inline CFX_DIBitmap* CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) {
82 return reinterpret_cast<CFX_DIBitmap*>(bitmap);
83}
84
Tom Sepez92f98b82019-07-26 20:32:35 +000085inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(
86 const CPDF_Dictionary* bookmark) {
87 return reinterpret_cast<FPDF_BOOKMARK>(
88 const_cast<CPDF_Dictionary*>(bookmark));
Tom Sepez525147a2018-05-03 17:19:53 +000089}
Tom Sepez22923602019-07-15 21:33:35 +000090inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
91 return reinterpret_cast<CPDF_Dictionary*>(bookmark);
Tom Sepez525147a2018-05-03 17:19:53 +000092}
93
94inline FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath* path) {
95 return reinterpret_cast<FPDF_CLIPPATH>(path);
96}
97inline CPDF_ClipPath* CPDFClipPathFromFPDFClipPath(FPDF_CLIPPATH path) {
98 return reinterpret_cast<CPDF_ClipPath*>(path);
99}
100
Tom Sepez92f98b82019-07-26 20:32:35 +0000101inline FPDF_DEST FPDFDestFromCPDFArray(const CPDF_Array* dest) {
102 return reinterpret_cast<FPDF_DEST>(const_cast<CPDF_Array*>(dest));
Tom Sepez525147a2018-05-03 17:19:53 +0000103}
Tom Sepez22923602019-07-15 21:33:35 +0000104inline CPDF_Array* CPDFArrayFromFPDFDest(FPDF_DEST dest) {
105 return reinterpret_cast<CPDF_Array*>(dest);
Tom Sepez525147a2018-05-03 17:19:53 +0000106}
107
108inline FPDF_FONT FPDFFontFromCPDFFont(CPDF_Font* font) {
109 return reinterpret_cast<FPDF_FONT>(font);
110}
111inline CPDF_Font* CPDFFontFromFPDFFont(FPDF_FONT font) {
112 return reinterpret_cast<CPDF_Font*>(font);
113}
114
Lei Zhang25661d12019-08-01 21:57:23 +0000115inline FPDF_JAVASCRIPT_ACTION FPDFJavaScriptActionFromCPDFJavaScriptAction(
116 CPDF_JavaScript* javascript) {
117 return reinterpret_cast<FPDF_JAVASCRIPT_ACTION>(javascript);
118}
119inline CPDF_JavaScript* CPDFJavaScriptActionFromFPDFJavaScriptAction(
120 FPDF_JAVASCRIPT_ACTION javascript) {
121 return reinterpret_cast<CPDF_JavaScript*>(javascript);
122}
123
Tom Sepez525147a2018-05-03 17:19:53 +0000124inline FPDF_LINK FPDFLinkFromCPDFDictionary(CPDF_Dictionary* link) {
125 return reinterpret_cast<FPDF_LINK>(link);
126}
127inline CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) {
128 return reinterpret_cast<CPDF_Dictionary*>(link);
129}
130
131inline FPDF_PAGELINK FPDFPageLinkFromCPDFLinkExtract(CPDF_LinkExtract* link) {
132 return reinterpret_cast<FPDF_PAGELINK>(link);
133}
134inline CPDF_LinkExtract* CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link) {
135 return reinterpret_cast<CPDF_LinkExtract*>(link);
136}
137
138inline FPDF_PAGEOBJECT FPDFPageObjectFromCPDFPageObject(
139 CPDF_PageObject* page_object) {
140 return reinterpret_cast<FPDF_PAGEOBJECT>(page_object);
141}
142inline CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(
143 FPDF_PAGEOBJECT page_object) {
144 return reinterpret_cast<CPDF_PageObject*>(page_object);
145}
146
147inline FPDF_PAGEOBJECTMARK FPDFPageObjectMarkFromCPDFContentMarkItem(
Henrique Nakashima144107d2018-07-10 21:04:05 +0000148 CPDF_ContentMarkItem* mark) {
Tom Sepez525147a2018-05-03 17:19:53 +0000149 return reinterpret_cast<FPDF_PAGEOBJECTMARK>(mark);
150}
Henrique Nakashima144107d2018-07-10 21:04:05 +0000151inline CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
Tom Sepez525147a2018-05-03 17:19:53 +0000152 FPDF_PAGEOBJECTMARK mark) {
Henrique Nakashima144107d2018-07-10 21:04:05 +0000153 return reinterpret_cast<CPDF_ContentMarkItem*>(mark);
Tom Sepez525147a2018-05-03 17:19:53 +0000154}
155
Tom Sepez22923602019-07-15 21:33:35 +0000156inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(CPDF_Array* range) {
Tom Sepez525147a2018-05-03 17:19:53 +0000157 return reinterpret_cast<FPDF_PAGERANGE>(range);
158}
Tom Sepez22923602019-07-15 21:33:35 +0000159inline CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) {
160 return reinterpret_cast<CPDF_Array*>(range);
Tom Sepez525147a2018-05-03 17:19:53 +0000161}
162
163inline FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint(
164 const FX_PATHPOINT* segment) {
165 return reinterpret_cast<FPDF_PATHSEGMENT>(segment);
166}
167inline const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(
168 FPDF_PATHSEGMENT segment) {
169 return reinterpret_cast<const FX_PATHPOINT*>(segment);
170}
171
172inline FPDF_STRUCTTREE FPDFStructTreeFromCPDFStructTree(
173 CPDF_StructTree* struct_tree) {
174 return reinterpret_cast<FPDF_STRUCTTREE>(struct_tree);
175}
176inline CPDF_StructTree* CPDFStructTreeFromFPDFStructTree(
177 FPDF_STRUCTTREE struct_tree) {
178 return reinterpret_cast<CPDF_StructTree*>(struct_tree);
179}
180
181inline FPDF_STRUCTELEMENT FPDFStructElementFromCPDFStructElement(
182 CPDF_StructElement* struct_element) {
183 return reinterpret_cast<FPDF_STRUCTELEMENT>(struct_element);
184}
185inline CPDF_StructElement* CPDFStructElementFromFPDFStructElement(
186 FPDF_STRUCTELEMENT struct_element) {
187 return reinterpret_cast<CPDF_StructElement*>(struct_element);
188}
189
190inline FPDF_TEXTPAGE FPDFTextPageFromCPDFTextPage(CPDF_TextPage* page) {
191 return reinterpret_cast<FPDF_TEXTPAGE>(page);
192}
193inline CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE page) {
194 return reinterpret_cast<CPDF_TextPage*>(page);
195}
196
197inline FPDF_SCHHANDLE FPDFSchHandleFromCPDFTextPageFind(
198 CPDF_TextPageFind* handle) {
199 return reinterpret_cast<FPDF_SCHHANDLE>(handle);
200}
201inline CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(
202 FPDF_SCHHANDLE handle) {
203 return reinterpret_cast<CPDF_TextPageFind*>(handle);
204}
205
Tom Sepez2563fc32018-08-01 19:13:06 +0000206inline FPDF_FORMHANDLE FPDFFormHandleFromCPDFSDKFormFillEnvironment(
207 CPDFSDK_FormFillEnvironment* handle) {
208 return reinterpret_cast<FPDF_FORMHANDLE>(handle);
209}
210inline CPDFSDK_FormFillEnvironment*
211CPDFSDKFormFillEnvironmentFromFPDFFormHandle(FPDF_FORMHANDLE handle) {
212 return reinterpret_cast<CPDFSDK_FormFillEnvironment*>(handle);
213}
214
Lei Zhange6fcdfa2019-02-14 04:07:09 +0000215CPDFSDK_InteractiveForm* FormHandleToInteractiveForm(FPDF_FORMHANDLE hHandle);
216
Lei Zhangb46a7632019-01-09 02:56:16 +0000217ByteString ByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
Lei Zhangf5fcd9e2018-12-23 03:11:50 +0000218WideString WideStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
219
Dan Sinclair7aba4722018-03-28 17:04:16 +0000220#ifdef PDF_ENABLE_XFA
221// Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't
222// be a static method of IFX_SeekableStream.
223RetainPtr<IFX_SeekableStream> MakeSeekableStream(
224 FPDF_FILEHANDLER* pFileHandler);
225#endif // PDF_ENABLE_XFA
Lei Zhang11767d32018-03-21 18:59:44 +0000226
Lei Zhang5cee3f22018-05-25 21:48:49 +0000227const CPDF_Array* GetQuadPointsArrayFromDictionary(const CPDF_Dictionary* dict);
228CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict);
Ralf Sippl16381792018-04-12 21:20:26 +0000229CPDF_Array* AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict);
230bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index);
231bool GetQuadPointsAtIndex(const CPDF_Array* array,
232 size_t quad_index,
233 FS_QUADPOINTSF* quad_points);
Lei Zhangaaed6982018-03-22 18:39:05 +0000234
Lei Zhang367e7de2017-10-31 13:32:17 +0000235CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect);
Lei Zhang3567c612019-11-18 18:10:02 +0000236FS_RECTF FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect);
Lei Zhang367e7de2017-10-31 13:32:17 +0000237
Lei Zhang6fef1e42018-12-20 19:14:02 +0000238CFX_Matrix CFXMatrixFromFSMatrix(const FS_MATRIX& matrix);
239
Ryan Harrison275e2602017-09-18 14:23:18 -0400240unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text,
Jane Liu18ae06d2017-07-18 10:15:16 -0400241 void* buffer,
242 unsigned long buflen);
Jeremy Chinsen617a2e82019-06-20 00:11:12 +0000243
244// Returns the length of the raw stream data from |stream|. The raw data is the
245// stream's data as stored in the PDF without applying any filters. If |buffer|
246// is non-nullptr and |buflen| is large enough to contain the raw data, then
247// the raw data is copied into |buffer|.
248unsigned long GetRawStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
249 void* buffer,
250 unsigned long buflen);
251
252// Return the length of the decoded stream data of |stream|. The decoded data is
253// the uncompressed stream data, i.e. the raw stream data after having all
254// filters applied. If |buffer| is non-nullptr and |buflen| is large enough to
255// contain the decoded data, then the decoded data is copied into |buffer|.
Jane Liu548334e2017-08-03 16:33:40 -0400256unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
257 void* buffer,
258 unsigned long buflen);
259
Tom Sepez69a4a702019-07-31 17:59:49 +0000260void SetPDFSandboxPolicy(FPDF_DWORD policy, FPDF_BOOL enable);
261FPDF_BOOL IsPDFSandboxPolicyEnabled(FPDF_DWORD policy);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000262
263// TODO(dsinclair): Where should this live?
Tom Sepezce613572019-11-07 19:44:11 +0000264void RenderPageWithContext(CPDF_Page* pPage,
265 CPDF_PageRenderContext* pContext,
Tom Sepez59d2a592018-09-14 19:51:10 +0000266 int start_x,
267 int start_y,
268 int size_x,
269 int size_y,
270 int rotate,
271 int flags,
272 bool bNeedToRestore,
Tom Sepez269f2ae2019-08-20 19:31:17 +0000273 CPDFSDK_PauseAdapter* pause);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274
Tom Sepez20c946f2019-07-31 19:33:21 +0000275void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info);
276UNSUPPORT_INFO* GetPDFUnssuportInto();
Tom Sepez81284852018-06-12 19:26:15 +0000277void ReportUnsupportedFeatures(CPDF_Document* pDoc);
Ryan Smith69fce9b2019-03-11 21:53:42 +0000278void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot);
Tom Sepezf10ae632016-01-26 14:19:52 -0800279void ProcessParseError(CPDF_Parser::Error err);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000280
Dan Sinclair00d47a62018-03-28 18:39:04 +0000281#endif // FPDFSDK_CPDFSDK_HELPERS_H_