unifont-6.3.20131020.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 open(A, "<combining.txt");
41 while (<A>) {
42    chomp;
43    $combining[ hex($_) ] = 1;
44 }
45 close(A);
46 #
47 # Modified by Paul Hardy, July 2008.
48 #
49 # Make pixel 64 units for greatest scale; floating point numbers in
50 # TrueType have 6 fractional bits, so this works out well (2^6 = 64).
51 # Also, make size of font a power of 2 (16 * 64) for efficient scaling
52 # to any point size in TrueType.  Made bitmask a variable for easy
53 # experimenting.
54 #
55 $pixel   = 64;
56 $descent = 2 * $pixel;
57 $ascent  = 16 * $pixel - $descent;
58 $bitmask = 25;  # round in x (doesn't really work), corner point selected
59
60 print << "END";
61 SplineFontDB: 1.0
62 FontName: unifont
63 FullName: GNU Unifont
64 FamilyName: unifont
65 Weight: Medium
66 Comments: Created from the 2008-07-06 version of the GNU Unifont
67 Comments: with Luis Gonzalez Miranda's Perl and FontForge scripts.
68 Comments: See http://www.lgm.cl/trabajos/unifont/index.en.html for
69 Comments: information on Luis' scripts.
70 Comments: See http://czyborra.com/unifont
71 Comments: and http://unifoundry.com/unifont.html
72 Comments: for information on GNU Unifont.
73 Comments: See http://fontforge.sf.net for information on FontForge.
74 Version: 1.00
75 ItalicAngle: 0
76 UnderlinePosition: -100
77 UnderlineWidth: 40
78 Ascent: $ascent
79 Descent: $descent
80 NeedsXUIDChange: 1
81 XUID: [1021 140 1293607838 5610107]
82 FSType: 0
83 PfmFamily: 33
84 TTFWeight: 500
85 TTFWidth: 5
86 Panose: 2 0 6 4 0 0 0 0 0 0
87 LineGap: 72
88 VLineGap: 0
89 OS2WinAscent: 0
90 OS2WinAOffset: 1
91 OS2WinDescent: 0
92 OS2WinDOffset: 1
93 HheadAscent: 0
94 HheadAOffset: 1
95 HheadDescent: 0
96 HheadDOffset: 1
97 ScriptLang: 1
98  1 latn 1 dflt 
99 Encoding: UnicodeBmp
100 UnicodeInterp: none
101 DisplaySize: -24
102 AntiAlias: 1
103 FitToEm: 1
104 WinInfo: 0 50 22
105 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
106 BeginChars: 65536 3
107 END
108 $count=0;
109 while(<STDIN>) {
110         chomp;
111         ($c,$d)=split(/:/);
112         $width=length($d)/4;
113         $ptwidth=$pixel * $width;
114 #       if($combining{$c}) {             # this was the original "if"
115         if ($combining[ hex($c) ]) {
116                 $ptwidth = 0;
117         }
118         $cn=hex($c);
119         # Changed "Flags: H" to "Flags: HW" to fix spaces - Paul Hardy, 2008
120         print << "END";
121 StartChar: $c
122 Encoding: $cn $cn $count
123 Width: $ptwidth
124 Flags: HW
125 TeX: 0 0 0 0
126 Fore
127 END
128
129         for($i=0;$i<16;$i++) {
130                 $l=substr($d, $i*$width/4, $width/4);
131                 $num=hex($l);
132                 $prev=0;
133                 for($j=0; $j<$width; $j++) {
134                         $x=$width - 1 - $j;
135                         $y=15 - $i;
136                         if($num%2) {
137                                 # point at i, width-1-j
138                                 if(!$prev) {
139                                         $x1=$x * $pixel + $pixel;
140                                         $y1=$y * $pixel - $descent;
141                                         $x2=$x1 + $pixel;
142                                         $y2=$y1 + $pixel;
143                                 }
144                                 $prev=1;
145                         } else {
146                                 if($prev) {
147                                         $x2=$x * $pixel + $pixel;
148                                         print << "END";
149 $x1 $y1 m $bitmask
150  $x1 $y2 l $bitmask
151  $x2 $y2 l $bitmask
152  $x2 $y1 l $bitmask
153  $x1 $y1 l $bitmask
154 END
155                                 }
156                                 $prev=0;
157                         }
158                         $num=int($num/2);
159                 }
160                 if($prev) {
161                         $x2=0;
162                         print << "END";
163 $x1 $y1 m $bitmask
164  $x1 $y2 l $bitmask
165  $x2 $y2 l $bitmask
166  $x2 $y1 l $bitmask
167  $x1 $y1 l $bitmask
168 END
169                 }
170         }
171         print << "END";
172 EndSplineSet
173 EndChar
174 END
175         $count++;
176 }
177 print << "END";
178 EndChars
179 EndSplineFont
180 END