Font and text attributes

The text that is used within <fo:block> element can be enriched with font attributes. XSL-FO font attributes are taken from CSS2. You can use the following font attributes:

  • font-family
  • font-size
  • font-style
  • font-weight

These are the most used font attributes, to see the full list follow Common Font Properties section in the W3C XSL 1.1 Recommendation. All attributes can be enumerated inside one font property. It has the following syntax:

[<style, weight, and/or variant>] <size> [/<line height>] <family>

You can also set hyphenation properties. Here are several of them:

  • country - specifies a country in conformance with ISO 3166 to be used by formatter
  • language - specifies the language to be used by the formatter
  • hyphenate - specifies whether hyphenation is allowed

Text also can be alligned. There are two attributes:

  • text-allign describes how content of a <fo:block> element is aligned and have the following values: left, right, center, and justify.
  • text-allign-last specifies the allignment of the last line of the last block.

Additionally you can decorate and transform text using text-decoration and text-transform attributes respectively.

Here is a simple XSL-FO example that illustrates the usage of introduced attributes:

   <fo:block font-family="Calibri" font-size="12pt" font-weight="bold" font-style="italic" 
	   hyphenate="yes" text-align="center">
     Hello, World!

It is also possible to use one font property font="italic bold 12 pt Calibri" instead of all font attributes.

To change text direction see "Writing mode and text direction" section.