font: search font files in multiple candidates
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 2 Apr 2012 21:11:16 +0000 (23:11 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 10 Apr 2012 01:03:24 +0000 (03:03 +0200)
font.plp
tools/convert-allfonts

index f9b7ac6501326b32ecaec92ada1e810790852a42..22479b4763f2b124264b94ae33a5c27f29186e7f 100644 (file)
--- a/font.plp
+++ b/font.plp
@@ -26,13 +26,12 @@ use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
 
 my %oslist = (
-       win95 => [qw( arial ariuni verdana times )],
-       mac10 => [qw( )],
-       oss   => [qw( dvsans droid c2k guf )],
-
-       android => ['droid'],
+       win95   => [qw( arial ariuni verdana times )],  # microsoft
+       mac10   => [qw( )],  # apple
+       android => [qw( droidsans )],  # google
+       oss     => [qw( dvsans c2k unifont )],
 );
-my @ossel = qw(win95 oss);
+my @ossel = qw( win95 oss android );
 
 my $tables = do 'unicode-table.inc.pl' or die $@ || $!;
 my (%font, @fontlist);
index e7d1964bf835c439f2f227fcec80a3e63158af62..f3ccffc45d6f112d7254c295c297bcb57264cb96 100755 (executable)
@@ -1,51 +1,74 @@
-#!/bin/sh
+#!/usr/bin/env perl
+use strict;
+use warnings;
+no warnings 'syntax';  # if assignment
 
-cd $(dirname $0)
+use List::Util 'first';
+use File::Basename 'dirname';
 
-CONVBIN=./convert-ttf.pl
-OUTDIR=../ttfsupport
-TTFDIR=~/.fonts
+chdir dirname $0;
 
-# microsoft
+my $convbin = './convert-ttf.pl';
+my $outdir = '../ttfsupport';
+my @ttfpath = '~/.fonts';  # local fallbacks
 
-TTFDIR_MS=/usr/share/fonts/truetype/msttcorefonts
-if [ -e $TTFDIR_MS ]; then
-$CONVBIN $TTFDIR_MS/Verdana.ttf $OUTDIR/verdana.inc.pl
-$CONVBIN $TTFDIR_MS/Times_New_Roman.ttf $OUTDIR/times.inc.pl
-$CONVBIN $TTFDIR_MS/Arial.ttf $OUTDIR/arial.inc.pl
-$CONVBIN $TTFDIR_MS/Courier_New.ttf $OUTDIR/courier.inc.pl
-$CONVBIN $TTFDIR_MS/Comic_Sans_MS.ttf $OUTDIR/comic.inc.pl
-$CONVBIN $TTFDIR_MS/Georgia.ttf $OUTDIR/georgia.inc.pl
-fi
+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";
+       }
+}
 
-# bitstream
+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";
+       }
+}
 
-TTFDIR_DV=/usr/share/fonts/truetype/ttf-dejavu
-if [ -e $TTFDIR_DV ]; then
-$CONVBIN $TTFDIR_DV/DejaVuSans.ttf $OUTDIR/dvsans.inc.pl
-$CONVBIN $TTFDIR_DV/DejaVuSerif.ttf $OUTDIR/dvserif.inc.pl
-$CONVBIN $TTFDIR_DV/DejaVuSansMono.ttf $OUTDIR/dvmono.inc.pl
-fi
+if (my $gdpath = '/usr/share/fonts/truetype/droid') {
+       if (my $src = first { -e } map { glob "$_/DroidSans.ttf" } $gdpath, @ttfpath) {
+               system $convbin, $src, "$outdir/droidsans.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";
+       }
+}
 
-# google
+{
+       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";
+       }
+}
 
-TTFDIR_GD=/usr/share/fonts/truetype/droid
-if [ -e $TTFDIR_GD ]; then
-$CONVBIN $TTFDIR_DV/DroidSans.ttf $OUTDIR/droidsans.inc.pl
-$CONVBIN $TTFDIR_DV/DroidSerif.ttf $OUTDIR/droidserif.inc.pl
-$CONVBIN $TTFDIR_DV/DroidSansMono.ttf $OUTDIR/droidmono.inc.pl
-fi
-
-# other
-
-find $TTFDIR -iname code2000.ttf -exec \
-       $CONVBIN "{}" $OUTDIR/c2k.inc.pl \;
-
-find $TTFDIR -iname arial\*uni\*.ttf -exec \
-       $CONVBIN "{}" $OUTDIR/ariuni.inc.pl \;
-
-TTFDIR_GU=/usr/share/fonts/truetype/unifont/
-if [ -e $TTFDIR_GU ]; then
-$CONVBIN $TTFDIR_GU/unifont.ttf $OUTDIR/unifont.inc.pl
-fi
+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";
+       }
+}