aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2004-09-26 09:44:29 +0000
committerKeith Packard <keithp@keithp.com>2004-09-26 09:44:29 +0000
commit9020db18ff228c628758f4766bad1a148e4dedbc (patch)
tree5d2c6ad0896b6020bfdd86a4d673d38882efd63d
parent4a7e68c133df46045206d2ab8b21f2f1a6a2dd10 (diff)
downloadlibtwin-9020db18ff228c628758f4766bad1a148e4dedbc.tar.gz
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. 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. Show baseline in huge text sample
-rw-r--r--ChangeLog17
-rw-r--r--twin_convolve.c101
-rw-r--r--twin_font.c4
-rw-r--r--xtwin.c14
4 files changed, 50 insertions, 86 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b51c7e..0a1362b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2004-09-26 Keith Packard <keithp@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@keithp.com>
+
* twin.h:
* twin_convolve.c: (_twin_path_leftpoint), (_twin_path_step),
(_twin_subpath_convolve):
diff --git a/twin_convolve.c b/twin_convolve.c
index 54b3c0f..6451171 100644
--- a/twin_convolve.c
+++ b/twin_convolve.c
@@ -58,31 +58,6 @@ _twin_path_leftpoint (twin_path_t *path,
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 @@ _twin_subpath_convolve (twin_path_t *path,
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 @@ _twin_subpath_convolve (twin_path_t *path,
/* 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 @@ _twin_subpath_convolve (twin_path_t *path,
*/
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 @@ _twin_subpath_convolve (twin_path_t *path,
_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 @@ _twin_subpath_convolve (twin_path_t *path,
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)
+ /* draw a cap */
+ while (p != ptarget)
{
- twin_path_close (path);
- }
- else
- {
- /* 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 @@ _twin_subpath_convolve (twin_path_t *path,
/* 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;
}
}
diff --git a/twin_font.c b/twin_font.c
index e802371..d68a8fb 100644
--- a/twin_font.c
+++ b/twin_font.c
@@ -112,6 +112,8 @@ _twin_ucs4_base(twin_ucs4_t ucs4)
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_ucs4 (twin_path_t *path,
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)
diff --git a/xtwin.c b/xtwin.c
index 58d178e..7b8fefa 100644
--- a/xtwin.c
+++ b/xtwin.c
@@ -77,14 +77,18 @@ main (int argc, char **argv)
#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)