Re: use windows fonts and adobe distiller and lout

Martin Michel <[email protected]> Thu, 30 Jan 2020 21:44:29 +0100
Newsgroups gmane.comp.type-setting.lout
Message-ID <[email protected]>
Hey Doug,

author of the script here. William and David already explained the idea
of the script very well, I have not much to add. It is basically a
wrapper around ttf2pt1 which automates the whole chain of preparation
for using a TTF/OTF font within Lout. The Readme on GitHub [1] gives
some more details, but you know it probably already.

I used the script successful on MacOS and Linux but have no experience
with it on Windows. To directly use it, you could try to install Cygwin
[2] or MSYS2 [3], install the required programs and follow the steps
from the Readme. The dependencies are a bunch of GNU Unix/Linux tools
which should come out-of-the box in Cygwin (bash, sed, grep, tee, ...) an=
d
the ttf2pt1 program [4]. Compilation requires specific development
headers, e.g. Freetype 2 [5] and build essential tools like make and
gcc.  Although all those resource should be accessible by Cygwin's
package system, I have to admit, this is not an easy path if you are
completely new to GNU/Linux/Unix. To cut a long story short, I cannot
guarantee it will work this way but if you are ambitious and eager to
learn something new, just give it a try. (Alternatively, you could
install a Linux VM using Virtualbox [6] but this would make your task
even bigger=E2=80=A6)

If there is another, easier way (Windows or Linux), I would be also very
happy to learn about it from the community.

=E2=88=92Martin

[1] https://github.com/smartmic/addfonts
[2] https://www.cygwin.com/
[3] https://www.msys2.org/
[4] http://ttf2pt1.sourceforge.net/
[5] https://www.freetype.org/
[6] https://www.virtualbox.org/


On Tue, Jan 28, 2020 at 05:33:49PM -0500, douglas mcallaster wrote:
> Folks,
>=20
> Can lout use the truetype fonts which come with Windows 10?
> (And I am using Adobe Distiller to make pdf from the lout generated pos=
tscript.)
>=20
> I found an explanation for using non standard fonts from 20 years ago (=
using PFA or PFB and AFM files),
> but I assume truetype fonts would provide much higher quality.
>=20
> I discovered (on git hub) a script from Martin Michel from 2014 but it =
is for Linux and ghostscript.
> Has someone made a Windows powershell script which could perform this m=
agic for me?
>=20
> Or perhaps someone could explain the script (copied next under) so that=
 I could try to its steps manually.
> =C2=A0
> As I understand it, I would have to set up lout to find the AFM file vi=
a a myfonts.ld file.
>=20
> If someone could reply with the requisite (I assume) AFM file (based on=
 some Windows10 truetype font),
> and a myfonts.ld file (with the correct matching @name, @family, @face,=
 @tag, @metrics, @mapping info)
> what would be really great. (An early success would keep me going, as I=
 have a day job.)
>=20
> Also, if folks have done this and can suggest a nice Windows Monospace,=
 Serif, and San Serif font, I welcome it.
>=20
> Finally, my thoughts go out to Dr Kingston, who enjoyed hiking in Austr=
alia,
> as I wonder how much of his treasured woodlands are now destroyed.
>=20
> Thanks, Doug
>=20
> #!/bin/bash
> #
> # addfonts.sh
> # Converts True Type or Open Type Fonts to Postscript Type1 Fonts and p=
opulates
> # the Ghostscript Fontmap file and the Basser Lout FontDef databases fo=
r local
> # users.
> #
> # Depends on non-standard commands: ttfpt1 (compiled against Freetype)
> #
> #
> # Copyright 2014 Martin Michel
> #
> # =C2=A0 Licensed under the Apache License, Version 2.0 (the "License")=
; you may not
> # =C2=A0 use this file except in compliance with the License.=C2=A0 You=
 may obtain a copy
