SaveDraw 6.86 KB
Newer Older
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
/* Copyright 1997 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.
 */
/***************************************************/
/* File   : SaveDraw.h                             */
/*                                                 */
/* Purpose: Save a web page as a Draw file.        */
/*                                                 */
/* Author : Merlyn Kline for Customer browser;    */
/*          This source adapted by A.D.Hodgkinson  */
/*          including bits from RISC_OSLib.        */
/*                                                 */
/* History: 13-Nov-97: Created.                    */
/***************************************************/

/* General bits and pieces */

typedef enum
{
  draw_OBJFONTLIST = 0,
  draw_OBJTEXT     = 1,
  draw_OBJPATH     = 2,
  draw_OBJSPRITE   = 5,
  draw_OBJGROUP    = 6,
  draw_OBJTEXTAREA = 9,
37 38
  draw_OBJTEXTCOL  = 10,
  draw_OBJTEXTTRFM = 12
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
}
draw_tagtyp;

typedef int  draw_sizetyp;
typedef BBox draw_bboxtyp;
typedef int  draw_coltyp;

/* For paths */

typedef int draw_pathwidth;

typedef struct
{
  unsigned char joincapwind; /* 1 byte  */ /* bit 0..1 join         */
                                           /* bit 2..3 end cap      */
                                           /* bit 4..5 start cap    */
                                           /* bit 6    winding rule */
                                           /* bit 7    dashed       */
  unsigned char reserved8;   /* 1 byte  */
  unsigned char tricapwid;   /* 1 byte  */ /* 1/16th of line width */
  unsigned char tricaphei;   /* 1 byte  */ /* 1/16th of line width */
}
draw_pathstyle;

typedef enum
{
   draw_PathTERM  = 0, /* end of path                                   */
   draw_PathMOVE  = 2, /* move to (x,y), starts new subpath             */
   draw_PathLINE  = 8, /* line to (x,y)                                 */
   draw_PathCURVE = 6, /* bezier curve to (x3,y3) with 2 control points */
   draw_PathCLOSE = 5  /* close current subpath with a line             */
}
draw_path_tagtype;

/* For text */

typedef char draw_fontref;

typedef struct
{
  draw_fontref fontref;    /* 1 byte  */
  char         reserved8;  /* 1 byte  */
  short        reserved16; /* 2 bytes */
}
draw_textstyle;

typedef unsigned int draw_fontsize;

typedef struct
{
  int         typeface;   /* Index into fontname table */
  int         typesizex;
  int         typesizey;
  draw_coltyp textcolour; /* Text colour RGB */
  draw_coltyp background; /* Hint for anti-aliased printing RGB */
}
fontrec;


/* Path structure header item */

typedef struct
{
  draw_tagtyp     tag;         /* 1 word  */
  draw_sizetyp    size;        /* 1 word  */
  draw_bboxtyp    bbox;        /* 4 words */
  draw_coltyp     fillcolour;  /* 1 word  */
  draw_coltyp     pathcolour;  /* 1 word  */
  draw_pathwidth  pathwidth;   /* 1 word  */
  draw_pathstyle  pathstyle;   /* 1 word  */
}
draw_pathstrhdr;

/* Sprite header */

typedef struct
{
  draw_tagtyp  tag;  /* 1 word  */
  draw_sizetyp size; /* 1 word  */
  draw_bboxtyp bbox; /* 4 words */
}
draw_spristrhdr;

122
/* A line of text (maybe transformed) */
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

typedef struct
{
  int x;
  int y;
}
draw_objcoord;

typedef struct
{
  draw_tagtyp    tag;        /* 1 word  */
  draw_sizetyp   size;       /* 1 word  */
  draw_bboxtyp   bbox;       /* 4 words */
  draw_coltyp    textcolour; /* 1 word  */
  draw_coltyp    background; /* 1 word  */
  draw_textstyle textstyle;  /* 1 word  */
  draw_fontsize  fsizex;     /* 1 word, unsigned */
  draw_fontsize  fsizey;     /* 1 word, unsigned */
  draw_objcoord  coord;      /* 2 words */
}
draw_textstrhdr;

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
#define SaveDraw_FontFlags_Kerned      (1u<<0)
#define SaveDraw_FontFlags_RightToLeft (1u<<1)

typedef struct
{
  draw_tagtyp    tag;        /* 1 word  */
  draw_sizetyp   size;       /* 1 word  */
  draw_bboxtyp   bbox;       /* 4 words */
  int            matrix[6];
  unsigned int   fontflags;
  draw_coltyp    textcolour; /* 1 word  */
  draw_coltyp    background; /* 1 word  */
  draw_textstyle textstyle;  /* 1 word  */
  draw_fontsize  fsizex;     /* 1 word, unsigned */
  draw_fontsize  fsizey;     /* 1 word, unsigned */
  draw_objcoord  coord;      /* 2 words */
}
draw_trfmtextstrhdr;

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
/* File header */

typedef struct
{
  char         title[4];

  int          majorstamp;
  int          minorstamp;
  char         progident[12];

  draw_bboxtyp bbox;
}
draw_fileheader;

/* General header for graphic objects */

typedef struct
{
  draw_tagtyp  tag;  /* 1 word  */
  draw_sizetyp size; /* 1 word  */
  draw_bboxtyp bbox; /* 4 words */
}
draw_objhdr;

/* A font list */

typedef struct
{
  draw_tagtyp  tag;  /* 1 word  */
  draw_sizetyp size; /* 1 word  */
}
draw_fontliststrhdr;

typedef struct
{
  draw_tagtyp  tag;
  draw_sizetyp size;

  draw_fontref fontref;
  char         fontname[1]; /* String, null terminated */
}
draw_fontliststr;

/* For sprites */

typedef struct /* Format of a sprite header */
{
  int  next;      /*  Offset to next sprite                */
  char name[12];  /*  Sprite name                          */
  int  width;     /*  Width in words-1      (0..639)       */
  int  height;    /*  Height in scanlines-1 (0..255/511)   */
  int  lbit;      /*  First bit used (left end of row)     */
  int  rbit;      /*  Last bit used (right end of row)     */
  int  image;     /*  Offset to sprite image               */
  int  mask;      /*  Offset to transparency mask          */
  int  mode;      /*  Mode sprite was defined in           */
                  /*  Palette data optionally follows this */
                  /*  in memory                            */
}
sprite_header;

typedef struct
{
 int width;
 int height;
 int mask;
 int mode;
}
sprite_info;

/* We're going to fix scale factors for OS units and points */
/* to Draw units.                                           */

#define PTD(x) (((x)*16)/25) /* Convert millipoints to draw units */
#define OTD(x) ((x)*256)     /* Convert OS units to draw units    */

/* Some miscellaneous useful definitions */

#define DSIZE_FRECT (sizeof(draw_pathstrhdr)+5*12+4)
#define DSIZE_FTRIA (sizeof(draw_pathstrhdr)+4*12+4)

/* Function prototypes */

int               savedraw_write_bytes    (const char * s, unsigned int n);
int               savedraw_rectangle_fill (int x, int y, int w, int h, int c);

_kernel_oserror * savedraw_save_draw      (browser_data * b, const char * pathname, int bgimages);
int               savedraw_draw_size      (browser_data * b, int bgimages);