Prepare for joins and caps

This commit is contained in:
Keith Packard 2002-08-14 18:32:42 +00:00
parent 71b804a301
commit 6b1903c40e
7 changed files with 184 additions and 28 deletions

View file

@ -1,5 +1,9 @@
XCOMM $XFree86: $
#ifndef NormalLibXr
#define NormalLibXr YES
#endif
#define DoNormalLib NormalLibXr
#define DoSharedLib SharedLibXr
#define DoDebugLib DebugLibXr

View file

@ -55,8 +55,14 @@ typedef enum _XrPathDirection {
XrPathDirectionReverse
} XrPathDirection;
typedef enum _XrSubPathDone {
XrSubPathDoneCap,
XrSubPathDoneJoin
} XrSubPathDone;
typedef struct _XrPathCallbacks {
void (*AddEdge)(void *closure, XPointFixed *p1, XPointFixed *p2);
void (*DoneSubPath) (void *closure, XrSubPathDone done);
} XrPathCallbacks;
#define XR_PATH_BUF_SZ 64
@ -180,9 +186,18 @@ struct _XrState {
XrGState *stack;
};
typedef struct _XrStrokeFace {
XPointFixed ccw;
XPointFixed pt;
XPointFixed cw;
} XrStrokeFace;
typedef struct _XrStroker {
XrGState *gstate;
XrTraps *traps;
int have_prev;
XrStrokeFace prev;
XrStrokeFace first;
} XrStroker;
/* xrstate.c */
@ -354,6 +369,9 @@ XrStrokerDeinit(XrStroker *stroker);
void
XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2);
void
XrStrokerDoneSubPath (void *closure, XrSubPathDone done);
/* xrtransform.c */
void
XrTransformInit(XrTransform *transform);

View file

@ -257,6 +257,11 @@ _TranslatePointFixed(XPointFixed *pt, XPointFixed *offset)
pt->y += offset->y;
}
void
XrPolygonDoneSubPath (void *closure, XrSubPathDone done)
{
}
#define START_ARGS(n) \
{ \
if (dir != XrPathDirectionForward) \
@ -299,6 +304,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
XPointFixed current = {0, 0};
XPointFixed first = {0, 0};
int has_current = 0;
int has_edge = 0;
int step = (dir == XrPathDirectionForward) ? 1 : -1;
for (op_buf = (dir == XrPathDirectionForward) ? path->op_head : path->op_tail;
@ -321,12 +327,15 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
switch (op) {
case XrPathOpMoveTo:
if (has_edge)
(*cb->DoneSubPath) (closure, XrSubPathDoneCap);
START_ARGS(1);
NEXT_ARG(pt);
END_ARGS(1);
first = pt;
current = pt;
has_current = 1;
has_edge = 0;
break;
case XrPathOpLineTo:
START_ARGS(1);
@ -335,6 +344,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
if (has_current) {
(*cb->AddEdge)(closure, &current, &pt);
current = pt;
has_edge = 1;
} else {
first = pt;
current = pt;
@ -342,6 +352,8 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
}
break;
case XrPathOpRelMoveTo:
if (has_edge)
(*cb->DoneSubPath) (closure, XrSubPathDoneCap);
START_ARGS(1);
NEXT_ARG(pt);
END_ARGS(1);
@ -349,6 +361,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
first = pt;
current = pt;
has_current = 1;
has_edge = 0;
break;
case XrPathOpRelLineTo:
START_ARGS(1);
@ -358,6 +371,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
if (has_current) {
(*cb->AddEdge)(closure, &current, &pt);
current = pt;
has_edge = 1;
} else {
first = pt;
current = pt;
@ -365,15 +379,18 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
}
break;
case XrPathOpClosePath:
(*cb->AddEdge)(closure, &current, &first);
if (has_edge) {
(*cb->AddEdge)(closure, &current, &first);
(*cb->DoneSubPath) (closure, XrSubPathDoneJoin);
}
current.x = 0;
current.y = 0;
first.x = 0;
first.y = 0;
has_current = 0;
has_edge = 0;
break;
}
}
}
}

View file

