Mapper  0.9.0
API documentation
Classes | Macros | Typedefs | Enumerations | Functions
libocad.h File Reference

(9169056 on 6 Feb 2019)

#include <stdio.h>
#include "types.h"
#include "array.h"
#include "geometry.h"
Include dependency graph for libocad.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  _OCADString
 
struct  _OCADObjectIndex
 
struct  _OCADFile
 
struct  _OCADBackground
 
struct  _OCADExportOptions
 
struct  _OCADPaintSymbolIndex
 
struct  _OCADPaintColorIndex
 
struct  _OCADPaintData
 
struct  _OCADPaintCallback
 

Macros

#define O_BINARY   0
 
#define PX_CTL1   0x1
 
#define PX_CTL2   0x2
 
#define PX_LEFT   0x4
 
#define PY_CORNER   0x1
 
#define PY_HOLE   0x2
 
#define PY_RIGHT   0x4
 
#define PY_DASH   0x8
 
#define OCAD_MAX_OBJECT_PTS   32768
 
#define OCAD_POINT_SYMBOL   1
 
#define OCAD_LINE_SYMBOL   2
 
#define OCAD_AREA_SYMBOL   3
 
#define OCAD_TEXT_SYMBOL   4
 
#define OCAD_RECT_SYMBOL   5
 
#define OCADSymbol_COMMON
 
#define OCAD_LINE_ELEMENT   1
 
#define OCAD_AREA_ELEMENT   2
 
#define OCAD_CIRCLE_ELEMENT   3
 
#define OCAD_DOT_ELEMENT   4
 
#define OCADExportOptions_COMMON
 
#define OCAD_OK   0
 
#define OCAD_OUT_OF_MEMORY   -1
 
#define OCAD_FILE_WAS_READONLY   -2
 
#define OCAD_MMAP_FAILED   -3
 
#define OCAD_INVALID_FORMAT   -4
 
#define OCAD_MMAP_NOT_SUPPORTED   -10
 

Typedefs

typedef char str
 
typedef struct _OCADString OCADString
 
typedef OCADObjectEntry struct _OCADObjectIndex OCADObjectIndex
 
typedef OCADSetup struct _OCADFile OCADFile
 
typedef struct _OCADBackground OCADBackground
 
typedef struct _OCADExportOptions OCADExportOptions
 
typedef struct _OCADPaintSymbolIndex OCADPaintSymbolIndex
 
typedef struct _OCADPaintColorIndex OCADPaintColorIndex
 
typedef struct _OCADPaintData OCADPaintData
 
typedef struct _OCADPaintCallback OCADPaintCallback
 
typedef bool(* OCADSymbolCallback) (void *, OCADFile *, OCADSymbol *)
 
typedef bool(* OCADSymbolElementCallback) (void *, OCADSymbolElement *)
 
typedef bool(* OCADObjectCallback) (void *, OCADFile *, OCADObject *)
 
typedef bool(* OCADObjectEntryCallback) (void *, OCADFile *, OCADObjectEntry *)
 
typedef bool(* OCADStringEntryCallback) (void *, OCADFile *, OCADStringEntry *)
 
typedef enum _SegmentType SegmentType
 
typedef bool(* IntPathCallback) (void *, SegmentType, s32 *)
 

Enumerations

enum  _SegmentType { MoveTo, SegmentLineTo, CurveTo, ClosePath }
 

Functions

char * my_strdup (const char *s)
 
