The Leonardo XML File Format Version 1.0

Copyright © 2005 wirejunkie
Last revised: 2005-05-31
Author: Tim Serong <moc.eiknujeriw@mit> (use your imagination)

Table of Contents


The World According to Leonardo

Co-ordinates

Leonardo's world is a two-dimensional plane. X co-ordinates are positive moving right and Y co-ordinates are positive moving down. Valid co-ordinates in both dimensions are integers in the range -32768 to 32767 inclusive. The center or origin of the image is at (0, 0). One Leonardo co-ordinate corresponds to one pixel on the screen if your image is zoomed to 100% (i.e.: zoom level 0).

Angles

As far as Leonardo is concerned, there are 256 "degrees" in a circle, as opposed to the more widely used 360 degrees. However, when using Leonardo itself, degrees are represented in their normal range (0 - 359) in the user interface, so users will understand what is going on. 0 - 255 is Leonardo's internal representation which has the advantage of only occupying one byte of memory. This provides lower memory consumption than would be possible with 360 degrees (which would require two bytes) and allows Leonardo to perform calculations on angles more efficiently than it would otherwise. Looking at a circle front-on, Leonardo angles start at 0 at the topmost point of the circle then move clockwise as shown in the diagram below.

If you need to convert a Leonardo angle to degrees, multiply by 1.40625. Here's a handy conversion table for common angles:

DegreesLeoAngle
0
45° 32
90° 64
135° 96
180° 128
225° 160
270° 192
315° 224

Colors

All colors are represented by a hexadecimal index in the range 0x00 to 0xe9 depending on the palette type of the image, which can be 1, 2, 4 or 8 bits per pixel. Following is a mapping of Leonardo color indices to HTML RGB values:

1 BPP Palette

0x00#ffffff0x01#000000

2 BPP Palette

0x00#ffffff0x01#888888 0x02#4444440x03#000000

4 BPP Palette

0x00#ffffff0x01#eeeeee 0x02#dddddd0x03#cccccc 0x04#bbbbbb0x05#aaaaaa 0x06#9999990x07#888888
0x08#7777770x09#666666 0x0a#5555550x0b#444444 0x0c#3333330x0d#222222 0x0e#1111110x0f#000000

8 BPP Palette

Note that the entire possible set of 256 palette entries is not visible in Leonardo - the palette display in Leonardo only goes up to 0xe9. The remaining 21 palette entries all map to black, but this may not necessarily be true in future.

