unifont-6.3.20140202.tar.gz
[unifont.git] / src / hex2sfd
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2005 Luis Gonzalez Miranda
4 #
5 # hex2sfd created in 2005 by Luis Gonzalez Miranda, http://www.lgm.cl
6 #
7 # LICENSE:
8 #
9 #    This program is free software: you can redistribute it and/or modify
10 #    it under the terms of the GNU General Public License as published by
11 #    the Free Software Foundation, either version 2 of the License, or
12 #    (at your option) any later version.
13 #  
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
17 #    GNU General Public License for more details.
18 #  
19 #    You should have received a copy of the GNU General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22 #
23 # %combining = ();
24 # open(A, "<combining.txt");
25 # while(<A>) {
26 #       chomp;
27 #       $combining{$A} = 1;
28 # }
29 # close(A);
30 #
31 # Modified by Paul Hardy, June 2008.
32 #
33 # The original code above didn't work properly.  The replacement code
34 # below wastes RAM, but it works as a quick fix.
35 #
36 @combining = ();
37 for ($i = 0; $i < 65536; $i++) {
38    push(@combining, 0);
39 }
40 if ($#ARGV < 0) {
41    open(A, "<", "combining.txt");
42 }
43 else {
44    open(A, "<", $ARGV[0]);
45 }
46 while (<A>) {
47    chomp;
48    $combining[ hex($_) ] = 1;
49 }
50 close(A);
51 #
52 # Modified by Paul Hardy, July 2008.
53 #
54 # Make pixel 64 units for greatest scale; floating point numbers in
55 # TrueType have 6 fractional bits, so this works out well (2^6 = 64).
56 # Also, make size of font a power of 2 (16 * 64) for efficient scaling
57 # to any point size in TrueType.  Made bitmask a variable for easy
58 # experimenting.
59 #
60 $pixel   = 64;
61 $descent = 2 * $pixel;
62 $ascent  = 16 * $pixel - $descent;
63 $bitmask = 25;  # round in x (doesn't really work), corner point selected
64
65 print << "END";
66 SplineFontDB: 1.0
67 FontName: unifont
68 FullName: GNU Unifont
69 FamilyName: unifont
70 Weight: Medium
71 Comments: Created from the 2008-07-06 version of the GNU Unifont
72 Comments: with Luis Gonzalez Miranda's Perl and FontForge scripts.
73 Comments: See http://www.lgm.cl/trabajos/unifont/index.en.html for
74 Comments: information on Luis' scripts.
75 Comments: See http://czyborra.com/unifont
76 Comments: and http://unifoundry.com/unifont.html
77 Comments: for information on GNU Unifont.
78 Comments: See http://fontforge.sf.net for information on FontForge.
79 Version: 1.00
80 ItalicAngle: 0
81 UnderlinePosition: -100
82 UnderlineWidth: 40
83 Ascent: $ascent
84 Descent: $descent
85 NeedsXUIDChange: 1
86 XUID: [1021 140 1293607838 5610107]
87 FSType: 0
88 PfmFamily: 33
89 TTFWeight: 500
90 TTFWidth: 5
91 Panose: 2 0 6 4 0 0 0 0 0 0
92 LineGap: 72
93 VLineGap: 0
94 OS2WinAscent: 0
95 OS2WinAOffset: 1
96 OS2WinDescent: 0
97 OS2WinDOffset: 1
98 HheadAscent: 0
99 HheadAOffset: 1
100 HheadDescent: 0
101 HheadDOffset: 1
102 ScriptLang: 1
103  1 latn 1 dflt 
104 Encoding: UnicodeBmp
105 UnicodeInterp: none
106 DisplaySize: -24
107 AntiAlias: 1
108 FitToEm: 1
109 WinInfo: 0 50 22
110 TeXData: 1 0 0 346030 173015 115343 0 1048576 115343 783286 444596 497025 792723 393216 433062 380633 303038 157286 324010 404750 52429 2506097 1059062 262144
111 BeginChars: 65536 3
112 END
113 $count=0;
114 while(<STDIN>) {
115         chomp;
116         ($c,$d)=split(/:/);
117         $width=length($d)/4;
118         $ptwidth=$pixel * $width;
119 #       if($combining{$c}) {             # this was the original "if"
120         if ($combining[ hex($c) ]) {
121                 $ptwidth = 0;
122         }
123         $cn=hex($c);
124         # Changed "Flags: H" to "Flags: HW" to fix spaces - Paul Hardy, 2008
125         print << "END";
126 StartChar: $c
127 Encoding: $cn $cn $count
128 Width: $ptwidth
129 Flags: HW
130 TeX: 0 0 0 0
131 Fore
132 END
133
134         for($i=0;$i<16;$i++) {
135                 $l=substr($d, $i*$width/4, $width/4);
136                 $num=hex($l);
137                 $prev=0;
138                 for($j=0; $j<$width; $j++) {
139                         $x=$width - 1 - $j;
140                         $y=15 - $i;
141                         if($num%2) {
142                                 # point at i, width-1-j
143                                 if(!$prev) {
144                                         $x1=$x * $pixel + $pixel;
145                                         $y1=$y * $pixel - $descent;
146                                         $x2=$x1 + $pixel;
147                                         $y2=$y1 + $pixel;
148                                 }
149                                 $prev=1;
150                         } else {
151                                 if($prev) {
152                                         $x2=$x * $pixel + $pixel;
153                                         print << "END";
154 $x1 $y1 m $bitmask
155  $x1 $y2 l $bitmask
156  $x2 $y2 l $bitmask
157  $x2 $y1 l $bitmask
158  $x1 $y1 l $bitmask
159 END
160                                 }
161                                 $prev=0;
162                         }
163                         $num=int($num/2);
164                 }
165                 if($prev) {
166                         $x2=0;
167                         print << "END";
168 $x1 $y1 m $bitmask
169  $x1 $y2 l $bitmask
170  $x2 $y2 l $bitmask
171  $x2 $y1 l $bitmask
172  $x1 $y1 l $bitmask
173 END
174                 }
175         }
176         print << "END";
177 EndSplineSet
178 EndChar
179 END
180         $count++;
181 }
182 print << "END";
183 EndChars
184 EndSplineFont
185 END