Writing mode and text direction

XSL-FO has ability to deal with non-Western writing systems. You ca use horizontal or vertical lines, define the order of characters and line stacking. For these puproses writing-mode property should be used. This property can be specified inside <fo:simple-page-master>, <fo:region>, <fo:table>, <fo:block-container>, and <fo:inline-container> elements.

The writing-mode property has the following values:

  • The primary values are:
    • lr-tb (default) is used for normal text (alphabetic). Inline components and text within a line are written left-to-right. Lines and blocks are placed top-to-bottom.
    • rl-tb is used in Arabic and Hebrew text. Inline components and text within a line are written right-to-left. Lines and blocks are placed top-to-bottom.
    • tb-rl is used in Chinese and Japanese text. Inline components and text within a line are written top-to-bottom. Lines and blocks are placed right-to-left.
  • The other values are:
    • tb-lr. Inline components and text within a line are stacked top-to-bottom. Lines and blocks are stacked left-to-right.
    • bt-lr. Inline components and text within a line are stacked bottom-to-top. Lines and blocks are stacked left-to-right.
    • bt-rl. Inline components and text within a line are stacked bottom-to-top. Lines and blocks are stacked right-to-left.
    • lr-bt. Inline components and text within a line are stacked left-to-right. Lines and blocks are stacked bottom-to-top.
    • rl-bt. Inline components and text within a line are stacked right-to-left. Lines and blocks are stacked bottom-to-top.
    • several values with alternating and inverting directions.

Here is a simple example:

   <fo:block-container writing-mode="rl-tb">
     <fo:block xml:lang="ar"> 
       Imagine that this text is in Arabic. 
     </fo:block>
   </fo:block-container>

Sometimes it is needed to mix several writing directions (in mixed-language contexts) in one text segment. This is possible due to the Unicode Bidi algorithm that defines a complex algorithm for determining the proper directionality of text.

When the Unicode Bidi algorithm is not enough and fails, the <fo:bidi-override> element is used. The <fo:bidi-override> forces a string of text to be written in a specific direction. It has 2 properties:

  • direction
  • and
  • unicode-bidi

The direction property defines the base writing direction of blocks, the direction of embeddings and overrides and, additionally, the direction of table column layout and the direction of horizontal overflow. This property has 2 values:

  • ltr (default) defines left to right direction.
  • rtl defines right to left direction.

The unicode-bidi property defines the behaviour of a text span with respect to the Unicode bidi algorithm. It has the following values:

  • normal - characters are ordered by Unicode Bidi algorithm.
  • embed - an additional level of embedding is opened and the direction of the embedded level is given by the direction property.
  • bidi-override - orders characters inside an element (inline-level or block-level with only inline-level elements) according to the direction property.

Here is a simple example:

   <fo:block text-align="left" space-after.optimum="15pt">
     Here is a paragraph of some text
     <fo:bidi-override direction="ltr" unicode-bidi="bidi-override">
	   Text here goes left to right.
     </fo:bidi-override>
     <fo:bidi-override direction="rtl" unicode-bidi="bidi-override">
	   and here - right to left.
     </fo:bidi-override>
   </fo:block>