1 /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. 2 3 Copyright (C) 2002-2015 by Jin-Hwan Cho and Shunsaku Hirata, 4 the dvipdfmx project team. 5 6 Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 21 */ 22 23 #ifndef _PDFDEV_H_ 24 #define _PDFDEV_H_ 25 26 #include "numbers.h" 27 #include "pdfobj.h" 28 #include "pdfcolor.h" 29 30 typedef signed long spt_t; 31 32 typedef struct pdf_tmatrix 33 { 34 double a, b, c, d, e, f; 35 } pdf_tmatrix; 36 37 typedef struct pdf_rect 38 { 39 double llx, lly, urx, ury; 40 } pdf_rect; 41 42 typedef struct pdf_coord 43 { 44 double x, y; 45 } pdf_coord; 46 47 /* The name transform_info is misleading. 48 * I'll put this here for a moment... 49 */ 50 typedef struct 51 { 52 /* Physical dimensions 53 * 54 * If those values are given, images will be scaled 55 * and/or shifted to fit within a box described by 56 * those values. 57 */ 58 double width; 59 double height; 60 double depth; 61 62 pdf_tmatrix matrix; /* transform matrix */ 63 pdf_rect bbox; /* user_bbox */ 64 65 int flags; 66 } transform_info; 67 #define INFO_HAS_USER_BBOX (1 << 0) 68 #define INFO_HAS_WIDTH (1 << 1) 69 #define INFO_HAS_HEIGHT (1 << 2) 70 #define INFO_DO_CLIP (1 << 3) 71 #define INFO_DO_HIDE (1 << 4) 72 extern void transform_info_clear (transform_info *info); 73 74 75 extern void pdf_dev_set_verbose (void); 76 77 /* Not in spt_t. */ 78 extern int pdf_sprint_matrix (char *buf, const pdf_tmatrix *p); 79 extern int pdf_sprint_rect (char *buf, const pdf_rect *p); 80 extern int pdf_sprint_coord (char *buf, const pdf_coord *p); 81 extern int pdf_sprint_length (char *buf, double value); 82 extern int pdf_sprint_number (char *buf, double value); 83 84 /* unit_conv: multiplier for input unit (spt_t) to bp conversion. 85 * precision: How many fractional digits preserved in output (not real 86 * accuracy control). 87 * is_bw: Ignore color related special instructions. 88 */ 89 extern void pdf_init_device (double unit_conv, int precision, int is_bw); 90 extern void pdf_close_device (void); 91 92 /* returns 1.0/unit_conv */ 93 extern double dev_unit_dviunit (void); 94 95 #if 0 96 /* DVI interpreter knows text positioning in relative motion. 97 * However, pdf_dev_set_string() recieves text string with placement 98 * in absolute position in user space, and it convert absolute 99 * positioning back to relative positioning. It is quite wasteful. 100 * 101 * TeX using DVI register stack operation to do CR and then use down 102 * command for LF. DVI interpreter knows hint for current leading 103 * and others (raised or lowered), but they are mostly lost in 104 * pdf_dev_set_string(). 105 */ 106 107 typedef struct 108 { 109 int argc; 110 111 struct { 112 int is_kern; /* kern or string */ 113 114 spt_t kern; /* negative kern means space */ 115 116 int offset; /* offset to sbuf */ 117 int length; /* length of string */ 118 } args[]; 119 120 unsigned char sbuf[PDF_STRING_LEN_MAX]; 121 122 } pdf_text_string; 123 124 /* Something for handling raise, leading, etc. here. */ 125 126 #endif 127 128 /* Draw texts and rules: 129 * 130 * xpos, ypos, width, and height are all fixed-point numbers 131 * converted to big-points by multiplying unit_conv (dvi2pts). 132 * They must be position in the user space. 133 * 134 * ctype: 135 * 0 - input string is in multi-byte encoding. 136 * 1 - input string is in 8-bit encoding. 137 * 2 - input string is in 16-bit encoding. 138 */ 139 extern void pdf_dev_set_string (spt_t xpos, spt_t ypos, 140 const void *instr_ptr, int instr_len, 141 spt_t text_width, 142 int font_id, int ctype); 143 extern void pdf_dev_set_rule (spt_t xpos, spt_t ypos, 144 spt_t width, spt_t height); 145 146 /* Place XObject */ 147 extern int pdf_dev_put_image (int xobj_id, 148 transform_info *p, double ref_x, double ref_y); 149 150 /* The design_size and ptsize required by PK font support... 151 */ 152 extern int pdf_dev_locate_font (const char *font_name, spt_t ptsize); 153 154 extern int pdf_dev_setfont (const char *font_name, spt_t ptsize); 155 156 /* The following two routines are NOT WORKING. 157 * Dvipdfmx doesn't manage gstate well.. 158 */ 159 #if 0 160 /* pdf_dev_translate() or pdf_dev_concat() should be used. */ 161 extern void pdf_dev_set_origin (double orig_x, double orig_y); 162 #endif 163 /* Always returns 1.0, please rename this. */ 164 extern double pdf_dev_scale (void); 165 166 /* Access text state parameters. */ 167 #if 0 168 extern int pdf_dev_currentfont (void); /* returns font_id */ 169 extern double pdf_dev_get_font_ptsize (int font_id); 170 #endif 171 extern int pdf_dev_get_font_wmode (int font_id); /* ps: special support want this (pTeX). */ 172 173 /* Text composition (direction) mode 174 * This affects only when auto_rotate is enabled. 175 */ 176 extern int pdf_dev_get_dirmode (void); 177 extern void pdf_dev_set_dirmode (int dir_mode); 178 179 /* Set rect to rectangle in device space. 180 * Unit conversion spt_t to bp and transformation applied within it. 181 */ 182 extern void pdf_dev_set_rect (pdf_rect *rect, 183 spt_t x_pos, spt_t y_pos, 184 spt_t width, spt_t height, spt_t depth); 185 186 /* Accessor to various device parameters. 187 */ 188 #define PDF_DEV_PARAM_AUTOROTATE 1 189 #define PDF_DEV_PARAM_COLORMODE 2 190 191 extern int pdf_dev_get_param (int param_type); 192 extern void pdf_dev_set_param (int param_type, int value); 193 194 /* Text composition mode is ignored (always same as font's 195 * writing mode) and glyph rotation is not enabled if 196 * auto_rotate is unset. 197 */ 198 #define pdf_dev_set_autorotate(v) pdf_dev_set_param(PDF_DEV_PARAM_AUTOROTATE, (v)) 199 #define pdf_dev_set_colormode(v) pdf_dev_set_param(PDF_DEV_PARAM_COLORMODE, (v)) 200 201 /* 202 * For pdf_doc, pdf_draw and others. 203 */ 204 205 /* Force reselecting font and color: 206 * XFrom (content grabbing) and Metapost support want them. 207 */ 208 extern void pdf_dev_reset_fonts (int newpage); 209 extern void pdf_dev_reset_color (int force); 210 211 /* Initialization of transformation matrix with M and others. 212 * They are called within pdf_doc_begin_page() and pdf_doc_end_page(). 213 */ 214 extern void pdf_dev_bop (const pdf_tmatrix *M); 215 extern void pdf_dev_eop (void); 216 217 /* Text is normal and line art is not normal in dvipdfmx. So we don't have 218 * begin_text (BT in PDF) and end_text (ET), but instead we have graphics_mode() 219 * to terminate text section. pdf_dev_flushpath() and others call this. 220 */ 221 extern void graphics_mode (void); 222 223 extern void pdf_dev_get_coord(double *xpos, double *ypos); 224 extern void pdf_dev_push_coord(double xpos, double ypos); 225 extern void pdf_dev_pop_coord(void); 226 227 #endif /* _PDFDEV_H_ */ 228