]> git.imager.perl.org - imager.git/blob - lib/Imager/Font.pm
c806a25cfc983b2e9e3a75edccb6de2c40539023
[imager.git] / lib / Imager / Font.pm
1 package Imager::Font;
2
3 use Imager::Color;
4 use strict;
5
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
11 my %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',
26          files=>'.*\.(pfa|pfb|otf|ttf|fon|fnt|dfont|pcf(\.gz)?)$',
27         },
28    ifs=>{
29          class=>'Imager::Font::Image',
30          module=>'Imager/Font/Image.pm',
31          files=>'.*\.ifs$',
32         },
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
40 my @priority = qw(t1 tt ft2 ifs);
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
44 sub __init {
45   @priority = grep Imager::i_has_format($_), @priority;
46   delete @drivers{grep !Imager::i_has_format($_), keys %drivers};
47 }
48
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
55 sub new {
56   my $class = shift;
57   my $self = {};
58   my ($file, $type, $id);
59   my %hsh=(color => Imager::Color->new(255,0,0,0),
60            size => 15,
61            @_);
62
63   bless $self,$class;
64
65   if ($hsh{'file'}) {
66     $file = $hsh{'file'};
67     if ( $file !~ m/^\// ) {
68       $file = './'.$file;
69       if (! -e $file) {
70         $Imager::ERRSTR = "Font $file not found";
71         return();
72       }
73     }
74
75     $type = $hsh{'type'};
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       }
85     }
86     if (!defined($type)) {
87       $Imager::ERRSTR = "Font type not found";
88       return;
89     }
90   } elsif ($hsh{face}) {
91     $type = "w32";
92   } else {
93     $Imager::ERRSTR="No font file specified";
94     return;
95   }
96
97   if (!$Imager::formats{$type}) {
98     $Imager::ERRSTR = "`$type' not enabled";
99     return;
100   }
101
102   # here we should have the font type or be dead already.
103
104   require $drivers{$type}{module};
105   return $drivers{$type}{class}->new(%hsh);
106 }
107
108 # returns first defined parameter
109 sub _first {
110   for (@_) {
111     return $_ if defined $_;
112   }
113   return undef;
114 }
115
116 sub draw {
117   my $self = shift;
118   my %input = ('x' => 0, 'y' => 0, @_);
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}) {
125     $Imager::ERRSTR = "Missing required parameter 'string'";
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});
132   $input{color} = Imager::_color($input{'color'});
133
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);
140   $input{utf8} = _first($input{utf8}, $self->{utf8}, 0);
141   $input{vlayout} = _first($input{vlayout}, $self->{vlayout}, 0);
142
143   $self->_draw(%input);
144 }
145
146 sub 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   }
156
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);
164
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)$/;
169
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'};
176
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
221 sub bounding_box {
222   my $self=shift;
223   my %input=@_;
224
225   if (!exists $input{'string'}) { 
226     $Imager::ERRSTR='string parameter missing'; 
227     return;
228   }
229   $input{size} ||= $self->{size};
230   $input{sizew} = _first($input{sizew}, $self->{sizew}, 0);
231   $input{utf8} = _first($input{utf8}, $self->{utf8}, 0);
232
233   my @box = $self->_bounding_box(%input);
234
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);
252   }
253 }
254
255 sub 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
268 sub 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   }
281
282   return $self->_transform(%hsh);
283 }
284
285 sub _transform {
286   $Imager::ERRSTR = "This type of font cannot be transformed";
287   return;
288 }
289
290 sub utf8 {
291   return 0;
292 }
293
294 sub 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
304 1;
305
306 __END__
307
308 =head1 NAME
309
310 Imager::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');
316   $w32font = Imager::Font->new(face => 'Times New Roman');
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,
329    $advance_width,
330    $right_bearing) = $font->bounding_box(string=>"Foo");
331
332   $logo = $font->logo(text   => "Slartibartfast Enterprises",
333                       size   => 40,
334                       border => 5,
335                       color  => $green);
336   # logo is proposed - doesn't exist yet
337
338
339   $img->string(font  => $font,
340              text  => "Model-XYZ",
341              x     => 15,
342              y     => 40,
343              size  => 40,
344              color => $red,
345              aa    => 1);
346
347   # Documentation in Imager.pm
348
349 =head1 DESCRIPTION
350
351 This module handles creating Font objects used by imager.  The module
352 also handles querying fonts for sizes and such.  If both T1lib and
353 freetype were avaliable at the time of compilation then Imager should
354 be able to work with both truetype fonts and t1 postscript fonts.  To
355 check if Imager is t1 or truetype capable you can use something like
356 this:
357
358   use Imager;
359   print "Has truetype"      if $Imager::formats{tt};
360   print "Has t1 postscript" if $Imager::formats{t1};
361   print "Has Win32 fonts"   if $Imager::formats{w32};
362   print "Has Freetype2"     if $Imager::formats{ft2};
363
364 =over 4
365
366 =item new
367
368 This creates a font object to pass to functions that take a font argument.
369
370   $font = Imager::Font->new(file  => 'denmark.ttf',
371                             index => 0,
372                             color => $blue,
373                             size  => 30,
374                             aa    => 1);
375
376 This creates a font which is the truetype font denmark.ttf.  It's
377 default color is $blue, default size is 30 pixels and it's rendered
378 antialised by default.  Imager can see which type of font a file is by
379 looking at the suffix of the filename for the font.  A suffix of 'ttf'
380 is taken to mean a truetype font while a suffix of 'pfb' is taken to
381 mean a t1 postscript font.  If Imager cannot tell which type a font is
382 you can tell it explicitly by using the C<type> parameter:
383
384   $t1font = Imager::Font->new(file => 'fruitcase', type => 't1');
385   $ttfont = Imager::Font->new(file => 'arglebarf', type => 'tt');
386
387 The C<index> parameter is used to select a single face from a font
388 file containing more than one face, for example, from a Macintosh font
389 suitcase or a .dfont file.
390
391 If any of the C<color>, C<size> or C<aa> parameters are omitted when
392 calling C<Imager::Font->new()> the they take the following values:
393
394   color => Imager::Color->new(255, 0, 0, 0);  # this default should be changed
395   size  => 15
396   aa    => 0
397   index => 0
398
399 To use Win32 fonts supply the facename of the font:
400
401   $font = Imager::Font->new(face=>'Arial Bold Italic');
402
403 There isn't any access to other logical font attributes, but this
404 typically isn't necessary for Win32 TrueType fonts, since you can
405 contruct the full name of the font as above.
406
407 Other logical font attributes may be added if there is sufficient demand.
408
409 =item bounding_box
410
411 Returns the bounding box for the specified string.  Example:
412
413   my ($neg_width,
414       $global_descent,
415       $pos_width,
416       $global_ascent,
417       $descent,
418       $ascent,
419       $advance_width,
420       $right_bearing) = $font->bounding_box(string => "A Fool");
421
422   my $bbox_object = $font->bounding_box(string => "A Fool");
423
424 =over
425
426 =item C<$neg_width>
427
428 the relative start of a the string.  In some
429 cases this can be a negative number, in that case the first letter
430 stretches to the left of the starting position that is specified in
431 the string method of the Imager class
432
433 =item C<$global_descent> 
434
435 how far down the lowest letter of the entire font reaches below the
436 baseline (this is often j).
437
438 =item C<$pos_width>
439
440 how wide the string from
441 the starting position is.  The total width of the string is
442 C<$pos_width-$neg_width>.
443
444 =item C<$descent> 
445
446 =item C<$ascent> 
447
448 the same as <$global_descent> and <$global_ascent> except that they
449 are only for the characters that appear in the string.
450
451 =item C<$advance_width>
452
453 the distance from the start point that the next string output should
454 start at, this is often the same as C<$pos_width>, but can be
455 different if the final character overlaps the right side of its
456 character cell.
457
458 =item C<$right_bearing>
459
460 The distance from the right side of the final glyph to the end of the
461 advance width.  If the final glyph overflows the advance width this
462 value is negative.
463
464 =back
465
466 Obviously we can stuff all the results into an array just as well:
467
468   @metrics = $font->bounding_box(string => "testing 123");
469
470 Note that extra values may be added, so $metrics[-1] isn't supported.
471 It's possible to translate the output by a passing coordinate to the
472 bounding box method:
473
474   @metrics = $font->bounding_box(string => "testing 123", x=>45, y=>34);
475
476 This gives the bounding box as if the string had been put down at C<(x,y)>
477 By giving bounding_box 'canon' as a true value it's possible to measure
478 the space needed for the string:
479
480   @metrics = $font->bounding_box(string=>"testing",size=>15,canon=>1);
481
482 This returns tha same values in $metrics[0] and $metrics[1],
483 but:
484
485  $bbox[2] - horizontal space taken by glyphs
486  $bbox[3] - vertical space taken by glyphs
487
488 Returns an L<Imager::Font::BBox> object in scalar context, so you can
489 avoid all those confusing indices.  This has methods as named above,
490 with some extra convenience methods.
491
492 =item string
493
494 This is a method of the Imager class but because it's described in
495 here since it belongs to the font routines.  Example:
496
497   $img=Imager->new();
498   $img->read(file=>"test.jpg");
499   $img->string(font=>$t1font,
500                text=>"Model-XYZ",
501                x=>0,
502                y=>40,
503                size=>40,
504                color=>$red);
505   $img->write(file=>"testout.jpg");
506
507 This would put a 40 pixel high text in the top left corner of an
508 image.  If you measure the actuall pixels it varies since the fonts
509 usually do not use their full height.  It seems that the color and
510 size can be specified twice.  When a font is created only the actual
511 font specified matters.  It his however convenient to store default
512 values in a font, such as color and size.  If parameters are passed to
513 the string function they are used instead of the defaults stored in
514 the font.
515
516 The following parameters can be supplied to the string() method:
517
518 =over
519
520 =item string
521
522 The text to be rendered.  If this isn't present the 'text' parameter
523 is used.  If neither is present the call will fail.
524
525 =item aa
526
527 If non-zero the output will be anti-aliased.
528
529 =item x
530
531 =item y
532
533 The start point for rendering the text.  See the align parameter.
534
535 =item align
536
537 If non-zero the point supplied in (x,y) will be on the base-line, if
538 zero then (x,y) will be at the top-left of the string.
539
540 ie. if drawing the string "yA" and align is 0 the point (x,y) will
541 aligned with the top of the A.  If align is 1 (the default) it will be
542 aligned with the baseline of the font, typically bottom of the A,
543 depending on the font used.
544
545 =item channel
546
547 If present, the text will be written to the specified channel of the
548 image and the color parameter will be ignore.
549
550 =item color
551
552 The color to draw the text in.
553
554 =item size
555
556 The point-size to draw the text at.
557
558 =item sizew
559
560 For drivers that support it, the width to draw the text at.  Defaults
561 to be value of the 'size' parameter.
562
563 =item utf8
564
565 For drivers that support it, treat the string as UTF8 encoded.  For
566 versions of perl that support Unicode (5.6 and later), this will be
567 enabled automatically if the 'string' parameter is already a UTF8
568 string. See L<UTF8> for more information.
569
570 =item vlayout
571
572 For drivers that support it, draw the text vertically.  Note: I
573 haven't found a font that has the appropriate metrics yet.
574
575 =back
576
577 If string() is called with the C<channel> parameter then the color
578 isn't used and the font is drawn in only one channel of the image.
579 This can be quite handy to create overlays.  See the examples for tips
580 about this.
581
582 Sometimes it is necessary to know how much space a string takes before
583 rendering it.  The bounding_box() method described earlier can be used
584 for that.
585
586 =item align(string=>$text, size=>$size, x=>..., y=>..., valign => ..., halign=>...)
587
588 Higher level text output - outputs the text aligned as specified
589 around the given point (x,y).
590
591   # "Hello" centered at 100, 100 in the image.
592   my ($left, $top, $bottom, $right) = 
593     $font->align(string=>"Hello",
594                  x=>100, y=>100, 
595                  halign=>'center', valign=>'center', 
596                  image=>$image);
597
598 Takes the same parameters as $font->draw(), and the following extra
599 parameters:
600
601 =over
602
603 =item valign
604
605 Possible values are:
606
607 =over
608
609 =item top
610
611 Point is at the top of the text.
612
613 =item bottom
614
615 Point is at the bottom of the text.
616
617 =item baseline
618
619 Point is on the baseline of the text (default.)
620
621 =item center
622
623 Point is vertically centered within the text.
624
625 =back
626
627 =item halign
628
629 =over
630
631 =item left
632
633 The point is at the left of the text.
634
635 =item start
636
637 The point is at the start point of the text.
638
639 =item center
640
641 The point is horizontally centered within the text.
642
643 =item right
644
645 The point is at the right end of the text.
646
647 =item end
648
649 The point is at the right end of the text.  This will change to the
650 end point of the text (once the proper bounding box interfaces are
651 available).
652
653 =back
654
655 =item image
656
657 The image to draw to.  Set to C<undef> to avoid drawing but still
658 calculate the bounding box.
659
660 =back
661
662 Returns a list specifying the bounds of the drawn text.
663
664 =item dpi()
665
666 =item dpi(xdpi=>$xdpi, ydpi=>$ydpi)
667
668 =item dpi(dpi=>$dpi)
669
670 Set retrieve the spatial resolution of the image in dots per inch.
671 The default is 72 dpi.
672
673 This isn't implemented for all font types yet.
674
675 =item transform(matrix=>$matrix)
676
677 Applies a transformation to the font, where matrix is an array ref of
678 numbers representing a 2 x 3 matrix:
679
680   [  $matrix->[0],  $matrix->[1],  $matrix->[2],
681      $matrix->[3],  $matrix->[4],  $matrix->[5]   ]
682
683 Not all font types support transformations, these will return false.
684
685 It's possible that a driver will disable hinting if you use a
686 transformation, to prevent discontinuities in the transformations.
687 See the end of the test script t/t38ft2font.t for an example.
688
689 Currently only the ft2 (Freetype 2.x) driver supports the transform()
690 method.
691
692 =item has_chars(string=>$text)
693
694 Checks if the characters in $text are defined by the font.
695
696 In a list context returns a list of true or false value corresponding
697 to the characters in $text, true if the character is defined, false if
698 not.  In scalar context returns a string of NUL or non-NUL
699 characters.  Supports UTF8 where the font driver supports UTF8.
700
701 Not all fonts support this method (use $font->can("has_chars") to
702 check.)
703
704 =item logo
705
706 This method doesn't exist yet but is under consideration.  It would mostly
707 be helpful for generating small tests and such.  Its proposed interface is:
708
709   $img = $font->logo(string=>"Plan XYZ", color=>$blue, border=>7);
710
711 This would be nice for writing (admittedly multiline) one liners like:
712
713 Imager::Font->new(file=>"arial.ttf", color=>$blue, aa=>1)
714             ->string(text=>"Plan XYZ", border=>5)
715             ->write(file=>"xyz.png");
716
717 =item face_name()
718
719 Returns the internal name of the face.  Not all font types support
720 this method yet.
721
722 =item glyph_names(string=>$string [, utf8=>$utf8 ][, reliable_only=>0 ] );
723
724 Returns a list of glyph names for each of the characters in the
725 string.  If the character has no name then C<undef> is returned for
726 the character.
727
728 Some font files do not include glyph names, in this case Freetype 2
729 will not return any names.  Freetype 1 can return standard names even
730 if there are no glyph names in the font.
731
732 Freetype 2 has an API function that returns true only if the font has
733 "reliable glyph names", unfortunately this always returns false for
734 TTF fonts.  This can avoid the check of this API by supplying
735 C<reliable_only> as 0.  The consequences of using this on an unknown
736 font may be unpredictable, since the Freetype documentation doesn't
737 say how those name tables are unreliable, or how FT2 handles them.
738
739 Both Freetype 1.x and 2.x allow support for glyph names to not be
740 included.
741
742 =back
743
744 =head1 MULTIPLE MASTER FONTS
745
746 The Freetype 2 driver supports multiple master fonts:
747
748 =over
749
750 =item is_mm()
751
752 Test if the font is a multiple master font.
753
754 =item mm_axes()
755
756 Returns a list of the axes that can be changes in the font.  Each
757 entry is an array reference which contains:
758
759 =over
760
761 =item 1.
762
763 Name of the axis.
764
765 =item 2.
766
767 minimum value for this axis.
768
769 =item 3.
770
771 maximum value for this axis
772
773 =back
774
775 =item set_mm_coords(coords=>\@values)
776
777 Blends an interpolated design from the master fonts.  @values must
778 contain as many values as there are axes in the font.
779
780 =back
781
782 For example, to select the minimum value in each axis:
783
784   my @axes = $font->mm_axes;
785   my @coords = map $_->[1], @axes;
786   $font->set_mm_coords(coords=>\@coords);
787
788 It's possible other drivers will support multiple master fonts in the
789 future, check if your selected font object supports the is_mm() method
790 using the can() method.
791
792 =head1 UTF8
793
794 There are 2 ways of rendering Unicode characters with Imager:
795
796 =over
797
798 =item *
799
800 For versions of perl that support it, use perl's native UTF8 strings.
801 This is the simplest method.
802
803 =item *
804
805 Hand build your own UTF8 encoded strings.  Only recommended if your
806 version of perl has no UTF8 support.
807
808 =back
809
810 Imager won't construct characters for you, so if want to output
811 unicode character 00C3 "LATIN CAPITAL LETTER A WITH DIAERESIS", and
812 your font doesn't support it, Imager will I<not> build it from 0041
813 "LATIN CAPITAL LETTER A" and 0308 "COMBINING DIAERESIS".
814
815 =head2 Native UTF8 Support
816
817 If your version of perl supports UTF8 and the driver supports UTF8,
818 just use the $im->string() method, and it should do the right thing.
819
820 =head2 Build your own
821
822 In this case you need to build your own UTF8 encoded characters.
823
824 For example:
825
826  $x = pack("C*", 0xE2, 0x80, 0x90); # character code 0x2010 HYPHEN
827
828 You need to be be careful with versions of perl that have UTF8
829 support, since your string may end up doubly UTF8 encoded.
830
831 For example:
832
833  $x = "A\xE2\x80\x90\x41\x{2010}";
834  substr($x, -1, 0) = ""; 
835  # at this point $x is has the UTF8 flag set, but has 5 characters,
836  # none, of which is the constructed UTF8 character
837
838 The test script t/t38ft2font.t has a small example of this after the 
839 comment:
840
841   # an attempt using emulation of UTF8
842
843 =head1 DRIVER CONTROL
844
845 If you don't supply a 'type' parameter to Imager::Font->new(), but you
846 do supply a 'file' parameter, Imager will attempt to guess which font
847 driver to used based on the extension of the font file.
848
849 Since some formats can be handled by more than one driver, a priority
850 list is used to choose which one should be used, if a given format can
851 be handled by more than one driver.
852
853 The current priority can be retrieved with:
854
855   @drivers = Imager::Font->priorities();
856
857 You can set new priorities and save the old priorities with:
858
859   @old = Imager::Font->priorities(@drivers);
860
861 If you supply driver names that are not currently supported, they will
862 be ignored.
863
864 Imager supports both T1Lib and Freetype2 for working with Type 1
865 fonts, but currently only T1Lib does any caching, so by default T1Lib
866 is given a higher priority.  Since Imager's Freetype2 support can also
867 do font transformations, you may want to give that a higher priority:
868
869   my @old = Imager::Font->priorities(qw(tt ft2 t1));
870
871 =head1 AUTHOR
872
873 Arnar M. Hrafnkelsson, addi@umich.edu
874 And a great deal of help from others - see the README for a complete
875 list.
876
877 =head1 BUGS
878
879 You need to modify this class to add new font types.
880
881 The $pos_width member returned by the bounding_box() method has
882 historically returned different values from different drivers.  The
883 Freetype 1.x and 2.x, and the Win32 drivers return the max of the
884 advance width and the right edge of the right-most glyph.  The Type 1
885 driver always returns the right edge of the right-most glyph.
886
887 The newer advance_width and right_bearing values allow access to any
888 of the above.
889
890 =head1 SEE ALSO
891
892 Imager(3), Imager::Font::FreeType2(3), Imager::Font::Type1(3),
893 Imager::Font::Win32(3), Imager::Font::Truetype(3), Imager::Font::BBox(3)
894
895  http://imager.perl.org/
896
897 =cut
898
899