Lists style

We can change the way a list is displayed by using a ListStyle object.

A list style is assigned to a specific level of a list, not to the whole list; If a list is not contained within another one, the list level is 1. If the list is contained within another list, the list level is the level of the containing list incremented by one.

To create a TextStyle, we call the constructor, passing the name of the list style as argument.

$listStyle = new ListStyle('myListStyle');

Then, we assign it to a list using the method setStyle of the class ODTList.


Number level

If we want the items of a list to be preceded by a number, we use the method setNumberLevel($level, $numFormat, $textstyle).

  • $level: The level that will be modified.
  • $numFormat, (optional): The format of the numbers, which is a NumberFormat instance.
  • $textstyle (optional): This TextStyle object will be applied to the numbers displayed.

Number format

Using the class NumberFormat, we can change the way numbers are displayed, like adding a prefix before the number, or suffix after; we can also specify what type of numbering we want: Numeric(1, 2, 3, ...), Alphabetic(a, b, c, ... or A, B, C, ...) or Roman(i, ii, iii, iv, ... or I, II, III, IV,...).

The constructor of NumberFormat has 3 arguments:

  • $prefix: what will be displayed before the number.
  • $suffix: what will be displayed after the number.
  • $format: what type of numbering we want. The possible values are: "1", "a", "A", "i", or "I", meaning respectively: numeric, lowercase alphabetic, uppercase alphabetic, lowercase roman, uppercase roman.
$listStyle = new ListStyle('myListStyle');
$numberFormat = new NumberFormat('', '', 'a');
$listStyle->setNumberLevel(1, $numberFormat);

$list = new ODTList(array('item1', 'item2', 'item3'));

$sublist = new ODTSubList(array('item3.1', 'item3.2', 'item3.3'));

You can see that the alphabetic number format was applied to the first level of the list.

Bullet level

If we want to make the list items preceded by a bullet, we can use setBulletLevel($level, $bulletChar, $prefix, $suffix, $textstyle).

  • $level: The level we want to change.
  • $bulletChar (optional): The character to use as the bullet.
    • StyleConstants::BULLET: •
    • StyleConstants::BLACK_CIRCLE: ●
    • StyleConstants::CHECK_MARK: ✔
    • StyleConstants::RIGHT_ARROW: ➔
    • StyleConstants::RIGHT_ARROWHEAD: ➢
  • $prefix (optional): The characters to add before the bullet character.
  • $suffix (optional): The characters to add after the bullet character.
  • $textstyle (optional): The TextStyle to use to format the list bullet.
$listStyle = new ListStyle('myListStyle');
$listStyle->setBulletLevel(1, StyleConstants::RIGHT_ARROW);

$list = new ODTList(array('item1', 'item2', 'item3'));

Image bullet

To use an image as a bullet, we use the method setImageLevel($level, $image).

$listStyle = new ListStyle('myListStyle');
$listStyle->setImageLevel(1, 'bullet.png');

$list = new ODTList(array('item1', 'item2', 'item3'));