October 9, 1997 D. Ryan Willhoit OVERVIEW This is release 1 of my patch to allow the GDK to support bezier curves. It adds several functions to the library handling a variety of bezier curves. It also makes a minor correction to the polygon function which contained an error. (The error was that if the polygon was not closed then to close it another line was simply drawn, but if I understand things correctly this would not correctly join this line to the others! I fixed this.) Hopefully I did everything right. Note that I implement the way to compute the bezier in two different ways. Comparing performance on my Pentium Pro shows that the default one is faster, but on machines with a lighter weight FPU I think the other might end up being better. To use the other one #define ALTERNATE_BEZIER_IMPLEMENTATION I tested this stuff but not extensively - there could be bugs! Also there could be areas where performance could be boasted. I didn't add this info to the documentation... The following datatype is added: struct GdkBezierSegment { gint16 x1; gint16 y1; gint16 x2; gint16 y2; gint16 x3; gint16 y3; gint16 x4; gint16 y4; } The following functions are added: [Note in all functions: subs is the number of subdivisions the bezier should have. All line styles, etc in the GC apply to the bezier.] /*This draws a 3rd degree bezier curve defined by the four points. */ void gdk_draw_bezier (GdkDrawable *drawable, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gint x3, gint y3, gint x4, gint y4, gint subs); /* This draws discontinous bezier segments */ void gdk_draw_bezier_segments (GdkDrawable *drawable, GdkGC *gc, GdkBezierSegment *segments, gint nsegments, gint subs); /* This draws a curve of several continious beziers. The points array should contain data like this: 2 3 / ..... \ 1 . . 4 . ..7 \ ..... / 5 6 Okay its crude but hopefully gets the picture across. BTW 3 and 5 do not have to be symmetric around 4. */ void gdk_draw_poly_bezier (GdkDrawable *drawable, GdkGC *gc, GdkPoint *points, gint npoints, gint subs); /* This draws a closed poly bezier. Like above except that it assumes that the last point it is given is the same as the first point. Make sure this is the case! Perhaps sometime I will make it more robust but since it would be hard to decide how best to close the bezier just close it yourself! Note it fills as per the winding rule in the GC. */ void gdk_draw_closed_poly_bezier(GdkDrawable *drawable, GdkGC *gc, gint filled, GdkPoint *points, gint npoints, gint subs); INSTALLATION To patch all you should have to do if the gtk is in the directory gtk+970925 is put the patch in the directory above it and type patch < willhoit_gdk_patch.1 Hopefully I got the patch cleanly. make distclean didn't seem to clean out all the junk (somebody maybe could fix this?) Also note that while I would like to retain my copyright to this material its here b/c I thought it would of general use to the GTK community and as a result it probably falls under the same license as the GTK. MY WISHLIST 1. The number one thing I would like to see would be the ability to draw a character that is under an arbitrary matrix transform. That way we could skew, rotate, etc. text easily. I'd add this expect I'm not 100% sure where to really start - X doesn't seem to want to do that. I've investigated using a program like FreeType to do it for me, but that requires TTF when X uses Type 1, and I'd rather not have to have users convert/install special fonts just for use with a program I am writing... 2. Versions of the drawing commands that can do antialiasing. 3. C++ wrappers. (Yes I am following G--) 4. An interface builder (Gubi is looking good...)