unifont-8.0.01.tar.gz
[unifont.git] / src / hex2bdf
index fc4f02d50d91ea9bacd8a950fb888b7216ad32d8..5255120e75587b0207131909035b5aee9880b8df 100755 (executable)
 #    You should have received a copy of the GNU General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+#    First, parse command-line options.  Two are available:
+#
+#       - Font name (-f name or --font name)
+#       - Lines per glyph (-lnn or --lines nn, where nn is a decimal number)
+#
+use Getopt::Long;
+
+$result = GetOptions (
+             "copyright|c=s" => \$copyright, # Copyright string
+             "font|f=s"      => \$font_name, # XLFD FAMILY_NAME
+             "rows|r=i"      => \$vpixels,   # XLFD PIXEL_SIZE; vertical pixels
+             "version|v=s"   => \$version    # Version of this font
+             );
+
+if (not $font_name) {
+   $font_name = "Unifont";
+}
+if (not $vpixels) {
+   $vpixels  = 16;
+}
+if (not $version) {
+   $version = "1.0";
+}
+
+$point_size   = $vpixels;
+$point_size10 = 10 * $point_size;
 
-while (<>) { $glyph{$1} = $2 if /(....):(.+)\n/; }
+while (<>) { chomp; $glyph{$1} = $2 if /^([0-9a-fA-F]+):([0-9a-fA-F]+)/; }
 @chars = sort keys %glyph;
 $nchars = $#chars + 1;
-# dbmopen (%charname, "/usr/share/unicode/unidata/charname.db", 0);
+
 
 print "STARTFONT 2.1
-FONT -gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1
-SIZE 16 75 75
-FONTBOUNDINGBOX 16 16 0 -2
-STARTPROPERTIES 3
+FONT -gnu-${font_name}-Medium-R-Normal-Sans-${vpixels}-${point_size10}-75-75-c-80-iso10646-1
+SIZE $point_size 75 75
+FONTBOUNDINGBOX $vpixels $vpixels 0 -2
+STARTPROPERTIES 24
+COPYRIGHT \"${copyright}\"
+FONT_VERSION \"${version}\"
+FONT_TYPE \"Bitmap\"
+FOUNDRY \"GNU\"
+FAMILY_NAME \"${font_name}\"
+WEIGHT_NAME \"Medium\"
+SLANT \"R\"
+SETWIDTH_NAME \"Normal\"
+ADD_STYLE_NAME \"Sans Serif\"
+PIXEL_SIZE ${vpixels}
+POINT_SIZE ${point_size10}
+RESOLUTION_X 75
+RESOLUTION_Y 75
+SPACING \"C\"
+AVERAGE_WIDTH 80
+CHARSET_REGISTRY \"ISO10646\"
+CHARSET_ENCODING \"1\"
+UNDERLINE_POSITION -2
+UNDERLINE_THICKNESS 1
+CAP_HEIGHT 10
+X_HEIGHT 8
 FONT_ASCENT 14
 FONT_DESCENT 2
 DEFAULT_CHAR 65533
 ENDPROPERTIES
-CHARS $nchars\n";
+CHARS $nchars\n" or die ("Cannot print to stdout.\n");
+
+# TODO: $swidth needs to be modified to accomodate different widths better
+#       for glyphs with height different than 16 pixels.
 
 foreach $character (@chars)
 {
        $encoding = hex($character); $glyph = $glyph{$character};
-       $width = length ($glyph) > 32 ? 2 : 1;
-       $dwidth = $width * 8; $swidth= $width * 500;
-       $glyph =~ s/((..){$width})/\n$1/g;
+       $width    = length ($glyph) / $vpixels;  # hex digits per row
+       $dwidth   = $width * 4;     # device width, in pixels; 1 digit = 4 px
+       # scalable width, units of 1/1000th full-width glyph
+       $swidth   = (1000 * $width) / ($vpixels / 4);
+       $glyph    =~ s/((.){$width})/\n$1/g;
        $character = "$character $charname"
            if $charname = $charname{pack("n",hex($character))};
 
@@ -47,9 +99,9 @@ foreach $character (@chars)
 ENCODING $encoding
 SWIDTH $swidth 0
 DWIDTH $dwidth 0
-BBX $dwidth 16 0 -2
+BBX $dwidth $vpixels 0 -2
 BITMAP $glyph
-ENDCHAR\n";
+ENDCHAR\n" or die ("Cannot print to stdout.\n");
 }
 
-print "ENDFONT\n";
+print "ENDFONT\n" or die ("Cannot print to stdout.\n");