| 1 | /* |
| 2 | * Print plug-in header file for the GIMP. |
| 3 | * |
| 4 | * Copyright 1997-2000 Michael Sweet ([email protected]) and |
| 5 | * Robert Krawitz ([email protected]) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
| 9 | * Software Foundation; either version 2 of the License, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | * for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | * Revision History: |
| 21 | * |
| 22 | * See ChangeLog |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * This file must include only standard C header files. The core code must |
| 27 | * compile on generic platforms that don't support glib, gimp, gtk, etc. |
| 28 | */ |
| 29 | |
| 30 | #ifndef GUTENPRINT_INTERNAL_INTERNAL_H |
| 31 | #define GUTENPRINT_INTERNAL_INTERNAL_H |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
| 37 | #ifdef HAVE_CONFIG_H |
| 38 | #include <config.h> |
| 39 | #endif |
| 40 | |
| 41 | #include <gutenprint/gutenprint-module.h> |
| 42 | #include <time.h> |
| 43 | |
| 44 | /** |
| 45 | * Utility functions (internal). |
| 46 | * |
| 47 | * @defgroup util_internal util-internal |
| 48 | * @{ |
| 49 | */ |
| 50 | |
| 51 | extern void stpi_init_paper(void); |
| 52 | extern void stpi_init_dither(void); |
| 53 | extern void stpi_init_printer(void); |
| 54 | #define BUFFER_FLAG_FLIP_X 0x1 |
| 55 | #define BUFFER_FLAG_FLIP_Y 0x2 |
| 56 | extern stp_image_t* stpi_buffer_image(stp_image_t* image, unsigned int flags); |
| 57 | |
| 58 | #define STPI_ASSERT(x,v) \ |
| 59 | do \ |
| 60 | { \ |
| 61 | if (stp_get_debug_level() & STP_DBG_ASSERTIONS) \ |
| 62 | stp_erprintf("DEBUG: Testing assertion %s file %s line %d\n", \ |
| 63 | #x, __FILE__, __LINE__); \ |
| 64 | if (!(x)) \ |
| 65 | { \ |
| 66 | stp_erprintf("\nERROR: ***Gutenprint %s assertion %s failed!" \ |
| 67 | " file %s, line %d. %s\n", PACKAGE_VERSION, \ |
| 68 | #x, __FILE__, __LINE__, "Please report this bug!"); \ |
| 69 | if ((v)) stp_vars_print_error((v), "ERROR"); \ |
| 70 | stp_abort(); \ |
| 71 | } \ |
| 72 | } while (0) |
| 73 | |
| 74 | /** @} */ |
| 75 | |
| 76 | /* Internal printer stuff, moved from printers.h */ |
| 77 | typedef struct |
| 78 | { |
| 79 | stp_parameter_list_t (*list_parameters)(const stp_vars_t *v); |
| 80 | void (*parameters)(const stp_vars_t *v, const char *name, |
| 81 | stp_parameter_t *); |
| 82 | void (*media_size)(const stp_vars_t *v, stp_dimension_t *width, |
| 83 | stp_dimension_t *height); |
| 84 | void (*imageable_area)(const stp_vars_t *v, stp_dimension_t *left, |
| 85 | stp_dimension_t *right, stp_dimension_t *bottom, |
| 86 | stp_dimension_t *top); |
| 87 | void (*maximum_imageable_area)(const stp_vars_t *v, stp_dimension_t *left, |
| 88 | stp_dimension_t *right, stp_dimension_t *bottom, |
| 89 | stp_dimension_t *top); |
| 90 | void (*limit)(const stp_vars_t *v, stp_dimension_t *max_width, |
| 91 | stp_dimension_t *max_height, stp_dimension_t *min_width, |
| 92 | stp_dimension_t *min_height); |
| 93 | int (*print)(const stp_vars_t *v, stp_image_t *image); |
| 94 | void (*describe_resolution)(const stp_vars_t *v, stp_resolution_t *x, |
| 95 | stp_resolution_t *y); |
| 96 | const char *(*describe_output)(const stp_vars_t *v); |
| 97 | int (*verify)(stp_vars_t *v); |
| 98 | int (*start_job)(const stp_vars_t *v, stp_image_t *image); |
| 99 | int (*end_job)(const stp_vars_t *v, stp_image_t *image); |
| 100 | stp_string_list_t *(*get_external_options)(const stp_vars_t *v); |
| 101 | const stp_papersize_t *(*describe_papersize)(const stp_vars_t *v, |
| 102 | const char *name); |
| 103 | } stp_printfuncs_t; |
| 104 | |
| 105 | typedef struct stp_family |
| 106 | { |
| 107 | const stp_printfuncs_t *printfuncs; /* printfuncs for the printer */ |
| 108 | stp_list_t *printer_list; /* list of printers */ |
| 109 | } stp_family_t; |
| 110 | |
| 111 | extern int stpi_family_register(stp_list_t *family); |
| 112 | extern int stpi_family_unregister(stp_list_t *family); |
| 113 | |
| 114 | |
| 115 | /* |
| 116 | * Paper size functions |
| 117 | */ |
| 118 | |
| 119 | typedef stp_list_t stp_papersize_list_t; |
| 120 | typedef stp_list_item_t stp_papersize_list_item_t; |
| 121 | #define stpi_papersize_list_get_start stp_list_get_start |
| 122 | #define stpi_papersize_list_get_end stp_list_get_end |
| 123 | #define stpi_paperlist_item_next stp_list_item_next |
| 124 | #define stpi_paperlist_item_prev stp_list_item_prev |
| 125 | #define stpi_paperlist_item_get_data(item) (stp_papersize_t *) (stp_list_item_get_data((item))) |
| 126 | |
| 127 | /** |
| 128 | * Get a named list of paper sizes |
| 129 | * @param name the list of paper sizes to find |
| 130 | * @param file name of the file to load (relative to $STP_XML_PATH) |
| 131 | * if the list does not exist. Empty filename indicates that the system |
| 132 | * should identify the file; NULL indicates that the list should not be |
| 133 | * created if it does not exist. |
| 134 | * @returns a static pointer to the papersize list, or NULL on failure |
| 135 | */ |
| 136 | extern const stp_papersize_list_t *stpi_get_papersize_list_named(const char *name, |
| 137 | const char *file); |
| 138 | |
| 139 | /** |
| 140 | * Create a new list of paper sizes without loading from a file. |
| 141 | * @param name the list of paper sizes to create |
| 142 | * @returns a static pointer to the (mutable) papersize list, |
| 143 | * or NULL if the list already exists |
| 144 | */ |
| 145 | extern stp_papersize_list_t *stpi_new_papersize_list(const char *name); |
| 146 | |
| 147 | /** |
| 148 | * Find an existing papersize list, if it exists |
| 149 | * @param name the list of paper sizes to find |
| 150 | * @returns a static pointer to the (mutable) papersize list, |
| 151 | * or NULL if the list does not exist |
| 152 | */ |
| 153 | extern stp_papersize_list_t *stpi_find_papersize_list_named(const char *name); |
| 154 | |
| 155 | /** |
| 156 | * Get the standard papersize list. |
| 157 | * @returns a static const pointer to the standard paper list. |
| 158 | */ |
| 159 | extern const stp_papersize_list_t *stpi_get_standard_papersize_list(void); |
| 160 | |
| 161 | /** |
| 162 | * Create and return a new paper list |
| 163 | * @returns a pointer to the new paper list |
| 164 | */ |
| 165 | extern stp_papersize_list_t *stpi_create_papersize_list(void); |
| 166 | |
| 167 | /** |
| 168 | * Get a papersize by its name from a list of papersizes Paper sizes |
| 169 | * @param list the list of papers to search |
| 170 | * @param name the name of the paper to search for |
| 171 | * @returns a static pointer to the papersize, or NULL on failure. |
| 172 | */ |
| 173 | extern const stp_papersize_t *stpi_get_papersize_by_name(const stp_papersize_list_t *list, |
| 174 | const char *name); |
| 175 | |
| 176 | /** |
| 177 | * Dispatch to printer-specific call to describe paper size |
| 178 | * @param v the Gutenprint vars object |
| 179 | * @param name the name of the paper size |
| 180 | * @returns a static pointer to the papersize, or NULL on failure. |
| 181 | */ |
| 182 | extern const stp_papersize_t *stpi_printer_describe_papersize(const stp_vars_t *v, |
| 183 | const char *name); |
| 184 | |
| 185 | |
| 186 | /** |
| 187 | * Get a papersize by its name from the standard list of papersizes |
| 188 | * @param v the Gutenprint vars object |
| 189 | * @param name the name of the paper size |
| 190 | * @returns a static pointer to the papersize, or NULL on failure. |
| 191 | */ |
| 192 | extern const stp_papersize_t *stpi_standard_describe_papersize(const stp_vars_t *v, |
| 193 | const char *name); |
| 194 | |
| 195 | /** |
| 196 | * Add a new papersize to a list |
| 197 | * @param list the name of the list to search |
| 198 | * @param papersize the stp_papersize_t to add |
| 199 | * @returns 1 on success, 0 on failure (e. g. already exists) |
| 200 | */ |
| 201 | extern int stpi_papersize_create(stp_papersize_list_t *list, |
| 202 | stp_papersize_t *p); |
| 203 | |
| 204 | /** |
| 205 | * Get a papersize by its name from a list |
| 206 | * @param list the name of the list to search |
| 207 | * @param name the name of the paper size |
| 208 | * @returns a static pointer to the papersize, or NULL on failure. |
| 209 | */ |
| 210 | extern const stp_papersize_t *stpi_get_listed_papersize(const char *list, |
| 211 | const char *name); |
| 212 | |
| 213 | /** |
| 214 | * Get the number of available papersizes. |
| 215 | * @param list the paper size list |
| 216 | * @returns the number of papersizes. |
| 217 | */ |
| 218 | extern int stpi_papersize_count(const stp_list_t *paper_size_list); |
| 219 | |
| 220 | /** |
| 221 | * Get a papersize by size. |
| 222 | * The nearest available size to the size requested will be found. |
| 223 | * Only paper sizes within 5 points of width and height will be considered. |
| 224 | * @param v the Gutenprint vars object |
| 225 | * @param length the length of the paper. |
| 226 | * @param width the width of the paper |
| 227 | * @returns a static pointer to the papersize, or NULL on failure. |
| 228 | */ |
| 229 | extern const stp_papersize_t *stpi_get_papersize_by_size(const stp_papersize_list_t *l, |
| 230 | stp_dimension_t length, |
| 231 | stp_dimension_t width); |
| 232 | |
| 233 | /** |
| 234 | * Get a papersize by size if an exact match is found. |
| 235 | * @param v the Gutenprint vars object |
| 236 | * @param length the length of the paper. |
| 237 | * @param width the width of the paper |
| 238 | * @returns a static pointer to the papersize, or NULL on failure. |
| 239 | */ |
| 240 | extern const stp_papersize_t *stpi_get_papersize_by_size_exact(const stp_papersize_list_t *l, |
| 241 | stp_dimension_t length, |
| 242 | stp_dimension_t width); |
| 243 | |
| 244 | /** |
| 245 | * Check for duplicate printers. Abort if any duplicates are found. |
| 246 | */ |
| 247 | extern void stpi_find_duplicate_printers(void); |
| 248 | |
| 249 | extern time_t stpi_time(time_t *t); |
| 250 | |
| 251 | #define CAST_IS_SAFE GCC_DIAG_OFF(cast-qual) |
| 252 | #define CAST_IS_UNSAFE GCC_DIAG_ON(cast-qual) |
| 253 | |
| 254 | #pragma GCC diagnostic ignored "-Woverlength-strings" |
| 255 | #pragma GCC diagnostic push |
| 256 | #pragma GCC diagnostic ignored "-Wcast-qual" |
| 257 | static inline void * |
| 258 | stpi_cast_safe(const void *ptr) |
| 259 | { |
| 260 | return (void *)ptr; |
| 261 | } |
| 262 | #pragma GCC diagnostic pop |
| 263 | |
| 264 | #ifdef __cplusplus |
| 265 | } |
| 266 | #endif |
| 267 | |
| 268 | #endif /* GUTENPRINT_INTERNAL_INTERNAL_H */ |