Configuring
Font Configuration
The main task involved in configuring the AFP Renderer is to specify the name and location of AFP font files for each typeface, size and style used (the AFP Renderer uses these files to calculate the size and position of rendered elements on each page).
The AFP Renderer reads a file called afp-fonts.xml
from the
root of the classpath to determine the location of the AFP font files. An
example of afp-fonts.xml
is included as part of the
distribution (inside the resources directory). However, this file only
refers to a limited set of fonts, which are distrubuted under a restrictive
licence, so most users of the AFP Renderer will need to create their own.
afp-fonts.xml
Reference
afp-fonts.xml
has the following structure:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE installed-fonts PUBLIC "-//APACHE/DTD AFP Installed Font Definition DTD 1.1//EN" "http://org.apache.fop/installed-afp-fonts-1.1.dtd"> <installed-fonts path="..."> <afp-font id="..." codepage="..." encoding="..."> <raster size="..." weight="..." style="..." characterset="..."/> ... </afp-font> <afp-font id="..." codepage="..." encoding="..."> <outline weight="..." style="..." characterset="..."/> ... </afp-font> ... </installed-fonts>
Reference material for each of the elements above can be found below.
<!DOCTYPE installed-fonts>
The xml DOCTYPE is required exactly as shown above.
<installed-fonts>
<installed-fonts>
is the top level element in
afp-fonts.xml
. It acts as a container for one or more child
<afp-font>
elements.
Attribute | Definition |
---|---|
path | The path to the codepage and characterset files. The AFP Renderer will combine the value of this attribute with the name of the codepage or characterset to generate a path to a file. It will try and resolve file in the classpath. If this is unsuccessful, it will then try and find the file in the filesystem. |
<afp-font>
<afp-font>
is a child of the <installed-fonts>
element. The valid child elements are either one or more <raster>
elements or one or more <outline>
elements.
Attribute | Definition |
---|---|
id | The identifier for the font. This identifier corresponds to the
"font-family" attribute using within the XSL-FO input. If an <afp-font> element has an id of "any", it
will be used for unrecognised "font-family" names. |
codepage | The codepage of the font. In order to locate the resource for
the codepage, the value of this attribute is combined with the path
attribute on the <installed-fonts> element, and
the codepage value is appended to this in order determine the
resource path. File extensions are ignored for the purpose of
finding the codepage resource. |
encoding | The encoding of the codepage file. Common values for this attribute are "Cp1146" for files encoded in EBCIDIC, or "Cp1252" for files encoding in ASCII. Many other codepages are possible. |
<raster>
<raster>
can be a child of the <afp-font>
element. It specifies the size, weight, style and characters of a raster
font.
Attribute | Definition |
---|---|
size | The font size in points. |
weight | Can be either "normal" or "bold". |
style | Can be either "normal" or "italic". |
characterset | The characterset of the font. The value of this attribute is
combined with the path attribute on the
<installed-fonts> element in order to locate the
characterset file. |
<outline>
<outline>
can be a child of the <afp-font>
element. It specifies the weight, style and characters of an outline font.
Attribute | Definition |
---|---|
weight | Can be either "normal" or "bold". |
style | Can be either "normal" or "italic". |
characterset | The characterset of the font. In order to locate the resource
for the characterset, the value of this attribute is combined with
the path attribute on the <installed-fonts>
element, and the characterset value is appended to this in order
determine the resource path. File extensions are ignored for the
purpose of finding the characterset resource. |
afp-fonts.xml
Example
The example afp-fonts.xml
shown below is distributed as part
of the AFP Renderer, in the resources directory.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE installed-fonts PUBLIC "-//APACHE/DTD AFP Installed Font Definition DTD 1.1//EN" "http://org.apache.fop/installed-afp-fonts-1.1.dtd"> <installed-fonts path="fonts/240"> <afp-font id="any" codepage="T1TS0285" encoding="Cp1146"> <raster size="10" weight="normal" style="normal" characterset="C0TSRG10"/> <raster size="10" weight="normal" style="italic" characterset="C0TSIT10"/> <raster size="10" weight="bold" style="normal" characterset="C0TSBO10"/> <raster size="10" weight="bold" style="italic" characterset="C0TSBI10"/> <raster size="12" weight="normal" style="normal" characterset="C0TSRG12"/> <raster size="12" weight="normal" style="italic" characterset="C0TSIT12"/> <raster size="12" weight="bold" style="normal" characterset="C0TSBO12"/> <raster size="12" weight="bold" style="italic" characterset="C0TSBI12"/> </afp-font> <afp-font id="TerrapinSans240" codepage="T1TS0285" encoding="Cp1146"> <raster size="10" weight="normal" style="normal" characterset="C0TSRG10"/> <raster size="10" weight="normal" style="italic" characterset="C0TSIT10"/> <raster size="10" weight="bold" style="normal" characterset="C0TSBO10"/> <raster size="10" weight="bold" style="italic" characterset="C0TSBI10"/> <raster size="12" weight="normal" style="normal" characterset="C0TSRG12"/> <raster size="12" weight="normal" style="italic" characterset="C0TSIT12"/> <raster size="12" weight="bold" style="normal" characterset="C0TSBO12"/> <raster size="12" weight="bold" style="italic" characterset="C0TSBI12"/> </afp-font> </installed-fonts>