Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/platform/gl/gl-app.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 // Copyright (C) 2004-2022 Artifex Software, Inc. | |
| 2 // | |
| 3 // This file is part of MuPDF. | |
| 4 // | |
| 5 // MuPDF is free software: you can redistribute it and/or modify it under the | |
| 6 // terms of the GNU Affero General Public License as published by the Free | |
| 7 // Software Foundation, either version 3 of the License, or (at your option) | |
| 8 // any later version. | |
| 9 // | |
| 10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | |
| 13 // details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU Affero General Public License | |
| 16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html> | |
| 17 // | |
| 18 // Alternative licensing terms are available from the licensor. | |
| 19 // For commercial licensing, see <https://www.artifex.com/> or contact | |
| 20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, | |
| 21 // CA 94129, USA, for further information. | |
| 22 | |
| 23 #ifndef MUPDF_GL_APP_H | |
| 24 #define MUPDF_GL_APP_H | |
| 25 | |
| 26 #ifdef _WIN32 | |
| 27 #include <windows.h> | |
| 28 void win_install(void); | |
| 29 #endif | |
| 30 | |
| 31 #include "mupdf/fitz.h" | |
| 32 #include "mupdf/ucdn.h" | |
| 33 #include "mupdf/pdf.h" /* for pdf specifics and forms */ | |
| 34 | |
| 35 #ifndef __APPLE__ | |
| 36 #include <GL/freeglut.h> | |
| 37 #else | |
| 38 #include <GLUT/glut.h> | |
| 39 #endif | |
| 40 | |
| 41 /* UI */ | |
| 42 | |
| 43 enum | |
| 44 { | |
| 45 /* regular control characters */ | |
| 46 KEY_ESCAPE = 27, | |
| 47 KEY_ENTER = '\r', | |
| 48 KEY_TAB = '\t', | |
| 49 KEY_BACKSPACE = '\b', | |
| 50 KEY_DELETE = 127, | |
| 51 | |
| 52 KEY_CTL_A = 'A' - 64, | |
| 53 KEY_CTL_B, KEY_CTL_C, KEY_CTL_D, KEY_CTL_E, KEY_CTL_F, | |
| 54 KEY_CTL_G, KEY_CTL_H, KEY_CTL_I, KEY_CTL_J, KEY_CTL_K, KEY_CTL_L, | |
| 55 KEY_CTL_M, KEY_CTL_N, KEY_CTL_O, KEY_CTL_P, KEY_CTL_Q, KEY_CTL_R, | |
| 56 KEY_CTL_S, KEY_CTL_T, KEY_CTL_U, KEY_CTL_V, KEY_CTL_W, KEY_CTL_X, | |
| 57 KEY_CTL_Y, KEY_CTL_Z, | |
| 58 | |
| 59 /* reuse control characters > 127 for special keys */ | |
| 60 KEY_INSERT = 128, | |
| 61 KEY_PAGE_UP, | |
| 62 KEY_PAGE_DOWN, | |
| 63 KEY_HOME, | |
| 64 KEY_END, | |
| 65 KEY_LEFT, | |
| 66 KEY_UP, | |
| 67 KEY_RIGHT, | |
| 68 KEY_DOWN, | |
| 69 KEY_F1, | |
| 70 KEY_F2, | |
| 71 KEY_F3, | |
| 72 KEY_F4, | |
| 73 KEY_F5, | |
| 74 KEY_F6, | |
| 75 KEY_F7, | |
| 76 KEY_F8, | |
| 77 KEY_F9, | |
| 78 KEY_F10, | |
| 79 KEY_F11, | |
| 80 KEY_F12, | |
| 81 }; | |
| 82 | |
| 83 enum side { ALL, T, R, B, L }; | |
| 84 enum fill { NONE = 0, X = 1, Y = 2, BOTH = 3 }; | |
| 85 enum anchor { CENTER, N, NE, E, SE, S, SW, W, NW }; | |
| 86 | |
| 87 struct layout | |
| 88 { | |
| 89 enum side side; | |
| 90 enum fill fill; | |
| 91 enum anchor anchor; | |
| 92 int padx, pady; | |
| 93 }; | |
| 94 | |
| 95 struct ui | |
| 96 { | |
| 97 int window_w, window_h; | |
| 98 | |
| 99 int x, y; | |
| 100 int down, down_x, down_y; | |
| 101 int middle, middle_x, middle_y; | |
| 102 int right, right_x, right_y; | |
| 103 | |
| 104 int scroll_x, scroll_y; | |
| 105 int key, mod, plain; | |
| 106 | |
| 107 int grab_down, grab_middle, grab_right; | |
| 108 const void *hot, *active, *focus; | |
| 109 int last_cursor, cursor; | |
| 110 | |
| 111 float scale; | |
| 112 int fontsize; | |
| 113 int baseline; | |
| 114 int lineheight; | |
| 115 int gridsize; | |
| 116 int padsize; | |
| 117 | |
| 118 struct layout *layout; | |
| 119 fz_irect *cavity; | |
| 120 struct layout layout_stack[32]; | |
| 121 fz_irect cavity_stack[32]; | |
| 122 | |
| 123 int overlay; | |
| 124 GLuint overlay_list; | |
| 125 | |
| 126 void (*dialog)(void); | |
| 127 | |
| 128 pdf_annot *selected_annot; | |
| 129 }; | |
| 130 | |
| 131 extern struct ui ui; | |
| 132 | |
| 133 void ui_init_dpi(float override_ui_scale); | |
| 134 void ui_init(int w, int h, const char *title); | |
| 135 void ui_quit(void); | |
| 136 void ui_invalidate(void); | |
| 137 void ui_finish(void); | |
| 138 | |
| 139 void ui_set_clipboard(const char *buf); | |
| 140 const char *ui_get_clipboard(void); | |
| 141 | |
| 142 void ui_init_fonts(void); | |
| 143 void ui_finish_fonts(void); | |
| 144 | |
| 145 void ui_draw_string(float x, float y, const char *str); | |
| 146 void ui_draw_string_part(float x, float y, const char *s, const char *e); | |
| 147 void ui_draw_character(float x, float y, int c); | |
| 148 float ui_measure_character(int ucs); | |
| 149 float ui_measure_string(const char *str); | |
| 150 float ui_measure_string_part(const char *s, const char *e); | |
| 151 | |
| 152 struct line { char *a, *b; }; | |
| 153 | |
| 154 int ui_break_lines(char *a, struct line *lines, int nlines, int width, int *maxwidth); | |
| 155 void ui_draw_lines(float x, float y, struct line *lines, int n); | |
| 156 | |
| 157 struct texture | |
| 158 { | |
| 159 GLuint id; | |
| 160 int x, y, w, h; | |
| 161 float s, t; | |
| 162 }; | |
| 163 | |
| 164 void ui_texture_from_pixmap(struct texture *tex, fz_pixmap *pix); | |
| 165 void ui_draw_image(struct texture *tex, float x, float y); | |
| 166 | |
| 167 enum | |
| 168 { | |
| 169 UI_INPUT_NONE = 0, | |
| 170 UI_INPUT_EDIT = 1, | |
| 171 UI_INPUT_ACCEPT = 2, | |
| 172 }; | |
| 173 | |
| 174 #define UI_INPUT_SIZE (16*1024) | |
| 175 | |
| 176 struct input | |
| 177 { | |
| 178 char text[UI_INPUT_SIZE]; | |
| 179 char *end, *p, *q; | |
| 180 int scroll; | |
| 181 pdf_annot *widget; | |
| 182 }; | |
| 183 | |
| 184 #define UI_READLINE_SIZE 20 | |
| 185 | |
| 186 struct readline | |
| 187 { | |
| 188 struct input input; | |
| 189 char buffer[UI_READLINE_SIZE][UI_INPUT_SIZE]; | |
| 190 char *history[UI_READLINE_SIZE]; | |
| 191 int used; | |
| 192 int current; | |
| 193 }; | |
| 194 | |
| 195 struct list | |
| 196 { | |
| 197 fz_irect area; | |
| 198 int scroll_y; | |
| 199 int item_y; | |
| 200 int is_tree; | |
| 201 }; | |
| 202 | |
| 203 void ui_begin(void); | |
| 204 void ui_end(void); | |
| 205 | |
| 206 int ui_mouse_inside(fz_irect area); | |
| 207 | |
| 208 void ui_layout(enum side side, enum fill fill, enum anchor anchor, int padx, int pady); | |
| 209 fz_irect ui_pack_layout(int slave_w, int slave_h, enum side side, enum fill fill, enum anchor anchor, int padx, int pady); | |
| 210 fz_irect ui_pack(int slave_w, int slave_h); | |
| 211 int ui_available_width(void); | |
| 212 int ui_available_height(void); | |
| 213 void ui_pack_push(fz_irect cavity); | |
| 214 void ui_pack_pop(void); | |
| 215 | |
| 216 void ui_dialog_begin(int w, int h); | |
| 217 void ui_dialog_end(void); | |
| 218 void ui_panel_begin(int w, int h, int padx, int pady, int opaque); | |
| 219 void ui_panel_end(void); | |
| 220 | |
| 221 void ui_spacer(void); | |
| 222 void ui_splitter(int *start, int *x, int min, int max, enum side side); | |
| 223 void ui_label(const char *fmt, ...); | |
| 224 void ui_label_with_scrollbar(char *text, int width, int height, int *scroll, int *sticky); | |
| 225 | |
| 226 int ui_button(const char *label); | |
| 227 /* flags: bit 0 -> disabled. all other bits 0 for now. */ | |
| 228 int ui_button_aux(const char *label, int flags); | |
| 229 int ui_checkbox(const char *label, int *value); | |
| 230 int ui_checkbox_aux(const char *label, int *value, int flags); | |
| 231 int ui_slider(int *value, int min, int max, int width); | |
| 232 int ui_select(const void *id, const char *current, const char *options[], int n); | |
| 233 int ui_select_aux(const void *id, const char *current, const char *options[], int n, int flags); | |
| 234 | |
| 235 void ui_input_init(struct input *input, const char *text); | |
| 236 int ui_input(struct input *input, int width, int height); | |
| 237 void ui_scrollbar(int x0, int y0, int x1, int y1, int *value, int page_size, int max, int *sticky); | |
| 238 | |
| 239 void ui_readline_init(struct readline *readline, const char *text); | |
| 240 const char *ui_readline(struct readline *readline, int width); | |
| 241 | |
| 242 void ui_tree_begin(struct list *list, int count, int req_w, int req_h, int is_tree); | |
| 243 int ui_tree_item(struct list *list, const void *id, const char *label, int selected, int depth, int is_branch, int *is_open); | |
| 244 void ui_tree_end(struct list *list); | |
| 245 | |
| 246 void ui_list_begin(struct list *list, int count, int req_w, int req_h); | |
| 247 int ui_list_item(struct list *list, const void *id, const char *label, int selected); | |
| 248 void ui_list_end(struct list *list); | |
| 249 | |
| 250 int ui_popup(const void *id, const char *label, int is_button, int count); | |
| 251 int ui_popup_item(const char *title); | |
| 252 int ui_popup_aux(const void *id, const char *label, int is_button, int count, int flags); | |
| 253 int ui_popup_item_aux(const char *title, int flags); | |
| 254 void ui_popup_end(void); | |
| 255 | |
| 256 void ui_init_open_file(const char *dir, int (*filter)(const char *fn)); | |
| 257 int ui_open_file(char *filename, const char *label); | |
| 258 void ui_init_save_file(const char *path, int (*filter)(const char *fn)); | |
| 259 int ui_save_file(char *filename, void (*extra_panel)(void), const char *label); | |
| 260 | |
| 261 void ui_show_warning_dialog(const char *fmt, ...); | |
| 262 void ui_show_error_dialog(const char *fmt, ...); | |
| 263 | |
| 264 void ui_select_annot(pdf_annot *annot); | |
| 265 | |
| 266 /* Theming */ | |
| 267 | |
| 268 enum | |
| 269 { | |
| 270 UI_COLOR_PANEL = 0xc0c0c0, | |
| 271 UI_COLOR_BUTTON = 0xc0c0c0, | |
| 272 UI_COLOR_SCROLLBAR = 0xdfdfdf, | |
| 273 UI_COLOR_TEXT_BG = 0xffffff, | |
| 274 UI_COLOR_TEXT_FG = 0x000000, | |
| 275 UI_COLOR_TEXT_GRAY = 0x808080, | |
| 276 UI_COLOR_TEXT_SEL_BG = 0x000080, | |
| 277 UI_COLOR_TEXT_SEL_FG = 0xffffff, | |
| 278 UI_COLOR_BEVEL_1 = 0x000000, | |
| 279 UI_COLOR_BEVEL_2 = 0x808080, | |
| 280 UI_COLOR_BEVEL_3 = 0xdfdfdf, | |
| 281 UI_COLOR_BEVEL_4 = 0xffffff, | |
| 282 }; | |
| 283 | |
| 284 void glColorHex(unsigned int hex); | |
| 285 void ui_draw_bevel(fz_irect area, int depressed); | |
| 286 void ui_draw_ibevel(fz_irect area, int depressed); | |
| 287 void ui_draw_bevel_rect(fz_irect area, unsigned int fill, int depressed); | |
| 288 void ui_draw_ibevel_rect(fz_irect area, unsigned int fill, int depressed); | |
| 289 | |
| 290 /* App */ | |
| 291 | |
| 292 extern fz_context *ctx; | |
| 293 extern fz_colorspace *profile; | |
| 294 extern pdf_document *pdf; | |
| 295 extern pdf_page *page; | |
| 296 extern fz_stext_page *page_text; | |
| 297 extern fz_matrix draw_page_ctm, view_page_ctm, view_page_inv_ctm; | |
| 298 extern fz_rect page_bounds, draw_page_bounds, view_page_bounds; | |
| 299 extern fz_irect view_page_area; | |
| 300 extern char filename[]; | |
| 301 extern int showform; | |
| 302 extern int showannotate; | |
| 303 extern int reloadrequested; | |
| 304 extern char *search_needle; | |
| 305 extern int search_hit_count; | |
| 306 extern fz_quad search_hit_quads[]; | |
| 307 extern int page_contents_changed; | |
| 308 extern int page_annots_changed; | |
| 309 | |
| 310 int search_has_results(void); | |
| 311 enum { | |
| 312 ANNOTATE_MODE_NONE = 0, | |
| 313 ANNOTATE_MODE_NORMAL = 1, | |
| 314 ANNOTATE_MODE_REDACT = 2 | |
| 315 }; | |
| 316 void toggle_annotate(int mode); | |
| 317 void run_main_loop(void); | |
| 318 void do_annotate_panel(void); | |
| 319 void do_annotate_canvas(fz_irect canvas_area); | |
| 320 void do_redact_panel(void); | |
| 321 void do_widget_canvas(fz_irect canvas_area); | |
| 322 void load_page(void); | |
| 323 void update_title(void); | |
| 324 void reload_document(void); | |
| 325 void reload(void); | |
| 326 void do_save_pdf_file(void); | |
| 327 void do_save_signed_pdf_file(void); | |
| 328 int do_sign(void); | |
| 329 void trace_action(const char *fmt, ...); | |
| 330 void trace_page_update(void); | |
| 331 void trace_save_snapshot(void); | |
| 332 const char *format_date(int64_t secs); | |
| 333 | |
| 334 #endif |
