2 |
- |
1 |
/*
|
|
|
2 |
* drawfile.h
|
|
|
3 |
* Copyright (C) 2005 A.J. van Os; Released under GNU GPL
|
|
|
4 |
*
|
|
|
5 |
* Description:
|
|
|
6 |
* Include file to deal with drawfiles
|
|
|
7 |
*
|
|
|
8 |
* Based on:
|
|
|
9 |
* C header file for DrawFile
|
|
|
10 |
* written by DefMod (May 4 2004) on Tue May 4 13:34:17 2004
|
|
|
11 |
* Jonathan Coxhead, jonathan@doves.demon.co.uk, 21 Aug 1995
|
|
|
12 |
* OSLib---efficient, type-safe, transparent, extensible,
|
|
|
13 |
* register-safe A P I coverage of RISC O S
|
|
|
14 |
* Copyright (C) 1994 Jonathan Coxhead
|
|
|
15 |
*
|
|
|
16 |
* All credit should go to him, but all the bugs are mine
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#if !defined(__drawfile_h)
|
|
|
20 |
#define __drawfile_h
|
|
|
21 |
|
|
|
22 |
#include "DeskLib:Sprite.h"
|
|
|
23 |
#include "DeskLib:Wimp.h"
|
|
|
24 |
|
|
|
25 |
#if !defined(BOOL)
|
|
|
26 |
#define BOOL int
|
|
|
27 |
#define TRUE 1
|
|
|
28 |
#define FALSE 0
|
|
|
29 |
#endif /* !BOOL */
|
|
|
30 |
|
|
|
31 |
/*********************
|
|
|
32 |
* Conversion macros *
|
|
|
33 |
*********************/
|
|
|
34 |
#define Drawfile_DrawToScreen(i) ((i) / 256)
|
|
|
35 |
#define Drawfile_ScreenToDraw(i) ((i) * 256)
|
|
|
36 |
|
|
|
37 |
/**********************************
|
|
|
38 |
* SWI names and SWI reason codes *
|
|
|
39 |
**********************************/
|
|
|
40 |
#define DrawFile_Render 0x45540
|
|
|
41 |
#define DrawFile_BBox 0x45541
|
|
|
42 |
#define DrawFile_DeclareFonts 0x45542
|
|
|
43 |
|
|
|
44 |
/********************
|
|
|
45 |
* Type definitions *
|
|
|
46 |
********************/
|
|
|
47 |
typedef unsigned int bits;
|
|
|
48 |
typedef unsigned char byte;
|
|
|
49 |
|
|
|
50 |
typedef byte drawfile_fontref;
|
|
|
51 |
|
|
|
52 |
typedef byte drawfile_path_style_flags;
|
|
|
53 |
|
|
|
54 |
typedef bits drawfile_text_flags;
|
|
|
55 |
|
|
|
56 |
typedef bits drawfile_render_flags;
|
|
|
57 |
|
|
|
58 |
typedef bits drawfile_declare_fonts_flags;
|
|
|
59 |
|
|
|
60 |
typedef bits drawfile_paper_options;
|
|
|
61 |
|
|
|
62 |
typedef bits drawfile_entry_mode;
|
|
|
63 |
|
|
|
64 |
typedef enum {
|
|
|
65 |
drawfile_TYPE_FONT_TABLE = 0,
|
|
|
66 |
drawfile_TYPE_TEXT = 1,
|
|
|
67 |
drawfile_TYPE_PATH = 2,
|
|
|
68 |
drawfile_TYPE_SPRITE = 5,
|
|
|
69 |
drawfile_TYPE_GROUP = 6,
|
|
|
70 |
drawfile_TYPE_TAGGED = 7,
|
|
|
71 |
drawfile_TYPE_TEXT_AREA = 9,
|
|
|
72 |
drawfile_TYPE_TEXT_COLUMN = 10,
|
|
|
73 |
drawfile_TYPE_OPTIONS = 11,
|
|
|
74 |
drawfile_TYPE_TRFM_TEXT = 12,
|
|
|
75 |
drawfile_TYPE_TRFM_SPRITE = 13,
|
|
|
76 |
drawfile_TYPE_JPEG = 16
|
|
|
77 |
} drawfile_type;
|
|
|
78 |
|
|
|
79 |
typedef enum {
|
|
|
80 |
drawfile_PATH_END_PATH = 0,
|
|
|
81 |
drawfile_PATH_CONTINUATION = 1,
|
|
|
82 |
drawfile_PATH_MOVE_TO = 2,
|
|
|
83 |
drawfile_PATH_SPECIAL_MOVE_TO = 3,
|
|
|
84 |
drawfile_PATH_CLOSE_GAP = 4,
|
|
|
85 |
drawfile_PATH_CLOSE_LINE = 5,
|
|
|
86 |
drawfile_PATH_BEZIER_TO = 6,
|
|
|
87 |
drawfile_PATH_GAP_TO = 7,
|
|
|
88 |
drawfile_PATH_LINE_TO = 8
|
|
|
89 |
} drawfile_path_type;
|
|
|
90 |
|
|
|
91 |
typedef struct {
|
|
|
92 |
int start;
|
|
|
93 |
int element_count;
|
|
|
94 |
int elements [6];
|
|
|
95 |
} draw_dash_pattern;
|
|
|
96 |
|
|
|
97 |
typedef struct {
|
|
|
98 |
int entries [3] [2];
|
|
|
99 |
} os_trfm;
|
|
|
100 |
|
|
|
101 |
typedef struct {
|
|
|
102 |
void *data;
|
|
|
103 |
size_t length;
|
|
|
104 |
} drawfile_info;
|
|
|
105 |
|
|
|
106 |
typedef struct {
|
|
|
107 |
drawfile_fontref font_ref;
|
|
|
108 |
char font_name [1];
|
|
|
109 |
} drawfile_font_def;
|
|
|
110 |
|
|
|
111 |
typedef struct {
|
|
|
112 |
drawfile_fontref font_ref;
|
|
|
113 |
byte reserved [3];
|
|
|
114 |
} drawfile_text_style;
|
|
|
115 |
|
|
|
116 |
typedef struct {
|
|
|
117 |
drawfile_path_style_flags flags;
|
|
|
118 |
byte reserved;
|
|
|
119 |
byte cap_width;
|
|
|
120 |
byte cap_length;
|
|
|
121 |
} drawfile_path_style;
|
|
|
122 |
|
|
|
123 |
typedef struct {
|
|
|
124 |
drawfile_font_def font_def[1];
|
|
|
125 |
} drawfile_font_table;
|
|
|
126 |
|
|
|
127 |
typedef struct {
|
|
|
128 |
wimp_box bbox;
|
|
|
129 |
palette_entry fill;
|
|
|
130 |
palette_entry bg_hint;
|
|
|
131 |
drawfile_text_style style;
|
|
|
132 |
int xsize;
|
|
|
133 |
int ysize;
|
|
|
134 |
wimp_coord base;
|
|
|
135 |
char text [1];
|
|
|
136 |
} drawfile_text;
|
|
|
137 |
|
|
|
138 |
typedef struct {
|
|
|
139 |
wimp_box bbox;
|
|
|
140 |
palette_entry fill;
|
|
|
141 |
palette_entry outline;
|
|
|
142 |
int width;
|
|
|
143 |
drawfile_path_style style;
|
|
|
144 |
int path [1];
|
|
|
145 |
} drawfile_path;
|
|
|
146 |
|
|
|
147 |
typedef struct {
|
|
|
148 |
wimp_box bbox;
|
|
|
149 |
palette_entry fill;
|
|
|
150 |
palette_entry outline;
|
|
|
151 |
int width;
|
|
|
152 |
drawfile_path_style style;
|
|
|
153 |
draw_dash_pattern pattern;
|
|
|
154 |
int path [1];
|
|
|
155 |
} drawfile_path_with_pattern;
|
|
|
156 |
|
|
|
157 |
typedef struct {
|
|
|
158 |
wimp_box bbox;
|
|
|
159 |
sprite_header header;
|
|
|
160 |
byte data [1];
|
|
|
161 |
} drawfile_sprite;
|
|
|
162 |
|
|
|
163 |
typedef struct {
|
|
|
164 |
wimp_box bbox;
|
|
|
165 |
char name [12];
|
|
|
166 |
int objects [1];
|
|
|
167 |
} drawfile_group;
|
|
|
168 |
|
|
|
169 |
typedef struct {
|
|
|
170 |
wimp_box bbox;
|
|
|
171 |
drawfile_type tag;
|
|
|
172 |
int object [1];
|
|
|
173 |
} drawfile_tagged;
|
|
|
174 |
|
|
|
175 |
typedef struct {
|
|
|
176 |
wimp_box box;
|
|
|
177 |
} drawfile_text_column;
|
|
|
178 |
|
|
|
179 |
typedef struct {
|
|
|
180 |
struct {
|
|
|
181 |
drawfile_type type;
|
|
|
182 |
int size;
|
|
|
183 |
drawfile_text_column data;
|
|
|
184 |
} columns [1];
|
|
|
185 |
} drawfile_text_column_list;
|
|
|
186 |
|
|
|
187 |
typedef struct {
|
|
|
188 |
drawfile_type type;
|
|
|
189 |
int reserved [2];
|
|
|
190 |
palette_entry fill;
|
|
|
191 |
palette_entry bg_hint;
|
|
|
192 |
char text [1];
|
|
|
193 |
} drawfile_area_text;
|
|
|
194 |
|
|
|
195 |
typedef struct {
|
|
|
196 |
wimp_box bbox;
|
|
|
197 |
drawfile_text_column_list header;
|
|
|
198 |
drawfile_area_text area_text;
|
|
|
199 |
} drawfile_text_area;
|
|
|
200 |
|
|
|
201 |
typedef struct {
|
|
|
202 |
wimp_box bbox;
|
|
|
203 |
int paper_size;
|
|
|
204 |
drawfile_paper_options paper_options;
|
|
|
205 |
double grid_spacing;
|
|
|
206 |
int grid_division;
|
|
|
207 |
BOOL isometric;
|
|
|
208 |
BOOL auto_adjust;
|
|
|
209 |
BOOL show;
|
|
|
210 |
BOOL lock;
|
|
|
211 |
BOOL cm;
|
|
|
212 |
int zoom_mul;
|
|
|
213 |
int zoom_div;
|
|
|
214 |
BOOL zoom_lock;
|
|
|
215 |
BOOL toolbox;
|
|
|
216 |
drawfile_entry_mode entry_mode;
|
|
|
217 |
int undo_size;
|
|
|
218 |
} drawfile_options;
|
|
|
219 |
|
|
|
220 |
typedef struct {
|
|
|
221 |
wimp_box bbox;
|
|
|
222 |
os_trfm trfm;
|
|
|
223 |
drawfile_text_flags flags;
|
|
|
224 |
palette_entry fill;
|
|
|
225 |
palette_entry bg_hint;
|
|
|
226 |
drawfile_text_style style;
|
|
|
227 |
int xsize;
|
|
|
228 |
int ysize;
|
|
|
229 |
wimp_coord base;
|
|
|
230 |
char text [1];
|
|
|
231 |
} drawfile_trfm_text;
|
|
|
232 |
|
|
|
233 |
typedef struct {
|
|
|
234 |
wimp_box bbox;
|
|
|
235 |
os_trfm trfm;
|
|
|
236 |
sprite_header header;
|
|
|
237 |
byte data [1];
|
|
|
238 |
} drawfile_trfm_sprite;
|
|
|
239 |
|
|
|
240 |
typedef struct {
|
|
|
241 |
wimp_box bbox;
|
|
|
242 |
int width;
|
|
|
243 |
int height;
|
|
|
244 |
int xdpi;
|
|
|
245 |
int ydpi;
|
|
|
246 |
os_trfm trfm;
|
|
|
247 |
int len;
|
|
|
248 |
byte data [1];
|
|
|
249 |
} drawfile_jpeg;
|
|
|
250 |
|
|
|
251 |
/* ------------------------------------------------------------------------
|
|
|
252 |
* Type: drawfile_object
|
|
|
253 |
*
|
|
|
254 |
* Description: This type is used to declare pointers rather than objects
|
|
|
255 |
*/
|
|
|
256 |
|
|
|
257 |
typedef struct {
|
|
|
258 |
drawfile_type type;
|
|
|
259 |
int size;
|
|
|
260 |
union {
|
|
|
261 |
drawfile_font_table font_table;
|
|
|
262 |
drawfile_text text;
|
|
|
263 |
drawfile_path path;
|
|
|
264 |
drawfile_path_with_pattern path_with_pattern;
|
|
|
265 |
drawfile_sprite sprite;
|
|
|
266 |
drawfile_group group;
|
|
|
267 |
drawfile_tagged tagged;
|
|
|
268 |
drawfile_text_column text_column;
|
|
|
269 |
drawfile_text_area text_area;
|
|
|
270 |
drawfile_options options;
|
|
|
271 |
drawfile_trfm_text trfm_text;
|
|
|
272 |
drawfile_trfm_sprite trfm_sprite;
|
|
|
273 |
drawfile_jpeg jpeg;
|
|
|
274 |
} data;
|
|
|
275 |
} drawfile_object;
|
|
|
276 |
|
|
|
277 |
typedef struct {
|
|
|
278 |
char tag [4];
|
|
|
279 |
int major_version;
|
|
|
280 |
int minor_version;
|
|
|
281 |
char source [12];
|
|
|
282 |
wimp_box bbox;
|
|
|
283 |
drawfile_object objects [1];
|
|
|
284 |
} drawfile_diagram;
|
|
|
285 |
|
|
|
286 |
typedef bits drawfile_bbox_flags;
|
|
|
287 |
|
|
|
288 |
typedef struct {
|
|
|
289 |
drawfile_object *object;
|
|
|
290 |
drawfile_diagram *diagram;
|
|
|
291 |
drawfile_object *font_table;
|
|
|
292 |
drawfile_declare_fonts_flags flags;
|
|
|
293 |
os_error *error;
|
|
|
294 |
} drawfile_declare_fonts_state;
|
|
|
295 |
|
|
|
296 |
/************************
|
|
|
297 |
* Constant definitions *
|
|
|
298 |
************************/
|
|
|
299 |
#define error_DRAW_FILE_NOT_DRAW 0x20C00u
|
|
|
300 |
#define error_DRAW_FILE_VERSION 0x20C01u
|
|
|
301 |
#define error_DRAW_FILE_FONT_TAB 0x20C02u
|
|
|
302 |
#define error_DRAW_FILE_BAD_FONT_NO 0x20C03u
|
|
|
303 |
#define error_DRAW_FILE_BAD_MODE 0x20C04u
|
|
|
304 |
#define error_DRAW_FILE_BAD_FILE 0x20C05u
|
|
|
305 |
#define error_DRAW_FILE_BAD_GROUP 0x20C06u
|
|
|
306 |
#define error_DRAW_FILE_BAD_TAG 0x20C07u
|
|
|
307 |
#define error_DRAW_FILE_SYNTAX 0x20C08u
|
|
|
308 |
#define error_DRAW_FILE_FONT_NO 0x20C09u
|
|
|
309 |
#define error_DRAW_FILE_AREA_VER 0x20C0Au
|
|
|
310 |
#define error_DRAW_FILE_NO_AREA_VER 0x20C0Bu
|
|
|
311 |
|
|
|
312 |
#define drawfile_PATH_MITRED ((drawfile_path_style_flags) 0x0u)
|
|
|
313 |
#define drawfile_PATH_ROUND ((drawfile_path_style_flags) 0x1u)
|
|
|
314 |
#define drawfile_PATH_BEVELLED ((drawfile_path_style_flags) 0x2u)
|
|
|
315 |
#define drawfile_PATH_BUTT ((drawfile_path_style_flags) 0x0u)
|
|
|
316 |
#define drawfile_PATH_SQUARE ((drawfile_path_style_flags) 0x2u)
|
|
|
317 |
#define drawfile_PATH_TRIANGLE ((drawfile_path_style_flags) 0x3u)
|
|
|
318 |
#define drawfile_PATH_JOIN_SHIFT 0
|
|
|
319 |
#define drawfile_PATH_JOIN ((drawfile_path_style_flags) 0x3u)
|
|
|
320 |
#define drawfile_PATH_END_SHIFT 2
|
|
|
321 |
#define drawfile_PATH_END ((drawfile_path_style_flags) 0xCu)
|
|
|
322 |
#define drawfile_PATH_START_SHIFT 4
|
|
|
323 |
#define drawfile_PATH_START ((drawfile_path_style_flags) 0x30u)
|
|
|
324 |
#define drawfile_PATH_WINDING_EVEN_ODD ((drawfile_path_style_flags) 0x40u)
|
|
|
325 |
#define drawfile_PATH_DASHED ((drawfile_path_style_flags) 0x80u)
|
|
|
326 |
#define drawfile_PATH_CAP_WIDTH_SHIFT 16
|
|
|
327 |
#define drawfile_PATH_CAP_WIDTH ((drawfile_path_style_flags) 0xFF0000u)
|
|
|
328 |
#define drawfile_PATH_CAP_LENGTH_SHIFT 24
|
|
|
329 |
#define drawfile_PATH_CAP_LENGTH ((drawfile_path_style_flags) 0xFF000000u)
|
|
|
330 |
#define drawfile_TEXT_KERN ((drawfile_text_flags) 0x1u)
|
|
|
331 |
#define drawfile_TEXT_RIGHT_TO_LEFT ((drawfile_text_flags) 0x2u)
|
|
|
332 |
#define drawfile_TEXT_UNDERLINE ((drawfile_text_flags) 0x4u)
|
|
|
333 |
#define drawfile_RENDER_BBOXES ((drawfile_render_flags) 0x1u)
|
|
|
334 |
#define drawfile_RENDER_SUPPRESS ((drawfile_render_flags) 0x2u)
|
|
|
335 |
#define drawfile_RENDER_GIVEN_FLATNESS ((drawfile_render_flags) 0x4u)
|
|
|
336 |
#define drawfile_RENDER_GIVEN_COLOUR_MAPPING ((drawfile_render_flags) 0x8u)
|
|
|
337 |
#define drawfile_NO_DOWNLOAD ((drawfile_declare_fonts_flags) 0x1u)
|
|
|
338 |
#define drawfile_PAPER_SHOW ((drawfile_paper_options) 0x1u)
|
|
|
339 |
#define drawfile_PAPER_LANDSCAPE ((drawfile_paper_options) 0x10u)
|
|
|
340 |
#define drawfile_PAPER_DEFAULT ((drawfile_paper_options) 0x100u)
|
|
|
341 |
#define drawfile_ENTRY_MODE_LINE ((drawfile_entry_mode) 0x1u)
|
|
|
342 |
#define drawfile_ENTRY_MODE_CLOSED_LINE ((drawfile_entry_mode) 0x2u)
|
|
|
343 |
#define drawfile_ENTRY_MODE_CURVE ((drawfile_entry_mode) 0x4u)
|
|
|
344 |
#define drawfile_ENTRY_MODE_CLOSED_CURVE ((drawfile_entry_mode) 0x8u)
|
|
|
345 |
#define drawfile_ENTRY_MODE_RECTANGLE ((drawfile_entry_mode) 0x10u)
|
|
|
346 |
#define drawfile_ENTRY_MODE_ELLIPSE ((drawfile_entry_mode) 0x20u)
|
|
|
347 |
#define drawfile_ENTRY_MODE_TEXT_LINE ((drawfile_entry_mode) 0x40u)
|
|
|
348 |
#define drawfile_ENTRY_MODE_SELECT ((drawfile_entry_mode) 0x80u)
|
|
|
349 |
|
|
|
350 |
/*************************
|
|
|
351 |
* Function declarations *
|
|
|
352 |
*************************/
|
|
|
353 |
|
|
|
354 |
#if defined(__cplusplus)
|
|
|
355 |
extern "C" {
|
|
|
356 |
#endif /* __cplusplus */
|
|
|
357 |
|
|
|
358 |
/* ------------------------------------------------------------------------
|
|
|
359 |
* Function: drawfile_render()
|
|
|
360 |
*
|
|
|
361 |
* Description: Calls SWI 0x45540
|
|
|
362 |
*
|
|
|
363 |
* Input: flags - value of R0 on entry
|
|
|
364 |
* diagram - value of R1 on entry
|
|
|
365 |
* size - value of R2 on entry
|
|
|
366 |
* trfm - value of R3 on entry
|
|
|
367 |
* clip - value of R4 on entry
|
|
|
368 |
* flatness - value of R5 on entry
|
|
|
369 |
*/
|
|
|
370 |
|
|
|
371 |
extern os_error *Drawfile_Render (drawfile_render_flags flags,
|
|
|
372 |
drawfile_diagram const *diagram,
|
|
|
373 |
int size,
|
|
|
374 |
os_trfm const *trfm,
|
|
|
375 |
wimp_box const *clip,
|
|
|
376 |
int flatness);
|
|
|
377 |
|
|
|
378 |
/* ------------------------------------------------------------------------
|
|
|
379 |
* Function: drawfile_bbox()
|
|
|
380 |
*
|
|
|
381 |
* Description: Calls SWI 0x45541
|
|
|
382 |
*
|
|
|
383 |
* Input: flags - value of R0 on entry
|
|
|
384 |
* diagram - value of R1 on entry
|
|
|
385 |
* size - value of R2 on entry
|
|
|
386 |
* trfm - value of R3 on entry
|
|
|
387 |
* bbox - value of R4 on entry
|
|
|
388 |
*/
|
|
|
389 |
|
|
|
390 |
extern os_error *Drawfile_Bbox (drawfile_bbox_flags flags,
|
|
|
391 |
drawfile_diagram const *diagram,
|
|
|
392 |
int size,
|
|
|
393 |
os_trfm const *trfm,
|
|
|
394 |
wimp_box *bbox);
|
|
|
395 |
|
|
|
396 |
/* ------------------------------------------------------------------------
|
|
|
397 |
* Function: Drawfile_DeclareFonts()
|
|
|
398 |
*
|
|
|
399 |
* Description: Calls SWI 0x45542
|
|
|
400 |
*
|
|
|
401 |
* Input: flags - value of R0 on entry
|
|
|
402 |
* diagram - value of R1 on entry
|
|
|
403 |
* size - value of R2 on entry
|
|
|
404 |
*/
|
|
|
405 |
|
|
|
406 |
extern os_error *Drawfile_DeclareFonts (drawfile_declare_fonts_flags flags,
|
|
|
407 |
drawfile_diagram const *diagram,
|
|
|
408 |
int size);
|
|
|
409 |
|
|
|
410 |
/* ------------------------------------------------------------------------
|
|
|
411 |
* Function: Drawfile_CreateDiagram()
|
|
|
412 |
*
|
|
|
413 |
*/
|
|
|
414 |
|
|
|
415 |
extern os_error * Drawfile_CreateDiagram(drawfile_info *info, size_t memory,
|
|
|
416 |
const char *creator, wimp_box box);
|
|
|
417 |
|
|
|
418 |
extern os_error *Drawfile_AppendObject(drawfile_info *info, size_t memory,
|
|
|
419 |
const drawfile_object *object, BOOL rebind);
|
|
|
420 |
|
|
|
421 |
extern os_error *Drawfile_RenderDiagram(drawfile_info *info,
|
|
|
422 |
window_redrawblock *redraw, double scale);
|
|
|
423 |
|
|
|
424 |
extern os_error *Drawfile_VerifyDiagram(drawfile_info *info);
|
|
|
425 |
|
|
|
426 |
extern void Drawfile_QueryBox(drawfile_info *info,
|
|
|
427 |
wimp_box *rect, BOOL screenUnits);
|
|
|
428 |
|
|
|
429 |
#if defined(__cplusplus)
|
|
|
430 |
}
|
|
|
431 |
#endif /* __cplusplus */
|
|
|
432 |
|
|
|
433 |
#endif /* __drawfile.h */
|