FreeType-2.2.1 API Reference

Outline Processing

Synopsis

FT_OutlineFT_Outline_MoveToFunc
FT_OUTLINE_FLAGSFT_Outline_LineToFunc
FT_Outline_NewFT_Outline_ConicToFunc
FT_Outline_DoneFT_Outline_CubicToFunc
FT_Outline_CopyFT_Outline_Funcs
FT_Outline_TranslateFT_Outline_Decompose
FT_Outline_TransformFT_Outline_Get_CBox
FT_Outline_EmboldenFT_Outline_Get_Bitmap
FT_Outline_ReverseFT_Outline_Render
FT_Outline_CheckFT_Orientation
FT_Outline_Get_BBoxFT_Outline_Get_Orientation
ft_outline_flags


This section contains routines used to create and destroy scalable glyph images known as ‘outlines’. These can also be measured, transformed, and converted into bitmaps and pixmaps.


FT_Outline


  typedef struct  FT_Outline_
  {
    short       n_contours;      /* number of contours in glyph        */
    short       n_points;        /* number of points in the glyph      */

    FT_Vector*  points;          /* the outline's points               */
    char*       tags;            /* the points flags                   */
    short*      contours;        /* the contour end points             */

    int         flags;           /* outline masks                      */

  } FT_Outline;


This structure is used to describe an outline to the scan-line converter.


fields
n_contours

The number of contours in the outline.

n_points

The number of points in the outline.

points

A pointer to an array of ‘n_points’ FT_Vector elements, giving the outline's point coordinates.

tags

A pointer to an array of ‘n_points’ chars, giving each outline point's type. If bit 0 is unset, the point is ‘off’ the curve, i.e., a Bézier control point, while it is ‘on’ when set.

Bit 1 is meaningful for ‘off’ points only. If set, it indicates a third-order Bézier arc control point; and a second-order control point if unset.

contours

An array of ‘n_contours’ shorts, giving the end point of each contour within the outline. For example, the first contour is defined by the points ‘0’ to ‘contours[0]’, the second one is defined by the points ‘contours[0]+1’ to ‘contours[1]’, etc.

flags

A set of bit flags used to characterize the outline and give hints to the scan-converter and hinter on how to convert/grid-fit it. See FT_OUTLINE_FLAGS.


[Index] [TOC]

FT_OUTLINE_FLAGS


#define FT_OUTLINE_NONE             0x0
#define FT_OUTLINE_OWNER            0x1
#define FT_OUTLINE_EVEN_ODD_FILL    0x2
#define FT_OUTLINE_REVERSE_FILL     0x4
#define FT_OUTLINE_IGNORE_DROPOUTS  0x8

#define FT_OUTLINE_HIGH_PRECISION   0x100
#define FT_OUTLINE_SINGLE_PASS      0x200


A list of bit-field constants use for the flags in an outline's ‘flags’ field.


values
FT_OUTLINE_NONE

Value 0 is reserved.

FT_OUTLINE_OWNER

If set, this flag indicates that the outline's field arrays (i.e., ‘points’, ‘flags’ & ‘contours’) are ‘owned’ by the outline object, and should thus be freed when it is destroyed.

FT_OUTLINE_EVEN_ODD_FILL

By default, outlines are filled using the non-zero winding rule. If set to 1, the outline will be filled using the even-odd fill rule (only works with the smooth raster).

FT_OUTLINE_REVERSE_FILL

By default, outside contours of an outline are oriented in clock-wise direction, as defined in the TrueType specification. This flag is set if the outline uses the opposite direction (typically for Type 1 fonts). This flag is ignored by the scan-converter. However, it is very important for the auto-hinter.

FT_OUTLINE_IGNORE_DROPOUTS

By default, the scan converter will try to detect drop-outs in an outline and correct the glyph bitmap to ensure consistent shape continuity. If set, this flag hints the scan-line converter to ignore such cases.

