font: convert-allfonts: generic search
[sheet.git] / tools / convert-allfonts
index 9d75e0642ef00c89ff585aca2e010e0d96c45e33..54322f54d8aa000d688773c24597da5f87c8fc35 100755 (executable)
@@ -1,98 +1,50 @@
-#!/usr/bin/env perl
-use strict;
-use warnings;
-no warnings 'syntax';  # if assignment
+#!/bin/sh
+set -u
 
-use List::Util 'first';
-use File::Basename 'dirname';
+cd $(dirname "$0")
 
-chdir dirname $0;
+CONVBIN=./mkttfinfo
+OUTDIR=../ttfsupport
 
-my $convbin = './mkttfinfo';
-my $outdir = '../ttfsupport';
-my @ttfpath = ('~/.fonts', '../data/osx-fonts');  # local fallbacks
+INC=~/.fonts/\ /usr/share/fonts/truetype/
+INC=$INC\ ../data/macfonts/
 
-if (my $mspath = '/usr/share/fonts/truetype/msttcorefonts') {
-       if (my $src = first { -e } map { glob "$_/Verdana.ttf" } $mspath, @ttfpath) {
-               system $convbin, $src, "$outdir/verdana.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/Times_New_Roman.ttf" } $mspath, @ttfpath) {
-               system $convbin, $src, "$outdir/times.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/Arial.ttf" } $mspath, @ttfpath) {
-               system $convbin, $src, "$outdir/arial.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/Courier_New.ttf" } $mspath, @ttfpath) {
-               system $convbin, $src, "$outdir/courier.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/Comic_Sans_MS.ttf" } $mspath, @ttfpath) {
-               system $convbin, $src, "$outdir/comic.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/Georgia.ttf" } $mspath, @ttfpath) {
-               system $convbin, $src, "$outdir/georgia.inc.pl";
-       }
+convfont () {
+       find $INC -name "$1" -print -quit |
+       xargs -i $CONVBIN {} $OUTDIR/$2.inc.pl
 }
 
-if (my $ampath = '/usr/share/fonts/truetype/macfonts') {
-       if (my $src = first { -e } map { glob "$_/Lucida?Grande.ttf" } $ampath, @ttfpath) {
-               system $convbin, $src, "$outdir/lucida.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/AppleGaramond.ttf" } $ampath, @ttfpath) {
-               system $convbin, $src, "$outdir/garamond.inc.pl";
-       }
-}
+# /usr/share/fonts/truetype/msttcorefonts
+convfont Verdana.ttf verdana
+convfont Times_New_Roman.ttf times
+convfont Arial.ttf arial
+convfont Courier_New.ttf courier
+convfont Comic_Sans_MS.ttf comic
+convfont Georgia.ttf georgia
 
-if (my $dvpath = '/usr/share/fonts/truetype/ttf-dejavu') {
-       if (my $src = first { -e } map { glob "$_/DejaVuSans.ttf" } $dvpath, @ttfpath) {
-               system $convbin, $src, "$outdir/dvsans.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/DejaVuSerif.ttf" } $dvpath, @ttfpath) {
-               system $convbin, $src, "$outdir/dvserif.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/DejaVuSansMono.ttf" } $dvpath, @ttfpath) {
-               system $convbin, $src, "$outdir/dvmono.inc.pl";
-       }
-}
+convfont 'arial*uni*.ttf' ariuni
 
-if (my $gdpath = '/usr/share/fonts/truetype/droid') {
-       if (my $src = first { -e } map { glob "$_/DroidSans.ttf" } $gdpath, @ttfpath) {
-               system $convbin, $src, "$outdir/droid.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/DroidSerif.ttf" } $gdpath, @ttfpath) {
-               system $convbin, $src, "$outdir/droidserif.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/DroidSansMono.ttf" } $gdpath, @ttfpath) {
-               system $convbin, $src, "$outdir/droidmono.inc.pl";
-       }
-}
+# ../data/macfonts
+convfont Lucida\?Grande.ttf lucida
+convfont AppleGaramond.ttf garamond
 
-if (my $grpath = '/usr/share/fonts/truetype/roboto') {
-       if (my $src = first { -e } map { glob "$_/Roboto-Regular.ttf" } $grpath, @ttfpath) {
-               system $convbin, $src, "$outdir/roboto.inc.pl";
-       }
-}
+# /usr/share/fonts/truetype/ttf-dejavu
+convfont DejaVuSans.ttf dvsans
+convfont DejaVuSerif.ttf dvserif
+convfont DejaVuSansMono.ttf dvmono
 
-if (my $gnpath = '/usr/share/fonts/truetype/noto') {
-       if (my $src = first { -e } map { glob "$_/NotoSans-Regular.ttf" } $gnpath, @ttfpath) {
-               system $convbin, $src, "$outdir/noto.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/NotoSerif-Regular.ttf" } $gnpath, @ttfpath) {
-               system $convbin, $src, "$outdir/noto.inc.pl";
-       }
-}
+# /usr/share/fonts/truetype/droid
+convfont DroidSans.ttf droid
+convfont DroidSerif.ttf droidserif
+convfont DroidSansMono.ttf droidmono
+# /usr/share/fonts/truetype/roboto
+convfont Roboto-Regular.ttf roboto
+# /usr/share/fonts/truetype/noto
+convfont NotoSans-Regular.ttf noto
+convfont NotoSerif-Regular.ttf notoserif
 
-{
-       if (my $src = first { -e } map { glob "$_/code2000.ttf" } @ttfpath) {
-               system $convbin, $src, "$outdir/c2k.inc.pl";
-       }
-       if (my $src = first { -e } map { glob "$_/arial*uni*.ttf" } @ttfpath) {
-               system $convbin, $src, "$outdir/ariuni.inc.pl";
-       }
-}
+# /usr/share/fonts/truetype/unifont
+convfont unifont.ttf unifont
 
-if (my $gupath = '/usr/share/fonts/truetype/unifont') {
-       if (my $src = first { -e } map { glob "$_/unifont.ttf" } $gupath, @ttfpath) {
-               system $convbin, $src, "$outdir/unifont.inc.pl";
-       }
-}
+convfont code2000.ttf c2k