Using CSS with the speedata Publisher

CSS (Cascading Stylesheets) is a language mainly used on the web to determine the appearance of objects. The idea is to separate formatting from content. On the web - so the pure teaching - the content is described in HTML, while the appearance is determined by CSS. With the speedata Publisher the separation is even clearer. The data usually contains no information about the appearance, while the layout rules have no information about the data.

The speedata Publisher relies exclusively on the built-in language when formatting the objects. Some elements can be designed using CSS. In the Publisher this is only rudimentary: Currently the commands <Box>, <Circle>, <Frame>, <Paragraph>, <Rule>, <Td>, <Tablerule> and <U> can be formatted via CSS. The Command Reference lists the commands with the associated attributes that can be accessed via CSS functionality.

The CSS implementation in the speedata Publisher has more the character of a "proof of concept" or prototype. The commands and properties that can be controlled via CSS are very limited.

A CSS stylesheet can be available and integrated as an external file. Alternatively, one can write CSS instructions directly into the layout rules. <Stylesheet> is the command for both variants:

<Layout xmlns="urn:speedata.de:2009/publisher/en"
  xmlns:sd="urn:speedata:2009/publisher/functions/en">

  <Stylesheet filename="style.css"/>

  <Record element="data">
    <PlaceObject>
      <Textblock>
        <Paragraph>
          <Value>Test</Value>
        </Paragraph>
      </Textblock>
    </PlaceObject>
  </Record>

</Layout>

with the following CSS file:

p {
	color: red;
}

results in the word "Test" in the PDF in the color red.

If the CSS statements are inserted directly, the syntax is as follows:

  <Stylesheet>
    p {
      color: red;
    }
  </Stylesheet>

Selectors

As known from HTML, the CSS instructions are assigned to certain elements with so-called selectors.

<Table>
  <Tr minheight="4">
    <Td class="myclass" id="myid">
      <Paragraph>
        <Value>Hallo Welt</Value>
      </Paragraph>
    </Td>
  </Tr>
</Table>

The table cell in the example above could be accessed via the following selectors:

#myid {
  vertical-align: top ;
}
.myclass {
  vertical-align: top ;
}

and

td {
  vertical-align: top ;
}

The first case is via the 'id' attribute, which must be unique in the layout rules. The second case is addressed via the class class="…​". The class can be the same for several elements in the layout set of rules. The third case refers to all elements 'Td' in the layout set of rules. Here the usual specificity rules for CSS apply, but `!important' is not supported.

CSS and and elements in data

Text markup in the data works as follows:

<p>Text, Text, Text <b>bold</b>, Text Text</p>

The Publisher will ensure that the text within the 'b' element appears in bold.

You can also add CSS styles to your own elements. For example, if you have the following data

<data>hello <green>green</green> world</data>

you can use CSS to color the element:

<Layout
  xmlns="urn:speedata.de:2009/publisher/en"
  xmlns:sd="urn:speedata:2009/publisher/functions/en">

  <Stylesheet>
    green {
      color: green;
    }
  </Stylesheet>

  <Record element="data">
    <PlaceObject>
      <Textblock>
        <Paragraph>
          <Value select="."/>
        </Paragraph>
      </Textblock>
    </PlaceObject>
  </Record>
</Layout>
32 hellogreenworld
Elements in data can now be colored

Currently, only the attributes underline and color (text-decoration: underline; and color: …​) can be set via CSS.