1 /***************************************************************************/ 2 /* */ 3 /* pshints.h */ 4 /* */ 5 /* Interface to Postscript-specific (Type 1 and Type 2) hints */ 6 /* recorders (specification only). These are used to support native */ 7 /* T1/T2 hints in the "type1", "cid" and "cff" font drivers. */ 8 /* */ 9 /* Copyright 2001, 2002 by */ 10 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 11 /* */ 12 /* This file is part of the FreeType project, and may only be used, */ 13 /* modified, and distributed under the terms of the FreeType project */ 14 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 15 /* this file you indicate that you have read the license and */ 16 /* understand and accept it fully. */ 17 /* */ 18 /***************************************************************************/ 19 20 21 #ifndef __PSHINTS_H__ 22 #define __PSHINTS_H__ 23 24 25 #include <ft2build.h> 26 #include FT_FREETYPE_H 27 #include FT_TYPE1_TABLES_H 28 29 30 FT_BEGIN_HEADER 31 32 33 /*************************************************************************/ 34 /*************************************************************************/ 35 /***** *****/ 36 /***** INTERNAL REPRESENTATION OF GLOBALS *****/ 37 /***** *****/ 38 /*************************************************************************/ 39 /*************************************************************************/ 40 41 typedef struct PSH_GlobalsRec_* PSH_Globals; 42 43 typedef FT_Error 44 (*PSH_Globals_NewFunc)( FT_Memory memory, 45 T1_Private* private_dict, 46 PSH_Globals* aglobals ); 47 48 typedef FT_Error 49 (*PSH_Globals_SetScaleFunc)( PSH_Globals globals, 50 FT_Fixed x_scale, 51 FT_Fixed y_scale, 52 FT_Fixed x_delta, 53 FT_Fixed y_delta ); 54 55 typedef void 56 (*PSH_Globals_DestroyFunc)( PSH_Globals globals ); 57 58 59 typedef struct PSH_Globals_FuncsRec_ 60 { 61 PSH_Globals_NewFunc create; 62 PSH_Globals_SetScaleFunc set_scale; 63 PSH_Globals_DestroyFunc destroy; 64 65 } PSH_Globals_FuncsRec, *PSH_Globals_Funcs; 66 67 68 /*************************************************************************/ 69 /*************************************************************************/ 70 /***** *****/ 71 /***** PUBLIC TYPE 1 HINTS RECORDER *****/ 72 /***** *****/ 73 /*************************************************************************/ 74 /*************************************************************************/ 75 76 /*************************************************************************/ 77 /* */ 78 /* @type: */ 79 /* T1_Hints */ 80 /* */ 81 /* @description: */ 82 /* This is a handle to an opaque structure used to record glyph hints */ 83 /* from a Type 1 character glyph character string. */ 84 /* */ 85 /* The methods used to operate on this object are defined by the */ 86 /* @T1_Hints_FuncsRec structure. Recording glyph hints is normally */ 87 /* achieved through the following scheme: */ 88 /* */ 89 /* - Open a new hint recording session by calling the "open" method. */ 90 /* This will rewind the recorder and prepare it for new input. */ 91 /* */ 92 /* - For each hint found in the glyph charstring, call the */ 93 /* corresponding method ("stem", "stem3", or "reset"). Note that */ 94 /* these functions do not return an error code. */ 95 /* */ 96 /* - Close the recording session by calling the "close" method. It */ 97 /* will return an error code if the hints were invalid or something */ 98 /* strange happened (e.g. memory shortage). */ 99 /* */ 100 /* The hints accumulated in the object can later be used by the */ 101 /* PostScript hinter. */ 102 /* */ 103 typedef struct T1_HintsRec_* T1_Hints; 104 105 106 /*************************************************************************/ 107 /* */ 108 /* @type: */ 109 /* T1_Hints_Funcs */ 110 /* */ 111 /* @description: */ 112 /* A pointer to the @T1_Hints_FuncsRec structure that defines the */ 113 /* API of a given @T1_Hints object. */ 114 /* */ 115 typedef const struct T1_Hints_FuncsRec_* T1_Hints_Funcs; 116 117 118 /*************************************************************************/ 119 /* */ 120 /* @functype: */ 121 /* T1_Hints_OpenFunc */ 122 /* */ 123 /* @description: */ 124 /* A method of the @T1_Hints class used to prepare it for a new */ 125 /* Type 1 hints recording session. */ 126 /* */ 127 /* @input: */ 128 /* hints :: A handle to the Type 1 hints recorder. */ 129 /* */ 130 /* @note: */ 131 /* You should always call the @T1_Hints_CloseFunc method in order to */ 132 /* close an opened recording session. */ 133 /* */ 134 typedef void 135 (*T1_Hints_OpenFunc)( T1_Hints hints ); 136 137 138 /*************************************************************************/ 139 /* */ 140 /* @functype: */ 141 /* T1_Hints_SetStemFunc */ 142 /* */ 143 /* @description: */ 144 /* A method of the @T1_Hints class used to record a new horizontal or */ 145 /* vertical stem. This corresponds to the Type 1 "hstem" and "vstem" */ 146 /* operators. */ 147 /* */ 148 /* @input: */ 149 /* hints :: A handle to the Type 1 hints recorder. */ 150 /* */ 151 /* dimension :: 0 for horizontal stems (hstem), 1 for vertical ones */ 152 /* (vstem). */ 153 /* */ 154 /* coords :: Array of 2 integers, used as (position,length) stem */ 155 /* descriptor. */ 156 /* */ 157 /* @note: */ 158 /* Use vertical coordinates (y) for horizontal stems (dim=0). Use */ 159 /* horizontal coordinates (x) for vertical stems (dim=1). */ 160 /* */ 161 /* "coords[0]" is the absolute stem position (lowest coordinate); */ 162 /* "coords[1]" is the length. */ 163 /* */ 164 /* The length can be negative, in which case it must be either -20 or */ 165 /* -21. It will be interpreted as a "ghost" stem, according to */ 166 /* Type 1 specification. */ 167 /* */ 168 /* If the length is -21 (corresponding to a bottom ghost stem), then */ 169 /* the real stem position is "coords[0]+coords[1]". */ 170 /* */ 171 typedef void 172 (*T1_Hints_SetStemFunc)( T1_Hints hints, 173 FT_UInt dimension, 174 FT_Long* coords ); 175 176 177 /*************************************************************************/ 178 /* */ 179 /* @functype: */ 180 /* T1_Hints_SetStem3Func */ 181 /* */ 182 /* @description: */ 183 /* A method of the @T1_Hints class used to record three */ 184 /* counter-controlled horizontal or vertical stems at once. */ 185 /* */ 186 /* @input: */ 187 /* hints :: A handle to the Type 1 hints recorder. */ 188 /* */ 189 /* dimension :: 0 for horizontal stems, 1 for vertical ones. */ 190 /* */ 191 /* coords :: An array of 6 integers, holding 3 (position,length) */ 192 /* pairs for the counter-controlled stems. */ 193 /* */ 194 /* @note: */ 195 /* Use vertical coordinates (y) for horizontal stems (dim=0). Use */ 196 /* horizontal coordinates (x) for vertical stems (dim=1). */ 197 /* */ 198 /* The lengths cannot be negative (ghost stems are never */ 199 /* counter-controlled). */ 200 /* */ 201 typedef void 202 (*T1_Hints_SetStem3Func)( T1_Hints hints, 203 FT_UInt dimension, 204 FT_Long* coords ); 205 206 207 /*************************************************************************/ 208 /* */ 209 /* @functype: */ 210 /* T1_Hints_ResetFunc */ 211 /* */ 212 /* @description: */ 213 /* A method of the @T1_Hints class used to reset the stems hints in a */ 214 /* recording session. */ 215 /* */ 216 /* @input: */ 217 /* hints :: A handle to the Type 1 hints recorder. */ 218 /* */ 219 /* end_point :: The index of the last point in the input glyph in */ 220 /* which the previously defined hints apply. */ 221 /* */ 222 typedef void 223 (*T1_Hints_ResetFunc)( T1_Hints hints, 224 FT_UInt end_point ); 225 226 227 /*************************************************************************/ 228 /* */ 229 /* @functype: */ 230 /* T1_Hints_CloseFunc */ 231 /* */ 232 /* @description: */ 233 /* A method of the @T1_Hints class used to close a hint recording */ 234 /* session. */ 235 /* */ 236 /* @input: */ 237 /* hints :: A handle to the Type 1 hints recorder. */ 238 /* */ 239 /* end_point :: The index of the last point in the input glyph. */ 240 /* */ 241 /* @return: */ 242 /* FreeType error code. 0 means success. */ 243 /* */ 244 /* @note: */ 245 /* The error code will be set to indicate that an error occured */ 246 /* during the recording session. */ 247 /* */ 248 typedef FT_Error 249 (*T1_Hints_CloseFunc)( T1_Hints hints, 250 FT_UInt end_point ); 251 252 253 /*************************************************************************/ 254 /* */ 255 /* @functype: */ 256 /* T1_Hints_ApplyFunc */ 257 /* */ 258 /* @description: */ 259 /* A method of the @T1_Hints class used to apply hints to the */ 260 /* corresponding glyph outline. Must be called once all hints have */ 261 /* been recorded. */ 262 /* */ 263 /* @input: */ 264 /* hints :: A handle to the Type 1 hints recorder. */ 265 /* */ 266 /* outline :: A pointer to the target outline descriptor. */ 267 /* */ 268 /* globals :: The hinter globals for this font. */ 269 /* */ 270 /* hint_flags :: Hinter bit flags. */ 271 /* */ 272 /* @return: */ 273 /* FreeType error code. 0 means success. */ 274 /* */ 275 /* @note: */ 276 /* On input, all points within the outline are in font coordinates. */ 277 /* On output, they are in 1/64th of pixels. */ 278 /* */ 279 /* The scaling transformation is taken from the "globals" object */ 280 /* which must correspond to the same font as the glyph. */ 281 /* */ 282 typedef FT_Error 283 (*T1_Hints_ApplyFunc)( T1_Hints hints, 284 FT_Outline* outline, 285 PSH_Globals globals, 286 FT_Render_Mode hint_mode ); 287 288 289 /*************************************************************************/ 290 /* */ 291 /* @struct: */ 292 /* T1_Hints_FuncsRec */ 293 /* */ 294 /* @description: */ 295 /* The structure used to provide the API to @T1_Hints objects. */ 296 /* */ 297 /* @fields: */ 298 /* hints :: A handle to the T1 Hints recorder. */ 299 /* */ 300 /* open :: The function to open a recording session. */ 301 /* */ 302 /* close :: The function to close a recording session. */ 303 /* */ 304 /* stem :: The function to set a simple stem. */ 305 /* */ 306 /* stem3 :: The function to set counter-controlled stems. */ 307 /* */ 308 /* reset :: The function to reset stem hints. */ 309 /* */ 310 /* apply :: The function to apply the hints to the corresponding */ 311 /* glyph outline. */ 312 /* */ 313 typedef struct T1_Hints_FuncsRec_ 314 { 315 T1_Hints hints; 316 T1_Hints_OpenFunc open; 317 T1_Hints_CloseFunc close; 318 T1_Hints_SetStemFunc stem; 319 T1_Hints_SetStem3Func stem3; 320 T1_Hints_ResetFunc reset; 321 T1_Hints_ApplyFunc apply; 322 323 } T1_Hints_FuncsRec; 324 325 326 /*************************************************************************/ 327 /*************************************************************************/ 328 /***** *****/ 329 /***** PUBLIC TYPE 2 HINTS RECORDER *****/ 330 /***** *****/ 331 /*************************************************************************/ 332 /*************************************************************************/ 333 334 /*************************************************************************/ 335 /* */ 336 /* @type: */ 337 /* T2_Hints */ 338 /* */ 339 /* @description: */ 340 /* This is a handle to an opaque structure used to record glyph hints */ 341 /* from a Type 2 character glyph character string. */ 342 /* */ 343 /* The methods used to operate on this object are defined by the */ 344 /* @T2_Hints_FuncsRec structure. Recording glyph hints is normally */ 345 /* achieved through the following scheme: */ 346 /* */ 347 /* - Open a new hint recording session by calling the "open" method. */ 348 /* This will rewind the recorder and prepare it for new input. */ 349 /* */ 350 /* - For each hint found in the glyph charstring, call the */ 351 /* corresponding method ("stems", "hintmask", "counters"). Note */ 352 /* that these functions do not return an error code. */ 353 /* */ 354 /* - Close the recording session by calling the "close" method. It */ 355 /* will return an error code if the hints were invalid or something */ 356 /* strange happened (e.g. memory shortage). */ 357 /* */ 358 /* The hints accumulated in the object can later be used by the */ 359 /* Postscript hinter. */ 360 /* */ 361 typedef struct T2_HintsRec_* T2_Hints; 362 363 364 /*************************************************************************/ 365 /* */ 366 /* @type: */ 367 /* T2_Hints_Funcs */ 368 /* */ 369 /* @description: */ 370 /* A pointer to the @T2_Hints_FuncsRec structure that defines the API */ 371 /* of a given @T2_Hints object. */ 372 /* */ 373 typedef const struct T2_Hints_FuncsRec_* T2_Hints_Funcs; 374 375 376 /*************************************************************************/ 377 /* */ 378 /* @functype: */ 379 /* T2_Hints_OpenFunc */ 380 /* */ 381 /* @description: */ 382 /* A method of the @T2_Hints class used to prepare it for a new */ 383 /* Type 2 hints recording session. */ 384 /* */ 385 /* @input: */ 386 /* hints :: A handle to the Type 2 hints recorder. */ 387 /* */ 388 /* @note: */ 389 /* You should always call the @T2_Hints_CloseFunc method in order to */ 390 /* close an opened recording session. */ 391 /* */ 392 typedef void 393 (*T2_Hints_OpenFunc)( T2_Hints hints ); 394 395 396 /*************************************************************************/ 397 /* */ 398 /* @functype: */ 399 /* T2_Hints_StemsFunc */ 400 /* */ 401 /* @description: */ 402 /* A method of the @T2_Hints class used to set the table of stems in */ 403 /* either the vertical or horizontal dimension. Equivalent to the */ 404 /* "hstem", "vstem", "hstemhm", and "vstemhm" Type 2 operators. */ 405 /* */ 406 /* @input: */ 407 /* hints :: A handle to the Type 2 hints recorder. */ 408 /* */ 409 /* dimension :: 0 for horizontal stems (hstem), 1 for vertical ones */ 410 /* (vstem). */ 411 /* */ 412 /* count :: The number of stems. */ 413 /* */ 414 /* coords :: An array of "count" (position,length) pairs. */ 415 /* */ 416 /* @note: */ 417 /* Use vertical coordinates (y) for horizontal stems (dim=0). Use */ 418 /* horizontal coordinates (x) for vertical stems (dim=1). */ 419 /* */ 420 /* There are "2*count" elements in the "coords" aray. Each even */ 421 /* element is an absolute position in font units, each odd element is */ 422 /* a length in font units. */ 423 /* */ 424 /* A length can be negative, in which case it must be either -20 or */ 425 /* -21. It will be interpreted as a "ghost" stem, according to the */ 426 /* Type 1 specification. */ 427 /* */ 428 typedef void 429 (*T2_Hints_StemsFunc)( T2_Hints hints, 430 FT_UInt dimension, 431 FT_UInt count, 432 FT_Fixed* coordinates ); 433 434 435 /*************************************************************************/ 436 /* */ 437 /* @functype: */ 438 /* T2_Hints_MaskFunc */ 439 /* */ 440 /* @description: */ 441 /* A method of the @T2_Hints class used to set a given hintmask */ 442 /* (this corresponds to the "hintmask" Type 2 operator). */ 443 /* */ 444 /* @input: */ 445 /* hints :: A handle to the Type 2 hints recorder. */ 446 /* */ 447 /* end_point :: The glyph index of the last point to which the */ 448 /* previously defined/activated hints apply. */ 449 /* */ 450 /* bit_count :: The number of bits in the hint mask. */ 451 /* */ 452 /* bytes :: An array of bytes modelling the hint mask. */ 453 /* */ 454 /* @note: */ 455 /* If the hintmask starts the charstring (before any glyph point */ 456 /* definition), the value of "end_point" should be 0. */ 457 /* */ 458 /* "bit_count" is the number of meaningful bits in the "bytes" array; */ 459 /* it must be equal to the total number of hints defined so far */ 460 /* (i.e. horizontal+verticals). */ 461 /* */ 462 /* The "bytes" array can come directly from the Type 2 charstring and */ 463 /* respects the same format. */ 464 /* */ 465 typedef void 466 (*T2_Hints_MaskFunc)( T2_Hints hints, 467 FT_UInt end_point, 468 FT_UInt bit_count, 469 const FT_Byte* bytes ); 470 471 472 /*************************************************************************/ 473 /* */ 474 /* @functype: */ 475 /* T2_Hints_CounterFunc */ 476 /* */ 477 /* @description: */ 478 /* A method of the @T2_Hints class used to set a given counter mask */ 479 /* (this corresponds to the "hintmask" Type 2 operator). */ 480 /* */ 481 /* @input: */ 482 /* hints :: A handle to the Type 2 hints recorder. */ 483 /* */ 484 /* end_point :: A glyph index of the last point to which the */ 485 /* previously defined/active hints apply. */ 486 /* */ 487 /* bit_count :: The number of bits in the hint mask. */ 488 /* */ 489 /* bytes :: An array of bytes modelling the hint mask. */ 490 /* */ 491 /* @note: */ 492 /* If the hintmask starts the charstring (before any glyph point */ 493 /* definition), the value of "end_point" should be 0. */ 494 /* */ 495 /* "bit_count" is the number of meaningful bits in the "bytes" array; */ 496 /* it must be equal to the total number of hints defined so far */ 497 /* (i.e. horizontal+verticals). */ 498 /* */ 499 /* The "bytes" array can come directly from the Type 2 charstring and */ 500 /* respects the same format. */ 501 /* */ 502 typedef void 503 (*T2_Hints_CounterFunc)( T2_Hints hints, 504 FT_UInt bit_count, 505 const FT_Byte* bytes ); 506 507 508 /*************************************************************************/ 509 /* */ 510 /* @functype: */ 511 /* T2_Hints_CloseFunc */ 512 /* */ 513 /* @description: */ 514 /* A method of the @T2_Hints class used to close a hint recording */ 515 /* session. */ 516 /* */ 517 /* @input: */ 518 /* hints :: A handle to the Type 2 hints recorder. */ 519 /* */ 520 /* end_point :: The index of the last point in the input glyph. */ 521 /* */ 522 /* @return: */ 523 /* FreeType error code. 0 means success. */ 524 /* */ 525 /* @note: */ 526 /* The error code will be set to indicate that an error occured */ 527 /* during the recording session. */ 528 /* */ 529 typedef FT_Error 530 (*T2_Hints_CloseFunc)( T2_Hints hints, 531 FT_UInt end_point ); 532 533 534 /*************************************************************************/ 535 /* */ 536 /* @functype: */ 537 /* T2_Hints_ApplyFunc */ 538 /* */ 539 /* @description: */ 540 /* A method of the @T2_Hints class used to apply hints to the */ 541 /* corresponding glyph outline. Must be called after the "close" */ 542 /* method. */ 543 /* */ 544 /* @input: */ 545 /* hints :: A handle to the Type 2 hints recorder. */ 546 /* */ 547 /* outline :: A pointer to the target outline descriptor. */ 548 /* */ 549 /* globals :: The hinter globals for this font. */ 550 /* */ 551 /* hint_flags :: Hinter bit flags. */ 552 /* */ 553 /* @return: */ 554 /* FreeType error code. 0 means success. */ 555 /* */ 556 /* @note: */ 557 /* On input, all points within the outline are in font coordinates. */ 558 /* On output, they are in 1/64th of pixels. */ 559 /* */ 560 /* The scaling transformation is taken from the "globals" object */ 561 /* which must correspond to the same font than the glyph. */ 562 /* */ 563 typedef FT_Error 564 (*T2_Hints_ApplyFunc)( T2_Hints hints, 565 FT_Outline* outline, 566 PSH_Globals globals, 567 FT_Render_Mode hint_mode ); 568 569 570 /*************************************************************************/ 571 /* */ 572 /* @struct: */ 573 /* T2_Hints_FuncsRec */ 574 /* */ 575 /* @description: */ 576 /* The structure used to provide the API to @T2_Hints objects. */ 577 /* */ 578 /* @fields: */ 579 /* hints :: A handle to the T2 hints recorder object. */ 580 /* */ 581 /* open :: The function to open a recording session. */ 582 /* */ 583 /* close :: The function to close a recording session. */ 584 /* */ 585 /* stems :: The function to set the dimension's stems table. */ 586 /* */ 587 /* hintmask :: The function to set hint masks. */ 588 /* */ 589 /* counter :: The function to set counter masks. */ 590 /* */ 591 /* apply :: The function to apply the hints on the corresponding */ 592 /* glyph outline. */ 593 /* */ 594 typedef struct T2_Hints_FuncsRec_ 595 { 596 T2_Hints hints; 597 T2_Hints_OpenFunc open; 598 T2_Hints_CloseFunc close; 599 T2_Hints_StemsFunc stems; 600 T2_Hints_MaskFunc hintmask; 601 T2_Hints_CounterFunc counter; 602 T2_Hints_ApplyFunc apply; 603 604 } T2_Hints_FuncsRec; 605 606 607 /* */ 608 609 610 typedef struct PSHinter_Interface_ 611 { 612 PSH_Globals_Funcs (*get_globals_funcs)( FT_Module module ); 613 T1_Hints_Funcs (*get_t1_funcs) ( FT_Module module ); 614 T2_Hints_Funcs (*get_t2_funcs) ( FT_Module module ); 615 616 } PSHinter_Interface; 617 618 typedef PSHinter_Interface* PSHinter_Service; 619 620 621 FT_END_HEADER 622 623 #endif /* __PSHINTS_H__ */ 624 625 626 /* END */ 627