FT_OUTLINE_HIGH_PRECISION

This flag indicates that the scan-line converter should try to convert this outline to bitmaps with the highest possible quality. It is typically set for small character sizes. Note that this is only a hint, that might be completely ignored by a given scan-converter.

FT_OUTLINE_SINGLE_PASS

This flag is set to force a given scan-converter to only use a single pass over the outline to render a bitmap glyph image. Normally, it is set for very large character sizes. It is only a hint, that might be completely ignored by a given scan-converter.


[Index] [TOC]

FT_Outline_New


  FT_EXPORT( FT_Error )
  FT_Outline_New( FT_Library   library,
                  FT_UInt      numPoints,
                  FT_Int       numContours,
                  FT_Outline  *anoutline );


  FT_EXPORT( FT_Error )
  FT_Outline_New_Internal( FT_Memory    memory,
                           FT_UInt      numPoints,
                           FT_Int       numContours,
                           FT_Outline  *anoutline );


Creates a new outline of a given size.


input
library

A handle to the library object from where the outline is allocated. Note however that the new outline will not necessarily be freed, when destroying the library, by FT_Done_FreeType.

numPoints

The maximal number of points within the outline.

numContours

The maximal number of contours within the outline.

output
anoutline

A handle to the new outline. NULL in case of error.

return

FreeType error code. 0 means success.

note

The reason why this function takes a ‘library’ parameter is simply to use the library's memory allocator.


[Index] [TOC]

FT_Outline_Done


  FT_EXPORT( FT_Error )
  FT_Outline_Done( FT_Library   library,
                   FT_Outline*  outline );


  FT_EXPORT( FT_Error )
  FT_Outline_Done_Internal( FT_Memory    memory,
                            FT_Outline*  outline );


Destroys an outline created with FT_Outline_New.


input
library

A handle of the library object used to allocate the outline.

outline

A pointer to the outline object to be discarded.

return

FreeType error code. 0 means success.

note

If the outline's ‘owner’ field is not set, only the outline descriptor will be released.

The reason why this function takes an ‘library’ parameter is simply to use ft_mem_free().


[Index] [TOC]

FT_Outline_Copy


  FT_EXPORT( FT_Error )
  FT_Outline_Copy( const FT_Outline*  source,
                   FT_Outline        *target );


Copies an outline into another one. Both objects must have the same sizes (number of points & number of contours) when this function is called.


input
source

A handle to the source outline.

output
target

A handle to the target outline.

return

FreeType error code. 0 means success.


[Index] [TOC]

FT_Outline_Translate


  FT_EXPORT( void )
  FT_Outline_Translate( const FT_Outline*  outline,
                        FT_Pos             xOffset,
                        FT_Pos             yOffset );


Applies a simple translation to the points of an outline.


inout
outline

A pointer to the target outline descriptor.

input
xOffset

The horizontal offset.

yOffset

The vertical offset.


[Index] [TOC]

FT_Outline_Transform


  FT_EXPORT( void )
  FT_Outline_Transform( const FT_Outline*  outline,
                        const FT_Matrix*   matrix );


Applies a simple 2x2 matrix to all of an outline's points. Useful for applying rotations, slanting, flipping, etc.


inout
outline

A pointer to the target outline descriptor.

input
matrix

A pointer to the transformation matrix.

note

You can use FT_Outline_Translate if you need to translate the outline's points.


[Index] [TOC]

FT_Outline_Embolden


  FT_EXPORT( FT_Error )
  FT_Outline_Embolden( FT_Outline*  outline,
                       FT_Pos       strength );


Emboldens an outline. The new outline will be at most 4 times ‘strength’ pixels wider and higher. You may think of the left and bottom borders as unchanged.

Negative ‘strength’ values to reduce the outline thickness are possible also.


inout
outline

A handle to the target outline.

input
strength

How strong the glyph is emboldened. Expressed in 26.6 pixel format.

