aboutsummaryrefslogtreecommitdiff
path: root/fonts/sorttxtfont.pl
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-07-31 13:17:46 -0400
committerB. Watson <urchlay@slackware.uk>2024-07-31 13:17:46 -0400
commit3f7e4450e61fb9d62b3c12baa5ffb9b7c1e1604d (patch)
treeb683281f6af7f49a5cdf844500b5c4781328249d /fonts/sorttxtfont.pl
parenta11d325471be7ba147309f42148a9e16a6e82078 (diff)
downloadbw-atari8-tools-3f7e4450e61fb9d62b3c12baa5ffb9b7c1e1604d.tar.gz
fonts: sort glyphs by codepoint.
Diffstat (limited to 'fonts/sorttxtfont.pl')
-rw-r--r--fonts/sorttxtfont.pl33
1 files changed, 33 insertions, 0 deletions
diff --git a/fonts/sorttxtfont.pl b/fonts/sorttxtfont.pl
new file mode 100644
index 0000000..62c37cc
--- /dev/null
+++ b/fonts/sorttxtfont.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/perl -w
+
+# sort a font in psftools .txt format, by unicode codepoint.
+# only the *first* codepoint per glyph is used as the key.
+
+undef $/;
+$_ = <>;
+@glyphs = split "%";
+shift @glyphs;
+$header = "%" . (shift @glyphs);
+
+# 0 is a special case because fonts intended to become PSFs will
+# be padded with extra characters with encoding 0. only the first
+# one seen is the real one.
+$zeroseen = 0;
+
+for(@glyphs) {
+ my($cp, $dcp);
+ ($cp) = (/Unicode: \[([0-9a-fA-F]+)/);
+ $dcp = eval "0x$cp";
+ if($dcp == 0) {
+ next if $zeroseen++;
+ }
+ if(defined $sortme{$dcp}) {
+ warn "duplicate codepoint 0x$cp\n";
+ }
+ $sortme{$dcp} = $_;
+}
+
+for(sort { $a <=> $b } keys %sortme) {
+ push @sorted, $sortme{$_};
+}
+print join("%", $header, @sorted);