1 /* 2 * (c) Copyright 2003-2004 Uwe Steinmann. 3 * All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 * Boston, MA 02111-1307, USA. 19 */ 20 21 #ifndef __PS_INTERN_H__ 22 #define __PS_INTERN_H__ 23 24 #ifdef ENABLE_NLS 25 #include <libintl.h> 26 #define _(a) dgettext(GETTEXT_PACKAGE, a) 27 #else 28 #define _(a) a 29 #endif 30 31 #include <locale.h> 32 #include "libps/pslib.h" 33 #include "libps/psversion.h" 34 #include "ps_list.h" 35 #include "ps_strbuf.h" 36 #include "ght_hash_table.h" 37 #ifdef HAVE_LIBPNJ 38 #include "libhnj/hyphen.h" 39 #else 40 #include "hyphen.h" 41 #endif 42 43 #ifndef WIN32 44 #define max(a,b) ((a)>(b) ? (a) : (b)) 45 #define min(a,b) ((a)<(b) ? (a) : (b)) 46 #endif 47 48 #define PS_BORDER_UNSET 0 49 #define PS_BORDER_SOLID 1 50 #define PS_BORDER_DASHED 2 51 52 /* horizontal modes for PS_show_boxed() */ 53 #define PS_TEXT_HMODE_JUSTIFY 1 54 #define PS_TEXT_HMODE_LEFT 2 55 #define PS_TEXT_HMODE_RIGHT 3 56 #define PS_TEXT_HMODE_CENTER 4 57 #define PS_TEXT_HMODE_FULLJUSTIFY 5 58 59 typedef struct encoding_ ENCODING; 60 61 typedef struct lig_ LIG; 62 63 typedef struct kern_ KERN; 64 65 typedef struct adobeptr_ ADOBEPTR; 66 67 typedef struct pcc_ PCC; 68 69 typedef struct adobeinfo_ ADOBEINFO; 70 71 typedef struct adobefontmetric_ ADOBEFONTMETRIC; 72 73 typedef union _optvalue_value { 74 long lval; /* long value */ 75 double dval; /* double value */ 76 struct { 77 char *val; 78 int len; 79 } str; 80 ght_hash_table_t *ht; /* hash table value */ 81 } optvalue_value; 82 83 typedef struct _optval_struct optval; 84 85 struct _optval_struct { 86 optvalue_value value; 87 char type; 88 }; 89 90 struct lig_ { 91 struct lig_ *next ; 92 char *succ, *sub ; 93 short op, boundleft ; 94 }; 95 96 struct encoding_ { 97 char *name ; 98 char *vec[256] ; 99 }; 100 101 struct kern_ { 102 struct kern_ *next ; 103 char *succ ; 104 int delta ; 105 }; 106 107 struct adobeptr_ { 108 struct adobeptr_ *next; 109 struct adobeinfo_ *ch; 110 }; 111 112 struct pcc_ { 113 struct pcc_ *next ; 114 char * partname ; 115 int xoffset, yoffset ; 116 }; 117 118 struct adobeinfo_ { 119 int adobenum, texnum, width ; 120 char *adobename ; 121 int llx, lly, urx, ury ; 122 LIG *ligs ; 123 KERN *kerns ; 124 ADOBEPTR *kern_equivs ; 125 PCC *pccs ; 126 int lkern, rkern; /* Kerning on left and right margin */ 127 }; 128 129 struct adobefontmetric_ { 130 ght_hash_table_t *gadobechars; 131 FILE *afmin; /* File for encoding */ 132 char *fontname; // = "Unknown" ; 133 char *codingscheme; // = "Unspecified" ; 134 ght_hash_table_t *fontenc; 135 #ifdef VMCMS 136 char *ebfontname ; 137 char *ebcodingscheme ; 138 #endif 139 float italicangle; // = 0.0 ; 140 float underlineposition; 141 float underlinethickness; 142 float ascender; 143 float descender; 144 char fixedpitch ; 145 char makevpl ; 146 char pedantic ; 147 int xheight; // = 400 ; 148 int fontspace ; 149 int bc, ec ; 150 long cksum ; 151 float efactor; // = 1.0; 152 float slant; // = 0.0 ; 153 float capheight; // = 0.8 ; 154 char *efactorparam, *slantparam ; 155 double newslant ; 156 }; 157 158 typedef struct PSColor_ PSColor; 159 160 typedef struct PSImage_ PSImage; 161 162 struct PSImage_ { 163 PSDoc *psdoc; // Doc for which this font was created 164 char *name; // currently only used for templates 165 char *type; 166 char *data; 167 long length; 168 int width; 169 int height; 170 int components; 171 int bpc; 172 int colorspace; 173 ps_bool ismask; 174 PSColor *palette; 175 int numcolors; 176 PSImage *imagemask; // Use other image a s mask for this image 177 ps_bool isreusable; 178 }; 179 180 typedef struct PSFont_ PSFont; 181 182 struct PSFont_ { 183 PSDoc *psdoc; // Doc for which this font was created 184 char *name; // currently not used 185 float size; 186 int wordspace; 187 char *encoding; 188 ADOBEFONTMETRIC *metrics; 189 }; 190 191 typedef struct PSPattern_ PSPattern; 192 193 struct PSPattern_ { 194 PSDoc *psdoc; // Doc for which this font was created 195 char *name; 196 int painttype; 197 int shading; 198 float width; 199 float height; 200 float xstep; 201 float ystep; 202 }; 203 204 #define PS_COLORSPACE_GRAY 1 205 #define PS_COLORSPACE_RGB 2 206 #define PS_COLORSPACE_CMYK 3 207 #define PS_COLORSPACE_SPOT 4 208 #define PS_COLORSPACE_PATTERN 5 209 #define PS_COLORSPACE_INDEXED 6 210 211 #define PS_COLORTYPE_FILL 1 212 #define PS_COLORTYPE_STROKE 2 213 214 typedef struct PSSpotColor_ PSSpotColor; 215 216 struct PSSpotColor_ { 217 PSDoc *psdoc; // Doc for which this font was created 218 char *name; 219 int colorspace; 220 float c1; 221 float c2; 222 float c3; 223 float c4; 224 }; 225 226 struct PSColor_ { 227 int colorspace; 228 int prevcolorspace; // The last colorspace used for pattern of type 1 229 int pattern; // The pattern id 230 float c1; 231 float c2; 232 float c3; 233 float c4; 234 }; 235 236 typedef struct PSShading_ PSShading; 237 238 struct PSShading_ { 239 char *name; 240 int type; 241 float x0; 242 float y0; 243 float x1; 244 float y1; 245 float r0; 246 float r1; 247 float N; 248 ps_bool extend0; 249 ps_bool extend1; 250 ps_bool antialias; 251 PSColor startcolor; 252 PSColor endcolor; 253 }; 254 255 typedef struct PSGState_ PSGState; 256 257 struct PSGState_ { 258 char *name; 259 /* x, y for drawing */ 260 float x; 261 float y; 262 263 /* current fill color */ 264 PSColor fillcolor; 265 ps_bool fillcolorinvalid; /* set to ps_true if fill color has changed */ 266 267 /* current stroke color */ 268 PSColor strokecolor; 269 ps_bool strokecolorinvalid; /* set to ps_true if stroke color has changed */ 270 271 ght_hash_table_t *opthash; 272 }; 273 274 typedef struct PSTState_ PSTState; 275 276 struct PSTState_ { 277 /* x, y for drawing text */ 278 float tx; 279 float ty; 280 /* x, y for continue text */ 281 float cx; 282 float cy; 283 }; 284 285 typedef struct value_ PS_VALUE; 286 struct value_ { 287 char *name; 288 float value; 289 }; 290 291 typedef struct resource_ PS_PARAMETER; 292 typedef struct resource_ PS_RESOURCE; 293 struct resource_ { 294 char *name; 295 char *value; 296 }; 297 298 typedef struct categorie_ PS_CATEGORY; 299 struct categorie_ { 300 char *name; 301 DLIST *resources; 302 }; 303 304 typedef struct bookmark_ PS_BOOKMARK; 305 struct bookmark_ { 306 int id; 307 char *text; 308 int open; 309 int page; 310 DLIST *children; 311 }; 312 313 #define PS_MAX_GSTATE_LEVELS 10 314 #define PS_MAX_TSTATE_LEVELS 10 315 316 #define MAX_SCOPES 20 // maximum number of scopes on the stack 317 #define PS_SCOPE_NONE 0 318 #define PS_SCOPE_OBJECT 1 319 #define PS_SCOPE_DOCUMENT 2 320 #define PS_SCOPE_PAGE 4 321 #define PS_SCOPE_PATH 8 322 #define PS_SCOPE_TEMPLATE 16 323 #define PS_SCOPE_PATTERN 32 324 #define PS_SCOPE_PROLOG 64 325 #define PS_SCOPE_FONT 128 326 #define PS_SCOPE_GLYPH 256 327 328 #define LINEBUFLEN 1024 329 330 struct PSDoc_ { 331 /* Document Information */ 332 char *Keywords; 333 char *Subject; 334 char *Title; 335 char *Creator; 336 char *Author; 337 char *BoundingBox; 338 char *Orientation; 339 340 int copies; 341 342 STRBUFFER *sb; 343 FILE *fp; 344 ps_bool closefp; 345 ps_bool headerwritten; 346 ps_bool commentswritten; 347 ps_bool beginprologwritten; 348 ps_bool endprologwritten; 349 ps_bool setupwritten; 350 351 /* Creation date */ 352 char *CreationDate; 353 354 /* Input encoding */ 355 ENCODING *inputenc; 356 357 /* Hyphenation dictionary */ 358 HyphenDict *hdict; 359 char *hdictfilename; 360 361 /* The current font */ 362 PSFont *font; 363 364 /* The current pattern */ 365 PSPattern *pattern; 366 367 DLIST *categories; 368 DLIST *parameters; 369 DLIST *values; 370 DLIST *bookmarks; /* list of first level bookmarks */ 371 int lastbookmarkid; /* id of last bookmark */ 372 PS_BOOKMARK **bookmarkdict; /* Bookmark lookup table */ 373 int bookmarkcnt; /* Number of entries in lookup table */ 374 375 /* page stores the current page number. 376 * It is increased each time a page begins */ 377 unsigned int page; 378 int in_error; 379 ps_bool warnings; /* Whether warnings shall be output */ 380 381 /* The stack of scopes */ 382 int scopecount; 383 int scopes[MAX_SCOPES]; 384 385 /* List of fonts, images, patterns and spotcolors used in this document */ 386 PSFont **fonts; 387 int fontcnt; 388 PSImage **images; 389 int imagecnt; 390 PSPattern **patterns; 391 int patterncnt; 392 PSShading **shadings; 393 int shadingcnt; 394 PSSpotColor **spotcolors; 395 int spotcolorcnt; 396 PSGState **gstates; 397 int gstatecnt; 398 399 /* text appearance */ 400 ps_bool underline; 401 ps_bool overline; 402 ps_bool strikeout; 403 int textrendering; 404 405 /* grafic states */ 406 int agstate; 407 PSGState agstates[PS_MAX_GSTATE_LEVELS]; 408 int tstate; 409 PSTState tstates[PS_MAX_TSTATE_LEVELS]; 410 411 /* misc */ 412 ps_bool page_open; /* set to true when PS_begin_page() is called 413 * reset to false in PS_end_page() */ 414 ps_bool doc_open; /* set to true when document is opened and reset 415 * to false in PS_close() */ 416 417 /* border of annotations */ 418 int border_style; 419 float border_width; 420 float border_red; 421 float border_green; 422 float border_blue; 423 float border_black; 424 float border_white; 425 426 /* output function */ 427 size_t (*writeproc)(PSDoc *p, void *data, size_t size); 428 429 /* user data passed by PS_new2(). Can be retrieved with PS_get_opaque() */ 430 void *user_data; 431 432 /* error handler function */ 433 void (*errorhandler)(PSDoc *p, int level, const char* msg, void *data); 434 435 /* Memory allocation functions */ 436 void *(*malloc)(PSDoc *p, size_t size, const char *caller); 437 void *(*calloc)(PSDoc *p, size_t size, const char *caller); 438 void *(*realloc)(PSDoc *p, void *mem, size_t size, const char *caller); 439 void (*free)(PSDoc *p, void *mem); 440 }; 441 442 /* ps_util.c */ 443 void ps_write(PSDoc *p, const void *data, size_t size); 444 void ps_putc(PSDoc *p, char c); 445 void ps_puts(PSDoc *p, const char *s); 446 void ps_printf(PSDoc *p, const char *fmt, ...); 447 void* ps_ght_malloc(size_t size, void *data); 448 void ps_ght_free(void *ptr, void *data); 449 PS_RESOURCE **ps_get_resources(PSDoc *psdoc, const char *category, int *count); 450 char *ps_find_resource(PSDoc *psdoc, const char *category, const char *resource); 451 PS_RESOURCE * ps_add_resource(PSDoc *psdoc, const char *category, const char *resource, const char *filename, const char *prefix); 452 int ps_get_bool_parameter(PSDoc *psdoc, const char *name, int deflt); 453 float ps_get_word_spacing(PSDoc *psdoc, PSFont *psfont); 454 void ps_set_word_spacing(PSDoc *psdoc, PSFont *psfont, float value); 455 void ps_add_word_spacing(PSDoc *psdoc, PSFont *psfont, float value); 456 void ps_del_resources(PSDoc *psdoc); 457 void ps_del_parameters(PSDoc *psdoc); 458 void ps_del_values(PSDoc *psdoc); 459 void ps_del_bookmarks(PSDoc *psdoc, DLIST *bookmarks); 460 int ps_check_for_lig(PSDoc *psdoc, ADOBEFONTMETRIC *metrics, ADOBEINFO *ai, const char *text, char ligdischar, char **newadobename, int *offset); 461 ght_hash_table_t *ps_build_enc_hash(PSDoc *psdoc, ENCODING *enc); 462 ght_hash_table_t *ps_build_enc_from_font(PSDoc *psdoc, ADOBEFONTMETRIC *metrics); 463 ENCODING *ps_build_enc_vector(PSDoc *psdoc, ght_hash_table_t *hashvec); 464 void ps_list_fontenc(PSDoc *psdoc, ght_hash_table_t *hashvec); 465 void ps_free_enc_vector(PSDoc *psdoc, ENCODING *enc); 466 unsigned char ps_fontenc_code(PSDoc *psdoc, ght_hash_table_t *fontenc, char *adobename); 467 int ps_fontenc_has_glyph(PSDoc *psdoc, ght_hash_table_t *fontenc, char *adobename); 468 char *ps_inputenc_name(PSDoc *psdoc, unsigned char c); 469 void ps_enter_scope(PSDoc *psdoc, int scope); 470 void ps_leave_scope(PSDoc *psdoc, int scope); 471 int ps_current_scope(PSDoc *psdoc); 472 ps_bool ps_check_scope(PSDoc *psdoc, int scope); 473 FILE *ps_open_file_in_path(PSDoc *psdoc, const char *filename); 474 ght_hash_table_t *ps_parse_optlist(PSDoc *psdoc, const char *optstr); 475 void ps_free_optlist(PSDoc *psdoc, ght_hash_table_t *opthash); 476 int get_optlist_element_as_float(PSDoc *psdoc, ght_hash_table_t *opthash, const char *name, float *value); 477 int get_optlist_element_as_int(PSDoc *psdoc, ght_hash_table_t *opthash, const char *name, int *value); 478 int get_optlist_element_as_bool(PSDoc *psdoc, ght_hash_table_t *opthash, const char *name, ps_bool *value); 479 int get_optlist_element_as_string(PSDoc *psdoc, ght_hash_table_t *opthash, const char *name, char **value); 480 void ps_ascii85_encode(PSDoc *psdoc, char *data, size_t len); 481 void ps_asciihex_encode(PSDoc *psdoc, char *data, size_t len); 482 483 /* ps_afm.c */ 484 int calculatekern(ADOBEINFO *ai, ADOBEINFO *succ); 485 ADOBEFONTMETRIC *readadobe(PSDoc *psdoc, const char *filename); 486 ADOBEINFO *gfindadobe(ght_hash_table_t *adobechars, const char *p); 487 int readprotusion(PSDoc *psdoc, PSFont *psfont, const char *filename); 488 int readencoding(PSDoc *psdoc, ADOBEFONTMETRIC *metrics, const char *enc); 489 void addkern(PSDoc *psdoc, ADOBEINFO *ai, ADOBEINFO *succ, int kerning); 490 void addligature(PSDoc *psdoc, ADOBEINFO *ai, ADOBEINFO *succ, ADOBEINFO *sub); 491 492 #include "ps_inputenc.h" 493 #include "ps_fontenc.h" 494 495 496 #endif 497