00001 /***************************************************************************/ 00002 /* */ 00003 /* pshints.h */ 00004 /* */ 00005 /* Interface to Postscript-specific (Type 1 and Type 2) hints */ 00006 /* recorders (specification only). These are used to support native */ 00007 /* T1/T2 hints in the `type1', `cid', and `cff' font drivers. */ 00008 /* */ 00009 /* Copyright 2001, 2002, 2003, 2005, 2006, 2007, 2009 by */ 00010 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 00011 /* */ 00012 /* This file is part of the FreeType project, and may only be used, */ 00013 /* modified, and distributed under the terms of the FreeType project */ 00014 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 00015 /* this file you indicate that you have read the license and */ 00016 /* understand and accept it fully. */ 00017 /* */ 00018 /***************************************************************************/ 00019 00020 00021 #ifndef __PSHINTS_H__ 00022 #define __PSHINTS_H__ 00023 00024 00025 #include <ft2build.h> 00026 #include FT_FREETYPE_H 00027 #include FT_TYPE1_TABLES_H 00028 00029 00030 FT_BEGIN_HEADER 00031 00032 00033 /*************************************************************************/ 00034 /*************************************************************************/ 00035 /***** *****/ 00036 /***** INTERNAL REPRESENTATION OF GLOBALS *****/ 00037 /***** *****/ 00038 /*************************************************************************/ 00039 /*************************************************************************/ 00040 00041 typedef struct PSH_GlobalsRec_* PSH_Globals; 00042 00043 typedef FT_Error 00044 (*PSH_Globals_NewFunc)( FT_Memory memory, 00045 T1_Private* private_dict, 00046 PSH_Globals* aglobals ); 00047 00048 typedef FT_Error 00049 (*PSH_Globals_SetScaleFunc)( PSH_Globals globals, 00050 FT_Fixed x_scale, 00051 FT_Fixed y_scale, 00052 FT_Fixed x_delta, 00053 FT_Fixed y_delta ); 00054 00055 typedef void 00056 (*PSH_Globals_DestroyFunc)( PSH_Globals globals ); 00057 00058 00059 typedef struct PSH_Globals_FuncsRec_ 00060 { 00061 PSH_Globals_NewFunc create; 00062 PSH_Globals_SetScaleFunc set_scale; 00063 PSH_Globals_DestroyFunc destroy; 00064 00065 } PSH_Globals_FuncsRec, *PSH_Globals_Funcs; 00066 00067 00068 /*************************************************************************/ 00069 /*************************************************************************/ 00070 /***** *****/ 00071 /***** PUBLIC TYPE 1 HINTS RECORDER *****/ 00072 /***** *****/ 00073 /*************************************************************************/ 00074 /*************************************************************************/ 00075 00076 /************************************************************************* 00077 * 00078 * @type: 00079 * T1_Hints 00080 * 00081 * @description: 00082 * This is a handle to an opaque structure used to record glyph hints 00083 * from a Type 1 character glyph character string. 00084 * 00085 * The methods used to operate on this object are defined by the 00086 * @T1_Hints_FuncsRec structure. Recording glyph hints is normally 00087 * achieved through the following scheme: 00088 * 00089 * - Open a new hint recording session by calling the `open' method. 00090 * This rewinds the recorder and prepare it for new input. 00091 * 00092 * - For each hint found in the glyph charstring, call the corresponding 00093 * method (`stem', `stem3', or `reset'). Note that these functions do 00094 * not return an error code. 00095 * 00096 * - Close the recording session by calling the `close' method. It 00097 * returns an error code if the hints were invalid or something 00098 * strange happened (e.g., memory shortage). 00099 * 00100 * The hints accumulated in the object can later be used by the 00101 * PostScript hinter. 00102 * 00103 */ 00104 typedef struct T1_HintsRec_* T1_Hints; 00105 00106 00107 /************************************************************************* 00108 * 00109 * @type: 00110 * T1_Hints_Funcs 00111 * 00112 * @description: 00113 * A pointer to the @T1_Hints_FuncsRec structure that defines the API of 00114 * a given @T1_Hints object. 00115 * 00116 */ 00117 typedef const struct T1_Hints_FuncsRec_* T1_Hints_Funcs; 00118 00119 00120 /************************************************************************* 00121 * 00122 * @functype: 00123 * T1_Hints_OpenFunc 00124 * 00125 * @description: 00126 * A method of the @T1_Hints class used to prepare it for a new Type 1 00127 * hints recording session. 00128 * 00129 * @input: 00130 * hints :: 00131 * A handle to the Type 1 hints recorder. 00132 * 00133 * @note: 00134 * You should always call the @T1_Hints_CloseFunc method in order to 00135 * close an opened recording session. 00136 * 00137 */ 00138 typedef void 00139 (*T1_Hints_OpenFunc)( T1_Hints hints ); 00140 00141 00142 /************************************************************************* 00143 * 00144 * @functype: 00145 * T1_Hints_SetStemFunc 00146 * 00147 * @description: 00148 * A method of the @T1_Hints class used to record a new horizontal or 00149 * vertical stem. This corresponds to the Type 1 `hstem' and `vstem' 00150 * operators. 00151 * 00152 * @input: 00153 * hints :: 00154 * A handle to the Type 1 hints recorder. 00155 * 00156 * dimension :: 00157 * 0 for horizontal stems (hstem), 1 for vertical ones (vstem). 00158 * 00159 * coords :: 00160 * Array of 2 coordinates in 16.16 format, used as (position,length) 00161 * stem descriptor. 00162 * 00163 * @note: 00164 * Use vertical coordinates (y) for horizontal stems (dim=0). Use 00165 * horizontal coordinates (x) for vertical stems (dim=1). 00166 * 00167 * `coords[0]' is the absolute stem position (lowest coordinate); 00168 * `coords[1]' is the length. 00169 * 00170 * The length can be negative, in which case it must be either -20 or 00171 * -21. It is interpreted as a `ghost' stem, according to the Type 1 00172 * specification. 00173 * 00174 * If the length is -21 (corresponding to a bottom ghost stem), then 00175 * the real stem position is `coords[0]+coords[1]'. 00176 * 00177 */ 00178 typedef void 00179 (*T1_Hints_SetStemFunc)( T1_Hints hints, 00180 FT_UInt dimension, 00181 FT_Fixed* coords ); 00182 00183 00184 /************************************************************************* 00185 * 00186 * @functype: 00187 * T1_Hints_SetStem3Func 00188 * 00189 * @description: 00190 * A method of the @T1_Hints class used to record three 00191 * counter-controlled horizontal or vertical stems at once. 00192 * 00193 * @input: 00194 * hints :: 00195 * A handle to the Type 1 hints recorder. 00196 * 00197 * dimension :: 00198 * 0 for horizontal stems, 1 for vertical ones. 00199 * 00200 * coords :: 00201 * An array of 6 values in 16.16 format, holding 3 (position,length) 00202 * pairs for the counter-controlled stems. 00203 * 00204 * @note: 00205 * Use vertical coordinates (y) for horizontal stems (dim=0). Use 00206 * horizontal coordinates (x) for vertical stems (dim=1). 00207 * 00208 * The lengths cannot be negative (ghost stems are never 00209 * counter-controlled). 00210 * 00211 */ 00212 typedef void 00213 (*T1_Hints_SetStem3Func)( T1_Hints hints, 00214 FT_UInt dimension, 00215 FT_Fixed* coords ); 00216 00217 00218 /************************************************************************* 00219 * 00220 * @functype: 00221 * T1_Hints_ResetFunc 00222 * 00223 * @description: 00224 * A method of the @T1_Hints class used to reset the stems hints in a 00225 * recording session. 00226 * 00227 * @input: 00228 * hints :: 00229 * A handle to the Type 1 hints recorder. 00230 * 00231 * end_point :: 00232 * The index of the last point in the input glyph in which the 00233 * previously defined hints apply. 00234 * 00235 */ 00236 typedef void 00237 (*T1_Hints_ResetFunc)( T1_Hints hints, 00238 FT_UInt end_point ); 00239 00240 00241 /************************************************************************* 00242 * 00243 * @functype: 00244 * T1_Hints_CloseFunc 00245 * 00246 * @description: 00247 * A method of the @T1_Hints class used to close a hint recording 00248 * session. 00249 * 00250 * @input: 00251 * hints :: 00252 * A handle to the Type 1 hints recorder. 00253 * 00254 * end_point :: 00255 * The index of the last point in the input glyph. 00256 * 00257 * @return: 00258 * FreeType error code. 0 means success. 00259 * 00260 * @note: 00261 * The error code is set to indicate that an error occurred during the 00262 * recording session. 00263 * 00264 */ 00265 typedef FT_Error 00266 (*T1_Hints_CloseFunc)( T1_Hints hints, 00267 FT_UInt end_point ); 00268 00269 00270 /************************************************************************* 00271 * 00272 * @functype: 00273 * T1_Hints_ApplyFunc 00274 * 00275 * @description: 00276 * A method of the @T1_Hints class used to apply hints to the 00277 * corresponding glyph outline. Must be called once all hints have been 00278 * recorded. 00279 * 00280 * @input: 00281 * hints :: 00282 * A handle to the Type 1 hints recorder. 00283 * 00284 * outline :: 00285 * A pointer to the target outline descriptor. 00286 * 00287 * globals :: 00288 * The hinter globals for this font. 00289 * 00290 * hint_mode :: 00291 * Hinting information. 00292 * 00293 * @return: 00294 * FreeType error code. 0 means success. 00295 * 00296 * @note: 00297 * On input, all points within the outline are in font coordinates. On 00298 * output, they are in 1/64th of pixels. 00299 * 00300 * The scaling transformation is taken from the `globals' object which 00301 * must correspond to the same font as the glyph. 00302 * 00303 */ 00304 typedef FT_Error 00305 (*T1_Hints_ApplyFunc)( T1_Hints hints, 00306 FT_Outline* outline, 00307 PSH_Globals globals, 00308 FT_Render_Mode hint_mode ); 00309 00310 00311 /************************************************************************* 00312 * 00313 * @struct: 00314 * T1_Hints_FuncsRec 00315 * 00316 * @description: 00317 * The structure used to provide the API to @T1_Hints objects. 00318 * 00319 * @fields: 00320 * hints :: 00321 * A handle to the T1 Hints recorder. 00322 * 00323 * open :: 00324 * The function to open a recording session. 00325 * 00326 * close :: 00327 * The function to close a recording session. 00328 * 00329 * stem :: 00330 * The function to set a simple stem. 00331 * 00332 * stem3 :: 00333 * The function to set counter-controlled stems. 00334 * 00335 * reset :: 00336 * The function to reset stem hints. 00337 * 00338 * apply :: 00339 * The function to apply the hints to the corresponding glyph outline. 00340 * 00341 */ 00342 typedef struct T1_Hints_FuncsRec_ 00343 { 00344 T1_Hints hints; 00345 T1_Hints_OpenFunc open; 00346 T1_Hints_CloseFunc close; 00347 T1_Hints_SetStemFunc stem; 00348 T1_Hints_SetStem3Func stem3; 00349 T1_Hints_ResetFunc reset; 00350 T1_Hints_ApplyFunc apply; 00351 00352 } T1_Hints_FuncsRec; 00353 00354 00355 /*************************************************************************/ 00356 /*************************************************************************/ 00357 /***** *****/ 00358 /***** PUBLIC TYPE 2 HINTS RECORDER *****/ 00359 /***** *****/ 00360 /*************************************************************************/ 00361 /*************************************************************************/ 00362 00363 /************************************************************************* 00364 * 00365 * @type: 00366 * T2_Hints 00367 * 00368 * @description: 00369 * This is a handle to an opaque structure used to record glyph hints 00370 * from a Type 2 character glyph character string. 00371 * 00372 * The methods used to operate on this object are defined by the 00373 * @T2_Hints_FuncsRec structure. Recording glyph hints is normally 00374 * achieved through the following scheme: 00375 * 00376 * - Open a new hint recording session by calling the `open' method. 00377 * This rewinds the recorder and prepare it for new input. 00378 * 00379 * - For each hint found in the glyph charstring, call the corresponding 00380 * method (`stems', `hintmask', `counters'). Note that these 00381 * functions do not return an error code. 00382 * 00383 * - Close the recording session by calling the `close' method. It 00384 * returns an error code if the hints were invalid or something 00385 * strange happened (e.g., memory shortage). 00386 * 00387 * The hints accumulated in the object can later be used by the 00388 * Postscript hinter. 00389 * 00390 */ 00391 typedef struct T2_HintsRec_* T2_Hints; 00392 00393 00394 /************************************************************************* 00395 * 00396 * @type: 00397 * T2_Hints_Funcs 00398 * 00399 * @description: 00400 * A pointer to the @T2_Hints_FuncsRec structure that defines the API of 00401 * a given @T2_Hints object. 00402 * 00403 */ 00404 typedef const struct T2_Hints_FuncsRec_* T2_Hints_Funcs; 00405 00406 00407 /************************************************************************* 00408 * 00409 * @functype: 00410 * T2_Hints_OpenFunc 00411 * 00412 * @description: 00413 * A method of the @T2_Hints class used to prepare it for a new Type 2 00414 * hints recording session. 00415 * 00416 * @input: 00417 * hints :: 00418 * A handle to the Type 2 hints recorder. 00419 * 00420 * @note: 00421 * You should always call the @T2_Hints_CloseFunc method in order to 00422 * close an opened recording session. 00423 * 00424 */ 00425 typedef void 00426 (*T2_Hints_OpenFunc)( T2_Hints hints ); 00427 00428 00429 /************************************************************************* 00430 * 00431 * @functype: 00432 * T2_Hints_StemsFunc 00433 * 00434 * @description: 00435 * A method of the @T2_Hints class used to set the table of stems in 00436 * either the vertical or horizontal dimension. Equivalent to the 00437 * `hstem', `vstem', `hstemhm', and `vstemhm' Type 2 operators. 00438 * 00439 * @input: 00440 * hints :: 00441 * A handle to the Type 2 hints recorder. 00442 * 00443 * dimension :: 00444 * 0 for horizontal stems (hstem), 1 for vertical ones (vstem). 00445 * 00446 * count :: 00447 * The number of stems. 00448 * 00449 * coords :: 00450 * An array of `count' (position,length) pairs in 16.16 format. 00451 * 00452 * @note: 00453 * Use vertical coordinates (y) for horizontal stems (dim=0). Use 00454 * horizontal coordinates (x) for vertical stems (dim=1). 00455 * 00456 * There are `2*count' elements in the `coords' array. Each even 00457 * element is an absolute position in font units, each odd element is a 00458 * length in font units. 00459 * 00460 * A length can be negative, in which case it must be either -20 or 00461 * -21. It is interpreted as a `ghost' stem, according to the Type 1 00462 * specification. 00463 * 00464 */ 00465 typedef void 00466 (*T2_Hints_StemsFunc)( T2_Hints hints, 00467 FT_UInt dimension, 00468 FT_UInt count, 00469 FT_Fixed* coordinates ); 00470 00471 00472 /************************************************************************* 00473 * 00474 * @functype: 00475 * T2_Hints_MaskFunc 00476 * 00477 * @description: 00478 * A method of the @T2_Hints class used to set a given hintmask (this 00479 * corresponds to the `hintmask' Type 2 operator). 00480 * 00481 * @input: 00482 * hints :: 00483 * A handle to the Type 2 hints recorder. 00484 * 00485 * end_point :: 00486 * The glyph index of the last point to which the previously defined 00487 * or activated hints apply. 00488 * 00489 * bit_count :: 00490 * The number of bits in the hint mask. 00491 * 00492 * bytes :: 00493 * An array of bytes modelling the hint mask. 00494 * 00495 * @note: 00496 * If the hintmask starts the charstring (before any glyph point 00497 * definition), the value of `end_point' should be 0. 00498 * 00499 * `bit_count' is the number of meaningful bits in the `bytes' array; it 00500 * must be equal to the total number of hints defined so far (i.e., 00501 * horizontal+verticals). 00502 * 00503 * The `bytes' array can come directly from the Type 2 charstring and 00504 * respects the same format. 00505 * 00506 */ 00507 typedef void 00508 (*T2_Hints_MaskFunc)( T2_Hints hints, 00509 FT_UInt end_point, 00510 FT_UInt bit_count, 00511 const FT_Byte* bytes ); 00512 00513 00514 /************************************************************************* 00515 * 00516 * @functype: 00517 * T2_Hints_CounterFunc 00518 * 00519 * @description: 00520 * A method of the @T2_Hints class used to set a given counter mask 00521 * (this corresponds to the `hintmask' Type 2 operator). 00522 * 00523 * @input: 00524 * hints :: 00525 * A handle to the Type 2 hints recorder. 00526 * 00527 * end_point :: 00528 * A glyph index of the last point to which the previously defined or 00529 * active hints apply. 00530 * 00531 * bit_count :: 00532 * The number of bits in the hint mask. 00533 * 00534 * bytes :: 00535 * An array of bytes modelling the hint mask. 00536 * 00537 * @note: 00538 * If the hintmask starts the charstring (before any glyph point 00539 * definition), the value of `end_point' should be 0. 00540 * 00541 * `bit_count' is the number of meaningful bits in the `bytes' array; it 00542 * must be equal to the total number of hints defined so far (i.e., 00543 * horizontal+verticals). 00544 * 00545 * The `bytes' array can come directly from the Type 2 charstring and 00546 * respects the same format. 00547 * 00548 */ 00549 typedef void 00550 (*T2_Hints_CounterFunc)( T2_Hints hints, 00551 FT_UInt bit_count, 00552 const FT_Byte* bytes ); 00553 00554 00555 /************************************************************************* 00556 * 00557 * @functype: 00558 * T2_Hints_CloseFunc 00559 * 00560 * @description: 00561 * A method of the @T2_Hints class used to close a hint recording 00562 * session. 00563 * 00564 * @input: 00565 * hints :: 00566 * A handle to the Type 2 hints recorder. 00567 * 00568 * end_point :: 00569 * The index of the last point in the input glyph. 00570 * 00571 * @return: 00572 * FreeType error code. 0 means success. 00573 * 00574 * @note: 00575 * The error code is set to indicate that an error occurred during the 00576 * recording session. 00577 * 00578 */ 00579 typedef FT_Error 00580 (*T2_Hints_CloseFunc)( T2_Hints hints, 00581 FT_UInt end_point ); 00582 00583 00584 /************************************************************************* 00585 * 00586 * @functype: 00587 * T2_Hints_ApplyFunc 00588 * 00589 * @description: 00590 * A method of the @T2_Hints class used to apply hints to the 00591 * corresponding glyph outline. Must be called after the `close' 00592 * method. 00593 * 00594 * @input: 00595 * hints :: 00596 * A handle to the Type 2 hints recorder. 00597 * 00598 * outline :: 00599 * A pointer to the target outline descriptor. 00600 * 00601 * globals :: 00602 * The hinter globals for this font. 00603 * 00604 * hint_mode :: 00605 * Hinting information. 00606 * 00607 * @return: 00608 * FreeType error code. 0 means success. 00609 * 00610 * @note: 00611 * On input, all points within the outline are in font coordinates. On 00612 * output, they are in 1/64th of pixels. 00613 * 00614 * The scaling transformation is taken from the `globals' object which 00615 * must correspond to the same font than the glyph. 00616 * 00617 */ 00618 typedef FT_Error 00619 (*T2_Hints_ApplyFunc)( T2_Hints hints, 00620 FT_Outline* outline, 00621 PSH_Globals globals, 00622 FT_Render_Mode hint_mode ); 00623 00624 00625 /************************************************************************* 00626 * 00627 * @struct: 00628 * T2_Hints_FuncsRec 00629 * 00630 * @description: 00631 * The structure used to provide the API to @T2_Hints objects. 00632 * 00633 * @fields: 00634 * hints :: 00635 * A handle to the T2 hints recorder object. 00636 * 00637 * open :: 00638 * The function to open a recording session. 00639 * 00640 * close :: 00641 * The function to close a recording session. 00642 * 00643 * stems :: 00644 * The function to set the dimension's stems table. 00645 * 00646 * hintmask :: 00647 * The function to set hint masks. 00648 * 00649 * counter :: 00650 * The function to set counter masks. 00651 * 00652 * apply :: 00653 * The function to apply the hints on the corresponding glyph outline. 00654 * 00655 */ 00656 typedef struct T2_Hints_FuncsRec_ 00657 { 00658 T2_Hints hints; 00659 T2_Hints_OpenFunc open; 00660 T2_Hints_CloseFunc close; 00661 T2_Hints_StemsFunc stems; 00662 T2_Hints_MaskFunc hintmask; 00663 T2_Hints_CounterFunc counter; 00664 T2_Hints_ApplyFunc apply; 00665 00666 } T2_Hints_FuncsRec; 00667 00668 00669 /* */ 00670 00671 00672 typedef struct PSHinter_Interface_ 00673 { 00674 PSH_Globals_Funcs (*get_globals_funcs)( FT_Module module ); 00675 T1_Hints_Funcs (*get_t1_funcs) ( FT_Module module ); 00676 T2_Hints_Funcs (*get_t2_funcs) ( FT_Module module ); 00677 00678 } PSHinter_Interface; 00679 00680 typedef PSHinter_Interface* PSHinter_Service; 00681 00682 #ifndef FT_CONFIG_OPTION_PIC 00683 00684 #define FT_DEFINE_PSHINTER_INTERFACE(class_, get_globals_funcs_, \ 00685 get_t1_funcs_, get_t2_funcs_) \ 00686 static const PSHinter_Interface class_ = \ 00687 { \ 00688 get_globals_funcs_, get_t1_funcs_, get_t2_funcs_ \ 00689 }; 00690 00691 #else /* FT_CONFIG_OPTION_PIC */ 00692 00693 #define FT_DEFINE_PSHINTER_INTERFACE(class_, get_globals_funcs_, \ 00694 get_t1_funcs_, get_t2_funcs_) \ 00695 void \ 00696 FT_Init_Class_##class_( FT_Library library, \ 00697 PSHinter_Interface* clazz) \ 00698 { \ 00699 FT_UNUSED(library); \ 00700 clazz->get_globals_funcs = get_globals_funcs_; \ 00701 clazz->get_t1_funcs = get_t1_funcs_; \ 00702 clazz->get_t2_funcs = get_t2_funcs_; \ 00703 } 00704 00705 #endif /* FT_CONFIG_OPTION_PIC */ 00706 00707 FT_END_HEADER 00708 00709 #endif /* __PSHINTS_H__ */ 00710 00711 00712 /* END */