0x00#ffffff0x01#ffccff0x02#ff99ff0x03#ff66ff0x04#ff33ff0x05#ff00ff
0x06#ffffcc0x07#ffcccc0x08#ff99cc0x09#ff66cc0x0a#ff33cc0x0b#ff00cc
0x0c#ffff990x0d#ffcc990x0e#ff99990x0f#ff66990x10#ff33990x11#ff0099
0x12#ccffff0x13#ccccff0x14#cc99ff0x15#cc66ff0x16#cc33ff0x17#cc00ff
0x18#ccffcc0x19#cccccc0x1a#cc99cc0x1b#cc66cc0x1c#cc33cc0x1d#cc00cc
0x1e#ccff990x1f#cccc990x20#cc99990x21#cc66990x22#cc33990x23#cc0099
0x24#99ffff0x25#99ccff0x26#9999ff0x27#9966ff0x28#9933ff0x29#9900ff
0x2a#99ffcc0x2b#99cccc0x2c#9999cc0x2d#9966cc0x2e#9933cc0x2f#9900cc
0x30#99ff990x31#99cc990x32#9999990x33#9966990x34#9933990x35#990099
0x36#66ffff0x37#66ccff0x38#6699ff0x39#6666ff0x3a#6633ff0x3b#6600ff
0x3c#66ffcc0x3d#66cccc0x3e#6699cc0x3f#6666cc0x40#6633cc0x41#6600cc
0x42#66ff990x43#66cc990x44#6699990x45#6666990x46#6633990x47#660099
0x48#33ffff0x49#33ccff0x4a#3399ff0x4b#3366ff0x4c#3333ff0x4d#3300ff
0x4e#33ffcc0x4f#33cccc0x50#3399cc0x51#3366cc0x52#3333cc0x53#3300cc
0x54#33ff990x55#33cc990x56#3399990x57#3366990x58#3333990x59#330099
0x5a#00ffff0x5b#00ccff0x5c#0099ff0x5d#0066ff0x5e#0033ff0x5f#0000ff
0x60#00ffcc0x61#00cccc0x62#0099cc0x63#0066cc0x64#0033cc0x65#0000cc
0x66#00ff990x67#00cc990x68#0099990x69#0066990x6a#0033990x6b#000099
0x6c#ffff660x6d#ffcc660x6e#ff99660x6f#ff66660x70#ff33660x71#ff0066
0x72#ffff330x73#ffcc330x74#ff99330x75#ff66330x76#ff33330x77#ff0033
0x78#ffff000x79#ffcc000x7a#ff99000x7b#ff66000x7c#ff33000x7d#ff0000
0x7e#ccff660x7f#cccc660x80#cc99660x81#cc66660x82#cc33660x83#cc0066
0x84#ccff330x85#cccc330x86#cc99330x87#cc66330x88#cc33330x89#cc0033
0x8a#ccff000x8b#cccc000x8c#cc99000x8d#cc66000x8e#cc33000x8f#cc0000
0x90#99ff660x91#99cc660x92#9999660x93#9966660x94#9933660x95#990066
0x96#99ff330x97#99cc330x98#9999330x99#9966330x9a#9933330x9b#990033
0x9c#99ff000x9d#99cc000x9e#9999000x9f#9966000xa0#9933000xa1#990000
0xa2#66ff660xa3#66cc660xa4#6699660xa5#6666660xa6#6633660xa7#660066
0xa8#66ff330xa9#66cc330xaa#6699330xab#6666330xac#6633330xad#660033
0xae#66ff000xaf#66cc000xb0#6699000xb1#6666000xb2#6633000xb3#660000
0xb4#33ff660xb5#33cc660xb6#3399660xb7#3366660xb8#3333660xb9#330066
0xba#33ff330xbb#33cc330xbc#3399330xbd#3366330xbe#3333330xbf#330033
0xc0#33ff000xc1#33cc000xc2#3399000xc3#3366000xc4#3333000xc5#330000
0xc6#00ff660xc7#00cc660xc8#0099660xc9#0066660xca#0033660xcb#000066
0xcc#00ff330xcd#00cc330xce#0099330xcf#0066330xd0#0033330xd1#000033
0xd2#00ff000xd3#00cc000xd4#0099000xd5#0066000xd6#0033000xd7#111111
0xd8#2222220xd9#4444440xda#5555550xdb#7777770xdc#8888880xdd#aaaaaa
0xde#bbbbbb0xdf#dddddd0xe0#eeeeee0xe1#c0c0c00xe2#8000000xe3#800080
0xe4#0080000xe5#0080800xe6#0000000xe7#0000000xe8#0000000xe9#000000

Objects

There are seven different types of object (or shape) that Leonardo is aware of: arc, ellipse, bezier, rectangle, polyline, polygon and text. Following is a mapping of Leonardo drawing tools to actual Leonardo objects, to provide a point of reference. Some object flags are mentioned - the specifics of these are covered elsewhere in this document.

Drawing ToolActual Object Created
Bezier Tool bezier
Arc Tool arc
Straight Line Tool polyline (2 points, freehand = false)
Polyline Tool polyline (n points, freehand = false)
Freehand Tool polyline (n points, freehand = true)
Marker Tools Manipulate bezier/arc/polyline properties
Polygon Tool polygon (n points)
Isosceles Triangle Tool polygon (3 points)
Right Angle Triangle Tool polygon (3 points)
Square Tool rectangle
Rectangle Tool rectangle
Circle Tool ellipse
Ellipse Tool ellipse
Small Text Tool text (8 point)
Medium Text Tool text (8 point, bold)
Large Text Tool text (10 point, bold)

Leonardo's File Formats

If you have installed the conduit that comes with Leonardo's Workshop, when you hotsync your PDA, your Leonardo images will be converted to Leonardo image files in the c:\Palm\USERNAME\Leonardo folder. Likewise, any Leonardo image files in this folder will be synched back to your PDA. The images are in an XML format, described below. Because they are XML files, they can be edited by hand using a text editor. Programs can also be written relatively easily to manipulate and convert Leonardo images in this XML format.

For reasons of speed and size, Leonardo itself works directly with Palm databases, in a binary format. This binary format is not described in this document, although it is conceptually similar to the XML format. Note that this means the backup PDB files in your c:\Palm\USERNAME\Backup folder are not in the Leonardo XML format.

As you go through this document, it may be helpful to have a Leonardo image open in a text editor.

XML Document Structure

Because this is an XML file, the first line of the file must be the usual <?xml version="1.0"?> processing instruction. Following this, the root element is leonardoImage. Inside the leonardoImage element are the dbName, origin and objects elements. Finally, inside the objects element are the actual objects that make up the image, one after another.

