I just wanted to have that type of a preview they have on some font websites, where you type a phrase and it gets rendered in different fonts ... So here is a small bash script (tested on Ubuntu 9.10) which will loop through a directory where .ttf or .otf fonts are places, and will generate a .tex file with a phrase in all those fonts - and will finally call xelatex to generate a pdf based on the tex file.
Excuse the messy comments - and hope some may find it useful,
Cheers!
quickfonttest.sh:
Code: Select all
# to be used with xetex - xelatex
# for texlive:
# tlmgr install xetex xunicode xltxtra fontspec xkeyval euenc metalogo xetex-def
# Must NOT have spaces in font names !!
# Note - some fonts (those with commas in their names? can cause Segmentation fault).
# the script will loop through a directory (assuming it has only .ttf or .otf font files) and will generate a xetex file, which will display a phrase in all the fonts found in that directory; and then it will compile the file with xelatex. (something similar to http://fontforge.sourceforge.net/fontimage.html)
# sudo apt-get install fontforge # for showttf
# bugs - Verbatim doesn't wrap (break lines) and doesn't show footnotesize
OFN=fonttester # output file name (base)
TEXF=$OFN.tex
function becho()
{
echo "$*" | tee -a $TEXF
}
PHRASE="My Test Phrase"
FONTDIR=/home/USERNAME/.openoffice.org/3/user/fonts
echo "" > "$TEXF" # erase
becho "
\documentclass{article}
\usepackage{fontspec}
\usepackage{xunicode}
%\usepackage{xltxtra}
\usepackage{graphicx} % for scalebox
\usepackage{fancyvrb} % for Verbatim
\usepackage{fancybox} % for fbox?
% from fancybox.pdf:
\newenvironment{fminipage}%
{\begin{Sbox}\begin{minipage}}%
{\end{minipage}\end{Sbox}\fbox{\TheSbox}}
\begin{document}
"
for ifn in $(find $FONTDIR -type f)
do
ifnb=$(basename $ifn)
ifnd=$(dirname $ifn)
# dont forget closing / in ExtLoc, else "Invalid fontname"
becho "\begin{fminipage}{\textwidth}"
becho "\begin{Verbatim}[width=\textwidth,fontsize=\footnotesize]"
becho "$ifnb"
# push some info too
becho "$(showttf $ifn | grep -A 1 language=0.*UniqueID | grep strlen)"
becho "\end{Verbatim}"
becho "\fontspec[ExternalLocation={$ifnd/},]{$ifnb}"
# becho "\setmainfont[ExternalLocation={$ifnd/},]{$ifnb}"
# becho "\fontsize{48}{48}"
becho "\scalebox{3}{$PHRASE}"
becho "\end{fminipage}"
becho "\ \\"
becho "\bigskip"
becho
done
becho "
\end{document}
"
xelatex $TEXF # generates a pdf..
# for debug:
# xelatex -no-pdf fonttester.tex
# xdvipdfmx -E -vv fonttester.xdv
# clean up - leave tex and pdf.
rm $OFN.aux $OFN.log