Next / Previous / Contents / Shipman's homepage

4.20. font(): Dictionary of font properties

The etbuilder module makes it convenient to use keyword arguments to add XML attributes. However, this works only when the attribute names are valid Python identifiers. Unfortunately large numbers of XSL-FO attribute names have hyphens in them, e.g., font-size and the other font properties.

The purpose of the font() function, then, is to allow you to create a dictionary of standard XSL-FO font properties using keyword arguments. Here is the calling sequence:

font(fontFamily=None, fontSize=None, fontStyle=None,
     fontWeight=None, fontVariant=None, fontStretch=None)

The result is a dictionary. Each of the keyword arguments, if you supply it, becomes a key-value pair in this dictionary, except the key is converted to the corresponding font-related attribute. For example, an argument “fontFamily='Helvetica'”, in the result, becomes the key-value pair font-family='Helvetica'. The default for each of the arguments is not to have that key-value pair in the resulting dictionary. Here's an example.

>>> h.font(fontVariant='small-caps', fontStyle='italic',
...        fontSize='11pt', fontFamily='monospace')
{'font-size': '11pt', 'font-family': 'monospace', 'font-style':
'italic', 'font-variant': 'small-caps'}