The leonardoImage element has the following attributes:

NameDescriptionValid values
bgColorColor index of image background color.0x00 - 0xe9
lastModifiedTimestamp for when the image was last modified, expressed as the number of seconds since the first instant of January 1, 1904.0xnnnnnnnn
paletteTypeBits per pixel in palette.1, 2, 4 or 8
versionImage file format version1.0
zoomFactorCurrent zoom level for display in Leonardo (0 = 100% or 1:1 zoom)-101 to 9

The dbName element contains the name of the corresponding Leonardo image database on the PDA. Image database names are in the form "wLeoname", where name is the image name as displayed to the user. The name portion can be a maximum of 27 characters.

The origin element is an empty element (i.e.: it has no children) which specifies the current position of the center of the Leonardo viewport relative to the center of the image itself (the specifics of the attributes are defined below).

As mentioned previously, the objects element contains all the objects that make up the image, one after another. For display purposes, the first object listed in the file is the rear-most and the last object in the file is the front-most.

Here's an example snippet:

<?xml version="1.0"?>
<leonardoImage bgColor="0x04" lastModified="0xba23857f" paletteType="4"
  version="1.0" zoomFactor="-62">

 <dbName><![CDATA[wLeountitled]]></dbName>

 <origin x="0" y="0"/>

 <objects>

  <polyline freehand="false">

   <-- polyline data here -->

  </polyline>

  <-- more objects here -->

 </objects>

</leonardoImage>

Vertex, Size and Bounds Elements

In various places in Leonardo image files, there is a need to specify the co-ordinates of a vertex, or a size. The elements used for this have different names depending on their context, but they all share the same basic form; they are empty elements with an X and a Y attribute. These elements are:

The origin Element

The origin element specifies the center (origin) of an object. It has the following attributes:

NameDescriptionValid values
xX co-ordinate-32768 - 32767
yY co-ordinate-32768 - 32767

The v Element

The v element specifies the position of an individual vertex in a polyline, polygon or bezier. It has the following attributes:

NameDescriptionValid values
xX co-ordinate-32768 - 32767
yY co-ordinate-32768 - 32767

The points Element

The entire list of vertices that make up a polyline, polygon or bezier are defined in the points element as a list of v elements, for example:

   <points>
    <v x="-6" y="-13"/>
    <v x="-8" y="-12"/>
    <v x="-9" y="-9"/>
   </points>

The maximum number of points in any object is 500.

The topLeft Element

The topLeft element specifies the top left co-ordinate of a rectangular area. It has the following attributes:

NameDescriptionValid values
xX co-ordinate-32768 - 32767
yY co-ordinate-32768 - 32767

The bottomRight Element

The bottomRight element specifies the bottom right co-ordinate of a rectangular area. It has the following attributes:

NameDescriptionValid values
xX co-ordinate-32768 - 32767
yY co-ordinate-32768 - 32767

The extent Element

The extent element specifies the width and height of a rectangular area. It has the following attributes:

NameDescriptionValid values
xWidth-32768 - 32767
yHeight-32768 - 32767

The radius Element

The radius element is effectively the same as extent but is used when defining the X and Y radius of an ellipse. It's attributes are:

NameDescriptionValid values
xX Radius-32768 - 32767
yY Radius-32768 - 32767

The bounds Element

The bounds element defines a rectangular bounding box. It has no attributes, but instead includes a topLeft and an extent element. For example:

    <bounds>
     <topLeft x="-9" y="-13"/>
     <extent x="55" y="25"/>
    </bounds>

This defines an area 55 pixels by 25 pixels, whose top left corner is at (-9, -13).

Markers

Arcs, beziers and polylines can have markers attached to their ends. Each of these objects includes a marker element to specify the markers used. It is an empty element with the following attributes:

NameDescriptionValid values
startMarker at start of line"none", "circle", "square" or "triangle"
endMarker at end of line"none", "circle", "square" or "triangle"

Object Style

Each object in a Leonardo image includes a style element which defines the stroke, fill and position of the object. It has the following attributes:

NameDescriptionValid values
visibleObject is visible [N/I]"true" or "false"

It includes as children origin, bounds, stroke and fill elements. Here's an example:

   <style visible="true">
    <origin x="-55" y="-41"/>
    <bounds>
     <topLeft x="-64" y="-54"/>
     <extent x="19" y="26"/>
    </bounds>
    <stroke color="0xe9" type="solid" width="1"/>
    <fill color="0x00"/>
   </style>

The stroke Element

The stroke element defines the stroke width, color and style for an object. It is an empty element with the following attributes:

