File: make_EBLC

package info (click to toggle)
xfonts-mona 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 7,028 kB
  • ctags: 197
  • sloc: perl: 2,600; makefile: 329; lisp: 68
file content (232 lines) | stat: -rwxr-xr-x 5,729 bytes parent folder | download | duplicates (3)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/perl
#
# usage: usage: make_EBLC size1 BDF1 size2 BDF2 ... sizen BDFn
#
# build an EBLC(Embedded Bitmap LoCation, or bloc in MacOS) table from BDF(BIT)
# sets and dump it into stdout.
#
# BUGS: currently only indexFormat 1 is supported.
#       since it uses BDF as a source, vertical metrics isn't cared.
#       many parameters are fixed.
#
#	2002/2/3, by 1@2ch
#	* public domain *
#

require 'lib_util.pl';
require 'lib_metric.pl';

sub usage() {
    print "usage: make_EBLC size1 BDF1 size2 BDF2 ... sizen BDFn\n";
    exit 1;
}

@ppem = ();
@bdfs = ();
0 == @ARGV && usage();
while(0 < @ARGV) {
    push(@ppem, shift(@ARGV));
    push(@bdfs, shift(@ARGV));
}


# subtable size : 48bytes
sub subtable1($$$$$$$$$$$$$$$) {
    my ($csize, 
	$subtable,
	$subtable_chars,
	$subtable_start,
	$subtable_len,
	
	$HminOriginSB,
	$HminAdvanceSB,
	$HmaxBeforeBL,
	$HminAfterBL,
	$HwidMax,
	
	$VminOriginSB,
	$VminAdvanceSB,
	$VmaxBeforeBL,
	$VminAfterBL,
	$VwidMax) = @_;

    # indexSubTableArrayOffset
    wuint32((8 + $total_subtables*48) + $subtable_start);
    # indexTableSize
    wuint32(8 + $subtable_len);
    # numberOfIndexSubTables : 1
    wuint32(1);
    # colorRef : 0
    wuint32(0);
    # hori
    wsbitLineMetrics($HmaxBeforeBL,	# ascender
		     $HminAfterBL,	# descender
		     $HwidMax,		# widmax
		     1,0,0,		# calet p/q, +offset
		     $HminOriginSB, $HminAdvanceSB, 
		     $HmaxBeforeBL, $HminAfterBL);
    # vert (dirty assumption!)
    wsbitLineMetrics($HwidMax,		# ascender
		     0,			# descender
		     $VwidMax,		# widmax
		     0,1,0,		# calet p/q, +offset
		     $VminOriginSB, $VminAdvanceSB,
		     $VmaxBeforeBL, $VminAfterBL);
    # startGlyphIndex
    wuint16(0);
    # endGlyphIndex
    wuint16($subtable_chars-1);
    # ppemX : point size
    wuint8($csize);
    # ppemY : point size
    wuint8($csize);
    # bitDepth : 1
    wuint8(1);
    # flags : 0x01 (flgHorizontal)
    wuint8(0x01);
}

sub initialize1() {
    $index_subtable = '';
    $index_subtable_chars = 0;
    $bdat_local_offset = 0;

    $HminOriginSB = 999;
    $HminAdvanceSB = 999;
    $HmaxBeforeBL = -999;
    $HminAfterBL = 999;
    $HwidMax = 0;
    
    $VminOriginSB = 0;
    $VminAdvanceSB = 999;
    $VmaxBeforeBL = 0;
    $VminAfterBL = 999;
    $VwidMax = 0;
}

