home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 418.lha / DR2D_format / DR2D.txt < prev    next >
Text File  |  1990-08-31  |  12KB  |  436 lines

  1. 90/08/24
  2.  
  3. The following is the format of the DR2D IFF FORM file produced
  4. by ProVector, a 2-dimensional structured graphics program.
  5. Each chunk is described by first giving the chunk ID (both in
  6. ASCII and in hex) and then giving the structure associated with
  7. the chunk, as well as any extra definitions that make sense.
  8. Coordinates are specified in IEEE format (see note 1 for a
  9. description of the IEEE format).  It is assumed that these
  10. 'drawings' are on white 'paper'.
  11.  
  12.  
  13. FORM (0x464F524D)    /* All drawings are a FORM */
  14.  
  15.     struct FORMstruct {
  16.         ULONG    ID;
  17.         ULONG    Size;        /* Total size of the file    */
  18.     };
  19.  
  20.  
  21. DR2D (0x44523244)    /* ID of 2D drawing */
  22.  
  23.  
  24. DRHD (0x44524844)    /* Drawing header */
  25.  
  26.     struct DRHDstruct {
  27.         ULONG    ID;
  28.         ULONG    Size;        /* Always 18 */
  29.         IEEE    XLeft, YTop,
  30.             XRight, YBot;
  31.     };
  32.  
  33.     /* The point [XLeft,YTop] defines the virtual coordinates of the
  34.        upper left corner of the project.  The point [XRight,YBot]
  35.        defines the virtual coordinates of the lower right corner of
  36.        the project.  If XLeft < XRight, the X-axis increases toward
  37.        the right.  If YTop < YBot, the Y-axis increases toward the
  38.        bottom.  Other combinations are possible; for example, in
  39.        Cartesian coordinates, XLeft would be less than XRight but
  40.        YTop would be GREATER than YBot. */
  41.  
  42. /* The following are global project properties */
  43.  
  44. PPRF (0x50505249)    /* Page preferences */
  45.  
  46.     struct PPRFstruct {
  47.         ULONG    ID;
  48.         ULONG    Size;
  49.         char    Prefs[Size];
  50.     };
  51.  
  52.     /* The Prefs are a list of null-terminated strings.  The
  53.        currently supported strings are:
  54.  
  55.         Units=<unit-type>
  56.         Portrait=<boolean>
  57.         PageType=<page-type>
  58.         GridSize=<number>
  59.  
  60.        where:
  61.  
  62.         <unit-type>    is one of Inch, Cm, or Pica
  63.         <boolean>    is one of True or False
  64.         <page-type>    is one of Standard, Legal, B4, B5,
  65.                 A3, A4, A5, or Custom
  66.         <number>    is a floating-point number
  67.  
  68.        It is not required that programs understand this chunk;
  69.        it is mostly for the convenience of ProVector.
  70.     */
  71.  
  72. CMAP (0x434D4150)    /* Color map */    /* Same as ILBM CMAP */
  73.  
  74.     struct CMAPstruct {
  75.         ULONG    ID;
  76.         ULONG    Size;
  77.         UBYTE    ColorMap[Size];
  78.     };
  79.  
  80.  
  81. FONS (0x464F4E53)    /* Font for text */    /* Same as FTXT.FONS */
  82.  
  83.     struct FONSstruct {
  84.         ULONG    ID;
  85.         ULONG    Size;
  86.         UBYTE    FontID;            /* ID it's called */
  87.         UBYTE    Pad1;            /* Always 0 */
  88.         UBYTE    Proportional;        /* Is it proportional? */
  89.         UBYTE    Serif;            /* Has it serifs? */
  90.         CHAR    Name[Size-4];        /* The name of the font */
  91.     };
  92.  
  93.  
  94. DASH (0x44415348)    /* Line dash pattern for edges */
  95.  
  96.     struct DASHstruct {
  97.         ULONG    ID;
  98.         ULONG    Size;
  99.         USHORT    DashID;            /* Name of the dash pattern */
  100.         USHORT    NumDashes;        /* Should always be even */
  101.         IEEE    Dashes[NumDashes];    /* On-off pattern */
  102.     };
  103.  
  104.     /* The numbers in the dash patterns are relative to the line
  105.        weight.  The dash pattern {1.0,0.0} will always yield
  106.        a dotted line with the dots as long as they are tall.
  107.        By convention, DashID 0 is reserved to mean 'No line pattern
  108.        at all', i.e. the edges are invisible.  This DASH pattern
  109.        should NOT appear in a DR2D FORM.  Again by convention, a
  110.        NumDashes of 0 means that the line is solid. */
  111.  
  112.  
  113. AROW (0x41524F57)    /* An arrow-head pattern */
  114.  
  115.     #define ARROW_FIRST    0x01    /* Draw an arrow on the first point */
  116.     #define ARROW_LAST    0x02    /* Draw an arrow on the last point */
  117.  
  118.     struct AROWstruct {
  119.         ULONG    ID;
  120.         ULONG    Size;
  121.         UBYTE    Flags;        /* Flags, from ARROW_*, above */
  122.         UBYTE    Pad0;        /* Should always 0 */
  123.         USHORT    ArrowID;    /* Name of the arrow head */
  124.         USHORT    NumPoints;
  125.         IEEE    ArrowPoints[NumPoints]; /* See note 2 */
  126.     };
  127.  
  128.     /* The ArrowPoints are the points of a CPLY in the SAME coordinate
  129.        system as the rest of the project.  Note that the (0,0) point
  130.        of the coordinate system coincides with the appropriate endpoint
  131.        of the OPLY that this arrow is attached to.  The arrow head should
  132.        be drawn facing right, so that the appropriate rotation may be
  133.        applied to it before rendering. */
  134.  
  135.        
  136. FILL (0x46494C4C)    /* Object-oriented fill pattern */
  137.                 /* See note 3 */
  138.  
  139.     struct FILLstruct {
  140.         ULONG    ID;
  141.         ULONG    Size;
  142.         USHORT    FillID;        /* ID of the fill */
  143.     };
  144.  
  145.  
  146. LAYR (0x4C415952)    /* Define a layer */
  147.  
  148.     #define LF_ACTIVE    0x01    /* Active for editing */
  149.     #define LF_DISPLAYED    0x02    /* Displayed on the screen */
  150.  
  151.     struct LAYRstruct {
  152.         ULONG    ID;
  153.         ULONG    Size;
  154.         USHORT    LayerID;    /* ID of the layer */
  155.         char    LayerName[16];    /* Null terminated and padded */
  156.         UBYTE    Flags;        /* Flags, from LF_*, above */
  157.         UBYTE    Pad0;        /* Always 0 */
  158.     };
  159.  
  160.  
  161. /* The following sets object attributes for the next object(s).  The
  162.    attributes are in effect until the next ATTR chunk is found, or
  163.    until the end of the enclosing FORM, whichever comes first. */
  164.  
  165. ATTR (0x41545452)    /* Object attributes */
  166.  
  167.     /* Various fill types */
  168.     #define FT_NONE        0    /* No fill            */
  169.     #define FT_COLOR    1    /* Fill with color from palette */
  170.     #define FT_OBJECTS    2    /* Fill with tiled objects    */
  171.  
  172.     /* Join types */
  173.     #define JT_NONE        0    /* Don't do line joins */
  174.     #define JT_MITER    1    /* Mitered join */
  175.     #define JT_BEVEL    2    /* Beveled join */
  176.     #define JT_ROUND    3    /* Round join */
  177.  
  178.     struct ATTRstruct {
  179.         ULONG    ID;
  180.         ULONG    Size;
  181.         UBYTE    FillType;    /* One of FT_*, above    */
  182.         UBYTE    JoinType;    /* One of JT_*, above    */
  183.         UBYTE    EdgePattern;    /* ID of edge dash pattern*/
  184.         UBYTE    ArrowHeads;    /* ID of arrowhead to use */
  185.         USHORT    FillValue;    /* Color or object with which to fill */
  186.         USHORT    EdgeValue;    /* Edge color index    */
  187.         USHORT    WhichLayer;    /* ID of layer it's in    */
  188.         IEEE    EdgeThick;    /* Line width        */
  189.     };
  190.  
  191. BBOX (0x42424F48)    /* Bounding box of the next object in the FORM */
  192.  
  193.     struct BBOXstruct {
  194.         ULONG    ID;
  195.         ULONG    Size;
  196.         IEEE    XMin, YMin,    /* Bounding box of obj. */
  197.             XMax, YMax;    /* including line width    */
  198.     };
  199.  
  200.     /* This chunk is ONLY in effect for the NEXT object in the FORM.
  201.        Note that a BBOX may apply to a FILL or an AROW. */
  202.  
  203. /* The following are object definitions */
  204.  
  205. VBM  (0x56424D20)    /* Virtual BitMap */
  206.  
  207. struct VBMstruct {
  208.     IEEE        XPos, YPos,        /* Virtual coords */
  209.             XSize, YSize,        /* Virtual size */
  210.             Rotation;        /* Ignored for now... */
  211.     USHORT        PathLen;        /* Length of dir path */
  212.     char        Path[PathLen];        /* Null-terminated path of file */
  213. };
  214.  
  215. CPLY (0x43504C59)    /* Closed polygon */
  216. OPLY (0x4F504C59)    /* Open polygon, i.e. line segments */
  217.  
  218.     struct POLYstruct {
  219.         ULONG    ID;
  220.         ULONG    Size;
  221.         USHORT    NumPoints;
  222.         IEEE    PolyPoints[2*NumPoints]; /* See note 2 */
  223.     };
  224.  
  225.  
  226.  
  227. GRUP (0x47525550)    /* Group */    /* See note 3 */
  228.  
  229.     struct GROUPstruct {
  230.         ULONG    ID;
  231.         ULONG    Size;
  232.         USHORT    NumObjs;
  233.     };
  234.  
  235.     /* NOTE that for GRUPs, the Layer information of the GRUP
  236.        FORM overrides the Layer information of the nested objects. */
  237.  
  238. STXT (0x53545854)        /* Simple text */
  239.  
  240.     struct STXTstruct {
  241.         ULONG    ID;
  242.         ULONG    Size;
  243.         UBYTE    Pad0;        /* Always 0 (for future expansion) */
  244.         UBYTE    WhichFont;    /* Which font to use */
  245.         IEEE    CharW, CharH,    /* W/H of an individual char */
  246.             BaseX, BaseY,    /* Start of baseline */
  247.             Rotation;    /* Angle of text (in radians) */
  248.         USHORT    NumChars;
  249.         char    TextChars[NumChars];
  250.     };
  251.  
  252. TPTH (0x54505448)        /* A text string along a path */
  253.  
  254.     struct TPTHstruct {
  255.         ULONG    ID;
  256.         ULONG    Size;
  257.         UBYTE    Pad0;        /* Always 0 (for future expansion) */
  258.         UBYTE    WhichFont;    /* Which font to use */
  259.         IEEE    CharW, CharH;    /* W/H of an individual char    */
  260.         USHORT    NumChars;    /* Number of chars in the string */
  261.         USHORT    NumPoints;    /* Number of points in the path */
  262.         char    TextChars[NumChars];    /* PAD TO EVEN #! */
  263.         IEEE    Path[2*NumPoints]; /* The path on which the text lies */
  264.     };
  265.  
  266.  
  267. NOTE 1:    IEEE represents a single-precision IEEE floating point number.
  268.     These numbers consist of 32 bits, arranged as follows:
  269.  
  270.     +---------------+---------------+---------------+---------------+
  271.     |s e e e e e e e|e m m m m m m m|m m m m m m m m|m m m m m m m m|
  272.     +---------------+---------------+---------------+---------------+
  273.      31          24 23           16 15            8 7             0
  274.     
  275.     where
  276.         s    is the sign bit of the entire number.  If this
  277.             bit is '1', the number is negative.  If '0',
  278.             the number is positive.
  279.         e    is the 8-bit exponent, in excess-127 form.
  280.             This is the power of two to which the mantissa
  281.             should be raised before using the number
  282.             in calculations.  Excess-127 means that
  283.             127 is added to the exponent before packing
  284.             it into the number. An exponent of 0 here means
  285.             the real exponent is actually -127.  A value
  286.             of 127 means the exponent is actually 0.
  287.             A value of 255 means the exponenent is actually
  288.             128.
  289.         m    is the 23-bit mantissa.  A leading binary
  290.             1 is assumed.  This means that the mantissa
  291.             may vary from 1.0000000 to 1.999999...
  292.     
  293.     The value 0.0000000 is represented by all bits being cleared
  294.     to zero.  Note that on many computers, the natural format
  295.     of single-precision floating point numbers *IS* IEEE.  This
  296.     is true of the Amiga.  There are system calls to transform
  297.     IEEE numbers to and from Motorola FFP numbers, should your
  298.     application require them.
  299.  
  300.  
  301. NOTE 2: The algorithm for drawing polygons is as follows:
  302.  
  303.     typedef union {
  304.         IEEE num;
  305.         LONG bits;
  306.     } Coord;
  307.  
  308.     #define INDICATOR    0xFFFFFFFF
  309.     #define IND_CURVE    0x00000001
  310.     #define IND_MOVETO    0x00000002
  311.  
  312.     Coord    Temp0, Temp1;
  313.     int    FirstPoint, i, Increment;
  314.  
  315.     /* Initialize the path */
  316.     NewPath();
  317.     FirstPoint = 1;
  318.  
  319.     /* Draw the path */
  320.     i = 0;
  321.     while( i < NumPoints ) {
  322.         Temp0.num = PolyPoints[2*i];    Temp1.num = PolyPoints[2*i + 1];
  323.         if( Temp0.bits == INDICATOR ) {
  324.         /* Increment past the indicator */
  325.         Increment = 1;
  326.         if( Temp1.bits & IND_MOVETO ) {
  327.             /* Close and fill, if appropriate */
  328.             if( ID == CPLY ) {
  329.             FillPath();
  330.             }
  331.             else {
  332.             StrokePath();
  333.             }
  334.  
  335.             /* Set up the new path */
  336.             NewPath();
  337.             FirstPoint = 1;
  338.         }
  339.         if( Temp1.bits & IND_CURVE ) {
  340.             /* The next 4 points are Bezier cubic control points */
  341.             if( FirstPoint )
  342.             MoveTo(    PolyPoints[2*i + 2], PolyPoints[2*i + 3] );
  343.             else
  344.             LineTo(    PolyPoints[2*i + 2], PolyPoints[2*i + 3] );
  345.             CurveTo(    PolyPoints[2*i + 4], PolyPoints[2*i + 5],
  346.                 PolyPoints[2*i + 6], PolyPoints[2*i + 7],
  347.                 PolyPoints[2*i + 8], PolyPoints[2*i + 9] );
  348.             FirstPoint = 0;
  349.             /* Increment past the control points */
  350.             Increment += 4;
  351.         }
  352.         }
  353.         else {
  354.         if( FirstPoint )
  355.             MoveTo(    PolyPoints[2*i], PolyPoints[2*i + 1] );
  356.         else
  357.             LineTo(    PolyPoints[2*i], PolyPoints[2*i + 1] );
  358.         FirstPoint = 0;
  359.  
  360.         /* Increment past the last endpoint */
  361.         Increment = 1;
  362.         }
  363.  
  364.         /* Add the increment */
  365.         i += Increment;
  366.     }
  367.  
  368.     /* Close the last path */
  369.     if( ID == CPLY ) {
  370.         FillPath();
  371.     }
  372.     else {
  373.         StrokePath();
  374.     }
  375.  
  376.     Fills are according to the even-odd rule, so 'holes' in polygons
  377.     are easy to create (desirable in many cases).  Most objects produced
  378.     by ProVector (polygons, smoothed polygons, ellipses, rectangles,
  379.     and even the rendering of indivdiual characters in fonts) are
  380.     represented by this form.
  381.  
  382.  
  383. NOTE 3: FILL and GRUP chunks are ONLY valid inside nested
  384.     DR2D FORMs.  Here is an example:
  385.  
  386.     FORM { DR2D        /* Top-level drawing... */
  387.         DRHD { ... }    /* Confirmed by presence of DRHD chunk */
  388.         CMAP { ... }    /* Various other things... */
  389.         FONS { ... }
  390.         FORM { DR2D        /* A nested form... */
  391.             FILL { 1 }    /* Ah!  The fill-pattern table */
  392.             CPLY { ... }    /* with only 1 object */
  393.         }
  394.         FORM { DR2D        /* Yet another nested form */
  395.             GRUP { ..., 3 }    /* Ah! A group of 3 objects */
  396.             TEXT { ... }
  397.             CPLY { ... }
  398.             OPLY { ... }
  399.         }
  400.         FORM { DR2D        /* Still another nested form */
  401.             GRUP { ..., 2 }    /* A GRUP with 2 objects */
  402.             OPLY { ... }
  403.             TEXT { ... }
  404.         }
  405.     }
  406.  
  407.     All OBJECTS (i.e. CPLY, OPLY, TEXT, FORM { DR2D GRUP }, etc.)
  408.     are allowed inside these nested FORMs, but global drawing
  409.     attributes (i.e. CMAP, FILL, etc.) are not.
  410.  
  411.  
  412. Here is a (symbolic) DR2D form:
  413.  
  414.     FORM { DR2D
  415.         DRHD { 0.0, 0.0, 10.0, 8.0 }
  416.         CMAP { 0,0,0, 255,255,255 }
  417.         FONS { 1, 0, 1, 0, "Roman" }
  418.         DASH { 1, 2, {1.0, 1.0} }
  419.         ATTR { 0, 0, 0, 0, 0, 0, 0, 0.0 }
  420.         BBOX { 2.0, 2.0, 8.0, 6.0 }
  421.         FORM { DR2D
  422.             GRUP { 2 }
  423.             BBOX { 3.0, 4.0, 7.0, 5.0 }
  424.             TEXT { 1, 0.5, 1.0, 3.0, 5.0, 0.0, 12, "Hello, World" }
  425.             BBOX { 2.0, 2.0, 8.0, 6.0 }
  426.             OPLY { 5, {2.0,2.0, 8.0,2.0, 8.0,6.0, 2.0,6.0, 2.0,2.0 }
  427.         }
  428.     }
  429.  
  430. This picture should look something like this:
  431.  
  432.         .................
  433.         .        .
  434.         . Hello, World! .
  435.         .................
  436.