Stroker

class freetype.Stroker

FT_Stroker wrapper

This component generates stroked outlines of a given vectorial glyph. It also allows you to retrieve the ‘outside’ and/or the ‘inside’ borders of the stroke.

This can be useful to generate ‘bordered’ glyph, i.e., glyphs displayed with a coloured (and anti-aliased) border around their shape.

begin_subpath(to, _open)

Start a new sub-path in the stroker.

:param to A pointer to the start vector.

Parameters:_open – A boolean. If 1, the sub-path is treated as an open one.

Note:

This function is useful when you need to stroke a path that is not stored as an ‘Outline’ object.
conic_to(control, to)

‘Draw’ a single quadratic Bezier in the stroker’s current sub-path, from the last position.

Parameters:
  • control – A pointer to a Bezier control point.
  • to – A pointer to the destination point.

Note:

You should call this function between ‘begin_subpath’ and ‘end_subpath’.
cubic_to(control1, control2, to)

‘Draw’ a single quadratic Bezier in the stroker’s current sub-path, from the last position.

Parameters:
  • control1 – A pointer to the first Bezier control point.
  • control2 – A pointer to second Bezier control point.
  • to – A pointer to the destination point.

Note:

You should call this function between ‘begin_subpath’ and ‘end_subpath’.
end_subpath()

Close the current sub-path in the stroker.

Note:

You should call this function after ‘begin_subpath’. If the subpath was not ‘opened’, this function ‘draws’ a single line segment to the start position when needed.
export(outline)

Call this function after get_border_counts to export all borders to your own ‘Outline’ structure.

Note that this function appends the border points and contours to your outline, but does not try to resize its arrays.

Parameters:outline – The target outline.
export_border(border, outline)

Call this function after ‘get_border_counts’ to export the corresponding border to your own ‘Outline’ structure.

Note that this function appends the border points and contours to your outline, but does not try to resize its arrays.

Parameters:
  • border – The border index.
  • outline – The target outline.

Note:

Always call this function after get_border_counts to get sure that there is enough room in your ‘Outline’ object to receive all new data.

When an outline, or a sub-path, is ‘closed’, the stroker generates two independent ‘border’ outlines, named ‘left’ and ‘right’

When the outline, or a sub-path, is ‘opened’, the stroker merges the ‘border’ outlines with caps. The ‘left’ border receives all points, while the ‘right’ border becomes empty.

Use the function export instead if you want to retrieve all borders at once.

get_border_counts(border)

Call this function once you have finished parsing your paths with the stroker. It returns the number of points and contours necessary to export one of the ‘border’ or ‘stroke’ outlines generated by the stroker.

Parameters:border – The border index.
Returns:number of points, number of contours
get_counts()

Call this function once you have finished parsing your paths with the stroker. It returns the number of points and contours necessary to export all points/borders from the stroked outline/path.

Returns:number of points, number of contours
line_to(to)

‘Draw’ a single line segment in the stroker’s current sub-path, from the last position.

Parameters:to – A pointer to the destination point.

Note:

You should call this function between ‘begin_subpath’ and ‘end_subpath’.
parse_outline(outline, opened)

A convenience function used to parse a whole outline with the stroker. The resulting outline(s) can be retrieved later by functions like FT_Stroker_GetCounts and FT_Stroker_Export.

Parameters:outline – The source outline.
Pram opened:A boolean. If 1, the outline is treated as an open path instead of a closed one.

Note:

If ‘opened’ is 0 (the default), the outline is treated as a closed path, and the stroker generates two distinct ‘border’ outlines.

If ‘opened’ is 1, the outline is processed as an open path, and the stroker generates a single ‘stroke’ outline.

This function calls ‘rewind’ automatically.

rewind()

Reset a stroker object without changing its attributes. You should call this function before beginning a new series of calls to FT_Stroker_BeginSubPath or FT_Stroker_EndSubPath.

set(radius, line_cap, line_join, miter_limit)

Reset a stroker object’s attributes.

Parameters:
  • radius – The border radius.
  • line_cap – The line cap style.
  • line_join – The line join style.
  • miter_limit – The miter limit for the FT_STROKER_LINEJOIN_MITER style, expressed as 16.16 fixed point value.

Note:

The radius is expressed in the same units as the outline coordinates.