@ -34,6 +34,7 @@ XrStrokerInit(XrStroker *stroker, XrGState *gstate, XrTraps *traps)
{
stroker->gstate = gstate;
stroker->traps = traps;
stroker->have_prev = 0;
}
void
@ -49,6 +50,17 @@ _TranslatePoint(XPointFixed *pt, XPointFixed *offset)
pt->y += offset->y;
}
void
XrStrokerJoin(XrStroker *stroker, XrStrokeFace *f1, XrStrokeFace *f2)
{
XrGState *gstate = stroker->gstate;
}
void
XrStrokerCap(XrStroker *stroker, XrStrokeFace *f)
{
}
void
XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
{
@ -58,8 +70,9 @@ XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
XrTraps *traps = stroker->traps;
double mag, tmp;
XPointDouble vector;
XPointFixed offset;
XPointFixed offset_ccw, offset_cw;
XPointFixed quad[4];
XrStrokeFace face;
vector.x = XFixedToDouble(p2->x - p1->x);
vector.y = XFixedToDouble(p2->y - p1->y);
@ -80,25 +93,53 @@ XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
XrTransformPointWithoutTranslate(&gstate->ctm, &vector);
offset.x = XDoubleToFixed(vector.x);
offset.y = XDoubleToFixed(vector.y);
offset_ccw.x = XDoubleToFixed(vector.x);
offset_ccw.y = XDoubleToFixed(vector.y);
offset_cw.x = -offset_ccw.x;
offset_cw.y = -offset_ccw.y;
quad[0] = *p1;
_TranslatePoint(&quad[0], &offset);
quad[1] = *p2;
_TranslatePoint(&quad[1], &offset);
offset.x = - offset.x;
offset.y = - offset.y;
_TranslatePoint(&quad[0], &offset_cw);
quad[1] = *p1;
_TranslatePoint(&quad[1], &offset_ccw);
quad[2] = *p2;
_TranslatePoint(&quad[2], &offset);
quad[3] = *p1;
_TranslatePoint(&quad[3], &offset);
_TranslatePoint(&quad[1], &offset_ccw);
quad[3] = *p2;
_TranslatePoint(&quad[2], &offset_cw);
face.ccw = quad[2];
face.pt = *p2;
face.cw = quad[3];
if (stroker->have_prev)
XrStrokerJoin (stroker, &stroker->prev, &face);
else
stroker->first = face;
stroker->prev = face;
stroker->have_prev = 1;
XrTrapsTessellateConvexQuad(traps, quad);
}
void
XrStrokerDoneSubPath (void *closure, XrSubPathDone done)
{
XrStroker *stroker = closure;
switch (done) {
case XrSubPathDoneCap:
XrStrokerCap (stroker, &stroker->first);
XrStrokerCap (stroker, &stroker->prev);
break;
case XrSubPathDoneJoin:
XrStrokerJoin (stroker, &stroker->prev, &stroker->first);
break;
}
}
/* These functions aren't written yet... */
#if 0
static void

18
xrint.h
View file

@ -55,8 +55,14 @@ typedef enum _XrPathDirection {
XrPathDirectionReverse
} XrPathDirection;
typedef enum _XrSubPathDone {
XrSubPathDoneCap,
XrSubPathDoneJoin
} XrSubPathDone;
typedef struct _XrPathCallbacks {
void (*AddEdge)(void *closure, XPointFixed *p1, XPointFixed *p2);
void (*DoneSubPath) (void *closure, XrSubPathDone done);
} XrPathCallbacks;
#define XR_PATH_BUF_SZ 64
@ -180,9 +186,18 @@ struct _XrState {
XrGState *stack;
};
typedef struct _XrStrokeFace {
XPointFixed ccw;
XPointFixed pt;
XPointFixed cw;
} XrStrokeFace;
typedef struct _XrStroker {
XrGState *gstate;
XrTraps *traps;
int have_prev;
XrStrokeFace prev;
XrStrokeFace first;
} XrStroker;
/* xrstate.c */
@ -354,6 +369,9 @@ XrStrokerDeinit(XrStroker *stroker);
void
XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2);
void
XrStrokerDoneSubPath (void *closure, XrSubPathDone done);
/* xrtransform.c */
void
XrTransformInit(XrTransform *transform);

View file

