Font Attributes and Generic Fonts

This section describes font attributes to specify font family, size, style and weight. XSL-FO supports 5 generic font families: serif, sans-serif, cursive, fantasy, and monospace.

According to the XSL-FO specification, a common set of font attributes can be specified in many formatting objects like flow, static-content, block, inline, character, etc. But if they are not specified, a default font will be decided by the XSL processor.

Here some commonly used font attributes:

XSL-FO also supports 5 generic font families: "serif", "sans-serif", "cursive", "fantasy", and "monospace", which will be mapped to specific font families by the XSL processor.

Here is my tutorial example, XSL-FO-Generic-Font-Families.fo, that uses font attributes to select a font from XSL-FO generic font families:

<?xml version="1.0" encoding="utf-8"?>
<!-- XSL-FO-Generic-Font-Families.fo
 - Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="page" 
   margin="0.1in" page-height="4.4in" page-width="3.4in">
   <fo:region-body region-name="body"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="page">
  <fo:flow flow-name="body">
<fo:block margin-top="6pt">Default font:
 <fo:inline background-color="#ffddff">
  The tangram is a dissection puzzle.
 </fo:inline>
</fo:block>
<fo:block margin-top="6pt">Generic font "sans-serif":
 <fo:inline background-color="#ffddff"
  font-family="sans-serif" font-size="12pt">
  The tangram is a dissection puzzle.
 </fo:inline>
</fo:block>
<fo:block margin-top="6pt">Generic font "serif":
 <fo:inline background-color="#ffddff"
  font-family="serif" font-size="12pt" font-style="italic">
  The tangram is a dissection puzzle.
 </fo:inline>
</fo:block>
<fo:block margin-top="6pt">Generic font "cursive":
 <fo:inline background-color="#ffddff"
  font-family="cursive" font-size="12pt" font-weight="bold">
  The tangram is a dissection puzzle.
 </fo:inline>
</fo:block>
<fo:block margin-top="6pt">Generic font "fantasy":
 <fo:inline background-color="#ffddff"
  font-family="fantasy" font-size="12pt">
  The tangram is a dissection puzzle.
 </fo:inline>
</fo:block>
<fo:block margin-top="6pt">Generic font "monospace":
 <fo:inline background-color="#ffddff"
  font-family="monospace" font-size="12pt">
  The tangram is a dissection puzzle.
 </fo:inline>
</fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

If you process this example XSL-FO document with Apache FOP tool on the AWT window, you will get some warnings:

C:\herong>\fop\fop -fo XSL-FO-Generic-Font-Families.fo -awt

... org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "cursive,normal,700" not found. 
Substituting with "any,normal,700"

... org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "fantasy,normal,400" not found. 
Substituting with "any,normal,400"

... org.apache.fop.render.java2d.Java2DRenderer getPageImage
INFO: Rendering Page 1 (pageWidth 245, pageHeight 317)

Those warnings tell us that Apache FOP does not have built-in font to support "cursive,normal,700" and "fantasy,normal,400". Note that font-weight "normal" is "400" and "bold" is "700".

The picture below shows you how the Apache FOP AWT output looks like:

XSL-FO Generic Font Families

As can see from the first block, Apache FOP uses "sans-serif" as the default font family.

Last update: 2016.

Table of Contents

 About This XSL-FO Tutorial Book

 Introduction of XSL-FO

 Apache™ FOP (Formatting Objects Processor)

 RenderX XEP as an XSL-FO Tool

 Introduction of Area Model

 XSL-FO Document Basics and Examples

 Page Layout Masters

 Block-Level Formatting Objects

 Inline-Level Formatting Objects

 Including Graphics in XSL-FO document

 Table of Rows and Columns

 List, Item, Label, and Body

 Floating Blocks - "float" and "footnote"

 Hyperlinks, Table of Contents and Indexes

 Headers and Footers using "static-content"

Font Attributes and Font Families

 What Is a Font?

Font Attributes and Generic Fonts

 Adobe PDF Base-14 Fonts

 Generic Font for Chinese Characters

 Apache FOP Font Configurations

 RenderX XEP Font Configurations

 References

 PDF Printing Version