FreeType » Docs » Support API » Outline Processing
Outline Processing¶
Synopsis¶
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;
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 |
tags |
A pointer to an array of If bit 0 is unset, the point is ‘off’ the curve, i.e., a Bezier control point, while it is ‘on’ if set. Bit 1 is meaningful for ‘off’ points only. If set, it indicates a third-order Bezier 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 |
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 |
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.
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 );
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 |
numPoints |
The maximum number of points within the outline. Must be smaller than or equal to 0xFFFF (65535). |
numContours |
The maximum number of contours within the outline. This value must be in the range 0 to |
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.
FT_Outline_Done¶
Defined in FT_OUTLINE_H (freetype/ftoutln.h).
FT_EXPORT( FT_Error )
FT_Outline_Done( FT_Library library,
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.
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.
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. |
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.
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
.
To get meaningful results, font scaling values must be set with functions like FT_Set_Char_Size
before calling FT_Render_Glyph.
example
FT_Load_Glyph( face, index, FT_LOAD_DEFAULT );
if ( face->glyph->format == FT_GLYPH_FORMAT_OUTLINE )
FT_Outline_Embolden( &face->glyph->outline, strength );
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.
since
2.4.10
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.
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.
note
An empty outline, or an outline with a single point only is also valid.
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 Bezier 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 that contains Bezier 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.
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 that returns very quickly when the two boxes coincide. Otherwise, the outline Bezier 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.
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.
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.
input
library |
A handle to a FreeType library object. |
outline |
A pointer to the source outline descriptor. |
inout
params |
A pointer to an |
return
FreeType error code. 0 means success.
note
This advanced function uses FT_Raster_Params
as an argument. 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. Either params.target
must point to preallocated bitmap, or FT_RASTER_FLAG_DIRECT
must be set in params.flags
allowing FreeType rasterizer to be used for direct composition, translucency, etc. See FT_Raster_Params
for more details.
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 Bezier 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 that 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.
note
A contour that contains a single point only is represented by a ‘move to’ operation followed by ‘line to’ to the same point. In most cases, it is best to filter this out before using the outline for stroking purposes (otherwise it would result in a visible dot when round caps are used).
Similarly, the function returns success for an empty outline also (doing nothing, this is, not calling any emitter); if necessary, you should filter this out, too.
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 Beziers.
fields
move_to |
The ‘move to’ emitter. |
line_to |
The segment emitter. |
conic_to |
The second-order Bezier arc emitter. |
cubic_to |
The third-order Bezier 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' = (y << shift) - delta
Set the values of shift
and delta
to 0 to get the original point coordinates.
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.
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.
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 Bezier arc in the outline.
input
control |
An intermediate control point between the last position and the new target in |
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.
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 Bezier arc.
input
control1 |
A pointer to the first Bezier control point. |
control2 |
A pointer to the second Bezier 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.
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_FILL_LEFT |
This is identical to |
FT_ORIENTATION_NONE |
The orientation cannot be determined. That is, different parts of the glyph have different orientation. |
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 integrating the total area covered by the outline. The positive integral corresponds to the clockwise orientation and FT_ORIENTATION_POSTSCRIPT
is returned. The negative integral corresponds to the counter-clockwise orientation and FT_ORIENTATION_TRUETYPE
is returned.
Note that this will return FT_ORIENTATION_TRUETYPE
for empty outlines.
input
outline |
A handle to the source outline. |
return
The orientation.
FT_OUTLINE_XXX¶
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_OVERLAP 0x40
#define FT_OUTLINE_HIGH_PRECISION 0x100
#define FT_OUTLINE_SINGLE_PASS 0x200
/* these constants are deprecated; use the corresponding */
/* `FT_OUTLINE_XXX` values instead */
#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
A list of bit-field constants used 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., |
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_INCLUDE_STUBS |
If set, turn pixels on for ‘stubs’, otherwise exclude them. Ignored if |
FT_OUTLINE_OVERLAP |
This flag indicates that this outline contains overlapping contrours and the anti-aliased renderer should perform oversampling to mitigate possible artifacts. This flag should not be set for well designed glyphs without overlaps because it quadruples the rendering time. |
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.