1 package Font::TTF::Anchor;
 
   5 Font::TTF::Anchor - Anchor points for GPOS tables
 
   9 The Anchor defines an anchor point on a glyph providing various information
 
  10 depending on how much is available, including such information as the co-ordinates,
 
  11 a curve point and even device specific modifiers.
 
  13 =head1 INSTANCE VARIABLES
 
  19 XCoordinate of the anchor point
 
  23 YCoordinate of the anchor point
 
  27 Curve point on the glyph to use as the anchor point
 
  31 Device table (delta) for the xcoordinate
 
  35 Device table (delta) for the ycoordinate
 
  39 XIdAnchor for multiple master horizontal metric id
 
  43 YIdAnchor for multiple master vertical metric id
 
  72 Reads the anchor from the given file handle at that point. The file handle is left
 
  73 at an arbitrary read point, usually the end of something!
 
  80     my ($dat, $loc, $fmt, $p, $xoff, $yoff);
 
  83     $fmt = unpack('n', $dat);
 
  85     { ($self->{'xid'}, $self->{'yid'}) = TTF_Unpack('S2', substr($dat,2)); }
 
  87     { ($self->{'x'}, $self->{'y'}) = TTF_Unpack('s2', substr($dat,2)); }
 
  92         $self->{'p'} = unpack('n', $dat);
 
  96         ($xoff, $yoff) = unpack('n2', $dat);
 
  97         $loc = $fh->tell() - 10;
 
 100             $fh->seek($loc + $xoff, 0);
 
 101             $self->{'xdev'} = Font::TTF::Delta->new->read($fh);
 
 105             $fh->seek($loc + $yoff, 0);
 
 106             $self->{'ydev'} = Font::TTF::Delta->new->read($fh);
 
 113 =head2 out($fh, $style)
 
 115 Outputs the Anchor to the given file handle at this point also addressing issues
 
 116 of deltas. If $style is set, then no output is sent to the file handle. The return
 
 117 value is the output string.
 
 123     my ($self, $fh, $style) = @_;
 
 124     my ($xoff, $yoff, $fmt, $out);
 
 126     if (defined $self->{'xid'} || defined $self->{'yid'})
 
 127     { $out = TTF_Pack('SSS', 4, $self->{'xid'}, $self->{'yid'}); }
 
 128     elsif (defined $self->{'p'})
 
 129     { $out = TTF_Pack('Ssss', 2, @{$self}{'x', 'y', 'p'}); }
 
 130     elsif (defined $self->{'xdev'} || defined $self->{'ydev'})
 
 132         $out = TTF_Pack('Sss', 3, @{$self}{'x', 'y'});
 
 133         if (defined $self->{'xdev'})
 
 135             $out .= pack('n2', 10, 0);
 
 136             $out .= $self->{'xdev'}->out($fh, 1);
 
 137             $yoff = length($out) - 10;
 
 140         { $out .= pack('n2', 0, 0); }
 
 141         if (defined $self->{'ydev'})
 
 143             $yoff = 10 unless $yoff;
 
 144             substr($out, 8, 2) = pack('n', $yoff);
 
 145             $out .= $self->{'ydev'}->out($fh, 1);
 
 148     { $out = TTF_Pack('Sss', 1, @{$self}{'x', 'y'}); }
 
 149     $fh->print($out) unless $style;
 
 157     return join (",", map {"${_}=$self->{$_}"} qw(x y p xdev ydev xid yid));
 
 161 =head2 $a->out_xml($context)
 
 163 Outputs the anchor in XML
 
 169     my ($self, $context, $depth) = @_;
 
 170     my ($fh) = $context->{'fh'};
 
 173     $fh->print("$depth<anchor x='$self->{'x'}' y='$self->{'y'}'");
 
 174     $fh->print(" p='$self->{'p'}'") if defined ($self->{'p'});
 
 175     $end = (defined $self->{'xdev'} || defined $self->{'ydev'} || defined $self->{'xid'} || defined $self->{'yid'});
 
 182     if (defined $self->{'xdev'})
 
 184         $fh->print("$depth$context->{'indent'}<xdev>\n");
 
 185         $self->{'xdev'}->out_xml($context, $depth . ($context->{'indent'} x 2));
 
 186         $fh->print("$depth$context->{'indent'}</xdev>\n");
 
 189     if (defined $self->{'ydev'})
 
 191         $fh->print("$depth$context->{'indent'}<ydev>\n");
 
 192         $self->{'ydev'}->out_xml($context, $depth . ($context->{'indent'} x 2));
 
 193         $fh->print("$depth$context->{'indent'}</ydev>\n");
 
 196     if (defined $self->{'xid'} || defined $self->{'yid'})
 
 198         $fh->print("$depth$context->{'indent'}<mmaster");
 
 199         $fh->print(" xid='$self->{'xid'}'") if defined ($self->{'xid'});
 
 200         $fh->print(" yid='$self->{'yid'}'") if defined ($self->{'yid'});
 
 203     $fh->print("$depth</anchor>\n");
 
 210 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and