X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/2ada86c7bb585d419b95c95ce42d5b7a9fa45475..fefdce4e24f9e397df5538fe6e7f54b5ece4d841:/src/librarian/font-optimizer/gen-tests.pl?ds=sidebyside
diff --git a/src/librarian/font-optimizer/gen-tests.pl b/src/librarian/font-optimizer/gen-tests.pl
new file mode 100644
index 0000000..63bb153
--- /dev/null
+++ b/src/librarian/font-optimizer/gen-tests.pl
@@ -0,0 +1,235 @@
+# This script generates various 'interesting' fonts, and outputs an HTML file
+# containing the subsetted fonts and the original fonts.
+# View the output in browsers (preferably multiple, on multiple platforms) to
+# make sure the output looks the same as the original.
+
+use strict;
+use warnings;
+
+use lib 'ext/Font-TTF/lib';
+use Font::Subsetter;
+use Font::EOTWrapper;
+use Encode;
+use Clone;
+
+use utf8;
+
+# The following fonts need to exist in a directory called 'testfonts':
+my @all = qw(
+ GenBasR.ttf
+ GenR102.TTF
+ LinLibertine_Re-4.1.8.ttf
+ DoulosSILR.ttf
+ DejaVuSans.ttf
+ DejaVuSerif.ttf
+ calibri.ttf
+ FedraSansPro-Demi.ttf
+);
+
+my $index = $ARGV[0];
+die "Run '$0', or '$0 n' where n is the number of the test to rebuild\n"
+ if defined $index and $index !~ /^\d+$/;
+
+my @tests = (
+ # These aren't proper tests (they drop features that affect the rendering)
+ # TODO: fix them so they are proper, and test that they're really dropping the
+ # unneeded glyphs etc
+# [ [qw(DejaVuSans.ttf FedraSansPro-Demi.ttf)], ["fluffily Ùا f"], [20], [qw(aalt ccmp dlig fina hlig init liga locl medi rlig salt kern mark mkmk)] ],
+# [ [qw(DejaVuSans.ttf FedraSansPro-Demi.ttf)], ["fluffily Ùا f"], [20], [qw(liga)] ],
+# [ [qw(DejaVuSans.ttf FedraSansPro-Demi.ttf)], ["fluffily Ùا f"], [20], [qw(fina init rlig)] ],
+# [ [qw(DejaVuSans.ttf FedraSansPro-Demi.ttf)], ["fluffily Ùا f"], [20], [] ],
+
+ # Basic rendering
+ [ [@all], ["Hello world ABC abc 123"], [20] ],
+
+ # Substitution and NFC issues
+ [ [qw(GenBasR.ttf DejaVuSans.ttf FedraSansPro-Demi.ttf)], [
+ "i",
+ "\xec",
+ "i\x{0300}",
+ "i \x{0300}",
+ "ixixi",
+ "i\x{0300}",
+ ], [20, 8] ],
+ [ [qw(DejaVuSans.ttf FedraSansPro-Demi.ttf)], [
+ "s\x{0323}\x{0307}", # s, combining dot below, combining dot above
+ "s\x{0307}\x{0323}", # s, combining dot above, combining dot below
+ "\x{1e61}\x{0323}", # s with dot above, combining dot below
+ "\x{1e63}\x{0307}", # s with dot below, combining dot above
+ "\x{212b}", # angstrom
+ ], [20, 8] ],
+
+ # Ligature rendering
+ [ [qw(LinLibertine_Re-4.1.8.ttf DejaVuSans.ttf FedraSansPro-Demi.ttf)], [
+ "fluffily",
+ "fluffily",
+ "fluffily",
+ ], [20, 8] ],
+
+ # GPOS issues
+ [ [qw(DejaVuSans.ttf FedraSansPro-Demi.ttf calibri.ttf)],
+ ["|VAVAV|", "ToToT", "x//x"], [20], ['kern'] ],
+
+ # Lots of stuff
+ [ [@all], ["VABC(123) fTo fluffiest ffi!\@#,. \x{00e2}\x{00eb}I\x{0303}o\x{0300}u\x{030a}\x{0305}\x{0303} i\x{0331}\x{0301} \x{0d23}\x{0d4d}\x{200d} ÏαÏÎ±ÎºÎ±Î»Ï Ñ
Ñлло ä½ å¥½ 表示é®å ãã اÙتÙÙÙÙ ×××"], [20, 8] ],
+
+);
+
+my $common_css = <
+$text
}, (join ' ', map "$_", sort @glyph_names), qq{
}; + print $html qq{}, dump_sizes("testoutput/$path.ttf"), qq{}; + } + print $out "