return

FreeType error code. 0 means success.

note

The used algorithm to increase or decrease the thickness of the glyph doesn't change the number of points; this means that certain situations like acute angles or intersections are sometimes handled incorrectly.

Example call:

  FT_Load_Glyph( face, index, FT_LOAD_DEFAULT );                   
  if ( face->slot->format == FT_GLYPH_FORMAT_OUTLINE )             
    FT_Outline_Embolden( &face->slot->outline, strength );         

[Index] [TOC]

FT_Outline_Reverse


  FT_EXPORT( void )
  FT_Outline_Reverse( FT_Outline*  outline );


Reverses the drawing direction of an outline. This is used to ensure consistent fill conventions for mirrored glyphs.


inout
outline

A pointer to the target outline descriptor.

note

This functions toggles the bit flag FT_OUTLINE_REVERSE_FILL in the outline's ‘flags’ field.

It shouldn't be used by a normal client application, unless it knows what it is doing.


[Index] [TOC]

FT_Outline_Check


  FT_EXPORT( FT_Error )
  FT_Outline_Check( FT_Outline*  outline );


Check the contents of an outline descriptor.


input
outline

A handle to a source outline.

return

FreeType error code. 0 means success.


[Index] [TOC]

FT_Outline_Get_BBox


  FT_EXPORT( FT_Error )
  FT_Outline_Get_BBox( FT_Outline*  outline,
                       FT_BBox     *abbox );


Computes the exact bounding box of an outline. This is slower than computing the control box. However, it uses an advanced algorithm which returns very quickly when the two boxes coincide. Otherwise, the outline Bézier arcs are walked over to extract their extrema.


input
outline

A pointer to the source outline.

output
abbox

The outline's exact bounding box.

return

FreeType error code. 0 means success.


[Index] [TOC]

ft_outline_flags


#define ft_outline_none             FT_OUTLINE_NONE
#define ft_outline_owner            FT_OUTLINE_OWNER
#define ft_outline_even_odd_fill    FT_OUTLINE_EVEN_ODD_FILL
#define ft_outline_reverse_fill     FT_OUTLINE_REVERSE_FILL
#define ft_outline_ignore_dropouts  FT_OUTLINE_IGNORE_DROPOUTS
#define ft_outline_high_precision   FT_OUTLINE_HIGH_PRECISION
#define ft_outline_single_pass      FT_OUTLINE_SINGLE_PASS


These constants are deprecated. Please use the corresponding FT_OUTLINE_FLAGS values.


values
ft_outline_none

See FT_OUTLINE_NONE.

ft_outline_owner

See FT_OUTLINE_OWNER.

ft_outline_even_odd_fill

See FT_OUTLINE_EVEN_ODD_FILL.

ft_outline_reverse_fill

See FT_OUTLINE_REVERSE_FILL.

ft_outline_ignore_dropouts

See FT_OUTLINE_IGNORE_DROPOUTS.

ft_outline_high_precision

See FT_OUTLINE_HIGH_PRECISION.

ft_outline_single_pass

See FT_OUTLINE_SINGLE_PASS.


[Index] [TOC]

FT_Outline_MoveToFunc


  typedef int
  (*FT_Outline_MoveToFunc)( const FT_Vector*  to,
                            void*             user );

#define FT_Outline_MoveTo_Func  FT_Outline_MoveToFunc


A function pointer type used to describe the signature of a ‘move to’ function during outline walking/decomposition.

A ‘move to’ is emitted to start a new contour in an outline.


input
to

A pointer to the target point of the ‘move to’.

user

A typeless pointer which is passed from the caller of the decomposition function.

return

Error code. 0 means success.


[Index] [TOC]

FT_Outline_LineToFunc


  typedef int
  (*FT_Outline_LineToFunc)( const FT_Vector*  to,
                            void*             user );

