drawfobj 11.4 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/****************************************************************************
 * This source file was written by Acorn Computers Limited. It is part of   *
 * the RISCOS library for rendering RISCOS Draw files from applications     *
 * in C. It may be used freely in the creation of programs for Archimedes.  *
 * It should be used with Acorn's C Compiler Release 3 or later.            *
 *                                                                          *
 ***************************************************************************/

/*
 * Title:   drawfobj.h
 * Purpose: Processing of Draw format files (object level interface)
 *
 */

/*
 *
 * This file supplements the diagram level interface with routines for
 * dealing with individual objects.
 */

#ifndef __drawfobj_h
#define __drawfobj_h

#ifdef DRAWFILE_INTERNAL
#include "h.DrawIntern.drawcvttyp"
#else
/* Data types for specifying object details */
#ifndef __drawfdiag_h
#include "h.drawfdiag"
#endif
#ifndef __drawftypes_h
#include "h.drawftypes"
#endif
#endif

#ifndef BOOL
#define BOOL int
#define TRUE 1
#define FALSE 0
#endif



/******************************** DATA TYPES *******************************/

/*
 * Data type for specifying the full details of any object type.
 * It is used in operations on complete objects, such as creation
 * and querying, and so does not include the types needed for
 * contained structures and types, such as path elements or text
 * columns : those are defined in h.drawftypes.
 *
 */

typedef union
{
  draw_objhdr      *object;
  draw_fileheader  *fileHeader;
  draw_fontliststr *fontList;
  draw_textstr     *text;
  draw_pathstr     *path;
  draw_spristr     *sprite;
  draw_groustr     *group;
  draw_textareahdr *textarea;
  char             *bytep;
  int              *wordp;
} draw_objectType;



/* Symbolic code for no object */

#define draw_NoObject (draw_object)-1


/*
 * For functions that operate on a range of objects (and ONLY those
 * functions), the following special codes may be used to mean 'from the
 * start' and 'to the end'.
 *
 */

#define draw_FirstObject (draw_object)-1
#define draw_LastObject  (draw_object)-2



/********************************* Global data *****************************/
/* An array of 256 integers, used for font translation. Immediately after
 * a call to draw_createObject where the object was a font table, this
 * contains the mapping between old and new font reference numbers, such
 * that  transTable[old fontref] = new fontref.
 * draw_translateText makes use of this table; it is exported for
 * callers who may want to do something elaborate.
 */

extern int *draw_transTable;

/************************** Interface functions ****************************/


/* --------------------------- draw_create_diag ----------------------------
 * Description:   Create an empty diagram (ie. just the file header), with
 *                a given bounding box.
 *
 * Parameters:    draw_diag *diag -- pointer to store to hold diagram
 *                char *creator -- pointer to character string holding
 *                                 creator's name
 *                draw_box bbox -- the bounding box (in Draw units).
 * Returns:       void.
 * Other Info:    diag must point at sufficient memory to hold the diagram.
 *                The first 12 chars of creator are stored in the file
 *                header. diag.length is set appropriately by this function.
 *
 */

void draw_create_diag(draw_diag *diag, char *creator, draw_box bbox);


/* -------------------------- draw_doObjects -------------------------------
 * Description:   Render a specified range of objects from a diagram.
 *
 * Parameters:    draw_diag *diag -- the diagram
 *                draw_object start -- start of range of objects to be
 *                                     rendered
 *                draw_object end   -- end of range of objects to be rendered
 *                draw_redrawstr *r -- WIMP-style redraw rectangle
 *                double scale -- the scale factor for rendering
 *                draw_error *error -- possible error condition.
 * Returns:       TRUE if render was successful.
 * Other Info:    Parameters (except range) are used as in draw_render_diag,
 *                in diagram level module.
 *                The diagram must be verified before a call to this function
 *                If the range of objects inclues text with anti-aliasing
 *                fonts, you MUST call draw_setFontTable first.
 *                Very small (<0.00009) or negative scale factors will cause
 *                run-time errors.
 *
 */

BOOL draw_doObjects(draw_diag *diag, draw_object start, draw_object end,
                    draw_redrawstr *r, double scale, draw_error *error);


/* -------------------------- draw_setFontTable ----------------------------
 * Description:   Scans a diagram for a font table object and records it for
 *                a subsequent call of draw_doObjects.
 *
 * Parameters:    draw_diag *diag -- the diagram to be scanned.
 * Returns:       void.
 * Other Info:    This function must be called for draw_doObjects to work on
 *                a sequence of objects that includes text objects using
 *                anti-aliasing fonts, but no font table object. The font
 *                table remains valid until either a different one is
 *                encountered during a call to draw_doObjects, or until
 *                draw_render_diag is called, or until a different diagram
 *                is rendered.
 *
 */

