[Index] [TOC]

FreeType-2.4.10 API Reference

Outline Processing

Synopsis

FT_Outlineft_outline_flags
FT_OUTLINE_FLAGSFT_Outline_MoveToFunc
FT_Outline_NewFT_Outline_LineToFunc
FT_Outline_DoneFT_Outline_ConicToFunc
FT_Outline_CopyFT_Outline_CubicToFunc
FT_Outline_TranslateFT_Outline_Funcs
FT_Outline_TransformFT_Outline_Decompose
FT_Outline_EmboldenFT_Outline_Get_CBox
FT_Outline_EmboldenXYFT_Outline_Get_Bitmap
FT_Outline_ReverseFT_Outline_Render
FT_Outline_CheckFT_Orientation
FT_Outline_Get_BBoxFT_Outline_Get_Orientation


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

Defined in FT_IMAGE_H (freetype/ftimage.h).


  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;

  /* Following limits must be consistent with */
  /* FT_Outline.{n_contours,n_points}         */
#define FT_OUTLINE_CONTOURS_MAX  SHRT_MAX
#define FT_OUTLINE_POINTS_MAX    SHRT_MAX


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’ if 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.

If bit 2 is set, bits 5-7 contain the drop-out mode (as defined in the OpenType specification; the value is the same as the argument to the SCANMODE instruction).

Bits 3 and 4 are reserved for internal purposes.

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.

note

The B/W rasterizer only checks bit 2 in the ‘tags’ array for the first point of each contour. The drop-out mode as given with FT_OUTLINE_IGNORE_DROPOUTS, FT_OUTLINE_SMART_DROPOUTS, and FT_OUTLINE_INCLUDE_STUBS in ‘flags’ is then overridden.


[Index] [TOC]

FT_OUTLINE_FLAGS

Defined in FT_IMAGE_H (freetype/ftimage.h).


#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_SMART_DROPOUTS   0x10
#define FT_OUTLINE_INCLUDE_STUBS    0x20

#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’, and ‘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 rasterizer).

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.

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. See below for more information.

FT_OUTLINE_SMART_DROPOUTS

Select smart dropout control. If unset, use simple dropout control. Ignored if FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more information.

FT_OUTLINE_INCLUDE_STUBS

If set, turn pixels on for ‘stubs’, otherwise exclude them. Ignored if FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more information.

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.

note

The flags FT_OUTLINE_IGNORE_DROPOUTS, FT_OUTLINE_SMART_DROPOUTS, and FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth rasterizer.

There exists a second mechanism to pass the drop-out mode to the B/W rasterizer; see the ‘tags’ field in FT_Outline.

Please refer to the description of the ‘SCANTYPE’ instruction in the OpenType specification (in file ‘ttinst1.doc’) how simple drop-outs, smart drop-outs, and stubs are defined.


[Index] [TOC]

FT_Outline_New

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  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 );


Create 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 maximum number of points within the outline.

numContours

The maximum number of contours within the outline.

output

anoutline

A handle to the new outline.

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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  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 );


Destroy 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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Copy 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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Apply 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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Apply 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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Embolden 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.

If you need ‘better’ metrics values you should call FT_Outline_Get_CBox or FT_Outline_Get_BBox.

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_EmboldenXY

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  FT_EXPORT( FT_Error )
  FT_Outline_EmboldenXY( FT_Outline*  outline,
                         FT_Pos       xstrength,
                         FT_Pos       ystrength );


Embolden an outline. The new outline will be ‘xstrength’ pixels wider and ‘ystrength’ pixels higher. Otherwise, it is similar to FT_Outline_Embolden, which uses the same strength in both directions.



[Index] [TOC]

FT_Outline_Reverse

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  FT_EXPORT( void )
  FT_Outline_Reverse( FT_Outline*  outline );


Reverse 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 function 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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  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

Defined in FT_BBOX_H (freetype/ftbbox.h).


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


Compute 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 traversed 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.

note

If the font is tricky and the glyph has been loaded with FT_LOAD_NO_SCALE, the resulting BBox is meaningless. To get reasonable values for the BBox it is necessary to load the glyph at a large ppem value (so that the hinting instructions can properly shift and scale the subglyphs), then extracting the BBox which can be eventually converted back to font units.


[Index] [TOC]

ft_outline_flags

Defined in FT_IMAGE_H (freetype/ftimage.h).


#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

Defined in FT_IMAGE_H (freetype/ftimage.h).


  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

Defined in FT_IMAGE_H (freetype/ftimage.h).


  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

Defined in FT_IMAGE_H (freetype/ftimage.h).


  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 used to describe the signature of a ‘conic to’ function during outline walking or 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

Defined in FT_IMAGE_H (freetype/ftimage.h).


  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 or 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

Defined in FT_IMAGE_H (freetype/ftimage.h).


  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.


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 values of ‘shift’ and ‘delta’ to 0 to get the original point coordinates.


[Index] [TOC]

FT_Outline_Decompose

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Walk over an outline's structure to decompose it into individual segments and Bézier arcs. This function also emits ‘move to’ operations to indicate the start 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 success.


[Index] [TOC]

FT_Outline_Get_CBox

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Return 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.

note

See FT_Glyph_Get_CBox for a discussion of tricky fonts.


[Index] [TOC]

FT_Outline_Get_Bitmap

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Render 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! Consequently, the various fields in ‘abitmap’ should be set accordingly.

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

The value of the ‘num_grays’ field in ‘abitmap’ is ignored. If you select the gray-level rasterizer, and you want less than 256 gray levels, you have to use FT_Outline_Render directly.


[Index] [TOC]

FT_Outline_Render

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


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


Render an outline within a bitmap using the current scan-convert. This function 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.

The gray-level rasterizer always uses 256 gray levels. If you want less gray levels, you have to provide your own span callback. See the FT_RASTER_FLAG_DIRECT value of the ‘flags’ field in the FT_Raster_Params structure for more details.


[Index] [TOC]

FT_Orientation

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  typedef enum  FT_Orientation_
  {
    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

Defined in FT_OUTLINE_H (freetype/ftoutln.h).


  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]