1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef FPDFSDK_CPDFSDK_HELPERS_H_
#define FPDFSDK_CPDFSDK_HELPERS_H_
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/fx_dib.h"
#include "public/fpdf_doc.h"
#include "public/fpdfview.h"
#ifdef PDF_ENABLE_XFA
#include "core/fxcrt/fx_stream.h"
#endif // PDF_ENABLE_XFA
#ifdef _WIN32
#include <math.h>
#include <tchar.h>
#endif
class CPDF_Annot;
class CPDF_AnnotContext;
class CPDF_ClipPath;
class CPDF_ContentMarkItem;
class CPDF_Object;
class CPDF_Font;
class CPDF_LinkExtract;
class CPDF_Page;
class CPDF_PageObject;
class CPDF_PageRenderContext;
class CPDF_PathObject;
class CPDF_Stream;
class CPDF_StructElement;
class CPDF_StructTree;
class CPDF_TextPage;
class CPDF_TextPageFind;
class IPDFSDK_PauseAdapter;
class FX_PATHPOINT;
#ifdef PDF_ENABLE_XFA
class CPDFXFA_Context;
class CPDFXFA_Page;
class CXFA_FFWidget;
#endif // PDF_ENABLE_XFA
// Object types for public FPDF_ types; these correspond to next layer down
// from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are
// CPDFXFA_ types.
#ifndef PDF_ENABLE_XFA
using UnderlyingPageType = CPDF_Page;
#else // PDF_ENABLE_XFA
using UnderlyingPageType = CPDFXFA_Page;
#endif // PDF_ENABLE_XFA
// Conversions to/from underlying types.
UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page);
FPDF_PAGE FPDFPageFromUnderlying(UnderlyingPageType* page);
CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc);
CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
// Conversions to/from incomplete FPDF_ API types.
inline FPDF_ACTION FPDFActionFromCPDFDictionary(CPDF_Dictionary* action) {
return reinterpret_cast<FPDF_ACTION>(action);
}
inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
return reinterpret_cast<CPDF_Dictionary*>(action);
}
inline FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext(
CPDF_AnnotContext* annot) {
return reinterpret_cast<FPDF_ANNOTATION>(annot);
}
inline CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation(
FPDF_ANNOTATION annot) {
return reinterpret_cast<CPDF_AnnotContext*>(annot);
}
inline FPDF_ATTACHMENT FPDFAttachmentFromCPDFObject(CPDF_Object* attachment) {
return reinterpret_cast<FPDF_ATTACHMENT>(attachment);
}
inline CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) {
return reinterpret_cast<CPDF_Object*>(attachment);
}
inline FPDF_BITMAP FPDFBitmapFromCFXDIBitmap(CFX_DIBitmap* bitmap) {
return reinterpret_cast<FPDF_BITMAP>(bitmap);
}
inline CFX_DIBitmap* CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) {
return reinterpret_cast<CFX_DIBitmap*>(bitmap);
}
inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(CPDF_Dictionary* bookmark) {
return reinterpret_cast<FPDF_BOOKMARK>(bookmark);
}
inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
return reinterpret_cast<CPDF_Dictionary*>(bookmark);
}
inline FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath* path) {
return reinterpret_cast<FPDF_CLIPPATH>(path);
}
inline CPDF_ClipPath* CPDFClipPathFromFPDFClipPath(FPDF_CLIPPATH path) {
return reinterpret_cast<CPDF_ClipPath*>(path);
}
inline FPDF_DEST FPDFDestFromCPDFArray(CPDF_Array* dest) {
return reinterpret_cast<FPDF_DEST>(dest);
}
inline CPDF_Array* CPDFArrayFromFPDFDest(FPDF_DEST dest) {
return reinterpret_cast<CPDF_Array*>(dest);
}
inline FPDF_FONT FPDFFontFromCPDFFont(CPDF_Font* font) {
return reinterpret_cast<FPDF_FONT>(font);
}
inline CPDF_Font* CPDFFontFromFPDFFont(FPDF_FONT font) {
return reinterpret_cast<CPDF_Font*>(font);
}
inline FPDF_LINK FPDFLinkFromCPDFDictionary(CPDF_Dictionary* link) {
return reinterpret_cast<FPDF_LINK>(link);
}
inline CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) {
return reinterpret_cast<CPDF_Dictionary*>(link);
}
inline FPDF_PAGELINK FPDFPageLinkFromCPDFLinkExtract(CPDF_LinkExtract* link) {
return reinterpret_cast<FPDF_PAGELINK>(link);
}
inline CPDF_LinkExtract* CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link) {
return reinterpret_cast<CPDF_LinkExtract*>(link);
}
inline FPDF_PAGEOBJECT FPDFPageObjectFromCPDFPageObject(
CPDF_PageObject* page_object) {
return reinterpret_cast<FPDF_PAGEOBJECT>(page_object);
}
inline CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(
FPDF_PAGEOBJECT page_object) {
return reinterpret_cast<CPDF_PageObject*>(page_object);
}
inline FPDF_PAGEOBJECTMARK FPDFPageObjectMarkFromCPDFContentMarkItem(
const CPDF_ContentMarkItem* mark) {
return reinterpret_cast<FPDF_PAGEOBJECTMARK>(mark);
}
inline const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
FPDF_PAGEOBJECTMARK mark) {
return reinterpret_cast<const CPDF_ContentMarkItem*>(mark);
}
inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(const CPDF_Array* range) {
return reinterpret_cast<FPDF_PAGERANGE>(range);
}
inline const CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) {
return reinterpret_cast<const CPDF_Array*>(range);
}
inline FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint(
const FX_PATHPOINT* segment) {
return reinterpret_cast<FPDF_PATHSEGMENT>(segment);
}
inline const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(
FPDF_PATHSEGMENT segment) {
return reinterpret_cast<const FX_PATHPOINT*>(segment);
}
inline FPDF_STRUCTTREE FPDFStructTreeFromCPDFStructTree(
CPDF_StructTree* struct_tree) {
return reinterpret_cast<FPDF_STRUCTTREE>(struct_tree);
}
inline CPDF_StructTree* CPDFStructTreeFromFPDFStructTree(
FPDF_STRUCTTREE struct_tree) {
return reinterpret_cast<CPDF_StructTree*>(struct_tree);
}
inline FPDF_STRUCTELEMENT FPDFStructElementFromCPDFStructElement(
CPDF_StructElement* struct_element) {
return reinterpret_cast<FPDF_STRUCTELEMENT>(struct_element);
}
inline CPDF_StructElement* CPDFStructElementFromFPDFStructElement(
FPDF_STRUCTELEMENT struct_element) {
return reinterpret_cast<CPDF_StructElement*>(struct_element);
}
inline FPDF_TEXTPAGE FPDFTextPageFromCPDFTextPage(CPDF_TextPage* page) {
return reinterpret_cast<FPDF_TEXTPAGE>(page);
}
inline CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE page) {
return reinterpret_cast<CPDF_TextPage*>(page);
}
inline FPDF_SCHHANDLE FPDFSchHandleFromCPDFTextPageFind(
CPDF_TextPageFind* handle) {
return reinterpret_cast<FPDF_SCHHANDLE>(handle);
}
inline CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(
FPDF_SCHHANDLE handle) {
return reinterpret_cast<CPDF_TextPageFind*>(handle);
}
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
#ifdef PDF_ENABLE_XFA
inline FPDF_WIDGET FPDFWidgetFromCXFAFFWidget(CXFA_FFWidget* widget) {
return reinterpret_cast<FPDF_WIDGET>(widget);
}
inline CXFA_FFWidget* CXFAFFWidgetFromFPDFWidget(FPDF_WIDGET widget) {
return reinterpret_cast<CXFA_FFWidget*>(widget);
}
// Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't
// be a static method of IFX_SeekableStream.
RetainPtr<IFX_SeekableStream> MakeSeekableStream(
FPDF_FILEHANDLER* pFileHandler);
#endif // PDF_ENABLE_XFA
CPDF_Array* GetQuadPointsArrayFromDictionary(const CPDF_Dictionary* dict);
CPDF_Array* AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict);
bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index);
bool GetQuadPointsAtIndex(const CPDF_Array* array,
size_t quad_index,
FS_QUADPOINTSF* quad_points);
CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect);
void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect);
unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text,
void* buffer,
unsigned long buflen);
unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
void* buffer,
unsigned long buflen);
void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable);
FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy);
// TODO(dsinclair): Where should this live?
void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext,
FPDF_PAGE page,
int start_x,
int start_y,
int size_x,
int size_y,
int rotate,
int flags,
bool bNeedToRestore,
IPDFSDK_PauseAdapter* pause);
void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code);
void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot);
#ifndef _WIN32
void SetLastError(int err);
int GetLastError();
#endif // _WIN32
void ProcessParseError(CPDF_Parser::Error err);
// TODO(dsinclair): This seems like it should be a public API?
FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object,
unsigned int R,
unsigned int G,
unsigned int B,
unsigned int A);
#endif // FPDFSDK_CPDFSDK_HELPERS_H_
|