NAME
Graphics::Penplotter::GcodeXY::Font - TrueType font rendering for GcodeXY
DESCRIPTION
A Role::Tiny role that adds TrueType font rendering and hatch fill to Graphics::Penplotter::GcodeXY.
Font outlines are obtained via Font::FreeType, converted to SVG path data, and rendered through the standard _dopath machinery. Kerning is applied when the font supports it.
Hatch fill works by scanning the current path with a series of horizontal lines at hatchsep spacing, computing intersections with the path segments using the Liang-Barsky algorithm (provided by the host class as _getsegintersect), and emitting the interior segments as gcode moves.
METHODS
- $face = setfont($filename, $size)
-
Locate, open and size a TrueType font.
$filenamemay be a bare name (searched in the font path), a relative path, or an absolute path.$sizeis in points. Returns a Font::FreeType::Face object, orundefon failure. - setfontsize($size)
-
Set the current font size in points without opening a face.
- $path = findfont($name)
-
Search the font path list for
$name. Returns the full path, or an empty string if not found. - addfontpath(@dirs)
-
Prepend one or more directories to the font search path. Tilde expansion is applied.
- stroketext($face, $string)
-
Render
$stringusing$facewithout fill. The current path is flushed before rendering, and again after each glyph. The drawing position advances by the glyph advance width (with kerning). - stroketextfill($face, $string)
-
As
stroketext, but each glyph is hatch-filled before the path is flushed. - $width = textwidth($face, $string)
-
Return the total advance width of
$stringin the coordinate units of$face, accounting for kerning. - sethatchsep($sep)
-
Set the spacing between hatch lines, in the current drawing units. Default is 0.012 inches (
hatchsepattribute on the object). - strokefill()
-
Hatch-fill the current path, then stroke and clear it.
REQUIRED METHODS
This role requires the consuming class to provide: _croak, _flushPsegments, newpath, stroke, gsave, grestore, translate, _getsegintersect, _addtopage.
AUTHOR
Albert Koelmans (albert.koelmans@googlemail.com)
LICENSE
Same terms as Perl itself.