1 /***************************************************************************/ 2 /* */ 3 /* psaux.h */ 4 /* */ 5 /* Auxiliary functions and data structures related to PostScript fonts */ 6 /* (specification). */ 7 /* */ 8 /* Copyright 1996-2001, 2002 by */ 9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 10 /* */ 11 /* This file is part of the FreeType project, and may only be used, */ 12 /* modified, and distributed under the terms of the FreeType project */ 13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 14 /* this file you indicate that you have read the license and */ 15 /* understand and accept it fully. */ 16 /* */ 17 /***************************************************************************/ 18 19 20 #ifndef __PSAUX_H__ 21 #define __PSAUX_H__ 22 23 24 #include <ft2build.h> 25 #include FT_INTERNAL_OBJECTS_H 26 #include FT_INTERNAL_TYPE1_TYPES_H 27 28 29 FT_BEGIN_HEADER 30 31 32 /*************************************************************************/ 33 /*************************************************************************/ 34 /***** *****/ 35 /***** T1_TABLE *****/ 36 /***** *****/ 37 /*************************************************************************/ 38 /*************************************************************************/ 39 40 41 typedef struct PS_TableRec_* PS_Table; 42 typedef const struct PS_Table_FuncsRec_* PS_Table_Funcs; 43 44 45 /*************************************************************************/ 46 /* */ 47 /* <Struct> */ 48 /* PS_Table_FuncsRec */ 49 /* */ 50 /* <Description> */ 51 /* A set of function pointers to manage PS_Table objects. */ 52 /* */ 53 /* <Fields> */ 54 /* table_init :: Used to initialize a table. */ 55 /* */ 56 /* table_done :: Finalizes resp. destroy a given table. */ 57 /* */ 58 /* table_add :: Adds a new object to a table. */ 59 /* */ 60 /* table_release :: Releases table data, then finalizes it. */ 61 /* */ 62 typedef struct PS_Table_FuncsRec_ 63 { 64 FT_Error 65 (*init)( PS_Table table, 66 FT_Int count, 67 FT_Memory memory ); 68 69 void 70 (*done)( PS_Table table ); 71 72 FT_Error 73 (*add)( PS_Table table, 74 FT_Int index, 75 void* object, 76 FT_Int length ); 77 78 void 79 (*release)( PS_Table table ); 80 81 } PS_Table_FuncsRec; 82 83 84 /*************************************************************************/ 85 /* */ 86 /* <Struct> */ 87 /* PS_TableRec */ 88 /* */ 89 /* <Description> */ 90 /* A PS_Table is a simple object used to store an array of objects in */ 91 /* a single memory block. */ 92 /* */ 93 /* <Fields> */ 94 /* block :: The address in memory of the growheap's block. This */ 95 /* can change between two object adds, due to */ 96 /* reallocation. */ 97 /* */ 98 /* cursor :: The current top of the grow heap within its block. */ 99 /* */ 100 /* capacity :: The current size of the heap block. Increments by */ 101 /* 1kByte chunks. */ 102 /* */ 103 /* max_elems :: The maximum number of elements in table. */ 104 /* */ 105 /* num_elems :: The current number of elements in table. */ 106 /* */ 107 /* elements :: A table of element addresses within the block. */ 108 /* */ 109 /* lengths :: A table of element sizes within the block. */ 110 /* */ 111 /* memory :: The object used for memory operations */ 112 /* (alloc/realloc). */ 113 /* */ 114 /* funcs :: A table of method pointers for this object. */ 115 /* */ 116 typedef struct PS_TableRec_ 117 { 118 FT_Byte* block; /* current memory block */ 119 FT_Offset cursor; /* current cursor in memory block */ 120 FT_Offset capacity; /* current size of memory block */ 121 FT_Long init; 122 123 FT_Int max_elems; 124 FT_Int num_elems; 125 FT_Byte** elements; /* addresses of table elements */ 126 FT_Int* lengths; /* lengths of table elements */ 127 128 FT_Memory memory; 129 PS_Table_FuncsRec funcs; 130 131 } PS_TableRec; 132 133 134 /*************************************************************************/ 135 /*************************************************************************/ 136 /***** *****/ 137 /***** T1 FIELDS & TOKENS *****/ 138 /***** *****/ 139 /*************************************************************************/ 140 /*************************************************************************/ 141 142 typedef struct PS_ParserRec_* PS_Parser; 143 144 typedef struct T1_TokenRec_* T1_Token; 145 146 typedef struct T1_FieldRec_* T1_Field; 147 148 149 /* simple enumeration type used to identify token types */ 150 typedef enum T1_TokenType_ 151 { 152 T1_TOKEN_TYPE_NONE = 0, 153 T1_TOKEN_TYPE_ANY, 154 T1_TOKEN_TYPE_STRING, 155 T1_TOKEN_TYPE_ARRAY, 156 157 /* do not remove */ 158 T1_TOKEN_TYPE_MAX 159 160 } T1_TokenType; 161 162 163 /* a simple structure used to identify tokens */ 164 typedef struct T1_TokenRec_ 165 { 166 FT_Byte* start; /* first character of token in input stream */ 167 FT_Byte* limit; /* first character after the token */ 168 T1_TokenType type; /* type of token */ 169 170 } T1_TokenRec; 171 172 173 /* enumeration type used to identify object fields */ 174 typedef enum T1_FieldType_ 175 { 176 T1_FIELD_TYPE_NONE = 0, 177 T1_FIELD_TYPE_BOOL, 178 T1_FIELD_TYPE_INTEGER, 179 T1_FIELD_TYPE_FIXED, 180 T1_FIELD_TYPE_STRING, 181 T1_FIELD_TYPE_BBOX, 182 T1_FIELD_TYPE_INTEGER_ARRAY, 183 T1_FIELD_TYPE_FIXED_ARRAY, 184 T1_FIELD_TYPE_CALLBACK, 185 186 /* do not remove */ 187 T1_FIELD_TYPE_MAX 188 189 } T1_FieldType; 190 191 192 typedef enum T1_FieldLocation_ 193 { 194 T1_FIELD_LOCATION_CID_INFO, 195 T1_FIELD_LOCATION_FONT_DICT, 196 T1_FIELD_LOCATION_FONT_INFO, 197 T1_FIELD_LOCATION_PRIVATE, 198 T1_FIELD_LOCATION_BBOX, 199 200 /* do not remove */ 201 T1_FIELD_LOCATION_MAX 202 203 } T1_FieldLocation; 204 205 206 typedef void 207 (*T1_Field_ParseFunc)( FT_Face face, 208 FT_Pointer parser ); 209 210 211 /* structure type used to model object fields */ 212 typedef struct T1_FieldRec_ 213 { 214 const char* ident; /* field identifier */ 215 T1_FieldLocation location; 216 T1_FieldType type; /* type of field */ 217 T1_Field_ParseFunc reader; 218 FT_UInt offset; /* offset of field in object */ 219 FT_Byte size; /* size of field in bytes */ 220 FT_UInt array_max; /* maximal number of elements for */ 221 /* array */ 222 FT_UInt count_offset; /* offset of element count for */ 223 /* arrays */ 224 } T1_FieldRec; 225 226 227 #define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname ) \ 228 { \ 229 _ident, T1CODE, _type, \ 230 0, \ 231 FT_FIELD_OFFSET( _fname ), \ 232 FT_FIELD_SIZE( _fname ), \ 233 0, 0 \ 234 }, 235 236 #define T1_NEW_CALLBACK_FIELD( _ident, _reader ) \ 237 { \ 238 _ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \ 239 (T1_Field_ParseFunc)_reader, \ 240 0, 0, \ 241 0, 0 \ 242 }, 243 244 #define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max ) \ 245 { \ 246 _ident, T1CODE, _type, \ 247 0, \ 248 FT_FIELD_OFFSET( _fname ), \ 249 FT_FIELD_SIZE_DELTA( _fname ), \ 250 _max, \ 251 FT_FIELD_OFFSET( num_ ## _fname ) \ 252 }, 253 254 #define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max ) \ 255 { \ 256 _ident, T1CODE, _type, \ 257 0, \ 258 FT_FIELD_OFFSET( _fname ), \ 259 FT_FIELD_SIZE_DELTA( _fname ), \ 260 _max, 0 \ 261 }, 262 263 264 #define T1_FIELD_TYPE_BOOL( _ident, _fname ) \ 265 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BOOL, _fname ) 266 267 #define T1_FIELD_NUM( _ident, _fname ) \ 268 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER, _fname ) 269 270 #define T1_FIELD_FIXED( _ident, _fname ) \ 271 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED, _fname ) 272 273 #define T1_FIELD_STRING( _ident, _fname ) \ 274 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_STRING, _fname ) 275 276 #define T1_FIELD_BBOX( _ident, _fname ) \ 277 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BBOX, _fname ) 278 279 280 #define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax ) \ 281 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \ 282 _fname, _fmax ) 283 284 #define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax ) \ 285 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \ 286 _fname, _fmax ) 287 288 #define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax ) \ 289 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \ 290 _fname, _fmax ) 291 292 #define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax ) \ 293 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \ 294 _fname, _fmax ) 295 296 #define T1_FIELD_CALLBACK( _ident, _name ) \ 297 T1_NEW_CALLBACK_FIELD( _ident, _name ) 298 299 300 /*************************************************************************/ 301 /*************************************************************************/ 302 /***** *****/ 303 /***** T1 PARSER *****/ 304 /***** *****/ 305 /*************************************************************************/ 306 /*************************************************************************/ 307 308 typedef const struct PS_Parser_FuncsRec_* PS_Parser_Funcs; 309 310 typedef struct PS_Parser_FuncsRec_ 311 { 312 void 313 (*init)( PS_Parser parser, 314 FT_Byte* base, 315 FT_Byte* limit, 316 FT_Memory memory ); 317 318 void 319 (*done)( PS_Parser parser ); 320 321 void 322 (*skip_spaces)( PS_Parser parser ); 323 void 324 (*skip_alpha)( PS_Parser parser ); 325 326 FT_Long 327 (*to_int)( PS_Parser parser ); 328 FT_Fixed 329 (*to_fixed)( PS_Parser parser, 330 FT_Int power_ten ); 331 FT_Int 332 (*to_coord_array)( PS_Parser parser, 333 FT_Int max_coords, 334 FT_Short* coords ); 335 FT_Int 336 (*to_fixed_array)( PS_Parser parser, 337 FT_Int max_values, 338 FT_Fixed* values, 339 FT_Int power_ten ); 340 341 void 342 (*to_token)( PS_Parser parser, 343 T1_Token token ); 344 void 345 (*to_token_array)( PS_Parser parser, 346 T1_Token tokens, 347 FT_UInt max_tokens, 348 FT_Int* pnum_tokens ); 349 350 FT_Error 351 (*load_field)( PS_Parser parser, 352 const T1_Field field, 353 void** objects, 354 FT_UInt max_objects, 355 FT_ULong* pflags ); 356 357 FT_Error 358 (*load_field_table)( PS_Parser parser, 359 const T1_Field field, 360 void** objects, 361 FT_UInt max_objects, 362 FT_ULong* pflags ); 363 364 } PS_Parser_FuncsRec; 365 366 367 /*************************************************************************/ 368 /* */ 369 /* <Struct> */ 370 /* PS_ParserRec */ 371 /* */ 372 /* <Description> */ 373 /* A PS_Parser is an object used to parse a Type 1 font very quickly. */ 374 /* */ 375 /* <Fields> */ 376 /* cursor :: The current position in the text. */ 377 /* */ 378 /* base :: Start of the processed text. */ 379 /* */ 380 /* limit :: End of the processed text. */ 381 /* */ 382 /* error :: The last error returned. */ 383 /* */ 384 /* memory :: The object used for memory operations (alloc/realloc). */ 385 /* */ 386 /* funcs :: A table of functions for the parser. */ 387 /* */ 388 typedef struct PS_ParserRec_ 389 { 390 FT_Byte* cursor; 391 FT_Byte* base; 392 FT_Byte* limit; 393 FT_Error error; 394 FT_Memory memory; 395 396 PS_Parser_FuncsRec funcs; 397 398 } PS_ParserRec; 399 400 401 /*************************************************************************/ 402 /*************************************************************************/ 403 /***** *****/ 404 /***** T1 BUILDER *****/ 405 /***** *****/ 406 /*************************************************************************/ 407 /*************************************************************************/ 408 409 410 typedef struct T1_BuilderRec_* T1_Builder; 411 412 413 typedef FT_Error 414 (*T1_Builder_Check_Points_Func)( T1_Builder builder, 415 FT_Int count ); 416 417 typedef void 418 (*T1_Builder_Add_Point_Func)( T1_Builder builder, 419 FT_Pos x, 420 FT_Pos y, 421 FT_Byte flag ); 422 423 typedef FT_Error 424 (*T1_Builder_Add_Point1_Func)( T1_Builder builder, 425 FT_Pos x, 426 FT_Pos y ); 427 428 typedef FT_Error 429 (*T1_Builder_Add_Contour_Func)( T1_Builder builder ); 430 431 typedef FT_Error 432 (*T1_Builder_Start_Point_Func)( T1_Builder builder, 433 FT_Pos x, 434 FT_Pos y ); 435 436 typedef void 437 (*T1_Builder_Close_Contour_Func)( T1_Builder builder ); 438 439 440 typedef const struct T1_Builder_FuncsRec_* T1_Builder_Funcs; 441 442 typedef struct T1_Builder_FuncsRec_ 443 { 444 void 445 (*init)( T1_Builder builder, 446 FT_Face face, 447 FT_Size size, 448 FT_GlyphSlot slot, 449 FT_Bool hinting ); 450 451 void 452 (*done)( T1_Builder builder ); 453 454 T1_Builder_Check_Points_Func check_points; 455 T1_Builder_Add_Point_Func add_point; 456 T1_Builder_Add_Point1_Func add_point1; 457 T1_Builder_Add_Contour_Func add_contour; 458 T1_Builder_Start_Point_Func start_point; 459 T1_Builder_Close_Contour_Func close_contour; 460 461 } T1_Builder_FuncsRec; 462 463 464 /*************************************************************************/ 465 /* */ 466 /* <Structure> */ 467 /* T1_BuilderRec */ 468 /* */ 469 /* <Description> */ 470 /* A structure used during glyph loading to store its outline. */ 471 /* */ 472 /* <Fields> */ 473 /* memory :: The current memory object. */ 474 /* */ 475 /* face :: The current face object. */ 476 /* */ 477 /* glyph :: The current glyph slot. */ 478 /* */ 479 /* loader :: XXX */ 480 /* */ 481 /* base :: The base glyph outline. */ 482 /* */ 483 /* current :: The current glyph outline. */ 484 /* */ 485 /* max_points :: maximum points in builder outline */ 486 /* */ 487 /* max_contours :: Maximal number of contours in builder outline. */ 488 /* */ 489 /* last :: The last point position. */ 490 /* */ 491 /* scale_x :: The horizontal scale (FUnits to sub-pixels). */ 492 /* */ 493 /* scale_y :: The vertical scale (FUnits to sub-pixels). */ 494 /* */ 495 /* pos_x :: The horizontal translation (if composite glyph). */ 496 /* */ 497 /* pos_y :: The vertical translation (if composite glyph). */ 498 /* */ 499 /* left_bearing :: The left side bearing point. */ 500 /* */ 501 /* advance :: The horizontal advance vector. */ 502 /* */ 503 /* bbox :: Unused. */ 504 /* */ 505 /* path_begun :: A flag which indicates that a new path has begun. */ 506 /* */ 507 /* load_points :: If this flag is not set, no points are loaded. */ 508 /* */ 509 /* no_recurse :: Set but not used. */ 510 /* */ 511 /* error :: An error code that is only used to report memory */ 512 /* allocation problems. */ 513 /* */ 514 /* metrics_only :: A boolean indicating that we only want to compute */ 515 /* the metrics of a given glyph, not load all of its */ 516 /* points. */ 517 /* */ 518 /* funcs :: An array of function pointers for the builder. */ 519 /* */ 520 typedef struct T1_BuilderRec_ 521 { 522 FT_Memory memory; 523 FT_Face face; 524 FT_GlyphSlot glyph; 525 FT_GlyphLoader loader; 526 FT_Outline* base; 527 FT_Outline* current; 528 529 FT_Vector last; 530 531 FT_Fixed scale_x; 532 FT_Fixed scale_y; 533 534 FT_Pos pos_x; 535 FT_Pos pos_y; 536 537 FT_Vector left_bearing; 538 FT_Vector advance; 539 540 FT_BBox bbox; /* bounding box */ 541 FT_Bool path_begun; 542 FT_Bool load_points; 543 FT_Bool no_recurse; 544 FT_Bool shift; 545 546 FT_Error error; /* only used for memory errors */ 547 FT_Bool metrics_only; 548 549 void* hints_funcs; /* hinter-specific */ 550 void* hints_globals; /* hinter-specific */ 551 552 T1_Builder_FuncsRec funcs; 553 554 } T1_BuilderRec; 555 556 557 /*************************************************************************/ 558 /*************************************************************************/ 559 /***** *****/ 560 /***** T1 DECODER *****/ 561 /***** *****/ 562 /*************************************************************************/ 563 /*************************************************************************/ 564 565 #if 0 566 567 /*************************************************************************/ 568 /* */ 569 /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */ 570 /* calls during glyph loading. */ 571 /* */ 572 #define T1_MAX_SUBRS_CALLS 8 573 574 575 /*************************************************************************/ 576 /* */ 577 /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */ 578 /* minimum of 16 is required. */ 579 /* */ 580 #define T1_MAX_CHARSTRINGS_OPERANDS 32 581 582 #endif /* 0 */ 583 584 585 typedef struct T1_Decoder_ZoneRec_ 586 { 587 FT_Byte* cursor; 588 FT_Byte* base; 589 FT_Byte* limit; 590 591 } T1_Decoder_ZoneRec, *T1_Decoder_Zone; 592 593 594 typedef struct T1_DecoderRec_* T1_Decoder; 595 typedef const struct T1_Decoder_FuncsRec_* T1_Decoder_Funcs; 596 597 598 typedef FT_Error 599 (*T1_Decoder_Callback)( T1_Decoder decoder, 600 FT_UInt glyph_index ); 601 602 603 typedef struct T1_Decoder_FuncsRec_ 604 { 605 FT_Error 606 (*init)( T1_Decoder decoder, 607 FT_Face face, 608 FT_Size size, 609 FT_GlyphSlot slot, 610 FT_Byte** glyph_names, 611 PS_Blend blend, 612 FT_Bool hinting, 613 FT_Render_Mode hint_mode, 614 T1_Decoder_Callback callback ); 615 616 void 617 (*done)( T1_Decoder decoder ); 618 619 FT_Error 620 (*parse_charstrings)( T1_Decoder decoder, 621 FT_Byte* base, 622 FT_UInt len ); 623 624 } T1_Decoder_FuncsRec; 625 626 627 typedef struct T1_DecoderRec_ 628 { 629 T1_BuilderRec builder; 630 631 FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS]; 632 FT_Long* top; 633 634 T1_Decoder_ZoneRec zones[T1_MAX_SUBRS_CALLS + 1]; 635 T1_Decoder_Zone zone; 636 637 PSNames_Service psnames; /* for seac */ 638 FT_UInt num_glyphs; 639 FT_Byte** glyph_names; 640 641 FT_Int lenIV; /* internal for sub routine calls */ 642 FT_UInt num_subrs; 643 FT_Byte** subrs; 644 FT_Int* subrs_len; /* array of subrs length (optional) */ 645 646 FT_Matrix font_matrix; 647 FT_Vector font_offset; 648 649 FT_Int flex_state; 650 FT_Int num_flex_vectors; 651 FT_Vector flex_vectors[7]; 652 653 PS_Blend blend; /* for multiple master support */ 654 655 FT_UInt32 hint_flags; 656 FT_Render_Mode hint_mode; 657 658 T1_Decoder_Callback parse_callback; 659 T1_Decoder_FuncsRec funcs; 660 661 } T1_DecoderRec; 662 663 664 /*************************************************************************/ 665 /*************************************************************************/ 666 /***** *****/ 667 /***** TYPE1 CHARMAPS *****/ 668 /***** *****/ 669 /*************************************************************************/ 670 /*************************************************************************/ 671 672 typedef const struct T1_CMap_ClassesRec_* T1_CMap_Classes; 673 674 typedef struct T1_CMap_ClassesRec_ 675 { 676 FT_CMap_Class standard; 677 FT_CMap_Class expert; 678 FT_CMap_Class custom; 679 FT_CMap_Class unicode; 680 681 } T1_CMap_ClassesRec; 682 683 684 /*************************************************************************/ 685 /*************************************************************************/ 686 /***** *****/ 687 /***** PSAux Module Interface *****/ 688 /***** *****/ 689 /*************************************************************************/ 690 /*************************************************************************/ 691 692 typedef struct PSAux_ServiceRec_ 693 { 694 /* don't use `PS_Table_Funcs' and friends to avoid compiler warnings */ 695 const PS_Table_FuncsRec* ps_table_funcs; 696 const PS_Parser_FuncsRec* ps_parser_funcs; 697 const T1_Builder_FuncsRec* t1_builder_funcs; 698 const T1_Decoder_FuncsRec* t1_decoder_funcs; 699 700 void 701 (*t1_decrypt)( FT_Byte* buffer, 702 FT_Offset length, 703 FT_UShort seed ); 704 705 T1_CMap_Classes t1_cmap_classes; 706 707 } PSAux_ServiceRec, *PSAux_Service; 708 709 /* backwards-compatible type definition */ 710 typedef PSAux_ServiceRec PSAux_Interface; 711 712 FT_END_HEADER 713 714 #endif /* __PSAUX_H__ */ 715 716 717 /* END */ 718