summaryrefslogtreecommitdiff
path: root/cd/src/drv/cddxf.c
diff options
context:
space:
mode:
Diffstat (limited to 'cd/src/drv/cddxf.c')
-rwxr-xr-xcd/src/drv/cddxf.c206
1 files changed, 197 insertions, 9 deletions
diff --git a/cd/src/drv/cddxf.c b/cd/src/drv/cddxf.c
index db05978..c5d0df5 100755
--- a/cd/src/drv/cddxf.c
+++ b/cd/src/drv/cddxf.c
@@ -9,6 +9,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
+
#include "cd.h"
#include "cd_private.h"
#include "cddxf.h"
@@ -182,6 +183,123 @@ static void writepolyf (cdCtxCanvas *ctxcanvas, cdfPoint *poly, int nv) /* write
fprintf ( ctxcanvas->file, "SEQEND\n" );
}
+static void writehatch (cdCtxCanvas *ctxcanvas, cdPoint *poly, int nv) /* write polygon */
+{
+ int i;
+
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "HATCH\n" );
+ fprintf ( ctxcanvas->file, "8\n" );
+ fprintf ( ctxcanvas->file, "%d\n", ctxcanvas->layer); /* current layer */
+ fprintf ( ctxcanvas->file, "62\n" );
+ fprintf ( ctxcanvas->file, "%d\n", ctxcanvas->fgcolor );
+
+ fprintf ( ctxcanvas->file, "10\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "20\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "30\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+
+ fprintf ( ctxcanvas->file, "210\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "220\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "230\n" );
+ fprintf ( ctxcanvas->file, "1.0\n" );
+
+ fprintf ( ctxcanvas->file, "2\n" );
+ fprintf ( ctxcanvas->file, "SOLID\n" );
+ fprintf ( ctxcanvas->file, "70\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+ fprintf ( ctxcanvas->file, "71\n" );
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "91\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+
+ fprintf ( ctxcanvas->file, "92\n" );
+ fprintf ( ctxcanvas->file, "2\n" );
+ fprintf ( ctxcanvas->file, "72\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+
+ fprintf ( ctxcanvas->file, "73\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+ fprintf ( ctxcanvas->file, "93\n" ); /* entire polygon line width */
+ fprintf ( ctxcanvas->file, "%d\n", nv );
+ for ( i=0; i<nv; i++ )
+ {
+ fprintf ( ctxcanvas->file, "10\n" );
+ fprintf ( ctxcanvas->file, "%f\n", poly[i].x/ctxcanvas->canvas->xres );
+ fprintf ( ctxcanvas->file, "20\n" );
+ fprintf ( ctxcanvas->file, "%f\n", poly[i].y/ctxcanvas->canvas->xres );
+ }
+
+ fprintf ( ctxcanvas->file, "97\n" );
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "75\n" );
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "76\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+}
+
+static void writehatchf (cdCtxCanvas *ctxcanvas, cdfPoint *poly, int nv) /* write polygon */
+{
+ int i;
+
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "HATCH\n" );
+ fprintf ( ctxcanvas->file, "8\n" );
+ fprintf ( ctxcanvas->file, "%d\n", ctxcanvas->layer); /* current layer */
+ fprintf ( ctxcanvas->file, "62\n" );
+ fprintf ( ctxcanvas->file, "%d\n", ctxcanvas->fgcolor );
+
+ fprintf ( ctxcanvas->file, "10\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "20\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "30\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+
+ fprintf ( ctxcanvas->file, "210\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "220\n" );
+ fprintf ( ctxcanvas->file, "0.0\n" );
+ fprintf ( ctxcanvas->file, "230\n" );
+ fprintf ( ctxcanvas->file, "1.0\n" );
+
+ fprintf ( ctxcanvas->file, "2\n" );
+ fprintf ( ctxcanvas->file, "SOLID\n" );
+ fprintf ( ctxcanvas->file, "70\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+ fprintf ( ctxcanvas->file, "71\n" );
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "91\n" ); /* entire polygon line width */
+ fprintf ( ctxcanvas->file, "1\n" );
+
+ fprintf ( ctxcanvas->file, "92\n" );
+ fprintf ( ctxcanvas->file, "2\n" );
+ fprintf ( ctxcanvas->file, "72\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+
+ fprintf ( ctxcanvas->file, "73\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+ fprintf ( ctxcanvas->file, "93\n" ); /* entire polygon line width */
+ fprintf ( ctxcanvas->file, "%d\n", nv );
+ for ( i=0; i<nv; i++ )
+ {
+ fprintf ( ctxcanvas->file, "10\n" );
+ fprintf ( ctxcanvas->file, "%f\n", poly[i].x/ctxcanvas->canvas->xres );
+ fprintf ( ctxcanvas->file, "20\n" );
+ fprintf ( ctxcanvas->file, "%f\n", poly[i].y/ctxcanvas->canvas->xres );
+ }
+ fprintf ( ctxcanvas->file, "97\n" );
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "75\n" );
+ fprintf ( ctxcanvas->file, "0\n" );
+ fprintf ( ctxcanvas->file, "76\n" );
+ fprintf ( ctxcanvas->file, "1\n" );
+}
+
static void deflines (cdCtxCanvas *ctxcanvas) /* define lines */
{
int i, j;
@@ -323,6 +441,17 @@ static void cdflush (cdCtxCanvas *ctxcanvas)
/*==========================================================================*/
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
{
+ if (mode == CD_BEZIER)
+ {
+ cdSimPolyBezier(ctxcanvas->canvas, poly, n);
+ return;
+ }
+ if (mode == CD_PATH)
+ {
+ cdSimPolyPath(ctxcanvas->canvas, poly, n);
+ return;
+ }
+
if (mode == CD_CLOSED_LINES || mode == CD_FILL)
{
poly[n].x = poly[0].x;
@@ -330,7 +459,10 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
n++;
}
- writepoly (ctxcanvas, poly, n); /* write polygon */
+ if( mode == CD_FILL )
+ writehatch (ctxcanvas, poly, n); /* write fill area */
+ else
+ writepoly (ctxcanvas, poly, n); /* write polygon */
}
static void cdline (cdCtxCanvas *ctxcanvas, int x1, int y1, int x2, int y2)
@@ -344,7 +476,7 @@ static void cdline (cdCtxCanvas *ctxcanvas, int x1, int y1, int x2, int y2)
writepoly (ctxcanvas, line, 2); /* draw line as a polygon */
}
-static void cdboxrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
+static void cdrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
cdPoint rect[5]; /* uses new array of points to avoid */
@@ -361,8 +493,36 @@ static void cdboxrect(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int
writepoly (ctxcanvas, rect, 5); /* draw box as a polygon */
}
+static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
+{
+ cdPoint rect[5]; /* uses new array of points to avoid */
+
+ rect[0].x = xmin;
+ rect[0].y = ymin;
+ rect[1].x = xmin;
+ rect[1].y = ymax;
+ rect[2].x = xmax; /* box edges */
+ rect[2].y = ymax;
+ rect[3].x = xmax;
+ rect[3].y = ymin;
+ rect[4].x = xmin;
+ rect[4].y = ymin;
+ writehatch (ctxcanvas, rect, 5); /* write fill area */
+}
+
static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
{
+ if (mode == CD_BEZIER)
+ {
+ cdfSimPolyBezier(ctxcanvas->canvas, poly, n);
+ return;
+ }
+ if (mode == CD_PATH)
+ {
+ cdfSimPolyPath(ctxcanvas->canvas, poly, n);
+ return;
+ }
+
if (mode == CD_CLOSED_LINES || mode == CD_FILL)
{
poly[n].x = poly[0].x;
@@ -370,7 +530,10 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
n++;
}
- writepolyf (ctxcanvas, poly, n); /* write polygon */
+ if( mode == CD_FILL )
+ writehatchf (ctxcanvas, poly, n); /* write fill area */
+ else
+ writepolyf (ctxcanvas, poly, n); /* write polygon */
}
static void cdfline (cdCtxCanvas *ctxcanvas, double x1, double y1, double x2, double y2)
@@ -384,7 +547,7 @@ static void cdfline (cdCtxCanvas *ctxcanvas, double x1, double y1, double x2, do
writepolyf (ctxcanvas, line, 2); /* draw line as a polygon */
}
-static void cdfboxrect(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
+static void cdfrect(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
{
cdfPoint rect[5]; /* uses new array of points to avoid */
@@ -401,6 +564,23 @@ static void cdfboxrect(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double
writepolyf (ctxcanvas, rect, 5); /* draw box as a polygon */
}
+static void cdfbox(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
+{
+ cdfPoint rect[5]; /* uses new array of points to avoid */
+
+ rect[0].x = xmin;
+ rect[0].y = ymin;
+ rect[1].x = xmin;
+ rect[1].y = ymax;
+ rect[2].x = xmax; /* box edges */
+ rect[2].y = ymax;
+ rect[3].x = xmax;
+ rect[3].y = ymin;
+ rect[4].x = xmin;
+ rect[4].y = ymin;
+ writehatchf (ctxcanvas, rect, 5); /* write fill area */
+}
+
/*--------------------------------------------------------------------------*/
/* gives radius of the circle most resembling elliptic arc at angle t */
/*--------------------------------------------------------------------------*/
@@ -503,6 +683,7 @@ static void cdarc (cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double
bulge = calc_bulge (a, b, t, t+seg_angle); /* and t+seg_angle and write */
writevertex (ctxcanvas, xc, yc, a, b, t, bulge); /* vertex at t */
}
+
writevertex (ctxcanvas, xc, yc, a, b, t2, 0); /* bulge of last vertex is useless */
fprintf ( ctxcanvas->file, "0\n" );
@@ -551,12 +732,15 @@ static void cdsector (cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doub
if ((a2-a1) != 360)
writevertex (ctxcanvas, xc, yc, 0, 0, 0, 0); /* center */
+
for (i=0, t=t1; i<nseg; i++, t+=seg_angle)
{ /* calculate bulge between t */
bulge = calc_bulge (a, b, t, t+seg_angle); /* and t+seg_angle and write */
writevertex (ctxcanvas, xc, yc, a, b, t, bulge); /* vertex at t */
}
+
writevertex (ctxcanvas, xc, yc, a, b, t2, 0); /* bulge of last vertex is useless */
+
if ((a2-a1) != 360)
writevertex (ctxcanvas, xc, yc, 0, 0, 0, 0); /* center */
@@ -1066,6 +1250,10 @@ static void cdcreatecanvas(cdCanvas* canvas, void *data)
fprintf (ctxcanvas->file, "SECTION\n"); /* header maker */
fprintf (ctxcanvas->file, "2\n");
fprintf (ctxcanvas->file, "HEADER\n");
+ fprintf (ctxcanvas->file, " 9\n");
+ fprintf (ctxcanvas->file, "$ACADVER\n");
+ fprintf (ctxcanvas->file, " 1\n");
+ fprintf (ctxcanvas->file, "AC1006\n"); /* AutoCad R10 */
fprintf (ctxcanvas->file, "9\n");
fprintf (ctxcanvas->file, "$LIMCHECK\n");
fprintf (ctxcanvas->file, "70\n");
@@ -1142,12 +1330,12 @@ static void cdinittable(cdCanvas* canvas)
canvas->cxPixel = cdpixel;
canvas->cxLine = cdline;
canvas->cxPoly = cdpoly;
- canvas->cxRect = cdboxrect;
- canvas->cxBox = cdboxrect;
+ canvas->cxRect = cdrect;
+ canvas->cxBox = cdbox;
canvas->cxFLine = cdfline;
canvas->cxFPoly = cdfpoly;
- canvas->cxFRect = cdfboxrect;
- canvas->cxFBox = cdfboxrect;
+ canvas->cxFRect = cdfrect;
+ canvas->cxFBox = cdfbox;
canvas->cxArc = cdarc;
canvas->cxSector = cdsector;
canvas->cxText = cdtext;
@@ -1169,7 +1357,7 @@ static void cdinittable(cdCanvas* canvas)
static cdContext cdDXFContext =
{
CD_CAP_ALL & ~(CD_CAP_CLEAR | CD_CAP_PLAY | CD_CAP_PALETTE |
- CD_CAP_CLIPAREA | CD_CAP_CLIPPOLY |
+ CD_CAP_CLIPAREA | CD_CAP_CLIPPOLY | CD_CAP_PATH | CD_CAP_BEZIER |
CD_CAP_LINECAP | CD_CAP_LINEJOIN | CD_CAP_REGION | CD_CAP_CHORD |
CD_CAP_IMAGERGB | CD_CAP_IMAGEMAP | CD_CAP_IMAGESRV |
CD_CAP_BACKGROUND | CD_CAP_BACKOPACITY | CD_CAP_WRITEMODE |