2002-08-14 00:39:43 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* $XFree86: $
|
|
|
|
|
|
*
|
|
|
|
|
|
* Copyright <EFBFBD> 2002 Carl D. Worth
|
|
|
|
|
|
*
|
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
|
* appear in supporting documentation, and that the name of Carl
|
|
|
|
|
|
* D. Worth not be used in advertising or publicity pertaining to
|
|
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
|
|
* permission. Carl D. Worth makes no representations about the
|
|
|
|
|
|
* suitability of this software for any purpose. It is provided "as
|
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
|
*
|
|
|
|
|
|
* CARL D. WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL CARL D. WORTH BE LIABLE FOR ANY SPECIAL,
|
|
|
|
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "xrint.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
static void
|
|
|
|
|
|
_TranslatePoint(XPointFixed *pt, XPointFixed *offset);
|
|
|
|
|
|
|
2002-08-15 05:22:59 +00:00
|
|
|
|
static int
|
|
|
|
|
|
_XrStrokerFaceClockwise(XrStrokeFace *in, XrStrokeFace *out);
|
|
|
|
|
|
|
|
|
|
|
|
static XrError
|
|
|
|
|
|
_XrStrokerJoin(XrStroker *stroker, XrStrokeFace *in, XrStrokeFace *out);
|
|
|
|
|
|
|
2002-08-18 22:55:58 +00:00
|
|
|
|
static void
|
|
|
|
|
|
XrStrokerStartDash (XrStroker *stroker)
|
|
|
|
|
|
{
|
|
|
|
|
|
XrGState *gstate = stroker->gstate;
|
|
|
|
|
|
double offset;
|
|
|
|
|
|
int on = 1;
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
offset = gstate->dash_offset;
|
2002-10-01 04:37:42 +00:00
|
|
|
|
while (offset >= gstate->dashes[i]) {
|
2002-08-18 22:55:58 +00:00
|
|
|
|
offset -= gstate->dashes[i];
|
|
|
|
|
|
on = 1-on;
|
|
|
|
|
|
if (++i == gstate->ndashes)
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
stroker->dash_index = i;
|
|
|
|
|
|
stroker->dash_on = on;
|
|
|
|
|
|
stroker->dash_remain = gstate->dashes[i] - offset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
XrStrokerStepDash (XrStroker *stroker, double step)
|
|
|
|
|
|
{
|
|
|
|
|
|
XrGState *gstate = stroker->gstate;
|
|
|
|
|
|
stroker->dash_remain -= step;
|
2002-10-01 04:37:42 +00:00
|
|
|
|
if (stroker->dash_remain <= 0) {
|
2002-08-18 22:55:58 +00:00
|
|
|
|
stroker->dash_index++;
|
|
|
|
|
|
if (stroker->dash_index == gstate->ndashes)
|
|
|
|
|
|
stroker->dash_index = 0;
|
|
|
|
|
|
stroker->dash_on = 1-stroker->dash_on;
|
|
|
|
|
|
stroker->dash_remain = gstate->dashes[stroker->dash_index];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-14 00:39:43 +00:00
|
|
|
|
void
|
|
|
|
|
|
XrStrokerInit(XrStroker *stroker, XrGState *gstate, XrTraps *traps)
|
|
|
|
|
|
{
|
|
|
|
|
|
stroker->gstate = gstate;
|
|
|
|
|
|
stroker->traps = traps;
|
2002-08-14 18:32:42 +00:00
|
|
|
|
stroker->have_prev = 0;
|
2002-08-18 22:55:58 +00:00
|
|
|
|
stroker->have_first = 0;
|
|
|
|
|
|
stroker->is_first = 1;
|
|
|
|
|
|
if (gstate->dashes)
|
|
|
|
|
|
XrStrokerStartDash (stroker);
|
2002-08-14 00:39:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
XrStrokerDeinit(XrStroker *stroker)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* nothing to do here */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
_TranslatePoint(XPointFixed *pt, XPointFixed *offset)
|
|
|
|
|
|
{
|
|
|
|
|
|
pt->x += offset->x;
|
|
|
|
|
|
pt->y += offset->y;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-14 19:19:33 +00:00
|
|
|
|
static int
|
2002-08-15 05:22:59 +00:00
|
|
|
|
_XrStrokerFaceClockwise(XrStrokeFace *in, XrStrokeFace *out)
|
2002-08-14 19:19:33 +00:00
|
|
|
|
{
|
2002-08-15 16:48:16 +00:00
|
|
|
|
XPointDouble d_in, d_out;
|
2002-08-14 19:19:33 +00:00
|
|
|
|
|
2002-08-15 16:48:16 +00:00
|
|
|
|
d_in.x = XFixedToDouble(in->cw.x - in->pt.x);
|
|
|
|
|
|
d_in.y = XFixedToDouble(in->cw.y - in->pt.y);
|
|
|
|
|
|
d_out.x = XFixedToDouble(out->cw.x - out->pt.x);
|
|
|
|
|
|
d_out.y = XFixedToDouble(out->cw.y - out->pt.y);
|
2002-08-14 19:19:33 +00:00
|
|
|
|
|
|
|
|
|
|
return d_out.y * d_in.x > d_in.y * d_out.x;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-15 05:22:59 +00:00
|
|
|
|
static XrError
|
|
|
|
|
|
_XrStrokerJoin(XrStroker *stroker, XrStrokeFace *in, XrStrokeFace *out)
|
2002-08-14 18:32:42 +00:00
|
|
|
|
{
|
2002-08-15 05:22:59 +00:00
|
|
|
|
XrError err;
|
2002-08-14 19:19:33 +00:00
|
|
|
|
XrGState *gstate = stroker->gstate;
|
2002-08-15 05:22:59 +00:00
|
|
|
|
int clockwise = _XrStrokerFaceClockwise (in, out);
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XrPolygon polygon;
|
|
|
|
|
|
XPointFixed *inpt, *outpt;
|
2002-08-14 19:19:33 +00:00
|
|
|
|
|
2002-09-04 16:11:35 +00:00
|
|
|
|
/* XXX: There might be a more natural place to check for the
|
|
|
|
|
|
degenerate join later in the code, (such as right before
|
|
|
|
|
|
dividing by zero) */
|
|
|
|
|
|
if (in->cw.x == out->cw.x
|
|
|
|
|
|
&& in->cw.y == out->cw.y
|
|
|
|
|
|
&& in->ccw.x == out->ccw.x
|
|
|
|
|
|
&& in->ccw.y == out->ccw.y) {
|
|
|
|
|
|
return XrErrorSuccess;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-10-01 04:37:42 +00:00
|
|
|
|
if (clockwise) {
|
2002-08-15 03:50:28 +00:00
|
|
|
|
inpt = &in->cw;
|
|
|
|
|
|
outpt = &out->cw;
|
2002-10-01 04:37:42 +00:00
|
|
|
|
} else {
|
2002-08-15 03:50:28 +00:00
|
|
|
|
inpt = &in->ccw;
|
|
|
|
|
|
outpt = &out->ccw;
|
|
|
|
|
|
}
|
|
|
|
|
|
XrPolygonInit (&polygon);
|
2002-08-15 17:19:28 +00:00
|
|
|
|
switch (gstate->line_join) {
|
2002-08-14 19:19:33 +00:00
|
|
|
|
case XrLineJoinRound: {
|
|
|
|
|
|
}
|
|
|
|
|
|
case XrLineJoinMiter: {
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XDouble c = in->vector.x * out->vector.x + in->vector.y * out->vector.y;
|
2002-08-15 17:19:28 +00:00
|
|
|
|
double ml = gstate->miter_limit;
|
2002-10-01 04:37:42 +00:00
|
|
|
|
if (2 <= ml * ml * (1 - c)) {
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XDouble x1, y1, x2, y2;
|
|
|
|
|
|
XDouble mx, my;
|
|
|
|
|
|
XDouble dx1, dx2, dy1, dy2;
|
|
|
|
|
|
XPointFixed outer;
|
2002-08-15 16:48:16 +00:00
|
|
|
|
XPointDouble v1, v2;
|
2002-08-15 03:50:28 +00:00
|
|
|
|
|
|
|
|
|
|
x1 = XFixedToDouble(inpt->x);
|
|
|
|
|
|
y1 = XFixedToDouble(inpt->y);
|
2002-08-15 16:48:16 +00:00
|
|
|
|
v1 = in->vector;
|
|
|
|
|
|
XrTransformPointWithoutTranslate(&gstate->ctm, &v1);
|
|
|
|
|
|
dx1 = v1.x;
|
|
|
|
|
|
dy1 = v1.y;
|
2002-08-15 03:50:28 +00:00
|
|
|
|
|
|
|
|
|
|
x2 = XFixedToDouble(outpt->x);
|
|
|
|
|
|
y2 = XFixedToDouble(outpt->y);
|
2002-08-15 16:48:16 +00:00
|
|
|
|
v2 = out->vector;
|
|
|
|
|
|
XrTransformPointWithoutTranslate(&gstate->ctm, &v2);
|
|
|
|
|
|
dx2 = v2.x;
|
|
|
|
|
|
dy2 = v2.y;
|
2002-08-15 03:50:28 +00:00
|
|
|
|
|
|
|
|
|
|
my = (((x2 - x1) * dy1 * dy2 - y2 * dx2 * dy1 + y1 * dx1 * dy2) /
|
|
|
|
|
|
(dx1 * dy2 - dx2 * dy1));
|
|
|
|
|
|
if (dy1)
|
|
|
|
|
|
mx = (my - y1) * dx1 / dy1 + x1;
|
|
|
|
|
|
else
|
|
|
|
|
|
mx = (my - y2) * dx2 / dy2 + x2;
|
|
|
|
|
|
|
|
|
|
|
|
outer.x = XDoubleToFixed(mx);
|
|
|
|
|
|
outer.y = XDoubleToFixed(my);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, &in->pt, inpt);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, inpt, &outer);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, &outer, outpt);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, outpt, &in->pt);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* fall through ... */
|
2002-08-14 19:19:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
case XrLineJoinBevel: {
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XrPolygonAddEdge (&polygon, &in->pt, inpt);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, inpt, outpt);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, outpt, &in->pt);
|
2002-08-14 19:19:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-08-15 05:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
err = XrTrapsTessellatePolygon (stroker->traps, &polygon, 1);
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XrPolygonDeinit (&polygon);
|
2002-08-15 05:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
return err;
|
2002-08-14 18:32:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-15 16:48:16 +00:00
|
|
|
|
static XrError
|
2002-08-15 05:22:59 +00:00
|
|
|
|
_XrStrokerCap(XrStroker *stroker, XrStrokeFace *f)
|
2002-08-14 18:32:42 +00:00
|
|
|
|
{
|
2002-08-15 16:48:16 +00:00
|
|
|
|
XrError err;
|
|
|
|
|
|
XrGState *gstate = stroker->gstate;
|
|
|
|
|
|
XrPolygon polygon;
|
|
|
|
|
|
|
2002-08-15 17:19:28 +00:00
|
|
|
|
if (gstate->line_cap == XrLineCapButt)
|
2002-08-15 16:48:16 +00:00
|
|
|
|
return XrErrorSuccess;
|
|
|
|
|
|
|
|
|
|
|
|
XrPolygonInit (&polygon);
|
2002-08-15 17:19:28 +00:00
|
|
|
|
switch (gstate->line_cap) {
|
2002-08-15 16:48:16 +00:00
|
|
|
|
case XrLineCapRound: {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case XrLineCapSquare: {
|
|
|
|
|
|
XPointDouble vector = f->vector;
|
|
|
|
|
|
XPointFixed fvector;
|
2002-08-15 17:29:26 +00:00
|
|
|
|
XPointFixed occw, ocw;
|
2002-08-15 17:19:28 +00:00
|
|
|
|
vector.x *= gstate->line_width / 2.0;
|
|
|
|
|
|
vector.y *= gstate->line_width / 2.0;
|
2002-08-15 16:48:16 +00:00
|
|
|
|
XrTransformPointWithoutTranslate(&gstate->ctm, &vector);
|
|
|
|
|
|
fvector.x = XDoubleToFixed(vector.x);
|
|
|
|
|
|
fvector.y = XDoubleToFixed(vector.y);
|
|
|
|
|
|
occw.x = f->ccw.x + fvector.x;
|
|
|
|
|
|
occw.y = f->ccw.y + fvector.y;
|
|
|
|
|
|
ocw.x = f->cw.x + fvector.x;
|
|
|
|
|
|
ocw.y = f->cw.y + fvector.y;
|
|
|
|
|
|
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, &f->cw, &ocw);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, &ocw, &occw);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, &occw, &f->ccw);
|
|
|
|
|
|
XrPolygonAddEdge (&polygon, &f->ccw, &f->cw);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case XrLineCapButt: {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = XrTrapsTessellatePolygon (stroker->traps, &polygon, 1);
|
|
|
|
|
|
XrPolygonDeinit (&polygon);
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
2002-08-14 18:32:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-09-03 08:42:25 +00:00
|
|
|
|
static void
|
2002-09-10 09:51:14 +00:00
|
|
|
|
_ComputeFace(XPointFixed *pt, XrSlopeFixed *slope, XrGState *gstate, XrStrokeFace *face)
|
2002-08-14 00:39:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
double mag, tmp;
|
|
|
|
|
|
XPointDouble vector;
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XPointDouble user_vector;
|
2002-08-14 18:32:42 +00:00
|
|
|
|
XPointFixed offset_ccw, offset_cw;
|
2002-08-14 00:39:43 +00:00
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
vector.x = XFixedToDouble(slope->dx);
|
|
|
|
|
|
vector.y = XFixedToDouble(slope->dy);
|
2002-08-14 00:39:43 +00:00
|
|
|
|
|
2002-08-15 03:50:28 +00:00
|
|
|
|
XrTransformPointWithoutTranslate(&gstate->ctm_inverse, &vector);
|
|
|
|
|
|
|
2002-08-14 00:39:43 +00:00
|
|
|
|
mag = sqrt(vector.x * vector.x + vector.y * vector.y);
|
|
|
|
|
|
if (mag == 0) {
|
2002-09-03 08:42:25 +00:00
|
|
|
|
/* XXX: Can't compute other face points. Do we want a tag in the face for this case? */
|
|
|
|
|
|
return;
|
2002-08-14 00:39:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vector.x /= mag;
|
|
|
|
|
|
vector.y /= mag;
|
|
|
|
|
|
|
2002-08-15 03:50:28 +00:00
|
|
|
|
user_vector = vector;
|
2002-08-14 00:39:43 +00:00
|
|
|
|
|
|
|
|
|
|
tmp = vector.x;
|
2002-08-15 17:19:28 +00:00
|
|
|
|
vector.x = - vector.y * (gstate->line_width / 2.0);
|
|
|
|
|
|
vector.y = tmp * (gstate->line_width / 2.0);
|
2002-08-14 00:39:43 +00:00
|
|
|
|
|
|
|
|
|
|
XrTransformPointWithoutTranslate(&gstate->ctm, &vector);
|
|
|
|
|
|
|
2002-08-14 18:32:42 +00:00
|
|
|
|
offset_ccw.x = XDoubleToFixed(vector.x);
|
|
|
|
|
|
offset_ccw.y = XDoubleToFixed(vector.y);
|
|
|
|
|
|
offset_cw.x = -offset_ccw.x;
|
|
|
|
|
|
offset_cw.y = -offset_ccw.y;
|
2002-08-14 00:39:43 +00:00
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
face->ccw = *pt;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
_TranslatePoint(&face->ccw, &offset_ccw);
|
2002-08-14 00:39:43 +00:00
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
face->pt = *pt;
|
2002-08-14 18:32:42 +00:00
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
face->cw = *pt;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
_TranslatePoint(&face->cw, &offset_cw);
|
|
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
face->vector.x = user_vector.x;
|
|
|
|
|
|
face->vector.y = user_vector.y;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static XrError
|
|
|
|
|
|
XrStrokerAddSubEdge (XrStroker *stroker, XPointFixed *p1, XPointFixed *p2,
|
|
|
|
|
|
XrStrokeFace *start, XrStrokeFace *end)
|
|
|
|
|
|
{
|
|
|
|
|
|
XrGState *gstate = stroker->gstate;
|
|
|
|
|
|
XPointFixed quad[4];
|
2002-09-10 09:51:14 +00:00
|
|
|
|
XrSlopeFixed slope;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
if (p1->x == p2->x && p1->y == p2->y) {
|
|
|
|
|
|
/* XXX: Need to rethink how this case should be handled, (both
|
|
|
|
|
|
here and in _ComputeFace). The key behavior is that
|
|
|
|
|
|
degenerate paths should draw as much as possible. */
|
|
|
|
|
|
return XrErrorSuccess;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
ComputeSlope(p1, p2, &slope);
|
|
|
|
|
|
_ComputeFace(p1, &slope, gstate, start);
|
|
|
|
|
|
|
2002-09-03 08:42:25 +00:00
|
|
|
|
/* XXX: This could be optimized slightly by not calling
|
2002-09-10 09:51:14 +00:00
|
|
|
|
_ComputeFace again but rather translating the relevant
|
|
|
|
|
|
fields from start. */
|
|
|
|
|
|
_ComputeFace(p2, &slope, gstate, end);
|
2002-09-03 08:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
quad[0] = start->cw;
|
|
|
|
|
|
quad[1] = start->ccw;
|
|
|
|
|
|
quad[2] = end->ccw;
|
|
|
|
|
|
quad[3] = end->cw;
|
|
|
|
|
|
|
|
|
|
|
|
return XrTrapsTessellateRectangle(stroker->traps, quad);
|
2002-08-18 22:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XrError
|
|
|
|
|
|
XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
|
|
|
|
|
|
{
|
|
|
|
|
|
XrError err;
|
|
|
|
|
|
XrStroker *stroker = closure;
|
|
|
|
|
|
XrStrokeFace start, end;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
if (p1->x == p2->x && p1->y == p2->y) {
|
|
|
|
|
|
/* XXX: Need to rethink how this case should be handled, (both
|
|
|
|
|
|
here and in XrStrokerAddSubEdge and in _ComputeFace). The
|
|
|
|
|
|
key behavior is that degenerate paths should draw as much
|
|
|
|
|
|
as possible. */
|
|
|
|
|
|
return XrErrorSuccess;
|
|
|
|
|
|
}
|
2002-08-18 22:55:58 +00:00
|
|
|
|
|
|
|
|
|
|
err = XrStrokerAddSubEdge (stroker, p1, p2, &start, &end);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
2002-08-15 05:22:59 +00:00
|
|
|
|
if (stroker->have_prev) {
|
2002-08-18 22:55:58 +00:00
|
|
|
|
err = _XrStrokerJoin (stroker, &stroker->prev, &start);
|
2002-08-15 05:22:59 +00:00
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
} else {
|
2002-08-14 19:19:33 +00:00
|
|
|
|
stroker->have_prev = 1;
|
2002-08-18 22:55:58 +00:00
|
|
|
|
if (stroker->is_first) {
|
|
|
|
|
|
stroker->have_first = 1;
|
|
|
|
|
|
stroker->first = start;
|
|
|
|
|
|
}
|
2002-08-14 19:19:33 +00:00
|
|
|
|
}
|
2002-08-18 22:55:58 +00:00
|
|
|
|
stroker->prev = end;
|
|
|
|
|
|
stroker->is_first = 0;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
|
2002-08-18 22:55:58 +00:00
|
|
|
|
return XrErrorSuccess;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Dashed lines. Cap each dash end, join around turns when on
|
|
|
|
|
|
*/
|
|
|
|
|
|
XrError
|
|
|
|
|
|
XrStrokerAddEdgeDashed (void *closure, XPointFixed *p1, XPointFixed *p2)
|
|
|
|
|
|
{
|
|
|
|
|
|
XrError err = XrErrorSuccess;
|
|
|
|
|
|
XrStroker *stroker = closure;
|
|
|
|
|
|
XrGState *gstate = stroker->gstate;
|
|
|
|
|
|
double mag, remain, tmp;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
XPointDouble vector, d2;
|
2002-08-18 22:55:58 +00:00
|
|
|
|
XPointFixed fd1, fd2;
|
|
|
|
|
|
int first = 1;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
XrStrokeFace sub_start, sub_end;
|
2002-08-14 19:19:33 +00:00
|
|
|
|
|
2002-08-18 22:55:58 +00:00
|
|
|
|
vector.x = XFixedToDouble(p2->x - p1->x);
|
|
|
|
|
|
vector.y = XFixedToDouble(p2->y - p1->y);
|
|
|
|
|
|
|
|
|
|
|
|
XrTransformPointWithoutTranslate(&gstate->ctm_inverse, &vector);
|
|
|
|
|
|
|
|
|
|
|
|
mag = sqrt(vector.x * vector.x + vector.y * vector.y);
|
|
|
|
|
|
remain = mag;
|
|
|
|
|
|
fd1 = *p1;
|
2002-10-01 04:37:42 +00:00
|
|
|
|
while (remain) {
|
2002-08-18 22:55:58 +00:00
|
|
|
|
tmp = stroker->dash_remain;
|
|
|
|
|
|
if (tmp > remain)
|
|
|
|
|
|
tmp = remain;
|
|
|
|
|
|
remain -= tmp;
|
|
|
|
|
|
d2.x = vector.x * (mag - remain)/mag;
|
|
|
|
|
|
d2.y = vector.y * (mag - remain)/mag;
|
|
|
|
|
|
XrTransformPointWithoutTranslate (&gstate->ctm, &d2);
|
|
|
|
|
|
fd2.x = XDoubleToFixed (d2.x);
|
|
|
|
|
|
fd2.y = XDoubleToFixed (d2.y);
|
|
|
|
|
|
fd2.x += p1->x;
|
|
|
|
|
|
fd2.y += p1->y;
|
|
|
|
|
|
/*
|
|
|
|
|
|
* XXX simplify this case analysis
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (stroker->dash_on) {
|
|
|
|
|
|
err = XrStrokerAddSubEdge (stroker, &fd1, &fd2, &sub_start, &sub_end);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
if (!first) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Not first dash in this segment, cap start
|
|
|
|
|
|
*/
|
|
|
|
|
|
err = _XrStrokerCap (stroker, &sub_start);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* First in this segment, join to any prev, else
|
|
|
|
|
|
* if at start of sub-path, mark position, else
|
|
|
|
|
|
* cap
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (stroker->have_prev) {
|
|
|
|
|
|
err = _XrStrokerJoin (stroker, &stroker->prev, &sub_start);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (stroker->is_first) {
|
|
|
|
|
|
stroker->have_first = 1;
|
|
|
|
|
|
stroker->first = sub_start;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
err = _XrStrokerCap (stroker, &sub_start);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (remain) {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Cap if not at end of segment
|
|
|
|
|
|
*/
|
|
|
|
|
|
err = _XrStrokerCap (stroker, &sub_end);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Mark previous line face and fix up next time
|
|
|
|
|
|
* through
|
|
|
|
|
|
*/
|
|
|
|
|
|
stroker->prev = sub_end;
|
|
|
|
|
|
stroker->have_prev = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/*
|
|
|
|
|
|
* If starting with off dash, check previous face
|
|
|
|
|
|
* and cap if necessary
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (first) {
|
|
|
|
|
|
if (stroker->have_prev) {
|
|
|
|
|
|
err = _XrStrokerCap (stroker, &stroker->prev);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!remain)
|
|
|
|
|
|
stroker->have_prev = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
XrStrokerStepDash (stroker, tmp);
|
|
|
|
|
|
fd1 = fd2;
|
|
|
|
|
|
first = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
stroker->is_first = 0;
|
|
|
|
|
|
return err;
|
2002-08-14 00:39:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-15 17:29:26 +00:00
|
|
|
|
XrError
|
|
|
|
|
|
XrStrokerAddSpline (void *closure, XPointFixed *a, XPointFixed *b, XPointFixed *c, XPointFixed *d)
|
|
|
|
|
|
{
|
|
|
|
|
|
XrError err = XrErrorSuccess;
|
|
|
|
|
|
XrStroker *stroker = closure;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
XrGState *gstate = stroker->gstate;
|
2002-08-15 17:29:26 +00:00
|
|
|
|
XrSpline spline;
|
|
|
|
|
|
XrPen pen;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
XrStrokeFace start, end;
|
2002-09-13 12:55:37 +00:00
|
|
|
|
XrPenFlaggedPoint extra_points[4];
|
2002-08-15 17:29:26 +00:00
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
err = XrSplineInit(&spline, a, b, c, d);
|
|
|
|
|
|
if (err == XrErrorDegenerate)
|
|
|
|
|
|
return XrErrorSuccess;
|
2002-08-15 17:29:26 +00:00
|
|
|
|
|
2002-09-03 08:42:25 +00:00
|
|
|
|
err = XrPenInitCopy(&pen, &gstate->pen_regular);
|
2002-08-15 17:29:26 +00:00
|
|
|
|
if (err)
|
2002-09-13 12:55:37 +00:00
|
|
|
|
goto CLEANUP_SPLINE;
|
2002-08-15 17:29:26 +00:00
|
|
|
|
|
2002-09-10 09:51:14 +00:00
|
|
|
|
_ComputeFace(a, &spline.initial_slope, gstate, &start);
|
|
|
|
|
|
_ComputeFace(d, &spline.final_slope, gstate, &end);
|
2002-09-03 08:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
if (stroker->have_prev) {
|
2002-09-04 07:28:56 +00:00
|
|
|
|
err = _XrStrokerJoin (stroker, &stroker->prev, &start);
|
2002-09-03 08:42:25 +00:00
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
stroker->have_prev = 1;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
if (stroker->is_first) {
|
|
|
|
|
|
stroker->have_first = 1;
|
|
|
|
|
|
stroker->first = start;
|
|
|
|
|
|
}
|
2002-09-03 08:42:25 +00:00
|
|
|
|
}
|
2002-09-04 07:28:56 +00:00
|
|
|
|
stroker->prev = end;
|
|
|
|
|
|
stroker->is_first = 0;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
|
2002-09-13 12:55:37 +00:00
|
|
|
|
extra_points[0].pt = start.cw; extra_points[0].flag = XrPenVertexFlagForward;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
extra_points[0].pt.x -= start.pt.x;
|
|
|
|
|
|
extra_points[0].pt.y -= start.pt.y;
|
2002-09-13 12:55:37 +00:00
|
|
|
|
extra_points[1].pt = start.ccw; extra_points[1].flag = XrPenVertexFlagNone;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
extra_points[1].pt.x -= start.pt.x;
|
|
|
|
|
|
extra_points[1].pt.y -= start.pt.y;
|
2002-09-13 12:55:37 +00:00
|
|
|
|
extra_points[2].pt = end.cw; extra_points[2].flag = XrPenVertexFlagNone;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
extra_points[2].pt.x -= end.pt.x;
|
|
|
|
|
|
extra_points[2].pt.y -= end.pt.y;
|
2002-09-13 12:55:37 +00:00
|
|
|
|
extra_points[3].pt = end.ccw; extra_points[3].flag = XrPenVertexFlagReverse;
|
2002-09-04 07:28:56 +00:00
|
|
|
|
extra_points[3].pt.x -= end.pt.x;
|
|
|
|
|
|
extra_points[3].pt.y -= end.pt.y;
|
2002-09-03 08:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
err = XrPenAddPoints(&pen, extra_points, 4);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
goto CLEANUP_PEN;
|
2002-08-15 17:29:26 +00:00
|
|
|
|
|
2002-09-13 12:55:37 +00:00
|
|
|
|
err = XrPenStrokeSpline(&pen, &spline, gstate->tolerance, stroker->traps);
|
2002-08-15 17:29:26 +00:00
|
|
|
|
if (err)
|
|
|
|
|
|
goto CLEANUP_PEN;
|
|
|
|
|
|
|
|
|
|
|
|
CLEANUP_PEN:
|
|
|
|
|
|
XrPenDeinit(&pen);
|
2002-09-13 12:55:37 +00:00
|
|
|
|
CLEANUP_SPLINE:
|
2002-08-15 17:29:26 +00:00
|
|
|
|
XrSplineDeinit(&spline);
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-15 05:22:59 +00:00
|
|
|
|
XrError
|
2002-08-14 18:32:42 +00:00
|
|
|
|
XrStrokerDoneSubPath (void *closure, XrSubPathDone done)
|
|
|
|
|
|
{
|
2002-08-15 05:22:59 +00:00
|
|
|
|
XrError err;
|
2002-08-14 18:32:42 +00:00
|
|
|
|
XrStroker *stroker = closure;
|
|
|
|
|
|
|
|
|
|
|
|
switch (done) {
|
|
|
|
|
|
case XrSubPathDoneJoin:
|
2002-08-18 22:55:58 +00:00
|
|
|
|
if (stroker->have_first && stroker->have_prev) {
|
|
|
|
|
|
err = _XrStrokerJoin (stroker, &stroker->prev, &stroker->first);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* fall through... */
|
|
|
|
|
|
case XrSubPathDoneCap:
|
|
|
|
|
|
if (stroker->have_first) {
|
|
|
|
|
|
err = _XrStrokerCap (stroker, &stroker->first);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (stroker->have_prev) {
|
|
|
|
|
|
err = _XrStrokerCap (stroker, &stroker->prev);
|
|
|
|
|
|
if (err)
|
|
|
|
|
|
return err;
|
|
|
|
|
|
}
|
2002-08-14 00:39:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-09-13 12:55:37 +00:00
|
|
|
|
stroker->have_prev = 0;
|
|
|
|
|
|
stroker->have_first = 0;
|
|
|
|
|
|
stroker->is_first = 1;
|
|
|
|
|
|
|
2002-08-15 05:22:59 +00:00
|
|
|
|
return XrErrorSuccess;
|
2002-08-14 00:39:43 +00:00
|
|
|
|
}
|
2002-08-15 17:29:26 +00:00
|
|
|
|
|
|
|
|
|
|
XrError
|
|
|
|
|
|
XrStrokerDonePath (void *closure)
|
|
|
|
|
|
{
|
|
|
|
|
|
return XrErrorSuccess;
|
|
|
|
|
|
}
|