CartoType: Graphics for Maps

Graham Asher, 25th January 2003

Note

This document describes CartoType, a portable cartographic engine for rendering high-quality scalable maps on devices ranging from mobile phone upwards. CartoType is available (as of June 2004) for the following operating systems: Microsoft Windows, Symbian OS 7.0, and Palm OS 5. For updated information please refer to the CartoType home page.

Introduction

High quality of paper maps

Paper maps are often very beautiful. Typography, line graphics, color, shading and symbols are used harmoniously. Subtleties like fine gradations of line width, and repositioning of linear features that would otherwise coincide, are used to make maps clearer.

Low quality of computer maps

Maps displayed on computers are typically rather ugly. Colors are badly chosen; roads are often displayed as thick lines in a single color, rather than bordered lines; names are sometimes all drawn horizontally rather than adapted to the shape of a region or curved along a road; there is usually no use of shading or transparency. A map on a computer usually looks as if it has been drawn rather naively using the simple graphics primitives available.

Disadvantages of scanned bitmaps

On computers, only maps that have been scanned from paper originals give the same quality. Even their quality is limited by the lower resolution of computer displays, typically about 100 dots per inch, as compared to the resolution of high-quality typesetting, typically at least 1200 dots per inch.  However, scanned maps suffer from two main drawbacks. Firstly, scaling gives no increase in the information displayed; all the information in the map is given by the pixel values; and arbitrary scaling of bitmap images can in any case produce unpleasant results, especially when zooming in. Secondly, the map contains no explicit structural information, like boundaries, names, and attributes such as whether a certain element is a water feature or a right of way.

A new map engine

This paper outlines CartoType, a new map engine that overcomes the disadvantages of ordinary computer maps drawn using graphics primitives. The name indicates that CartoType combines cartography and typography to make high-quality maps. CartoType controls the entire process of cartographic rendering all the way to the final pixels. It uses techniques drawn from recent advances in bitmap graphics and digital typography to produce the best possible results at a given resolution.

Architecture

CartoType is made up from these main parts, starting at the lowest level and (roughly) going upwards.

Two-dimensional graphics

This subsystem draws lines, curves, filled shapes and text on a bitmapped drawing surface. It uses 32-bit coordinates, 24-bit colors and integer arithmetic. It performs alpha blending and graduated shading. Text can be scaled and transformed arbitrarily. The rendering model and graphics functions support all the capabilities of SVG (Scalable Vector Graphics) 1.1. CartoType contains a partial SVG interpreter that can handle a large enough subset of SVG to render icons and other graphics; these icons are thus scalable.

The color model in detail: 24-bit RGB is used for output. That is, the final product of a request to draw a map is a 24-bpp RGB bitmap, which is then converted to the graphics format required by the platform. Because the 24bpp format is preserved up to the last moment no information is lost during intermediate graphics operations. The SVG subsystem uses 32bpp RGBA internally where necessary. The 'A' indicates that 'alpha' (transparency) information is stored in addition to the three color components.

Graphics utilities

Affine transformations and curve fitting. Lines and filled shapes are represented as paths made from straight lines and Bézier splines; this system is also used by PostScript, METAFONT, SVG, TrueType and several Adobe typeface formats, and is by common consent the best method.

Cartographic utilities

Text label positioning. Street names and other names are repositioned so that they do not overlap. Names may overlap if desired; sometimes the name of a large area might conveniently be drawn as a faint transparent overlay.

Style sheets

Style sheets encapsulate particular cartographic styles. They include color schemes, transparency, symbols, typography, representation of relief, line widths, level of detail and layers present.

Projections

This subsystem implements map projections by converting between points expressed in latitude and longitude and pixel coordinates as necessary. It can also convert between these measurements and units of distance such as meters to make it possible to draw graticules and measure distances on the map.

Data import and export

This translates data between internal and external formats, allowing CartoType to inter-operate with existing cartographic software.

Interactive cartography support

Maps on computers are more useful if they are interactive. This subsystem can convert between x-y coordinates on the displayed map and elements in the map database, so that elements can be selected in response to pointer events, and information about selected elements can be retrieved.

Objects

CartoType is an object-oriented system. A single engine object manages all global resources. These include the typeface and glyph cache, and working memory used while digitizing outlines. Various plug-in objects, also owned by the engine, support access to external resources. The most important of these are the map database accessors and the font renderers.

The map database accessors obtain map data from files and databases and supply it to CartoType through a standard interface. CartoType queries the interface to find out what data is available, its geometry, bounds, and so on, then requests whatever data is needed to draw the map.

The font renderers obtain font data from typeface files (for instance TrueType) and supply it to CartoType through another standard interface. The most important font renderer is based on the open-source FreeType system.

Map objects manage the drawing of individual map instances using data from the data accessors and projection objects that convert latitude and longitude to pixel coordinates.

Implementation

CartoType is written in a subset of standard C++. It can be compiled and run unchanged on Microsoft Windows, Linux, PalmOS, Symbian OS and other operating systems. In particular, it makes no use of exception handling or assumptions about endian-ness or word size, other than the requirements that are already part of the C++ standard. The CartoType library is re-entrant and makes no use of writable global data. It makes relatively low demands on heap memory and is scalable to adapt to conditions of low memory.

API

The API (application programming interface) gives access to CartoType at all the architectural levels listed above.

At high levels, cartographic data can be imported from GIS (geographic information system) databases and drawn directly as a map, which can then be interrogated using the interactive cartography support.

The simplest way of using CartoType is to supply data using a data accessor and request the drawing of a map using a particular style sheet. A single function call can create the complete map at any desired scale.

At middle levels, map elements can be highlighted, data layers can be selectively enabled, the map projection can be changed, parts of the map can be drawn at different scales.

At low levels, graphics and text can be drawn directly to the display surface. The CartoType graphics system is a powerful general-purpose digital drawing engine that can be used for any purpose. For example, it can be used to draw the legend and scale information, using the same rich color model and typographic capabilities as the rest of the map.