3 # Copyright (C) 2005 Luis Alejandro Gonzalez Miranda
5 # hex2sfd created in 2005 by Luis Alejandro Gonzalez Miranda, http://www.lgm.cl
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.
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.
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/>.
23 # June 2008: modifications by Paul Hardy for the Unifont 5.1 build.
25 # July 2014: modifications by Paul Hardy as follows:
27 # - Updated comments to use Luis' full name and add a link to
28 # the Unifont page on savannah.gnu.org.
29 # - Store combining character code points for the entire Unicode
30 # range, not just for the Basic Multilingual Plane.
31 # - Change "Encoding: UnicodeBmp" by detecting whether the highest
32 # glyph is in the Basic Multilingual Plane or above that; if above,
33 # use "Encoding: Unicode" instead.
34 # - Add explicit definitions for three TrueType code points:
35 # ".notdef", ".null", and "nonmarkingreturn". These override
36 # the defaults that Fontforge creates. The ".notdef" and
37 # "nonmarkingreturn" glyphs now have widths of 8 pixels
38 # (512 units in the SFD output file).
39 # - Calculate exact number of glyphs in the font for "BeginChars" entry.
40 # - Convert the pixel outline drawing portion of this script
42 # - Add "uni" prefix to StartChar description of Unicode code points.
45 # Read the list of combining characters, which will have zero width.
48 for ($i = 0; $i < 0x110000; $i++) {
52 open (A, "<", "combining.txt") or die ("Cannot open combining.txt.\n");
55 open (A, "<", $ARGV[0]) or die ("Cannot open specified combining file for input.\n");
60 $codepoint = hex ($_);
61 $combining[ $codepoint ] = 1;
62 if ($codepoint > $maxcombining) {
63 $maxcombining = $codepoint;
66 close (A) or die ("Cannot properly close combining input file.\n");
68 $nglyphs = 0; # number of glyphs in font (none defined yet)
69 @codepoints = (); # code points of hex bitmaps
70 @bitmaps = (); # the corresponding hex bitmaps
73 # Add three special characters for TrueType; use these instead of
74 # the Fontforge defaults for these three characters.
76 push (@codepoints, ".notdef");
77 push (@bitmaps, "0000007E665A5A7A76767E76767E0000");
80 push (@codepoints, ".null");
84 push (@codepoints, "nonmarkingreturn");
85 push (@bitmaps, "00000000000000000000000000000000");
90 ($c,$d) = split (/:/);
91 push (@codepoints, $c);
95 $max_code_point=$codepoints[ $nglyphs - 1 ];
97 # Encoding tag: Is highest glyph above Plane 0?
98 if ($max_code_point > 0xFFFF) {
99 $encoding = "Unicode";
102 $encoding = "UnicodeBmp";
106 # Modified by Paul Hardy, July 2008.
108 # Make pixel 64 units for greatest scale; floating point numbers in
109 # TrueType have 6 fractional bits, so this works out well (2^6 = 64).
110 # Also, make size of font a power of 2 (16 * 64) for efficient scaling
111 # to any point size in TrueType. Made bitmask a variable for easy
115 $descent = 2 * $pixel;
116 $ascent = 16 * $pixel - $descent;
117 $bitmask = 25; # round in x (doesn't really work), corner point selected
119 print << "END" or die ("Cannot print to stdout.\n");
122 FullName: GNU Unifont
125 Comments: Created from GNU Unifont
126 Comments: with Luis Alejandro Gonzalez Miranda's Perl and FontForge scripts.
127 Comments: See http://www.lgm.cl/trabajos/unifont/index.en.html for
128 Comments: information on Luis' scripts. See
129 Comments: http://savannah.gnu.org/projects/unifont,
130 Comments: http://czyborra.com/unifont, and
131 Comments: http://unifoundry.com/unifont.html for information on GNU Unifont.
132 Comments: See http://fontforge.sf.net for information on FontForge.
135 UnderlinePosition: -100
140 XUID: [1021 140 1293607838 5610107]
145 Panose: 2 0 6 4 0 0 0 0 0 0
164 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
165 BeginChars: 65536 $nglyphs
169 # Print outlines for all glyphs using Fontforge's
170 # Spline Font Database (.sfd) format.
172 # $count=0; # number of glyphs created so far.
174 for ($count = 0; $count < $nglyphs; $count++) {
175 $c = $codepoints[ $count ];
176 $d = $bitmaps[ $count ];
177 outline ($count, $c, $d);
182 # ($c,$d)=split(/:/);
183 # outline ($count, $c, $d);
187 print << "END" or die ("Cannot print to stdout.\n");
195 # Print the outlines of a glyph's pixels.
199 # - Glyph non-Unicode name or Unicode hexadecimal code point
200 # - Unifont hexadecimal string to render glyph.
207 $ptwidth=$pixel * $width;
208 if ( $c =~ m/^[0-9A-Fa-f]+$/ ) {
210 if ($combining[ hex($c) ]) {
219 # Changed "Flags: H" to "Flags: HW" to fix spaces - Paul Hardy, 2008
220 print << "END" or die ("Cannot print to stdout.\n");
222 Encoding: $cn $cn $count
229 for($i=0;$i<16;$i++) {
230 $l=substr($d, $i*$width/4, $width/4);
233 for($j=0; $j<$width; $j++) {
237 # point at i, width-1-j
239 $x1=$x * $pixel + $pixel;
240 $y1=$y * $pixel - $descent;
247 $x2=$x * $pixel + $pixel;
248 print << "END" or die ("Cannot print to stdout.\n");
262 print << "END" or die ("Cannot print to stdout.\n");
271 print << "END" or die ("Cannot print to stdout.\n");