From 7027ad989c1bcdbd2a9eab8c7d419eda590a0204 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 24 Jul 2024 01:16:59 -0400 Subject: fonts/* and fauxtari.{rst,7} added. still WIP. --- fonts/mkpsf.pl | 639 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 639 insertions(+) create mode 100644 fonts/mkpsf.pl (limited to 'fonts/mkpsf.pl') diff --git a/fonts/mkpsf.pl b/fonts/mkpsf.pl new file mode 100644 index 0000000..1ff5816 --- /dev/null +++ b/fonts/mkpsf.pl @@ -0,0 +1,639 @@ +#!/usr/bin/perl -w + +# Read raw font data from atari rom images, plus a few hand-drawn +# "text bitmaps" from __DATA__. + +# Write 3 bitmap font "txt" files in the format txt2psf expects, then +# runs txt2psf on them. Results in 3 fonts: + +# fauxtari-8.psf - 8x8 native size +# fauxtari-16.psf - 16x16 scaled up +# fauxtari-24.psf - 24x24 scaled up + +# The fiddly bits of this are getting the Unicode mappings correct. + +# ROM dumps are mapped to Atari address space at $C000, the regular +# charset starts at $E000, so it's at offset $2000 (8192) in the +# image. The XL international set is at $CC00, or offset $0C00 (3072). +# In the Arabic ROM, the Arabic font takes the place of the standard +# charset. All the charsets are 1K in size. + +# Arabic ROM, plus some info about it and a mention of the Hebrew ROM: +# https://www.savetz.com/vintagecomputers/arabic65xe/ + +# TODO; +# BDF fonts too: psf2bdf --iso10646 --fontname ... +# Arabic. + +use bytes; + +$fontname = "fauxtari"; + +sub byte2line { + my $t = shift; + $t = sprintf("%08b", $t); + $t =~ y/0/-/; + $t =~ y/1/#/; + return $t; +} + +sub scale_line { + my $line = shift; + my $scale = shift; + my $one = '#' x $scale; + my $zero = '-' x $scale; + + $line =~ s/#/$one/g; + $line =~ s/-/$zero/g; + return ($line x $scale); +} + +sub chr2output { + my $codepoint = shift; + my $bytes = shift; + my $scale = shift || 1; + my $unicode = ""; + + if(!ref $codepoint) { + $codepoint = [ $codepoint ]; + } + + $unicode .= sprintf("[%04x];", $_) for @$codepoint; + + my $result = sprintf("%%\nUnicode: %s\nBitmap: \\\n", $unicode); + for(0..7) { + my $byte = $bytes->[$_]; + my $line = byte2line($byte); + $result .= scale_line($line, $scale); + $result .= " \\" unless $_ == 7; + $result .= "\n"; + } + return $result; +} + +sub internal2byte { + my $t = shift; + $t =~ y/-/0/; + $t =~ y/#/1/; + return pack("B*", $t); +} + +sub psf2txt_header { + my $charcount = shift; + my $scale = shift; + my $w = 8 * $scale; + my $h = 8 * $scale; + return <) { + push @scale1, $_; + $cnt++ if /^%/; + if(/^\s/) { + push @scale2, scale_line($_, 2); + push @scale3, scale_line($_, 3); + } else { + push @scale2, $_; + push @scale3, $_; + } +} + +warn "$cnt characters\n"; +#warn "(padding to 256 characters)\n" unless $cnt >= 256; +warn "(padding to 512 characters)\n" unless $cnt >= 512; +while($cnt < 512) { + my $fake = "%\nUnicode: [0000];\nBitmap: "; + push @scale1, $fake . (("-" x 8) x 8) . "\n"; + push @scale2, $fake . (("-" x 16) x 16) . "\n"; + push @scale3, $fake . (("-" x 24) x 24) . "\n"; + $cnt++; +} +warn "$cnt characters with padding\n"; + +open $fh, '>', "$fontname-8.txt" or die $!; +print $fh psf2txt_header($cnt, 1); +print $fh $_ for(@scale1); +close $fh; +system("txt2psf $fontname-8.txt $fontname-8.psf"); + +open $fh, '>', "$fontname-16.txt" or die $!; +print $fh psf2txt_header($cnt, 2); +print $fh $_ for(@scale2); +close $fh; +system("txt2psf $fontname-16.txt $fontname-16.psf"); + +open $fh, '>', "$fontname-24.txt" or die $!; +print $fh psf2txt_header($cnt, 3); +print $fh $_ for(@scale3); +close $fh; +system("txt2psf $fontname-24.txt $fontname-24.psf"); + +__DATA__ +% +// backtick +Unicode: [0060]; +Bitmap: \ + -------- \ + --##---- \ + --##---- \ + ---##--- \ + -------- \ + -------- \ + -------- \ + -------- +% +// curlies +Unicode: [007b]; +Bitmap: \ + ----##-- \ + ---##--- \ + ---##--- \ + --##---- \ + ---##--- \ + ---##--- \ + ----##-- \ + -------- +% +Unicode: [007d]; +Bitmap: \ + --##---- \ + ---##--- \ + ---##--- \ + ----##-- \ + ---##--- \ + ---##--- \ + --##---- \ + -------- +% +// tilde +Unicode: [007e]; +Bitmap: \ + -------- \ + -###--## \ + ##-##-## \ + ##--###- \ + -------- \ + -------- \ + -------- \ + -------- +% +// euro +Unicode: [20ac]; +Bitmap: \ + ---####- \ + --##---- \ + -#####-- \ + --##---- \ + -#####-- \ + --##---- \ + ---####- \ + -------- +% +// spanish left-quote +Unicode: [00ab]; +Bitmap: \ + -------- \ + -------- \ + -------- \ + -##--##- \ + ##--##-- \ + -##--##- \ + -------- \ + -------- +% +// spanish right-quote +Unicode: [00bb]; +Bitmap: \ + -------- \ + -------- \ + -------- \ + ##--##-- \ + -##--##- \ + ##--##-- \ + -------- \ + -------- +% +// spanish inverted question mark +Unicode: [00bf]; +Bitmap: \ + -------- \ + ---##--- \ + -------- \ + ---##--- \ + ----##-- \ + -##--##- \ + --####-- \ + -------- +% +// copyright +Unicode: [00a9]; +Bitmap: \ + -#####-- \ + #-----#- \ + #--##-#- \ + #-#---#- \ + #--##-#- \ + #-----#- \ + -#####-- \ + -------- +% +// degrees +Unicode: [00b0];[00ba]; +Bitmap: \ + -------- \ + ---XX--- \ + --x--x-- \ + ---xx--- \ + -------- \ + -------- \ + -------- \ + -------- -- cgit v1.2.3