| Server IP : 216.92.14.13 / Your IP : 216.73.216.171 Web Server : Apache System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 User : rmlac2fmr ( 1040637) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/bin/ |
Upload File : |
#!/usr/bin/perl
use strict;
use Font::TTF::Font;
use Getopt::Std;
our ($VERSION, $opt_v);
getopts('v');
$VERSION = '0.1'; # original
unless (defined $ARGV[0])
{
die <<"EOT";
ttfbboxfix [-v] in.ttf [out.ttf]
Re-calculates bounding boxes for all glyphs in a font.
if <outfile> is provided, rewrite corrected font. Options:
-v verbose output to stdout
Version $VERSION
EOT
}
my @metrics = (qw (xMin yMin xMax yMax));
my $count = 0;
my $f = Font::TTF::Font->open($ARGV[0]) || die "Cannot open TrueType font '$ARGV[0]' for reading.\n";
$f->{'glyf'}->read; # We're gonna modify the font, so read glyf table!
my $l = $f->{'loca'};
my @before; # bounding boxes before update.
# Build a list of original bbox values:
$l->glyphs_do (
sub {
my ($g, $gid) = @_;
$g->read_dat;
$before[$gid] = join(',', @{$g}{@metrics}); # Aren't slices fun!
}
);
# Also record the font-wide bounding box from head table:
my $oldfontbbox = join(',', @{$f->{'head'}}{@metrics});
# Update all bboxes the easy way:
$f->{'head'}->dirty;
$f->{'head'}->update;
# Find differences:
$l->glyphs_do (
sub {
my ($g, $gid) = @_;
my $after = join(',', @{$g}{@metrics});
if ($before[$gid] ne $after) {
$count++;
print "glyph $gid before: ($before[$gid]), after: ($after)\n" if $opt_v;
}
}
);
my $newfontbbox = join(',', @{$f->{'head'}}{@metrics});
if ($oldfontbbox ne $newfontbbox) {
print "font: before: ($oldfontbbox), after: ($newfontbbox)\n" if $opt_v;
$count++;
}
print "NB: all bounding boxes given as (", join(',', @metrics), ")\n" if $opt_v;
print "$count bounding box ", ($count == 1 ? "difference" : "differences"), ($ARGV[1] ? " fixed.\n" : " found.\n");
$f->out($ARGV[1]) if $ARGV[1];
=head1 NAME
ttfbboxfix - re-calculates bounding boxes for all glyphs in a font
=head1 SYNOPSIS
ttfbboxfix [-v] in.ttf [out.ttf]
Re-calculates bounding boxes for all glyphs in a font.
=head1 OPTIONS
-v verbose output to stdout
=head1 DESCRIPTION
Re-calculates bounding boxes for all glyphs in a font.
if <outfile> is provided, rewrite corrected font.
=head1 AUTHOR
Martin Hosken L<http://scripts.sil.org/FontUtils>.
(see CONTRIBUTORS for other authors).
=head1 LICENSING
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
This script is released under the terms of the Artistic License 2.0.
For details, see the full text of the license in the file LICENSE.
=cut