[Commit] twin ChangeLog, 1.9, 1.10 twin_convolve.c, 1.5, 1.6 twin_font.c, 1.5, 1.6 xtwin.c, 1.8, 1.9

Keith Packard commit at keithp.com
Sun Sep 26 02:44:31 PDT 2004


Committed by: keithp

Update of /local/src/CVS/twin
In directory home.keithp.com:/tmp/cvs-serv12112

Modified Files:
	ChangeLog twin_convolve.c twin_font.c xtwin.c 
Log Message:
2004-09-26  Keith Packard  <keithp at keithp.com>

	* twin_convolve.c: (_twin_subpath_convolve):
	Eliminate special case for closed paths.  Just draw caps at
	both ends and accept that the resulting path isn't minimal
	in all cases.  This eliminates the weird results from said
	attempted minimal path with large pens and small curves.
	It also eliminated a lot of extra code from this function.
	
	* twin_font.c: (twin_path_ucs4):
	Fix font baseline value (should be 9).  Take pen size
	into account when computing positions so that glyphs rest
	on the baseline instead of painting on top of it.

	* xtwin.c: (main):
	Show baseline in huge text sample


Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/twin/ChangeLog,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ChangeLog	26 Sep 2004 09:23:23 -0000	1.9
+++ ChangeLog	26 Sep 2004 09:44:29 -0000	1.10
@@ -1,5 +1,22 @@
 2004-09-26  Keith Packard  <keithp at keithp.com>
 
+	* twin_convolve.c: (_twin_subpath_convolve):
+	Eliminate special case for closed paths.  Just draw caps at
+	both ends and accept that the resulting path isn't minimal
+	in all cases.  This eliminates the weird results from said
+	attempted minimal path with large pens and small curves.
+	It also eliminated a lot of extra code from this function.
+	
+	* twin_font.c: (twin_path_ucs4):
+	Fix font baseline value (should be 9).  Take pen size
+	into account when computing positions so that glyphs rest
+	on the baseline instead of painting on top of it.
+
+	* xtwin.c: (main):
+	Show baseline in huge text sample
+
+2004-09-26  Keith Packard  <keithp at keithp.com>
+
 	* twin.h:
 	* twin_convolve.c: (_twin_path_leftpoint), (_twin_path_step),
 	(_twin_subpath_convolve):

Index: twin_convolve.c
===================================================================
RCS file: /local/src/CVS/twin/twin_convolve.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- twin_convolve.c	26 Sep 2004 09:23:23 -0000	1.5
+++ twin_convolve.c	26 Sep 2004 09:44:29 -0000	1.6
@@ -58,31 +58,6 @@
     return best;
 }
 