#define  FT_Outline_LineTo_Func  FT_Outline_LineToFunc


A function pointer type used to describe the signature of a ‘line to’ function during outline walking/decomposition.

A ‘line to’ is emitted to indicate a segment in the outline.


input
to

A pointer to the target point of the ‘line to’.

user

A typeless pointer which is passed from the caller of the decomposition function.

return

Error code. 0 means success.


[Index] [TOC]

FT_Outline_ConicToFunc


  typedef int
  (*FT_Outline_ConicToFunc)( const FT_Vector*  control,
                             const FT_Vector*  to,
                             void*             user );

#define  FT_Outline_ConicTo_Func  FT_Outline_ConicToFunc


A function pointer type use to describe the signature of a ‘conic to’ function during outline walking/decomposition.

A ‘conic to’ is emitted to indicate a second-order Bézier arc in the outline.


input
control

An intermediate control point between the last position and the new target in ‘to’.

to

A pointer to the target end point of the conic arc.

user

A typeless pointer which is passed from the caller of the decomposition function.

return

Error code. 0 means success.


[Index] [TOC]

FT_Outline_CubicToFunc


  typedef int
  (*FT_Outline_CubicToFunc)( const FT_Vector*  control1,
                             const FT_Vector*  control2,
                             const FT_Vector*  to,
                             void*             user );

#define  FT_Outline_CubicTo_Func  FT_Outline_CubicToFunc


A function pointer type used to describe the signature of a ‘cubic to’ function during outline walking/decomposition.

A ‘cubic to’ is emitted to indicate a third-order Bézier arc.


input
control1

A pointer to the first Bézier control point.

control2

A pointer to the second Bézier control point.

to

A pointer to the target end point.

user

A typeless pointer which is passed from the caller of the decomposition function.

return

Error code. 0 means success.


[Index] [TOC]

FT_Outline_Funcs


  typedef struct  FT_Outline_Funcs_
  {
    FT_Outline_MoveToFunc   move_to;
    FT_Outline_LineToFunc   line_to;
    FT_Outline_ConicToFunc  conic_to;
    FT_Outline_CubicToFunc  cubic_to;

    int                     shift;
    FT_Pos                  delta;

  } FT_Outline_Funcs;


A structure to hold various function pointers used during outline decomposition in order to emit segments, conic, and cubic Béziers, as well as ‘move to’ and ‘close to’ operations.


fields
move_to

The ‘move to’ emitter.

line_to

The segment emitter.

conic_to

The second-order Bézier arc emitter.

cubic_to

The third-order Bézier arc emitter.

shift

The shift that is applied to coordinates before they are sent to the emitter.

delta

The delta that is applied to coordinates before they are sent to the emitter, but after the shift.

note

The point coordinates sent to the emitters are the transformed version of the original coordinates (this is important for high accuracy during scan-conversion). The transformation is simple:

  x' = (x << shift) - delta                                        
  y' = (x << shift) - delta                                        

Set the value of ‘shift’ and ‘delta’ to 0 to get the original point coordinates.


[Index] [TOC]

FT_Outline_Decompose


  FT_EXPORT( FT_Error )
  FT_Outline_Decompose( FT_Outline*              outline,
                        const FT_Outline_Funcs*  func_interface,
                        void*                    user );


Walks over an outline's structure to decompose it into individual segments and Bézier arcs. This function is also able to emit ‘move to’ and ‘close to’ operations to indicate the start and end of new contours in the outline.


input
outline

A pointer to the source target.

func_interface

A table of ‘emitters’, i.e,. function pointers called during decomposition to indicate path operations.

inout
user

A typeless pointer which is passed to each emitter during the decomposition. It can be used to store the state during the decomposition.

return

FreeType error code. 0 means sucess.


[Index] [TOC]

FT_Outline_Get_CBox


  FT_EXPORT( void )
  FT_Outline_Get_CBox( const FT_Outline*  outline,
                       FT_BBox           *acbox );


