Home | History | Annotate | Download | only in freetype
      1 /***************************************************************************/
      2 /*                                                                         */
      3 /*  ftoutln.h                                                              */
      4 /*                                                                         */
      5 /*    Support for the FT_Outline type used to store glyph shapes of        */
      6 /*    most scalable font formats (specification).                          */
      7 /*                                                                         */
      8 /*  Copyright 1996-2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010 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 __FTOUTLN_H__
     21 #define __FTOUTLN_H__
     22 
     23 
     24 #include <ft2build.h>
     25 #include FT_FREETYPE_H
     26 
     27 #ifdef FREETYPE_H
     28 #error "freetype.h of FreeType 1 has been loaded!"
     29 #error "Please fix the directory search order for header files"
     30 #error "so that freetype.h of FreeType 2 is found first."
     31 #endif
     32 
     33 
     34 FT_BEGIN_HEADER
     35 
     36 
     37   /*************************************************************************/
     38   /*                                                                       */
     39   /* <Section>                                                             */
     40   /*    outline_processing                                                 */
     41   /*                                                                       */
     42   /* <Title>                                                               */
     43   /*    Outline Processing                                                 */
     44   /*                                                                       */
     45   /* <Abstract>                                                            */
     46   /*    Functions to create, transform, and render vectorial glyph images. */
     47   /*                                                                       */
     48   /* <Description>                                                         */
     49   /*    This section contains routines used to create and destroy scalable */
     50   /*    glyph images known as `outlines'.  These can also be measured,     */
     51   /*    transformed, and converted into bitmaps and pixmaps.               */
     52   /*                                                                       */
     53   /* <Order>                                                               */
     54   /*    FT_Outline                                                         */
     55   /*    FT_OUTLINE_FLAGS                                                   */
     56   /*    FT_Outline_New                                                     */
     57   /*    FT_Outline_Done                                                    */
     58   /*    FT_Outline_Copy                                                    */
     59   /*    FT_Outline_Translate                                               */
     60   /*    FT_Outline_Transform                                               */
     61   /*    FT_Outline_Embolden                                                */
     62   /*    FT_Outline_Reverse                                                 */
     63   /*    FT_Outline_Check                                                   */
     64   /*                                                                       */
     65   /*    FT_Outline_Get_CBox                                                */
     66   /*    FT_Outline_Get_BBox                                                */
     67   /*                                                                       */
     68   /*    FT_Outline_Get_Bitmap                                              */
     69   /*    FT_Outline_Render                                                  */
     70   /*                                                                       */
     71   /*    FT_Outline_Decompose                                               */
     72   /*    FT_Outline_Funcs                                                   */
     73   /*    FT_Outline_MoveTo_Func                                             */
     74   /*    FT_Outline_LineTo_Func                                             */
     75   /*    FT_Outline_ConicTo_Func                                            */
     76   /*    FT_Outline_CubicTo_Func                                            */
     77   /*                                                                       */
     78   /*************************************************************************/
     79 
     80 
     81   /*************************************************************************/
     82   /*                                                                       */
     83   /* <Function>                                                            */
     84   /*    FT_Outline_Decompose                                               */
     85   /*                                                                       */
     86   /* <Description>                                                         */
     87   /*    Walk over an outline's structure to decompose it into individual   */
     88   /*    segments and Bzier arcs.  This function also emits `move to'      */
     89   /*    operations to indicate the start of new contours in the outline.   */
     90   /*                                                                       */
     91   /* <Input>                                                               */
     92   /*    outline        :: A pointer to the source target.                  */
     93   /*                                                                       */
     94   /*    func_interface :: A table of `emitters', i.e., function pointers   */
     95   /*                      called during decomposition to indicate path     */
     96   /*                      operations.                                      */
     97   /*                                                                       */
     98   /* <InOut>                                                               */
     99   /*    user           :: A typeless pointer which is passed to each       */
    100   /*                      emitter during the decomposition.  It can be     */
    101   /*                      used to store the state during the               */
    102   /*                      decomposition.                                   */
    103   /*                                                                       */
    104   /* <Return>                                                              */
    105   /*    FreeType error code.  0~means success.                             */
    106   /*                                                                       */
    107   FT_EXPORT( FT_Error )
    108   FT_Outline_Decompose( FT_Outline*              outline,
    109                         const FT_Outline_Funcs*  func_interface,
    110                         void*                    user );
    111 
    112 
    113   /*************************************************************************/
    114   /*                                                                       */
    115   /* <Function>                                                            */
    116   /*    FT_Outline_New                                                     */
    117   /*                                                                       */
    118   /* <Description>                                                         */
    119   /*    Create a new outline of a given size.                              */
    120   /*                                                                       */
    121   /* <Input>                                                               */
    122   /*    library     :: A handle to the library object from where the       */
    123   /*                   outline is allocated.  Note however that the new    */
    124   /*                   outline will *not* necessarily be *freed*, when     */
    125   /*                   destroying the library, by @FT_Done_FreeType.       */
    126   /*                                                                       */
    127   /*    numPoints   :: The maximal number of points within the outline.    */
    128   /*                                                                       */
    129   /*    numContours :: The maximal number of contours within the outline.  */
    130   /*                                                                       */
    131   /* <Output>                                                              */
    132   /*    anoutline   :: A handle to the new outline.                        */
    133   /*                                                                       */
    134   /* <Return>                                                              */
    135   /*    FreeType error code.  0~means success.                             */
    136   /*                                                                       */
    137   /* <Note>                                                                */
    138   /*    The reason why this function takes a `library' parameter is simply */
    139   /*    to use the library's memory allocator.                             */
    140   /*                                                                       */
    141   FT_EXPORT( FT_Error )
    142   FT_Outline_New( FT_Library   library,
    143                   FT_UInt      numPoints,
    144                   FT_Int       numContours,
    145                   FT_Outline  *anoutline );
    146 
    147 
    148   FT_EXPORT( FT_Error )
    149   FT_Outline_New_Internal( FT_Memory    memory,
    150                            FT_UInt      numPoints,
    151                            FT_Int       numContours,
    152                            FT_Outline  *anoutline );
    153 
    154 
    155   /*************************************************************************/
    156   /*                                                                       */
    157   /* <Function>                                                            */
    158   /*    FT_Outline_Done                                                    */
    159   /*                                                                       */
    160   /* <Description>                                                         */
    161   /*    Destroy an outline created with @FT_Outline_New.                   */
    162   /*                                                                       */
    163   /* <Input>                                                               */
    164   /*    library :: A handle of the library object used to allocate the     */
    165   /*               outline.                                                */
    166   /*                                                                       */
    167   /*    outline :: A pointer to the outline object to be discarded.        */
    168   /*                                                                       */
    169   /* <Return>                                                              */
    170   /*    FreeType error code.  0~means success.                             */
    171   /*                                                                       */
    172   /* <Note>                                                                */
    173   /*    If the outline's `owner' field is not set, only the outline        */
    174   /*    descriptor will be released.                                       */
    175   /*                                                                       */
    176   /*    The reason why this function takes an `library' parameter is       */
    177   /*    simply to use ft_mem_free().                                       */
    178   /*                                                                       */
    179   FT_EXPORT( FT_Error )
    180   FT_Outline_Done( FT_Library   library,
    181                    FT_Outline*  outline );
    182 
    183 
    184   FT_EXPORT( FT_Error )
    185   FT_Outline_Done_Internal( FT_Memory    memory,
    186                             FT_Outline*  outline );
    187 
    188 
    189   /*************************************************************************/
    190   /*                                                                       */
    191   /* <Function>                                                            */
    192   /*    FT_Outline_Check                                                   */
    193   /*                                                                       */
    194   /* <Description>                                                         */
    195   /*    Check the contents of an outline descriptor.                       */
    196   /*                                                                       */
    197   /* <Input>                                                               */
    198   /*    outline :: A handle to a source outline.                           */
    199   /*                                                                       */
    200   /* <Return>                                                              */
    201   /*    FreeType error code.  0~means success.                             */
    202   /*                                                                       */
    203   FT_EXPORT( FT_Error )
    204   FT_Outline_Check( FT_Outline*  outline );
    205 
    206 
    207   /*************************************************************************/
    208   /*                                                                       */
    209   /* <Function>                                                            */
    210   /*    FT_Outline_Get_CBox                                                */
    211   /*                                                                       */
    212   /* <Description>                                                         */
    213   /*    Return an outline's `control box'.  The control box encloses all   */
    214   /*    the outline's points, including Bzier control points.  Though it  */
    215   /*    coincides with the exact bounding box for most glyphs, it can be   */
    216   /*    slightly larger in some situations (like when rotating an outline  */
    217   /*    which contains Bzier outside arcs).                               */
    218   /*                                                                       */
    219   /*    Computing the control box is very fast, while getting the bounding */
    220   /*    box can take much more time as it needs to walk over all segments  */
    221   /*    and arcs in the outline.  To get the latter, you can use the       */
    222   /*    `ftbbox' component which is dedicated to this single task.         */
    223   /*                                                                       */
    224   /* <Input>                                                               */
    225   /*    outline :: A pointer to the source outline descriptor.             */
    226   /*                                                                       */
    227   /* <Output>                                                              */
    228   /*    acbox   :: The outline's control box.                              */
    229   /*                                                                       */
    230   FT_EXPORT( void )
    231   FT_Outline_Get_CBox( const FT_Outline*  outline,
    232                        FT_BBox           *acbox );
    233 
    234 
    235   /*************************************************************************/
    236   /*                                                                       */
    237   /* <Function>                                                            */
    238   /*    FT_Outline_Translate                                               */
    239   /*                                                                       */
    240   /* <Description>                                                         */
    241   /*    Apply a simple translation to the points of an outline.            */
    242   /*                                                                       */
    243   /* <InOut>                                                               */
    244   /*    outline :: A pointer to the target outline descriptor.             */
    245   /*                                                                       */
    246   /* <Input>                                                               */
    247   /*    xOffset :: The horizontal offset.                                  */
    248   /*                                                                       */
    249   /*    yOffset :: The vertical offset.                                    */
    250   /*                                                                       */
    251   FT_EXPORT( void )
    252   FT_Outline_Translate( const FT_Outline*  outline,
    253                         FT_Pos             xOffset,
    254                         FT_Pos             yOffset );
    255 
    256 
    257   /*************************************************************************/
    258   /*                                                                       */
    259   /* <Function>                                                            */
    260   /*    FT_Outline_Copy                                                    */
    261   /*                                                                       */
    262   /* <Description>                                                         */
    263   /*    Copy an outline into another one.  Both objects must have the      */
    264   /*    same sizes (number of points & number of contours) when this       */
    265   /*    function is called.                                                */
    266   /*                                                                       */
    267   /* <Input>                                                               */
    268   /*    source :: A handle to the source outline.                          */
    269   /*                                                                       */
    270   /* <Output>                                                              */
    271   /*    target :: A handle to the target outline.                          */
    272   /*                                                                       */
    273   /* <Return>                                                              */
    274   /*    FreeType error code.  0~means success.                             */
    275   /*                                                                       */
    276   FT_EXPORT( FT_Error )
    277   FT_Outline_Copy( const FT_Outline*  source,
    278                    FT_Outline        *target );
    279 
    280 
    281   /*************************************************************************/
    282   /*                                                                       */
    283   /* <Function>                                                            */
    284   /*    FT_Outline_Transform                                               */
    285   /*                                                                       */
    286   /* <Description>                                                         */
    287   /*    Apply a simple 2x2 matrix to all of an outline's points.  Useful   */
    288   /*    for applying rotations, slanting, flipping, etc.                   */
    289   /*                                                                       */
    290   /* <InOut>                                                               */
    291   /*    outline :: A pointer to the target outline descriptor.             */
    292   /*                                                                       */
    293   /* <Input>                                                               */
    294   /*    matrix  :: A pointer to the transformation matrix.                 */
    295   /*                                                                       */
    296   /* <Note>                                                                */
    297   /*    You can use @FT_Outline_Translate if you need to translate the     */
    298   /*    outline's points.                                                  */
    299   /*                                                                       */
    300   FT_EXPORT( void )
    301   FT_Outline_Transform( const FT_Outline*  outline,
    302                         const FT_Matrix*   matrix );
    303 
    304 
    305   /*************************************************************************/
    306   /*                                                                       */
    307   /* <Function>                                                            */
    308   /*    FT_Outline_Embolden                                                */
    309   /*                                                                       */
    310   /* <Description>                                                         */
    311   /*    Embolden an outline.  The new outline will be at most 4~times      */
    312   /*    `strength' pixels wider and higher.  You may think of the left and */
    313   /*    bottom borders as unchanged.                                       */
    314   /*                                                                       */
    315   /*    Negative `strength' values to reduce the outline thickness are     */
    316   /*    possible also.                                                     */
    317   /*                                                                       */
    318   /* <InOut>                                                               */
    319   /*    outline  :: A handle to the target outline.                        */
    320   /*                                                                       */
    321   /* <Input>                                                               */
    322   /*    strength :: How strong the glyph is emboldened.  Expressed in      */
    323   /*                26.6 pixel format.                                     */
    324   /*                                                                       */
    325   /* <Return>                                                              */
    326   /*    FreeType error code.  0~means success.                             */
    327   /*                                                                       */
    328   /* <Note>                                                                */
    329   /*    The used algorithm to increase or decrease the thickness of the    */
    330   /*    glyph doesn't change the number of points; this means that certain */
    331   /*    situations like acute angles or intersections are sometimes        */
    332   /*    handled incorrectly.                                               */
    333   /*                                                                       */
    334   /*    If you need `better' metrics values you should call                */
    335   /*    @FT_Outline_Get_CBox ot @FT_Outline_Get_BBox.                      */
    336   /*                                                                       */
    337   /*    Example call:                                                      */
    338   /*                                                                       */
    339   /*    {                                                                  */
    340   /*      FT_Load_Glyph( face, index, FT_LOAD_DEFAULT );                   */
    341   /*      if ( face->slot->format == FT_GLYPH_FORMAT_OUTLINE )             */
    342   /*        FT_Outline_Embolden( &face->slot->outline, strength );         */
    343   /*    }                                                                  */
    344   /*                                                                       */
    345   FT_EXPORT( FT_Error )
    346   FT_Outline_Embolden( FT_Outline*  outline,
    347                        FT_Pos       strength );
    348 
    349 
    350   /*************************************************************************/
    351   /*                                                                       */
    352   /* <Function>                                                            */
    353   /*    FT_Outline_Reverse                                                 */
    354   /*                                                                       */
    355   /* <Description>                                                         */
    356   /*    Reverse the drawing direction of an outline.  This is used to      */
    357   /*    ensure consistent fill conventions for mirrored glyphs.            */
    358   /*                                                                       */
    359   /* <InOut>                                                               */
    360   /*    outline :: A pointer to the target outline descriptor.             */
    361   /*                                                                       */
    362   /* <Note>                                                                */
    363   /*    This function toggles the bit flag @FT_OUTLINE_REVERSE_FILL in     */
    364   /*    the outline's `flags' field.                                       */
    365   /*                                                                       */
    366   /*    It shouldn't be used by a normal client application, unless it     */
    367   /*    knows what it is doing.                                            */
    368   /*                                                                       */
    369   FT_EXPORT( void )
    370   FT_Outline_Reverse( FT_Outline*  outline );
    371 
    372 
    373   /*************************************************************************/
    374   /*                                                                       */
    375   /* <Function>                                                            */
    376   /*    FT_Outline_Get_Bitmap                                              */
    377   /*                                                                       */
    378   /* <Description>                                                         */
    379   /*    Render an outline within a bitmap.  The outline's image is simply  */
    380   /*    OR-ed to the target bitmap.                                        */
    381   /*                                                                       */
    382   /* <Input>                                                               */
    383   /*    library :: A handle to a FreeType library object.                  */
    384   /*                                                                       */
    385   /*    outline :: A pointer to the source outline descriptor.             */
    386   /*                                                                       */
    387   /* <InOut>                                                               */
    388   /*    abitmap :: A pointer to the target bitmap descriptor.              */
    389   /*                                                                       */
    390   /* <Return>                                                              */
    391   /*    FreeType error code.  0~means success.                             */
    392   /*                                                                       */
    393   /* <Note>                                                                */
    394   /*    This function does NOT CREATE the bitmap, it only renders an       */
    395   /*    outline image within the one you pass to it!  Consequently, the    */
    396   /*    various fields in `abitmap' should be set accordingly.             */
    397   /*                                                                       */
    398   /*    It will use the raster corresponding to the default glyph format.  */
    399   /*                                                                       */
    400   /*    The value of the `num_grays' field in `abitmap' is ignored.  If    */
    401   /*    you select the gray-level rasterizer, and you want less than 256   */
    402   /*    gray levels, you have to use @FT_Outline_Render directly.          */
    403   /*                                                                       */
    404   FT_EXPORT( FT_Error )
    405   FT_Outline_Get_Bitmap( FT_Library        library,
    406                          FT_Outline*       outline,
    407                          const FT_Bitmap  *abitmap );
    408 
    409 
    410   /*************************************************************************/
    411   /*                                                                       */
    412   /* <Function>                                                            */
    413   /*    FT_Outline_Render                                                  */
    414   /*                                                                       */
    415   /* <Description>                                                         */
    416   /*    Render an outline within a bitmap using the current scan-convert.  */
    417   /*    This function uses an @FT_Raster_Params structure as an argument,  */
    418   /*    allowing advanced features like direct composition, translucency,  */
    419   /*    etc.                                                               */
    420   /*                                                                       */
    421   /* <Input>                                                               */
    422   /*    library :: A handle to a FreeType library object.                  */
    423   /*                                                                       */
    424   /*    outline :: A pointer to the source outline descriptor.             */
    425   /*                                                                       */
    426   /* <InOut>                                                               */
    427   /*    params  :: A pointer to an @FT_Raster_Params structure used to     */
    428   /*               describe the rendering operation.                       */
    429   /*                                                                       */
    430   /* <Return>                                                              */
    431   /*    FreeType error code.  0~means success.                             */
    432   /*                                                                       */
    433   /* <Note>                                                                */
    434   /*    You should know what you are doing and how @FT_Raster_Params works */
    435   /*    to use this function.                                              */
    436   /*                                                                       */
    437   /*    The field `params.source' will be set to `outline' before the scan */
    438   /*    converter is called, which means that the value you give to it is  */
    439   /*    actually ignored.                                                  */
    440   /*                                                                       */
    441   /*    The gray-level rasterizer always uses 256 gray levels.  If you     */
    442   /*    want less gray levels, you have to provide your own span callback. */
    443   /*    See the @FT_RASTER_FLAG_DIRECT value of the `flags' field in the   */
    444   /*    @FT_Raster_Params structure for more details.                      */
    445   /*                                                                       */
    446   FT_EXPORT( FT_Error )
    447   FT_Outline_Render( FT_Library         library,
    448                      FT_Outline*        outline,
    449                      FT_Raster_Params*  params );
    450 
    451 
    452  /**************************************************************************
    453   *
    454   * @enum:
    455   *   FT_Orientation
    456   *
    457   * @description:
    458   *   A list of values used to describe an outline's contour orientation.
    459   *
    460   *   The TrueType and PostScript specifications use different conventions
    461   *   to determine whether outline contours should be filled or unfilled.
    462   *
    463   * @values:
    464   *   FT_ORIENTATION_TRUETYPE ::
    465   *     According to the TrueType specification, clockwise contours must
    466   *     be filled, and counter-clockwise ones must be unfilled.
    467   *
    468   *   FT_ORIENTATION_POSTSCRIPT ::
    469   *     According to the PostScript specification, counter-clockwise contours
    470   *     must be filled, and clockwise ones must be unfilled.
    471   *
    472   *   FT_ORIENTATION_FILL_RIGHT ::
    473   *     This is identical to @FT_ORIENTATION_TRUETYPE, but is used to
    474   *     remember that in TrueType, everything that is to the right of
    475   *     the drawing direction of a contour must be filled.
    476   *
    477   *   FT_ORIENTATION_FILL_LEFT ::
    478   *     This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to
    479   *     remember that in PostScript, everything that is to the left of
    480   *     the drawing direction of a contour must be filled.
    481   *
    482   *   FT_ORIENTATION_NONE ::
    483   *     The orientation cannot be determined.  That is, different parts of
    484   *     the glyph have different orientation.
    485   *
    486   */
    487   typedef enum  FT_Orientation_
    488   {
    489     FT_ORIENTATION_TRUETYPE   = 0,
    490     FT_ORIENTATION_POSTSCRIPT = 1,
    491     FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE,
    492     FT_ORIENTATION_FILL_LEFT  = FT_ORIENTATION_POSTSCRIPT,
    493     FT_ORIENTATION_NONE
    494 
    495   } FT_Orientation;
    496 
    497 
    498  /**************************************************************************
    499   *
    500   * @function:
    501   *   FT_Outline_Get_Orientation
    502   *
    503   * @description:
    504   *   This function analyzes a glyph outline and tries to compute its
    505   *   fill orientation (see @FT_Orientation).  This is done by computing
    506   *   the direction of each global horizontal and/or vertical extrema
    507   *   within the outline.
    508   *
    509   *   Note that this will return @FT_ORIENTATION_TRUETYPE for empty
    510   *   outlines.
    511   *
    512   * @input:
    513   *   outline ::
    514   *     A handle to the source outline.
    515   *
    516   * @return:
    517   *   The orientation.
    518   *
    519   */
    520   FT_EXPORT( FT_Orientation )
    521   FT_Outline_Get_Orientation( FT_Outline*  outline );
    522 
    523 
    524   /* */
    525 
    526 
    527 FT_END_HEADER
    528 
    529 #endif /* __FTOUTLN_H__ */
    530 
    531 
    532 /* END */
    533 
    534 
    535 /* Local Variables: */
    536 /* coding: utf-8    */
    537 /* End:             */
    538