-/*
- * step along a path avoiding coincident points.  These
- * occur in closed paths where the first and final points are
- * always the same
- */
-
-static int
-_twin_path_step (twin_point_t	*points,
-		 int		npoints,
-		 int		p,
-		 int		inc)
-{
-    int n = p;
-
-    for (;;)
-    {
-	n += inc;
-	if (n < 0) n += npoints;
-	else if (n >= npoints) n -= npoints;
-	if (points[n].x != points[p].x || points[n].y != points[p].y)
-	    break;
-    }
-    return n;
-}
-
 static int
 _around_order (twin_point_t    *a1,
 	       twin_point_t    *a2,
@@ -134,26 +109,21 @@
     int		    ns    = stroke->npoints;
     int		    np    = pen->npoints;
     twin_point_t    *sp0  = &sp[0];
-    twin_point_t    *sp1  = &sp[_twin_path_step(sp,ns,0,1)];
+    twin_point_t    *sp1  = &sp[1];
     int		    start = _twin_path_leftpoint (pen, sp0, sp1);
     twin_point_t    *spn1 = &sp[ns-1];
-    twin_point_t    *spn2 = &sp[_twin_path_step(sp,ns,ns-1,-1)];
+    twin_point_t    *spn2 = &sp[ns-2];
     int		    ret   = _twin_path_leftpoint (pen, spn1, spn2);
     int		    p;
     int		    s;
     int		    starget;
     int		    ptarget;
     int		    inc;
-    twin_bool_t	    closed = TWIN_FALSE;
-
-    if (sp[0].x == sp[ns - 1].x && sp[0].y == sp[ns - 1].y)
-	closed = TWIN_TRUE;
 
-    DBGOUT ("convolve: closed(%s)\n", closed ? "true" : "false");
-    DBGOUT ("stroke:\n");
+    DBGOUT ("convolve stroke:\n");
     for (s = 0; s < ns; s++)
 	DBGOUT ("\ts%02d: %9.4f, %9.4f\n", s, F(sp[s].x), F(sp[s].y));
-    DBGOUT ("pen:\n");
+    DBGOUT ("convolve pen:\n");
     for (p = 0; p < np; p++)
 	DBGOUT ("\tp%02d: %9.4f, %9.4f\n", p, F(pp[p].x), F(pp[p].y));
     
@@ -168,16 +138,8 @@
     
     /* step along the path first */
     inc = 1;
-    if (closed)
-    {
-	starget = ns-1;
-	ptarget = start;
-    }
-    else
-    {
-	starget = ns-1;
-	ptarget = ret;
-    }
+    starget = ns-1;
+    ptarget = ret;
     for (;;)
     {
 	/*
@@ -185,10 +147,9 @@
 	 */
 	do
 	{
-	    int	sn = _twin_path_step(sp,ns,s,inc);
+	    int	sn = s + inc;
 	    int	pn = (p == np - 1) ? 0 : p + 1;
 	    int	pm = (p == 0) ? np - 1 : p - 1;
-	    int o;
     
 	    /*
 	     * step along pen (forwards or backwards) or stroke as appropriate
@@ -198,14 +159,12 @@
 		    _angle (&sp[s], &sp[sn]),
 		    _angle (&pp[p], &pp[pn]),
 		    _angle (&pp[pm], &pp[p]));
-	    o = _around_order (&sp[s],&sp[sn],&pp[p],&pp[pn]);
-	    if (o > 0 || (o == 0 && (closed && s == starget)))
+	    if (_around_order (&sp[s],&sp[sn],&pp[p],&pp[pn]) > 0)
 	    {
 		DBGOUT ("+pen:   ");
 		p = pn;
 	    }
-	    else if ((s == starget && closed)
-		     || _around_order (&sp[s],&sp[sn],&pp[pm],&pp[p]) < 0)
+	    else if (_around_order (&sp[s],&sp[sn],&pp[pm],&pp[p]) < 0)
 	    {
 		DBGOUT ("-pen:   ");
 		p = pm;
@@ -220,29 +179,22 @@
 		    p, F(pp[p].x), F(pp[p].y),
 		    F(sp[s].x + pp[p].x), F(sp[s].y + pp[p].y));
 	    twin_path_draw (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y);
-	} while (s != starget || (closed && p != ptarget));
+	} while (s != starget);
 	
 	/*
 	 * Finish this edge
 	 */
 	
-	if (closed)
-	{
-	    twin_path_close (path);
-	}
-	else
+	/* draw a cap */
+	while (p != ptarget)
 	{
-	    /* draw a cap */
-	    while (p != ptarget)
-	    {
-		if (++p == np) p = 0;
-		DBGOUT("cap:    ");
-		DBGOUT ("s%02d (%9.4f, %9.4f), p%02d (%9.4f, %9.4f): %9.4f, %9.4f\n",
-			s, F(sp[s].x), F(sp[s].y),
-			p, F(pp[p].x), F(pp[p].y),
-			F(sp[s].x + pp[p].x), F(sp[s].y + pp[p].y));
-		twin_path_draw (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y);
-	    }
+	    if (++p == np) p = 0;
+	    DBGOUT("cap:    ");
+	    DBGOUT ("s%02d (%9.4f, %9.4f), p%02d (%9.4f, %9.4f): %9.4f, %9.4f\n",
+		    s, F(sp[s].x), F(sp[s].y),
+		    p, F(pp[p].x), F(pp[p].y),
+		    F(sp[s].x + pp[p].x), F(sp[s].y + pp[p].y));
+	    twin_path_draw (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y);
 	}
 	
 	if (inc == -1)
@@ -250,19 +202,8 @@
 	
 	/* reach the end of the path?  Go back the other way now */
 	inc = -1;
-	
-	if (closed)
-	{
-	    p = ret;
-	    ptarget = ret;
-	    starget = 0;
-	    twin_path_move (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y);
-	}
-	else
-	{
-	    ptarget = start;
-	    starget = 0;
-	}
+	ptarget = start;
+	starget = 0;
     }
 }
 

Index: twin_font.c
===================================================================
RCS file: /local/src/CVS/twin/twin_font.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- twin_font.c	25 Sep 2004 07:30:58 -0000	1.5
+++ twin_font.c	26 Sep 2004 09:44:29 -0000	1.6
@@ -112,6 +112,8 @@
     return _twin_glyphs + _twin_glyph_offsets[ucs4];
 }
 
+#define TWIN_FONT_BASELINE  9
+
 void
 twin_path_ucs4 (twin_path_t	*path, 
 		twin_fixed_t	scale_x,
@@ -205,7 +207,7 @@
     twin_path_circle (pen, pen_size);
 
     xc = SNAPI(xo - SX (p[0].x)) + pen_adjust;
-    yc = SNAPI(yo - SY (16)) + pen_adjust;
+    yc = SNAPI(yo - SY (TWIN_FONT_BASELINE) - pen_size) + pen_adjust;
 
     for (i = 1; p[i].y != -64; i++)
 	if (p[i].x == -64)

Index: xtwin.c
===================================================================
RCS file: /local/src/CVS/twin/xtwin.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- xtwin.c	26 Sep 2004 09:23:23 -0000	1.8
+++ xtwin.c	26 Sep 2004 09:44:29 -0000	1.9
@@ -77,14 +77,18 @@
 #endif
 #if 1
     stroke = twin_path_create ();
-    twin_path_move (stroke, D(-1), D(7));
-    twin_path_string (stroke, D(20), D(20), TWIN_TEXT_BOLD, ".");
-/*    twin_path_convolve (path, stroke, pen); */
-    twin_path_append (path, stroke);
+    twin_path_move (stroke, D(30), D(400));
+    twin_path_string (stroke, D(200), D(200), TWIN_TEXT_ROMAN, "jelly world.");
+    twin_path_convolve (path, stroke, pen);
+/*    twin_path_append (path, stroke); */
     twin_path_destroy (stroke);
+    stroke = twin_path_create ();
+    twin_path_move (stroke, D(30), D(400));
+    twin_path_draw (stroke, D(1000), D(400));
+    twin_path_convolve (path, stroke, pen);
 #endif
     
-#if 0
+#if 1
     fx = D(3);
     fy = 0;
     for (g = 8; g < 30; g += 4)




More information about the Commit mailing list