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 | |
19 | typedef struct pdfapp_s pdfapp_t; |
20 | |
21 | enum { ARROW, HAND, WAIT, CARET }; |
22 | |
23 | enum { DISCARD, SAVE, CANCEL }; |
24 | |
25 | enum { QUERY_NO, QUERY_YES }; |
26 | |
27 | extern void winwarn(pdfapp_t*, char *s); |
28 | extern void winerror(pdfapp_t*, char *s); |
29 | extern void wintitle(pdfapp_t*, char *title); |
30 | extern void winresize(pdfapp_t*, int w, int h); |
31 | extern void winrepaint(pdfapp_t*); |
32 | extern void winrepaintsearch(pdfapp_t*); |
33 | extern char *winpassword(pdfapp_t*, char *filename); |
34 | extern char *wintextinput(pdfapp_t*, char *inittext, int retry); |
35 | extern int winchoiceinput(pdfapp_t*, int nopts, const char *opts[], int *nvals, const char *vals[]); |
36 | extern void winopenuri(pdfapp_t*, char *s); |
37 | extern void wincursor(pdfapp_t*, int curs); |
38 | extern void windocopy(pdfapp_t*); |
39 | extern void windrawrect(pdfapp_t*, int x0, int y0, int x1, int y1); |
40 | extern void windrawstring(pdfapp_t*, int x, int y, char *s); |
41 | extern void winclose(pdfapp_t*); |
42 | extern void winhelp(pdfapp_t*); |
43 | extern void winfullscreen(pdfapp_t*, int state); |
44 | extern int winsavequery(pdfapp_t*); |
45 | extern int winquery(pdfapp_t*, const char*); |
46 | extern int wingetcertpath(char *buf, int len); |
47 | extern int wingetsavepath(pdfapp_t*, char *buf, int len); |
48 | extern void winalert(pdfapp_t *, pdf_alert_event *alert); |
49 | extern void winprint(pdfapp_t *); |
50 | extern void winadvancetimer(pdfapp_t *, float duration); |
51 | extern void winreplacefile(char *source, char *target); |
52 | extern void wincopyfile(char *source, char *target); |
53 | extern void winreloadpage(pdfapp_t *); |
54 | |
55 | struct 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 | |
158 | void pdfapp_init(fz_context *ctx, pdfapp_t *app); |
159 | void pdfapp_setresolution(pdfapp_t *app, int res); |
160 | void pdfapp_open(pdfapp_t *app, char *filename, int reload); |
161 | void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int kbps); |
162 | void pdfapp_close(pdfapp_t *app); |
163 | int pdfapp_preclose(pdfapp_t *app); |
164 | void pdfapp_reloadfile(pdfapp_t *app); |
165 | |
166 | char *pdfapp_version(pdfapp_t *app); |
167 | char *pdfapp_usage(pdfapp_t *app); |
168 | |
169 | void pdfapp_onkey(pdfapp_t *app, int c, int modifiers); |
170 | void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state); |
171 | void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen); |
172 | void pdfapp_onresize(pdfapp_t *app, int w, int h); |
173 | void pdfapp_gotopage(pdfapp_t *app, int number); |
174 | void pdfapp_reloadpage(pdfapp_t *app); |
175 | void pdfapp_autozoom_horizontal(pdfapp_t *app); |
176 | void pdfapp_autozoom_vertical(pdfapp_t *app); |
177 | void pdfapp_autozoom(pdfapp_t *app); |
178 | |
179 | void pdfapp_invert(pdfapp_t *app, fz_rect rect); |
180 | void pdfapp_inverthit(pdfapp_t *app); |
181 | |
182 | void pdfapp_postblit(pdfapp_t *app); |
183 | |
184 | #endif |
185 | |