groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] opentype and postscript fonts


From: Pierre-Jean
Subject: Re: [Groff] opentype and postscript fonts
Date: Fri, 03 Sep 2010 18:01:46 +0200


I've made some tests. Here is a tutorial about how to use
OpenType fonts with groff.

1) OpenType font format is just an encapsulation of
TrueType fonts or PostScript fonts. When choosing an
OpenType font, one must be carefull to choose a PostScript
one. Usualy, font.otf is a postscript one, and font.ttf is
a truetype one.

A single opentype font contain different features of each
letters. For example, it contains small caps, old style
numbers, superscripts... In the font, the variants glyphs
are named "glyph.variant", for example:
        small caps a is named: a.smcp
        old style one is named: one.onum

To make some tests, I've found a free (as in beer) opentype font:
Calluna-Regular.otf

2) To get the postscript font from the Opentype font,
some tools from lcdf-typetools are needed: cfftot1 and
t1rawafm. They are part of texlive-bin. If you don't want to
install texlive-bin, you can build them like this:

$ wget http://www.lcdf.org/~eddietwo/type/lcdf-typetools-2.83.tar.gz
$ tar -xf lcdf-typetools*.tar.gz
$ cd lcdf-typetools*
$ ./configure --without-kpathsea
$ make
$ make install
$ cd ../

3) It's now possible to adapt the opentype font to groff
(we assume that your font is "font.otf", and we build a
Roman font named fontR):

$ cfftot1 -a font.otf > font.pfa
$ t1rawafm font.pfa > font.afm
$ afmtodit -d DESC font.afm textmap fontR

4) `afmtodit` has build a groff font file.
For each glyph of the font, the groff font file contain a
line in the form:

        name metrics type code [entity_name] [-- comment]

The problem is that the glyphs variants are unnamed.
For the moment, we have to manually rename them, using this
sed line:

$ sed -i -e "
s/---\t\([^\t]*\)\t\([^\t]*\)\t\([^\t]*\)\t\(.*\)/\4\t\1\t\2\t\3\t\4/" \
fontR

This way, glyphs variants can be accessed using
\[glyph.variant] within groff, for example:
        \[a.smcp] or \[one.onum]