NameDescriptionValid values
typeStroke style"solid", "dot" or "dash"
widthStroke width0 - 99
colorStroke color0x00 - 0xe9

If the stroke width is zero, the line is considered to be infinitely thin - it will always be rendered one pixel wide regardless of how far you zoom in. The idea is that these magic thin lines can be used for guides when drawing, for example.

The fill Element

The fill element defines the fill style of an object. Fills can be either solid, a texture or a gradient. The exact structure of the fill element varies depending on this type. For a solid fill, the fill element is empty, and has one attribute - color - specifying the color to use. Here's an example:

    <fill color="0x00"/>

For a texture fill, the fill element has no attributes, but includes a texture element as its only child.

For a gradient fill, the fill element has no attributes, but includes a gradient element as its only child.

The texture and pattern Elements

The texture element includes a pattern element which defines a bitmask for the texture as a long hexadecimal number. The texture element has the following attributes:

NameDescriptionValid values
fgColorForeground color of bitmask0x00 - 0xe9
bgColorBackground color of bitmask0x00 - 0xe9

Here's an example texture fill:

    <fill>
     <texture bgColor="0x00" fgColor="0xe9">
      <pattern><![CDATA[0x004020100a060e00]]></pattern>
     </texture>
    </fill>

The hex number inside the pattern element defines an eight-byte bitmask (an 8x8 grid). In this case, the pattern is:

00                 
40                 
20                 
10                 
0a                 
06                 
0e                 
00                 
The gradient Element

The gradient element is an empty element with the following attributes:

NameDescriptionValid values
typeGradient type"linear" or "radial"
angleAngle for linear gradient0 - 255
color1Gradient from this color...0x00 - 0xe9
color2...to this color0x00 - 0xe9

Here's an example gradient fill:

    <fill>
     <gradient color2="0x00" type="linear" angle="32" color1="0xe9"/>
    </fill>

An Important Note on Object Co-ordinates

For example (using a rectangle):

  <rectangle angle="0">
   <style visible="true">
    <origin x="18" y="-1"/>
    <bounds>
     <topLeft x="-9" y="-13"/>
     <extent x="55" y="25"/>
    </bounds>
    <stroke color="0x4f" type="solid" width="1"/>
    <fill color="0x00"/>
   </style>
   <topLeft x="-27" y="-12"/>
   <bottomRight x="27" y="12"/>
  </rectangle>

