]> git.imager.perl.org - imager.git/blobdiff - lib/Imager/Font.pm
define 0.61 release goals
[imager.git] / lib / Imager / Font.pm
index bc46aa49de2a1099dbcfd6ccec7de529c723a576..1102e03068338b77721dcd58e6e78d9383eae244 100644 (file)
@@ -4,7 +4,7 @@ use Imager::Color;
 use strict;
 use vars qw($VERSION);
 
-$VERSION = sprintf "%d.%03d", q$Revision$=~/\d+/g;
+$VERSION = "1.033";
 
 # the aim here is that we can:
 #  - add file based types in one place: here
@@ -17,16 +17,19 @@ my %drivers =
         class=>'Imager::Font::Truetype',
         module=>'Imager/Font/Truetype.pm',
         files=>'.*\.ttf$',
+       description => 'FreeType 1.x',
        },
    t1=>{
         class=>'Imager::Font::Type1',
         module=>'Imager/Font/Type1.pm',
         files=>'.*\.pfb$',
+       description => 'T1Lib',
        },
    ft2=>{
          class=>'Imager::Font::FreeType2',
          module=>'Imager/Font/FreeType2.pm',
          files=>'.*\.(pfa|pfb|otf|ttf|fon|fnt|dfont|pcf(\.gz)?)$',
+        description => 'FreeType 2.x',
         },
    ifs=>{
          class=>'Imager::Font::Image',
@@ -36,6 +39,7 @@ my %drivers =
    w32=>{
          class=>'Imager::Font::Win32',
          module=>'Imager/Font/Win32.pm',
+        description => 'Win32 GDI Fonts',
         },
   );
 
@@ -46,7 +50,9 @@ my @priority = qw(t1 tt ft2 ifs);
 # this function is called from Imager.pm to finish initialization
 sub __init {
   @priority = grep Imager::i_has_format($_), @priority;
-  delete @drivers{grep !Imager::i_has_format($_), keys %drivers};
+  for my $driver_name (grep Imager::i_has_format($_), keys %drivers) {
+    $drivers{$driver_name}{enabled} = 1;
+  }
 }
 
 # search method
@@ -76,7 +82,7 @@ sub new {
     }
 
     $type = $hsh{'type'};
-    if (!defined($type) or !$drivers{$type}) {
+    if (!defined($type) or !$drivers{$type} or !$drivers{$type}{enabled}) {
       for my $drv (@priority) {
         undef $type;
         my $re = $drivers{$drv}{files} or next;
@@ -87,7 +93,21 @@ sub new {
       }
     }
     if (!defined($type)) {
-      $Imager::ERRSTR = "Font type not found";
+      # some types we can support, but the driver isn't available
+      # work out which drivers support it, so we can provide the user
+      # some useful information on how to get it working
+      my @not_here;
+      for my $driver_name (keys %drivers) {
+       my $driver = $drivers{$driver_name};
+       push @not_here, "$driver_name ($driver->{description})"
+         if $driver->{files} && $file =~ /$driver->{files}/i;
+      }
+      if (@not_here) {
+       $Imager::ERRSTR = "No font drivers enabled that can support this file, rebuild Imager with any of ".join(", ", @not_here)." to use this font file";
+      }
+      else {
+       $Imager::ERRSTR = "No font type found for $hsh{'file'}";
+      }
       return;
     }
   } elsif ($hsh{face}) {
@@ -470,8 +490,22 @@ parameter.  Default: 0.
 aa - the default value for the $im->string(...) C<aa> parameter.
 Default: 0.
 
+=item *
+
+index - for font file containing multiple fonts this selects which
+font to use.  This is useful for Macintosh DFON (.dfont) and suitcase
+font files.
+
+If you want to use a suitcase font you will need to tell Imager to use
+the FreeType 2.x driver by setting C<type> to C<'ft2'>:
+
+  my $font = Imager::Font->new(file=>$file, index => 1, type=>'ft2')
+    or die Imager->errstr;
+
 =back
 
+
+
 =item bounding_box
 
 Returns the bounding box for the specified string.  Example:
@@ -780,6 +814,11 @@ say how those name tables are unreliable, or how FT2 handles them.
 Both Freetype 1.x and 2.x allow support for glyph names to not be
 included.
 
+=item draw
+
+This is used by Imager's string() method to implement drawing text.
+See L<Imager::Draw/string>.
+
 =back
 
 =head1 MULTIPLE MASTER FONTS
@@ -853,6 +892,16 @@ unicode character 00C3 "LATIN CAPITAL LETTER A WITH DIAERESIS", and
 your font doesn't support it, Imager will I<not> build it from 0041
 "LATIN CAPITAL LETTER A" and 0308 "COMBINING DIAERESIS".
 
+To check if a driver supports UTF8 call the utf8 method:
+
+=over
+
+=item utf8
+
+Return true if the font supports UTF8.
+
+=back
+
 =head2 Native UTF8 Support
 
 If your version of perl supports UTF8 and the driver supports UTF8,
@@ -891,7 +940,11 @@ Since some formats can be handled by more than one driver, a priority
 list is used to choose which one should be used, if a given format can
 be handled by more than one driver.
 
-The current priority can be retrieved with:
+=over
+
+=item priorities
+
+The current priorities can be retrieved with:
 
   @drivers = Imager::Font->priorities();
 
@@ -899,6 +952,8 @@ You can set new priorities and save the old priorities with:
 
   @old = Imager::Font->priorities(@drivers);
 
+=back
+
 If you supply driver names that are not currently supported, they will
 be ignored.