~ubuntu-branches/ubuntu/wily/ntop/wily-proposed

« back to all changes in this revision

Viewing changes to gdchart0.94c/gd-1.8.3/bdftogd

  • Committer: Bazaar Package Importer
  • Author(s): Dennis Schoen
  • Date: 2002-04-12 11:38:47 UTC
  • Revision ID: james.westby@ubuntu.com-20020412113847-4k4yydw0pzybc6g8
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
#
 
4
# Simple convertor from bdf to gd font format.
 
5
#
 
6
# Author: Jan Pazdziora, adelton@fi.muni.cz, http://www.fi.muni.cz/~adelton/
 
7
# at Faculty of Informatics, Masaryk University in Brno, Czech Republic.
 
8
#
 
9
# Example of use:
 
10
# fstobdf -s fontserverhost:7100 -fn 8x16 | ./bdftogd FontLarge gdfontl
 
11
#
 
12
 
 
13
use strict;
 
14
 
 
15
my $VERSION = '0.60';
 
16
my $now = localtime;
 
17
 
 
18
if (@ARGV != 2)
 
19
        { die "usage: bdftogd fontname filename, eg. bdftogd FontLarge gdfontl\n"; }
 
20
 
 
21
my $gdname = shift;
 
22
$gdname = 'gd' . $gdname unless $gdname =~ /^gd/i;
 
23
 
 
24
my $filename = shift;
 
25
$filename = 'gd' . $filename unless $filename =~ /^gd/i;
 
26
 
 
27
if (-f "$filename.c") { die "File $filename.c already exists, won't overwrite\n"; }
 
28
if (-f "$filename.h") { die "File $filename.h already exists, won't overwrite\n"; }
 
29
 
 
30
my ($width, $height);
 
31
my (@data, @left, @bottom);
 
32
my ($globalleft, $globaltop);
 
33
 
 
34
my ($minchar, $maxchar);
 
35
 
 
36
my ($copyright, $fontdef);
 
37
 
 
38
my $currentchar;
 
39
my $gobitmap = 0;
 
40
 
 
41
 
 
42
while (<>)
 
43
        {
 
44
        chomp;
 
45
        s/\r$//;
 
46
        my ($tag, $value) = split / /, $_, 2;
 
47
        die "Font is not fixed width\n"
 
48
                        if $tag eq 'SPACING' and not $value =~ /[CM]/i;
 
49
        
 
50
        $currentchar = $value if $tag eq 'ENCODING';
 
51
        $minchar = $currentchar if not defined $minchar
 
52
                or $currentchar < $minchar;
 
53
        $maxchar = $currentchar if not defined $maxchar
 
54
                or $currentchar > $maxchar;
 
55
        
 
56
        if ($tag eq 'ENDCHAR')
 
57
                {
 
58
                $gobitmap = 0;
 
59
                my $bottom = $globaltop - $bottom[$currentchar];
 
60
                
 
61
 
 
62
                if ($bottom > 0)
 
63
                        { $data[$currentchar] = substr $data[$currentchar], 0, length($data[$currentchar]) - $bottom * $width; }
 
64
                else
 
65
                        { $data[$currentchar] .= '0' x (-$bottom * $width); }
 
66
                }
 
67
 
 
68
        if ($tag eq 'FONTBOUNDINGBOX')
 
69
                {
 
70
                my ($tag, $wid, $hei, $left, $top) = split / /;
 
71
                if (defined $top)
 
72
                        {
 
73
                        $globalleft = $left;
 
74
                        $globaltop = $top;
 
75
                        $height = $hei;
 
76
                        $width = $wid;
 
77
                        }
 
78
                }
 
79
        if ($tag eq 'FONT' and not defined $fontdef)
 
80
                { $fontdef = $value; }
 
81
        if ($tag eq 'COPYRIGHT' and not defined $copyright)
 
82
                { $copyright = $value; }
 
83
        
 
84
        if ($tag eq 'BBX')
 
85
                {
 
86
                my ($tag, $wid, $hei, $left, $bottom) = split / /;
 
87
                if (defined $bottom)
 
88
                        {
 
89
                        $left[$currentchar] = $left;
 
90
                        $bottom[$currentchar] = $bottom;
 
91
                        }
 
92
                }
 
93
 
 
94
        if ($gobitmap)
 
95
                {
 
96
                my $value = pack 'H*', $_;
 
97
                my $bits = unpack 'B*', $value;
 
98
                $bits = ('0' x $left[$currentchar]) . $bits;
 
99
                $bits .= '0' x ($width - length $bits);
 
100
                $bits = substr $bits, 0, $width;
 
101
                $data[$currentchar] .= $bits;
 
102
                }
 
103
        
 
104
        if ($tag eq 'BITMAP')
 
105
                {
 
106
                $gobitmap = 1;
 
107
                $data[$currentchar] = '';
 
108
                }
 
109
        }
 
