Home | History | Annotate | Download | only in autofit
      1 /***************************************************************************/
      2 /*                                                                         */
      3 /*  aflatin.h                                                              */
      4 /*                                                                         */
      5 /*    Auto-fitter hinting routines for latin writing system                */
      6 /*    (specification).                                                     */
      7 /*                                                                         */
      8 /*  Copyright 2003-2015 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 __AFLATIN_H__
     21 #define __AFLATIN_H__
     22 
     23 #include "afhints.h"
     24 
     25 
     26 FT_BEGIN_HEADER
     27 
     28   /* the `latin' writing system */
     29 
     30   AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin_writing_system_class )
     31 
     32 
     33   /* constants are given with units_per_em == 2048 in mind */
     34 #define AF_LATIN_CONSTANT( metrics, c )                                      \
     35   ( ( (c) * (FT_Long)( (AF_LatinMetrics)(metrics) )->units_per_em ) / 2048 )
     36 
     37 
     38   /*************************************************************************/
     39   /*************************************************************************/
     40   /*****                                                               *****/
     41   /*****            L A T I N   G L O B A L   M E T R I C S            *****/
     42   /*****                                                               *****/
     43   /*************************************************************************/
     44   /*************************************************************************/
     45 
     46 
     47   /*
     48    *  The following declarations could be embedded in the file `aflatin.c';
     49    *  they have been made semi-public to allow alternate writing system
     50    *  hinters to re-use some of them.
     51    */
     52 
     53 
     54 #define AF_LATIN_IS_TOP_BLUE( b ) \
     55           ( (b)->properties & AF_BLUE_PROPERTY_LATIN_TOP )
     56 #define AF_LATIN_IS_NEUTRAL_BLUE( b ) \
     57           ( (b)->properties & AF_BLUE_PROPERTY_LATIN_NEUTRAL )
     58 #define AF_LATIN_IS_X_HEIGHT_BLUE( b ) \
     59           ( (b)->properties & AF_BLUE_PROPERTY_LATIN_X_HEIGHT )
     60 #define AF_LATIN_IS_LONG_BLUE( b ) \
     61           ( (b)->properties & AF_BLUE_PROPERTY_LATIN_LONG )
     62 
     63 #define AF_LATIN_MAX_WIDTHS  16
     64 
     65 
     66 #define AF_LATIN_BLUE_ACTIVE      ( 1U << 0 ) /* zone height is <= 3/4px   */
     67 #define AF_LATIN_BLUE_TOP         ( 1U << 1 ) /* we have a top blue zone   */
     68 #define AF_LATIN_BLUE_NEUTRAL     ( 1U << 2 ) /* we have neutral blue zone */
     69 #define AF_LATIN_BLUE_ADJUSTMENT  ( 1U << 3 ) /* used for scale adjustment */
     70                                               /* optimization              */
     71 
     72 
     73   typedef struct  AF_LatinBlueRec_
     74   {
     75     AF_WidthRec  ref;
     76     AF_WidthRec  shoot;
     77     FT_Pos       ascender;
     78     FT_Pos       descender;
     79     FT_UInt      flags;
     80 
     81   } AF_LatinBlueRec, *AF_LatinBlue;
     82 
     83 
     84   typedef struct  AF_LatinAxisRec_
     85   {
     86     FT_Fixed         scale;
     87     FT_Pos           delta;
     88 
     89     FT_UInt          width_count;                 /* number of used widths */
     90     AF_WidthRec      widths[AF_LATIN_MAX_WIDTHS]; /* widths array          */
     91     FT_Pos           edge_distance_threshold;   /* used for creating edges */
     92     FT_Pos           standard_width;         /* the default stem thickness */
     93     FT_Bool          extra_light;         /* is standard width very light? */
     94 
     95     /* ignored for horizontal metrics */
     96     FT_UInt          blue_count;
     97     AF_LatinBlueRec  blues[AF_BLUE_STRINGSET_MAX];
     98 
     99     FT_Fixed         org_scale;
    100     FT_Pos           org_delta;
    101 
    102   } AF_LatinAxisRec, *AF_LatinAxis;
    103 
    104 
    105   typedef struct  AF_LatinMetricsRec_
    106   {
    107     AF_StyleMetricsRec  root;
    108     FT_UInt             units_per_em;
    109     AF_LatinAxisRec     axis[AF_DIMENSION_MAX];
    110 
    111   } AF_LatinMetricsRec, *AF_LatinMetrics;
    112 
    113 
    114   FT_LOCAL( FT_Error )
    115   af_latin_metrics_init( AF_LatinMetrics  metrics,
    116                          FT_Face          face );
    117 
    118   FT_LOCAL( void )
    119   af_latin_metrics_scale( AF_LatinMetrics  metrics,
    120                           AF_Scaler        scaler );
    121 
    122   FT_LOCAL( void )
    123   af_latin_metrics_init_widths( AF_LatinMetrics  metrics,
    124                                 FT_Face          face );
    125 
    126   FT_LOCAL( void )
    127   af_latin_metrics_check_digits( AF_LatinMetrics  metrics,
    128                                  FT_Face          face );
    129 
    130 
    131   /*************************************************************************/
    132   /*************************************************************************/
    133   /*****                                                               *****/
    134   /*****           L A T I N   G L Y P H   A N A L Y S I S             *****/
    135   /*****                                                               *****/
    136   /*************************************************************************/
    137   /*************************************************************************/
    138 
    139 #define AF_LATIN_HINTS_HORZ_SNAP    ( 1U << 0 ) /* stem width snapping  */
    140 #define AF_LATIN_HINTS_VERT_SNAP    ( 1U << 1 ) /* stem height snapping */
    141 #define AF_LATIN_HINTS_STEM_ADJUST  ( 1U << 2 ) /* stem width/height    */
    142                                                 /* adjustment           */
    143 #define AF_LATIN_HINTS_MONO         ( 1U << 3 ) /* monochrome rendering */
    144 
    145 
    146 #define AF_LATIN_HINTS_DO_HORZ_SNAP( h )             \
    147   AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_HORZ_SNAP )
    148 
    149 #define AF_LATIN_HINTS_DO_VERT_SNAP( h )             \
    150   AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_VERT_SNAP )
    151 
    152 #define AF_LATIN_HINTS_DO_STEM_ADJUST( h )             \
    153   AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_STEM_ADJUST )
    154 
    155 #define AF_LATIN_HINTS_DO_MONO( h )             \
    156   AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_MONO )
    157 
    158 
    159   /*
    160    *  The next functions shouldn't normally be exported.  However, other
    161    *  writing systems might like to use these functions as-is.
    162    */
    163   FT_LOCAL( FT_Error )
    164   af_latin_hints_compute_segments( AF_GlyphHints  hints,
    165                                    AF_Dimension   dim );
    166 
    167   FT_LOCAL( void )
    168   af_latin_hints_link_segments( AF_GlyphHints  hints,
    169                                 FT_UInt        width_count,
    170                                 AF_WidthRec*   widths,
    171                                 AF_Dimension   dim );
    172 
    173   FT_LOCAL( FT_Error )
    174   af_latin_hints_compute_edges( AF_GlyphHints  hints,
    175                                 AF_Dimension   dim );
    176 
    177   FT_LOCAL( FT_Error )
    178   af_latin_hints_detect_features( AF_GlyphHints  hints,
    179                                   FT_UInt        width_count,
    180                                   AF_WidthRec*   widths,
    181                                   AF_Dimension   dim );
    182 
    183 /* */
    184 
    185 FT_END_HEADER
    186 
    187 #endif /* __AFLATIN_H__ */
    188 
    189 
    190 /* END */
    191