1#ifndef PDFAPP_H
2#define PDFAPP_H
3
4#include "mupdf/fitz.h"
5#include "mupdf/pdf.h"
6
7#include <time.h>
8
9/*
10 * Utility object for handling a pdf application / view
11 * Takes care of PDF loading and displaying and navigation,
12 * uses a number of callbacks to the GUI app.
13 */
14
15/* 25% .. 1600% */
16#define MINRES 18
17#define MAXRES 1152
18
19typedef struct pdfapp_s pdfapp_t;
20
21enum { ARROW, HAND, WAIT, CARET };
22
23enum { DISCARD, SAVE, CANCEL };
24
25enum { QUERY_NO, QUERY_YES };
26
27extern void winwarn(pdfapp_t*, char *s);
28extern void winerror(pdfapp_t*, char *s);
29extern void wintitle(pdfapp_t*, char *title);
30extern void winresize(pdfapp_t*, int w, int h);
31extern void winrepaint(pdfapp_t*);
32extern void winrepaintsearch(pdfapp_t*);
33extern char *winpassword(pdfapp_t*, char *filename);
34extern char *wintextinput(pdfapp_t*, char *inittext, int retry);
35extern int winchoiceinput(pdfapp_t*, int nopts, const char *opts[], int *nvals, const char *vals[]);
36extern void winopenuri(pdfapp_t*, char *s);
37extern void wincursor(pdfapp_t*, int curs);
38extern void windocopy(pdfapp_t*);
39extern void windrawrect(pdfapp_t*, int x0, int y0, int x1, int y1);
40extern void windrawstring(pdfapp_t*, int x, int y, char *s);
41extern void winclose(pdfapp_t*);
42extern void winhelp(pdfapp_t*);
43extern void winfullscreen(pdfapp_t*, int state);
44extern int winsavequery(pdfapp_t*);
45extern int winquery(pdfapp_t*, const char*);
46extern int wingetcertpath(char *buf, int len);
47extern int wingetsavepath(pdfapp_t*, char *buf, int len);
48extern void winalert(pdfapp_t *, pdf_alert_event *alert);
49extern void winprint(pdfapp_t *);
50extern void winadvancetimer(pdfapp_t *, float duration);
51extern void winreplacefile(char *source, char *target);
52extern void wincopyfile(char *source, char *target);
53extern void winreloadpage(pdfapp_t *);
54
55struct pdfapp_s
56{
57 /* current document params */
58 fz_document *doc;
59 char *docpath;
60 char *doctitle;
61 fz_outline *outline;
62 int outline_deferred;
63
64 float layout_w;
65 float layout_h;
66 float layout_em;
67 char *layout_css;
68 int layout_use_doc_css;
69
70 int pagecount;
71
72 /* current view params */
73 float default_resolution;
74 float resolution;
75 int rotate;
76 fz_pixmap *image;
77 int imgw, imgh;
78 int grayscale;
79 fz_colorspace *colorspace;
80 int invert;
81 int tint, tint_white;
82 int useicc;
83 int useseparations;
84 int aalevel;
85
86 /* presentation mode */
87 int presentation_mode;
88 int transitions_enabled;
89 fz_pixmap *old_image;
90 fz_pixmap *new_image;
91 clock_t start_time;
92 int in_transit;
93 float duration;
94 fz_transition transition;
95
96 /* current page params */
97 int pageno;
98 fz_page *page;
99 fz_rect page_bbox;
100 fz_display_list *page_list;
101 fz_display_list *annotations_list;
102 fz_stext_page *page_text;
103 fz_link *page_links;
104 int errored;
105 int incomplete;
106
107 /* separations */
108 fz_separations *seps;
109
110 /* snapback history */
111 int hist[256];
112 int histlen;
113 int marks[10];
114
115 /* window system sizes */
116 int winw, winh;
117 int scrw, scrh;
118 int shrinkwrap;
119 int fullscreen;
120
121 /* event handling state */
122 char number[256];
123 int numberlen;
124
125 int ispanning;
126 int panx, pany;
127
128 int iscopying;
129 int selx, sely;
130 /* TODO - While sely keeps track of the relative change in
131 * cursor position between two ticks/events, beyondy shall keep
132 * track of the relative change in cursor position from the
133 * point where the user hits a scrolling limit. This is ugly.
134 * Used in pdfapp.c:pdfapp_onmouse.
135 */
136 int beyondy;
137 fz_rect selr;
138
139 int nowaitcursor;
140
141 /* search state */
142 int issearching;
143 int searchdir;
144 char search[512];
145 int searchpage;
146 fz_quad hit_bbox[512];
147 int hit_count;
148
149 /* client context storage */
150 void *userdata;
151
152 fz_context *ctx;
153#ifdef HAVE_CURL
154 fz_stream *stream;
155#endif
156};
157
158void pdfapp_init(fz_context *ctx, pdfapp_t *app);
159void pdfapp_setresolution(pdfapp_t *app, int res);
160void pdfapp_open(pdfapp_t *app, char *filename, int reload);
161void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int kbps);
162void pdfapp_close(pdfapp_t *app);
163int pdfapp_preclose(pdfapp_t *app);
164void pdfapp_reloadfile(pdfapp_t *app);
165
166char *pdfapp_version(pdfapp_t *app);
167char *pdfapp_usage(pdfapp_t *app);
168
169void pdfapp_onkey(pdfapp_t *app, int c, int modifiers);
170void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state);
171void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen);
172void pdfapp_onresize(pdfapp_t *app, int w, int h);
173void pdfapp_gotopage(pdfapp_t *app, int number);
174void pdfapp_reloadpage(pdfapp_t *app);
175void pdfapp_autozoom_horizontal(pdfapp_t *app);
176void pdfapp_autozoom_vertical(pdfapp_t *app);
177void pdfapp_autozoom(pdfapp_t *app);
178
179void pdfapp_invert(pdfapp_t *app, fz_rect rect);
180void pdfapp_inverthit(pdfapp_t *app);
181
182void pdfapp_postblit(pdfapp_t *app);
183
184#endif
185