Returns an outline's ‘control box’. The control box encloses all the outline's points, including Bézier control points. Though it coincides with the exact bounding box for most glyphs, it can be slightly larger in some situations (like when rotating an outline which contains Bézier outside arcs).

Computing the control box is very fast, while getting the bounding box can take much more time as it needs to walk over all segments and arcs in the outline. To get the latter, you can use the ‘ftbbox’ component which is dedicated to this single task.


input
outline

A pointer to the source outline descriptor.

output
acbox

The outline's control box.


[Index] [TOC]

FT_Outline_Get_Bitmap


  FT_EXPORT( FT_Error )
  FT_Outline_Get_Bitmap( FT_Library        library,
                         FT_Outline*       outline,
                         const FT_Bitmap  *abitmap );


Renders an outline within a bitmap. The outline's image is simply OR-ed to the target bitmap.


input
library

A handle to a FreeType library object.

outline

A pointer to the source outline descriptor.

inout
abitmap

A pointer to the target bitmap descriptor.

return

FreeType error code. 0 means success.

note

This function does NOT CREATE the bitmap, it only renders an outline image within the one you pass to it!

It will use the raster correponding to the default glyph format.


[Index] [TOC]

FT_Outline_Render


  FT_EXPORT( FT_Error )
  FT_Outline_Render( FT_Library         library,
                     FT_Outline*        outline,
                     FT_Raster_Params*  params );


Renders an outline within a bitmap using the current scan-convert. This functions uses an FT_Raster_Params structure as an argument, allowing advanced features like direct composition, translucency, etc.


input
library

A handle to a FreeType library object.

outline

A pointer to the source outline descriptor.

inout
params

A pointer to an FT_Raster_Params structure used to describe the rendering operation.

return

FreeType error code. 0 means success.

note

You should know what you are doing and how FT_Raster_Params works to use this function.

The field ‘params.source’ will be set to ‘outline’ before the scan converter is called, which means that the value you give to it is actually ignored.


[Index] [TOC]

FT_Orientation


  typedef enum
  {
    FT_ORIENTATION_TRUETYPE   = 0,
    FT_ORIENTATION_POSTSCRIPT = 1,
    FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE,
    FT_ORIENTATION_FILL_LEFT  = FT_ORIENTATION_POSTSCRIPT,
    FT_ORIENTATION_NONE
  
  } FT_Orientation;


A list of values used to describe an outline's contour orientation.

The TrueType and Postscript specifications use different conventions to determine whether outline contours should be filled or unfilled.


values
FT_ORIENTATION_TRUETYPE

According to the TrueType specification, clockwise contours must be filled, and counter-clockwise ones must be unfilled.

FT_ORIENTATION_POSTSCRIPT

According to the Postscript specification, counter-clockwise contours must be filled, and clockwise ones must be unfilled.

FT_ORIENTATION_FILL_RIGHT

This is identical to FT_ORIENTATION_TRUETYPE, but is used to remember that in TrueType, everything that is to the right of the drawing direction of a contour must be filled.

FT_ORIENTATION_FILL_LEFT

This is identical to FT_ORIENTATION_POSTSCRIPT, but is used to remember that in Postscript, everything that is to the left of the drawing direction of a contour must be filled.

FT_ORIENTATION_NONE

The orientation cannot be determined. That is, different parts of the glyph have different orientation.


[Index] [TOC]

FT_Outline_Get_Orientation


  FT_EXPORT( FT_Orientation )
  FT_Outline_Get_Orientation( FT_Outline*  outline );


This function analyzes a glyph outline and tries to compute its fill orientation (see FT_Orientation). This is done by computing the direction of each global horizontal and/or vertical extrema within the outline.

Note that this will return FT_ORIENTATION_TRUETYPE for empty outlines.


input
outline

A handle to the source outline.

return

The orientation.


[Index] [TOC]