Font-TTF-Scripts
view release on metacpan or search on metacpan
scripts/ttfbuilder view on Meta::CPAN
foreach $p (keys %{$xml_dat[$fnum][$gid]{'points'}})
{
next if $noaps{$p};
my ($p1) = $xml_dat[$fnum][$gid]{'points'}{$p};
$aglyph->{'points'}{$p}{'base'} = $aglyph;
$aglyph->{'points'}{$p}{'loc'} = [@{$p1->{'loc'}}] if (defined $p1->{'loc'});
$aglyph->{'points'}{$p}{'cont'} = $p1->{'cont'} if (defined $p1->{'cont'}); # deep copy - klunky
}
}
$aglyph->{'properties'} = {%{$xml_dat[$fnum][$gid]{'properties'}}} if defined $xml_dat[$fnum][$gid]{'properties'};
$aglyph->{'notes'} = $xml_dat[$fnum][$gid]{'notes'} if defined $xml_dat[$fnum][$gid]{'notes'};
if ($tag eq 'attach') # position attachment
{
my ($atx, $aty, $withx, $withy, $pt);
my ($currif) = $curbase->{'font'};
if (defined $attrs{'at'})
{
$pt = $xml_dat[$curbase->{'fnum'}][$curbase->{'gid'}]{'points'}{$attrs{'at'}};
if (!defined $pt)
{ $xml->xpcarp("Undefined attachment point $attrs{'at'} on glyph $xml_dat[$curbase->{'gid'}]{'ps'} in $opt_c"); }
elsif (!defined $pt->{'loc'})
{
if (defined $pt->{'cont'})
{
$xml->xpcarp("glyph $xml_dat[$curbase->{'fnum'}][$curbase->{'gid'}]{'ps'} has no outline in $opt_c")
unless ($curbase->{'glyph'});
$pt->{'loc'} = lookup_pt($curbase->{'glyph'}, $pt->{'cont'}, $curbase->{'font'}{'scale'});
}
else
{ $xml->xpcarp("Unlocatable attachment point $attrs{'at'} on glyph $xml_dat[$curbase->{'fnum'}][$curbase->{'gid'}]{'ps'} in $opt_c"); }
}
($atx, $aty) = @{$pt->{'loc'}};
delete $curbase->{'points'}{$attrs{'at'}}; # used it so delete it
} else # no attachment point, default centre the glyphs in x
{
$atx = $curbase->{'font'}{'hmtx'}{'advance'}[$curbase->{'gid'}] / 2 * $curbase->{'font'}{'scale'};
$aty = 0;
}
if (defined $attrs{'with'})
{
$pt = $xml_dat[$fnum][$aglyph->{'gid'}]{'points'}{$attrs{'with'}};
if (!defined $pt)
{
$xml->xpcarp("Undefined attachment point $attrs{'with'} on glyph $xml_dat[$fnum][$aglyph->{'gid'}]{'ps'} in $opt_c");
$pt->{'loc'} = [0, 0];
}
elsif (!defined $pt->{'loc'})
{
if (defined $pt->{'cont'})
{ $pt->{'loc'} = lookup_pt($aglyph->{'glyph'}, $pt->{'cont'}, $currif->{'scale'}); }
else
{
$xml->xpcarp("Unlocatable attachment point $attrs{'at'} on glyph $xml_dat[$fnum][$aglyph->{'gid'}]{'ps'} in $opt_c");
$pt->{'loc'} = [0, 0];
}
}
($withx, $withy) = @{$pt->{'loc'}};
delete $aglyph->{'points'}{$attrs{'with'}} # delete if attaching to a real glyph
if (defined $curbase->{'glyph'} && (!ref $curbase->{'glyph'}{'endpoints'} || $curbase->{'glyph'}{'numPoints'} != scalar @{$curbase->{'glyph'}{'endPoints'}}));
} else
{
$withx = $currif->{'hmtx'}{'advance'}[$aglyph->{'gid'}] / 2 * $currif->{'scale'};
$withy = 0;
}
$aglyph->{'roffset'} = [$atx - $withx, $aty - $withy];
}
$xml->{' curbase'} = $aglyph;
}
elsif ($tag eq 'advance')
{
$curbase->{'adv'} = $attrs{'width'};
}
elsif ($tag eq 'rsb')
{
$curbase->{'adv'} = $curbase->{'glyph'}->read->{'xMax'} + $attrs{'width'};
}
elsif ($tag eq 'lsb')
{
$curbase->{'lsb'} = $attrs{'width'};
}
elsif ($tag eq 'shift')
{
$curbase->{'roffset'}[0] += $attrs{'x'};
$curbase->{'roffset'}[1] += $attrs{'y'};
}
elsif ($tag eq 'scale')
{
my (@r, @s, $angle, $res);
if (defined $attrs{'rotate'})
{
$angle = $attrs{'rotate'} * 3.141592535 / 180;
@r = (cos($angle), -sin($angle), sin($angle), cos($angle))
}
else
{ @r = (1, 0, 0, 1); }
@s = (1, 0, 0, 1);
$s[0] = $attrs{'x'} if (defined $attrs{'x'});
$s[3] = $attrs{'y'} if (defined $attrs{'y'});
$res = mat_mult(\@s, \@r);
$curbase->{'scale'} = $res;
}
elsif ($tag eq 'string')
{
$cur_str = {%attrs};
$currtext = '';
}
elsif ($tag eq 'font')
{
my ($s);
$of->{'hhea'}{'Ascender'} = $attrs{'ascent'} if defined $attrs{'ascent'};
$of->{'hhea'}{'Descender'} = $attrs{'descent'} if defined $attrs{'descent'};
$of->{'hhea'}{'LineGap'} = $attrs{'linegap'} if defined $attrs{'linegap'};
if ($s = $attrs{'cp'})
{
$s = '0' x (16 - length($s)) . $s;
$of->{'OS/2'}{'ulCodePageRange1'} = hex(substr($s, 8));
$of->{'OS/2'}{'ulCodePageRange2'} = hex(substr($s, 0, 8));
scripts/ttfbuilder view on Meta::CPAN
foreach $k (keys %{$oc})
{ $bmpc{$k} = $oc->{$k} if ($k <= 0xFFFF); }
push (@{$of->{'cmap'}{'Tables'}}, {
'Platform' => 3,
'Encoding' => ($opt_d & 8 ? 0 : 1),
'Format' => 4,
'Ver' => 0,
'val' => \%bmpc});
}
$of->{'cmap'}{'Num'} = scalar @{$of->{'cmap'}{'Tables'}};
unless ($done_cpyrt || ($opt_d & 4))
{
my ($text) = $of->{'name'}->find_name(0);
$text .= " Derived from $fname by ttfbuilder v$VERSION";
do_name($of, {'num' => 0, 'text' => $text});
}
if ($ifissymbol ^ ($opt_d & 8 ? 1 : 0))
{
my ($n, $s);
foreach $n (@{$of->{'name'}{'strings'}})
{
if (defined ($s = $n->[3][!$ifissymbol]))
{
undef $n->[3][!$ifissymbol];
$n->[3][$ifissymbol] = $s;
}
}
}
unless ($opt_d & 1)
{
$of->{'head'}->setdate(time(), 1); # set creation date
$of->{'head'}->setdate(time(), 0); # set modified date
}
$of->tables_do(sub {$_[0]->dirty});
$of->update;
# $of->{'head'}{'flags'} &= ~2;
return $of;
}
sub resolve_glyph
{
my ($g, $orgx, $orgy, $pathcount, $overstrike) = @_;
my ($glyph, $xMin, $yMin, $xMax, $yMax, $c, $p, $adv, $lorg);
my ($f) = $g->{'font'};
my ($s) = $f->{'scale'};
$g->{'pathbase'} = $pathcount;
$g->{'offset'} = [$g->{'roffset'}[0] + $orgx,
$g->{'roffset'}[1] + $orgy];
$adv = (defined $g->{'adv'} ? $g->{'adv'} : $f->{'hmtx'}{'advance'}[$g->{'gid'}] * $s)
+ $g->{'offset'}[0];
if ($glyph = $g->{'glyph'})
{
$glyph->read->get_points;
$pathcount += scalar @{$glyph->{'endPoints'}} if (defined $glyph->{'endpoints'});
push (@{$g->{'glyph_list'}}, pos_glyphs($f, $g->{'gid'}, $glyph, @{$g->{'offset'}}, $g->{'scale'}, $s));
$xMin = $glyph->{'xMin'} * $s;
$yMin = $glyph->{'yMin'} * $s;
$xMax = $glyph->{'xMax'} * $s;
$yMax = $glyph->{'yMax'} * $s;
}
elsif (!defined $g->{'glyph_list'})
{ $g->{'glyph_list'} = []; }
$lorg = $xMin - $g->{'lsb'} + $g->{'offset'}[0];
foreach $c (@{$g->{'glyphs'}})
{
my ($lorgt);
$pathcount = resolve_glyph($c, @{$g->{'offset'}}, $pathcount);
$adv = $c->{'adv'} if (!$overstrike && $c->{'adv'} > $adv);
($xMin, $yMin, $xMax, $yMax) = findbox($xMin, $yMin, $xMax, $yMax, $c->{'bbox'}, $c->{'offset'});
$lorgt = $c->{'bbox'}[0] - $c->{'lsb'} + $c->{'offset'}[0];
$lorg = $lorgt if ($lorgt < $lorg);
push (@{$g->{'glyph_list'}}, @{$c->{'glyph_list'}});
foreach $p (keys %{$c->{'points'}})
{ $g->{'points'}{$p} = $c->{'points'}{$p}; }
}
$g->{'bbox'} = [$xMin, $yMin, $xMax, $yMax];
$g->{'adv'} = $adv;
$g->{'lorg'} = $lorg;
return $pathcount;
}
sub pos_glyphs
{
my ($font, $gid, $glyph, $orgx, $orgy, $scale, $qs) = @_;
my ($comp);
if ($glyph->{'numberOfContours'} < 0)
{
my (@res);
$glyph->read_dat;
foreach $comp (@{$glyph->{'comps'}})
{
push (@res, pos_glyphs($font, $comp->{'glyph'},
$font->{'loca'}{'glyphs'}[$comp->{'glyph'}],
$comp->{'args'}[0] * $qs + $orgx,
$comp->{'args'}[1] * $qs + $orgy, mat_mult($scale, $comp->{'scale'}, $qs), $qs)) if ($font->{'loca'}{'glyphs'}[$comp->{'glyph'}]);
}
return @res;
} elsif (scalar @{$glyph->{'endPoints'}} == $glyph->{'numPoints'})
{
return ();
} else
{
$glyph->{'required'} = -1 if (!defined $glyph->{'required'});
return ({
'font' => $font,
'fnum' => $font->{'number'},
'GID' => $gid,
'offset' => [$orgx, $orgy],
'scale' => $scale,
( run in 0.678 second using v1.01-cache-2.11-cpan-39bf76dae61 )