It is very important that when manipulating object co-ordinates (relative to the object's origin) that the object bounds (relative to the center of the image) are kept up to date. The bounds must be the smallest image-relative rectangle that contains all the vertices that make up the object. If the bounds are set incorrectly, the image will not view correctly in Leonardo. The bounds element will ultimately be removed in a later version of Leonardo's Workshop, as it is technically redundant data, and because it can cause this problem if manipulated incorrectly. However, for now, it must be maintained. To sum up:

  1. Always make sure the bounds are set correctly when creating version 1.0 Leonardo image files.
  2. Do not assume that the bounds element will exist when reading Leonardo image files.

The Objects Themselves

The arc Element

The arc element defines an elliptical arc. It contains three children: style, radius for the X and Y radius of the arc and marker for the markes to use at the ends of the arc. It has the following attributes:

NameDescriptionValid values
angleRotation angle [N/I]0 - 255
startAngle at which the arc starts0 - 255
endAngle at which the arc ends0 - 255

Here's an example:

  <arc angle="0" end="192" start="64">
   <style visible="true">
    <origin x="-21" y="-41"/>
    <bounds>
     <topLeft x="-29" y="-41"/>
     <extent x="17" y="18"/>
    </bounds>
    <stroke color="0xe9" type="solid" width="1"/>
    <fill color="0x00"/>
   </style>
   <radius x="8" y="17"/>
   <marker end="none" start="none"/>
  </arc>

The ellipse Element

The ellipse element has two children: style and radius for the X and Y radius of the ellipse. It has the following attributes:

NameDescriptionValid values
angleRotation angle [N/I]0 - 255

Here's an example:

  <ellipse angle="0">
   <style visible="true">
    <origin x="46" y="18"/>
    <bounds>
     <topLeft x="25" y="4"/>
     <extent x="43" y="29"/>
    </bounds>
    <stroke color="0xe9" type="solid" width="1"/>
    <fill color="0x7d"/>
   </style>
   <radius x="21" y="14"/>
  </ellipse>

The bezier Element

The bezier element defines a cubic Bézier curve. It has no attributes, but has three children: style, marker and points. There must be exactly four points defined for the bezier - Leonardo won't draw beziers with more or less points than this. Here's an example:

  <bezier>
   <style visible="true">
    <origin x="-43" y="46"/>
    <bounds>
     <topLeft x="-56" y="27"/>
     <extent x="26" y="38"/>
    </bounds>
    <stroke color="0xe9" type="solid" width="1"/>
    <fill color="0x00"/>
   </style>
   <marker end="none" start="none"/>
   <points>
    <v x="-13" y="-7"/>
    <v x="-1" y="-19"/>
    <v x="0" y="18"/>
    <v x="12" y="6"/>
   </points>
  </bezier>

The rectangle Element

The ellipse element has three children: style, topLeft and bottomRight. The latter two children define the corners of the rectangle. It has the following attributes:

NameDescriptionValid values
angleRotation angle [N/I]0 - 255

Here's an example:

  <rectangle angle="0">
   <style visible="true">
    <origin x="18" y="-1"/>
    <bounds>
     <topLeft x="-9" y="-13"/>
     <extent x="55" y="25"/>
    </bounds>
    <stroke color="0x4f" type="solid" width="1"/>
    <fill color="0x00"/>
   </style>
   <topLeft x="-27" y="-12"/>
   <bottomRight x="27" y="12"/>
  </rectangle>

The polyline Element

The polyline element has three children: style, marker and points. It can have between 2 and 500 points. It has the following attributes:

NameDescriptionValid values
freehandIf freehand, points cannot be manipulated in Leonardo."true" or "false"

Here's an example:

<polyline freehand="true"> <style visible="true"> <origin x="-55" y="-41"/> <bounds> <topLeft x="-64" y="-54"/> <extent x="19" y="26"/> </bounds> <stroke color="0xe9" type="solid" width="1"/> <fill color="0x00"/> </style> <marker end="circle" start="square"/> <points> <v x="-6" y="-13"/> <v x="-8" y="-12"/> <v x="-9" y="-9"/> <v x="-7" y="-5"/> <v x="-1" y="-4"/> <v x="4" y="-4"/> <v x="7" y="-4"/> <v x="9" y="-1"/> <v x="9" y="2"/> <v x="6" y="5"/> <v x="2" y="5"/> <v x="-1" y="5"/> <v x="-2" y="5"/> <v x="-3" y="6"/> <v x="-4" y="8"/> <v x="-4" y="9"/> <v x="-3" y="10"/> <v x="0" y="11"/> <v x="3" y="12"/> <v x="4" y="12"/> </points> </polyline>

The polygon Element

The polygon element has two children: style and points. It can have between 3 and 500 points. It has no attributes. Here's an example:

  <polygon>
   <style visible="true">
    <origin x="-3" y="24"/>
    <bounds>
     <topLeft x="-25" y="9"/>
     <extent x="45" y="30"/>
    </bounds>
    <stroke color="0xe9" type="solid" width="1"/>
    <fill color="0x7d"/>
   </style>
   <points>
    <v x="0" y="-15"/>
    <v x="-22" y="14"/>
    <v x="22" y="14"/>
   </points>
  </polygon>

The text Element

The text element has five children: style, topLeft, bottomRight, flags and string. It has the following attributes:

NameDescriptionValid values
angleRotation angle [N/I]0 - 255
sizePoint size of text8 or 10
fontFont index [N/I]0xnnnnnnnn

Note that the point size can in theory be from 1 - 255, but Leonardo will only render 8 or 10 point text as of this writing.

The topLeft and bottomRight elements specify the corners of the rectangle containing the text. The flags element specifies various font effects and has the following attributes:

NameDescriptionValid values
hiddenText is minimized"true" or "false"
boldFont is bold"true" or "false"
italicFont is italic [N/I]"true" or "false"
underlinedFont is underlined [N/I]"true" or "false"

The string element contains the text itself. Here's an example:

  <text angle="0" font="0x00" size="8">
   <style visible="true">
    <origin x="3" y="-4"/>
    <bounds>
     <topLeft x="-43" y="-49"/>
     <extent x="94" y="112"/>
    </bounds>
    <stroke color="0xe9" type="solid" width="1"/>
    <fill color="0x7d"/>
   </style>
   <topLeft x="-46" y="-45"/>
   <bottomRight x="47" y="66"/>
   <flags bold="true" hidden="false" italic="false" underlined="false"/>
   <string><![CDATA[This is a block of text consisting of a few paragraphs.

Here's the second paragraph.

Foo
Bar
Baz]]></string>
  </text>

The Future

The Leonardo XML format serves well to represent anything you can possibly create in Leonardo, and is reasonably human-readable. However there are some issues that will be addressed in a future version of the file format. These are:

Footnotes