@ -257,6 +257,11 @@ _TranslatePointFixed(XPointFixed *pt, XPointFixed *offset)
pt->y += offset->y;
}
void
XrPolygonDoneSubPath (void *closure, XrSubPathDone done)
{
}
#define START_ARGS(n) \
{ \
if (dir != XrPathDirectionForward) \
@ -299,6 +304,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
XPointFixed current = {0, 0};
XPointFixed first = {0, 0};
int has_current = 0;
int has_edge = 0;
int step = (dir == XrPathDirectionForward) ? 1 : -1;
for (op_buf = (dir == XrPathDirectionForward) ? path->op_head : path->op_tail;
@ -321,12 +327,15 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
switch (op) {
case XrPathOpMoveTo:
if (has_edge)
(*cb->DoneSubPath) (closure, XrSubPathDoneCap);
START_ARGS(1);
NEXT_ARG(pt);
END_ARGS(1);
first = pt;
current = pt;
has_current = 1;
has_edge = 0;
break;
case XrPathOpLineTo:
START_ARGS(1);
@ -335,6 +344,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
if (has_current) {
(*cb->AddEdge)(closure, &current, &pt);
current = pt;
has_edge = 1;
} else {
first = pt;
current = pt;
@ -342,6 +352,8 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
}
break;
case XrPathOpRelMoveTo:
if (has_edge)
(*cb->DoneSubPath) (closure, XrSubPathDoneCap);
START_ARGS(1);
NEXT_ARG(pt);
END_ARGS(1);
@ -349,6 +361,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
first = pt;
current = pt;
has_current = 1;
has_edge = 0;
break;
case XrPathOpRelLineTo:
START_ARGS(1);
@ -358,6 +371,7 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
if (has_current) {
(*cb->AddEdge)(closure, &current, &pt);
current = pt;
has_edge = 1;
} else {
first = pt;
current = pt;
@ -365,15 +379,18 @@ XrPathInterpret(XrPath *path, XrPathDirection dir, XrPathCallbacks *cb, void *cl
}
break;
case XrPathOpClosePath:
(*cb->AddEdge)(closure, &current, &first);
if (has_edge) {
(*cb->AddEdge)(closure, &current, &first);
(*cb->DoneSubPath) (closure, XrSubPathDoneJoin);
}
current.x = 0;
current.y = 0;
first.x = 0;
first.y = 0;
has_current = 0;
has_edge = 0;
break;
}
}
}
}

View file

@ -34,6 +34,7 @@ XrStrokerInit(XrStroker *stroker, XrGState *gstate, XrTraps *traps)
{
stroker->gstate = gstate;
stroker->traps = traps;
stroker->have_prev = 0;
}
void
@ -49,6 +50,17 @@ _TranslatePoint(XPointFixed *pt, XPointFixed *offset)
pt->y += offset->y;
}
void
XrStrokerJoin(XrStroker *stroker, XrStrokeFace *f1, XrStrokeFace *f2)
{
XrGState *gstate = stroker->gstate;
}
void
XrStrokerCap(XrStroker *stroker, XrStrokeFace *f)
{
}
void
XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
{
@ -58,8 +70,9 @@ XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
XrTraps *traps = stroker->traps;
double mag, tmp;
XPointDouble vector;
XPointFixed offset;
XPointFixed offset_ccw, offset_cw;
XPointFixed quad[4];
XrStrokeFace face;
vector.x = XFixedToDouble(p2->x - p1->x);
vector.y = XFixedToDouble(p2->y - p1->y);
@ -80,25 +93,53 @@ XrStrokerAddEdge(void *closure, XPointFixed *p1, XPointFixed *p2)
XrTransformPointWithoutTranslate(&gstate->ctm, &vector);
offset.x = XDoubleToFixed(vector.x);
offset.y = XDoubleToFixed(vector.y);
offset_ccw.x = XDoubleToFixed(vector.x);
offset_ccw.y = XDoubleToFixed(vector.y);
offset_cw.x = -offset_ccw.x;
offset_cw.y = -offset_ccw.y;
quad[0] = *p1;
_TranslatePoint(&quad[0], &offset);
quad[1] = *p2;
_TranslatePoint(&quad[1], &offset);
offset.x = - offset.x;
offset.y = - offset.y;
_TranslatePoint(&quad[0], &offset_cw);
quad[1] = *p1;
_TranslatePoint(&quad[1], &offset_ccw);
quad[2] = *p2;
_TranslatePoint(&quad[2], &offset);
quad[3] = *p1;
_TranslatePoint(&quad[3], &offset);
_TranslatePoint(&quad[1], &offset_ccw);
quad[3] = *p2;
_TranslatePoint(&quad[2], &offset_cw);
face.ccw = quad[2];
face.pt = *p2;
face.cw = quad[3];
if (stroker->have_prev)
XrStrokerJoin (stroker, &stroker->prev, &face);
else
stroker->first = face;
stroker->prev = face;
stroker->have_prev = 1;
XrTrapsTessellateConvexQuad(traps, quad);
}
void
XrStrokerDoneSubPath (void *closure, XrSubPathDone done)
{
XrStroker *stroker = closure;
switch (done) {
case XrSubPathDoneCap:
XrStrokerCap (stroker, &stroker->first);
XrStrokerCap (stroker, &stroker->prev);
break;
case XrSubPathDoneJoin:
XrStrokerJoin (stroker, &stroker->prev, &stroker->first);
break;
}
}
/* These functions aren't written yet... */
#if 0
static void