File: gfont_mkgdf.pl

package info (click to toggle)
gfont 1.0.3-1
  • links: PTS
  • area: non-free
  • in suites: sarge, woody
  • size: 504 kB
  • ctags: 513
  • sloc: ansic: 6,465; sh: 823; makefile: 284; perl: 156
file content (178 lines) | stat: -rw-r--r-- 4,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!@PATH_PERL@
eval 'exec @PATH_PERL@ -S $0 ${1+"$@"}'
    if $running_under_some_shell;
##
##  gfont_mkgdf -- Make GdF Files
##  Copyright (c) 1996-1997 Ralf S. Engelschall, <rse@engelschall.com>
##
##  Usage: gfont_mkgdf [type:]fontname[-size]
##

require 5.003;
use strict;

use vars qw($gfontpath $fontmap $tmpgdfdir $prg_pktopx $prg_pxtogdf);
use vars qw($origfont $type $font $size $mapline);

$gfontpath   = $ENV{'GFONT_BASE'} || "@libdir@@libsubdir@";
$fontmap     = "$gfontpath/etc/Fontmap";
$prg_pktopx  = "$gfontpath/exec/gfont_pktopx";
$prg_pxtogdf = "$gfontpath/exec/gfont_pxtogdf";
$tmpgdfdir   = $ENV{'GDFPATH'} || "@tmpgdfdir@";

sub system {
    my ($cmd) = @_;

    print "$cmd\n";
    system($cmd);
}

sub mf2gdf {
    my ($origfont, $font, $mag) = @_;
    my ($dpi, $dpiM, $dpiP, $cwd);

    #   determine DPI
    $dpi = int(85 * (1.2 ** $mag));
    $dpiM = $dpi - 1; 
    $dpiP = $dpi + 1;

    #   prepare
    if ($tmpgdfdir !~ m|^/.+|) {
        $cwd = `pwd`;
        $cwd =~ s|\n$||;
        $cwd =~ s|/$||;
        $tmpgdfdir =~ s|^\./||;
        $tmpgdfdir = "$cwd/$tmpgdfdir";
    }
    unlink("$tmpgdfdir/$font.gdf.gz");
    chdir("/tmp");

    #   create PK file via METAFONT and GFtoPK
    print "[Create PK file via METAFONT and GFtoPK]\n";
    &system('mf "\mode:=sun; mag:=magstep(' . $mag . '); scrollmode; input ' . $font . '"');
    unlink("$font.log");
    unlink("$font.tfm");
    $dpi = $dpiM if (-f "$font.${dpiM}gf");
    $dpi = $dpiP if (-f "$font.${dpiP}gf");
    &system("gftopk $font.${dpi}gf $font.${dpi}pk");
    unlink("$font.${dpi}gf");

    #   convert PK to GdF
    print "[Convert PK to GdF]\n";
    $dpi = $dpiM if (-f "./pk/$font.${dpiM}pk");
    $dpi = $dpiP if (-f "./pk/$font.${dpiP}pk");
    unlink("$font.${dpi}px");
    &system("$prg_pktopx $font.${dpi}pk $font.${dpi}px");
    &system("$prg_pxtogdf $font.${dpi}px $font.gdf $font.gdi");
    unlink("$font.${dpi}px");
    unlink("$font.gdi");

    #   create GdF file in final place
    print "[Compress GdF]\n";
    &system("gzip -9 <$font.gdf >$tmpgdfdir/$origfont.gdf.gz");

    #   cleanup
    unlink("$font.gdf");
}

sub ps2gdf {
    my ($origfont, $font, $pt, $mapline) = @_;
    my ($dpi, $dpiM, $dpiP, $cwd);

    #   determine DPI
    $dpi = int((72/12)*$pt);
    $dpiM = $dpi - 1; 
    $dpiP = $dpi + 1;

    #   prepare
    if ($tmpgdfdir !~ m|^/.+|) {
        $cwd = `pwd`;
        $cwd =~ s|\n$||;
        $cwd =~ s|/$||;
        $tmpgdfdir =~ s|^\./||;
        $tmpgdfdir = "$cwd/$tmpgdfdir";
    }
    unlink("$tmpgdfdir/$font.gdf.gz");
    chdir("/tmp");

    #   test whether Postscript commands were defined in Fontmap
    $mapline = "--mapline='$font $mapline'" if $mapline ne '';

    #   create PK file via GSFtoPK (uses Ghostscript in background)
    print "[Create PK file via GSFtoPK/Ghostscript]\n";
    &system("gsftopk $mapline -q $font $dpi");
    $dpi = $dpiM if (-f "$font.${dpiM}gf");
    $dpi = $dpiP if (-f "$font.${dpiP}gf");

    #   convert PK to GdF
    print "[Convert PK to GdF]\n";
    $dpi = $dpiM if (-f "$font.${dpiM}pk");
    $dpi = $dpiP if (-f "$font.${dpiP}pk");
    unlink("$font.${dpi}px");
    &system("$prg_pktopx $font.${dpi}pk $font.${dpi}px");
    &system("$prg_pxtogdf $font.${dpi}px $font.gdf $font.gdi");
    unlink("$font.${dpi}px");
    unlink("$font.gdi");

    #   create GdF file in final place
    print "[Compress GdF]\n";
    &system("gzip -9 <$font.gdf >$tmpgdfdir/$origfont.gdf.gz");

    #   cleanup
    unlink("$font.gdf");
}

if ($#ARGV != 0) {
    print STDERR "Usage: mkgdf fontname[-size]\n";
    exit(1);
}

$origfont = $ARGV[0];

$type = "ps";
$font = $origfont;
$size = 12;
$mapline = "";

if ($font =~ m/^(ps|mf):(.+)$/) {
    $type = $1;
    $font = $2;
}
if ($font =~ m|^(.+)-([0-9.]+)$|) {
    $font = $1;
    $size = $2;
}

open(FP, "<$fontmap");
while (<FP>) {
    next if (m|^\s*#|);
    next if (m|^\s*$|);
    if (m|^(\S+)\s+(.*)\n?$|) {
        my ($in, $out) = ($1, $2);
        if ($font eq $in) {
            $font = $out;
            if ($font =~ m|^(\S+)\s+(\S.*)$|) {
              ($font, $mapline) = ($1, $2);
            }
        }
    }
}
close(FP);

if ($font =~ m/^(ps|mf):(.+)$/) {
    $type = $1;
    $font = $2;
}
if ($font =~ m|^(.+)-([0-9.]+)$|) {
    $font = $1;
    $size = $2;
}

if ($type eq "ps") {
    &ps2gdf($origfont, $font, $size, $mapline);
}
else {
    &mf2gdf($origfont, $font, $size);
}

##EOF##