Note that this might change one day, as Werner Lemberg wrote:
> Hmm.  Perhaps we shall add an option to `afmtodit' to retain glyph
> variants.  Opinions?

5) Now, we can install the font (be sure that
GROFF_FONT_PATH is set):

$ cp fontR $GROFF_FONT_PATH/devps/
$ cp font.pfa $GROFF_FONT_PATH/devps/
$ cp font.afm $GROFF_FONT_PATH/devps/

6) When we build a postscript document, the font should be
build inside it. So, we must tell groff to "download" the
font. This is made by inserting a line inside the
"download" file.

$ cp /usr/share/groff/current/devps/download \
  $GROFF_FONT_PATH/devps/

The download file must contain a line in the form "font
filename", where font is the PostScript name of the font
(Calluna_Regular), and filename is the name of the file
containing the font (font.pfa).

The file containing the font is font.pfa, and to know the
Postscript name of the font, do:

$ grep internalname fontR | cut -d " " -f 2

So, let's add these names in $GROFF_FONT_PATH/devps/download:
Calluna_Regular font.pfa


7) To may use the differents features of the font with
groff, we have to map the characters according to the
feature we want. For example, if we want to write a small
caps "a", we should do:

.char a \[a.smcp]

This can be done manually by reading the groff font file,
but it's painfull. I've made a script which will build a
file containing macro to easyly use the glyphs variants.
The script also build a testfile to test the font and the
macros. Here it is:


################################################################################
#! /bin/sh
# font2macro
# Make some macro to use opentype features in a groff font.
# You can copy, modify, distribute freely this.
# Use it at your own risks.

FONTFILE="$GROFF_FONT_PATH/devps/$1$2"
FONT="$1"
TEXTMAP="/usr/share/groff/current/font/devps/generate/textmap"

# get list of features from groff font file
# (assuming that feature appear in the "entity_name" field of the file
# in the form "glyph.feature").
FEATURES=$(sed -n -e "
s/[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^.]*\.\(.*\)/\1/p" \
$FONTFILE)

for FEATURE in $FEATURES; do
        if ! echo $DONE | grep -q $FEATURE; then
                echo "$FEATURE"
                echo ".de $FEATURE" >> begin
                echo ".de S_$FEATURE" >> end
                # Get a list of glyphs having the feature
                GLYPHS=$(sed -n -e "s/^\([^.]*\)\.$FEATURE\t.*/\1/p" \
                $FONTFILE)
                for GLYPH in $GLYPHS; do
                        # Get the groff name of the glyph if it exists
                        NAME=$(sed -n -e "3,/^$GLYPH /s/^$GLYPH \(.*\)/\1/p" \
                        $TEXTMAP)
                        # If the glyph name is not found, comment the line
                        # where it appears in the macro file.
                        # Orelse, write it correctly.
                        case ${#NAME} in
                                0) echo -n ".   \\\"" >> begin
                                        echo -n ".      \\\"" >> end
                                        NAME="$GLYPH" ;;
                                1) NAME="$NAME" ;;
                                *) NAME="\\[$NAME]";;
                        esac
                        if [ "$NAME" = "\\" ]; then NAME="\\[\\]"; fi
                        echo ". char $NAME \\[$GLYPH.$FEATURE]" >> begin
                        echo ". rchar $NAME" >> end     
                done
                echo ".." >> begin
                echo ".." >> end
                cat begin >> $FONT.tmp.tmac
                cat end >> $FONT.tmp.tmac
                rm begin
                rm end
                DONE="$DONE $FEATURE"
        fi
done

# build the macro file 
echo ".ig
$FONT.tmac
tmac solution to use $FONT
Should be edited by hand.
List of features:
$DONE
.." >> $FONT.tmac

cat $FONT.tmp.tmac >> $FONT.tmac
rm $FONT.tmp.tmac

# build the test file
echo ".do mso $(pwd)/$FONT.tmac
.tl ''Test of $FONT and $FONT.tmac''
.sp 1
.de TEST
.fam $FONT
.while \\\\n[.\$] \\{\\
\&\\\\\$1: 
.br
.\\\\\$1
Portez ce vieux whisky au juge blond qui fume.
\\['e] \\[\`e] \\[~n] \\[ss] \\[oe] fi fl ff ct
.br
PORTEZ CE VIEUX WHISKY AU JUGE BLOND QUI FUME.
\\['E] \\[\`E] \\[~N] \\[OE] FI FL FF CT
.br
1234567890. .,;:?! ยง$@& ()[]{} ~#|-_ \\[Fo]\\[Fc]\"\'
\\[Eu]\\[Ye]\\[Po]\\[ct]\\[Fn]
.S_\\\\\$1
.sp 1
.       shift
.\}
..
.TEST$DONE" >> testfile

exit 0
###############################################################################

7) Copy the script in a file named font2macro.  font2macro
need two argument: the name of the font (here it is "font")
and the name of the subfont (here it is "R"). Launch it, wait
a few, and test the new macro file: 

$ chmod u+x ./font2macro
$ ./font2macro fontR
$ groff testfile > test.ps

8) You should manually edit the macro file "font.tmac" to give
a name to unnamed glyphs, and copy it in your tmac directory:

$ cp font.tmac $GROFF_TMAC_PATH/

9) Clean your dir:

$ rm fontR
$ rm font.afm
$ rm font.pfa
$ rm font.tmac
$ rm test.ps
$ rm lcdf-typetools*.tar.gz
$ cd lcdf-typetools*
$ make uninstall
$ cd ../
$ rm -rf lcdf-typetools*

10) Use the features of your font this way:

.do mso font.tmac
.smcp
My text in small caps.
.S_smcp
My text in normal caps.


Enjoy!

Pierre-Jean.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]