This repository has been archived by the owner on Sep 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
AFPDFDoc.h
executable file
·264 lines (242 loc) · 7.76 KB
/
AFPDFDoc.h
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
#pragma once
#define MAX_BITMAP_CACHE 4
#include "stdafx.h"
#include "globals.h"
#include "OutlineItemA.h"
#include "PageMemory.h"
#include "queue.h"
#include "CRect.h"
#include "AuxOutputDev.h"
#ifdef _MUPDF
#include "mupdfEngine.h"
#endif
void InitGlobalParams(char *configFile);
typedef int (__stdcall *NOTIFYHANDLE)();
typedef int (__stdcall *PAGERENDERNOTIFY)(int,bool);
typedef int (__stdcall *PROGRESSHANDLE)(int, int);
typedef void (__stdcall *OUTPUTFUNCTIONB)(unsigned char *,int);
typedef void (__stdcall *OUTPUTFUNCTION)(wchar_t *,int);
void OutputToDelegate(void *stream, char *str, int len);
class CPDFSearchResult
: public CRect
{
public:
CPDFSearchResult();
CPDFSearchResult(CRect r,long lPage);
long PageFound;
};
// AFPDFDoc command target
class AFPDFDoc
{
private:
#ifdef _MUPDF
mupdfEngine *_mupdf;
#endif
PageMemory *_bitmapCache[MAX_BITMAP_CACHE+1];
int _pageCached[MAX_BITMAP_CACHE+1];
int _countCached;
bool m_searchWholeWord;
bool _needNonText;
bool _useMuPDF;
PageMemory *GetBitmapCache(int page);
void InvalidateBitmapCache();
void RemoveFromCache(int page);
void AddBitmapCache(PageMemory *bmp, int page);
int RenderThreadFinished(AuxOutputDev *out,int page, bool enablePreRender);
static void CancelThumbRenderCallback( void * );
bool NoEmbedFontExists(Dict *resDict, PDFDoc *doc);
bool IsEmbed(GfxFont *font, PDFDoc *doc);
protected:
long m_PageToRenderByThread;
long m_LastPageRenderedByThread;
volatile LONG g_lLocker;
static UINT RenderingThread( LPVOID param );
static UINT RenderingThreadThumb( LPVOID param );
static GBool callbackAbortDisplay(void *data);
static UINT ExportingJpgThread( LPVOID param );
bool m_PageRenderedByThread;
bool getNeedNonText();
void setNeedNonText(bool needs);
HANDLE hExportJpgCancel;
HANDLE hRenderFinished;
HANDLE hExportJpgCancelled;
HANDLE hExportJpgFinished;
CRITICAL_SECTION hgMutex;
PDFDoc *createDoc(char *FileName);
public:
PROGRESSHANDLE m_ExportProgressHandle;
NOTIFYHANDLE m_ExportFinishHandle;
NOTIFYHANDLE m_RenderFinishHandle;
PAGERENDERNOTIFY m_RenderNotifyFinishHandle;
private:
GString m_LastOpenedFile;
BaseStream *m_LastOpenedStream;
HANDLE m_renderingThread;
HANDLE m_exportJpgThread;
HANDLE m_renderThumbs;
Queue m_QueuedThumbs;
DynArray<CPDFSearchResult> m_Selection;
DynArray<CPDFSearchResult> m_SelectionPrev;
PDFDoc *m_PDFDoc;
SplashOutputDev *m_thumbOut;
Links *_pageLinks;
AuxOutputDev *m_splashOut;
//SplashOutputDev *m_splashOutThread;
Outline *m_Outline;
PageMemory *m_Bitmap;
string_type m_OwnerPassword;
string_type m_UserPassword;
CRect m_bbox;
CRect m_sliceBox;
double __x0;
double __y0;
//Client Bounds
long m_ViewWidth;
long m_ViewHeight;
long m_ViewX;
long m_ViewY;
//Offset view
long m_ViewOffsetX;
long m_ViewOffsetY;
long m_CurrentPage;
long m_LastPageRendered;
long m_SearchPage;
long m_PageHeight;
long m_PageWidth;
int m_Rotation;
double m_LastRenderDPI;
double m_renderDPI;
bool m_HideMarks;
bool m_bCaseSensitive;
bool m_SearchStarted;
public:
AFPDFDoc(char *configFile);
virtual ~AFPDFDoc();
PDFDoc *getDoc(){
return m_PDFDoc;
}
long DrawPage(int page,long hdc, int width, int height, double dpi,bool bThread, void *callback, bool bAntialising);
bool ThumbInQueue(int page);
bool CancelThumbRender( void );
long LoadFromStream(void *callback,long fullLenght, char *user_password, char *owner_password);
long LoadFromFile(char *FileName, char *user_password, char *owner_password);
long LoadFromFile(char *FileName, char *user_password);
long LoadFromFile(char *sFileName);
bool LoadFromMuPDF();
void SetUserPassword(char *user_password);
void SetOwnerPassword(char *owner_password);
void SetSliceBox(int x, int y, int w, int h);
long RenderPage(long lhWnd);
long RenderPage(long lhWnd, bool bForce);
long RenderPage(long lhWnd, bool bForce, bool enableThread);
long RenderPageMuPDF(long lhWnd, bool bForce, bool enableThread);
long RenderPageThread(long lhWnd, bool bForce);
long RenderPageThreadMuPDF(long lhWnd, bool bForce);
long GetCurrentPage(void);
void SetCurrentPage(long newVal);
long GetCurrentX(void);
void SetCurrentX(long newVal);
long GetCurrentY(void);
void SetCurrentY(long newVal);
long GetViewX(){ return m_ViewX; }
void SetViewX(long newVal){ m_ViewX =newVal; }
long GetViewY(){ return m_ViewY; }
void SetViewY(long newVal){ m_ViewY =newVal; }
long GetViewWidth() { return m_ViewWidth; }
void SetViewWidth(long newVal) { m_ViewWidth =newVal; }
long GetViewHeight() { return m_ViewHeight; }
void SetViewHeight(long newVal) { m_ViewHeight=newVal; }
int SaveJpg(char *fileName,float renderDPI,int fromPage, int toPage, int quality, int waitProc);
int SaveTxt(char *fileName,int firstPage, int lastPage, bool htmlMeta,bool physLayout, bool rawOrder);
//int SaveHtml(char *outFileName, int firstPage, int lastPage, bool noFrames, bool nomerge, bool complexmode);
bool ExportToSWF(char *fileName,char *swfViewer,int fromPage, int toPage,int zoomtowidth,int jpegQuality);
void CancelJpgSave();
//Returns true if exists a background thread of jpg export is running
bool JpgIsBusy();
//Returns true if a background thread is rendering next page
bool IsBusy();
//void WaitForFinish();
bool IsEncrypted(){
return m_PDFDoc->isEncrypted()?true:false;
}
long LoadFromFile2(char * FileName);
long GetPageCount(void);
long NextPage(void);
long PreviousPage(void);
long GotoPage(long PageNumber);
double ZoomIN(void);
double ZoomOut(void);
double FitScreenWidth(long lhWnd);
double FitScreenHeight(long lhWnd);
long GetPageWidth(void);
long GetPageHeight(void);
OutlineItemA* GetOutline(long iOutline);
long GetOutlineCount(void);
long GetOutlinePtr(long iOutline);
long ProcessLinkAction(long lPtrLinkAction);
float GetRenderDPI(void);
void SetRenderDPI(FLOAT newVal);
wchar_t *GetPDFVersion(void);
long FindText(const wchar_t *sText, long iPage, long SearchOrder, bool bCaseSensitive, bool bBackward, bool bMarkAll, bool bWholeDoc, bool bWholeWord, bool stopOnFirstPageResults);
long FindNext(const wchar_t *sText);
long FindPrior(const wchar_t *sText);
long FindFirst(const wchar_t *sText, long SearchOrder, bool Backward, bool WholeWord);
long RenderHDC(long lHdc);
Links *GetLinksPage(long iPage);
LinkDest *findDest(char *destName);
void cvtUserToDev(double ux, double uy, int *dx, int *dy);
void cvtDevToUser(double ux, double uy, double *dx, double *dy);
long GetSearchPage(void);
long SetSearchPage(long lNewValue);
bool GetSearchCaseSensitive(void);
void SetSearchCaseSensitive(bool newVal);
long PrintToFile(LPCTSTR fileName, int fromPage, int toPage);
bool NoEmbedFontExists();
CPDFSearchResult *GetSearchResults();
void PreserveSearchResults();
void RecoverSearchResults();
long GetSearchCount();
int findpage(int num, int gen){ return m_PDFDoc->findPage(num,gen); }
void Dispose();
wchar_t * getTitle();
wchar_t * getAuthor();
wchar_t * getSubject();
wchar_t * getKeywords();
wchar_t * getCreator();
wchar_t * getProducer();
char * getCreationDate();
char * getLastModifiedDate();
//Add support for MuPDF
bool SupportsMuPDF(){
#ifndef _MUPDF_H_
return false;
#else
if(m_LastOpenedFile.getLength()==0 && this->m_LastOpenedStream!=0)
return false;
else
return true;
#endif
}
bool GetUseMuPDF(){
#ifndef _MUPDF
return false;
#endif
return _useMuPDF;
}
void SetUseMuPDF(bool buse){
#ifdef _MUPDF
_useMuPDF =buse;
//InvalidateBitmapCache();
#endif
}
};
struct ExportParams{
AFPDFDoc * _this;
char *fileName;
int fromPage;
int toPage;
int quality;
float renderDPI;
int rotation;
int WaitTime;
};