1 /***************************************************************************/
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. */
9 /* Copyright 2001-2003, 2005-2007, 2009, 2012, 2014 by */
10 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
18 /***************************************************************************/
26 #include FT_FREETYPE_H
27 #include FT_TYPE1_TABLES_H
33 /*************************************************************************/
34 /*************************************************************************/
36 /***** INTERNAL REPRESENTATION OF GLOBALS *****/
38 /*************************************************************************/
39 /*************************************************************************/
41 typedef struct PSH_GlobalsRec_* PSH_Globals;
44 (*PSH_Globals_NewFunc)( FT_Memory memory,
45 T1_Private* private_dict,
46 PSH_Globals* aglobals );
49 (*PSH_Globals_SetScaleFunc)( PSH_Globals globals,
56 (*PSH_Globals_DestroyFunc)( PSH_Globals globals );
59 typedef struct PSH_Globals_FuncsRec_
61 PSH_Globals_NewFunc create;
62 PSH_Globals_SetScaleFunc set_scale;
63 PSH_Globals_DestroyFunc destroy;
65 } PSH_Globals_FuncsRec, *PSH_Globals_Funcs;
68 /*************************************************************************/
69 /*************************************************************************/
71 /***** PUBLIC TYPE 1 HINTS RECORDER *****/
73 /*************************************************************************/
74 /*************************************************************************/
76 /*************************************************************************
82 * This is a handle to an opaque structure used to record glyph hints
83 * from a Type 1 character glyph character string.
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:
89 * - Open a new hint recording session by calling the `open' method.
90 * This rewinds the recorder and prepare it for new input.
92 * - For each hint found in the glyph charstring, call the corresponding
93 * method (`stem', `stem3', or `reset'). Note that these functions do
94 * not return an error code.
96 * - Close the recording session by calling the `close' method. It
97 * returns an error code if the hints were invalid or something
98 * strange happened (e.g., memory shortage).
100 * The hints accumulated in the object can later be used by the
104 typedef struct T1_HintsRec_* T1_Hints;
107 /*************************************************************************
113 * A pointer to the @T1_Hints_FuncsRec structure that defines the API of
114 * a given @T1_Hints object.
117 typedef const struct T1_Hints_FuncsRec_* T1_Hints_Funcs;
120 /*************************************************************************
126 * A method of the @T1_Hints class used to prepare it for a new Type 1
127 * hints recording session.
131 * A handle to the Type 1 hints recorder.
134 * You should always call the @T1_Hints_CloseFunc method in order to
135 * close an opened recording session.
139 (*T1_Hints_OpenFunc)( T1_Hints hints );
142 /*************************************************************************
145 * T1_Hints_SetStemFunc
148 * A method of the @T1_Hints class used to record a new horizontal or
149 * vertical stem. This corresponds to the Type 1 `hstem' and `vstem'
154 * A handle to the Type 1 hints recorder.
157 * 0 for horizontal stems (hstem), 1 for vertical ones (vstem).
160 * Array of 2 coordinates in 16.16 format, used as (position,length)
164 * Use vertical coordinates (y) for horizontal stems (dim=0). Use
165 * horizontal coordinates (x) for vertical stems (dim=1).
167 * `coords[0]' is the absolute stem position (lowest coordinate);
168 * `coords[1]' is the length.
170 * The length can be negative, in which case it must be either -20 or
171 * -21. It is interpreted as a `ghost' stem, according to the Type 1
174 * If the length is -21 (corresponding to a bottom ghost stem), then
175 * the real stem position is `coords[0]+coords[1]'.
179 (*T1_Hints_SetStemFunc)( T1_Hints hints,
184 /*************************************************************************
187 * T1_Hints_SetStem3Func
190 * A method of the @T1_Hints class used to record three
191 * counter-controlled horizontal or vertical stems at once.
195 * A handle to the Type 1 hints recorder.
198 * 0 for horizontal stems, 1 for vertical ones.
201 * An array of 6 values in 16.16 format, holding 3 (position,length)
202 * pairs for the counter-controlled stems.
205 * Use vertical coordinates (y) for horizontal stems (dim=0). Use
206 * horizontal coordinates (x) for vertical stems (dim=1).
208 * The lengths cannot be negative (ghost stems are never
209 * counter-controlled).
213 (*T1_Hints_SetStem3Func)( T1_Hints hints,
218 /*************************************************************************
224 * A method of the @T1_Hints class used to reset the stems hints in a
229 * A handle to the Type 1 hints recorder.
232 * The index of the last point in the input glyph in which the
233 * previously defined hints apply.
237 (*T1_Hints_ResetFunc)( T1_Hints hints,
241 /*************************************************************************
247 * A method of the @T1_Hints class used to close a hint recording
252 * A handle to the Type 1 hints recorder.
255 * The index of the last point in the input glyph.
258 * FreeType error code. 0 means success.
261 * The error code is set to indicate that an error occurred during the
266 (*T1_Hints_CloseFunc)( T1_Hints hints,
270 /*************************************************************************
276 * A method of the @T1_Hints class used to apply hints to the
277 * corresponding glyph outline. Must be called once all hints have been
282 * A handle to the Type 1 hints recorder.
285 * A pointer to the target outline descriptor.
288 * The hinter globals for this font.
291 * Hinting information.
294 * FreeType error code. 0 means success.
297 * On input, all points within the outline are in font coordinates. On
298 * output, they are in 1/64th of pixels.
300 * The scaling transformation is taken from the `globals' object which
301 * must correspond to the same font as the glyph.
305 (*T1_Hints_ApplyFunc)( T1_Hints hints,
308 FT_Render_Mode hint_mode );
311 /*************************************************************************
317 * The structure used to provide the API to @T1_Hints objects.
321 * A handle to the T1 Hints recorder.
324 * The function to open a recording session.
327 * The function to close a recording session.
330 * The function to set a simple stem.
333 * The function to set counter-controlled stems.
336 * The function to reset stem hints.
339 * The function to apply the hints to the corresponding glyph outline.
342 typedef struct T1_Hints_FuncsRec_
345 T1_Hints_OpenFunc open;
346 T1_Hints_CloseFunc close;
347 T1_Hints_SetStemFunc stem;
348 T1_Hints_SetStem3Func stem3;
349 T1_Hints_ResetFunc reset;
350 T1_Hints_ApplyFunc apply;
355 /*************************************************************************/
356 /*************************************************************************/
358 /***** PUBLIC TYPE 2 HINTS RECORDER *****/
360 /*************************************************************************/
361 /*************************************************************************/
363 /*************************************************************************
369 * This is a handle to an opaque structure used to record glyph hints
370 * from a Type 2 character glyph character string.
372 * The methods used to operate on this object are defined by the
373 * @T2_Hints_FuncsRec structure. Recording glyph hints is normally
374 * achieved through the following scheme:
376 * - Open a new hint recording session by calling the `open' method.
377 * This rewinds the recorder and prepare it for new input.
379 * - For each hint found in the glyph charstring, call the corresponding
380 * method (`stems', `hintmask', `counters'). Note that these
381 * functions do not return an error code.
383 * - Close the recording session by calling the `close' method. It
384 * returns an error code if the hints were invalid or something
385 * strange happened (e.g., memory shortage).
387 * The hints accumulated in the object can later be used by the
391 typedef struct T2_HintsRec_* T2_Hints;
394 /*************************************************************************
400 * A pointer to the @T2_Hints_FuncsRec structure that defines the API of
401 * a given @T2_Hints object.
404 typedef const struct T2_Hints_FuncsRec_* T2_Hints_Funcs;
407 /*************************************************************************
413 * A method of the @T2_Hints class used to prepare it for a new Type 2
414 * hints recording session.
418 * A handle to the Type 2 hints recorder.
421 * You should always call the @T2_Hints_CloseFunc method in order to
422 * close an opened recording session.
426 (*T2_Hints_OpenFunc)( T2_Hints hints );
429 /*************************************************************************
435 * A method of the @T2_Hints class used to set the table of stems in
436 * either the vertical or horizontal dimension. Equivalent to the
437 * `hstem', `vstem', `hstemhm', and `vstemhm' Type 2 operators.
441 * A handle to the Type 2 hints recorder.
444 * 0 for horizontal stems (hstem), 1 for vertical ones (vstem).
447 * The number of stems.
450 * An array of `count' (position,length) pairs in 16.16 format.
453 * Use vertical coordinates (y) for horizontal stems (dim=0). Use
454 * horizontal coordinates (x) for vertical stems (dim=1).
456 * There are `2*count' elements in the `coords' array. Each even
457 * element is an absolute position in font units, each odd element is a
458 * length in font units.
460 * A length can be negative, in which case it must be either -20 or
461 * -21. It is interpreted as a `ghost' stem, according to the Type 1
466 (*T2_Hints_StemsFunc)( T2_Hints hints,
469 FT_Fixed* coordinates );
472 /*************************************************************************
478 * A method of the @T2_Hints class used to set a given hintmask (this
479 * corresponds to the `hintmask' Type 2 operator).
483 * A handle to the Type 2 hints recorder.
486 * The glyph index of the last point to which the previously defined
487 * or activated hints apply.
490 * The number of bits in the hint mask.
493 * An array of bytes modelling the hint mask.
496 * If the hintmask starts the charstring (before any glyph point
497 * definition), the value of `end_point' should be 0.
499 * `bit_count' is the number of meaningful bits in the `bytes' array; it
500 * must be equal to the total number of hints defined so far (i.e.,
501 * horizontal+verticals).
503 * The `bytes' array can come directly from the Type 2 charstring and
504 * respects the same format.
508 (*T2_Hints_MaskFunc)( T2_Hints hints,
511 const FT_Byte* bytes );
514 /*************************************************************************
517 * T2_Hints_CounterFunc
520 * A method of the @T2_Hints class used to set a given counter mask
521 * (this corresponds to the `hintmask' Type 2 operator).
525 * A handle to the Type 2 hints recorder.
528 * A glyph index of the last point to which the previously defined or
529 * active hints apply.
532 * The number of bits in the hint mask.
535 * An array of bytes modelling the hint mask.
538 * If the hintmask starts the charstring (before any glyph point
539 * definition), the value of `end_point' should be 0.
541 * `bit_count' is the number of meaningful bits in the `bytes' array; it
542 * must be equal to the total number of hints defined so far (i.e.,
543 * horizontal+verticals).
545 * The `bytes' array can come directly from the Type 2 charstring and
546 * respects the same format.
550 (*T2_Hints_CounterFunc)( T2_Hints hints,
552 const FT_Byte* bytes );
555 /*************************************************************************
561 * A method of the @T2_Hints class used to close a hint recording
566 * A handle to the Type 2 hints recorder.
569 * The index of the last point in the input glyph.
572 * FreeType error code. 0 means success.
575 * The error code is set to indicate that an error occurred during the
580 (*T2_Hints_CloseFunc)( T2_Hints hints,
584 /*************************************************************************
590 * A method of the @T2_Hints class used to apply hints to the
591 * corresponding glyph outline. Must be called after the `close'
596 * A handle to the Type 2 hints recorder.
599 * A pointer to the target outline descriptor.
602 * The hinter globals for this font.
605 * Hinting information.
608 * FreeType error code. 0 means success.
611 * On input, all points within the outline are in font coordinates. On
612 * output, they are in 1/64th of pixels.
614 * The scaling transformation is taken from the `globals' object which
615 * must correspond to the same font than the glyph.
619 (*T2_Hints_ApplyFunc)( T2_Hints hints,
622 FT_Render_Mode hint_mode );
625 /*************************************************************************
631 * The structure used to provide the API to @T2_Hints objects.
635 * A handle to the T2 hints recorder object.
638 * The function to open a recording session.
641 * The function to close a recording session.
644 * The function to set the dimension's stems table.
647 * The function to set hint masks.
650 * The function to set counter masks.
653 * The function to apply the hints on the corresponding glyph outline.
656 typedef struct T2_Hints_FuncsRec_
659 T2_Hints_OpenFunc open;
660 T2_Hints_CloseFunc close;
661 T2_Hints_StemsFunc stems;
662 T2_Hints_MaskFunc hintmask;
663 T2_Hints_CounterFunc counter;
664 T2_Hints_ApplyFunc apply;
672 typedef struct PSHinter_Interface_
674 PSH_Globals_Funcs (*get_globals_funcs)( FT_Module module );
675 T1_Hints_Funcs (*get_t1_funcs) ( FT_Module module );
676 T2_Hints_Funcs (*get_t2_funcs) ( FT_Module module );
678 } PSHinter_Interface;
680 typedef PSHinter_Interface* PSHinter_Service;
683 #ifndef FT_CONFIG_OPTION_PIC
685 #define FT_DEFINE_PSHINTER_INTERFACE( \
687 get_globals_funcs_, \
690 static const PSHinter_Interface class_ = \
692 get_globals_funcs_, \
697 #else /* FT_CONFIG_OPTION_PIC */
699 #define FT_DEFINE_PSHINTER_INTERFACE( \
701 get_globals_funcs_, \
705 FT_Init_Class_ ## class_( FT_Library library, \
706 PSHinter_Interface* clazz ) \
708 FT_UNUSED( library ); \
710 clazz->get_globals_funcs = get_globals_funcs_; \
711 clazz->get_t1_funcs = get_t1_funcs_; \
712 clazz->get_t2_funcs = get_t2_funcs_; \
715 #endif /* FT_CONFIG_OPTION_PIC */
719 #endif /* __PSHINTS_H__ */