[cairo-commit] cairo-5c ChangeLog, 1.7, 1.8 cairo-5c.h, 1.4,
1.5 cairo.5c, 1.1, 1.2 draw.c, 1.3, 1.4 init.c, 1.5,
1.6 surface.c, 1.4, 1.5
Keith Packard
commit at pdx.freedesktop.org
Fri Dec 17 01:40:45 PST 2004
Committed by: keithp
Update of /cvs/cairo/cairo-5c
In directory gabe:/tmp/cvs-serv24992
Modified Files:
ChangeLog cairo-5c.h cairo.5c draw.c init.c surface.c
Log Message:
2004-12-17 Keith Packard <keithp at keithp.com>
* cairo-5c.h:
* cairo.5c:
* draw.c: (path_new), (path_box), (cairo_5c_move_to),
(cairo_5c_line_to), (cairo_5c_curve_to), (cairo_5c_close_path),
(do_Cairo_current_path_list), (do_Cairo_current_path_flat_list):
* init.c: (make_typedef), (init_types), (nickle_init):
* surface.c: (get_cairo_5c):
Add current_path/current_path_flat by creating nickle structure in C
code holding the entire path and walking it in nickle code.
* examples/.cvsignore:
ignore build files
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-5c/ChangeLog,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ChangeLog 17 Dec 2004 02:11:25 -0000 1.7
+++ ChangeLog 17 Dec 2004 09:40:43 -0000 1.8
@@ -1,3 +1,18 @@
+2004-12-17 Keith Packard <keithp at keithp.com>
+
+ * cairo-5c.h:
+ * cairo.5c:
+ * draw.c: (path_new), (path_box), (cairo_5c_move_to),
+ (cairo_5c_line_to), (cairo_5c_curve_to), (cairo_5c_close_path),
+ (do_Cairo_current_path_list), (do_Cairo_current_path_flat_list):
+ * init.c: (make_typedef), (init_types), (nickle_init):
+ * surface.c: (get_cairo_5c):
+ Add current_path/current_path_flat by creating nickle structure in C
+ code holding the entire path and walking it in nickle code.
+
+ * examples/.cvsignore:
+ ignore build files
+
2004-12-16 Keith Packard <keithp at keithp.com>
* examples/Makefile.am:
Index: cairo-5c.h
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo-5c.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairo-5c.h 17 Dec 2004 02:09:45 -0000 1.4
+++ cairo-5c.h 17 Dec 2004 09:40:43 -0000 1.5
@@ -84,6 +84,12 @@
extern Type *typeCairoPoint;
extern Type *typeCairoRect;
extern Type *typeCairoRgbColor;
+extern Type *typeCairoPattern;
+extern Type *typeCairoPath;
+extern Type *typeCairoMoveTo;
+extern Type *typeCairoLineTo;
+extern Type *typeCairoCurveTo;
+extern Type *typeCairoClosePath;
/* surface.c */
cairo_5c_t *
@@ -308,10 +314,10 @@
do_Cairo_fill_extents (Value cv);
Value
-do_Cairo_current_path (Value cv, Value mv, Value lv, Value cuv, Value clp);
+do_Cairo_current_path_list (Value cv);
Value
-do_Cairo_current_path_flat (Value cv, Value mv, Value lv, Value np);
+do_Cairo_current_path_flat_list (Value cv);
/* text.c */
Value
Index: cairo.5c
===================================================================
RCS file: /cvs/cairo/cairo-5c/cairo.5c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cairo.5c 17 Dec 2004 02:09:45 -0000 1.1
+++ cairo.5c 17 Dec 2004 09:40:43 -0000 1.2
@@ -37,5 +37,73 @@
Foreign::load ("libcairo-5c.so");
extend namespace Cairo {
+
+ public typedef void (real x, real y) move_to_func_t;
+ public typedef void (real x, real y) line_to_func_t;
+ public typedef void (real x1, real y1, real x2, real y2, real x3, real y3) curve_to_func_t;
+ public typedef void () close_path_func_t;
+
+ void walk_path (path_t path,
+ move_to_func_t move_to,
+ line_to_func_t line_to,
+ curve_to_func_t curve_to,
+ close_path_func_t close_path)
+ {
+ while (path != path_t.end)
+ {
+ union switch (path) {
+ case move_to m:
+ move_to (m->x, m->y);
+ path = m->next;
+ break;
+ case line_to l:
+ line_to (l->x, l->y);
+ path = l->next;
+ break;
+ case curve_to c:
+ curve_to (c->x1, c->y1, c->x2, c->y2, c->x3, c->y3);
+ path = c->next;
+ break;
+ case close_path c:
+ close_path ();
+ path = c->next;
+ break;
+ case end:
+ break;
+ }
+ }
+ }
+
+ public void current_path (cairo_t cr,
+ move_to_func_t move_to,
+ line_to_func_t line_to,
+ curve_to_func_t curve_to,
+ close_path_func_t close_path)
+ /*
+ * Walk path calling provided functions for matching
+ * elements sequentially
+ */
+ {
+ walk_path (current_path_list (cr),
+ move_to, line_to, curve_to, close_path);
+ }
+
+ public void current_path_flat (cairo_t cr,
+ move_to_func_t move_to,
+ line_to_func_t line_to,
+ close_path_func_t close_path)
+ /*
+ * Walk path calling provided functions for matching
+ * elements sequentially. Curves are replaced by
+ * lines as needed to meet current_tolerance
+ */
+ {
+ void no_curve_to (real x1, real y1, real x2, real y2, real x2, real y3)
+ {
+ abort ("flat paths have no curves", cr);
+ }
+ walk_path (current_path_flat_list (cr),
+ move_to, line_to, no_curve_to, close_path);
+ }
}
Index: draw.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/draw.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- draw.c 17 Dec 2004 02:09:45 -0000 1.3
+++ draw.c 17 Dec 2004 09:40:43 -0000 1.4
@@ -281,25 +281,124 @@
RETURN (ret);
}
-#if 0
+typedef struct _path_closure {
+ Value head;
+ Value *tail;
+} path_closure_t;
+
+static Value
+path_new (char *tag, Value value)
+{
+ ENTER ();
+ Value pt = NewUnion (TypeCanon (typeCairoPath)->structs.structs, False);
+ BoxPtr box = pt->unions.value;
+ pt->unions.tag = AtomId (tag);
+ BoxValueSet (box, 0, value);
+ RETURN (pt);
+}
+
+static Value
+path_box (void *closure, Type *type, char *tag)
+{
+ ENTER ();
+ path_closure_t *pc = closure;
+ Value elt = NewStruct (TypeCanon (type)->structs.structs, False);
+ Value elt_ref = NewRef (NewBox (False, False, 1, type), 0);
+ Value path = path_new (tag, elt_ref);
+ BoxPtr box = elt->structs.values;
+
+ RefValueSet (elt_ref, elt);
+ /* move End element after this element */
+ BoxValueSet (box, 0, *pc->tail);
+ /* append element to list */
+ *pc->tail = path;
+ pc->tail = &BoxElements(box)[0];
+ RETURN (elt);
+}
+
static void
cairo_5c_move_to (void *closure, double x, double y)
{
ENTER ();
+ Value elt = path_box (closure, typeCairoMoveTo, "move_to");
+ BoxPtr box = elt->structs.values;
+ BoxValueSet (box, 1, NewDoubleFloat (x));
+ BoxValueSet (box, 2, NewDoubleFloat (y));
+ EXIT ();
+}
+
+static void
+cairo_5c_line_to (void *closure, double x, double y)
+{
+ ENTER ();
+ Value elt = path_box (closure, typeCairoLineTo, "line_to");
+ BoxPtr box = elt->structs.values;
+ BoxValueSet (box, 1, NewDoubleFloat (x));
+ BoxValueSet (box, 2, NewDoubleFloat (y));
+ EXIT ();
+}
+
+static void
+cairo_5c_curve_to (void *closure,
+ double x1, double y1,
+ double x2, double y2,
+ double x3, double y3)
+{
+ ENTER ();
+ Value elt = path_box (closure, typeCairoCurveTo, "curve_to");
+ BoxPtr box = elt->structs.values;
+ BoxValueSet (box, 1, NewDoubleFloat (x1));
+ BoxValueSet (box, 2, NewDoubleFloat (y1));
+ BoxValueSet (box, 3, NewDoubleFloat (x2));
+ BoxValueSet (box, 4, NewDoubleFloat (y2));
+ BoxValueSet (box, 5, NewDoubleFloat (x3));
+ BoxValueSet (box, 6, NewDoubleFloat (y3));
+ EXIT ();
+}
+
+static void
+cairo_5c_close_path (void *closure)
+{
+ ENTER ();
+ (void) path_box (closure, typeCairoClosePath, "close_path");
EXIT ();
}
-#endif
Value
-do_Cairo_current_path (Value cv, Value mv, Value lv, Value cuv, Value clp)
+do_Cairo_current_path_list (Value cv)
{
- /* XXX */
- return Void;
+ ENTER ();
+ path_closure_t close;
+ cairo_5c_t *c5c = get_cairo_5c (cv);
+
+ if (aborting)
+ RETURN (Void);
+ close.head = path_new ("end", Void);
+ close.tail = &close.head;
+ cairo_current_path (c5c->cr,
+ cairo_5c_move_to,
+ cairo_5c_line_to,
+ cairo_5c_curve_to,
+ cairo_5c_close_path,
+ &close);
+ RETURN(close.head);
}
Value
-do_Cairo_current_path_flat (Value cv, Value mv, Value lv, Value clp)
+do_Cairo_current_path_flat_list (Value cv)
{
- /* XXX */
- return Void;
+ ENTER ();
+ path_closure_t close;
+ cairo_5c_t *c5c = get_cairo_5c (cv);
+
+ if (aborting)
+ RETURN (Void);
+ close.head = path_new ("end", Void);
+ close.tail = &close.head;
+ cairo_current_path_flat (c5c->cr,
+ cairo_5c_move_to,
+ cairo_5c_line_to,
+ cairo_5c_close_path,
+ &close);
+ RETURN(close.head);
}
Index: init.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/init.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- init.c 17 Dec 2004 02:09:45 -0000 1.5
+++ init.c 17 Dec 2004 09:40:43 -0000 1.6
@@ -49,6 +49,12 @@
Type *typeCairoPoint;
Type *typeCairoRect;
Type *typeCairoRgbColor;
+Type *typeCairoPattern;
+Type *typeCairoPath;
+Type *typeCairoMoveTo;
+Type *typeCairoLineTo;
+Type *typeCairoCurveTo;
+Type *typeCairoClosePath;
#define CAIRO_I 0
#define CAIRO_S "00"
@@ -76,11 +82,25 @@
#define RECT_S "11"
#define RGB_COLOR_I 12
#define RGB_COLOR_S "12"
+#define PATTERN_I 13
+#define PATTERN_S "13"
+#define PATH_I 14
+#define PATH_S "14"
+#define MOVE_TO_I 15
+#define MOVE_TO_S "15"
+#define LINE_TO_I 16
+#define LINE_TO_S "16"
+#define CURVE_TO_I 17
+#define CURVE_TO_S "17"
+#define CLOSE_PATH_I 18
+#define CLOSE_PATH_S "18"
static Type *
-make_typedef (char *name_str,
- int usertype_id,
- Type *type)
+make_typedef (char *name_str,
+ Publish publish,
+ int usertype_id,
+ Symbol **sret,
+ Type *type)
{
ENTER ();
Atom name = AtomId (name_str);
@@ -88,26 +108,33 @@
Type *typed = NewTypeName (NewExprAtom (name, 0, False),
sym);
- NamespaceAddName (CairoNamespace, sym, publish_public);
+ NamespaceAddName (CairoNamespace, sym, publish);
BuiltinSetUserdefType (typed, usertype_id);
MemAddRoot (typed);
+ if (sret)
+ *sret = sym;
RETURN (typed);
}
static void
init_types (void)
{
+ Symbol *mt, *lt, *ct, *cp, *path;
ENTER ();
CairoNamespace = BuiltinNamespace (/* parent */ 0, "Cairo")->namespace.namespace;
typeCairo = make_typedef ("cairo_t",
+ publish_public,
CAIRO_I,
+ NULL,
typePrim[rep_foreign]);
typeCairoStatus = make_typedef ("status_t",
+ publish_public,
STATUS_I,
+ NULL,
BuildEnumType (8,
"SUCCESS",
"NO_MEMORY",
@@ -118,7 +145,9 @@
"NO_TARGET_SURFACE",
"NULL_POINTER"));
typeCairoOperator = make_typedef ("operator_t",
+ publish_public,
OPERATOR_I,
+ NULL,
BuildEnumType (14,
"CLEAR",
"SRC",
@@ -136,39 +165,51 @@
"SATURATE"));
typeCairoFillRule = make_typedef ("fill_rule_t",
+ publish_public,
FILL_RULE_I,
+ NULL,
BuildEnumType (2,
"WINDING",
"EVEN_ODD"));
typeCairoLineCap = make_typedef ("line_cap_t",
+ publish_public,
LINE_CAP_I,
+ NULL,
BuildEnumType (3,
"BUTT",
"ROUND",
"SQUARE"));
typeCairoLineJoin = make_typedef ("line_join_t",
+ publish_public,
LINE_JOIN_I,
+ NULL,
BuildEnumType (3,
"MITER",
"ROUND",
"BEVEL"));
typeCairoFontSlant = make_typedef ("font_slant_t",
+ publish_public,
FONT_SLANT_I,
+ NULL,
BuildEnumType (3,
"NORMAL",
"ITALIC",
"OBLIQUE"));
typeCairoFontWeight = make_typedef ("font_weight_t",
+ publish_public,
FONT_WEIGHT_I,
+ NULL,
BuildEnumType (2,
"NORMAL",
"BOLD"));
typeCairoTextExtents = make_typedef ("text_extents_t",
+ publish_public,
TEXT_EXTENTS_I,
+ NULL,
BuildStructType (6,
typePrim[rep_float], "x_bearing",
typePrim[rep_float], "y_bearing",
@@ -177,18 +218,24 @@
typePrim[rep_float], "x_advance",
typePrim[rep_float], "y_advance"));
typeCairoMatrix = make_typedef ("matrix_t",
+ publish_public,
MATRIX_I,
+ NULL,
BuildArrayType (typePrim[rep_float],
2, 2, 3));
typeCairoPoint = make_typedef ("point_t",
+ publish_public,
POINT_I,
+ NULL,
BuildStructType (2,
typePrim[rep_float], "x",
typePrim[rep_float], "y"));
typeCairoRect = make_typedef ("rect_t",
+ publish_public,
RECT_I,
+ NULL,
BuildStructType (4,
typePrim[rep_float], "x",
typePrim[rep_float], "y",
@@ -196,12 +243,81 @@
typePrim[rep_float], "height"));
typeCairoRgbColor = make_typedef ("rgb_color_t",
+ publish_public,
RGB_COLOR_I,
+ NULL,
BuildStructType (3,
typePrim[rep_float], "red",
typePrim[rep_float], "green",
typePrim[rep_float], "blue"));
-
+
+ typeCairoPattern = make_typedef ("pattern_t",
+ publish_public,
+ PATTERN_I,
+ NULL,
+ typePrim[rep_foreign]);
+
+ /*
+ * Recursive datatypes aren't supported by the simple API
+ */
+
+ typeCairoMoveTo = make_typedef ("move_to_t",
+ publish_public,
+ MOVE_TO_I,
+ &mt,
+ 0);
+
+ typeCairoLineTo = make_typedef ("line_to_t",
+ publish_public,
+ LINE_TO_I,
+ <,
+ 0);
+
+ typeCairoCurveTo = make_typedef ("curve_to_t",
+ publish_public,
+ CURVE_TO_I,
+ &ct,
+ 0);
+
+ typeCairoClosePath = make_typedef ("close_path_t",
+ publish_public,
+ CLOSE_PATH_I,
+ &cp,
+ 0);
+
+ typeCairoPath = make_typedef ("path_t",
+ publish_public,
+ PATH_I,
+ &path,
+ BuildUnionType(5,
+ NewTypeRef (typeCairoMoveTo, True), "move_to",
+ NewTypeRef (typeCairoLineTo, True), "line_to",
+ NewTypeRef (typeCairoCurveTo, True), "curve_to",
+ NewTypeRef (typeCairoClosePath, True), "close_path",
+ typePrim[rep_void], "end"));
+
+ mt->symbol.type = BuildStructType (3,
+ typeCairoPath, "next",
+ typePrim[rep_float], "x",
+ typePrim[rep_float], "y");
+
+ lt->symbol.type = BuildStructType (3,
+ typeCairoPath, "next",
+ typePrim[rep_float], "x",
+ typePrim[rep_float], "y");
+
+ ct->symbol.type = BuildStructType (7,
+ typeCairoPath, "next",
+ typePrim[rep_float], "x1",
+ typePrim[rep_float], "y1",
+ typePrim[rep_float], "x2",
+ typePrim[rep_float], "y2",
+ typePrim[rep_float], "x3",
+ typePrim[rep_float], "y3");
+
+ cp->symbol.type = BuildStructType (1,
+ typeCairoPath, "next");
+
EXIT();
}
@@ -246,6 +362,7 @@
nickle_init (void)
{
ENTER ();
+
static const struct fbuiltin_v funcs_v[] = {
{ do_Cairo_new, "new", CAIRO_S, ".i", "\n"
" cairo_t new (int...)\n"
@@ -317,6 +434,16 @@
"\n"
" Stroke the current path\n" },
+ { do_Cairo_current_path_flat_list, "current_path_flat_list", PATH_S, CAIRO_S, "\n"
+ " void current_path_flat (cairo_t cr)\n"
+ "\n"
+ " Returns the current path with curves tesselated to lines\n" },
+
+ { do_Cairo_current_path_list, "current_path_list", PATH_S, CAIRO_S, "\n"
+ " void current_path (cairo_t cr)\n"
+ "\n"
+ " Returns the current path\n" },
+
{ do_Cairo_init_clip, "init_clip", "v", CAIRO_S, "\n"
" void init_clip (cairo_t cairo)\n"
"\n"
Index: surface.c
===================================================================
RCS file: /cvs/cairo/cairo-5c/surface.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- surface.c 17 Dec 2004 02:09:45 -0000 1.4
+++ surface.c 17 Dec 2004 09:40:43 -0000 1.5
@@ -45,7 +45,7 @@
if (av->foreign.id != CairoId)
{
RaiseStandardException (exception_invalid_argument,
- "not a cairo",
+ "not a cairo_t",
2, NewInt(0), av);
return 0;
}
More information about the cairo-commit
mailing list