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
|
#ifdef _WIN32
#include <windows.h>
void win_install(void);
#endif
#include "mupdf/fitz.h"
#include "mupdf/ucdn.h"
#include "mupdf/pdf.h" /* for pdf specifics and forms */
#ifndef __APPLE__
#include <GL/freeglut.h>
#else
#include <GLUT/glut.h>
#endif
/* UI */
enum
{
/* regular control characters */
KEY_ESCAPE = 27,
KEY_ENTER = '\r',
KEY_TAB = '\t',
KEY_BACKSPACE = '\b',
KEY_DELETE = 127,
KEY_CTL_A = 'A' - 64,
KEY_CTL_B, KEY_CTL_C, KEY_CTL_D, KEY_CTL_E, KEY_CTL_F,
KEY_CTL_G, KEY_CTL_H, KEY_CTL_I, KEY_CTL_J, KEY_CTL_K, KEY_CTL_L,
KEY_CTL_M, KEY_CTL_N, KEY_CTL_O, KEY_CTL_P, KEY_CTL_Q, KEY_CTL_R,
KEY_CTL_S, KEY_CTL_T, KEY_CTL_U, KEY_CTL_V, KEY_CTL_W, KEY_CTL_X,
KEY_CTL_Y, KEY_CTL_Z,
/* reuse control characters > 127 for special keys */
KEY_INSERT = 128,
KEY_PAGE_UP,
KEY_PAGE_DOWN,
KEY_HOME,
KEY_END,
KEY_LEFT,
KEY_UP,
KEY_RIGHT,
KEY_DOWN,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
};
enum side { ALL, T, R, B, L };
enum fill { NONE = 0, X = 1, Y = 2, BOTH = 3 };
enum anchor { CENTER, N, NE, E, SE, S, SW, W, NW };
struct layout
{
enum side side;
enum fill fill;
enum anchor anchor;
int padx, pady;
};
struct ui
{
int window_w, window_h;
int x, y;
int down, down_x, down_y;
int middle, middle_x, middle_y;
int right, right_x, right_y;
int scroll_x, scroll_y;
int key, mod, plain;
int grab_down, grab_middle, grab_right;
const void *hot, *active, *focus;
int last_cursor, cursor;
int fontsize;
int baseline;
int lineheight;
int gridsize;
struct layout *layout;
fz_irect *cavity;
struct layout layout_stack[32];
fz_irect cavity_stack[32];
int overlay;
GLuint overlay_list;
void (*dialog)(void);
};
extern struct ui ui;
void ui_init(int w, int h, const char *title);
void ui_quit(void);
void ui_invalidate(void);
void ui_finish(void);
void ui_set_clipboard(const char *buf);
const char *ui_get_clipboard(void);
void ui_init_fonts(float pixelsize);
void ui_finish_fonts(void);
float ui_measure_character(int ucs);
void ui_begin_text(void);
float ui_draw_character(int ucs, float x, float y);
void ui_end_text(void);
float ui_draw_string(float x, float y, const char *str);
float ui_measure_string(const char *str);
struct texture
{
GLuint id;
int x, y, w, h;
float s, t;
};
void ui_texture_from_pixmap(struct texture *tex, fz_pixmap *pix);
void ui_draw_image(struct texture *tex, float x, float y);
enum
{
UI_INPUT_NONE = 0,
UI_INPUT_EDIT = 1,
UI_INPUT_ACCEPT = 2,
};
struct input
{
char text[16*1024];
char *end, *p, *q;
int scroll;
};
struct list
{
fz_irect area;
int scroll_y;
int item_y;
};
void ui_begin(void);
void ui_end(void);
int ui_mouse_inside(fz_irect *area);
void ui_layout(enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
fz_irect ui_pack_layout(int slave_w, int slave_h, enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
fz_irect ui_pack(int slave_w, int slave_h);
void ui_pack_push(fz_irect cavity);
void ui_pack_pop(void);
void ui_dialog_begin(int w, int h);
void ui_dialog_end(void);
void ui_panel_begin(int w, int h, int padx, int pady, int opaque);
void ui_panel_end(void);
void ui_spacer(void);
void ui_splitter(int *x, int min, int max, enum side side);
void ui_label(const char *fmt, ...);
int ui_button(const char *label);
int ui_checkbox(const char *label, int *value);
int ui_slider(int *value, int min, int max, int width);
int ui_select(const void *id, const char *current, const char *options[], int n);
void ui_input_init(struct input *input, const char *text);
int ui_input(struct input *input, int width, int height);
void ui_scrollbar(int x0, int y0, int x1, int y1, int *value, int page_size, int max);
void ui_list_begin(struct list *list, int count, int req_w, int req_h);
int ui_list_item(struct list *list, const void *id, const char *label, int selected);
int ui_list_item_x(struct list *list, const void *id, int indent, const char *label, int selected);
void ui_list_end(struct list *list);
int ui_popup(const void *id, const char *label, int is_button, int count);
int ui_popup_item(const char *title);
void ui_popup_end(void);
void ui_init_open_file(const char *dir, int (*filter)(const char *fn));
int ui_open_file(char filename[]);
void ui_init_save_file(const char *path, int (*filter)(const char *fn));
int ui_save_file(char filename[], void (*extra_panel)(void));
void ui_show_warning_dialog(const char *message);
void ui_show_error_dialog(const char *message);
/* Theming */
enum
{
UI_COLOR_PANEL = 0xc0c0c0,
UI_COLOR_BUTTON = 0xc0c0c0,
UI_COLOR_SCROLLBAR = 0xdfdfdf,
UI_COLOR_TEXT_BG = 0xffffff,
UI_COLOR_TEXT_FG = 0x000000,
UI_COLOR_TEXT_SEL_BG = 0x000080,
UI_COLOR_TEXT_SEL_FG = 0xffffff,
UI_COLOR_BEVEL_1 = 0x000000,
UI_COLOR_BEVEL_2 = 0x808080,
UI_COLOR_BEVEL_3 = 0xdfdfdf,
UI_COLOR_BEVEL_4 = 0xffffff,
};
void glColorHex(unsigned int hex);
void ui_draw_bevel(fz_irect area, int depressed);
void ui_draw_ibevel(fz_irect area, int depressed);
void ui_draw_bevel_rect(fz_irect area, unsigned int fill, int depressed);
void ui_draw_ibevel_rect(fz_irect area, unsigned int fill, int depressed);
/* App */
extern fz_context *ctx;
extern pdf_document *pdf;
extern pdf_page *page;
extern fz_stext_page *page_text;
extern pdf_annot *selected_annot;
extern fz_matrix draw_page_ctm, view_page_ctm, view_page_inv_ctm;
extern fz_rect page_bounds, draw_page_bounds, view_page_bounds;
extern fz_irect view_page_area;
extern char filename[];
void run_main_loop(void);
void do_annotate_panel(void);
void do_annotate_canvas(fz_irect canvas_area);
void render_page(void);
void update_title(void);
void reload(void);
|