<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Imager::Font::FT2;
use strict;
use Imager;
use vars qw($VERSION @ISA);
@ISA = qw(Imager::Font);

BEGIN {
  $VERSION = "0.78";

  eval {
    require XSLoader;
    XSLoader::load('Imager::Font::FT2', $VERSION);
    1;
  } or do {
    require DynaLoader;
    push @ISA, 'DynaLoader';
    bootstrap Imager::Font::FT2 $VERSION;
  };
}

*_first = \&amp;Imager::Font::_first;

sub new {
  my $class = shift;
  my %hsh=(color=&gt;Imager::Color-&gt;new(255,0,0,0),
	   size=&gt;15,
	   @_);

  unless ($hsh{file}) {
    $Imager::ERRSTR = "No font file specified";
    return;
  }
  unless (-e $hsh{file}) {
    $Imager::ERRSTR = "Font file $hsh{file} not found";
    return;
  }
  unless ($Imager::formats{ft2}) {
    $Imager::ERRSTR = "Freetype2 not supported in this build";
    return;
  }
  my $id = i_ft2_new($hsh{file}, $hsh{'index'} || 0);
  unless ($id) { # the low-level code may miss some error handling
    $Imager::ERRSTR = Imager::_error_as_msg();
    return;
  }
  return bless {
		id       =&gt; $id,
		aa       =&gt; $hsh{aa} || 0,
		file     =&gt; $hsh{file},
		type     =&gt; 't1',
		size     =&gt; $hsh{size},
		color    =&gt; $hsh{color},
                utf8     =&gt; $hsh{utf8},
                vlayout  =&gt; $hsh{vlayout},
	       }, $class;
}

sub _draw {
  my $self = shift;
  my %input = @_;
  if (exists $input{channel}) {
    i_ft2_cp($self-&gt;{id}, $input{image}{IMG}, $input{'x'}, $input{'y'},
             $input{channel}, $input{size}, $input{sizew} || 0,
             $input{string}, , $input{align}, $input{aa}, $input{vlayout},
             $input{utf8});
  } else {
    i_ft2_text($self-&gt;{id}, $input{image}{IMG},
               $input{'x'}, $input{'y'},
               $input{color}, $input{size}, $input{sizew} || 0,
               $input{string}, $input{align}, $input{aa}, $input{vlayout},
               $input{utf8});
  }
}

sub _bounding_box {
  my $self = shift;
  my %input = @_;

  return i_ft2_bbox($self-&gt;{id}, $input{size}, $input{sizew}, $input{string}, 
		    $input{utf8});
}

sub dpi {
  my $self = shift;
  my @old = i_ft2_getdpi($self-&gt;{id});
  if (@_) {
    my %hsh = @_;
    my $result;
    unless ($hsh{xdpi} &amp;&amp; $hsh{ydpi}) {
      if ($hsh{dpi}) {
        $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
      }
      else {
        $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
        return;
      }
      i_ft2_setdpi($self-&gt;{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
    }
  }
  
  return @old;
}

sub hinting {
  my ($self, %opts) = @_;

  i_ft2_sethinting($self-&gt;{id}, $opts{hinting} || 0);
}

sub _transform {
  my $self = shift;

  my %hsh = @_;
  my $matrix = $hsh{matrix} or return undef;

  return i_ft2_settransform($self-&gt;{id}, $matrix)
}

sub utf8 {
  return 1;
}

# check if the font has the characters in the given string
sub has_chars {
  my ($self, %hsh) = @_;

  unless (defined $hsh{string} &amp;&amp; length $hsh{string}) {
    $Imager::ERRSTR = "No string supplied to \$font-&gt;has_chars()";
    return;
  }
  return i_ft2_has_chars($self-&gt;{id}, $hsh{string}, 
			 _first($hsh{'utf8'}, $self-&gt;{utf8}, 0));
}

sub face_name {
  my ($self) = @_;

  i_ft2_face_name($self-&gt;{id});
}

sub can_glyph_names {
  i_ft2_can_do_glyph_names();
}

sub glyph_names {
  my ($self, %input) = @_;

  my $string = $input{string};
  defined $string
    or return Imager-&gt;_set_error("no string parameter passed to glyph_names");
  my $utf8 = _first($input{utf8}, 0);
  my $reliable_only = _first($input{reliable_only}, 1);

  my @names = i_ft2_glyph_name($self-&gt;{id}, $string, $utf8, $reliable_only);
  @names or return Imager-&gt;_set_error(Imager-&gt;_error_as_msg);

  return @names if wantarray;
  return pop @names;
}

sub is_mm {
  my ($self) = @_;

  i_ft2_is_multiple_master($self-&gt;{id});
}

sub mm_axes {
  my ($self) = @_;

  my ($num_axis, $num_design, @axes) =
    i_ft2_get_multiple_masters($self-&gt;{id})
      or return Imager-&gt;_set_error(Imager-&gt;_error_as_msg);

  return @axes;
}

sub set_mm_coords {
  my ($self, %opts) = @_;

  $opts{coords}
    or return Imager-&gt;_set_error("Missing coords parameter");
  ref($opts{coords}) &amp;&amp; $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
    or return Imager-&gt;_set_error("coords parameter must be an ARRAY ref");

  i_ft2_set_mm_coords($self-&gt;{id}, @{$opts{coords}})
    or return Imager-&gt;_set_error(Imager-&gt;_error_as_msg);

  return 1;
}
1;

__END__

=head1 NAME

Imager::Font::FT2 - font support using FreeType 2

=head1 SYNOPSIS

  use Imager;

  my $img = Imager-&gt;new;
  my $font = Imager::Font-&gt;new(file =&gt; "foo.ttf", type =&gt; "ft2");

  $img-&gt;string(... font =&gt; $font);

=head1 DESCRIPTION

This provides font support on FreeType 2.

=head1 CAVEATS

Unfortunately, older versions of Imager would install
C&lt;Imager::Font::FreeType2&gt; even if FreeType 2 wasn't available, and if
no font was created would succeed in loading the module.  This means
that an existing C&lt;FreeType2.pm&gt; could cause a probe success for
supported font files, so I've renamed it.

=head1 AUTHOR

Tony Cook &lt;tony@imager.perl.org&gt;

=head1 SEE ALSO

Imager, Imager::Font.

=cut
</pre></body></html>