[net.micro.mac] Info on MacDraw file format

weber@brand.UUCP (Allan G. Weber) (09/13/86)

I have seen some requests go by for information on the format of MacDraw
data files.  I deciphered some of the format while in the process of writing
a MacDraw to Impress program for printing MacDraw pictures on Imagen
printers.  The following is a files of notes I made on the format.  If
anybody can fill in the holes or find mistakes I would appreciate hearing
about it.

				Allan Weber
				Weber%Brand@USC-ECL
				...sdcrdcf!usc-oberon!brand!weber

-----------------------------

	MacDraw data file information

	Allan Weber (Weber@USC-ECLC)
	USC Signal and Image Processing Institute

	Last edit: 16-Dec-85

This file contains a description of the data records produced by "Macdraw
Version 1.7 3/18/85".  Some of the information in the data records has not
yet been deciphered and is indicated below by question marks.

Note:  Many of the data structures for points and rectangles use 4-byte
"fixed-point numbers" instead of the normal 2-byte integers.  Fixed-point
numbers are described in "Inside Macintosh", page MI-11.  They are similar
to integers with the addition of a 2-byte fractional part, thus yielding a
number with the same range but greater precision.


A MacDraw file starts with a 512 byte header.  There does not appear to be
any information in the header required for recreating the image on a device
like a laser printer.  

			File header (512 bytes)

Offset
0..213		?
214..229	Enclosing rectangle for entire drawing (Fixed-point)
230..511	?



After the file header is a sequence of data records, one for each object in
the image.  Each object data record starts with an 8-byte record header,
followed in most cases by varible-length object-dependent data.  The first
byte in each of the record headers indicates the type of object.  At the end
of the file is a terminator (type 0) record.


		       Record header (8 bytes)

Offset
0	code 	0 = terminator		1 = text
		2 = right angle vector	3 = sloped vector
		4 = rectangle		5 = round rectangle
		6 = ellipse		7 = arc
		8 = curve		9 = polygon
		10= group	       11 = PICT data (from MacPaint)
1	lock	0 = unlocked, 1 = locked
2	?
3	?
4	line	width code:  1 = 0 pixels, 2 = 1 pixel, 3 = 2 pixels,
		4 = 4 pixels, 5 = 6 pixels
5	pen	pattern number: 1..36
6	fill	pattern number: 1..36
7	special
		for vectors, the arrow type
		 0 = ------, 1 = ----->, 2 = <-----, 3 = <----->
		for round rectangles, the corner radius:
		1 = 0", 2 = 1/8, 3 = 3/16, 4 = 1/4, 5 = 5/16, 6 = 3/8
8..	An object-specific record (if any) follows after the header


	     Object Specific Data (follows record header)

		    0: Terminator record (0 bytes)

A terminator record is used to mark the end of the list of objects or
the end of a set of objects that have been grouped together.


	     1: Text record (20 bytes + length of string)

0..3	?
4	style	0 = plain, 1 = bold, 2 = italic, 4 = underline, 8 = hollow,
		16 = shadow
5	font	1 = Chicago, 2 = Geneva, 3 = New York, 4 = Monaco, 5 = Venice,
		6 = London, 7 = Athens
6	size	1 = 9 pt, 2 = 10 pt, 3 = 12 pt, 4 = 14 pt, 5 = 18 pt, etc.
7	spacing	1 = single, 2 = three halves, 3 = double
8	align	1 = left, 2 = center, 3 = right
9	angle	0 = normal		4 = flip horizontal
		1 = rotate right	5 = flip vertical
		2 = upsidedown		6 = rotate right and flip horizontal
		3 = rotate left		7 = rotate left and flip horizontal
10:11	Number of characters in text string
12:19	Rectangle enclosing text (Integer)
	(Note: the rectangle gives the location of the text BEFORE doing any
	rotating and/or flipping according to byte 9.)
20	Start of text string (not terminated with null)


		     2,3: Vector record (16 bytes)

0:7	Start point (Fixed-point)
8:15	End point (Fixed-point)


	    4,5,6: Rectangles and Ellipse record (16 bytes)

0:15	Rectangle enclosing object (Fixed-point)


		       7: Arc record (20 bytes)

0:15	Rectangle enclosing ellipse used to generate arc (Fixed-point)
16:17	Start angle (degrees)
18:19	Extent of arc (degrees)


	      8: Curve record (32 bytes + 2 bytes/point)

0..1	?
2:3	Number of bytes in rest of record
4:5	Number of points in curve including start point and ending null point
6:21	Rectangle enclosing curve (Fixed-point)
22	1 = make closed (add final point same as first point)
23	?
24:31	Start point (Fixed-point)
32	Start of X,Y increment pairs (2 bytes/pair), 2's complement,
	terminated by a pair of zero bytes.


	     9: Polygon record (24 bytes + 8 bytes/point)

0..1	?
2:3	Number of bytes in rest of record
4:5	Number of points in polygon
6:21	Rectangle enclosing curve (Fixed-point)
22	1 = make closed (add final point same as first point)
	2 = smoothed polygon
23	?
24	Start of list of points in the polygon (Fixed-point), 8 bytes/pnt


		      10: Group record (32 bytes)

A group record is used to indicate the beginning of a collection of objects
that have been grouped together using the Group command under the Arrange
menu.  The group contains all the following objects until a terminator 
record is encountered.

0:15	Rectangle enclosing all members in the group (Fixed-point)
16..31	?


			 11: PICT record (42+)

0..3	?
4:11	? Rectangle (Integer)
12:27	Rectangle enclosing picture (Fixed-point)
28..31	?
32:33	Width of picture in bytes
34:41	? Rectangle (Integer)
42..	Bitmap
-------------------------------------