> # =C2=A0 of the License at
> #
> # =C2=A0 =C2=A0 http://www.apache.org/licenses/LICENSE-2.0
> #
> # =C2=A0 Unless required by applicable law or agreed to in writing, sof=
tware
> # =C2=A0 distributed under the License is distributed on an "AS IS" BAS=
IS, WITHOUT
> # =C2=A0 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implie=
d.=C2=A0 See the
> # =C2=A0 License for the specific language governing permissions and li=
mitations
> # =C2=A0 under the License.
> =C2=A0 =C2=A0
> shfile=3D$(sed 's/^.*\///' <<< $0)
> logfile=3D$(sed -e 's/\.sh/\.log/; s/^.*\///' <<< $0)
> #echo $0 $shfile $logfile
>=20
> usage=3D"Usage: ./$shfile
> No arguments applicable. This script scans for new True Type or Open Ty=
pe Font
> files, converts them to Postscript Type1 Fonts and updates the Fontmap
> (Ghostscript) and @FontDef (Lout) databases. The script and all associa=
ted input
> and output files must be in the local user ghostscript font path."
>=20
> echo "*****************************************************************=
"\
> =C2=A0 =C2=A0>>$logfile
> echo "LOG ENTRY from '$shfile'">>$logfile
> echo -e "Run by $USER on $HOSTNAME at $(date) \n ">>$logfile
>=20
> if [ $# -gt 0 ] ; then
> =C2=A0 =C2=A0 echo -e "TERMINATION: Wrong number of arguments. \n" |tee=
 -a $logfile
> =C2=A0 =C2=A0 echo -e "$usage\n"
> =C2=A0 =C2=A0 exit 1
> fi
>=20
> if [[ "$GS_FONTPATH" !=3D "$(pwd)" ]] ; then
> =C2=A0 =C2=A0 echo -e "TERMINATION: Wrong working directory or GS_FONTP=
ATH not set.\n" |tee -a $logfile
> =C2=A0 =C2=A0 echo -e "Current directory: $(pwd)" |tee -a $logfile
> =C2=A0 =C2=A0 echo -e "GS_FONTPATH: $GS_FONTPATH" |tee -a $logfile
> =C2=A0 =C2=A0 echo -e "$usage\n"
> =C2=A0 =C2=A0 exit 2
> fi
>=20
> [ ! -f Fontmap ] && echo -e "INFO: Ghostscripts local 'Fontmap' file mi=
ssing, will
> be created.\n" |tee -a $logfile =C2=A0&& touch Fontmap
>=20
> ls *.[oOtT][tT][fF] 2>/dev/null 1>&2
> if [ $? -ne 0 ] ; then
> =C2=A0 =C2=A0 echo -e "TERMINATION: No True or Open Type Font files (.t=
tf,.otf) in directory." |tee -a $logfile
> =C2=A0 =C2=A0 echo -e "$usage\n"
> =C2=A0 =C2=A0 exit 3
> fi
>=20
> availableTTF=3D( $(ls -1 *.[oOtT][tT][fF] | sed 's/\.otf\|\.ttf//i') )
> installedPFB=3D( $(grep -e '^/' Fontmap | sed 's/^.*(\|\.pfb.*$//g') )
>=20
> typeset -i counter
> typeset -i numTTF
> typeset -i numInstalled
> typeset -i numPFB
> numTTF=3D${#availableTTF[*]}
> numInstalled=3D${#installedPFB[*]}
> counter=3D$numInstalled
> numPT1=3D$(ls -1 *.[aApP][fF][bBmM] 2>/dev/null | wc -l )
>=20
> let z=3DnumPT1/2
> let m=3DnumPT1%2
>=20
> if (( $numInstalled < z && m =3D=3D 0 )) ; then
> =C2=A0 =C2=A0 echo -e "WARNING: There are unregistered PS Type1 font fi=
les.\n" |tee -a $logfile
> elif (( $numInstalled > z || m > 0 )) ; then
> =C2=A0 =C2=A0 echo -e "TERMINATION: There are missing PS Type1 font fil=
es. It is recommend to
> syncronize all files and databases in this directory (delete Fontmap an=
d rerun
> $0)\n" |tee -a $logfile
> =C2=A0 =C2=A0 exit 4
> fi
>=20
> echo -e "STATUS: There are $numInstalled installed Postscript Type1 Fon=
ts out of $numTTF
> available True Type or Open Type Fonts for user $USER. \n" >>$logfile
>=20
> if (( $numTTF !=3D $numInstalled ))
> then
> =C2=A0 =C2=A0 for ii in ${availableTTF[*]}; do
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 for jj in ${installedPFB[*]}; do
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if [[ "$ii" !=3D "$jj" ]]; th=
en
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 counter=3D$coun=
ter-1
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fi
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 done
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (( $counter =3D=3D =C2=A00 )) ; then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 queueFonts=3D("${queueFonts[@=
]}" "$ii")
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 fi
> =C2=A0 =C2=A0 =C2=A0 =C2=A0counter=3D$numInstalled
> =C2=A0 =C2=A0 done
> else
> =C2=A0 =C2=A0 echo "INFO: Font database is up-to-date if you have not f=
iddled with the
> contents of this directory or the local Fontmap file manually after the
> last run of this script. Consult the log file for history.
> =C2=A0 =C2=A0
> Nothing to do. No new fonts installed." |tee -a $logfile
> =C2=A0 =C2=A0 exit 0
> fi
>=20
> for ff in ${queueFonts[@]}; do
> =C2=A0 =C2=A0 echo "---------------------------------------------------=
--------------"\
> =C2=A0 =C2=A0 =C2=A0 =C2=A0>>$logfile
> =C2=A0 =C2=A0 echo "START OF TTF2PT1 LOG ENTRY FOR '$ff'" >>$logfile
> =C2=A0 =C2=A0 echo $(date) >>$logfile
> =C2=A0 =C2=A0 echo "---------------------------------------------------=
--------------"\
> =C2=A0 =C2=A0 =C2=A0 =C2=A0>>$logfile
>=20
> =C2=A0 =C2=A0 ttf2pt1 -b $ff.[oOtT][tT][fF] =C2=A0>>$logfile 2>&1
>=20
> =C2=A0 =C2=A0 fontNames=3D("${fontNames[@]}" "$(grep FontName $ff.afm |=
 cut -d' ' -f2-)")
> =C2=A0 =C2=A0 familyNames=3D("${familyNames[@]}" \
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 "$(grep FamilyName $ff.afm | cut -d' ' -f2-=
 | sed 's/ /_/g')")
> =C2=A0 =C2=A0 faceNames=3D("${faceNames[@]}" \
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 "$(grep Weight $ff.afm | cut -d' ' -f2- | \
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 sed -e' s/^./\U&/g; s/ *//g; s/Regular/Base=
/i; s/Italic/Slope/i ')")
> =C2=A0 =C2=A0 tagNames=3D("${tagNames[@]}" "${familyNames[@]:(-1)}-${fa=
ceNames[@]:(-1)}")
>=20
> =C2=A0 =C2=A0 echo "/${fontNames[@]:(-1)} ($ff.pfb);" >>Fontmap
> =C2=A0 =C2=A0
> =C2=A0 =C2=A0 if [[ -z `cat myfontdefs.ld | sed -n '/'"$ff"'.afm/p'` ]]=
 ; then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 cat >>myfontdefs.ld<<LOUT_ENTRY
> { @FontDef
> =C2=A0 =C2=A0 =C2=A0 @Tag { ${tagNames[@]:(-1)} }
> =C2=A0 =C2=A0 =C2=A0 @Family { ${familyNames[@]:(-1)} }
> =C2=A0 =C2=A0 =C2=A0 @Face { ${faceNames[@]:(-1)} }
> =C2=A0 =C2=A0 =C2=A0 @Name { ${fontNames[@]:(-1)} }
> =C2=A0 =C2=A0 =C2=A0 @Metrics { $ff.afm }
> =C2=A0 =C2=A0 =C2=A0 @Mapping { LtLatin1.LCM }
> }
>=20
> LOUT_ENTRY
> =C2=A0 =C2=A0 fi
> =C2=A0 =C2=A0
> =C2=A0 =C2=A0 # Correct for whitespace error in afm files
> =C2=A0 =C2=A0 sed -i 's/.null/space/' $ff.afm
>=20
> =C2=A0 =C2=A0 echo "***************************************************=
**************"\
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 >>$logfile
> =C2=A0 =C2=A0 echo -e "Font: ${fontNames[@]:(-1)}; Tag: ${tagNames[@]:(=
-1)} (has been \
> installed.)" |tee -a $logfile
> done