Structure of a CartoType style sheet

Summary:

<?xml version="1.0" encoding="UTF-8"?>
<CartoTypeStyleSheet background='lightblue' border='lightgrey' labelFormat=';int_name;name:en;ref+{font-style:italic}"&#10;("name:en")"' landLayer='outline' name='standard style'>
   <defs> ... </defs>
   <layer name="park"> ... </layer>
   <layer name="river"> ... </layer>
   <layer name="road"> ... </layer>
   <layer name="other-layer"> ... </layer>
   ...
   <labelLayer/>
</CartoTypeStyleSheet>

XML Declaration and <CartoTypeStyleSheet> section

The style sheet starts with the xml declaration and the opening tag of the <CartoTypeStyleSheet> section:

<?xml version="1.0" encoding="UTF-8"?>
<CartoTypeStyleSheet background='lightblue' border='lightgrey' labelFormat=';int_name;name:en;ref+{font-style:italic}"&#10;("name:en")"' landLayer='outline' name='standard style'>

The background attribute tells CartoType what color to draw over the whole map before anything else is drawn. If it is omitted, the background of the map is drawn in white.

The border attribute sets the color of the area outside the map entirely.

The labelFormat attribute provides a standard format for labels. This one uses either the name, international name, English name or reference, in that order of preference; then displays the English name on a new line, parenthesized and in italics, if there is one and if it has not already been used.

The landLayer attribute tells CartoType the name of the layer used for land as opposed to sea.

Global definitions

There may be an optional <defs> section like this, defining objects used throughout the style sheet:

<defs>
   <hachure id="other-area-shading" width="1pt" interval="4pt" color="brown" opacity="0.4"/> 
   <icon id='station-icon' width='45m,5pt,200pt'>
      <svg width='220' height='220'>
      <circle fill='red' stroke='black' stroke-width='20' cx='110' cy='110' r='95'/> 
      </svg>
   </icon>
   <!-- A general-purpose arrow that will not stick outside its stroke if drawn using units of 1/1024 of the stroke width. -->
   <def id='arrow' string='M -450 -50 V 50 H 250 L -100 400 H 50 L 450 0 L 50 -400 H -100 L 250 -50 H -450 Z'/>
   <macro id='standard-tunnel'>
      <tunnel dashArray='1,1' fade='0.3' mouth='dimgrey' mouthWidth='20%,1' mouthPath='m 0 512 a 512 512 0 1 1 0 -1024'/>
   </macro>
</defs>

This example defines a hachure, an SVG icon, the path of an arrow for one-way roads, and a macro for tunnel styles.

Layers

then one or more <layer> sections like this, defining map layers to be drawn:

<layer name="park">
   <shape fill="lightgreen"/>
   <label font-size="300m,8pt,24pt" color="green" case="title" position="centralpath"/>
</layer>

A layer can have a roadflags attribute, which overrides the default value or any value set in <CartoTypeStyleSheet>. See the section on <CartoTypeStyleSheet> above for details of this attribute.>

Label layer

The <labelLayer> section tells CartoType to draw any icons and labels:

<labelLayer/>

You can have more than one <labelLayer/> tag, and they can actually occur anywhere in the style sheet, not just at the end. Every time a <labelLayer/>is encountered, any labels for objects in the layers between it and any preceding <labelLayer/> tag are drawn. Labels are sorted according to their priorities if any, then by layer order, and within that in reverse order of <condition> sections (so that labels for objects drawn later and so taken to be more important, are drawn earlier and are thus more likely to appear).

Closing tag

The style sheet ends with the closing tag:

</CartoTypeStyleSheet>

Drawing order

When CartoType draws a map it draws objects in order of their z-level (optional vertical level), and within that, in order of the layers, as they appear in the style sheet.

This can make a big difference to the appearance of the map. For example, parks often contain lakes. If the parks in your data have holes in to exclude the lakes in them (which is unlikely), there is no problem, but usually park polygons have no such holes; the lakes are part of the park. Therefore you would usually draw parks before lakes and other bodies of water.

In detail, objects are sorted like this before drawing:

1. By phase. A phase is a group of layers to be drawn together, and is ended either by a <stratum/> or <labelLayer/> directive in the style sheet. There is also an implicit phase boundary before the first road layer, so that roads and railways can be drawn over parks and rivers even if they are in tunnels. Another phase rule is that 3D buildings are drawn after everything else. There may be up to 256 phases.

2. By level, which means that tunnels are drawn before surface features, then first-level bridges, then bridges over bridges, etc. There are 15 levels, from -8 to +7.

3. By layer: layers earlier in the style sheet are drawn before later ones. There may be up to 1024 layers in a style sheet.

4. By <condition> within layer. A layer may have a number of styles defined by <condition> sections. They are drawn in the order they appear in the style sheet. There may be up to 1024 conditions in a layer.

Style Sheets Directory