int my_round (double x)
 
 PACK (typedef struct _OCADPoint { s32 x;s32 y;}, OCADPoint) PACK(typedef struct _OCADRect
 
OCADRect PACK (typedef struct _OCADFileHeader { word magic;word ftype;word major;word minor;dword osymidx;dword oobjidx;dword osetup;dword ssetup;dword infopos;dword infosize;dword ostringidx;dword res4;dword res5;dword res6;word ncolors;word nsep;u8 res8[20];}, OCADFileHeader) PACK(typedef struct _OCADColor
 
OCADColor PACK (typedef struct _OCADColorSeparation { str sep_name[16];byte cyan;byte magenta;byte yellow;byte black;word raster_freq;word raster_angle;}, OCADColorSeparation) PACK(typedef struct _OCADSymbolEntry
 
OCADSymbolEntry PACK (typedef struct _OCADSymbolIndex { dword next;OCADSymbolEntry entry[256];}, OCADSymbolIndex) PACK(typedef struct _OCADSymbolElement
 
OCADSymbolElement PACK (typedef struct _OCADSymbol { OCADSymbol_COMMON }, OCADSymbol) PACK(typedef struct _OCADPointSymbol
 
OCADPointSymbol PACK (typedef struct _OCADLineSymbol { OCADSymbol_COMMON u16 color;u16 width;word ends;s16 bdist;s16 edist;s16 len;s16 elen;s16 gap;s16 gap2;s16 egap;s16 smin;s16 snum;s16 sdist;word dmode;word dflags;s16 dcolor;s16 lcolor;s16 rcolor;s16 dwidth;s16 lwidth;s16 rwidth;s16 dlen;s16 dgap;s16 dres[3];word tmode;s16 tlast;s16 tres;s16 fcolor;s16 fwidth;s16 fstyle;s16 smnpts;s16 ssnpts;s16 scnpts;s16 sbnpts;s16 senpts;s16 res4;OCADPoint pts[1];}, OCADLineSymbol) PACK(typedef struct _OCADAreaSymbol
 
OCADAreaSymbol PACK (typedef struct _OCADTextSymbol { OCADSymbol_COMMON str font[32];s16 color;s16 dpts;s16 bold;byte italic;byte charset;s16 cspace;s16 wspace;s16 halign;s16 lspace;s16 pspace;s16 indent1;s16 indent2;s16 ntabs;s32 tab[32];wbool under;s16 ucolor;s16 uwidth;s16 udist;s16 res4;s16 fmode;str ffont[32];s16 fcolor;s16 fdpts;s16 fbold;wbool fitalic;s16 fdx;s16 fdy;}, OCADTextSymbol) PACK(typedef struct _OCADRectSymbol
 
OCADRectSymbol PACK (typedef struct _OCADObject { s16 symbol;byte type;byte unicode;u16 npts;u16 ntext;s16 angle;s16 res1;s32 res2;u8 res3[16];OCADPoint pts[1];}, OCADObject) PACK(typedef struct _OCADObjectEntry
 
 PACK (typedef struct _OCADCString { char str[1];}, OCADCString) PACK(typedef struct _OCADStringEntry
 
OCADStringEntry PACK (typedef struct _OCADStringIndex { dword next;OCADStringEntry entry[256];}, OCADStringIndex) PACK(typedef struct _OCADSetup
 
bool ocad_path_iterate (u32 npts, const OCADPoint *pts, IntPathCallback callback, void *param)
 Iterates over an set of OCAD points, providing a list of PostScript-like path segments. More...
 
int ocad_init ()
 Initializes the libocad library. More...
 
int ocad_shutdown ()
 Shuts down the libocad library. More...
 
const s32ocad_point (s32 *buf, const OCADPoint *pt)
 Converts an OCAD point into a triplet of signed integers. More...
 
const s32ocad_point2 (s32 **pbuf, const OCADPoint *pt)
 Converts an OCAD point into a triplet of signed integers like ocad_point(), but advances the buffer pointer by three elements. More...
 
const char * ocad_str (char *buf, const str *ostr)
 Converts an OCAD string (0-255 characters) to a zero-terminated string in the given buffer. More...
 
const char * ocad_str2 (char **buf, const str *ostr)
 Converts an OCAD string (0-255 characters) to a zero-terminated string in the given buffer, returns a pointer to the zero-terminated string, and advances the buffer point just beyond the zero byte. More...
 
bool ocad_path_bounds (s32 *prect, u32 npts, const OCADPoint *pts)
 Calculates the bounds of the given path and returns it in the provided rectangle. More...
 
bool ocad_path_bounds_rect (OCADRect *prect, u32 npts, const OCADPoint *pts)
 Calculates the bounds of the given path and returns it in the provided rectangle. More...
 
bool ocad_rect_grow (OCADRect *prect, s32 amount)
 Grows the given rectangle by the given amount, which may be negative. More...
 
bool ocad_rect_intersects (const OCADRect *r1, const OCADRect *r2)
 Returns true if the two rectangle intersect, FALSE otherwise. More...
 
int ocad_to_background (OCADBackground *bg, OCADCString *templ)
 Converts an OCAD string of the correct type into an OCADBackground structure. More...
 
int ocad_file_new (OCADFile **pfile)
 Creates a new OCADFile struct in memory. More...
 
int ocad_file_reserve (OCADFile *file, int amount)
 Makes sure that 'amount' number of bytes are reserved in the file's buffer in addition to the already used space. More...
 
int ocad_file_open (OCADFile **pfile, const char *filename)
 Opens a file with the given filename. More...
 
int ocad_file_open_mapped (OCADFile **pfile, const char *filename)
 Behaves exactly like ocad_file_open(), except that the system attempts to open the file via memory mapping. More...
 
int ocad_file_open_memory (OCADFile **pfile, u8 *buffer, u32 size)
 Behaves exactly like ocad_file_open(), except that the given buffer must contain the map data. More...
 
int ocad_file_close (OCADFile *pfile)
 Closes an open OCADFile. More...
 
int ocad_file_compact (OCADFile *pfile)
 Optimizes and repairs an open OCADFile. More...
 
int ocad_file_save_as (OCADFile *pfile, const char *filename)
 Saves an open OCADFile to the given filename. More...
 
bool ocad_file_bounds (OCADFile *file, OCADRect *rect)
 Calculates the bounding rectangle of all objects in the file. More...
 
int ocad_export (OCADFile *pfile, void *options)
 Exports part or all of an OCAD file to a specific format. More...
 
int ocad_export_file (OCADFile *pfile, const char *filename, void *options)
 Exports part or all of an OCAD file to a specific file. More...
 
bool ocad_setup_world_matrix (OCADFile *pfile, Transform *matrix)
 Fills in the provided matrix with a transformation from map coordinates to real-world coordinates. More...
 
int ocad_color_count (OCADFile *pfile)
 Returns the number of colors defined in the color table, or -1 if the file isn't valid. More...
 
OCADColor * ocad_color_at (OCADFile *pfile, int index)
 Returns a pointer to a particular color in the color table. More...
 
OCADColor * ocad_color (OCADFile *pfile, u8 number)
 Returns a pointer to a color in the color table with the given number. More...
 
int ocad_separation_count (OCADFile *pfile)
 Returns the number of spot colors defined in the separations table. More...
 
OCADColorSeparation * ocad_separation_at (OCADFile *pfile, int index)
 Returns a pointer to a particular spot color definition in the separations table. More...
 
void ocad_color_to_rgb (const OCADColor *c, int *arr)
 Converts an OCADColor to an RGB triplet in the provided array of ints. More...
 
void ocad_color_to_rgbf (const OCADColor *c, float *arr)
 Converts an OCADColor to an RGB triplet in the provided array of floats. More...
 
OCADSymbolIndex * ocad_symidx_first (OCADFile *pfile)
 Returns a pointer to the first symbol index block, or nullptr if the file isn't valid. More...
 
OCADSymbolIndex * ocad_symidx_next (OCADFile *pfile, OCADSymbolIndex *current)
 Returns a pointer to the next symbol index block after the given one, or nullptr if there is none. More...
 
int ocad_symbol_count (OCADFile *pfile)
 Returns the number of symbols defined in the file, or -1 if the file is invalid. More...
 
OCADSymbol * ocad_symbol_new (OCADFile *pfile, int size)
 Adds a new symbol with the given size in bytes to the file and returns a pointer to the new symbol. More...
 
OCADSymbol * ocad_symbol_at (OCADFile *pfile, OCADSymbolIndex *current, int index)
 Returns a pointer to the symbol in the specified location within the index block, or nullptr if there is no such symbol. More...
 
OCADSymbol * ocad_symbol (OCADFile *pfile, word number)
 Finds the symbol with a particular number, or nullptr if no such symbol exists. More...
 
bool ocad_symbol_uses_color (const OCADSymbol *symbol, s16 number)
 Returns TRUE if the symbol uses the given color number, FALSE otherwise. More...
 
bool ocad_symbol_iterate (OCADFile *pfile, OCADSymbolCallback callback, void *param)
 Iterates over all symbols in the file. More...
 
bool ocad_symbol_element_iterate (s16 ngrp, OCADPoint *pts, OCADSymbolElementCallback callback, void *param)
 Iterates over all symbol elements in the given location. More...
 
bool ocad_symbol_elements_use_color (s16 ngrp, OCADPoint *pts, s16 number)
 Returns TRUE if any of the sequence of symbol elements at the given location use the specified color. More...
 
OCADObjectIndexocad_objidx_first (OCADFile *pfile)
 Returns a pointer to the first object index block, or nullptr if the file isn't valid. More...
 
OCADObjectIndexocad_objidx_next (OCADFile *pfile, OCADObjectIndex *current)
 Returns a pointer to the next object index block after the given one, or nullptr if there is none. More...
 
OCADObjectEntry * ocad_object_entry_at (OCADFile *pfile, OCADObjectIndex *current, int index)
 Returns a pointer to the given object index entry, or nullptr if the file isn't valid. More...
 
void ocad_object_entry_refresh (OCADFile *pfile, OCADObjectEntry *entry, OCADObject *object)
 Recalculates the bounding rectangle and updates the size and symbol fields in an object index entry. More...
 
OCADObjectEntry * ocad_object_entry_new (OCADFile *pfile, u32 npts)
 Returns a pointer to the first empty object index entry large enough to fit an object with the given number of points. More...
 
int ocad_object_remove (OCADFile *pfile, OCADObjectEntry *entry)
 Removes the object at the given object index entry. More...
 
bool ocad_object_entry_iterate (OCADFile *pfile, OCADObjectEntryCallback callback, void *param)
 Iterates over all object entries in the file. More...
 
OCADObject * ocad_object_at (OCADFile *pfile, OCADObjectIndex *current, int index)
 Returns a pointer to the object in the specified location within the index block, or nullptr if there is no such object. More...
 
OCADObject * ocad_object (OCADFile *pfile, OCADObjectEntry *entry)
 Returns a pointer to an object, given a valid pointer to its index entry. More...
 
bool ocad_object_iterate (OCADFile *pfile, OCADObjectCallback callback, void *param)
 Iterates over all objects in the file. More...
 
u32 ocad_object_size (const OCADObject *object)
 Returns the storage size of an OCAD object, in bytes. More...
 
u32 ocad_object_size_npts (u32 npts)
 Returns the storage size of an OCAD object, in bytes, given the number of points. More...
 
OCADObject * ocad_object_alloc (const OCADObject *source)
 Allocates space for a temporary OCAD object, optionally copying it from an existing object. More...
 
OCADObject * ocad_object_add (OCADFile *file, const OCADObject *object, OCADObjectEntry **out_entry)
 Adds a new object to the file. More...
 
OCADStringIndex * ocad_string_index_first (OCADFile *pfile)
 Returns a pointer to the first string index block, or nullptr if the file isn't valid. More...
 
OCADStringIndex * ocad_string_index_next (OCADFile *pfile, OCADStringIndex *current)
 Returns a pointer to the next string index block after the given one, or nullptr if there is none. More...
 
OCADStringEntry * ocad_string_entry_at (OCADFile *pfile, OCADStringIndex *current, int index)
 Returns a pointer to the given string index entry, or nullptr if the file isn't valid. More...
 
OCADStringEntry * ocad_string_entry_new (OCADFile *pfile, u32 size)
 Creates a new string entry large enough to fit the specified number of bytes. More...
 
int ocad_string_remove (OCADFile *pfile, OCADStringEntry *entry)
 Removes the string at the given entry. More...
 
bool ocad_string_entry_iterate (OCADFile *pfile, OCADStringEntryCallback callback, void *param)
 Iterates over all string entries in the file. More...
 
OCADCString * ocad_string_at (OCADFile *pfile, OCADStringIndex *current, int index)
 Returns a pointer to the string in the specified location within the index block, or nullptr if there is no such string. More...
 
OCADCString * ocad_string (OCADFile *pfile, OCADStringEntry *entry)
 Returns a pointer to a string, given a valid pointer to its index entry. More...
 
int ocad_string_add_background (OCADFile *pfile, OCADBackground *bg)
 Adds a background template to the file. More...
 
int ocad_paint_data_init (OCADFile *pfile, OCADPaintData *data)
 Initializes an OCADPaintData object suitable for the given file. More...
 
int ocad_paint_data_free (OCADPaintData *data)
 Frees the memory used by an OCADPaintData object. More...
 
void ocad_paint_data_fill (OCADPaintData *pdata, const OCADRect *rect)
 Initializes the given OCADPaintData object and fills it with references to all objects intersecting the specified rectangle. More...
 
bool ocad_paint (const OCADPaintData *pdata, OCADPaintCallback *callback, void *param)
 Paints the contents of a valid OCADPaintData object, by creating successive calls to the methods defined in the callback object. More...
 
void ocad_rect_union (OCADRect *into, const OCADRect *other)
 Combines two OCADRects. More...
 
void dump_bytes (u8 *base, u32 size)
 

Macro Definition Documentation

◆ O_BINARY

#define O_BINARY   0

◆ OCAD_AREA_ELEMENT

#define OCAD_AREA_ELEMENT   2

◆ OCAD_AREA_SYMBOL

#define OCAD_AREA_SYMBOL   3

◆ OCAD_CIRCLE_ELEMENT

#define OCAD_CIRCLE_ELEMENT   3

◆ OCAD_DOT_ELEMENT

#define OCAD_DOT_ELEMENT   4

◆ OCAD_FILE_WAS_READONLY

#define OCAD_FILE_WAS_READONLY   -2

◆ OCAD_INVALID_FORMAT

#define OCAD_INVALID_FORMAT   -4

◆ OCAD_LINE_ELEMENT

#define OCAD_LINE_ELEMENT   1

◆ OCAD_LINE_SYMBOL

#define OCAD_LINE_SYMBOL   2

◆ OCAD_MAX_OBJECT_PTS

#define OCAD_MAX_OBJECT_PTS   32768

◆ OCAD_MMAP_FAILED

#define OCAD_MMAP_FAILED   -3

◆ OCAD_MMAP_NOT_SUPPORTED

#define OCAD_MMAP_NOT_SUPPORTED   -10

◆ OCAD_OK

#define OCAD_OK   0

◆ OCAD_OUT_OF_MEMORY

#define OCAD_OUT_OF_MEMORY   -1

◆ OCAD_POINT_SYMBOL

#define OCAD_POINT_SYMBOL   1

◆ OCAD_RECT_SYMBOL

#define OCAD_RECT_SYMBOL   5

◆ OCAD_TEXT_SYMBOL

#define OCAD_TEXT_SYMBOL   4

◆ OCADExportOptions_COMMON

#define OCADExportOptions_COMMON
Value:
int (*do_export)(OCADFile *, OCADExportOptions *); \
FILE *output; \
OCADRect rect; \
int partial;
OCADSetup struct _OCADFile OCADFile
Definition: libocad.h:530

◆ OCADSymbol_COMMON

#define OCADSymbol_COMMON
Value:
s16 size; \
s16 number; \
s16 type; \
byte subtype; \
byte base_flags; \
s16 extent; \
bool selected; \
byte status; \
s16 res2; \
s16 res3; \
dword respos; \
u8 colors[32]; /* bitmask */ \
str name[32]; \
u8 icon[12 * 22];
const QLatin1String type("type")
const QLatin1String name("name")
const char * icon
Definition: text_alignment_widget.cpp:41
int16_t s16
Definition: types.h:38

◆ PX_CTL1

#define PX_CTL1   0x1

◆ PX_CTL2

#define PX_CTL2   0x2

◆ PX_LEFT

#define PX_LEFT   0x4

◆ PY_CORNER

#define PY_CORNER   0x1

◆ PY_DASH

#define PY_DASH   0x8

◆ PY_HOLE

#define PY_HOLE   0x2

◆ PY_RIGHT

#define PY_RIGHT   0x4

Typedef Documentation

◆ IntPathCallback

typedef bool(* IntPathCallback) (void *, SegmentType, s32 *)

◆ OCADBackground

◆ OCADExportOptions

◆ OCADFile

typedef OCADSetup struct _OCADFile OCADFile

◆ OCADObjectCallback

typedef bool(* OCADObjectCallback) (void *, OCADFile *, OCADObject *)

◆ OCADObjectEntryCallback

typedef bool(* OCADObjectEntryCallback) (void *, OCADFile *, OCADObjectEntry *)

◆ OCADObjectIndex

typedef OCADObjectEntry struct _OCADObjectIndex OCADObjectIndex

◆ OCADPaintCallback

◆ OCADPaintColorIndex

◆ OCADPaintData

typedef struct _OCADPaintData OCADPaintData

◆ OCADPaintSymbolIndex

◆ OCADString

typedef struct _OCADString OCADString

◆ OCADStringEntryCallback

typedef bool(* OCADStringEntryCallback) (void *, OCADFile *, OCADStringEntry *)

◆ OCADSymbolCallback

typedef bool(* OCADSymbolCallback) (void *, OCADFile *, OCADSymbol *)

◆ OCADSymbolElementCallback

typedef bool(* OCADSymbolElementCallback) (void *, OCADSymbolElement *)

◆ SegmentType

typedef enum _SegmentType SegmentType

◆ str

typedef char str

Enumeration Type Documentation

◆ _SegmentType

Enumerator
MoveTo 
SegmentLineTo 
CurveTo 
ClosePath 

Function Documentation

◆ dump_bytes()

void dump_bytes ( u8 base,
u32  size 
)

◆ my_round()

int my_round ( double  x)

◆ my_strdup()

char* my_strdup ( const char *  s)

◆ ocad_color()

OCADColor* ocad_color ( OCADFile pfile,
u8  number 
)

Returns a pointer to a color in the color table with the given number.

If a color with that number is not found, nullptr is returned.

◆ ocad_color_at()

OCADColor* ocad_color_at ( OCADFile pfile,
int  index 
)

Returns a pointer to a particular color in the color table.

If index is less than zero or greater than the maximum color index, then nullptr is returned. Otherwise, a valid pointer to a color is returned. Note that the color index defined the order that colors are drawn (from top to bottom), and is independent from the color number that is used by symbol definition. The color number is available from (OCADColor *)->number.

◆ ocad_color_count()

int ocad_color_count ( OCADFile pfile)

Returns the number of colors defined in the color table, or -1 if the file isn't valid.

◆ ocad_color_to_rgb()

void ocad_color_to_rgb ( const OCADColor *  c,
int *  arr 
)

Converts an OCADColor to an RGB triplet in the provided array of ints.

The RGB values range from 0 to 255, and the array must have at least three valid elements.

◆ ocad_color_to_rgbf()

void ocad_color_to_rgbf ( const OCADColor *  c,
float *  arr 
)

Converts an OCADColor to an RGB triplet in the provided array of floats.

The RGB values range from 0.0f to 1.0f, and the array must have at least three valid elements.

◆ ocad_export()

int ocad_export ( OCADFile pfile,
void *  options 
)

Exports part or all of an OCAD file to a specific format.

The output stream must be preset in the options structure. You can use ocad_export_file() to export to a file. The options parameter must be binary compatible with OCADExportOptions.

◆ ocad_export_file()

int ocad_export_file ( OCADFile pfile,
const char *  filename,
void *  options 
)

Exports part or all of an OCAD file to a specific file.

The "output" field in the options is ignored and will be overwritten by a stream for the provided filename. The options parameter must be binary compatible with OCADExportOptions.

◆ ocad_file_bounds()

bool ocad_file_bounds ( OCADFile file,
OCADRect *  rect 
)

Calculates the bounding rectangle of all objects in the file.

◆ ocad_file_close()

int ocad_file_close ( OCADFile pfile)

Closes an open OCADFile.

The memory map is cleared, the file is closed, and all memory buffers used by the object are deallocated. After calling this function, the OCADFile object can be reused by ocad_file_open() without causing a memory leak.

Always returns OCAD_OK for success.

◆ ocad_file_compact()

int ocad_file_compact ( OCADFile pfile)

Optimizes and repairs an open OCADFile.

The file is reordered into Header, Colors, Setup, Symbols, Objects, and Strings. Entities of the same type are brought together into a contiguous section of file and any free space is compacted. The entity indexes are likewise compacted and cached data in the entities and index entries is regenerated, as follows:

Symbols: The "extent" field is recalculated from the symbol properties.

Objects: The bounding rectangle is recalculated from the path and symbol.

◆ ocad_file_new()

int ocad_file_new ( OCADFile **  pfile)

Creates a new OCADFile struct in memory.

Unused parts of the file buffer are set to zero.

Returns OCAD_OK on success, or OCAD_OUT_OF_MEMORY.

◆ ocad_file_open()

int ocad_file_open ( OCADFile **  pfile,
const char *  filename 
)

Opens a file with the given filename.

The file is loaded into memory and is accessible through the various ocad_file_* methods. The first argument can either be a pointer to a pre-allocated OCADFile object (e.g., on the stack), or nullptr to cause the object to be allocated on the heap. In the first case, the preallocated memory is considered to be uninitialized and will be zeroed before opening the file.

This function will verify the magic number and set up the OCAD file version.

An open OCADFile can be closed with ocad_file_close().

Returns OCAD_OK on success, or one of the following error codes:

  • OCAD_OUT_OF_MEMORY: Unable to allocate memory. errno was last set by malloc(2).
  • OCAD_FILE_WAS_READONLY: Unable to open file in read/write mode. errno was last set by open(2).
  • OCAD_MMAP_FAILED: Unable to memory map file. errno was last set by mmap(2) or read(2).
  • OCAD_INVALID_FORMAT: Unknown file format.

◆ ocad_file_open_mapped()

int ocad_file_open_mapped ( OCADFile **  pfile,
const char *  filename 
)

Behaves exactly like ocad_file_open(), except that the system attempts to open the file via memory mapping.

Returns 0 on success, one of the error codes returned by ocad_file_open(), or one of the following:

  • OCAD_MMAP_NOT_SUPPORTED: Memory mapping is not supported with this combination of system and libraries.

◆ ocad_file_open_memory()

int ocad_file_open_memory ( OCADFile **  pfile,
u8 buffer,
u32  size 
)

Behaves exactly like ocad_file_open(), except that the given buffer must contain the map data.

The buffer must be allocated with malloc(). Ownership of the buffer is transferred to libocad.

◆ ocad_file_reserve()

int ocad_file_reserve ( OCADFile file,
int  amount 
)

Makes sure that 'amount' number of bytes are reserved in the file's buffer in addition to the already used space.

Sets newly reserved memory to zero. Returns OCAD_OK or OCAD_OUT_OF_MEMORY.

WARNING: be extremely careful with this, as it might invalidate pointers to the buffer!

◆ ocad_file_save_as()

int ocad_file_save_as ( OCADFile pfile,
const char *  filename 
)

Saves an open OCADFile to the given filename.

Returns 0 on success, or one of the following error codes: -2: Unable to open file for writing errno was last set by open(2). -3: Unable to completely write data to the file. errno was last set by write(2).

◆ ocad_init()

int ocad_init ( )

Initializes the libocad library.

Currently, this only does some checks to determine that the library was compiled correctly and structures are packed appropriately. Returns 0 on success, or exits the current process on failure.

◆ ocad_object()

OCADObject* ocad_object ( OCADFile pfile,
OCADObjectEntry *  entry 
)

Returns a pointer to an object, given a valid pointer to its index entry.

Returns nullptr if the file isn't valid or the index entry is empty.

◆ ocad_object_add()

OCADObject* ocad_object_add ( OCADFile file,
const OCADObject *  object,
OCADObjectEntry **  out_entry 
)

Adds a new object to the file.

The size field should be set correctly prior to calling this function. This method can be used either to add a new object created by ocad_object_alloc(), or to duplicate an object by passing a pointer to an object already in the file.

The provided object is copied into the file and is left unchanged by this call. A pointer to the new object is returned, or nullptr if the object could not be added.

◆ ocad_object_alloc()

OCADObject* ocad_object_alloc ( const OCADObject *  source)

Allocates space for a temporary OCAD object, optionally copying it from an existing object.

The allocated space is the size of the largest object supported by the file format (32767 points). This object can then be manipulated with the ocad_object_* functions, and finally saved back into the file with ocad_object_add() or ocad_object_replace().

You may pass a nullptr parameter to create a new, empty object.

◆ ocad_object_at()

OCADObject* ocad_object_at ( OCADFile pfile,
OCADObjectIndex current,
int  index 
)

Returns a pointer to the object in the specified location within the index block, or nullptr if there is no such object.

◆ ocad_object_entry_at()

OCADObjectEntry* ocad_object_entry_at ( OCADFile pfile,
OCADObjectIndex current,
int  index 
)

Returns a pointer to the given object index entry, or nullptr if the file isn't valid.

Also returns nullptr if the index is out of range, but always returns a valid pointer if the file, index block, and index are valid.

◆ ocad_object_entry_iterate()

bool ocad_object_entry_iterate ( OCADFile pfile,
OCADObjectEntryCallback  callback,
void *  param 
)

Iterates over all object entries in the file.

◆ ocad_object_entry_new()

OCADObjectEntry* ocad_object_entry_new ( OCADFile pfile,
u32  npts 
)

Returns a pointer to the first empty object index entry large enough to fit an object with the given number of points.

If no suitable object index entry is found, a new entry will be created. This method will only return nullptr if the file isn't valid or if there is a memory allocation problem.

The returned entry will have its ptr and npts fields set; the caller is responsible for writing the object into the location pointed to by ptr, and setting the symbol, min, and max fields in the index entry. ocad_object_entry_refresh provides an easy way to sync these extra fields with an existing object.

◆ ocad_object_entry_refresh()

void ocad_object_entry_refresh ( OCADFile pfile,
OCADObjectEntry *  entry,
OCADObject *  object 
)

Recalculates the bounding rectangle and updates the size and symbol fields in an object index entry.

The entry's pointer and size field are not affected, and the object passed to this function doesn't need to be the same as the object referenced by the entry (although it should end up that way). The extent of the object's symbol is included in the bounding rectangle.

You usually shouldn't need to call this method directly. It is implicitly used by ocad_object_add(), ocad_object_replace(), and ocad_file_compact(). However, it's made available in case you need to selectively repair a particular index entry.

◆ ocad_object_iterate()

bool ocad_object_iterate ( OCADFile pfile,
OCADObjectCallback  callback,
void *  param 
)

Iterates over all objects in the file.

◆ ocad_object_remove()

int ocad_object_remove ( OCADFile pfile,
OCADObjectEntry *  entry 
)

Removes the object at the given object index entry.

Returns 0 on success, -1 if the file isn't valid. The object's symbol number is set to zero, and the entry's symbol number is set to zero. The entry becomes eligible to be returned by a call to ocad_object_entry_new(), if it is large enough for the new object.

◆ ocad_object_size()

u32 ocad_object_size ( const OCADObject *  object)

Returns the storage size of an OCAD object, in bytes.

◆ ocad_object_size_npts()

u32 ocad_object_size_npts ( u32  npts)

Returns the storage size of an OCAD object, in bytes, given the number of points.

◆ ocad_objidx_first()

OCADObjectIndex* ocad_objidx_first ( OCADFile pfile)

Returns a pointer to the first object index block, or nullptr if the file isn't valid.

Also returns nullptr if the file contains no object.

◆ ocad_objidx_next()

OCADObjectIndex* ocad_objidx_next ( OCADFile pfile,
OCADObjectIndex current 
)

Returns a pointer to the next object index block after the given one, or nullptr if there is none.

◆ ocad_paint()

bool ocad_paint ( const OCADPaintData pdata,
OCADPaintCallback callback,
void *  param 
)

Paints the contents of a valid OCADPaintData object, by creating successive calls to the methods defined in the callback object.

The callback can abort painting (by returning FALSE from callback->paint_object()), and if this happens the function will return FALSE. Otherwise, TRUE is returned.

The sequence of calls to the callback look like this:

set_color(OCADColor *color1); set_symbol(OCADSymbol *symbol1); paint_object(OCADObject *object1); paint_object(OCADObject *object2); paint_object(OCADObject *object3); set_symbol(OCADSymbol *symbol2); paint_object(OCADObject *object4); set_color(OCADColor *color2); set_symbol(OCADSymbol *symbol1); paint_object(OCADObject *object2);

Colors are selected in reverse index order (bottom to top), and objects with the same symbol are grouped together, to minimize the need for switching pen and brush properties in the target rendering context.

◆ ocad_paint_data_fill()

void ocad_paint_data_fill ( OCADPaintData pdata,
const OCADRect *  rect 
)

Initializes the given OCADPaintData object and fills it with references to all objects intersecting the specified rectangle.

The rectangle may be nullptr to indicate no spatial filtering.

If this call completes successfully, then the OCADPaintData object can be passed to ocad_paint(). The object can be cached and used for later calls to ocad_paint(), if desired.

◆ ocad_paint_data_free()

int ocad_paint_data_free ( OCADPaintData data)

Frees the memory used by an OCADPaintData object.

◆ ocad_paint_data_init()

int ocad_paint_data_init ( OCADFile pfile,
OCADPaintData data 
)

Initializes an OCADPaintData object suitable for the given file.

◆ ocad_path_bounds()

bool ocad_path_bounds ( s32 rect,
u32  npts,
const OCADPoint *  pts 
)

Calculates the bounds of the given path and returns it in the provided rectangle.

Returns FALSE and does not modify the rectangle if and only if npts is equal to zero. Otherwise, the rectangle is modified and TRUE is returned.

The "prect" array must have at least four elements. The bounds are returned in the order { minX, minY, maxX, maxY }.

Calculates the bounds of the given path and returns it in the provided rectangle.

If npts is 0, then the array is not modified and FALSE is returned; otherwise, it is modified and TRUE is returned.

◆ ocad_path_bounds_rect()

bool ocad_path_bounds_rect ( OCADRect *  rect,
u32  npts,
const OCADPoint *  pts 
)

Calculates the bounds of the given path and returns it in the provided rectangle.

Returns FALSE and does not modify the rectangle if and only if npts is equal to zero. Otherwise, the rectangle is modified and TRUE is returned.

Calculates the bounds of the given path and returns it in the provided rectangle.

All flags within the OCADRect are set to 0. If npts is 0, then rect is not modified and FALSE is returned; otherwise, it is modified and TRUE is returned.

◆ ocad_path_iterate()

bool ocad_path_iterate ( u32  npts,
const OCADPoint *  pts,
IntPathCallback  callback,
void *  param 
)

Iterates over an set of OCAD points, providing a list of PostScript-like path segments.

Iterates over an set of OCAD points, providing a list of PostScript-like path segments.

◆ ocad_point()

const s32* ocad_point ( s32 buf,
const OCADPoint *  pt 
)

Converts an OCAD point into a triplet of signed integers.

The first value is the x-coordinate, second is the y-coordinate, and the third is a set of flags. The buffer should have at least three elements (3 * sizeof(s32)), or 12 bytes. A pointer to the beginning of the buffer is returned.

◆ ocad_point2()

const s32* ocad_point2 ( s32 **  pbuf,
const OCADPoint *  pt 
)

Converts an OCAD point into a triplet of signed integers like ocad_point(), but advances the buffer pointer by three elements.

This allows the caller to accumulate a list of points in a single buffer.

◆ ocad_rect_grow()

bool ocad_rect_grow ( OCADRect *  prect,
s32  amount 
)

Grows the given rectangle by the given amount, which may be negative.

This method will not validate the size of rectangle. Always returns TRUE.

Grows the given rectangle by the given amount, which may be negative.

The flags in the OCADRect are unaffected. This function always returns TRUE.

◆ ocad_rect_intersects()

bool ocad_rect_intersects ( const OCADRect *  r1,
const OCADRect *  r2 
)

Returns true if the two rectangle intersect, FALSE otherwise.

Returns true if the two rectangle intersect, FALSE otherwise.

If the result is empty, r1 is unchanged and FALSE is returned. Otherwise, the result is stored in r1 and TRUE is returned.

◆ ocad_rect_union()

void ocad_rect_union ( OCADRect *  r1,
const OCADRect *  r2 
)

Combines two OCADRects.

Combines two OCADRects.

The flags in the OCADRect are unaffected. This function always returns TRUE.

◆ ocad_separation_at()

OCADColorSeparation* ocad_separation_at ( OCADFile pfile,
int  index 
)

Returns a pointer to a particular spot color definition in the separations table.

If index is less than zero, greater than the maximum color index or greater than 32, then nullptr is returned. The index corresponds to the index in the spot color table at OCADColor::spot.

◆ ocad_separation_count()

int ocad_separation_count ( OCADFile pfile)

Returns the number of spot colors defined in the separations table.

Returns -1 if the file isn't valid, or returns the negative value if the number in the file exceeds 32.

◆ ocad_setup_world_matrix()

bool ocad_setup_world_matrix ( OCADFile pfile,
Transform matrix 
)

Fills in the provided matrix with a transformation from map coordinates to real-world coordinates.

Returns TRUE if the matrix was computed, FALSE if it could not be computed because the file is invalid or the real-world coordinate flag is unset (in which case the parameters are invalid.)

◆ ocad_shutdown()

int ocad_shutdown ( )

Shuts down the libocad library.

Currently this is a no-op, but is included as part of the API to support future enhancements. Processes that use the library should call this function when they exit. The function always returns 0 for success.

◆ ocad_str()

const char* ocad_str ( char *  buf,
const str ostr 
)

Converts an OCAD string (0-255 characters) to a zero-terminated string in the given buffer.

The buffer must be at least 256 bytes long. A pointer to the zero-terminated string is returned.

◆ ocad_str2()

const char* ocad_str2 ( char **  buf,
const str ostr 
)

Converts an OCAD string (0-255 characters) to a zero-terminated string in the given buffer, returns a pointer to the zero-terminated string, and advances the buffer point just beyond the zero byte.

Subsequent calls to this function can be made to build up a list of zero- terminated strings. This is useful, for example, in printf statements.

char tmp[512], *ptmp = &tmp;
printf("%s %s", ocad_str2(&ptmp, str1), ocad_str2(&ptmp, str2));

Both OCAD strings will be appended to the buffer and separate pointers will be passed to printf. Note that the buffer size must be at least 256 times the number of strings to be converted before ptmp is reset, to prevent the potential for buffer overflow.

◆ ocad_string()

OCADCString* ocad_string ( OCADFile pfile,
OCADStringEntry *  entry 
)

Returns a pointer to a string, given a valid pointer to its index entry.

Returns nullptr if the file isn't valid or the index entry is empty.

◆ ocad_string_add_background()

int ocad_string_add_background ( OCADFile pfile,
OCADBackground bg 
)

Adds a background template to the file.

◆ ocad_string_at()

OCADCString* ocad_string_at ( OCADFile pfile,
OCADStringIndex *  current,
int  index 
)

Returns a pointer to the string in the specified location within the index block, or nullptr if there is no such string.

◆ ocad_string_entry_at()

OCADStringEntry* ocad_string_entry_at ( OCADFile pfile,
OCADStringIndex *  current,
int  index 
)

Returns a pointer to the given string index entry, or nullptr if the file isn't valid.

Also returns nullptr if the index is out of range, but always returns a valid pointer if the file, index block, and index are valid.

◆ ocad_string_entry_iterate()

bool ocad_string_entry_iterate ( OCADFile pfile,
OCADStringEntryCallback  callback,
void *  param 
)

Iterates over all string entries in the file.

◆ ocad_string_entry_new()

OCADStringEntry* ocad_string_entry_new ( OCADFile pfile,
u32  size 
)

Creates a new string entry large enough to fit the specified number of bytes.

If there is an empty string index entry of sufficient size, it will be used; otherwise, a new entry will be allocated. The entry returned will have its ptr and size fields set; the size field may be larger than the size requested in the parameter. The caller is responsible for copying data into the actual string (retrieved via ocad_string()). If there is not enough memory to create a new entry, nullptr is returned.

◆ ocad_string_index_first()

OCADStringIndex* ocad_string_index_first ( OCADFile pfile)

Returns a pointer to the first string index block, or nullptr if the file isn't valid.

Also returns nullptr if the file contains no object.

◆ ocad_string_index_next()

OCADStringIndex* ocad_string_index_next ( OCADFile pfile,
OCADStringIndex *  current 
)

Returns a pointer to the next string index block after the given one, or nullptr if there is none.

◆ ocad_string_remove()

int ocad_string_remove ( OCADFile pfile,
OCADStringEntry *  entry 
)

Removes the string at the given entry.

The string type is set to zero and the entry becomes eligibile to be returned by ocad_string_entry_new().

◆ ocad_symbol()

OCADSymbol* ocad_symbol ( OCADFile pfile,
word  number 
)

Finds the symbol with a particular number, or nullptr if no such symbol exists.

◆ ocad_symbol_at()

OCADSymbol* ocad_symbol_at ( OCADFile pfile,
OCADSymbolIndex *  current,
int  index 
)

Returns a pointer to the symbol in the specified location within the index block, or nullptr if there is no such symbol.

◆ ocad_symbol_count()

int ocad_symbol_count ( OCADFile pfile)

Returns the number of symbols defined in the file, or -1 if the file is invalid.

◆ ocad_symbol_element_iterate()

bool ocad_symbol_element_iterate ( s16  ngrp,
OCADPoint *  pts,
OCADSymbolElementCallback  callback,
void *  param 
)

Iterates over all symbol elements in the given location.

ngrp is the number of 8-byte groups, starting at the pts pointer. Currently this is used in two places; within point objects, and within area objects that have a pattern defined. The callback should return TRUE to continue iteration or FALSE to abort iteration. This function returns TRUE if the iteration completed successfully, FALSE if it was aborted by the callback.

◆ ocad_symbol_elements_use_color()

bool ocad_symbol_elements_use_color ( s16  ngrp,
OCADPoint *  pts,
s16  number 
)

Returns TRUE if any of the sequence of symbol elements at the given location use the specified color.

◆ ocad_symbol_iterate()

bool ocad_symbol_iterate ( OCADFile pfile,
OCADSymbolCallback  callback,
void *  param 
)

Iterates over all symbols in the file.

The extra parameter is passed to the callback function, together with a pointer to the file and a pointer to the current symbol. The callback should return TRUE to continue iteration or FALSE to abort iteration. This function returns TRUE if the iteration completed successfully, FALSE if it was aborted by the callback.

◆ ocad_symbol_new()

OCADSymbol* ocad_symbol_new ( OCADFile pfile,
int  size 
)

Adds a new symbol with the given size in bytes to the file and returns a pointer to the new symbol.

◆ ocad_symbol_uses_color()

bool ocad_symbol_uses_color ( const OCADSymbol *  symbol,
s16  number 
)

Returns TRUE if the symbol uses the given color number, FALSE otherwise.

◆ ocad_symidx_first()

OCADSymbolIndex* ocad_symidx_first ( OCADFile pfile)

Returns a pointer to the first symbol index block, or nullptr if the file isn't valid.

Also returns nullptr if the file contains no symbols.

◆ ocad_symidx_next()

OCADSymbolIndex* ocad_symidx_next ( OCADFile pfile,
OCADSymbolIndex *  current 
)

Returns a pointer to the next symbol index block after the given one, or nullptr if there is none.

◆ ocad_to_background()

int ocad_to_background ( OCADBackground bg,
OCADCString *  templ 
)

Converts an OCAD string of the correct type into an OCADBackground structure.

◆ PACK() [1/10]

PACK ( typedef struct _OCADPoint { s32 x;s32 y;}  ,
OCADPoint   
)

◆ PACK() [2/10]

OCADRect PACK ( typedef struct _OCADFileHeader { word magic;word ftype;word major;word minor;dword osymidx;dword oobjidx;dword osetup;dword ssetup;dword infopos;dword infosize;dword ostringidx;dword res4;dword res5;dword res6;word ncolors;word nsep;u8 res8[20];}  ,
OCADFileHeader   
)

The color number associated with this color. This is independent from the color index (which defines the painting order) and is the number referenced by symbols.

A reserved word in the data structure.

The proportion of cyan ink in this color, in the range 0 to 200 inclusive.

The proportion of magenta ink in this color, in the range 0 to 200 inclusive.

The proportion of yellow ink in this color, in the range 0 to 200 inclusive.

The proportion of black ink in this color, in the range 0 to 200 inclusive.

The name of this color.

The spot color attributes for this color; currently an uncharacteristized data blob.

◆ PACK() [3/10]

OCADColor PACK ( typedef struct _OCADColorSeparation { str sep_name[16];byte cyan;byte magenta;byte yellow;byte black;word raster_freq;word raster_angle;}  ,
OCADColorSeparation   
)

◆ PACK() [4/10]

OCADSymbolEntry PACK ( typedef struct _OCADSymbolIndex { dword next;OCADSymbolEntry entry[256];}  ,
OCADSymbolIndex   
)

◆ PACK() [5/10]

OCADSymbolElement PACK ( typedef struct _OCADSymbol { OCADSymbol_COMMON ,
OCADSymbol   
)

◆ PACK() [6/10]

OCADPointSymbol PACK ( typedef struct _OCADLineSymbol { OCADSymbol_COMMON u16 color;u16 width;word ends;s16 bdist;s16 edist;s16 len;s16 elen;s16 gap;s16 gap2;s16 egap;s16 smin;s16 snum;s16 sdist;word dmode;word dflags;s16 dcolor;s16 lcolor;s16 rcolor;s16 dwidth;s16 lwidth;s16 rwidth;s16 dlen;s16 dgap;s16 dres[3];word tmode;s16 tlast;s16 tres;s16 fcolor;s16 fwidth;s16 fstyle;s16 smnpts;s16 ssnpts;s16 scnpts;s16 sbnpts;s16 senpts;s16 res4;OCADPoint pts[1];}  ,
OCADLineSymbol   
)

◆ PACK() [7/10]

OCADAreaSymbol PACK ( typedef struct _OCADTextSymbol { OCADSymbol_COMMON str font[32];s16 color;s16 dpts;s16 bold;byte italic;byte charset;s16 cspace;s16 wspace;s16 halign;s16 lspace;s16 pspace;s16 indent1;s16 indent2;s16 ntabs;s32 tab[32];wbool under;s16 ucolor;s16 uwidth;s16 udist;s16 res4;s16 fmode;str ffont[32];s16 fcolor;s16 fdpts;s16 fbold;wbool fitalic;s16 fdx;s16 fdy;}  ,
OCADTextSymbol   
)

◆ PACK() [8/10]

OCADRectSymbol PACK ( typedef struct _OCADObject { s16 symbol;byte type;byte unicode;u16 npts;u16 ntext;s16 angle;s16 res1;s32 res2;u8 res3[16];OCADPoint pts[1];}  ,
OCADObject   
)

◆ PACK() [9/10]

PACK ( typedef struct _OCADCString { char str[1];}  ,
OCADCString   
)

◆ PACK() [10/10]

OCADStringEntry PACK ( typedef struct _OCADStringIndex { dword next;OCADStringEntry entry[256];}  ,
OCADStringIndex   
)