#! /usr/bin/perl -w
# -*- Perl -*-
# Copyright (C) 1989-2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
# 2009, 2010
# Free Software Foundation, Inc.
# Written by James Clark (jjc@jclark.com)
#
# This file is part of groff.
#
# groff is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# groff is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
use strict;
@afmtodit.tables@
my $prog = $0;
$prog =~ s@.*/@@;
my $groff_sys_fontdir = "@FONTDIR@";
use Getopt::Std;
getopts('a:cd:e:f:i:kmno:svx');
our ($opt_a, $opt_c, $opt_d, $opt_e, $opt_f, $opt_i, $opt_k,
$opt_m, $opt_n, $opt_o, $opt_s, $opt_v, $opt_x);
if ($opt_v) {
print "GNU afmtodit (groff) version @VERSION@\n";
exit 0;
}
if ($#ARGV != 2) {
die "usage: $prog [-ckmnsvx] [-a angle] [-d DESC] [-e encoding]\n" .
" [-f name] [-i n] [-o outfile] afmfile mapfile font\n";
}
my $afm = $ARGV[0];
my $map = $ARGV[1];
my $font = $ARGV[2];
my $outfile = $opt_o || $font;
my $desc = $opt_d || "DESC";
my $sys_map = $groff_sys_fontdir . "/devps/generate/" . $map;
my $sys_desc = $groff_sys_fontdir . "/devps/" . $desc;
# read the afm file
my $psname;
my ($notice, $version, $fullname, $familyname, @comments);
my $italic_angle = 0;
my (@kern1, @kern2, @kernx);
my (%italic_correction, %left_italic_correction);
my %subscript_correction;
# my %ligs
my %ligatures;
my (@encoding, %in_encoding);
my (%width, %height, %depth);
my (%left_side_bearing, %right_side_bearing);
open(AFM, $afm) || die "$prog: can't open \`$ARGV[0]': $!\n";
while () {
chomp;
s/\x0D$//;
my @field = split(' ');
next if $#field < 0;
if ($field[0] eq "FontName") {
$psname = $field[1];
if($opt_f) {
$psname = $opt_f;
}
}
elsif($field[0] eq "Notice") {
$notice = $_;
}
elsif($field[0] eq "Version") {
$version = $_;
}
elsif($field[0] eq "FullName") {
$fullname = $_;
}
elsif($field[0] eq "FamilyName") {
$familyname = $_;
}
elsif($field[0] eq "Comment") {
push(@comments, $_);
}
elsif($field[0] eq "ItalicAngle") {
$italic_angle = -$field[1];
}
elsif ($field[0] eq "KPX") {
if ($#field == 3) {
push(@kern1, $field[1]);
push(@kern2, $field[2]);
push(@kernx, $field[3]);
}
}
elsif ($field[0] eq "italicCorrection") {
$italic_correction{$field[1]} = $field[2];
}
elsif ($field[0] eq "leftItalicCorrection") {
$left_italic_correction{$field[1]} = $field[2];
}
elsif ($field[0] eq "subscriptCorrection") {
$subscript_correction{$field[1]} = $field[2];
}
elsif ($field[0] eq "StartCharMetrics") {
while () {
@field = split(' ');
next if $#field < 0;
last if ($field[0] eq "EndCharMetrics");
if ($field[0] eq "C") {
my $w;
my $wx = 0;
my $n = "";
# %ligs = ();
my $lly = 0;
my $ury = 0;
my $llx = 0;
my $urx = 0;
my $c = $field[1];
my $i = 2;
while ($i <= $#field) {
if ($field[$i] eq "WX") {
$w = $field[$i + 1];
$i += 2;
}
elsif ($field[$i] eq "N") {
$n = $field[$i + 1];
$i += 2;
}
elsif ($field[$i] eq "B") {
$llx = $field[$i + 1];
$lly = $field[$i + 2];
$urx = $field[$i + 3];
$ury = $field[$i + 4];
$i += 5;
}
# elsif ($field[$i] eq "L") {
# $ligs{$field[$i + 2]} = $field[$i + 1];
# $i += 3;
# }
else {
while ($i <= $#field && $field[$i] ne ";") {
$i++;
}
$i++;
}
}
if (!$opt_e && $c != -1) {
$encoding[$c] = $n;
$in_encoding{$n} = 1;
}
$width{$n} = $w;
$height{$n} = $ury;
$depth{$n} = -$lly;
$left_side_bearing{$n} = -$llx;
$right_side_bearing{$n} = $urx - $w;
# while ((my $lig, my $glyph2) = each %ligs) {
# $ligatures{$lig} = $n . " " . $glyph2;
# }
}
}
}
}
close(AFM);
# read the DESC file
my ($sizescale, $resolution, $unitwidth);
$sizescale = 1;
open(DESC, $desc) || open(DESC, $sys_desc) ||
die "$prog: can't open \`$desc' or \`$sys_desc': $!\n";
while () {
next if /^#/;
chop;
my @field = split(' ');
next if $#field < 0;
last if $field[0] eq "charset";
if ($field[0] eq "res") {
$resolution = $field[1];
}
elsif ($field[0] eq "unitwidth") {
$unitwidth = $field[1];
}
elsif ($field[0] eq "sizescale") {
$sizescale = $field[1];
}
}
close(DESC);
if ($opt_e) {
# read the encoding file
my $sys_opt_e = $groff_sys_fontdir . "/devps/" . $opt_e;
open(ENCODING, $opt_e) || open(ENCODING, $sys_opt_e) ||
die "$prog: can't open \`$opt_e' or \`$sys_opt_e': $!\n";
while () {
next if /^#/;
chop;
my @field = split(' ');
next if $#field < 0;
if ($#field == 1) {
if ($field[1] >= 0 && defined $width{$field[0]}) {
$encoding[$field[1]] = $field[0];
$in_encoding{$field[0]} = 1;
}
}
}
close(ENCODING);
}
# read the map file
my (%nmap, %map);
open(MAP, $map) || open(MAP, $sys_map) ||
die "$prog: can't open \`$map' or \`$sys_map': $!\n";
while (