Multiple master test font
[imager.git] / lib / Imager / Font.pm
CommitLineData
02d1d628
AMH
1package Imager::Font;
2
3use Imager::Color;
4use strict;
02d1d628 5
faa9b3e7
TC
6# the aim here is that we can:
7# - add file based types in one place: here
8# - make sure we only attempt to create types that exist
9# - give reasonable defaults
10# - give the user some control over which types get used
11my %drivers =
12 (
13 tt=>{
14 class=>'Imager::Font::Truetype',
15 module=>'Imager/Font/Truetype.pm',
16 files=>'.*\.ttf$',
17 },
18 t1=>{
19 class=>'Imager::Font::Type1',
20 module=>'Imager/Font/Type1.pm',
21 files=>'.*\.pfb$',
22 },
23 ft2=>{
24 class=>'Imager::Font::FreeType2',
25 module=>'Imager/Font/FreeType2.pm',
1ae57608 26 files=>'.*\.(pfa|pfb|otf|ttf|fon|fnt|dfont)$',
faa9b3e7 27 },
b4d8a00b
AMH
28 ifs=>{
29 class=>'Imager::Font::Image',
30 module=>'Imager/Font/Image.pm',
31 files=>'.*\.ifs$',
32 },
faa9b3e7
TC
33 w32=>{
34 class=>'Imager::Font::Win32',
35 module=>'Imager/Font/Win32.pm',
36 },
37 );
38
39# this currently should only contain file based types, don't add w32
b4d8a00b 40my @priority = qw(t1 tt ft2 ifs);
faa9b3e7
TC
41
42# when Imager::Font is loaded, Imager.xs has not been bootstrapped yet
43# this function is called from Imager.pm to finish initialization
44sub __init {
45 @priority = grep Imager::i_has_format($_), @priority;
46 delete @drivers{grep !Imager::i_has_format($_), keys %drivers};
47}
02d1d628 48
02d1d628
AMH
49# search method
50# 1. start by checking if file is the parameter
51# 1a. if so qualify path and compare to the cache.
52# 2a. if in cache - take it's id from there and increment count.
53#
54
55sub new {
56 my $class = shift;
b4d8a00b
AMH
57 my $self = {};
58 my ($file, $type, $id);
59 my %hsh=(color => Imager::Color->new(255,0,0,0),
60 size => 15,
02d1d628
AMH
61 @_);
62
63 bless $self,$class;
64
b4d8a00b
AMH
65 if ($hsh{'file'}) {
66 $file = $hsh{'file'};
02d1d628 67 if ( $file !~ m/^\// ) {
b4d8a00b 68 $file = './'.$file;
02d1d628 69 if (! -e $file) {
b4d8a00b 70 $Imager::ERRSTR = "Font $file not found";
02d1d628
AMH
71 return();
72 }
73 }
74
b4d8a00b 75 $type = $hsh{'type'};
faa9b3e7
TC
76 if (!defined($type) or !$drivers{$type}) {
77 for my $drv (@priority) {
78 undef $type;
79 my $re = $drivers{$drv}{files} or next;
80 if ($file =~ /$re/i) {
81 $type = $drv;
82 last;
83 }
84 }
02d1d628
AMH
85 }
86 if (!defined($type)) {
b4d8a00b 87 $Imager::ERRSTR = "Font type not found";
02d1d628
AMH
88 return;
89 }
faa9b3e7
TC
90 } elsif ($hsh{face}) {
91 $type = "w32";
02d1d628
AMH
92 } else {
93 $Imager::ERRSTR="No font file specified";
94 return;
95 }
96
b4d8a00b
AMH
97 if (!$Imager::formats{$type}) {
98 $Imager::ERRSTR = "`$type' not enabled";
02d1d628
AMH
99 return;
100 }
101
102 # here we should have the font type or be dead already.
103
faa9b3e7
TC
104 require $drivers{$type}{module};
105 return $drivers{$type}{class}->new(%hsh);
02d1d628
AMH
106}
107
96190b6e
TC
108# returns first defined parameter
109sub _first {
110 for (@_) {
111 return $_ if defined $_;
112 }
113 return undef;
114}
02d1d628 115
96190b6e
TC
116sub draw {
117 my $self = shift;
9d540150 118 my %input = ('x' => 0, 'y' => 0, @_);
96190b6e
TC
119 unless ($input{image}) {
120 $Imager::ERRSTR = 'No image supplied to $font->draw()';
121 return;
122 }
123 $input{string} = _first($input{string}, $input{text});
124 unless (defined $input{string}) {
3799c4d1 125 $Imager::ERRSTR = "Missing required parameter 'string'";
96190b6e
TC
126 return;
127 }
128 $input{aa} = _first($input{aa}, $input{antialias}, $self->{aa}, 1);
129 # the original draw code worked this out but didn't use it
130 $input{align} = _first($input{align}, $self->{align});
131 $input{color} = _first($input{color}, $self->{color});
3799c4d1
TC
132 $input{color} = Imager::_color($input{'color'});
133
96190b6e
TC
134 $input{size} = _first($input{size}, $self->{size});
135 unless (defined $input{size}) {
136 $input{image}{ERRSTR} = "No font size provided";
137 return undef;
138 }
139 $input{align} = _first($input{align}, 1);
faa9b3e7
TC
140 $input{utf8} = _first($input{utf8}, $self->{utf8}, 0);
141 $input{vlayout} = _first($input{vlayout}, $self->{vlayout}, 0);
142
96190b6e
TC
143 $self->_draw(%input);
144}
02d1d628 145
3799c4d1
TC
146sub align {
147 my $self = shift;
148 my %input = ( halign => 'left', valign => 'baseline',
149 'x' => 0, 'y' => 0, @_ );
150
151 my $text = _first($input{string}, $input{text});
152 unless (defined $text) {
153 Imager->_set_error("Missing required parameter 'string'");
154 return;
155 }
b4d8a00b 156
3799c4d1
TC
157 # image needs to be supplied, but can be supplied as undef
158 unless (exists $input{image}) {
159 Imager->_set_error("Missing required parameter 'image'");
160 return;
161 }
162 my $size = _first($input{size}, $self->{size});
163 my $utf8 = _first($input{utf8}, 0);
b4d8a00b 164
3799c4d1
TC
165 my $bbox = $self->bounding_box(string=>$text, size=>$size, utf8=>$utf8);
166 my $valign = $input{valign};
167 $valign = 'baseline'
168 unless $valign && $valign =~ /^(?:top|center|bottom|baseline)$/;
b4d8a00b 169
3799c4d1
TC
170 my $halign = $input{halign};
171 $halign = 'start'
172 unless $halign && $halign =~ /^(?:left|start|center|end|right)$/;
173
174 my $x = $input{'x'};
175 my $y = $input{'y'};
b4d8a00b 176
3799c4d1
TC
177 if ($valign eq 'top') {
178 $y += $bbox->ascent;
179 }
180 elsif ($valign eq 'center') {
181 $y += $bbox->ascent - $bbox->text_height / 2;
182 }
183 elsif ($valign eq 'bottom') {
184 $y += $bbox->descent;
185 }
186 # else baseline is the default
187
188 if ($halign eq 'left') {
189 $x -= $bbox->start_offset;
190 }
191 elsif ($halign eq 'start') {
192 # nothing to do
193 }
194 elsif ($halign eq 'center') {
195 $x -= $bbox->start_offset + $bbox->total_width / 2;
196 }
197 elsif ($halign eq 'end' || $halign eq 'right') {
198 $x -= $bbox->start_offset + $bbox->total_width - 1;
199 }
200 $x = int($x);
201 $y = int($y);
202
203 if ($input{image}) {
204 delete @input{qw/x y/};
205 $self->draw(%input, 'x' => $x, 'y' => $y, align=>1)
206 or return;
207# for my $i (1 .. length $text) {
208# my $work = substr($text, 0, $i);
209# my $bbox = $self->bounding_box(string=>$work, size=>$size, utf8=>$utf8);
210# my $nx = $x + $bbox->end_offset;
211# $input{image}->setpixel(x=>[ ($nx) x 5 ],
212# 'y'=>[ $y-2, $y-1, $y, $y+1, $y+2 ],
213# color=>'FF0000');
214# }
215 }
216
217 return ($x+$bbox->start_offset, $y-$bbox->ascent,
218 $x+$bbox->end_offset, $y-$bbox->descent+1);
219}
220
02d1d628
AMH
221sub bounding_box {
222 my $self=shift;
223 my %input=@_;
02d1d628 224
96190b6e
TC
225 if (!exists $input{'string'}) {
226 $Imager::ERRSTR='string parameter missing';
227 return;
02d1d628 228 }
96190b6e 229 $input{size} ||= $self->{size};
90654457 230 $input{sizew} = _first($input{sizew}, $self->{sizew}, 0);
fec2a434 231 $input{utf8} = _first($input{utf8}, $self->{utf8}, 0);
96190b6e
TC
232
233 my @box = $self->_bounding_box(%input);
02d1d628 234
3799c4d1
TC
235 if (wantarray) {
236 if(@box && exists $input{'x'} and exists $input{'y'}) {
237 my($gdescent, $gascent)=@box[1,3];
238 $box[1]=$input{'y'}-$gascent; # top = base - ascent (Y is down)
239 $box[3]=$input{'y'}-$gdescent; # bottom = base - descent (Y is down, descent is negative)
240 $box[0]+=$input{'x'};
241 $box[2]+=$input{'x'};
242 } elsif (@box && $input{'canon'}) {
243 $box[3]-=$box[1]; # make it cannoical (ie (0,0) - (width, height))
244 $box[2]-=$box[0];
245 }
246 return @box;
247 }
248 else {
249 require Imager::Font::BBox;
250
251 return Imager::Font::BBox->new(@box);
02d1d628 252 }
02d1d628
AMH
253}
254
faa9b3e7
TC
255sub dpi {
256 my $self = shift;
257
258 # I'm assuming a default of 72 dpi
259 my @old = (72, 72);
260 if (@_) {
261 $Imager::ERRSTR = "Setting dpi not implemented for this font type";
262 return;
263 }
264
265 return @old;
266}
267
268sub transform {
269 my $self = shift;
270
271 my %hsh = @_;
272
273 # this is split into transform() and _transform() so we can
274 # implement other tags like: degrees=>12, which would build a
275 # 12 degree rotation matrix
276 # but I'll do that later
277 unless ($hsh{matrix}) {
278 $Imager::ERRSTR = "You need to supply a matrix";
279 return;
280 }
b4d8a00b 281
faa9b3e7
TC
282 return $self->_transform(%hsh);
283}
284
285sub _transform {
286 $Imager::ERRSTR = "This type of font cannot be transformed";
287 return;
288}
289
290sub utf8 {
291 return 0;
292}
293
294sub priorities {
295 my $self = shift;
296 my @old = @priority;
297
298 if (@_) {
299 @priority = grep Imager::i_has_format($_), @_;
300 }
301 return @old;
302}
303
02d1d628
AMH
3041;
305
02d1d628
AMH
306__END__
307
308=head1 NAME
309
310Imager::Font - Font handling for Imager.
311
312=head1 SYNOPSIS
313
314 $t1font = Imager::Font->new(file => 'pathtofont.pfb');
315 $ttfont = Imager::Font->new(file => 'pathtofont.ttf');
faa9b3e7 316 $w32font = Imager::Font->new(face => 'Times New Roman');
02d1d628
AMH
317
318 $blue = Imager::Color->new("#0000FF");
319 $font = Imager::Font->new(file => 'pathtofont.ttf',
320 color => $blue,
321 size => 30);
322
323 ($neg_width,
324 $global_descent,
325 $pos_width,
326 $global_ascent,
327 $descent,
328 $ascent) = $font->bounding_box(string=>"Foo");
329
330 $logo = $font->logo(text => "Slartibartfast Enterprises",
331 size => 40,
332 border => 5,
333 color => $green);
334 # logo is proposed - doesn't exist yet
335
336
337 $img->string(font => $font,
338 text => "Model-XYZ",
339 x => 15,
340 y => 40,
341 size => 40,
5b0d044f 342 color => $red,
02d1d628
AMH
343 aa => 1);
344
345 # Documentation in Imager.pm
346
347=head1 DESCRIPTION
348
349This module handles creating Font objects used by imager. The module
350also handles querying fonts for sizes and such. If both T1lib and
351freetype were avaliable at the time of compilation then Imager should
352be able to work with both truetype fonts and t1 postscript fonts. To
353check if Imager is t1 or truetype capable you can use something like
354this:
355
356 use Imager;
357 print "Has truetype" if $Imager::formats{tt};
358 print "Has t1 postscript" if $Imager::formats{t1};
faa9b3e7
TC
359 print "Has Win32 fonts" if $Imager::formats{w32};
360 print "Has Freetype2" if $Imager::formats{ft2};
02d1d628
AMH
361
362=over 4
363
364=item new
365
366This creates a font object to pass to functions that take a font argument.
367
368 $font = Imager::Font->new(file => 'denmark.ttf',
1ae57608 369 index => 0,
02d1d628
AMH
370 color => $blue,
371 size => 30,
372 aa => 1);
373
374This creates a font which is the truetype font denmark.ttf. It's
375default color is $blue, default size is 30 pixels and it's rendered
376antialised by default. Imager can see which type of font a file is by
377looking at the suffix of the filename for the font. A suffix of 'ttf'
378is taken to mean a truetype font while a suffix of 'pfb' is taken to
379mean a t1 postscript font. If Imager cannot tell which type a font is
380you can tell it explicitly by using the C<type> parameter:
381
382 $t1font = Imager::Font->new(file => 'fruitcase', type => 't1');
383 $ttfont = Imager::Font->new(file => 'arglebarf', type => 'tt');
384
1ae57608
TC
385The C<index> parameter is used to select a single face from a font
386file containing more than one face, for example, from a Macintosh font
387suitcase or a .dfont file.
388
02d1d628
AMH
389If any of the C<color>, C<size> or C<aa> parameters are omitted when
390calling C<Imager::Font->new()> the they take the following values:
391
02d1d628
AMH
392 color => Imager::Color->new(255, 0, 0, 0); # this default should be changed
393 size => 15
394 aa => 0
1ae57608 395 index => 0
02d1d628 396
faa9b3e7
TC
397To use Win32 fonts supply the facename of the font:
398
399 $font = Imager::Font->new(face=>'Arial Bold Italic');
400
401There isn't any access to other logical font attributes, but this
402typically isn't necessary for Win32 TrueType fonts, since you can
403contruct the full name of the font as above.
404
405Other logical font attributes may be added if there is sufficient demand.
406
02d1d628 407=item bounding_box
faa9b3e7 408
02d1d628
AMH
409Returns the bounding box for the specified string. Example:
410
3799c4d1
TC
411 my ($neg_width,
412 $global_descent,
413 $pos_width,
414 $global_ascent,
415 $descent,
416 $ascent,
417 $advance_width) = $font->bounding_box(string => "A Fool");
418
419 my $bbox_object = $font->bounding_box(string => "A Fool");
420
421=over
422
423=item C<$neg_width>
02d1d628 424
3799c4d1 425the relative start of a the string. In some
02d1d628
AMH
426cases this can be a negative number, in that case the first letter
427stretches to the left of the starting position that is specified in
3799c4d1
TC
428the string method of the Imager class
429
430=item C<$global_descent>
431
432how far down the lowest letter of the entire font reaches below the
433baseline (this is often j).
434
435=item C<$pos_width>
436
437how wide the string from
438the starting position is. The total width of the string is
439C<$pos_width-$neg_width>.
440
441=item C<$descent>
442
443=item C<$ascent>
444
445the same as <$global_descent> and <$global_ascent> except that they
446are only for the characters that appear in the string.
447
448=item C<$advance_width>
449
450the distance from the start point that the next string output should
451start at, this is often the same as C<$pos_width>, but can be
452different if the final character overlaps the right side of its
453character cell.
454
455=back
456
457Obviously we can stuff all the results into an array just as well:
02d1d628
AMH
458
459 @metrics = $font->bounding_box(string => "testing 123");
460
461Note that extra values may be added, so $metrics[-1] isn't supported.
462It's possible to translate the output by a passing coordinate to the
463bounding box method:
464
465 @metrics = $font->bounding_box(string => "testing 123", x=>45, y=>34);
466
467This gives the bounding box as if the string had been put down at C<(x,y)>
468By giving bounding_box 'canon' as a true value it's possible to measure
469the space needed for the string:
470
471 @metrics = $font->bounding_box(string=>"testing",size=>15,canon=>1);
472
473This returns tha same values in $metrics[0] and $metrics[1],
474but:
475
476 $bbox[2] - horizontal space taken by glyphs
477 $bbox[3] - vertical space taken by glyphs
478
3799c4d1
TC
479Returns an L<Imager::Font::BBox> object in scalar context, so you can
480avoid all those confusing indices. This has methods as named above,
481with some extra convenience methods.
02d1d628
AMH
482
483=item string
484
485This is a method of the Imager class but because it's described in
486here since it belongs to the font routines. Example:
487
488 $img=Imager->new();
5b0d044f 489 $img->read(file=>"test.jpg");
02d1d628
AMH
490 $img->string(font=>$t1font,
491 text=>"Model-XYZ",
492 x=>0,
493 y=>40,
494 size=>40,
495 color=>$red);
496 $img->write(file=>"testout.jpg");
497
498This would put a 40 pixel high text in the top left corner of an
499image. If you measure the actuall pixels it varies since the fonts
500usually do not use their full height. It seems that the color and
501size can be specified twice. When a font is created only the actual
502font specified matters. It his however convenient to store default
503values in a font, such as color and size. If parameters are passed to
504the string function they are used instead of the defaults stored in
505the font.
506
faa9b3e7
TC
507The following parameters can be supplied to the string() method:
508
509=over
510
511=item string
512
513The text to be rendered. If this isn't present the 'text' parameter
514is used. If neither is present the call will fail.
515
516=item aa
517
518If non-zero the output will be anti-aliased.
519
520=item x
521
522=item y
523
524The start point for rendering the text. See the align parameter.
525
526=item align
527
528If non-zero the point supplied in (x,y) will be on the base-line, if
529zero then (x,y) will be at the top-left of the first character.
530
531=item channel
532
533If present, the text will be written to the specified channel of the
534image and the color parameter will be ignore.
535
536=item color
537
538The color to draw the text in.
539
540=item size
541
542The point-size to draw the text at.
543
544=item sizew
545
546For drivers that support it, the width to draw the text at. Defaults
547to be value of the 'size' parameter.
548
549=item utf8
550
551For drivers that support it, treat the string as UTF8 encoded. For
552versions of perl that support Unicode (5.6 and later), this will be
553enabled automatically if the 'string' parameter is already a UTF8
554string. See L<UTF8> for more information.
555
556=item vlayout
557
558For drivers that support it, draw the text vertically. Note: I
559haven't found a font that has the appropriate metrics yet.
560
561=back
562
02d1d628
AMH
563If string() is called with the C<channel> parameter then the color
564isn't used and the font is drawn in only one channel of the image.
565This can be quite handy to create overlays. See the examples for tips
566about this.
567
568Sometimes it is necessary to know how much space a string takes before
569rendering it. The bounding_box() method described earlier can be used
570for that.
571
3799c4d1
TC
572=item align(string=>$text, size=>$size, x=>..., y=>..., valign => ..., halign=>...)
573
574Higher level text output - outputs the text aligned as specified
575around the given point (x,y).
576
577 # "Hello" centered at 100, 100 in the image.
578 my ($left, $top, $bottom, $right) =
579 $font->align(string=>"Hello",
580 x=>100, y=>100,
581 halign=>'center', valign=>'center',
582 image=>$image);
583
584Takes the same parameters as $font->draw(), and the following extra
585parameters:
586
587=over
588
589=item valign
590
591Possible values are:
592
593=over
594
595=item top
596
597Point is at the top of the text.
598
599=item bottom
600
601Point is at the bottom of the text.
602
603=item baseline
604
605Point is on the baseline of the text (default.)
606
607=item center
608
609Point is vertically centered within the text.
610
611=back
612
613=item halign
614
615=over
616
617=item left
618
619The point is at the left of the text.
620
621=item start
622
623The point is at the start point of the text.
624
625=item center
626
627The point is horizontally centered within the text.
628
629=item right
630
631The point is at the right end of the text.
632
633=item end
634
635The point is at the right end of the text. This will change to the
636end point of the text (once the proper bounding box interfaces are
637available).
638
639=back
640
641=item image
642
643The image to draw to. Set to C<undef> to avoid drawing but still
644calculate the bounding box.
645
646=back
647
648Returns a list specifying the bounds of the drawn text.
649
faa9b3e7
TC
650=item dpi()
651
652=item dpi(xdpi=>$xdpi, ydpi=>$ydpi)
653
654=item dpi(dpi=>$dpi)
655
656Set retrieve the spatial resolution of the image in dots per inch.
657The default is 72 dpi.
658
659This isn't implemented for all font types yet.
660
661=item transform(matrix=>$matrix)
662
663Applies a transformation to the font, where matrix is an array ref of
664numbers representing a 2 x 3 matrix:
665
666 [ $matrix->[0], $matrix->[1], $matrix->[2],
667 $matrix->[3], $matrix->[4], $matrix->[5] ]
668
669Not all font types support transformations, these will return false.
670
671It's possible that a driver will disable hinting if you use a
672transformation, to prevent discontinuities in the transformations.
673See the end of the test script t/t38ft2font.t for an example.
02d1d628 674
a53f48bb
TC
675Currently only the ft2 (Freetype 2.x) driver supports the transform()
676method.
677
3dec2c92
TC
678=item has_chars(string=>$text)
679
680Checks if the characters in $text are defined by the font.
681
682In a list context returns a list of true or false value corresponding
683to the characters in $text, true if the character is defined, false if
684not. In scalar context returns a string of NUL or non-NUL
10461f9a 685characters. Supports UTF8 where the font driver supports UTF8.
3dec2c92
TC
686
687Not all fonts support this method (use $font->can("has_chars") to
688check.)
689
02d1d628
AMH
690=item logo
691
692This method doesn't exist yet but is under consideration. It would mostly
693be helpful for generating small tests and such. Its proposed interface is:
694
695 $img = $font->logo(string=>"Plan XYZ", color=>$blue, border=>7);
696
697This would be nice for writing (admittedly multiline) one liners like:
698
699Imager::Font->new(file=>"arial.ttf", color=>$blue, aa=>1)
700 ->string(text=>"Plan XYZ", border=>5)
701 ->write(file=>"xyz.png");
702
3799c4d1
TC
703=item face_name()
704
705Returns the internal name of the face. Not all font types support
706this method yet.
707
a4168bea 708=item glyph_names(string=>$string [, utf8=>$utf8 ][, reliable_only=>0 ] );
3799c4d1
TC
709
710Returns a list of glyph names for each of the characters in the
711string. If the character has no name then C<undef> is returned for
712the character.
713
714Some font files do not include glyph names, in this case Freetype 2
715will not return any names. Freetype 1 can return standard names even
716if there are no glyph names in the font.
717
a4168bea
TC
718Freetype 2 has an API function that returns true only if the font has
719"reliable glyph names", unfortunately this always returns false for
720TTF fonts. This can avoid the check of this API by supplying
721C<reliable_only> as 0. The consequences of using this on an unknown
722font may be unpredictable, since the Freetype documentation doesn't
723say how those name tables are unreliable, or how FT2 handles them.
724
3799c4d1
TC
725Both Freetype 1.x and 2.x allow support for glyph names to not be
726included.
727
faa9b3e7
TC
728=back
729
730=head1 UTF8
731
732There are 2 ways of rendering Unicode characters with Imager:
02d1d628 733
faa9b3e7
TC
734=over
735
736=item *
737
738For versions of perl that support it, use perl's native UTF8 strings.
739This is the simplest method.
740
741=item *
742
743Hand build your own UTF8 encoded strings. Only recommended if your
744version of perl has no UTF8 support.
02d1d628
AMH
745
746=back
747
faa9b3e7
TC
748Imager won't construct characters for you, so if want to output
749unicode character 00C3 "LATIN CAPITAL LETTER A WITH DIAERESIS", and
750your font doesn't support it, Imager will I<not> build it from 0041
751"LATIN CAPITAL LETTER A" and 0308 "COMBINING DIAERESIS".
752
753=head2 Native UTF8 Support
754
755If your version of perl supports UTF8 and the driver supports UTF8,
756just use the $im->string() method, and it should do the right thing.
757
758=head2 Build your own
759
760In this case you need to build your own UTF8 encoded characters.
761
762For example:
763
764 $x = pack("C*", 0xE2, 0x80, 0x90); # character code 0x2010 HYPHEN
765
766You need to be be careful with versions of perl that have UTF8
767support, since your string may end up doubly UTF8 encoded.
768
769For example:
770
771 $x = "A\xE2\x80\x90\x41\x{2010}";
772 substr($x, -1, 0) = "";
773 # at this point $x is has the UTF8 flag set, but has 5 characters,
774 # none, of which is the constructed UTF8 character
775
776The test script t/t38ft2font.t has a small example of this after the
777comment:
778
779 # an attempt using emulation of UTF8
780
781=head1 DRIVER CONTROL
782
783If you don't supply a 'type' parameter to Imager::Font->new(), but you
784do supply a 'file' parameter, Imager will attempt to guess which font
785driver to used based on the extension of the font file.
786
787Since some formats can be handled by more than one driver, a priority
788list is used to choose which one should be used, if a given format can
789be handled by more than one driver.
790
791The current priority can be retrieved with:
792
793 @drivers = Imager::Font->priorities();
794
795You can set new priorities and save the old priorities with:
796
797 @old = Imager::Font->priorities(@drivers);
798
799If you supply driver names that are not currently supported, they will
800be ignored.
801
802Imager supports both T1Lib and Freetype2 for working with Type 1
803fonts, but currently only T1Lib does any caching, so by default T1Lib
804is given a higher priority. Since Imager's Freetype2 support can also
805do font transformations, you may want to give that a higher priority:
806
807 my @old = Imager::Font->priorities(qw(tt ft2 t1));
808
02d1d628
AMH
809=head1 AUTHOR
810
811Arnar M. Hrafnkelsson, addi@umich.edu
812And a great deal of help from others - see the README for a complete
813list.
814
96190b6e
TC
815=head1 BUGS
816
817You need to modify this class to add new font types.
818
02d1d628
AMH
819=head1 SEE ALSO
820
412e7a35 821Imager(3), Imager::Font::FreeType2(3), Imager::Font::Type1(3),
3799c4d1 822Imager::Font::Win32(3), Imager::Font::Truetype(3), Imager::Font::BBox(3)
412e7a35 823
8f22b8d8 824 http://imager.perl.org/
02d1d628
AMH
825
826=cut
827
828