Chapter 5. Stylesheet Contents

1. @charset declaration
2. Specifying page sizes
3. Selectors
4. Paragraph and Character Styles
5. @media rules
6. Contents Language: xml:lang

This section describes details on what a downCast stylesheet should contain and how it is processed by the application. The following parts are the minimal elements a stylesheet must contain:

Important

Due to specifics and compatibility reasons with existing CSS aware applications, you cannot use the space character (0x20) in CSS class names, though RTF does allow and actually use these for several of its standard style names. Therefore, you need to replace them by a non-breaking space character (0xa0 hex, ?\00a0 ? in CSS escape sequence notation). Non-breaking spaces are converted to normal space characters automatically when rendering the RTF by downCast.

Some of these components will be detailed on in the following.

1. @charset declaration

downCast supports the @charset at-rule for specifying the encoding of a stylesheet. upCast writes the stylesheet in UTF-8 encoding. For compatibility reasons, we recommend specifying UTF-8 as the encoding, but making sure you only use plain ASCII characters in the contents and use the CSS escaping mechanism ('\' [0-9A-Fa-f]{1,6} ' ') for all characters with a Unicode code point higher than 127.

Specify the @charset rule as the very first item in a CSS file:

@charset "UTF-8";
/* remaining stylesheet contents... */

2. Specifying page sizes

Paper and page sizes are specified using the CSS2 @page rules. The size property specifies the actual paper sheet size, and with the margin-... properties, you define the margins inward from the paper size. You can use the pseudo selectors :first, :left and :right to specify different margin setups for the first page, all left pages and all right pages respectively of the contents of a part.

@page mainmatter { size: 210.0mm 297.0mm; margin-top: 25.0mm; margin-bottom: 20.0mm; margin-left: 25.0mm; margin-right: 25.0mm; }

specifies a named page layout with a paper size of A4 and with margins as specified at the respective sides. To refer to this page layout on a part in the XML document instance, you would use a style attribute as follows:

<part style="page: mainmatter;">
   ...
</part>

You can also add the -ilx-page-numbering-* properties to an @page rule.

3. Selectors

downCast does not understand (CSS2-) selectors other than the shorthand notation for class selectors, i.e. selectors that look for a certain value of the class attribute on an element:

.class { definition }

and its mostly equivalent:

*[attname="value"] { definition }

Some elements do not evaluate attached class attributes, part and section among them.

This limitation will be addressed in a subsequent release.

Note

Experimental support only is included for he following type of selectors:

element { definition }
element[attname] { definition }
element[attname="value"] { definition }
*#id { definition }

4. Paragraph and Character Styles

RTF has the concept of Paragraph Styles and Character Styles. These are supported by downCast in the following way:

  • From a CSS rule with a selector only based on the class attribute and a value for the display property of inline, downCast will create a character style in the resulting RTF document with the value of the class attribute as the style name.

  • From a CSS rule with a selector only based on the class attribute and a value for the display property of block, downCast will create a paragraph style in the resulting RTF document with the value of the class attribute as the style name.

Important

Any non-breaking space characters in the value will be replaced by normal spaces.

This character translation is necessary to allow style names that contain spaces. If you wrote

<par class="first paragraph">...</par>

, the contents of the class attribute would be interpreted as a list of values { first, paragraph } according to the XML specification. To have the two parts treated as a single token, you need to use a different character than the normal space, and downCast uses the non-breaking space (&nbsp;) for this. Any non-breaking space in a stale name will be converted to a normal space at the time of writing the resulting RTF file.

To get the equivalent of assigning a character or paragraph style to an element in an application like Word, you need to set the class attribute of the respective element in the XML document to the corresponding selector value of the desired style rule in the CSS.

downCast automatically generates correct style table entries and code to link the RTF document contents to that style definition.

Note

RTF does not support nested, named character styles, only one specific character style can be active at any position in the document (together with exactly one paragraph style). A construction like

<inline class="emph">use <inline class="tag">part</inline> elements</inline>

will be treated in RTF as if it was written like

<inline class="emph">use </inline><inline class="tag">part</inline><inline class="emph"> elements</inline>

5. @media rules

downCast supports the use of @media rules, that is sets of specific rules that the stylesheet author only intends to be used for certain kinds of output media like display in a browser on screen compared to printed output on paper.

downCast respects all rules without any specific media kind specified as well as @media print. This allows you to author a single stylesheet for optimized output depending on the output medium by specifying rule variations in different @media blocks.

Also supported is the media dependant @import of external stylesheets.

6. Contents Language: xml:lang

downCast supports the use of the xml:lang attribute on elements. Most two-byte language codes are supported.