#!/bin/sh # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ttf2texfonts version 2.2 : produce PostScript fonts for TeX from # # TrueType fonts and install them # # Copyright (C) 2004-2005 Glad Deschrijver, Thu Oct 07 2004, # # Tue Oct 19 2004, Mon Feb 14 2005, Thu Mar 17 2005, Wed Apr 27 2005 # # Glad.Deschrijver@UGent.be # # # # This program is free software; you can redistribute it and/or # # modify it under the terms of the GNU General Public License # # as published by the Free Software Foundation; either version 2 # # of the License, or (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # # USA. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Thanks to Jérôme Ortais for suggesting to export TEXMFVAR # Usage: # ttf2texfonts --init (at first installation) # ttf2texfonts --regular=bar.ttf --bold=barb.ttf foo # or ttf2texfonts --regular=bar.ttf foo # ttf2texfonts --install foor # ttf2texfonts --uninstall foo # ttf2texfonts --clean foo # Todo: - check whether there exists already a ttf.map somewhere in your # local texmf or in the system-wide texmf located in the wrong # place (i.e. a different place than the one used by this script) # - --init should look automatically for the system-wide texmf # and warn the user if it is not found # - put the default values in a file ~/.ttf2texfonts or in the # file specified by the environment variable $TTF2TEXFONTSCFG so # that the user doesn't have to change this code anymore # - add a flag --systemtexmf which works similarly as --texmf, but # for the system wide texmf-directory # - use updmap --enable Map ttf.map instead of editing updmap.cfg # - use mkdirhier instead of our own makedir subroutine # History: # 2.2 : - when a font is uninstalled the corresponding entry in the # temporary ttf.map is deleted, therefore the addition of this # entry is moved from createpfafromttf to installfonts # - some minor changes # 2.1 : - improve the help # - check if an already existing updmap.cfg contains the line # "Map ttf.map" before adding the line (previously the line could # be added more than once) # 2.0 : - automatically check if the line "Map ttf.map" is present in the # local updmap.cfg file, if not, then the line is added. If the local # updmap.cfg does not exist, then it is copied from /usr/share/texmf # (note: I do not check whether your local texmf-directory is # /usr/share/texmf, change $systemtexmf below if it isn't; # I do not check whether the contents of # /usr/share/texmf/updmap.cfg make sense, this is the # responsibility of the user) # - the TeX font files can now be generated without the need for # the local texmf-tree to exist (the texmf-tree will be created # when you actually install the font) # - generating the fonts and installing can be done using one command: # e.g. ttf2texfonts --regular=bar.ttf --install foo # - when combining --clean with other options, --clean takes precedence # and the other options are ignored # (the same holds for --help, which takes precedence even on --clean) # - fix an annoying bug which overwrites the ttf.map in your # texmf-directory if it is not also available in the working # directory # 1.1 : automatically update ttf.map when creating and uninstalling fonts # 1.0 : automatically create missing directories # Change the following defaults texmf=/home/gdschrij/texmf systemtexmf=/usr/share/texmf ttfmap2=ttf.map ttfmap=${texmf}/dvips/misc/${ttfmap2} ttfmap_tmp=ttf.map.tmp ttf2texfonts_temp=ttf2texfonts_temp # You shouldn't change anything below outputfont=foo inputregular= inputbold= inputitalic= inputbolditalic= install=no uninstall=no delete=no init=no progname=`echo "$0" | sed -e 's/[^\/]*\///g'` version=2.2 copyright="Copyright (C) 2004-2005 Glad Deschrijver" usage() { cat << EOF Usage: $progname [OPTIONS] outputfamily Options: Configuration: When creating the font the following options can be used (at least one of them should be used): --regular=FILE let FILE be the TTF for regular shape --bold=FILE let FILE be the TTF for the bold shape --italic=FILE let FILE be the TTF for the italic shape --bolditalic=FILE let FILE be the TTF for the bold italic shape Other options: -i, --install install fonts in ${texmf} -u, --uninstall uninstall fonts in ${texmf} -c, --clean remove output files in the working directory --texmf=DIR let DIR be the root of your texmf-tree where the files will be installed [$texmf] Notes: The first time you use the script, some initialisation must be done; run the following command to install the necessary configuration files: $progname --init Example: to create and install the Postscript font "foo" for TeX from the TrueType fonts bar.ttf (regular typeface) and barb.ttf (bold typeface), you run the following commands: $progname --regular=bar.ttf --bold=barb.ttf foo $progname --install foo Creating and installing the fonts can be done in a single step by running the command: $progname --regular=bar.ttf --bold=barb.ttf --install foo In your LaTeX-documents use e.g.: \usefont{T1}{foo}{m}{n}\selectfont Warning: this script assumes that your TeX-system uses updmap; if it doesn't, then the fonts will be installed anyway, but you will have to make sure yourself that TeX finds them and uses them. EOF } init () { makedir "${texmf}/dvips/misc" if test ! -f "${texmf}/web2c/updmap.cfg" then makedir "${texmf}/web2c" echo "cp ${systemtexmf}/web2c/updmap.cfg ${texmf}/web2c" cp ${systemtexmf}/web2c/updmap.cfg "${texmf}/web2c" fi if test -z "`grep ${ttfmap2} ${texmf}/web2c/updmap.cfg`" then echo "echo \"Map ${ttfmap2}\" >> ${texmf}/web2c/updmap.cfg" echo "Map ${ttfmap2}" >> ${texmf}/web2c/updmap.cfg fi exit 0; } createpfafromttf () { local a ttf2pt1 -e $1 "${2}8a" } createfonts () { if `test -e "$inputregular"` then createpfafromttf $inputregular "${outputfont}r" fi if `test -e "$inputitalic"` then createpfafromttf $inputitalic "${outputfont}ri" fi if `test -e "$inputbold"` then createpfafromttf $inputbold "${outputfont}b" fi if `test -e "$inputbolditalic"` then createpfafromttf $inputbolditalic "${outputfont}bi" fi #latex `kpsewhich fontinst.sty` # -> \latinfamily{fma}{}\bye echo "\\input fontinst.sty" > ${ttf2texfonts_temp}.tex echo "\\latinfamily{${outputfont}}{}\bye" >> ${ttf2texfonts_temp}.tex tex ${ttf2texfonts_temp} rm ${ttf2texfonts_temp}.* for x in ${outputfont}*.pl; do pltotf $x; done for x in ${outputfont}*.vpl; do vptovf $x; done rm ${outputfont}*.vpl ${outputfont}*.pl ${outputfont}*.mtx } makedir () { local a=`echo "$1" | sed -e "s/\/*$//"` if test ! -d "$a" then echo "Creating directory $a" local b=`echo "$a" | sed -e "s/\/[^\/]*$//"` makedir "$b" mkdir "$a" fi } installfonts () { makedir "${texmf}/fonts/type1/public/ttf" echo "cp *${outputfont}*.pfa ${texmf}/fonts/type1/public/ttf/" cp *${outputfont}*.pfa ${texmf}/fonts/type1/public/ttf/ makedir "${texmf}/fonts/tfm/public/ttf" echo "cp *${outputfont}*.tfm ${texmf}/fonts/tfm/public/ttf/" cp *${outputfont}*.tfm ${texmf}/fonts/tfm/public/ttf/ makedir "${texmf}/fonts/vf/public/ttf" echo "cp *${outputfont}*.vf ${texmf}/fonts/vf/public/ttf/" cp *${outputfont}*.vf ${texmf}/fonts/vf/public/ttf/ makedir "${texmf}/tex/latex/psnfss/ttf" echo "cp *${outputfont}*.fd ${texmf}/tex/latex/psnfss/ttf/" cp *${outputfont}*.fd ${texmf}/tex/latex/psnfss/ttf/ a=`grep FontName "${outputfont}r8a.afm" | sed -e "s/FontName //"` if test -z "`grep $a ${ttfmap_tmp}`" then echo "${outputfont}r8r $a <${outputfont}r8a.pfa" >> ${ttfmap_tmp} fi for a in `sed -e "s/\ .*//" ${ttfmap_tmp}` do if test -z "`grep $a ${ttfmap}`" then grep $a ${ttfmap_tmp} >> ${ttfmap} fi done updmap echo "TTF fonts succesfully installed as TeX-fonts." } uninstallfonts () { if test ! -d "${texmf}" then echo "${progname}: directory ${texmf} does not exist." exit 0; fi; echo "rm ${texmf}/fonts/type1/public/ttf/*${outputfont}*" rm ${texmf}/fonts/type1/public/ttf/*${outputfont}* echo "rm ${texmf}/fonts/tfm/public/ttf/*${outputfont}*" rm ${texmf}/fonts/tfm/public/ttf/*${outputfont}* echo "rm ${texmf}/fonts/vf/public/ttf/*${outputfont}*" rm ${texmf}/fonts/vf/public/ttf/*${outputfont}* echo "rm ${texmf}/tex/latex/psnfss/ttf/*${outputfont}*" rm ${texmf}/tex/latex/psnfss/ttf/*${outputfont}* sed "/${outputfont}r8a/d;/${outputfont}ri8a/d;/${outputfont}b8a/d;/${outputfont}bi8a/d" ${ttfmap_tmp} > "${ttfmap_tmp}_ttf2texfonts_temp" mv "${ttfmap_tmp}_ttf2texfonts_temp" ${ttfmap_tmp} sed "/${outputfont}r8a/d;/${outputfont}ri8a/d;/${outputfont}b8a/d;/${outputfont}bi8a/d" $ttfmap > "${ttfmap}_ttf2texfonts_temp" mv "${ttfmap}_ttf2texfonts_temp" $ttfmap updmap echo "TTF fonts ${outputfont} succesfully removed." } deleteauxfiles () { rm *${outputfont}*.pfa rm *${outputfont}*.afm rm *${outputfont}*.tfm rm *${outputfont}*.vf rm *${outputfont}*.fd exit 0; } export TEXMFVAR=$texmf while test x"$1" != x do case $1 in -h|--help) usage; exit 0;; --init) init=yes shift ;; -i|--install) install=yes shift ;; -u|--uninstall) uninstall=yes shift ;; -c|--clean) delete=yes shift ;; --regular=*) inputregular=`echo $1 | sed -e 's/--regular=//'` shift ;; --italic=*) inputitalic=`echo $1 | sed -e 's/--italic=//'` shift ;; --bold=*) inputbold=`echo $1 | sed -e 's/--bold=//'` shift ;; --bolditalic=*) inputbolditalic=`echo $1 | sed -e 's/--bolditalic=//'` shift ;; --texmf=*) texmf=`echo $1 | sed -e 's/--texmf=//'` shift ;; -v|--version) echo "$progname $version" echo "$copyright" echo "This program comes with ABSOLUTELY NO WARRANTY. This is free" echo "software, and you are welcome to redistribute it under" echo "the terms of the GNU General Public License." exit 0 ;; -*) usage; exit 1;; *) outputfont=$1; shift;; esac done if `test "$init" = "yes"` then init; fi if `test "$delete" = "yes"` then deleteauxfiles fi if `test "$install" = "yes"` then if test -z "`grep ${ttfmap2} ${texmf}/web2c/updmap.cfg`" then echo "$progname: This seems to be the first usage of this program in ${texmf}." echo "Run $progname --init to install the necessary configuration files." exit 1 fi if ([ -e "$inputregular" ] && [ ! -f "${outputfont}r8t.vf" ]) \ || ([ -e "$inputitalic" ] && [ ! -f "${outputfont}ri8t.vf" ]) \ || ([ -e "$inputbold" ] && [ ! -f "${outputfont}b8t.vf" ]) \ || ([ -e "$inputbolditalic" ] && [ ! -f "${outputfont}bi8t.vf" ]) then createfonts fi installfonts else if `test "$uninstall" = "yes"` then uninstallfonts else createfonts fi fi