summaryrefslogtreecommitdiff
path: root/src/drv
diff options
context:
space:
mode:
Diffstat (limited to 'src/drv')
-rw-r--r--src/drv/cdirgb.c186
-rw-r--r--src/drv/cdpdf.c28
-rw-r--r--src/drv/cdpicture.c12
-rw-r--r--src/drv/cdps.c44
4 files changed, 48 insertions, 222 deletions
diff --git a/src/drv/cdirgb.c b/src/drv/cdirgb.c
index e6cb4b5..9f367e0 100644
--- a/src/drv/cdirgb.c
+++ b/src/drv/cdirgb.c
@@ -580,7 +580,7 @@ static void irgbClipPoly(cdCtxCanvas* ctxcanvas, unsigned char* clip_region, cdP
memcpy(t_poly, poly, sizeof(cdPoint)*n);
poly = t_poly;
- for(i = 0; i < n; i++)
+ for(i = 0; i < n; i++) /* must duplicate because clip poly is stored */
cdMatrixTransformPoint(canvas->matrix, poly[i].x, poly[i].y, &poly[i].x, &poly[i].y);
}
@@ -642,79 +642,6 @@ static void irgbClipPoly(cdCtxCanvas* ctxcanvas, unsigned char* clip_region, cdP
irgPostProcessIntersect(ctxcanvas->clip_region, ctxcanvas->canvas->w * ctxcanvas->canvas->h);
}
-static void irgbClipElipse(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, double angle1, double angle2, int sector)
-{
- float c, s, sx, sy, x, y, prev_x, prev_y;
- double da;
- int i, p;
- cdPoint* poly;
-
- /* number of segments of equivalent poligonal for a full ellipse */
- int n = cdSimCalcEllipseNumSegments(ctxcanvas->canvas, xc, yc, width, height);
-
- /* number of segments for the arc */
- n = cdRound((fabs(angle2-angle1)*n)/360);
- if (n < 1) n = 1;
-
- poly = (cdPoint*)malloc(sizeof(cdPoint)*(n+2+1)); /* n+1 points +1 center */
-
- /* converts degrees into radians */
- angle1 *= CD_DEG2RAD;
- angle2 *= CD_DEG2RAD;
-
- /* generates arc points at origin with axis x and y */
-
- da = (angle2-angle1)/n;
- c = (float)cos(da);
- s = (float)sin(da);
- sx = -(width*s)/height;
- sy = (height*s)/width;
-
- x = xc + (width/2.0f)*(float)cos(angle1);
- y = yc + (height/2.0f)*(float)sin(angle1);
- poly[0].x = _cdRound(x);
- poly[0].y = _cdRound(y);
- prev_x = x;
- prev_y = y;
- p = 1;
-
- for (i = 1; i < n+1; i++) /* n+1 points */
- {
- x = xc + c*(prev_x-xc) + sx*(prev_y-yc);
- y = yc + sy*(prev_x-xc) + c*(prev_y-yc);
-
- poly[p].x = _cdRound(x);
- poly[p].y = _cdRound(y);
-
- if (poly[p-1].x != poly[p].x || poly[p-1].y != poly[p].y)
- p++;
-
- prev_x = x;
- prev_y = y;
- }
-
- if (poly[p-1].x != poly[0].x || poly[p-1].y != poly[0].y)
- {
- if (sector) /* cdSector */
- {
- /* add center */
- poly[p].x = xc;
- poly[p].y = yc;
- }
- else /* cdChord */
- {
- /* add initial point */
- poly[p].x = poly[0].x;
- poly[p].y = poly[0].y;
- }
- p++;
- }
-
- irgbClipPoly(ctxcanvas, ctxcanvas->clip_region, poly, p, ctxcanvas->canvas->combine_mode);
-
- free(poly);
-}
-
static void irgbClipBox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
int combine_mode = ctxcanvas->canvas->combine_mode;
@@ -952,54 +879,6 @@ static void cdfbox(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin
cdfSimBox(ctxcanvas, xmin, xmax, ymin, ymax);
}
-static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a1, double a2)
-{
- if (ctxcanvas->canvas->new_region)
- {
- /* matrix transformation is done inside irgbClip* if necessary */
- irgbClipElipse(ctxcanvas, xc, yc, w, h, a1, a2, 1);
- return;
- }
-
- cdSimSector(ctxcanvas, xc, yc, w, h, a1, a2);
-}
-
-static void cdchord(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a1, double a2)
-{
- if (ctxcanvas->canvas->new_region)
- {
- /* matrix transformation is done inside irgbClip* if necessary */
- irgbClipElipse(ctxcanvas, xc, yc, w, h, a1, a2, 0);
- return;
- }
-
- cdSimChord(ctxcanvas, xc, yc, w, h, a1, a2);
-}
-
-static void cdfsector(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2)
-{
- if (ctxcanvas->canvas->new_region)
- {
- /* matrix transformation is done inside irgbClip* if necessary */
- irgbClipElipse(ctxcanvas, _cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, 1);
- return;
- }
-
- cdfSimSector(ctxcanvas, xc, yc, w, h, a1, a2);
-}
-
-static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, double h, double a1, double a2)
-{
- if (ctxcanvas->canvas->new_region)
- {
- /* matrix transformation is done inside irgbClip* if necessary */
- irgbClipElipse(ctxcanvas, _cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, 0);
- return;
- }
-
- cdfSimChord(ctxcanvas, xc, yc, w, h, a1, a2);
-}
-
static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
if (ctxcanvas->canvas->new_region)
@@ -1035,59 +914,6 @@ static void cdpoly(cdCtxCanvas* ctxcanvas, int mode, cdPoint* poly, int n)
cdSimPoly(ctxcanvas, mode, poly, n);
}
-static void cdfpoly(cdCtxCanvas* ctxcanvas, int mode, cdfPoint* fpoly, int n)
-{
- int i;
-
- switch(mode)
- {
- case CD_CLOSED_LINES:
- fpoly[n] = fpoly[0];
- n++;
- /* continue */
- case CD_OPEN_LINES:
- cdfSimPolyLine(ctxcanvas->canvas, fpoly, n);
- break;
- case CD_BEZIER:
- cdfSimPolyBezier(ctxcanvas->canvas, fpoly, n);
- break;
- case CD_PATH:
- cdfSimPolyPath(ctxcanvas->canvas, fpoly, n);
- break;
- case CD_FILL:
- {
- cdPoint* poly = malloc(sizeof(cdPoint)*n);
-
- for (i = 0; i<n; i++)
- {
- poly[i].x = _cdRound(fpoly[i].x);
- poly[i].y = _cdRound(fpoly[i].y);
- }
-
- cdpoly(ctxcanvas, CD_FILL, poly, n);
-
- free(poly);
- }
- break;
- case CD_CLIP:
- {
- cdPoint* poly = malloc(sizeof(cdPoint)*n);
-
- for (i = 0; i<n; i++)
- {
- poly[i].x = _cdRound(fpoly[i].x);
- poly[i].y = _cdRound(fpoly[i].y);
- }
-
- cdpoly(ctxcanvas, CD_CLIP, poly, n);
-
- free(poly);
- if (ctxcanvas->canvas->clip_mode == CD_CLIPPOLYGON) cdclip(ctxcanvas, CD_CLIPPOLYGON);
- }
- break;
- }
-}
-
static void cdgetimagergb(cdCtxCanvas* ctxcanvas, unsigned char *r, unsigned char *g, unsigned char *b, int x, int y, int w, int h)
{
int dst_offset, src_offset, l, xsize, ysize, xpos, ypos;
@@ -2031,8 +1857,8 @@ static void cdinittable(cdCanvas* canvas)
canvas->cxRect = cdSimRect;
canvas->cxBox = cdbox;
canvas->cxArc = cdSimArc;
- canvas->cxSector = cdsector;
- canvas->cxChord = cdchord;
+ canvas->cxSector = cdSimSector;
+ canvas->cxChord = cdSimChord;
canvas->cxPoly = cdpoly;
canvas->cxText = cdtext;
@@ -2040,9 +1866,9 @@ static void cdinittable(cdCanvas* canvas)
canvas->cxFRect = cdfSimRect;
canvas->cxFBox = cdfbox;
canvas->cxFArc = cdfSimArc;
- canvas->cxFSector = cdfsector;
- canvas->cxFChord = cdfchord;
- canvas->cxFPoly = cdfpoly;
+ canvas->cxFSector = cdfSimSector;
+ canvas->cxFChord = cdfSimChord;
+ canvas->cxFPoly = cdfSimPoly;
canvas->cxKillCanvas = cdkillcanvas;
diff --git a/src/drv/cdpdf.c b/src/drv/cdpdf.c
index 2c48d50..f6621d3 100644
--- a/src/drv/cdpdf.c
+++ b/src/drv/cdpdf.c
@@ -570,15 +570,16 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
if (i+3 > n) return;
- xc = poly[i].x,
- yc = poly[i].y,
- w = poly[i+1].x,
- h = poly[i+1].y,
- a1 = poly[i+2].x/1000.0,
- a2 = poly[i+2].y/1000.0;
+ if (!cdCanvasGetArcPathF(ctxcanvas->canvas, poly+i, &xc, &yc, &w, &h, &a1, &a2))
+ return;
if (w==h)
- PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2);
+ {
+ if ((a2-a1)<0)
+ PDF_arcn(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2);
+ else
+ PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2);
+ }
else /* Ellipse: change the scale to create from the circle */
{
PDF_save(ctxcanvas->pdf); /* save to use the local transform */
@@ -587,7 +588,10 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
PDF_scale(ctxcanvas->pdf, w/h, 1);
PDF_translate(ctxcanvas->pdf, -xc, -yc);
- PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2);
+ if ((a2-a1)<0)
+ PDF_arcn(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2);
+ else
+ PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*h, a1, a2);
PDF_restore(ctxcanvas->pdf); /* restore from local */
}
@@ -716,12 +720,8 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
if (i+3 > n) return;
- xc = poly[i].x,
- yc = poly[i].y,
- w = poly[i+1].x,
- h = poly[i+1].y,
- a1 = poly[i+2].x,
- a2 = poly[i+2].y;
+ if (!cdfCanvasGetArcPath(ctxcanvas->canvas, poly+i, &xc, &yc, &w, &h, &a1, &a2))
+ return;
if (w==h)
PDF_arc(ctxcanvas->pdf, xc, yc, 0.5*w, a1, a2);
diff --git a/src/drv/cdpicture.c b/src/drv/cdpicture.c
index f1d089a..4cbc5d5 100644
--- a/src/drv/cdpicture.c
+++ b/src/drv/cdpicture.c
@@ -508,7 +508,7 @@ static void cdarc(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a
prim->param.arcsectorchord.angle1 = a1;
prim->param.arcsectorchord.angle2 = a2;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetEllipseBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, ctxcanvas->canvas->line_width);
picUpdateBBox(ctxcanvas, xmax, ymax, ctxcanvas->canvas->line_width);
}
@@ -525,7 +525,7 @@ static void cdfarc(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, doubl
prim->param.arcsectorchordf.angle1 = a1;
prim->param.arcsectorchordf.angle2 = a2;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetEllipseBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, ctxcanvas->canvas->line_width);
picUpdateBBox(ctxcanvas, xmax, ymax, ctxcanvas->canvas->line_width);
}
@@ -542,7 +542,7 @@ static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doubl
prim->param.arcsectorchord.angle1 = a1;
prim->param.arcsectorchord.angle2 = a2;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetEllipseBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, 0);
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
picUpdateBBox(ctxcanvas, xc, yc, 0);
@@ -560,7 +560,7 @@ static void cdfsector(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, do
prim->param.arcsectorchordf.angle1 = a1;
prim->param.arcsectorchordf.angle2 = a2;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetEllipseBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, 0);
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
picUpdateBBox(ctxcanvas, _cdRound(xc), _cdRound(yc), 0);
@@ -578,7 +578,7 @@ static void cdchord(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double
prim->param.arcsectorchord.angle1 = a1;
prim->param.arcsectorchord.angle2 = a2;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetEllipseBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, 0);
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
}
@@ -595,7 +595,7 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou
prim->param.arcsectorchordf.angle1 = a1;
prim->param.arcsectorchordf.angle2 = a2;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetEllipseBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, 0);
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
}
diff --git a/src/drv/cdps.c b/src/drv/cdps.c
index b651994..357abf4 100644
--- a/src/drv/cdps.c
+++ b/src/drv/cdps.c
@@ -648,7 +648,7 @@ static void cdarc(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double a
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
- cdCanvasGetEllipseBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
}
@@ -680,7 +680,7 @@ static void cdfarc(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, doubl
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
- cdCanvasGetEllipseBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
}
@@ -720,7 +720,7 @@ static void cdsector(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doubl
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
- cdCanvasGetEllipseBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
bbox(ctxcanvas, xc, yc);
@@ -761,7 +761,7 @@ static void cdfsector(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, do
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
- cdCanvasGetEllipseBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
fbbox(ctxcanvas, xc, yc);
@@ -800,7 +800,7 @@ static void cdchord(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
- cdCanvasGetEllipseBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(xc, yc, w, h, a1, a2, &xmin, &xmax, &ymin, &ymax);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
}
@@ -838,7 +838,7 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
- cdCanvasGetEllipseBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetArcBox(_cdRound(xc), _cdRound(yc), _cdRound(w), _cdRound(h), a1, a2, &xmin, &xmax, &ymin, &ymax);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
}
@@ -1110,19 +1110,19 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
case CD_PATH_ARC:
{
double xc, yc, w, h, a1, a2;
+ char* arc = "arc";
if (i+3 > n) return;
- xc = poly[i].x,
- yc = poly[i].y,
- w = poly[i+1].x,
- h = poly[i+1].y,
- a1 = poly[i+2].x/1000.0,
- a2 = poly[i+2].y/1000.0;
+ if (!cdCanvasGetArcPathF(ctxcanvas->canvas, poly+i, &xc, &yc, &w, &h, &a1, &a2))
+ return;
+
+ if ((a2-a1)<0)
+ arc = "arcn";
if (w==h) /* Circulo: PS implementa direto */
{
- fprintf(ctxcanvas->file, "N %d %d %g %g %g arc\n", xc, yc, 0.5*w, a1, a2);
+ fprintf(ctxcanvas->file, "N %d %d %g %g %g %s\n", xc, yc, 0.5*w, a1, a2, arc);
}
else /* Elipse: mudar a escala p/ criar a partir do circulo */
{
@@ -1130,7 +1130,7 @@ static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
fprintf(ctxcanvas->file, "%d %d translate\n", xc, yc);
fprintf(ctxcanvas->file, "1 %g scale\n", ((double)h)/w);
fprintf(ctxcanvas->file, "N\n");
- fprintf(ctxcanvas->file, "0 0 %g %g %g arc\n", 0.5*w, a1, a2);
+ fprintf(ctxcanvas->file, "0 0 %g %g %g %s\n", 0.5*w, a1, a2, arc);
fprintf(ctxcanvas->file, "setmatrix\n"); /* back to CTM */
}
@@ -1303,19 +1303,19 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
case CD_PATH_ARC:
{
double xc, yc, w, h, a1, a2;
+ char* arc = "arc";
if (i+3 > n) return;
- xc = poly[i].x,
- yc = poly[i].y,
- w = poly[i+1].x,
- h = poly[i+1].y,
- a1 = poly[i+2].x,
- a2 = poly[i+2].y;
+ if (!cdfCanvasGetArcPath(ctxcanvas->canvas, poly+i, &xc, &yc, &w, &h, &a1, &a2))
+ return;
+
+ if ((a2-a1)<0)
+ arc = "arcn";
if (w==h) /* Circulo: PS implementa direto */
{
- fprintf(ctxcanvas->file, "N %g %g %g %g %g arc\n", xc, yc, 0.5*w, a1, a2);
+ fprintf(ctxcanvas->file, "N %g %g %g %g %g %s\n", xc, yc, 0.5*w, a1, a2, arc);
}
else /* Elipse: mudar a escala p/ criar a partir do circulo */
{
@@ -1323,7 +1323,7 @@ static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n)
fprintf(ctxcanvas->file, "%g %g translate\n", xc, yc);
fprintf(ctxcanvas->file, "1 %g scale\n", ((double)h)/w);
fprintf(ctxcanvas->file, "N\n");
- fprintf(ctxcanvas->file, "0 0 %g %g %g arc\n", 0.5*w, a1, a2);
+ fprintf(ctxcanvas->file, "0 0 %g %g %g %s\n", 0.5*w, a1, a2, arc);
fprintf(ctxcanvas->file, "setmatrix\n"); /* back to CTM */
}