110
 
 
111
my $info = <<"EOF";
 
112
/*
 
113
        This is a header file for gd font, generated using
 
114
        bdftogd version $VERSION by Jan Pazdziora, adelton\@fi.muni.cz
 
115
        from bdf font
 
116
        $fontdef
 
117
        at $now.
 
118
EOF
 
119
 
 
120
if (defined $copyright)
 
121
        {
 
122
        $info .= <<"EOF";
 
123
        The original bdf was holding following copyright:
 
124
        $copyright
 
125
 */
 
126
EOF
 
127
        }
 
128
else
 
129
        {
 
130
        $info .= <<"EOF";
 
131
        No copyright info was found in the original bdf.
 
132
 */
 
133
EOF
 
134
        }
 
135
 
 
136
open FILEC, "> $filename.c" or die "Error writing $filename.c: $!\n";
 
137
open FILEH, "> $filename.h" or die "Error writing $filename.h: $!\n";
 
138
print FILEC <<"EOF";
 
139
 
 
140
$info
 
141
 
 
142
#include "$filename.h"
 
143
 
 
144
char ${gdname}Data[] = {
 
145
EOF
 
146
 
 
147
$minchar = 0 unless defined $minchar;
 
148
$maxchar = 255 unless defined $maxchar;
 
149
for (my $i = $minchar; $i <= $maxchar; $i++)
 
150
        {
 
151
        $data[$i] = '' unless defined $data[$i];
 
152
        $data[$i] = '0' x ($width * $height - length $data[$i]) . $data[$i];
 
153
        
 
154
        print FILEC "/* Char $i */\n";
 
155
        for my $line (0 .. $height - 1)
 
156
                { print FILEC join ',', split(//, substr($data[$i], $line * $width, $width)), "\n"; }
 
157
 
 
158
        print FILEC "\n";
 
159
 
 
160
        next;
 
161
        
 
162
        for my $line (0 .. $height - 1)
 
163
                { print substr($data[$i], $line * $width, $width), "\n"; }
 
164
        }
 
165
 
 
166
my $capdef = "\U_${filename}_H_";
 
167
 
 
168
print FILEC <<"EOF";
 
169
 
 
170
};
 
171
 
 
172
gdFont ${gdname}Rep = {
 
173
        @{[ $maxchar - $minchar + 1]},
 
174
        $minchar,
 
175
        $width,
 
176
        $height,
 
177
        ${gdname}Data
 
178
};
 
179
 
 
180
gdFontPtr ${gdname} = &${gdname}Rep;
 
181
 
 
182
/* This file has not been truncated. */
 
183
 
 
184
EOF
 
185
 
 
186
 
 
187
close FILEC;
 
188
 
 
189
print FILEH <<"EOF";
 
190
 
 
191
#ifndef $capdef
 
192
#define $capdef 1
 
193
 
 
194
$info
 
195
 
 
196
#include "gd.h"
 
197
 
 
198
extern gdFontPtr $gdname;
 
199
 
 
200
#endif
 
201
 
 
202
EOF
 
203
 
 
204
1;
 
205