# format 1
sub indexSubTable1($) {
    open(IN, $_[0]) || die("open: $_[0]: $!");
    my $bw, $bh, $hox, $hoy, $hbytes, $had, $vad;
    while(<IN>) {
	chop;
	my @F = split(/\s+/);
	my $c = shift(@F);
	if ($c eq 'BBX') {
	    ($bw, $bh, $hox, $hoy) = @F;
	    # HminOriginSB : min. of $hox
	    # HminAdvanceSB : min. of $had-$hox-$bw
	    # HmaxBeforeBL : max of $hoy+$bh
	    # HminAfterBL : min. of $hoy
	    $HminOriginSB = $hox if ($hox < $HminOriginSB);
	    $HminAdvanceSB = $had-$hox-$bw if ($had-$hox-$bw < $HminAdvanceSB);
	    $HmaxBeforeBL = $hoy+$bh if ($HmaxBeforeBL < $hoy+$bh);
	    $HminAfterBL = $hoy if ($hoy < $HminAfterBL);
	    $HwidMax = $bw if ($HwidMax < $bw);

	    # VminOriginSB = 0
	    # VminAdvanceSB = min. of $bh
	    # VmaxBeforeBL = 0
	    # VminAfterBL = min. of $bw
	    $VminAdvanceSB = $bh if ($bh < $VminAdvanceSB);
	    $VminAfterBL = $bw if ($bw < $VminAfterBL);
	    $VwidMax = $bh if ($VwidMax < $bh);
	    
	    $hbytes = int(($bw+7)/8);
	} elsif ($c eq 'DWIDTH') {
	    ($had, $vad_dummy) = @F;
	} elsif ($c eq 'ENDCHAR') {
	    $index_subtable .= pack('N', $bdat_local_offset);
	    $index_subtable_chars++;
	    $bdat_local_offset += $hbytes * $bh + 8;
	}
    }
    close(IN);
}

## initialize

$index_subtable_offset = 0;
$bdat_total_offset = 4;

initialize1();
for(my $i = 0; $i < 0+@ppem; $i++) {
    indexSubTable1($bdfs[$i]);
    
    my $len = 8 + 8 + length($index_subtable);
    push(@map_csizes, $ppem[$i]);
    push(@map_index_subtables, $index_subtable);
    push(@map_index_subtable_chars, $index_subtable_chars);
    push(@map_index_subtable_starts, $index_subtable_offset);
    push(@map_index_subtable_lens, $len);
    push(@map_index_subtable_bdat_total_offset, $bdat_total_offset);
    
    push(@map_HminOriginSB, $HminOriginSB);
    push(@map_HminAdvanceSB, $HminAdvanceSB);
    push(@map_HmaxBeforeBL, $HmaxBeforeBL);
    push(@map_HminAfterBL, $HminAfterBL);
    push(@map_HwidMax, $HwidMax);
    
    push(@map_VminOriginSB, $VminOriginSB);
    push(@map_VminAdvanceSB, $VminAdvanceSB);
    push(@map_VmaxBeforeBL, $VmaxBeforeBL);
    push(@map_VminAfterBL, $VminAfterBL);
    push(@map_VwidMax, $VwidMax);
    
    $index_subtable_offset += $len;
    $bdat_total_offset += $bdat_local_offset;
    initialize1();
}

$total_subtables = 0+@map_csizes;

## write

wopen('&STDOUT');

# version number (0x00020000 fixed)
wuint32(0x00020000);
# num of subtables
wuint32($total_subtables);

for(my $i = 0; $i < $total_subtables; $i++) {
    subtable1($map_csizes[$i],
	       $map_index_subtables[$i],
	       $map_index_subtable_chars[$i],
	       $map_index_subtable_starts[$i],
	       $map_index_subtable_lens[$i],

	       $map_HminOriginSB[$i],
	       $map_HminAdvanceSB[$i],
	       $map_HmaxBeforeBL[$i],
	       $map_HminAfterBL[$i],
	       $map_HwidMax[$i],
	       
	       $map_VminOriginSB[$i],
	       $map_VminAdvanceSB[$i],
	       $map_VmaxBeforeBL[$i],
	       $map_VminAfterBL[$i],
	       $map_VwidMax[$i]);
}

for(my $i = 0; $i < $total_subtables; $i++) {
    # firstGlyphIndex
    wuint16(0);
    # lastGlyphIndex
    wuint16($map_index_subtable_chars[$i]-1);
    # additionalOffsetToIndexSubtable
    wuint32(8);

    # indexSubtable

    # indexformat: 1
    wuint16(1);
    # imageformat: 6
    wuint16(6);
    # imageDataOffset
    wuint32($map_index_subtable_bdat_total_offset[$i]);
    # offsetArray
    wstrn($map_index_subtables[$i]);
}

wclose();