.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Font::FreeType 3pm" .TH Font::FreeType 3pm "2018-12-21" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Font::FreeType \- read font files and render glyphs from Perl using FreeType2 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Font::FreeType; \& \& my $freetype = Font::FreeType\->new; \& my $face = $freetype\->face(\*(AqVera.ttf\*(Aq); \& \& $face\->set_char_size(24, 24, 100, 100); \& my $glyph = $face\->glyph_from_char(\*(AqA\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module allows Perl programs to conveniently read information from font files. All the font access is done through the FreeType2 library, which supports many formats. It can render images of characters with high-quality hinting and antialiasing, extract metrics information, and extract the outlines of characters in scalable formats like TrueType. .PP Warning: this module is currently in 'beta' stage. It'll be another release or two before it stabilizes. The \s-1API\s0 may change in ways that break programs based on it, but I don't think it will change much. Some of the values returned may be wrong, or not scaled correctly. See the \fI\s-1TODO\s0\fR file to get a handle on how far along this work is. Contributions welcome, particularly if you know more than I do (which isn't much) about fonts and the FreeType2 library. .PP The Font::FreeType \s-1API\s0 is not intended to replicate the C \s-1API\s0 of the FreeType library \*(-- it offers a much more Perl-friendly interface. .PP The quickest way to get started with this library is to look at the examples in the \fIexamples\fR directory of the distribution. Full details of the \s-1API\s0 are contained in this documentation, and (more importantly) the documentation for the Font::FreeType::Face and Font::FreeType::Glyph classes. .PP To use the library, first create a Font::FreeType object. This can be used to load \fBfaces\fR from files, for example: .PP .Vb 2 \& my $freetype = Font::FreeType\->new; \& my $face = $freetype\->face(\*(AqVera.ttf\*(Aq); .Ve .PP If your font is scalable (i.e., not a bitmapped font) then set the size and resolution you want to see it at, for example 24pt at 100dpi: .PP .Vb 1 \& $face\->set_char_size(24, 24, 100, 100); .Ve .PP Then load a particular glyph (an image of a character), either by character code (in Unicode) or the actual character: .PP .Vb 2 \& my $glyph = $face\->glyph_from_char_code(65); \& my $glyph = $face\->glyph_from_char(\*(AqA\*(Aq); .Ve .PP Glyphs can be rendered to bitmap images, among other things: .PP .Vb 1 \& my $bitmap = $glyph\->bitmap; .Ve .PP See the documentation for Font::FreeType::Glyph for details of the format of the bitmap array reference that returns, and for other ways to get information about a glyph. .SH "METHODS" .IX Header "METHODS" Unless otherwise stated, all methods will die if there is an error. .IP "\fBnew()\fR" 4 .IX Item "new()" Create a new 'instance' of the freetype library and return the object. This is a class method, which doesn't take any arguments. If you only want to load one face, then it's probably not even worth saving the object to a variable: .Sp .Vb 1 \& my $face = Font::FreeType\->new\->face(\*(AqVera.ttf\*(Aq); .Ve .IP "face(\fIfilename\fR, \fI\f(CI%options\fI\fR)" 4 .IX Item "face(filename, %options)" Return a Font::FreeType::Face object representing a font face from the specified file. .Sp The \f(CW\*(C`index\*(C'\fR option specifies which face to load from the file. It defaults to 0, and since most fonts only contain one face it rarely needs to be provided. .Sp The \f(CW\*(C`load_flags\*(C'\fR option takes various flags which alter the way glyphs are loaded. The default is usually \s-1OK\s0 for rendering fonts to bitmap images. When extracting outlines from fonts, be sure to set the \s-1FT_LOAD_NO_HINTING\s0 flag. .Sp The following load flags are available. They can be combined with the bitwise \s-1OR\s0 operator (\f(CW\*(C`|\*(C'\fR). The symbols are exported by the module and so will be available once you do \f(CW\*(C`use Font::FreeType\*(C'\fR. .RS 4 .IP "\s-1FT_LOAD_DEFAULT\s0" 4 .IX Item "FT_LOAD_DEFAULT" The same as doing nothing special. .IP "\s-1FT_LOAD_COMPUTE_METRICS\s0" 4 .IX Item "FT_LOAD_COMPUTE_METRICS" Compute glyph metrics from the glyph data, without the use of bundled metrics tables (for example, the 'hdmx' table in TrueType fonts). This flag is mainly used by font validating or font editing applications, which need to ignore, verify, or edit those tables. .Sp This option is only available with FreeType 2.6.1 or newer. .IP "\s-1FT_LOAD_CROP_BITMAP\s0" 4 .IX Item "FT_LOAD_CROP_BITMAP" Remove extraneous black bits round the edges of bitmaps when loading embedded bitmaps. .IP "\s-1FT_LOAD_FORCE_AUTOHINT\s0" 4 .IX Item "FT_LOAD_FORCE_AUTOHINT" Use FreeType's own automatic hinting algorithm rather than the normal TrueType one. Probably only useful for testing the FreeType library. .IP "\s-1FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH\s0" 4 .IX Item "FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH" Probably only useful for loading fonts with wrong metrics. .IP "\s-1FT_LOAD_IGNORE_TRANSFORM\s0" 4 .IX Item "FT_LOAD_IGNORE_TRANSFORM" Don't transform glyphs. This module doesn't yet have support for transformations. .IP "\s-1FT_LOAD_LINEAR_DESIGN\s0" 4 .IX Item "FT_LOAD_LINEAR_DESIGN" Don't scale the metrics. .IP "\s-1FT_LOAD_NO_AUTOHINT\s0" 4 .IX Item "FT_LOAD_NO_AUTOHINT" Don't use the FreeType autohinting algorithm. Hinting with other algorithms (such as the TrueType one) will still be done if possible. Apparently some fonts look worse with the autohinter than without any hinting. .Sp This option is only available with FreeType 2.1.3 or newer. .IP "\s-1FT_LOAD_NO_BITMAP\s0" 4 .IX Item "FT_LOAD_NO_BITMAP" Don't load embedded bitmaps provided with scalable fonts. Bitmap fonts are still loaded normally. This probably doesn't make much difference in the current version of this module, as embedded bitmaps aren't deliberately used. .IP "\s-1FT_LOAD_NO_HINTING\s0" 4 .IX Item "FT_LOAD_NO_HINTING" Prevents the coordinates of the outline from being adjusted ('grid fitted') to the current size. Hinting should be turned on when rendering bitmap images of glyphs, and off when extracting the outline information if you don't know at what resolution it will be rendered. For example, when converting glyphs to PostScript or \s-1PDF,\s0 use this to turn the hinting off. .IP "\s-1FT_LOAD_NO_SCALE\s0" 4 .IX Item "FT_LOAD_NO_SCALE" Don't scale the font's outline or metrics to the right size. This will currently generate bad numbers. To be fixed in a later version. .IP "\s-1FT_LOAD_PEDANTIC\s0" 4 .IX Item "FT_LOAD_PEDANTIC" Raise errors when a font file is broken, rather than trying to work around it. .IP "\s-1FT_LOAD_VERTICAL_LAYOUT\s0" 4 .IX Item "FT_LOAD_VERTICAL_LAYOUT" Return metrics and glyphs suitable for vertical layout. This module doesn't yet provide any intentional support for vertical layout, so this probably won't be much use. .RE .RS 4 .RE .IP "\fBversion()\fR" 4 .IX Item "version()" Returns the version number of the underlying FreeType library being used. If called in scalar context returns a string containing three numbers in the format \*(L"major.minor.patch\*(R". In list context returns the three numbers as separate values. .SH "SEE ALSO" .IX Header "SEE ALSO" Font::FreeType::Face, Font::FreeType::Glyph .SH "AUTHOR" .IX Header "AUTHOR" Geoff Richards .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2004, Geoff Richards. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.