Fonts and FOP
with the expert help of Marie-Anne Moreaux (INaLCO)
- Motivation
- About the standard fonts
- Definition
- Typefaces with the same names...
- FOP configuration files
- Option of the fop command
- .xconf files
- A complete solution
- Configuration file
- XSL transform
- Result
-
Apache FOP is equipped with standard fonts, which are able to
cope
with the most frequent situations (from a Western point of view).
If for some reason you need any other font, then you have to register
it thanks to a configuration file for FOP.
This may happen on two different grounds:
- for purely graphic reasons: you must use a certain font
because
it is part of the graphic charter of your project;
- for linguistic reasons: the language you write requires a
character set outside the range provided by the standard fonts
(i.e. basically, Latin-1).
The present document takes the second point of view.
Our starting point is the experience of Zuzana Lietavcová, whose
DocBook report is in Czech: while written with the Latin alphabet,
the language requires a number of
accented letters (such as 'ř'
which appears in the name
of the famous musician Antonín Dvořák), some of which are not
served by the standard fonts. As a consequence, the missing
characters are rendered by FOP as '#'.
For instance, the first sentence of her
report, which should read
Při ohlášení projektů do předmětu ITU došlo mezi
studenty k silné
debatě a obecnému nadšení.
appears as
P#i ohlášení projekt# do p#edm#tu ITU došlo mezi
studenty k silné
debat# a obecnému nadšení.
Our aim is to solve this problem.
-
-
Actually, these are the fonts that are required by any PDF processor [Apache FOP Fonts].
PDF prescribes a set of 14 standard fonts
that
can be used without
prior definition.
These include four faces each of three Latin text
typefaces (Courier, Helvetica*, and Times*), as well as two symbolic
fonts (Symbol and ITC Zapf Dingbats®).
These fonts, or suitable
substitute fonts with the same metrics, are guaranteed to be available
in all PDF viewer applications.
[PDF Reference third edition]
Recall the difference of meaning between the words font and typeface
:
- typeface is equivalent to font-family,
e.g. Helvetica, Times, Courier are
different typefaces (or polices
in French),
- specifying a number of features (such as serif,
monospace, etc)
- but leaving open the weight (bold or
normal), the style
(italics or roman), and the size
!
- font in the strict sense means a fully specified
character set such as Times
italics bold 12pt.
The name comes from lead typography, when character sets of different
sizes were stored in different cases.
The distinction is not so important nowadays, and font is used
in an extended sense, often equivalent to typeface.
(If you care about the proper use of words, have a look at this interesting discussion).
Here, however, a distinction is maintained, as you will see right now.
The PDF standard fonts are known as Base-14.
- Helvetica, normal, bold, italic, bold italic (4 font
files),
doing service for sans-serif;
- Times, normal, bold, italic, bold italic (4 font files),
doing service for serif;
- Courier, normal, bold, italic, bold italic (4 font
files),
doing service for monospace;
- Symbol, for Greek and other special characters (1 font
file);
- Zapf Dingbats, for ornament (1 font file).
Total is 14 font files.
This a minimal font set that satisfies the needs of a prominent group
of Western languages, as seen in 1993, date of the publication of the
PDF spec.
But there is a possibie misunderstanding about the exact meaning of the
list...
-
Helvetica, Times, Courier are available today on
most computers, but with a much more complete coverage !
Our above extract is perfectly displayed with Times
italics bold 12pt :
Při
ohlášení projektů do předmětu ITU došlo mezi
studenty k silné
debatě a obecnému nadšení.
Therefore a first step toward solving our problem will be to ensure
that our PDF generator (FOP) makes use of the system's fonts
rather than the PDF standard fonts.
This will be achieved by using a proper configuration for FOP.
-
-
[Review
fop
use]
The command 'sh /Path/To/.../fop-1.1/fop -xml Menu.xml -xsl
Menu2FO.xsl -pdf Menu.pdf
'
becomes
'sh /Path/To/.../fop-1.1/fop -c myConf.xconf
-xml Menu.xml -xsl Menu2FO.xsl -pdf Menu.pdf
'
-
are XML files conforming to the model given in
fop-1.1/conf/fop.xconf
.
Actually most of this document deals with the AFP renderer (AFP = Advanced Function Presentation) which does
not concern us.
For our present purposes, we only need to cater for the PDF renderer <renderer
mime="application/pdf">
.
See here for details.
Here is a short configuration file importing only one system font, Arial
Unicode : call it Conf-AU.xconf
<?xml version="1.0"?>
<!-- Arial Unicode only -->
<fop version="1.0">
<!-- Base URL for resolving relative URLs -->
<base>.</base>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font
embed-url="/Library/Fonts/Arial Unicode.ttf">
<font-triplet
name="Arial Unicode" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
Note that the use of font metrics files is no
longer necessary, contrary to some outdated info about DocBook.
".ttf
" files are imported "as they are".
Now let us use this font both for text body and for titles : doc2fo-AU.xsl
<?xml version='1.0'?>
<!DOCTYPE stylesheet [
<!ENTITY dbdir
"/Path/to/.../DocBook/docbook-xsl-ns-1.78.1">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://docbook.org/ns/docbook"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:import href= "&dbdir;/fo/docbook.xsl"/>
<xsl:output method="xml" indent="yes"/>
<!-- setting paper size -->
<xsl:param name="paper.type" select="'A4'"/>
<!-- fonts -->
<xsl:param name="body.font.family" select="'Arial
Unicode'"/>
<xsl:param name="title.font.family" select="'Arial Unicode'"/>
<!-- ensuring a page break before first-level sections
-->
<xsl:attribute-set name="section.level1.properties">
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>
and execute
sh /Path/To/.../fop-1.1/fop -c Conf-AU.xconf
-xml DocReport.xml -xsl doc2fo-AU.xsl -pdf Report-AU.pdf
.
Here is a snippet showing how our critical extract is rendered :
This shows that,
- as expected, our Arial Unicode font contains all the
necessary glyphs to correctly print Czech,
- but also that the weight attribute is not dealt
with : the title is indeed set in a larger size, as prescribed, but not
bold !
Further exmination reveals that there are no italics either.
We must do better !
-
This time we import the 3 usual typefaces (Helvetica, Times, Courier for sans-serif, serif
and monospace),
and for each the 3 font
files (normal, bold, italic) that are available.
They are enough for the traditional rendering, bold italic
being synthetized from bold and italic.
Note that on some systems these typefaces are bundled as dfont
files, which are not suitable for importing.
You must unpack them to get hold of the individual .ttf
files, e.g. via Transfonter : http://transfonter.org/ttc-unpack
-
Conf-HTC.xconf
<?xml version="1.0"?>
<!-- Helvetica, Times, Courier -->
<fop version="1.0">
<!-- Base URL for resolving relative URLs -->
<base>.</base>
<!-- Information for specific renderers -->
<!-- Uses renderer mime type for renderers -->
<renderers>
<renderer mime="application/pdf">
<fonts>
<font
embed-url="/users/jfp/Library.new/Fonts/Helvetica.ttf">
<font-triplet
name="Helvetica" style="normal" weight="normal"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Helvetica-Bold.ttf">
<font-triplet
name="Helvetica" style="normal" weight="bold"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Helvetica-Oblique.ttf">
<font-triplet
name="Helvetica" style="italic" weight="normal"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Times-Roman.ttf">
<font-triplet
name="Times" style="normal" weight="normal"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Times-Bold.ttf">
<font-triplet
name="Times" style="normal" weight="bold"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Times-Italic.ttf">
<font-triplet
name="Times" style="italic" weight="normal"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Courier.ttf">
<font-triplet
name="Courier" style="normal" weight="normal"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Courier-Bold.ttf">
<font-triplet
name="Courier" style="normal" weight="bold"/>
</font>
<font
embed-url="/users/jfp/Library.new/Fonts/Courier-Oblique.ttf">
<font-triplet
name="Courier" style="italic" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
-
We try to make it a bit more elaborate, in order to make
full use of our fonts...
For technical details, see the Cookbook.
doc2foHTC.xsl
<?xml version='1.0'?>
<!DOCTYPE stylesheet [
<!ENTITY dbdir "
/Path/to/.../DocBook
/docbook-xsl-ns-1.78.1">
]>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:d="http://docbook.org/ns/docbook"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href= "&dbdir;/fo/docbook.xsl"/>
<xsl:output method="xml" indent="yes"/>
<!-- setting paper size -->
<xsl:param name="paper.type" select="'A4'"/>
<!-- fonts -->
<xsl:param name="body.font.family"
select="'Helvetica'"/>
<xsl:param name="title.font.family" select="'Times'"/>
<!-- automatic numbering of sections -->
<xsl:param name="section.autolabel" select="1" />
<!-- do not print URL after link texts -->
<xsl:param name="ulink.show" select="0"/>
<!-- ensuring a 30pt space before first-level sections -->
<xsl:attribute-set name="section.level1.properties">
<xsl:attribute
name="space-before">30pt</xsl:attribute>
</xsl:attribute-set>
<!-- ensuring a 15pt space before second-level sections -->
<xsl:attribute-set name="section.level2.properties">
<xsl:attribute
name="space-before">15pt</xsl:attribute>
</xsl:attribute-set>
<!-- hypertext links as in traditional HTML -->
<xsl:attribute-set name="xref.properties">
<xsl:attribute name="color">blue</xsl:attribute>
<xsl:attribute
name="text-decoration">underline</xsl:attribute>
</xsl:attribute-set>
<!-- special rule for captions -->
<xsl:template match="d:caption/d:para">
<fo:block font-family="Courier"
space-after="30pt">
<xsl:apply-imports />
</fo:block>
</xsl:template>
</xsl:stylesheet>
-
Showing that bold is taken care of...
...as well as bold+italic.