From 3f105ae3161afb8bfc16cb0b6fee0faa2e43cc55 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 2 Apr 2012 23:11:16 +0200 Subject: [PATCH] font: search font files in multiple candidates --- font.plp | 11 ++--- tools/convert-allfonts | 107 +++++++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 48 deletions(-) diff --git a/font.plp b/font.plp index f9b7ac6..22479b4 100644 --- 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); diff --git a/tools/convert-allfonts b/tools/convert-allfonts index e7d1964..f3ccffc 100755 --- a/tools/convert-allfonts +++ b/tools/convert-allfonts @@ -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"; + } +} -- 2.30.0