pshalgo.h

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  pshalgo.h                                                              */
00004 /*                                                                         */
00005 /*    PostScript hinting algorithm (specification).                        */
00006 /*                                                                         */
00007 /*  Copyright 2001, 2002, 2003, 2008 by                                    */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #ifndef __PSHALGO_H__
00020 #define __PSHALGO_H__
00021 
00022 
00023 #include "pshrec.h"
00024 #include "pshglob.h"
00025 #include FT_TRIGONOMETRY_H
00026 
00027 
00028 FT_BEGIN_HEADER
00029 
00030 
00031   /* handle to Hint structure */
00032   typedef struct PSH_HintRec_*  PSH_Hint;
00033 
00034   /* hint bit-flags */
00035   typedef enum  PSH_Hint_Flags_
00036   {
00037     PSH_HINT_GHOST  = PS_HINT_FLAG_GHOST,
00038     PSH_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM,
00039     PSH_HINT_ACTIVE = 4,
00040     PSH_HINT_FITTED = 8
00041 
00042   } PSH_Hint_Flags;
00043 
00044 
00045 #define psh_hint_is_active( x )  ( ( (x)->flags & PSH_HINT_ACTIVE ) != 0 )
00046 #define psh_hint_is_ghost( x )   ( ( (x)->flags & PSH_HINT_GHOST  ) != 0 )
00047 #define psh_hint_is_fitted( x )  ( ( (x)->flags & PSH_HINT_FITTED ) != 0 )
00048 
00049 #define psh_hint_activate( x )    (x)->flags |=  PSH_HINT_ACTIVE
00050 #define psh_hint_deactivate( x )  (x)->flags &= ~PSH_HINT_ACTIVE
00051 #define psh_hint_set_fitted( x )  (x)->flags |=  PSH_HINT_FITTED
00052 
00053   /* hint structure */
00054   typedef struct  PSH_HintRec_
00055   {
00056     FT_Int    org_pos;
00057     FT_Int    org_len;
00058     FT_Pos    cur_pos;
00059     FT_Pos    cur_len;
00060     FT_UInt   flags;
00061     PSH_Hint  parent;
00062     FT_Int    order;
00063 
00064   } PSH_HintRec;
00065 
00066 
00067   /* this is an interpolation zone used for strong points;  */
00068   /* weak points are interpolated according to their strong */
00069   /* neighbours                                             */
00070   typedef struct  PSH_ZoneRec_
00071   {
00072     FT_Fixed  scale;
00073     FT_Fixed  delta;
00074     FT_Pos    min;
00075     FT_Pos    max;
00076 
00077   } PSH_ZoneRec, *PSH_Zone;
00078 
00079 
00080   typedef struct  PSH_Hint_TableRec_
00081   {
00082     FT_UInt        max_hints;
00083     FT_UInt        num_hints;
00084     PSH_Hint       hints;
00085     PSH_Hint*      sort;
00086     PSH_Hint*      sort_global;
00087     FT_UInt        num_zones;
00088     PSH_ZoneRec*   zones;
00089     PSH_Zone       zone;
00090     PS_Mask_Table  hint_masks;
00091     PS_Mask_Table  counter_masks;
00092 
00093   } PSH_Hint_TableRec, *PSH_Hint_Table;
00094 
00095 
00096   typedef struct PSH_PointRec_*    PSH_Point;
00097   typedef struct PSH_ContourRec_*  PSH_Contour;
00098 
00099   enum
00100   {
00101     PSH_DIR_NONE  =  4,
00102     PSH_DIR_UP    = -1,
00103     PSH_DIR_DOWN  =  1,
00104     PSH_DIR_LEFT  = -2,
00105     PSH_DIR_RIGHT =  2
00106   };
00107 
00108 #define PSH_DIR_HORIZONTAL  2
00109 #define PSH_DIR_VERTICAL    1
00110 
00111 #define PSH_DIR_COMPARE( d1, d2 )   ( (d1) == (d2) || (d1) == -(d2) )
00112 #define PSH_DIR_IS_HORIZONTAL( d )  PSH_DIR_COMPARE( d, PSH_DIR_HORIZONTAL )
00113 #define PSH_DIR_IS_VERTICAL( d )    PSH_DIR_COMPARE( d, PSH_DIR_VERTICAL )
00114 
00115 
00116  /* the following bit-flags are computed once by the glyph */
00117  /* analyzer, for both dimensions                          */
00118   enum
00119   {
00120     PSH_POINT_OFF    = 1,   /* point is off the curve */
00121     PSH_POINT_SMOOTH = 2,   /* point is smooth        */
00122     PSH_POINT_INFLEX = 4    /* point is inflection    */
00123   };
00124 
00125 #define psh_point_is_smooth( p )  ( (p)->flags & PSH_POINT_SMOOTH )
00126 #define psh_point_is_off( p )     ( (p)->flags & PSH_POINT_OFF    )
00127 #define psh_point_is_inflex( p )  ( (p)->flags & PSH_POINT_INFLEX )
00128 
00129 #define psh_point_set_smooth( p )  (p)->flags |= PSH_POINT_SMOOTH
00130 #define psh_point_set_off( p )     (p)->flags |= PSH_POINT_OFF
00131 #define psh_point_set_inflex( p )  (p)->flags |= PSH_POINT_INFLEX
00132 
00133   /* the following bit-flags are re-computed for each dimension */
00134   enum
00135   {
00136     PSH_POINT_STRONG   = 16,   /* point is strong                           */
00137     PSH_POINT_FITTED   = 32,   /* point is already fitted                   */
00138     PSH_POINT_EXTREMUM = 64,   /* point is local extremum                   */
00139     PSH_POINT_POSITIVE = 128,  /* extremum has positive contour flow        */
00140     PSH_POINT_NEGATIVE = 256,  /* extremum has negative contour flow        */
00141     PSH_POINT_EDGE_MIN = 512,  /* point is aligned to left/bottom stem edge */
00142     PSH_POINT_EDGE_MAX = 1024  /* point is aligned to top/right stem edge   */
00143   };
00144 
00145 #define psh_point_is_strong( p )    ( (p)->flags2 & PSH_POINT_STRONG )
00146 #define psh_point_is_fitted( p )    ( (p)->flags2 & PSH_POINT_FITTED )
00147 #define psh_point_is_extremum( p )  ( (p)->flags2 & PSH_POINT_EXTREMUM )
00148 #define psh_point_is_positive( p )  ( (p)->flags2 & PSH_POINT_POSITIVE )
00149 #define psh_point_is_negative( p )  ( (p)->flags2 & PSH_POINT_NEGATIVE )
00150 #define psh_point_is_edge_min( p )  ( (p)->flags2 & PSH_POINT_EDGE_MIN )
00151 #define psh_point_is_edge_max( p )  ( (p)->flags2 & PSH_POINT_EDGE_MAX )
00152 
00153 #define psh_point_set_strong( p )    (p)->flags2 |= PSH_POINT_STRONG
00154 #define psh_point_set_fitted( p )    (p)->flags2 |= PSH_POINT_FITTED
00155 #define psh_point_set_extremum( p )  (p)->flags2 |= PSH_POINT_EXTREMUM
00156 #define psh_point_set_positive( p )  (p)->flags2 |= PSH_POINT_POSITIVE
00157 #define psh_point_set_negative( p )  (p)->flags2 |= PSH_POINT_NEGATIVE
00158 #define psh_point_set_edge_min( p )  (p)->flags2 |= PSH_POINT_EDGE_MIN
00159 #define psh_point_set_edge_max( p )  (p)->flags2 |= PSH_POINT_EDGE_MAX
00160 
00161 
00162   typedef struct  PSH_PointRec_
00163   {
00164     PSH_Point    prev;
00165     PSH_Point    next;
00166     PSH_Contour  contour;
00167     FT_UInt      flags;
00168     FT_UInt      flags2;
00169     FT_Char      dir_in;
00170     FT_Char      dir_out;
00171     FT_Angle     angle_in;
00172     FT_Angle     angle_out;
00173     PSH_Hint     hint;
00174     FT_Pos       org_u;
00175     FT_Pos       org_v;
00176     FT_Pos       cur_u;
00177 #ifdef DEBUG_HINTER
00178     FT_Pos       org_x;
00179     FT_Pos       cur_x;
00180     FT_Pos       org_y;
00181     FT_Pos       cur_y;
00182     FT_UInt      flags_x;
00183     FT_UInt      flags_y;
00184 #endif
00185 
00186   } PSH_PointRec;
00187 
00188 
00189 #define PSH_POINT_EQUAL_ORG( a, b )  ( (a)->org_u == (b)->org_u && \
00190                                        (a)->org_v == (b)->org_v )
00191 
00192 #define PSH_POINT_ANGLE( a, b )  FT_Atan2( (b)->org_u - (a)->org_u,  \
00193                                            (b)->org_v - (a)->org_v )
00194 
00195   typedef struct  PSH_ContourRec_
00196   {
00197     PSH_Point  start;
00198     FT_UInt    count;
00199 
00200   } PSH_ContourRec;
00201 
00202 
00203   typedef struct  PSH_GlyphRec_
00204   {
00205     FT_UInt            num_points;
00206     FT_UInt            num_contours;
00207 
00208     PSH_Point          points;
00209     PSH_Contour        contours;
00210 
00211     FT_Memory          memory;
00212     FT_Outline*        outline;
00213     PSH_Globals        globals;
00214     PSH_Hint_TableRec  hint_tables[2];
00215 
00216     FT_Bool            vertical;
00217     FT_Int             major_dir;
00218     FT_Int             minor_dir;
00219 
00220     FT_Bool            do_horz_hints;
00221     FT_Bool            do_vert_hints;
00222     FT_Bool            do_horz_snapping;
00223     FT_Bool            do_vert_snapping;
00224     FT_Bool            do_stem_adjust;
00225 
00226   } PSH_GlyphRec, *PSH_Glyph;
00227 
00228 
00229 #ifdef DEBUG_HINTER
00230   extern PSH_Hint_Table  ps_debug_hint_table;
00231 
00232   typedef void
00233   (*PSH_HintFunc)( PSH_Hint  hint,
00234                    FT_Bool   vertical );
00235 
00236   extern PSH_HintFunc    ps_debug_hint_func;
00237 
00238   extern PSH_Glyph       ps_debug_glyph;
00239 #endif
00240 
00241 
00242   extern FT_Error
00243   ps_hints_apply( PS_Hints        ps_hints,
00244                   FT_Outline*     outline,
00245                   PSH_Globals     globals,
00246                   FT_Render_Mode  hint_mode );
00247 
00248 
00249 FT_END_HEADER
00250 
00251 
00252 #endif /* __PSHALGO_H__ */
00253 
00254 
00255 /* END */

Generated on Tue Jul 5 14:13:50 2011 for ROOT_528-00b_version by  doxygen 1.5.1