Drawfile is a Python module that contains classes for reading and writing Drawfiles with example scripts.
The Drawfile format is a file format for storing vector graphics created using the Draw application on RISC OS systems. As the standard file format for vector graphics on the RISC OS platform it has enjoyed support from both users and from developers, although only with the creation of the Drawfile module has the format become accessible to applications made by smaller development organisations. The simplicity of the Draw application and its competitors, such as Drawplus and Vector, has inspired a large amount of freely available clip art despite the restrictions the format places on the complexity of drawings which can be created.
Available libraries and tools
The drawfile module
This Python module was written to ensure that many of the diagrams and illustrations I required for my thesis would be portable to platforms other than RISC OS in the case that I should encounter problems with my workstation. The module contains classes which encapsulate the standard objects present in Drawfiles and allow them to be individually read, modified and written back to Drawfiles, providing varying degrees of abstraction over the underlying data. For example, the path object will contain information on the line and fill styles of a path, and maintains a list of the path operations, but does not provide a convenient interface for adding or removing points to or from a path. This approach works quite well for the text_area object which will construct a list of text formatting commands and arguments to assist applications in recreating visual representations of text areas.
Since Drawfiles may contain images in the form of sprites, embedded as single image Spritefiles within sprite objects, the drawfile module will attempt to import the spritefile module on initialisation, although this is not really necessary if the lazy flag is passed to drawfile objects on initialisation. This flag is used by sprite objects to determine whether the embedded Spritefiles they contain should be decoded when read, and encoded when written.
The module supports the following Drawfile objects:
· Font tables, although successful mapping between RISC OS font name and native fonts depends on the configuration of the user's system.
· Text objects, including transformed text.
· Paths, although the non-zero winding rule is as yet unsupported.
· Sprites including transformed sprites.
· Groups of objects.
· Text areas and columns of text. These features have been fairly extensively tested but may well require further attention.
· Options, although many of these are discarded since they are concerned with Draw's user interface.
· JPEG files. It is not clear whether the set of JPEG files supported by Sketch is a superset of those supported by Draw.
What's New in This Release:
· Used the struct module to handle bytes and 32 bit words from Drawfiles.
· Changed the license to the GNU General Public License.