From 3f7e4450e61fb9d62b3c12baa5ffb9b7c1e1604d Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 31 Jul 2024 13:17:46 -0400 Subject: fonts: sort glyphs by codepoint. --- fonts/sorttxtfont.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 fonts/sorttxtfont.pl (limited to 'fonts/sorttxtfont.pl') 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); -- cgit v1.2.3