void draw_setFontTable(draw_diag *diag);


/* -------------------------- draw_verifyObject ----------------------------
 * Description:   Verify the data for an existing object in a diagram
 *
 * Parameters:    draw_diag *diag -- the diagram
 *                draw_object object -- the object to be verified
 *                int *size -- gets set to the amount of memory occupied by
 *                             the object.
 *                draw_error *error -- possible error condition.
 * Returns:       TRUE if object found and verified.
 * Other Info:    Verifying an object ensures that its bounding box is
 *                consistent with the data in it; if not, no error is
 *                reported, but the box is made consistent, On an error, the
 *                location is relative to the start of the diagram.
 *                Note: the object's size is only returned if "size" is a
 *                non-null pointer.
 *
 */

BOOL draw_verifyObject(draw_diag *diag, draw_object object, int *size,
                       draw_error *error);


/* -------------------------- draw_createObject ----------------------------
 * Description:   Creates an object after a specified object in a given
 *                diagram.
 *
 * Parameters:    draw_diag *diag -- the diagram
 *                draw_objectType newObject -- the created object
 *                draw_object after -- the object after which the new object
 *                                     should be created
 *                BOOL rebind -- if TRUE, the bounding box of the diagram is
 *                               updated to the union of its existing value
 *                               and that of the new object
 *                draw_object *object -- new object's handle
 *                draw_error *error -- possible error condition
 * Returns:       TRUE if object was created OK
 * Other Info:    All data after the insertion point is moved down. "after"
 *                may be set to draw_FirstObject/draw_LastObject for
 *                inserting at the start/end of the diagram.
 *                Diagram must be large enough for the new data; its length
 *                field is updated.
 *                On an error, the location is not meaningful.
 *                The handle of the new object is returned in "object"
 *                If this function is used to create a font table, "after"
 *                is ignored, and the object merged with the existing one
 *                (if such exists) or inserted at the start of the diagram
 *                otherwise.  This can cause the font reference numbers to
 *                change; if a call to this function is followed by a
 *                draw_translateText(), the font change will be applied (only
 *                needed when anti-aliased fonts are used in text objects.
 *
 */

BOOL draw_createObject(draw_diag *diag, draw_objectType newObject,
                       draw_object after, BOOL rebind, draw_object *object,
                       draw_error *error);


/* ---------------------------- draw_deleteObjects -------------------------
 * Description:   Deletes the specified range of objects from a diagram.
 *
 * Parameters:    draw_diag *diag -- the diagram
 *                draw_object start -- start of range of objects to be
 *                                     deleted
 *                draw_object end   -- end of range of objects to be deleted
 *                BOOL rebind -- if set to TRUE, then the diagram's bounding
 *                               box will be set to the union of those
 *                               remaining objects
 *                draw_error *error -- possible error condition.
 * Returns:       TRUE if objects deleted successfully.
 * Other Info:    diag.length is updated appropriately.
 *
 */

BOOL draw_deleteObjects(draw_diag *diag, draw_object start, draw_object end,
                        BOOL rebind, draw_error *error);


/* ----------------------- draw_extractObject ------------------------------
 * Description:   Extracts an object from a diagram into a supplied buffer
 *
 * Parameters:    draw_diag *diag -- the diagram
 *                draw_object object -- the object to be extracted
 *                draw_objectType result -- pointer to the buffer
 *                draw_error *error -- possible error division
 * Returns:       TRUE if the object was extracted successfully.
 * Other Info:    The buffer for the result must be large enough to hold
 *                the extracted object (an object's size can be ascertained
 *                by calling draw_verifyObject()).
 *
 */

BOOL draw_extractObject(draw_diag *diag, draw_object object,
                        draw_objectType result, draw_error *error);


/* -------------------------- draw_translateText ---------------------------
 * Description:   Updates all font reference numbers for text objects
 *                following creation of a font table.
 *
 * Parameters:    draw_diag *diag -- the diagram.
 * Returns:       void.
 * Other Info:    If the font table has not been changed then this function
 *                does nothing.
 *
 */

void draw_translateText(draw_diag *diag);


/* -------------------------- drawfobj_init --------------------------------
 * Description:   Initialise the object level interface
 *
 * Parameters:    void
 * Returns:       TRUE if all went OK.
 * Other Info:    none
 *
 */

BOOL drawfobj_init(void);

#endif

/* end drawfobj.h */