summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2002-06-11 04:02:23 +0000
committerCarl Worth <cworth@cworth.org>2002-06-11 04:02:23 +0000
commit00807705bf00ce370bb5860db23edbc0fa507015 (patch)
tree67b313dffcde3880cca0700e29c80f8b93b84c8b
Initial import of Xrinitial
-rw-r--r--Imakefile49
-rw-r--r--Xr.h103
-rw-r--r--src/Xr.h103
-rw-r--r--src/xr.c149
-rw-r--r--src/xrcolor.c72
-rw-r--r--src/xrgstate.c389
-rw-r--r--src/xrint.h343
-rw-r--r--src/xrpath.c169
-rw-r--r--src/xrstate.c94
-rw-r--r--src/xrtransform.c129
-rw-r--r--xr.c149
-rw-r--r--xrcolor.c72
-rw-r--r--xrgstate.c389
-rw-r--r--xrint.h343
-rw-r--r--xrpath.c169
-rw-r--r--xrpicture.c102
-rw-r--r--xrstate.c94
-rw-r--r--xrsubpath.c147
-rw-r--r--xrtransform.c129
19 files changed, 3194 insertions, 0 deletions
diff --git a/Imakefile b/Imakefile
new file mode 100644
index 000000000..bb49fc78b
--- /dev/null
+++ b/Imakefile
@@ -0,0 +1,49 @@
+XCOMM $XFree86: $
+
+#define DoNormalLib NormalLibXr
+#define DoSharedLib SharedLibXr
+#define DoDebugLib DebugLibXr
+#define DoProfileLib ProfileLibXr
+
+#define LibName Xr
+#define SoRev SOXRREV
+#define IncSubdir X11
+#define IncSubSubdir Xr
+
+#include <Threads.tmpl>
+
+WARNINGS=-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs
+INCLUDES=$(WARNINGS)
+DEFINES=$(RENDERDEFINES)
+
+XRENDER_LIBS=$(XRENDERLIB)
+XRENDER_CFLAGS=$(XRENDERINCLUDES)
+
+REQUIREDLIBS=$(LDPRELIBS) $(XRENDERLIB) $(XLIB)
+
+SRCS = xr.c \
+ xrcolor.c \
+ xrgstate.c \
+ xrpath.c \
+ xrpicture.c \
+ xrstate.c \
+ xrsubpath.c \
+ xrtransform.c
+
+OBJS = xr.o \
+ xrcolor.o \
+ xrgstate.o \
+ xrpath.o \
+ xrpicture.o \
+ xrstate.o \
+ xrsubpath.o \
+ xrtransform.o
+
+HEADERS = Xr.h
+
+#include <Library.tmpl>
+
+CDEBUGFLAGS=-g -Wall
+
+DependTarget()
+
diff --git a/Xr.h b/Xr.h
new file mode 100644
index 000000000..24df20fe1
--- /dev/null
+++ b/Xr.h
@@ -0,0 +1,103 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#ifndef _XR_H_
+#define _XR_H_
+
+#include <X11/extensions/Xrender.h>
+
+typedef struct _XrState XrState;
+
+/* Functions for manipulating state objects */
+XrState *
+XrCreate(Display *dpy, Drawable drawable, Visual *visual);
+
+void
+XrDestroy(XrState *xrs);
+
+void
+XrSave(XrState *xrs);
+
+void
+XrRestore(XrState *xrs);
+
+/* XXX: XrClone */
+
+/* Modify state */
+void
+XrSetDrawable(XrState *xrs, Drawable drawable, Visual *visual);
+
+void
+XrSetColorRGB(XrState *xrs, double red, double green, double blue);
+
+void
+XrSetAlpha(XrState *xrs, double alpha);
+
+void
+XrSetLineWidth(XrState *xrs, double width);
+
+void
+XrTranslate(XrState *xrs, double tx, double ty);
+
+void
+XrScale(XrState *xrs, double sx, double sy);
+
+void
+XrRotate(XrState *xrs, double angle);
+
+/* XXX: XrSetLineCap, XrSetLineJoin, XrSetDash, ... */
+
+/* Path creation */
+void
+XrNewPath(XrState *xrs);
+
+void
+XrMoveTo(XrState *xrs, double x, double y);
+
+void
+XrLineTo(XrState *xrs, double x, double y);
+
+void
+XrRelMoveTo(XrState *xrs, double x, double y);
+
+void
+XrRelLineTo(XrState *xrs, double x, double y);
+
+void
+XrClosePath(XrState *xrs);
+
+/* XXX: XrArcTo, XrCurveTo, XrRelCurveTo, ... */
+
+/* Render current path */
+void
+XrStroke(XrState *xrs);
+
+void
+XrFill(XrState *xrs);
+
+#endif
diff --git a/src/Xr.h b/src/Xr.h
new file mode 100644
index 000000000..24df20fe1
--- /dev/null
+++ b/src/Xr.h
@@ -0,0 +1,103 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#ifndef _XR_H_
+#define _XR_H_
+
+#include <X11/extensions/Xrender.h>
+
+typedef struct _XrState XrState;
+
+/* Functions for manipulating state objects */
+XrState *
+XrCreate(Display *dpy, Drawable drawable, Visual *visual);
+
+void
+XrDestroy(XrState *xrs);
+
+void
+XrSave(XrState *xrs);
+
+void
+XrRestore(XrState *xrs);
+
+/* XXX: XrClone */
+
+/* Modify state */
+void
+XrSetDrawable(XrState *xrs, Drawable drawable, Visual *visual);
+
+void
+XrSetColorRGB(XrState *xrs, double red, double green, double blue);
+
+void
+XrSetAlpha(XrState *xrs, double alpha);
+
+void
+XrSetLineWidth(XrState *xrs, double width);
+
+void
+XrTranslate(XrState *xrs, double tx, double ty);
+
+void
+XrScale(XrState *xrs, double sx, double sy);
+
+void
+XrRotate(XrState *xrs, double angle);
+
+/* XXX: XrSetLineCap, XrSetLineJoin, XrSetDash, ... */
+
+/* Path creation */
+void
+XrNewPath(XrState *xrs);
+
+void
+XrMoveTo(XrState *xrs, double x, double y);
+
+void
+XrLineTo(XrState *xrs, double x, double y);
+
+void
+XrRelMoveTo(XrState *xrs, double x, double y);
+
+void
+XrRelLineTo(XrState *xrs, double x, double y);
+
+void
+XrClosePath(XrState *xrs);
+
+/* XXX: XrArcTo, XrCurveTo, XrRelCurveTo, ... */
+
+/* Render current path */
+void
+XrStroke(XrState *xrs);
+
+void
+XrFill(XrState *xrs);
+
+#endif
diff --git a/src/xr.c b/src/xr.c
new file mode 100644
index 000000000..2211a45c4
--- /dev/null
+++ b/src/xr.c
@@ -0,0 +1,149 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include "xrint.h"
+
+XrState *
+XrCreate(Display *dpy, Drawable drawable, Visual *visual)
+{
+ XrState *xrs;
+
+ xrs = XrStateCreate(dpy);
+ XrSetDrawable(xrs, drawable, visual);
+
+ return xrs;
+}
+
+void
+XrDestroy(XrState *xrs)
+{
+ XrStateDestroy(xrs);
+}
+
+void
+XrSave(XrState *xrs)
+{
+ XrStatePush(xrs);
+}
+
+void
+XrRestore(XrState *xrs)
+{
+ XrStatePop(xrs);
+}
+
+void
+XrSetDrawable(XrState *xrs, Drawable drawable, Visual *visual)
+{
+ XrGStateSetDrawable(CURRENT_GSTATE(xrs), drawable, visual);
+}
+
+void
+XrSetColorRGB(XrState *xrs, double red, double green, double blue)
+{
+ XrGStateSetColorRGB(CURRENT_GSTATE(xrs), red, green, blue);
+}
+
+void
+XrSetAlpha(XrState *xrs, double alpha)
+{
+ XrGStateSetAlpha(CURRENT_GSTATE(xrs), alpha);
+}
+
+void
+XrSetLineWidth(XrState *xrs, double width)
+{
+ XrGStateSetLineWidth(CURRENT_GSTATE(xrs), width);
+}
+
+void
+XrTranslate(XrState *xrs, double tx, double ty)
+{
+ XrGStateTranslate(CURRENT_GSTATE(xrs), tx, ty);
+}
+
+void
+XrScale(XrState *xrs, double sx, double sy)
+{
+ XrGStateScale(CURRENT_GSTATE(xrs), sx, sy);
+}
+
+void
+XrRotate(XrState *xrs, double angle)
+{
+ XrGStateRotate(CURRENT_GSTATE(xrs), angle);
+}
+
+void
+XrNewPath(XrState *xrs)
+{
+ XrGStateNewPath(CURRENT_GSTATE(xrs));
+}
+
+void
+XrMoveTo(XrState *xrs, double x, double y)
+{
+ XrGStateMoveTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrLineTo(XrState *xrs, double x, double y)
+{
+ XrGStateLineTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrRelMoveTo(XrState *xrs, double x, double y)
+{
+ XrGStateRelMoveTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrRelLineTo(XrState *xrs, double x, double y)
+{
+ XrGStateRelLineTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrClosePath(XrState *xrs)
+{
+ XrGStateClosePath(CURRENT_GSTATE(xrs));
+}
+
+void
+XrStroke(XrState *xrs)
+{
+ XrGStateStroke(CURRENT_GSTATE(xrs));
+}
+
+void
+XrFill(XrState *xrs)
+{
+ XrGStateFill(CURRENT_GSTATE(xrs));
+}
+
diff --git a/src/xrcolor.c b/src/xrcolor.c
new file mode 100644
index 000000000..a09b10e42
--- /dev/null
+++ b/src/xrcolor.c
@@ -0,0 +1,72 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include "xrint.h"
+
+static XrColor XR_COLOR_DEFAULT = { 1.0, 1.0, 1.0, 1.0, {0xffff, 0xffff, 0xffff, 0xffff}};
+
+static void
+_XrColorComputeRenderColor(XrColor *color);
+
+void
+XrColorInit(XrColor *color)
+{
+ *color = XR_COLOR_DEFAULT;
+}
+
+void
+XrColorDeinit(XrColor *color)
+{
+ /* Nothing to do here */
+}
+
+static void
+_XrColorComputeRenderColor(XrColor *color)
+{
+ color->render.red = color->red * color->alpha * 0xffff;
+ color->render.green = color->green * color->alpha * 0xffff;
+ color->render.blue = color->blue * color->alpha * 0xffff;
+}
+
+void
+XrColorSetRGB(XrColor *color, double red, double green, double blue)
+{
+ color->red = red;
+ color->green = green;
+ color->blue = blue;
+
+ _XrColorComputeRenderColor(color);
+}
+
+void
+XrColorSetAlpha(XrColor *color, double alpha)
+{
+ color->alpha = alpha;
+
+ _XrColorComputeRenderColor(color);
+}
diff --git a/src/xrgstate.c b/src/xrgstate.c
new file mode 100644
index 000000000..a7bd58418
--- /dev/null
+++ b/src/xrgstate.c
@@ -0,0 +1,389 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include <math.h>
+
+#include "xrint.h"
+
+/* Private functions */
+static XrGState *
+_XrGStateAlloc(void);
+
+static void
+_TranslatePoint(XPointDouble *pt, const XPointDouble *offset);
+
+static void
+_XrGStateStrokePath(XrGState *gstate, XrPath *path, XrPath *outline);
+
+static void
+_XrGStateStrokeSubPath(XrGState *gstate, XrSubPath *subpath, XrPath *outline);
+
+static void
+_XrGStateStrokeSegment(XrGState *gstate, const XPointDouble *p0, const XPointDouble *p1, XrPath *outline);
+
+static void
+_XrGStateFillPath(XrGState *gstate, XrPath *path);
+
+static XrGState *
+_XrGStateAlloc(void)
+{
+ return malloc(sizeof(XrGState));
+}
+
+XrGState *
+XrGStateCreate(Display *dpy)
+{
+ XrGState *gstate;
+
+ gstate = _XrGStateAlloc();
+ XrGStateInit(gstate, dpy);
+
+ return gstate;
+}
+
+void
+XrGStateInit(XrGState *gstate, Display *dpy)
+{
+ gstate->dpy = dpy;
+
+ gstate->op = XR_GSTATE_OP_DEFAULT;
+ gstate->winding = XR_GSTATE_WINDING_DEFAULT;
+ gstate->line_width = XR_GSTATE_LINE_WIDTH_DEFAULT;
+
+ gstate->solidFormat = XRenderFindStandardFormat(dpy, PictStandardARGB32);
+ gstate->alphaFormat = XRenderFindStandardFormat(dpy, PictStandardA8);
+
+ XrPictureInit(&gstate->picture, dpy);
+
+ XrPictureInit(&gstate->src, dpy);
+ XrColorInit(&gstate->color);
+ XrPictureSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat);
+
+ XrTransformInit(&gstate->transform);
+
+ XrPathInit(&gstate->path);
+ XrPathInit(&gstate->outline);
+}
+
+void
+XrGStateInitCopy(XrGState *gstate, XrGState *other)
+{
+ *gstate = *other;
+
+ XrPathInitCopy(&gstate->path, &other->path);
+ XrPathInitCopy(&gstate->outline, &other->outline);
+}
+
+void
+XrGStateDeinit(XrGState *gstate)
+{
+ XrColorDeinit(&gstate->color);
+ XrPictureDeinit(&gstate->src);
+ XrPictureDeinit(&gstate->picture);
+ XrTransformInit(&gstate->transform);
+
+ XrPathDeinit(&gstate->path);
+}
+
+void
+XrGStateDestroy(XrGState *gstate)
+{
+ XrGStateDeinit(gstate);
+ free(gstate);
+}
+
+XrGState *
+XrGStateClone(XrGState *gstate)
+{
+ XrGState *clone;
+
+ clone = _XrGStateAlloc();
+
+ XrGStateInitCopy(clone, gstate);
+ return clone;
+}
+
+void
+XrGStateGetCurrentPoint(XrGState *gstate, XPointDouble *pt)
+{
+ XrPathGetCurrentPoint(&gstate->path, pt);
+}
+
+void
+XrGStateSetDrawable(XrGState *gstate, Drawable drawable, Visual *visual)
+{
+ XrPictureSetDrawable(&gstate->picture, drawable, visual);
+}
+
+void
+XrGStateSetColorRGB(XrGState *gstate, double red, double green, double blue)
+{
+ XrColorSetRGB(&gstate->color, red, green, blue);
+ XrPictureSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat);
+}
+
+void
+XrGStateSetAlpha(XrGState *gstate, double alpha)
+{
+ XrColorSetAlpha(&gstate->color, alpha);
+ XrPictureSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat);
+}
+
+void
+XrGStateSetLineWidth(XrGState *gstate, double width)
+{
+ gstate->line_width = width;
+}
+
+void
+XrGStateTranslate(XrGState *gstate, double tx, double ty)
+{
+ XrTransform new;
+
+ XrTransformInitTranslate(&new, tx, ty);
+ XrTransformCompose(&gstate->transform, &new);
+}
+
+void
+XrGStateScale(XrGState *gstate, double sx, double sy)
+{
+ XrTransform new;
+
+ XrTransformInitScale(&new, sx, sy);
+ XrTransformCompose(&gstate->transform, &new);
+}
+
+void
+XrGStateRotate(XrGState *gstate, double angle)
+{
+ XrTransform new;
+
+ XrTransformInitRotate(&new, angle);
+ XrTransformCompose(&gstate->transform, &new);
+}
+
+void
+XrGStateNewPath(XrGState *gstate)
+{
+ XrPathDeinit(&gstate->path);
+}
+
+void
+XrGStateMoveTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPoint(&gstate->transform, &pt);
+ XrPathMoveTo(&gstate->path, &pt);
+}
+
+void
+XrGStateLineTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPoint(&gstate->transform, &pt);
+ XrPathLineTo(&gstate->path, &pt);
+}
+
+static void
+_TranslatePoint(XPointDouble *pt, const XPointDouble *offset)
+{
+ pt->x += offset->x;
+ pt->y += offset->y;
+}
+
+void
+XrGStateRelMoveTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt, current;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPointWithoutTranslate(&gstate->transform, &pt);
+ XrGStateGetCurrentPoint(gstate, &current);
+ _TranslatePoint(&pt, &current);
+ XrPathMoveTo(&gstate->path, &pt);
+}
+
+void
+XrGStateRelLineTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt, current;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPointWithoutTranslate(&gstate->transform, &pt);
+ XrGStateGetCurrentPoint(gstate, &current);
+ _TranslatePoint(&pt, &current);
+ XrPathLineTo(&gstate->path, &pt);
+}
+
+void
+XrGStateClosePath(XrGState *gstate)
+{
+ XrPathClose(&gstate->path);
+}
+
+void
+XrGStateStroke(XrGState *gstate)
+{
+ int winding_save = gstate->winding;
+
+ gstate->winding = 1;
+ XrPathInit(&gstate->outline);
+ _XrGStateStrokePath(gstate, &gstate->path, &gstate->outline);
+ _XrGStateFillPath(gstate, &gstate->outline);
+ XrPathDeinit(&gstate->outline);
+ gstate->winding = winding_save;
+}
+
+void
+XrGStateFill(XrGState *gstate)
+{
+ _XrGStateFillPath(gstate, &gstate->path);
+}
+
+static void
+_XrGStateStrokePath(XrGState *gstate, XrPath *path, XrPath *outline)
+{
+ XrSubPath *sub;
+
+ for (sub = path->head; sub; sub = sub->next) {
+ if (sub->num_pts) {
+ _XrGStateStrokeSubPath(gstate, sub, outline);
+ }
+ }
+}
+
+static void
+_XrGStateStrokeSubPath(XrGState *gstate, XrSubPath *subpath, XrPath *outline)
+{
+ int i;
+ XPointDouble *p0, *p1;
+
+ XrPathNewSubPath(outline);
+
+ /* Stroke right-side of path forward */
+ for (i = 0; i < subpath->num_pts - 1; i++) {
+ p0 = subpath->pts + i;
+ p1 = p0 + 1;
+
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ }
+
+ /* Close path or add cap as necessary */
+ if (subpath->closed) {
+ p0 = subpath->pts + subpath->num_pts - 1;
+ p1 = subpath->pts;
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ XrPathClose(outline);
+ } else {
+ /* XXX: NYI: Add cap here */
+ }
+
+ /* Stroke right-side of path in reverse */
+ for (i = subpath->num_pts - 1; i > 0; i--) {
+ p0 = subpath->pts + i;
+ p1 = p0 - 1;
+
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ }
+
+ /* Close path or add cap as necessary */
+ if (subpath->closed) {
+ p0 = subpath->pts;
+ p1 = subpath->pts + subpath->num_pts - 1;
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ XrPathClose(outline);
+ } else {
+ /* XXX: NYI: Add cap here */
+ }
+}
+
+static void
+_XrGStateStrokeSegment(XrGState *gstate, const XPointDouble *p0, const XPointDouble *p1, XrPath *outline)
+{
+ double dx, dy, mag;
+ XPointDouble offset;
+ XPointDouble p0_off = *p0;
+ XPointDouble p1_off = *p1;
+
+ dx = p1->x - p0->x;
+ dy = p1->y - p0->y;
+ mag = (gstate->line_width / 2) / sqrt(dx * dx + dy *dy);
+
+ offset.x = -dy * mag;
+ offset.y = dx * mag;
+
+ XrTransformPointWithoutTranslate(&gstate->transform, &offset);
+
+ _TranslatePoint(&p0_off, &offset);
+ XrPathAddPoint(outline, &p0_off);
+
+ _TranslatePoint(&p1_off, &offset);
+ XrPathAddPoint(outline, &p1_off);
+}
+
+static void
+_XrGStateFillPath(XrGState *gstate, XrPath *path)
+{
+ XPolygonDouble *polys;
+ int i, npolys;
+ XrSubPath *subpath;
+
+ npolys = XrPathNumSubPaths(path);
+
+ polys = malloc(npolys * sizeof(XPolygonDouble));
+ if (polys == NULL) {
+ return;
+ }
+
+ for (i=0, subpath = path->head; i < npolys && subpath; i++, subpath = subpath->next) {
+ polys[i].points = subpath->pts;
+ polys[i].npoints = subpath->num_pts;
+ }
+
+ XRenderCompositeDoublePolys(gstate->dpy, gstate->op,
+ gstate->src.picture, gstate->picture.picture,
+ gstate->alphaFormat,
+ 0, 0, 0, 0,
+ polys, npolys,
+ gstate->winding);
+
+ free(polys);
+}
diff --git a/src/xrint.h b/src/xrint.h
new file mode 100644
index 000000000..6ac30b0ac
--- /dev/null
+++ b/src/xrint.h
@@ -0,0 +1,343 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+/*
+ * These definitions are solely for use by the implementation of Xr
+ * and constitute no kind of standard. If you need any of these
+ * functions, please drop me a note. Either the library needs new
+ * functionality, or there's a way to do what you need using the
+ * existing published interfaces. cworth@isi.edu
+ */
+
+#ifndef _XRINT_H_
+#define _XRINT_H_
+
+#include "Xr.h"
+
+typedef struct _XrSubPath {
+ int num_pts;
+ int pts_size;
+ XPointDouble *pts;
+ int closed;
+
+ struct _XrSubPath *next;
+} XrSubPath;
+
+typedef struct _XrPath {
+ XrSubPath *head;
+ XrSubPath *tail;
+} XrPath;
+
+typedef struct _XrPicture {
+ Display *dpy;
+
+ Drawable drawable;
+
+ Visual *visual;
+ unsigned int depth;
+
+ XRenderPictFormat *format;
+ unsigned long pa_mask;
+ XRenderPictureAttributes pa;
+
+ Picture picture;
+ Picture alpha;
+
+ /* XXX: Will also need a mechanism for a non-render picture here */
+} XrPicture;
+
+typedef struct _XrColor {
+ double red;
+ double green;
+ double blue;
+ double alpha;
+
+ XRenderColor render;
+
+ /* XXX: Will also need a mechanism for a non-render color here */
+} XrColor;
+
+
+typedef struct _XrTransform {
+ double matrix[6];
+} XrTransform;
+
+#define XR_GSTATE_OP_DEFAULT PictOpOver
+#define XR_GSTATE_WINDING_DEFAULT 1
+#define XR_GSTATE_LINE_WIDTH_DEFAULT 1.0
+
+typedef struct _XrGState {
+ Display *dpy;
+
+ int op;
+ int winding;
+ double line_width;
+
+ XRenderPictFormat *solidFormat;
+ XRenderPictFormat *alphaFormat;
+
+ XrColor color;
+ XrPicture src;
+ XrPicture picture;
+ XrTransform transform;
+
+ XrPath path;
+ XrPath outline;
+
+ struct _XrGState *next;
+} XrGState;
+
+struct _XrState {
+ Display *dpy;
+ XrGState *stack;
+};
+
+/* xrstate.c */
+
+#define CURRENT_GSTATE(xrs) (xrs->stack)
+
+XrState *
+XrStateCreate(Display *dpy);
+
+void
+XrStateInit(XrState *state, Display *dpy);
+
+void
+XrStateDeinit(XrState *xrs);
+
+void
+XrStateDestroy(XrState *state);
+
+void
+XrStatePush(XrState *xrs);
+
+void
+XrStatePop(XrState *xrs);
+
+/* xrgstate.c */
+XrGState *
+XrGStateCreate(Display *dpy);
+
+XrGState *
+XrGStateClone(XrGState *gstate);
+
+void
+XrGStateInit(XrGState *gstate, Display *dpy);
+
+void
+XrGStateInitCopy(XrGState *gstate, XrGState *other);
+
+void
+XrGStateDeinit(XrGState *gstate);
+
+void
+XrGStateDestroy(XrGState *gstate);
+
+void
+XrGStateGetCurrentPoint(XrGState *gstate, XPointDouble *pt);
+
+void
+XrGStateSetDrawable(XrGState *gstate, Drawable drawable, Visual *visual);
+
+void
+XrGStateSetColorRGB(XrGState *gstate, double red, double green, double blue);
+
+void
+XrGStateSetAlpha(XrGState *gstate, double alpha);
+
+void
+XrGStateSetLineWidth(XrGState *gstate, double width);
+
+void
+XrGStateTranslate(XrGState *gstate, double tx, double ty);
+
+void
+XrGStateScale(XrGState *gstate, double sx, double sy);
+
+void
+XrGStateRotate(XrGState *gstate, double angle);
+
+void
+XrGStateNewPath(XrGState *gstate);
+
+void
+XrGStateMoveTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateLineTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateRelMoveTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateRelLineTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateClosePath(XrGState *gstate);
+
+void
+XrGStateStroke(XrGState *gstate);
+
+void
+XrGStateFill(XrGState *fill);
+
+/* xrcolor.c */
+void
+XrColorInit(XrColor *color);
+
+void
+XrColorDeinit(XrColor *color);
+
+void
+XrColorSetRGB(XrColor *color, double red, double green, double blue);
+
+void
+XrColorSetAlpha(XrColor *color, double alpha);
+
+/* xrpath.c */
+XrPath *
+XrPathCreate(void);
+
+void
+XrPathInit(XrPath *path);
+
+void
+XrPathInitCopy(XrPath *path, XrPath *other);
+
+void
+XrPathReinit(XrPath *path);
+
+void
+XrPathDeinit(XrPath *path);
+
+void
+XrPathDestroy(XrPath *path);
+
+XrPath *
+XrPathClone(XrPath *path);
+
+void
+XrPathGetCurrentPoint(XrPath *path, XPointDouble *pt);
+
+int
+XrPathNumSubPaths(XrPath *path);
+
+void
+XrPathNewSubPath(XrPath *path);
+
+void
+XrPathAddPoint(XrPath *path, const XPointDouble *pt);
+
+void
+XrPathMoveTo(XrPath *path, const XPointDouble *pt);
+
+void
+XrPathLineTo(XrPath *path, const XPointDouble *pt);
+
+void
+XrPathClose(XrPath *path);
+
+/* xrsubpath.c */
+XrSubPath *
+XrSubPathCreate(void);
+
+void
+XrSubPathInit(XrSubPath *path);
+
+void
+XrSubPathInitCopy(XrSubPath *path, XrSubPath *other);
+
+void
+XrSubPathDeinit(XrSubPath *path);
+
+void
+XrSubPathDestroy(XrSubPath *path);
+
+XrSubPath *
+XrSubPathClone(XrSubPath *path);
+
+void
+XrSubPathGetCurrentPoint(XrSubPath *path, XPointDouble *pt);
+
+void
+XrSubPathSetCurrentPoint(XrSubPath *path, const XPointDouble *pt);
+
+void
+XrSubPathAddPoint(XrSubPath *path, const XPointDouble *pt);
+
+void
+XrSubPathClose(XrSubPath *path);
+
+/* xrpicture.c */
+void
+XrPictureInit(XrPicture *picture, Display *dpy);
+
+void
+XrPictureDeinit(XrPicture *picture);
+
+void
+XrPictureSetSolidColor(XrPicture *picture, XrColor *color, XRenderPictFormat *format);
+
+void
+XrPictureSetDrawable(XrPicture *picture, Drawable drawable, Visual *visual);
+
+/* xrtransform.c */
+void
+XrTransformInit(XrTransform *transform);
+
+void
+XrTransformInitMatrix(XrTransform *transform,
+ double a, double b,
+ double c, double d,
+ double tx, double ty);
+
+void
+XrTransformInitTranslate(XrTransform *transform,
+ double tx, double ty);
+
+void
+XrTransformInitScale(XrTransform *transform,
+ double sx, double sy);
+
+void
+XrTransformInitRotate(XrTransform *transform,
+ double angle);
+
+void
+XrTransformDeinit(XrTransform *transform);
+
+void
+XrTransformCompose(XrTransform *t1, const XrTransform *t2);
+
+void
+XrTransformPointWithoutTranslate(XrTransform *transform, XPointDouble *pt);
+
+void
+XrTransformPoint(XrTransform *transform, XPointDouble *pt);
+
+#endif
diff --git a/src/xrpath.c b/src/xrpath.c
new file mode 100644
index 000000000..4ee16e437
--- /dev/null
+++ b/src/xrpath.c
@@ -0,0 +1,169 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include "xrint.h"
+
+/* private functions */
+static void
+_XrPathAddSubPath(XrPath *path, XrSubPath *subpath);
+
+XrPath *
+XrPathCreate(void)
+{
+ XrPath *path;
+
+ path = malloc(sizeof(XrPath));
+ return path;
+}
+
+void
+XrPathInit(XrPath *path)
+{
+ path->head = NULL;
+ path->tail = NULL;
+}
+
+void
+XrPathInitCopy(XrPath *path, XrPath *other)
+{
+ XrSubPath *subpath, *othersub;
+
+ XrPathInit(path);
+
+ for (othersub = other->head; othersub; othersub = othersub->next) {
+ subpath = XrSubPathClone(othersub);
+ _XrPathAddSubPath(path, subpath);
+ }
+}
+
+void
+XrPathDeinit(XrPath *path)
+{
+ XrSubPath *subpath;
+
+ while (path->head) {
+ subpath = path->head;
+ path->head = subpath->next;
+ XrSubPathDestroy(subpath);
+ }
+ path->tail = NULL;
+}
+
+void
+XrPathDestroy(XrPath *path)
+{
+ free(path);
+}
+
+XrPath *
+XrPathClone(XrPath *path)
+{
+ XrPath *clone;
+
+ clone = XrPathCreate();
+ XrPathInitCopy(clone, path);
+ return clone;
+}
+
+void
+XrPathGetCurrentPoint(XrPath *path, XPointDouble *pt)
+{
+ XrSubPathGetCurrentPoint(path->tail, pt);
+}
+
+int
+XrPathNumSubPaths(XrPath *path)
+{
+ XrSubPath *subpath;
+ int num_subpaths;
+
+ num_subpaths = 0;
+ for (subpath = path->head; subpath; subpath = subpath->next) {
+ num_subpaths++;
+ }
+
+ return num_subpaths;
+}
+
+static void
+_XrPathAddSubPath(XrPath *path, XrSubPath *subpath)
+{
+ subpath->next = NULL;
+
+ if (path->tail) {
+ path->tail->next = subpath;
+ } else {
+ path->head = subpath;
+ }
+
+ path->tail = subpath;
+}
+
+void
+XrPathNewSubPath(XrPath *path)
+{
+ XrSubPath *subpath;
+
+ subpath = XrSubPathCreate();
+ _XrPathAddSubPath(path, subpath);
+}
+
+void
+XrPathAddPoint(XrPath *path, const XPointDouble *pt)
+{
+ XrSubPathAddPoint(path->tail, pt);
+}
+
+void
+XrPathMoveTo(XrPath *path, const XPointDouble *pt)
+{
+ XrSubPath *subpath;
+
+ subpath = path->tail;
+
+ if (subpath == NULL || subpath->num_pts > 1) {
+ XrPathNewSubPath(path);
+ XrPathAddPoint(path, pt);
+ } else {
+ XrSubPathSetCurrentPoint(subpath, pt);
+ }
+}
+
+void
+XrPathLineTo(XrPath *path, const XPointDouble *pt)
+{
+ XrPathAddPoint(path, pt);
+}
+
+void
+XrPathClose(XrPath *path)
+{
+ XrSubPathClose(path->tail);
+ XrPathNewSubPath(path);
+}
diff --git a/src/xrstate.c b/src/xrstate.c
new file mode 100644
index 000000000..37c8f501f
--- /dev/null
+++ b/src/xrstate.c
@@ -0,0 +1,94 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include "xrint.h"
+
+XrState *
+XrStateCreate(Display *dpy)
+{
+ XrState *xrs;
+
+ xrs = malloc(sizeof(XrState));
+
+ XrStateInit(xrs, dpy);
+
+ return xrs;
+}
+
+void
+XrStateInit(XrState *xrs, Display *dpy)
+{
+ xrs->dpy = dpy;
+ xrs->stack = NULL;
+ XrStatePush(xrs);
+}
+
+void
+XrStateDeinit(XrState *xrs)
+{
+ while (xrs->stack) {
+ XrStatePop(xrs);
+ }
+}
+
+void
+XrStateDestroy(XrState *xrs)
+{
+ XrStateDeinit(xrs);
+ free(xrs);
+}
+
+void
+XrStatePush(XrState *xrs)
+{
+ XrGState *top;
+
+ if (xrs->stack) {
+ top = XrGStateClone(xrs->stack);
+ } else {
+ top = XrGStateCreate(xrs->dpy);
+ }
+
+ top->next = xrs->stack;
+ xrs->stack = top;
+}
+
+void
+XrStatePop(XrState *xrs)
+{
+ XrGState *top;
+
+ if (xrs->stack) {
+ top = xrs->stack;
+ xrs->stack = top->next;
+
+ XrGStateDestroy(top);
+ }
+}
+
diff --git a/src/xrtransform.c b/src/xrtransform.c
new file mode 100644
index 000000000..b90d02c70
--- /dev/null
+++ b/src/xrtransform.c
@@ -0,0 +1,129 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include <math.h>
+
+#include "xrint.h"
+
+static XrTransform XR_TRANSFORM_DEFAULT = {
+ {1, 0,
+ 0, 1,
+ 0, 0}
+};
+
+void
+XrTransformInit(XrTransform *transform)
+{
+ *transform = XR_TRANSFORM_DEFAULT;
+}
+
+void
+XrTransformInitMatrix(XrTransform *transform,
+ double a, double b,
+ double c, double d,
+ double tx, double ty)
+{
+ transform->matrix[0] = a; transform->matrix[1] = b;
+ transform->matrix[2] = c; transform->matrix[3] = d;
+ transform->matrix[4] = tx; transform->matrix[5] = ty;
+}
+
+void
+XrTransformInitTranslate(XrTransform *transform,
+ double tx, double ty)
+{
+ XrTransformInitMatrix(transform,
+ 1, 0,
+ 0, 1,
+ tx, ty);
+}
+
+void
+XrTransformInitScale(XrTransform *transform,
+ double sx, double sy)
+{
+ XrTransformInitMatrix(transform,
+ sx, 0,
+ 0, sy,
+ 0, 0);
+}
+
+void
+XrTransformInitRotate(XrTransform *transform,
+ double angle)
+{
+ XrTransformInitMatrix(transform,
+ cos(angle), sin(angle),
+ -sin(angle), cos(angle),
+ 0, 0);
+}
+
+void
+XrTransformDeinit(XrTransform *transform)
+{
+ /* Nothing to do here */
+}
+
+void
+XrTransformCompose(XrTransform *t1, const XrTransform *t2)
+{
+ double new[6];
+
+ new[0] = t2->matrix[0] * t1->matrix[0] + t2->matrix[1] * t1->matrix[2];
+ new[1] = t2->matrix[0] * t1->matrix[1] + t2->matrix[1] * t1->matrix[3];
+ new[2] = t2->matrix[2] * t1->matrix[0] + t2->matrix[3] * t1->matrix[2];
+ new[3] = t2->matrix[2] * t1->matrix[1] + t2->matrix[3] * t1->matrix[3];
+ new[4] = t2->matrix[4] * t1->matrix[0] + t2->matrix[5] * t1->matrix[2] + t1->matrix[4];
+ new[5] = t2->matrix[4] * t1->matrix[1] + t2->matrix[5] * t1->matrix[3] + t1->matrix[5];
+
+ memcpy(t1->matrix, new, 6 * sizeof(double));
+}
+
+void
+XrTransformPointWithoutTranslate(XrTransform *transform, XPointDouble *pt)
+{
+ double new_x, new_y;
+
+ new_x = (transform->matrix[0] * pt->x
+ + transform->matrix[2] * pt->y);
+ new_y = (transform->matrix[1] * pt->x
+ + transform->matrix[3] * pt->y);
+
+ pt->x = new_x;
+ pt->y = new_y;
+}
+
+void
+XrTransformPoint(XrTransform *transform, XPointDouble *pt)
+{
+ XrTransformPointWithoutTranslate(transform, pt);
+
+ pt->x += transform->matrix[4];
+ pt->y += transform->matrix[5];
+}
diff --git a/xr.c b/xr.c
new file mode 100644
index 000000000..2211a45c4
--- /dev/null
+++ b/xr.c
@@ -0,0 +1,149 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include "xrint.h"
+
+XrState *
+XrCreate(Display *dpy, Drawable drawable, Visual *visual)
+{
+ XrState *xrs;
+
+ xrs = XrStateCreate(dpy);
+ XrSetDrawable(xrs, drawable, visual);
+
+ return xrs;
+}
+
+void
+XrDestroy(XrState *xrs)
+{
+ XrStateDestroy(xrs);
+}
+
+void
+XrSave(XrState *xrs)
+{
+ XrStatePush(xrs);
+}
+
+void
+XrRestore(XrState *xrs)
+{
+ XrStatePop(xrs);
+}
+
+void
+XrSetDrawable(XrState *xrs, Drawable drawable, Visual *visual)
+{
+ XrGStateSetDrawable(CURRENT_GSTATE(xrs), drawable, visual);
+}
+
+void
+XrSetColorRGB(XrState *xrs, double red, double green, double blue)
+{
+ XrGStateSetColorRGB(CURRENT_GSTATE(xrs), red, green, blue);
+}
+
+void
+XrSetAlpha(XrState *xrs, double alpha)
+{
+ XrGStateSetAlpha(CURRENT_GSTATE(xrs), alpha);
+}
+
+void
+XrSetLineWidth(XrState *xrs, double width)
+{
+ XrGStateSetLineWidth(CURRENT_GSTATE(xrs), width);
+}
+
+void
+XrTranslate(XrState *xrs, double tx, double ty)
+{
+ XrGStateTranslate(CURRENT_GSTATE(xrs), tx, ty);
+}
+
+void
+XrScale(XrState *xrs, double sx, double sy)
+{
+ XrGStateScale(CURRENT_GSTATE(xrs), sx, sy);
+}
+
+void
+XrRotate(XrState *xrs, double angle)
+{
+ XrGStateRotate(CURRENT_GSTATE(xrs), angle);
+}
+
+void
+XrNewPath(XrState *xrs)
+{
+ XrGStateNewPath(CURRENT_GSTATE(xrs));
+}
+
+void
+XrMoveTo(XrState *xrs, double x, double y)
+{
+ XrGStateMoveTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrLineTo(XrState *xrs, double x, double y)
+{
+ XrGStateLineTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrRelMoveTo(XrState *xrs, double x, double y)
+{
+ XrGStateRelMoveTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrRelLineTo(XrState *xrs, double x, double y)
+{
+ XrGStateRelLineTo(CURRENT_GSTATE(xrs), x, y);
+}
+
+void
+XrClosePath(XrState *xrs)
+{
+ XrGStateClosePath(CURRENT_GSTATE(xrs));
+}
+
+void
+XrStroke(XrState *xrs)
+{
+ XrGStateStroke(CURRENT_GSTATE(xrs));
+}
+
+void
+XrFill(XrState *xrs)
+{
+ XrGStateFill(CURRENT_GSTATE(xrs));
+}
+
diff --git a/xrcolor.c b/xrcolor.c
new file mode 100644
index 000000000..a09b10e42
--- /dev/null
+++ b/xrcolor.c
@@ -0,0 +1,72 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include "xrint.h"
+
+static XrColor XR_COLOR_DEFAULT = { 1.0, 1.0, 1.0, 1.0, {0xffff, 0xffff, 0xffff, 0xffff}};
+
+static void
+_XrColorComputeRenderColor(XrColor *color);
+
+void
+XrColorInit(XrColor *color)
+{
+ *color = XR_COLOR_DEFAULT;
+}
+
+void
+XrColorDeinit(XrColor *color)
+{
+ /* Nothing to do here */
+}
+
+static void
+_XrColorComputeRenderColor(XrColor *color)
+{
+ color->render.red = color->red * color->alpha * 0xffff;
+ color->render.green = color->green * color->alpha * 0xffff;
+ color->render.blue = color->blue * color->alpha * 0xffff;
+}
+
+void
+XrColorSetRGB(XrColor *color, double red, double green, double blue)
+{
+ color->red = red;
+ color->green = green;
+ color->blue = blue;
+
+ _XrColorComputeRenderColor(color);
+}
+
+void
+XrColorSetAlpha(XrColor *color, double alpha)
+{
+ color->alpha = alpha;
+
+ _XrColorComputeRenderColor(color);
+}
diff --git a/xrgstate.c b/xrgstate.c
new file mode 100644
index 000000000..a7bd58418
--- /dev/null
+++ b/xrgstate.c
@@ -0,0 +1,389 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include <math.h>
+
+#include "xrint.h"
+
+/* Private functions */
+static XrGState *
+_XrGStateAlloc(void);
+
+static void
+_TranslatePoint(XPointDouble *pt, const XPointDouble *offset);
+
+static void
+_XrGStateStrokePath(XrGState *gstate, XrPath *path, XrPath *outline);
+
+static void
+_XrGStateStrokeSubPath(XrGState *gstate, XrSubPath *subpath, XrPath *outline);
+
+static void
+_XrGStateStrokeSegment(XrGState *gstate, const XPointDouble *p0, const XPointDouble *p1, XrPath *outline);
+
+static void
+_XrGStateFillPath(XrGState *gstate, XrPath *path);
+
+static XrGState *
+_XrGStateAlloc(void)
+{
+ return malloc(sizeof(XrGState));
+}
+
+XrGState *
+XrGStateCreate(Display *dpy)
+{
+ XrGState *gstate;
+
+ gstate = _XrGStateAlloc();
+ XrGStateInit(gstate, dpy);
+
+ return gstate;
+}
+
+void
+XrGStateInit(XrGState *gstate, Display *dpy)
+{
+ gstate->dpy = dpy;
+
+ gstate->op = XR_GSTATE_OP_DEFAULT;
+ gstate->winding = XR_GSTATE_WINDING_DEFAULT;
+ gstate->line_width = XR_GSTATE_LINE_WIDTH_DEFAULT;
+
+ gstate->solidFormat = XRenderFindStandardFormat(dpy, PictStandardARGB32);
+ gstate->alphaFormat = XRenderFindStandardFormat(dpy, PictStandardA8);
+
+ XrPictureInit(&gstate->picture, dpy);
+
+ XrPictureInit(&gstate->src, dpy);
+ XrColorInit(&gstate->color);
+ XrPictureSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat);
+
+ XrTransformInit(&gstate->transform);
+
+ XrPathInit(&gstate->path);
+ XrPathInit(&gstate->outline);
+}
+
+void
+XrGStateInitCopy(XrGState *gstate, XrGState *other)
+{
+ *gstate = *other;
+
+ XrPathInitCopy(&gstate->path, &other->path);
+ XrPathInitCopy(&gstate->outline, &other->outline);
+}
+
+void
+XrGStateDeinit(XrGState *gstate)
+{
+ XrColorDeinit(&gstate->color);
+ XrPictureDeinit(&gstate->src);
+ XrPictureDeinit(&gstate->picture);
+ XrTransformInit(&gstate->transform);
+
+ XrPathDeinit(&gstate->path);
+}
+
+void
+XrGStateDestroy(XrGState *gstate)
+{
+ XrGStateDeinit(gstate);
+ free(gstate);
+}
+
+XrGState *
+XrGStateClone(XrGState *gstate)
+{
+ XrGState *clone;
+
+ clone = _XrGStateAlloc();
+
+ XrGStateInitCopy(clone, gstate);
+ return clone;
+}
+
+void
+XrGStateGetCurrentPoint(XrGState *gstate, XPointDouble *pt)
+{
+ XrPathGetCurrentPoint(&gstate->path, pt);
+}
+
+void
+XrGStateSetDrawable(XrGState *gstate, Drawable drawable, Visual *visual)
+{
+ XrPictureSetDrawable(&gstate->picture, drawable, visual);
+}
+
+void
+XrGStateSetColorRGB(XrGState *gstate, double red, double green, double blue)
+{
+ XrColorSetRGB(&gstate->color, red, green, blue);
+ XrPictureSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat);
+}
+
+void
+XrGStateSetAlpha(XrGState *gstate, double alpha)
+{
+ XrColorSetAlpha(&gstate->color, alpha);
+ XrPictureSetSolidColor(&gstate->src, &gstate->color, gstate->solidFormat);
+}
+
+void
+XrGStateSetLineWidth(XrGState *gstate, double width)
+{
+ gstate->line_width = width;
+}
+
+void
+XrGStateTranslate(XrGState *gstate, double tx, double ty)
+{
+ XrTransform new;
+
+ XrTransformInitTranslate(&new, tx, ty);
+ XrTransformCompose(&gstate->transform, &new);
+}
+
+void
+XrGStateScale(XrGState *gstate, double sx, double sy)
+{
+ XrTransform new;
+
+ XrTransformInitScale(&new, sx, sy);
+ XrTransformCompose(&gstate->transform, &new);
+}
+
+void
+XrGStateRotate(XrGState *gstate, double angle)
+{
+ XrTransform new;
+
+ XrTransformInitRotate(&new, angle);
+ XrTransformCompose(&gstate->transform, &new);
+}
+
+void
+XrGStateNewPath(XrGState *gstate)
+{
+ XrPathDeinit(&gstate->path);
+}
+
+void
+XrGStateMoveTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPoint(&gstate->transform, &pt);
+ XrPathMoveTo(&gstate->path, &pt);
+}
+
+void
+XrGStateLineTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPoint(&gstate->transform, &pt);
+ XrPathLineTo(&gstate->path, &pt);
+}
+
+static void
+_TranslatePoint(XPointDouble *pt, const XPointDouble *offset)
+{
+ pt->x += offset->x;
+ pt->y += offset->y;
+}
+
+void
+XrGStateRelMoveTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt, current;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPointWithoutTranslate(&gstate->transform, &pt);
+ XrGStateGetCurrentPoint(gstate, &current);
+ _TranslatePoint(&pt, &current);
+ XrPathMoveTo(&gstate->path, &pt);
+}
+
+void
+XrGStateRelLineTo(XrGState *gstate, double x, double y)
+{
+ XPointDouble pt, current;
+
+ pt.x = x;
+ pt.y = y;
+
+ XrTransformPointWithoutTranslate(&gstate->transform, &pt);
+ XrGStateGetCurrentPoint(gstate, &current);
+ _TranslatePoint(&pt, &current);
+ XrPathLineTo(&gstate->path, &pt);
+}
+
+void
+XrGStateClosePath(XrGState *gstate)
+{
+ XrPathClose(&gstate->path);
+}
+
+void
+XrGStateStroke(XrGState *gstate)
+{
+ int winding_save = gstate->winding;
+
+ gstate->winding = 1;
+ XrPathInit(&gstate->outline);
+ _XrGStateStrokePath(gstate, &gstate->path, &gstate->outline);
+ _XrGStateFillPath(gstate, &gstate->outline);
+ XrPathDeinit(&gstate->outline);
+ gstate->winding = winding_save;
+}
+
+void
+XrGStateFill(XrGState *gstate)
+{
+ _XrGStateFillPath(gstate, &gstate->path);
+}
+
+static void
+_XrGStateStrokePath(XrGState *gstate, XrPath *path, XrPath *outline)
+{
+ XrSubPath *sub;
+
+ for (sub = path->head; sub; sub = sub->next) {
+ if (sub->num_pts) {
+ _XrGStateStrokeSubPath(gstate, sub, outline);
+ }
+ }
+}
+
+static void
+_XrGStateStrokeSubPath(XrGState *gstate, XrSubPath *subpath, XrPath *outline)
+{
+ int i;
+ XPointDouble *p0, *p1;
+
+ XrPathNewSubPath(outline);
+
+ /* Stroke right-side of path forward */
+ for (i = 0; i < subpath->num_pts - 1; i++) {
+ p0 = subpath->pts + i;
+ p1 = p0 + 1;
+
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ }
+
+ /* Close path or add cap as necessary */
+ if (subpath->closed) {
+ p0 = subpath->pts + subpath->num_pts - 1;
+ p1 = subpath->pts;
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ XrPathClose(outline);
+ } else {
+ /* XXX: NYI: Add cap here */
+ }
+
+ /* Stroke right-side of path in reverse */
+ for (i = subpath->num_pts - 1; i > 0; i--) {
+ p0 = subpath->pts + i;
+ p1 = p0 - 1;
+
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ }
+
+ /* Close path or add cap as necessary */
+ if (subpath->closed) {
+ p0 = subpath->pts;
+ p1 = subpath->pts + subpath->num_pts - 1;
+ _XrGStateStrokeSegment(gstate, p0, p1, outline);
+ XrPathClose(outline);
+ } else {
+ /* XXX: NYI: Add cap here */
+ }
+}
+
+static void
+_XrGStateStrokeSegment(XrGState *gstate, const XPointDouble *p0, const XPointDouble *p1, XrPath *outline)
+{
+ double dx, dy, mag;
+ XPointDouble offset;
+ XPointDouble p0_off = *p0;
+ XPointDouble p1_off = *p1;
+
+ dx = p1->x - p0->x;
+ dy = p1->y - p0->y;
+ mag = (gstate->line_width / 2) / sqrt(dx * dx + dy *dy);
+
+ offset.x = -dy * mag;
+ offset.y = dx * mag;
+
+ XrTransformPointWithoutTranslate(&gstate->transform, &offset);
+
+ _TranslatePoint(&p0_off, &offset);
+ XrPathAddPoint(outline, &p0_off);
+
+ _TranslatePoint(&p1_off, &offset);
+ XrPathAddPoint(outline, &p1_off);
+}
+
+static void
+_XrGStateFillPath(XrGState *gstate, XrPath *path)
+{
+ XPolygonDouble *polys;
+ int i, npolys;
+ XrSubPath *subpath;
+
+ npolys = XrPathNumSubPaths(path);
+
+ polys = malloc(npolys * sizeof(XPolygonDouble));
+ if (polys == NULL) {
+ return;
+ }
+
+ for (i=0, subpath = path->head; i < npolys && subpath; i++, subpath = subpath->next) {
+ polys[i].points = subpath->pts;
+ polys[i].npoints = subpath->num_pts;
+ }
+
+ XRenderCompositeDoublePolys(gstate->dpy, gstate->op,
+ gstate->src.picture, gstate->picture.picture,
+ gstate->alphaFormat,
+ 0, 0, 0, 0,
+ polys, npolys,
+ gstate->winding);
+
+ free(polys);
+}
diff --git a/xrint.h b/xrint.h
new file mode 100644
index 000000000..6ac30b0ac
--- /dev/null
+++ b/xrint.h
@@ -0,0 +1,343 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+/*
+ * These definitions are solely for use by the implementation of Xr
+ * and constitute no kind of standard. If you need any of these
+ * functions, please drop me a note. Either the library needs new
+ * functionality, or there's a way to do what you need using the
+ * existing published interfaces. cworth@isi.edu
+ */
+
+#ifndef _XRINT_H_
+#define _XRINT_H_
+
+#include "Xr.h"
+
+typedef struct _XrSubPath {
+ int num_pts;
+ int pts_size;
+ XPointDouble *pts;
+ int closed;
+
+ struct _XrSubPath *next;
+} XrSubPath;
+
+typedef struct _XrPath {
+ XrSubPath *head;
+ XrSubPath *tail;
+} XrPath;
+
+typedef struct _XrPicture {
+ Display *dpy;
+
+ Drawable drawable;
+
+ Visual *visual;
+ unsigned int depth;
+
+ XRenderPictFormat *format;
+ unsigned long pa_mask;
+ XRenderPictureAttributes pa;
+
+ Picture picture;
+ Picture alpha;
+
+ /* XXX: Will also need a mechanism for a non-render picture here */
+} XrPicture;
+
+typedef struct _XrColor {
+ double red;
+ double green;
+ double blue;
+ double alpha;
+
+ XRenderColor render;
+
+ /* XXX: Will also need a mechanism for a non-render color here */
+} XrColor;
+
+
+typedef struct _XrTransform {
+ double matrix[6];
+} XrTransform;
+
+#define XR_GSTATE_OP_DEFAULT PictOpOver
+#define XR_GSTATE_WINDING_DEFAULT 1
+#define XR_GSTATE_LINE_WIDTH_DEFAULT 1.0
+
+typedef struct _XrGState {
+ Display *dpy;
+
+ int op;
+ int winding;
+ double line_width;
+
+ XRenderPictFormat *solidFormat;
+ XRenderPictFormat *alphaFormat;
+
+ XrColor color;
+ XrPicture src;
+ XrPicture picture;
+ XrTransform transform;
+
+ XrPath path;
+ XrPath outline;
+
+ struct _XrGState *next;
+} XrGState;
+
+struct _XrState {
+ Display *dpy;
+ XrGState *stack;
+};
+
+/* xrstate.c */
+
+#define CURRENT_GSTATE(xrs) (xrs->stack)
+
+XrState *
+XrStateCreate(Display *dpy);
+
+void
+XrStateInit(XrState *state, Display *dpy);
+
+void
+XrStateDeinit(XrState *xrs);
+
+void
+XrStateDestroy(XrState *state);
+
+void
+XrStatePush(XrState *xrs);
+
+void
+XrStatePop(XrState *xrs);
+
+/* xrgstate.c */
+XrGState *
+XrGStateCreate(Display *dpy);
+
+XrGState *
+XrGStateClone(XrGState *gstate);
+
+void
+XrGStateInit(XrGState *gstate, Display *dpy);
+
+void
+XrGStateInitCopy(XrGState *gstate, XrGState *other);
+
+void
+XrGStateDeinit(XrGState *gstate);
+
+void
+XrGStateDestroy(XrGState *gstate);
+
+void
+XrGStateGetCurrentPoint(XrGState *gstate, XPointDouble *pt);
+
+void
+XrGStateSetDrawable(XrGState *gstate, Drawable drawable, Visual *visual);
+
+void
+XrGStateSetColorRGB(XrGState *gstate, double red, double green, double blue);
+
+void
+XrGStateSetAlpha(XrGState *gstate, double alpha);
+
+void
+XrGStateSetLineWidth(XrGState *gstate, double width);
+
+void
+XrGStateTranslate(XrGState *gstate, double tx, double ty);
+
+void
+XrGStateScale(XrGState *gstate, double sx, double sy);
+
+void
+XrGStateRotate(XrGState *gstate, double angle);
+
+void
+XrGStateNewPath(XrGState *gstate);
+
+void
+XrGStateMoveTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateLineTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateRelMoveTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateRelLineTo(XrGState *gstate, double x, double y);
+
+void
+XrGStateClosePath(XrGState *gstate);
+
+void
+XrGStateStroke(XrGState *gstate);
+
+void
+XrGStateFill(XrGState *fill);
+
+/* xrcolor.c */
+void
+XrColorInit(XrColor *color);
+
+void
+XrColorDeinit(XrColor *color);
+
+void
+XrColorSetRGB(XrColor *color, double red, double green, double blue);
+
+void
+XrColorSetAlpha(XrColor *color, double alpha);
+
+/* xrpath.c */
+XrPath *
+XrPathCreate(void);
+
+void
+XrPathInit(XrPath *path);
+
+void
+XrPathInitCopy(XrPath *path, XrPath *other);
+
+void
+XrPathReinit(XrPath *path);
+
+void
+XrPathDeinit(XrPath *path);
+
+void
+XrPathDestroy(XrPath *path);
+
+XrPath *
+XrPathClone(XrPath *path);
+
+void
+XrPathGetCurrentPoint(XrPath *path, XPointDouble *pt);
+
+int
+XrPathNumSubPaths(XrPath *path);
+
+void
+XrPathNewSubPath(XrPath *path);
+
+void
+XrPathAddPoint(XrPath *path, const XPointDouble *pt);
+
+void
+XrPathMoveTo(XrPath *path, const XPointDouble *pt);
+
+void
+XrPathLineTo(XrPath *path, const XPointDouble *pt);
+
+void
+XrPathClose(XrPath *path);
+
+/* xrsubpath.c */
+XrSubPath *
+XrSubPathCreate(void);
+
+void
+XrSubPathInit(XrSubPath *path);
+
+void
+XrSubPathInitCopy(XrSubPath *path, XrSubPath *other);
+
+void
+XrSubPathDeinit(XrSubPath *path);
+
+void
+XrSubPathDestroy(XrSubPath *path);
+
+XrSubPath *
+XrSubPathClone(XrSubPath *path);
+
+void
+XrSubPathGetCurrentPoint(XrSubPath *path, XPointDouble *pt);
+
+void
+XrSubPathSetCurrentPoint(XrSubPath *path, const XPointDouble *pt);
+
+void
+XrSubPathAddPoint(XrSubPath *path, const XPointDouble *pt);
+
+void
+XrSubPathClose(XrSubPath *path);
+
+/* xrpicture.c */
+void
+XrPictureInit(XrPicture *picture, Display *dpy);
+
+void
+XrPictureDeinit(XrPicture *picture);
+
+void
+XrPictureSetSolidColor(XrPicture *picture, XrColor *color, XRenderPictFormat *format);
+
+void
+XrPictureSetDrawable(XrPicture *picture, Drawable drawable, Visual *visual);
+
+/* xrtransform.c */
+void
+XrTransformInit(XrTransform *transform);
+
+void
+XrTransformInitMatrix(XrTransform *transform,
+ double a, double b,
+ double c, double d,
+ double tx, double ty);
+
+void
+XrTransformInitTranslate(XrTransform *transform,
+ double tx, double ty);
+
+void
+XrTransformInitScale(XrTransform *transform,
+ double sx, double sy);
+
+void
+XrTransformInitRotate(XrTransform *transform,
+ double angle);
+
+void
+XrTransformDeinit(XrTransform *transform);
+
+void
+XrTransformCompose(XrTransform *t1, const XrTransform *t2);
+
+void
+XrTransformPointWithoutTranslate(XrTransform *transform, XPointDouble *pt);
+
+void
+XrTransformPoint(XrTransform *transform, XPointDouble *pt);
+
+#endif
diff --git a/xrpath.c b/xrpath.c
new file mode 100644
index 000000000..4ee16e437
--- /dev/null
+++ b/xrpath.c
@@ -0,0 +1,169 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include "xrint.h"
+
+/* private functions */
+static void
+_XrPathAddSubPath(XrPath *path, XrSubPath *subpath);
+
+XrPath *
+XrPathCreate(void)
+{
+ XrPath *path;
+
+ path = malloc(sizeof(XrPath));
+ return path;
+}
+
+void
+XrPathInit(XrPath *path)
+{
+ path->head = NULL;
+ path->tail = NULL;
+}
+
+void
+XrPathInitCopy(XrPath *path, XrPath *other)
+{
+ XrSubPath *subpath, *othersub;
+
+ XrPathInit(path);
+
+ for (othersub = other->head; othersub; othersub = othersub->next) {
+ subpath = XrSubPathClone(othersub);
+ _XrPathAddSubPath(path, subpath);
+ }
+}
+
+void
+XrPathDeinit(XrPath *path)
+{
+ XrSubPath *subpath;
+
+ while (path->head) {
+ subpath = path->head;
+ path->head = subpath->next;
+ XrSubPathDestroy(subpath);
+ }
+ path->tail = NULL;
+}
+
+void
+XrPathDestroy(XrPath *path)
+{
+ free(path);
+}
+
+XrPath *
+XrPathClone(XrPath *path)
+{
+ XrPath *clone;
+
+ clone = XrPathCreate();
+ XrPathInitCopy(clone, path);
+ return clone;
+}
+
+void
+XrPathGetCurrentPoint(XrPath *path, XPointDouble *pt)
+{
+ XrSubPathGetCurrentPoint(path->tail, pt);
+}
+
+int
+XrPathNumSubPaths(XrPath *path)
+{
+ XrSubPath *subpath;
+ int num_subpaths;
+
+ num_subpaths = 0;
+ for (subpath = path->head; subpath; subpath = subpath->next) {
+ num_subpaths++;
+ }
+
+ return num_subpaths;
+}
+
+static void
+_XrPathAddSubPath(XrPath *path, XrSubPath *subpath)
+{
+ subpath->next = NULL;
+
+ if (path->tail) {
+ path->tail->next = subpath;
+ } else {
+ path->head = subpath;
+ }
+
+ path->tail = subpath;
+}
+
+void
+XrPathNewSubPath(XrPath *path)
+{
+ XrSubPath *subpath;
+
+ subpath = XrSubPathCreate();
+ _XrPathAddSubPath(path, subpath);
+}
+
+void
+XrPathAddPoint(XrPath *path, const XPointDouble *pt)
+{
+ XrSubPathAddPoint(path->tail, pt);
+}
+
+void
+XrPathMoveTo(XrPath *path, const XPointDouble *pt)
+{
+ XrSubPath *subpath;
+
+ subpath = path->tail;
+
+ if (subpath == NULL || subpath->num_pts > 1) {
+ XrPathNewSubPath(path);
+ XrPathAddPoint(path, pt);
+ } else {
+ XrSubPathSetCurrentPoint(subpath, pt);
+ }
+}
+
+void
+XrPathLineTo(XrPath *path, const XPointDouble *pt)
+{
+ XrPathAddPoint(path, pt);
+}
+
+void
+XrPathClose(XrPath *path)
+{
+ XrSubPathClose(path->tail);
+ XrPathNewSubPath(path);
+}
diff --git a/xrpicture.c b/xrpicture.c
new file mode 100644
index 000000000..79f62e290
--- /dev/null
+++ b/xrpicture.c
@@ -0,0 +1,102 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include "xrint.h"
+
+void
+XrPictureInit(XrPicture *picture, Display *dpy)
+{
+ picture->dpy = dpy;
+
+ picture->drawable = 0;
+
+ picture->depth = 0;
+ picture->visual = 0;
+
+ picture->format = 0;
+ picture->pa_mask = 0;
+
+ picture->picture = 0;
+}
+
+void
+XrPictureDeinit(XrPicture *picture)
+{
+ /* XXX: Leak for now. The problem is that I'm not currently cloning this as I should be sometime during XrSave.
+ if (picture->picture) {
+ XRenderFreePicture(picture->dpy, picture->picture);
+ }
+ */
+}
+
+void
+XrPictureSetSolidColor(XrPicture *picture, XrColor *color, XRenderPictFormat *format)
+{
+ /* XXX: Special handling for depth==1 ala xftdraw.c? */
+
+ if (picture->picture == 0) {
+ Pixmap pix;
+ XRenderPictureAttributes pa;
+
+ pix = XCreatePixmap(picture->dpy, DefaultRootWindow(picture->dpy), 1, 1, format->depth);
+ pa.repeat = True;
+ picture->picture = XRenderCreatePicture(picture->dpy, pix, format, CPRepeat, &pa);
+ XFreePixmap(picture->dpy, pix);
+ }
+
+ XRenderFillRectangle(picture->dpy, PictOpSrc,
+ picture->picture, &color->render,
+ 0, 0, 1, 1);
+}
+
+static void
+_XrPictureFindFormat(XrPicture *picture)
+{
+ if (picture->format) {
+ return;
+ }
+
+ picture->format = XRenderFindVisualFormat(picture->dpy, picture->visual);
+}
+
+void
+XrPictureSetDrawable(XrPicture *picture, Drawable drawable, Visual *visual)
+{
+ if (picture->picture) {
+ XRenderFreePicture(picture->dpy, picture->picture);
+ }
+
+ picture->visual = visual;
+ picture->drawable = drawable;
+
+ _XrPictureFindFormat(picture);
+
+ picture->picture = XRenderCreatePicture(picture->dpy, drawable,
+ picture->format, picture->pa_mask, &picture->pa);
+}
+
diff --git a/xrstate.c b/xrstate.c
new file mode 100644
index 000000000..37c8f501f
--- /dev/null
+++ b/xrstate.c
@@ -0,0 +1,94 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include "xrint.h"
+
+XrState *
+XrStateCreate(Display *dpy)
+{
+ XrState *xrs;
+
+ xrs = malloc(sizeof(XrState));
+
+ XrStateInit(xrs, dpy);
+
+ return xrs;
+}
+
+void
+XrStateInit(XrState *xrs, Display *dpy)
+{
+ xrs->dpy = dpy;
+ xrs->stack = NULL;
+ XrStatePush(xrs);
+}
+
+void
+XrStateDeinit(XrState *xrs)
+{
+ while (xrs->stack) {
+ XrStatePop(xrs);
+ }
+}
+
+void
+XrStateDestroy(XrState *xrs)
+{
+ XrStateDeinit(xrs);
+ free(xrs);
+}
+
+void
+XrStatePush(XrState *xrs)
+{
+ XrGState *top;
+
+ if (xrs->stack) {
+ top = XrGStateClone(xrs->stack);
+ } else {
+ top = XrGStateCreate(xrs->dpy);
+ }
+
+ top->next = xrs->stack;
+ xrs->stack = top;
+}
+
+void
+XrStatePop(XrState *xrs)
+{
+ XrGState *top;
+
+ if (xrs->stack) {
+ top = xrs->stack;
+ xrs->stack = top->next;
+
+ XrGStateDestroy(top);
+ }
+}
+
diff --git a/xrsubpath.c b/xrsubpath.c
new file mode 100644
index 000000000..79384cfcf
--- /dev/null
+++ b/xrsubpath.c
@@ -0,0 +1,147 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include "xrint.h"
+
+#define XR_SUBPATH_GROWTH_INC 10
+
+XrSubPath *
+XrSubPathCreate(void)
+{
+ XrSubPath *path;
+
+ path = malloc(sizeof(XrSubPath));
+
+ XrSubPathInit(path);
+
+ return path;
+}
+
+void
+XrSubPathInit(XrSubPath *path)
+{
+ path->num_pts = 0;
+
+ path->pts_size = 0;
+ path->pts = NULL;
+
+ path->closed = 0;
+
+ path->next = NULL;
+}
+
+void
+XrSubPathInitCopy(XrSubPath *path, XrSubPath *other)
+{
+ *path = *other;
+
+ path->pts = malloc(path->pts_size * sizeof(XPointDouble));
+ *path->pts = *other->pts;
+}
+
+void
+XrSubPathDeinit(XrSubPath *path)
+{
+ if (path->pts_size) {
+ free(path->pts);
+ path->pts_size = 0;
+ path->num_pts = 0;
+ }
+}
+
+void
+XrSubPathDestroy(XrSubPath *path)
+{
+ XrSubPathDeinit(path);
+ free(path);
+}
+
+XrSubPath *
+XrSubPathClone(XrSubPath *path)
+{
+ XrSubPath *clone;
+
+ clone = XrSubPathCreate();
+ XrSubPathInitCopy(clone, path);
+
+ return clone;
+}
+
+void
+XrSubPathGetCurrentPoint(XrSubPath *path, XPointDouble *pt)
+{
+ if (path->num_pts) {
+ *pt = path->pts[path->num_pts-1];
+ } else {
+ /* XXX: What to do for error handling? */
+ }
+}
+
+void
+XrSubPathSetCurrentPoint(XrSubPath *path, const XPointDouble *pt)
+{
+ if (path->num_pts) {
+ path->pts[path->num_pts - 1] = *pt;
+ } else {
+ /* XXX: What to do for error handling? */
+ }
+}
+
+static void
+_XrSubPathGrow(XrSubPath *path)
+{
+ XPointDouble *new_pts;
+
+ path->pts_size += XR_SUBPATH_GROWTH_INC;
+ new_pts = realloc(path->pts, path->pts_size * sizeof(XPointDouble));
+
+ if (new_pts) {
+ path->pts = new_pts;
+ } else {
+ path->pts_size -= XR_SUBPATH_GROWTH_INC;
+ }
+}
+
+void
+XrSubPathAddPoint(XrSubPath *path, const XPointDouble *pt)
+{
+ if (path->num_pts == path->pts_size) {
+ _XrSubPathGrow(path);
+ }
+
+ if (path->num_pts < path->pts_size) {
+ path->pts[path->num_pts++] = *pt;
+ }
+}
+
+void
+XrSubPathClose(XrSubPath *path)
+{
+ path->closed = 1;
+}
diff --git a/xrtransform.c b/xrtransform.c
new file mode 100644
index 000000000..b90d02c70
--- /dev/null
+++ b/xrtransform.c
@@ -0,0 +1,129 @@
+/*
+ * $XFree86: $
+ *
+ * Copyright 2002 University of Southern California
+ *
+ * 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 University
+ * of Southern California not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission. University of Southern California makes
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL UNIVERSITY OF
+ * SOUTHERN CALIFORNIA 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.
+ *
+ * Author: Carl Worth, USC, Information Sciences Institute */
+
+#include <stdlib.h>
+#include <math.h>
+
+#include "xrint.h"
+
+static XrTransform XR_TRANSFORM_DEFAULT = {
+ {1, 0,
+ 0, 1,
+ 0, 0}
+};
+
+void
+XrTransformInit(XrTransform *transform)
+{
+ *transform = XR_TRANSFORM_DEFAULT;
+}
+
+void
+XrTransformInitMatrix(XrTransform *transform,
+ double a, double b,
+ double c, double d,
+ double tx, double ty)
+{
+ transform->matrix[0] = a; transform->matrix[1] = b;
+ transform->matrix[2] = c; transform->matrix[3] = d;
+ transform->matrix[4] = tx; transform->matrix[5] = ty;
+}
+
+void
+XrTransformInitTranslate(XrTransform *transform,
+ double tx, double ty)
+{
+ XrTransformInitMatrix(transform,
+ 1, 0,
+ 0, 1,
+ tx, ty);
+}
+
+void
+XrTransformInitScale(XrTransform *transform,
+ double sx, double sy)
+{
+ XrTransformInitMatrix(transform,
+ sx, 0,
+ 0, sy,
+ 0, 0);
+}
+
+void
+XrTransformInitRotate(XrTransform *transform,
+ double angle)
+{
+ XrTransformInitMatrix(transform,
+ cos(angle), sin(angle),
+ -sin(angle), cos(angle),
+ 0, 0);
+}
+
+void
+XrTransformDeinit(XrTransform *transform)
+{
+ /* Nothing to do here */
+}
+
+void
+XrTransformCompose(XrTransform *t1, const XrTransform *t2)
+{
+ double new[6];
+
+ new[0] = t2->matrix[0] * t1->matrix[0] + t2->matrix[1] * t1->matrix[2];
+ new[1] = t2->matrix[0] * t1->matrix[1] + t2->matrix[1] * t1->matrix[3];
+ new[2] = t2->matrix[2] * t1->matrix[0] + t2->matrix[3] * t1->matrix[2];
+ new[3] = t2->matrix[2] * t1->matrix[1] + t2->matrix[3] * t1->matrix[3];
+ new[4] = t2->matrix[4] * t1->matrix[0] + t2->matrix[5] * t1->matrix[2] + t1->matrix[4];
+ new[5] = t2->matrix[4] * t1->matrix[1] + t2->matrix[5] * t1->matrix[3] + t1->matrix[5];
+
+ memcpy(t1->matrix, new, 6 * sizeof(double));
+}
+
+void
+XrTransformPointWithoutTranslate(XrTransform *transform, XPointDouble *pt)
+{
+ double new_x, new_y;
+
+ new_x = (transform->matrix[0] * pt->x
+ + transform->matrix[2] * pt->y);
+ new_y = (transform->matrix[1] * pt->x
+ + transform->matrix[3] * pt->y);
+
+ pt->x = new_x;
+ pt->y = new_y;
+}
+
+void
+XrTransformPoint(XrTransform *transform, XPointDouble *pt)
+{
+ XrTransformPointWithoutTranslate(transform, pt);
+
+ pt->x += transform->matrix[4];
+ pt->y += transform->matrix[5];
+}