/usr/bin/hex2sfd is in unifont-bin 1:10.0.07-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | #!/usr/bin/perl
#
# Copyright (C) 2005 Luis Alejandro Gonzalez Miranda
#
# hex2sfd created in 2005 by Luis Alejandro Gonzalez Miranda, http://www.lgm.cl
#
# LICENSE:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# June 2008: modifications by Paul Hardy for the Unifont 5.1 build.
#
# July 2014: modifications by Paul Hardy as follows:
#
# - Updated comments to use Luis' full name and add a link to
# the Unifont page on savannah.gnu.org.
# - Store combining character code points for the entire Unicode
# range, not just for the Basic Multilingual Plane.
# - Change "Encoding: UnicodeBmp" by detecting whether the highest
# glyph is in the Basic Multilingual Plane or above that; if above,
# use "Encoding: Unicode" instead.
# - Add explicit definitions for three TrueType code points:
# ".notdef", ".null", and "nonmarkingreturn". These override
# the defaults that Fontforge creates. The ".notdef" and
# "nonmarkingreturn" glyphs now have widths of 8 pixels
# (512 units in the SFD output file).
# - Calculate exact number of glyphs in the font for "BeginChars" entry.
# - Convert the pixel outline drawing portion of this script
# to a subroutine.
# - Add "uni" prefix to StartChar description of Unicode code points.
# - Updated comments to use Luis' full name and add a link to
#
# 30 June 2017 [Paul Hardy]:
# - Modifies combining character positioning to position properly
# over preceding glyph in several applications.
#
# 8 July 2017 [Paul Hardy]:
# - Handles x-offset field added to font/plane*/plane*-combining.txt
# files. This allows handling of special situations such as double
# diacritics, which combine with the letter on either side of them.
#
# 11 July 2017 [Paul Hardy]:
# - Convert number assigned to $max_code_point with hex(), based on
# request of Leroy Vargas-Ortiz.
# - Scale $xoffset by $pixel for combining characters.
#
#
# Read the list of combining characters and the x-axis (horizontal)
# offset of each one.
#
@combining = ();
@x_origin = ();
for ($i = 0; $i < 0x110000; $i++) {
push (@combining, 0);
push (@x_origin, 0);
}
if ($#ARGV < 0) {
open (A, "<", "combining.txt") or die ("Cannot open combining.txt.\n");
}
else {
open (A, "<", $ARGV[0]) or die ("Cannot open specified combining file for input.\n");
}
$maxcombining = 0;
while (<A>) {
chomp;
($a, $b) = split (/:/);
$codepoint = hex ($a);
$combining[ $codepoint ] = 1;
$x_origin [ $codepoint ] = $b;
if ($codepoint > $maxcombining) {
$maxcombining = $codepoint;
}
}
close (A) or die ("Cannot properly close combining input file.\n");
$nglyphs = 0; # number of glyphs in font (none defined yet)
@codepoints = (); # code points of hex bitmaps
@bitmaps = (); # the corresponding hex bitmaps
#
# Add three special characters for TrueType; use these instead of
# the Fontforge defaults for these three characters.
#
push (@codepoints, ".notdef");
push (@bitmaps, "0000007E665A5A7A76767E76767E0000");
$nglyphs++;
push (@codepoints, ".null");
push (@bitmaps, "");
$nglyphs++;
push (@codepoints, "nonmarkingreturn");
push (@bitmaps, "00000000000000000000000000000000");
$nglyphs++;
while(<STDIN>) {
chomp;
($c,$d) = split (/:/);
push (@codepoints, $c);
push (@bitmaps, $d);
$nglyphs++;
}
$max_code_point = hex ($codepoints[ $nglyphs - 1 ]);
# Encoding tag: Is highest glyph above Plane 0?
if ($max_code_point > 0xFFFF) {
$encoding = "Unicode";
}
else {
$encoding = "UnicodeBmp";
}
#
# Modified by Paul Hardy, July 2008.
#
# Make pixel 64 units for greatest scale; floating point numbers in
# TrueType have 6 fractional bits, so this works out well (2^6 = 64).
# Also, make size of font a power of 2 (16 * 64) for efficient scaling
# to any point size in TrueType. Made bitmask a variable for easy
# experimenting.
#
$pixel = 64;
$descent = 2 * $pixel;
$ascent = 16 * $pixel - $descent;
$bitmask = 25; # round in x (doesn't really work), corner point selected
print << "END" or die ("Cannot print to stdout.\n");
SplineFontDB: 1.0
FontName: unifont
FullName: GNU Unifont
FamilyName: unifont
Weight: Medium
Comments: Created from GNU Unifont
Comments: with Luis Alejandro Gonzalez Miranda's Perl and FontForge scripts.
Comments: See http://www.lgm.cl/trabajos/unifont/index.en.html for
Comments: information on Luis' scripts. See
Comments: http://savannah.gnu.org/projects/unifont,
Comments: http://czyborra.com/unifont, and
Comments: http://unifoundry.com/unifont.html for information on GNU Unifont.
Comments: See http://fontforge.sf.net for information on FontForge.
Version: 1.00
ItalicAngle: 0
UnderlinePosition: -100
UnderlineWidth: 40
Ascent: $ascent
Descent: $descent
NeedsXUIDChange: 1
XUID: [1021 140 1293607838 5610107]
FSType: 0
PfmFamily: 33
TTFWeight: 500
TTFWidth: 5
Panose: 2 0 6 4 0 0 0 0 0 0
LineGap: 72
VLineGap: 0
OS2WinAscent: 0
OS2WinAOffset: 1
OS2WinDescent: 0
OS2WinDOffset: 1
HheadAscent: 0
HheadAOffset: 1
HheadDescent: 0
HheadDOffset: 1
ScriptLang: 1
1 latn 1 dflt
Encoding: $encoding
UnicodeInterp: none
DisplaySize: -24
AntiAlias: 1
FitToEm: 1
WinInfo: 0 50 22
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
BeginChars: 65536 $nglyphs
END
#
# Print outlines for all glyphs using Fontforge's
# Spline Font Database (.sfd) format.
#
# $count=0; # number of glyphs created so far.
for ($count = 0; $count < $nglyphs; $count++) {
$c = $codepoints[ $count ];
$d = $bitmaps[ $count ];
outline ($count, $c, $d);
}
# while (<STDIN>) {
# chomp;
# ($c,$d)=split(/:/);
# outline ($count, $c, $d);
# $count++;
# }
print << "END" or die ("Cannot print to stdout.\n");
EndChars
EndSplineFont
END
exit;
#
# Print the outlines of a glyph's pixels.
#
# Parameters:
# - Position in font
# - Glyph non-Unicode name or Unicode hexadecimal code point
# - Unifont hexadecimal string to render glyph.
#
sub outline {
my $count = $_[0];
my $c = $_[1];
my $d = $_[2];
$width = length($d)/4;
$ptwidth = $pixel * $width;
$xoffset = 0;
if ( $c =~ m/^[0-9A-Fa-f]+$/ ) {
$charname = "uni$c";
$codepoint = hex ($c);
if ($combining[ $codepoint ]) {
$xoffset = $x_origin[ $codepoint ] * $pixel;
$ptwidth = 0;
}
$cn = hex ($c);
}
else {
$charname = $c;
$cn = -1;
}
# Changed "Flags: H" to "Flags: HW" to fix spaces - Paul Hardy, 2008
print << "END" or die ("Cannot print to stdout.\n");
StartChar: $charname
Encoding: $cn $cn $count
Width: $ptwidth
Flags: HW
TeX: 0 0 0 0
Fore
END
# for each line in the glyph
for($i=0;$i<16;$i++) {
$l=substr($d, $i*$width/4, $width/4);
$num=hex($l);
$prev=0; # Start of row; calculate y coordinates.
for($j=0; $j<$width; $j++) {
$x=$width - 1 - $j;
$y=15 - $i;
if($num%2) {
# point at i, width-1-j
if(!$prev) {
$x1=$x * $pixel + $pixel + $xoffset;
$y1=$y * $pixel - $descent;
$x2=$x1 + $pixel + $xoffset;
$y2=$y1 + $pixel;
}
$prev=1;
} else {
if($prev) {
$x2=$x * $pixel + $pixel + $xoffset;
print << "END" or die ("Cannot print to stdout.\n");
$x1 $y1 m $bitmask
$x1 $y2 l $bitmask
$x2 $y2 l $bitmask
$x2 $y1 l $bitmask
$x1 $y1 l $bitmask
END
}
$prev=0;
}
$num=int($num/2);
}
if($prev) {
$x2=$xoffset;
print << "END" or die ("Cannot print to stdout.\n");
$x1 $y1 m $bitmask
$x1 $y2 l $bitmask
$x2 $y2 l $bitmask
$x2 $y1 l $bitmask
$x1 $y1 l $bitmask
END
}
}
print << "END" or die ("Cannot print to stdout.\n");
EndSplineSet
EndChar
END
}
|