From 1f40779f1aabbbd211747aa653c42dfd0bca6230 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 7 Dec 2009 17:49:14 +0100 Subject: Update path fill, stroke and dash code. --- fitzdraw/Jamfile | 4 +- fitzdraw/glyphcache.c | 27 +---- fitzdraw/pathfill.c | 51 +++------ fitzdraw/pathscan.c | 56 +++------- fitzdraw/pathstroke.c | 286 ++++++++++++++++---------------------------------- 5 files changed, 131 insertions(+), 293 deletions(-) (limited to 'fitzdraw') diff --git a/fitzdraw/Jamfile b/fitzdraw/Jamfile index 826fedcc..613e2d7a 100644 --- a/fitzdraw/Jamfile +++ b/fitzdraw/Jamfile @@ -9,8 +9,8 @@ Library libfitzdraw : imageunpack.c imagescale.c pathscan.c -# pathfill.c -# pathstroke.c + pathfill.c + pathstroke.c # render.c blendmodes.c ; diff --git a/fitzdraw/glyphcache.c b/fitzdraw/glyphcache.c index 183a19ad..776b3e4c 100644 --- a/fitzdraw/glyphcache.c +++ b/fitzdraw/glyphcache.c @@ -55,14 +55,12 @@ static unsigned int hashkey(fz_key *key) return hash; } -fz_error -fz_newglyphcache(fz_glyphcache **arenap, int slots, int size) +fz_glyphcache * +fz_newglyphcache(int slots, int size) { fz_glyphcache *arena; - arena = *arenap = fz_malloc(sizeof(fz_glyphcache)); - if (!arena) - return fz_rethrow(-1, "out of memory"); + arena = fz_malloc(sizeof(fz_glyphcache)); arena->slots = slots; arena->size = size; @@ -72,16 +70,8 @@ fz_newglyphcache(fz_glyphcache **arenap, int slots, int size) arena->buffer = nil; arena->hash = fz_malloc(sizeof(fz_hash) * slots); - if (!arena->hash) - goto cleanup; - arena->lru = fz_malloc(sizeof(fz_val) * slots); - if (!arena->lru) - goto cleanup; - arena->buffer = fz_malloc(size); - if (!arena->buffer) - goto cleanup; memset(arena->hash, 0, sizeof(fz_hash) * slots); memset(arena->lru, 0, sizeof(fz_val) * slots); @@ -89,18 +79,11 @@ fz_newglyphcache(fz_glyphcache **arenap, int slots, int size) arena->load = 0; arena->used = 0; - return fz_okay; - -cleanup: - fz_free(arena->hash); - fz_free(arena->lru); - fz_free(arena->buffer); - fz_free(arena); - return fz_rethrow(-1, "out of memory"); + return arena; } void -fz_dropglyphcache(fz_glyphcache *arena) +fz_freeglyphcache(fz_glyphcache *arena) { fz_free(arena->hash); fz_free(arena->lru); diff --git a/fitzdraw/pathfill.c b/fitzdraw/pathfill.c index 8703e066..96928a4f 100644 --- a/fitzdraw/pathfill.c +++ b/fitzdraw/pathfill.c @@ -1,23 +1,22 @@ #include "fitz.h" -static fz_error +static void line(fz_gel *gel, fz_matrix *ctm, float x0, float y0, float x1, float y1) { float tx0 = ctm->a * x0 + ctm->c * y0 + ctm->e; float ty0 = ctm->b * x0 + ctm->d * y0 + ctm->f; float tx1 = ctm->a * x1 + ctm->c * y1 + ctm->e; float ty1 = ctm->b * x1 + ctm->d * y1 + ctm->f; - return fz_insertgel(gel, tx0, ty0, tx1, ty1); + fz_insertgel(gel, tx0, ty0, tx1, ty1); } -static fz_error +static void bezier(fz_gel *gel, fz_matrix *ctm, float flatness, float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd) { - fz_error error; float dmax; float xab, yab; float xbc, ybc; @@ -31,8 +30,10 @@ bezier(fz_gel *gel, fz_matrix *ctm, float flatness, dmax = MAX(dmax, ABS(ya - yb)); dmax = MAX(dmax, ABS(xd - xc)); dmax = MAX(dmax, ABS(yd - yc)); - if (dmax < flatness) - return line(gel, ctm, xa, ya, xd, yd); + if (dmax < flatness) { + line(gel, ctm, xa, ya, xd, yd); + return; + } xab = xa + xb; yab = ya + yb; @@ -58,16 +59,13 @@ bezier(fz_gel *gel, fz_matrix *ctm, float flatness, xabcd *= 0.125f; yabcd *= 0.125f; - error = bezier(gel, ctm, flatness, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd); - if (error) - return error; - return bezier(gel, ctm, flatness, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd); + bezier(gel, ctm, flatness, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd); + bezier(gel, ctm, flatness, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd); } -fz_error -fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) +void +fz_fillpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness) { - fz_error error; float x1, y1, x2, y2, x3, y3; float cx = 0; float cy = 0; @@ -82,12 +80,7 @@ fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) case FZ_MOVETO: /* implicit closepath before moveto */ if (i && (cx != bx || cy != by)) - { - error = line(gel, &ctm, cx, cy, bx, by); - if (error) - return error; - } - + line(gel, &ctm, cx, cy, bx, by); x1 = path->els[i++].v; y1 = path->els[i++].v; cx = bx = x1; @@ -97,9 +90,7 @@ fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) case FZ_LINETO: x1 = path->els[i++].v; y1 = path->els[i++].v; - error = line(gel, &ctm, cx, cy, x1, y1); - if (error) - return error; + line(gel, &ctm, cx, cy, x1, y1); cx = x1; cy = y1; break; @@ -111,17 +102,13 @@ fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) y2 = path->els[i++].v; x3 = path->els[i++].v; y3 = path->els[i++].v; - error = bezier(gel, &ctm, flatness, cx, cy, x1, y1, x2, y2, x3, y3); - if (error) - return error; + bezier(gel, &ctm, flatness, cx, cy, x1, y1, x2, y2, x3, y3); cx = x3; cy = y3; break; case FZ_CLOSEPATH: - error = line(gel, &ctm, cx, cy, bx, by); - if (error) - return error; + line(gel, &ctm, cx, cy, bx, by); cx = bx; cy = by; break; @@ -129,12 +116,6 @@ fz_fillpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness) } if (i && (cx != bx || cy != by)) - { - error = line(gel, &ctm, cx, cy, bx, by); - if (error) - return error; - } - - return fz_okay; + line(gel, &ctm, cx, cy, bx, by); } diff --git a/fitzdraw/pathscan.c b/fitzdraw/pathscan.c index 5c060c6f..c1ac3a13 100644 --- a/fitzdraw/pathscan.c +++ b/fitzdraw/pathscan.c @@ -16,24 +16,15 @@ enum { HSCALE = 17, VSCALE = 15, SF = 1 }; * See Mike Abrash -- Graphics Programming Black Book (notably chapter 40) */ -fz_error -fz_newgel(fz_gel **gelp) +fz_gel * +fz_newgel(void) { fz_gel *gel; - gel = *gelp = fz_malloc(sizeof(fz_gel)); - if (!gel) - return fz_rethrow(-1, "out of memory"); - - gel->edges = nil; - + gel = fz_malloc(sizeof(fz_gel)); gel->cap = 512; gel->len = 0; gel->edges = fz_malloc(sizeof(fz_edge) * gel->cap); - if (!gel->edges) { - fz_free(gel); - return fz_rethrow(-1, "out of memory"); - } gel->clip.x0 = gel->clip.y0 = INT_MAX; gel->clip.x1 = gel->clip.y1 = INT_MIN; @@ -41,7 +32,7 @@ fz_newgel(fz_gel **gelp) gel->bbox.x0 = gel->bbox.y0 = INT_MAX; gel->bbox.x1 = gel->bbox.y1 = INT_MIN; - return fz_okay; + return gel; } void @@ -66,7 +57,7 @@ fz_resetgel(fz_gel *gel, fz_irect clip) } void -fz_dropgel(fz_gel *gel) +fz_freegel(fz_gel *gel) { fz_free(gel->edges); fz_free(gel); @@ -112,7 +103,7 @@ cliplerpx(int val, int m, int x0, int y0, int x1, int y1, int *out) } } -fz_error +void fz_insertgel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) { fz_edge *edge; @@ -129,17 +120,17 @@ fz_insertgel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) int y1 = fz_floor(fy1 * VSCALE); d = cliplerpy(gel->clip.y0, 0, x0, y0, x1, y1, &v); - if (d == OUTSIDE) return fz_okay; + if (d == OUTSIDE) return; if (d == LEAVE) { y1 = gel->clip.y0; x1 = v; } if (d == ENTER) { y0 = gel->clip.y0; x0 = v; } d = cliplerpy(gel->clip.y1, 1, x0, y0, x1, y1, &v); - if (d == OUTSIDE) return fz_okay; + if (d == OUTSIDE) return; if (d == LEAVE) { y1 = gel->clip.y1; x1 = v; } if (d == ENTER) { y0 = gel->clip.y1; x0 = v; } if (y0 == y1) - return fz_okay; + return; if (y0 > y1) { winding = -1; @@ -158,12 +149,8 @@ fz_insertgel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) if (y1 > gel->bbox.y1) gel->bbox.y1 = y1; if (gel->len + 1 == gel->cap) { - int newcap = gel->cap + 512; - fz_edge *newedges = fz_realloc(gel->edges, sizeof(fz_edge) * newcap); - if (!newedges) - return fz_rethrow(-1, "out of memory"); - gel->cap = newcap; - gel->edges = newedges; + gel->cap = gel->cap + 512; + gel->edges = fz_realloc(gel->edges, sizeof(fz_edge) * gel->cap); } edge = &gel->edges[gel->len++]; @@ -196,8 +183,6 @@ fz_insertgel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) edge->xmove = (width / dy) * edge->xdir; edge->adjup = width % dy; } - - return fz_okay; } void @@ -241,28 +226,19 @@ fz_sortgel(fz_gel *gel) * Active Edge List -- keep track of active edges while sweeping */ -fz_error -fz_newael(fz_ael **aelp) +fz_ael * +fz_newael(void) { fz_ael *ael; - - ael = *aelp = fz_malloc(sizeof(fz_ael)); - if (!ael) - return fz_rethrow(-1, "out of memory"); - + ael = fz_malloc(sizeof(fz_ael)); ael->cap = 64; ael->len = 0; ael->edges = fz_malloc(sizeof(fz_edge*) * ael->cap); - if (!ael->edges) { - fz_free(ael); - return fz_rethrow(-1, "out of memory"); - } - - return fz_okay; + return ael; } void -fz_dropael(fz_ael *ael) +fz_freeael(fz_ael *ael) { fz_free(ael->edges); fz_free(ael); diff --git a/fitzdraw/pathstroke.c b/fitzdraw/pathstroke.c index 81c9d90e..0373931a 100644 --- a/fitzdraw/pathstroke.c +++ b/fitzdraw/pathstroke.c @@ -17,30 +17,31 @@ struct sctx int sn, bn; int dot; - fz_dash *dash; + float *dashlist; + float dashphase; + int dashlen; int toggle; int offset; float phase; fz_point cur; }; -static fz_error +static void line(struct sctx *s, float x0, float y0, float x1, float y1) { float tx0 = s->ctm->a * x0 + s->ctm->c * y0 + s->ctm->e; float ty0 = s->ctm->b * x0 + s->ctm->d * y0 + s->ctm->f; float tx1 = s->ctm->a * x1 + s->ctm->c * y1 + s->ctm->e; float ty1 = s->ctm->b * x1 + s->ctm->d * y1 + s->ctm->f; - return fz_insertgel(s->gel, tx0, ty0, tx1, ty1); + fz_insertgel(s->gel, tx0, ty0, tx1, ty1); } -static fz_error +static void arc(struct sctx *s, float xc, float yc, float x0, float y0, float x1, float y1) { - fz_error error; float th0, th1, r; float theta; float ox, oy, nx, ny; @@ -71,42 +72,29 @@ arc(struct sctx *s, theta = th0 + (th1 - th0) * i / n; nx = cos(theta) * r; ny = sin(theta) * r; - error = line(s, xc + ox, yc + oy, xc + nx, yc + ny); - if (error) return error; + line(s, xc + ox, yc + oy, xc + nx, yc + ny); ox = nx; oy = ny; } - error = line(s, xc + ox, yc + oy, xc + x1, yc + y1); - if (error) return error; - - return fz_okay; + line(s, xc + ox, yc + oy, xc + x1, yc + y1); } -static fz_error +static void linestroke(struct sctx *s, fz_point a, fz_point b) { - fz_error error; - float dx = b.x - a.x; float dy = b.y - a.y; float scale = s->linewidth / sqrt(dx * dx + dy * dy); float dlx = dy * scale; float dly = -dx * scale; - - error = line(s, a.x - dlx, a.y - dly, b.x - dlx, b.y - dly); - if (error) return error; - - error = line(s, b.x + dlx, b.y + dly, a.x + dlx, a.y + dly); - if (error) return error; - - return fz_okay; + line(s, a.x - dlx, a.y - dly, b.x - dlx, b.y - dly); + line(s, b.x + dlx, b.y + dly, a.x + dlx, a.y + dly); } -static fz_error +static void linejoin(struct sctx *s, fz_point a, fz_point b, fz_point c) { - fz_error error; float miterlimit = s->miterlimit; float linewidth = s->linewidth; int linejoin = s->linejoin; @@ -126,13 +114,9 @@ linejoin(struct sctx *s, fz_point a, fz_point b, fz_point c) dy1 = c.y - b.y; if (dx0 * dx0 + dy0 * dy0 < FLT_EPSILON) - { linejoin = BEVEL; - } if (dx1 * dx1 + dy1 * dy1 < FLT_EPSILON) - { linejoin = BEVEL; - } scale = linewidth / sqrt(dx0 * dx0 + dy0 * dy0); dlx0 = dy0 * scale; @@ -157,10 +141,8 @@ linejoin(struct sctx *s, fz_point a, fz_point b, fz_point c) if (linejoin == BEVEL) { - error = line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); - if (error) return error; - error = line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); - if (error) return error; + line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); + line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); } if (linejoin == MITER) @@ -171,21 +153,15 @@ linejoin(struct sctx *s, fz_point a, fz_point b, fz_point c) if (cross < 0) { - error = line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); - if (error) return error; - error = line(s, b.x + dlx1, b.y + dly1, b.x + dmx, b.y + dmy); - if (error) return error; - error = line(s, b.x + dmx, b.y + dmy, b.x + dlx0, b.y + dly0); - if (error) return error; + line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); + line(s, b.x + dlx1, b.y + dly1, b.x + dmx, b.y + dmy); + line(s, b.x + dmx, b.y + dmy, b.x + dlx0, b.y + dly0); } else { - error = line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); - if (error) return error; - error = line(s, b.x - dlx0, b.y - dly0, b.x - dmx, b.y - dmy); - if (error) return error; - error = line(s, b.x - dmx, b.y - dmy, b.x - dlx1, b.y - dly1); - if (error) return error; + line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); + line(s, b.x - dlx0, b.y - dly0, b.x - dmx, b.y - dmy); + line(s, b.x - dmx, b.y - dmy, b.x - dlx1, b.y - dly1); } } @@ -193,27 +169,20 @@ linejoin(struct sctx *s, fz_point a, fz_point b, fz_point c) { if (cross < 0) { - error = line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); - if (error) return error; - error = arc(s, b.x, b.y, dlx1, dly1, dlx0, dly0); - if (error) return error; + line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); + arc(s, b.x, b.y, dlx1, dly1, dlx0, dly0); } else { - error = line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); - if (error) return error; - error = arc(s, b.x, b.y, -dlx0, -dly0, -dlx1, -dly1); - if (error) return error; + line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); + arc(s, b.x, b.y, -dlx0, -dly0, -dlx1, -dly1); } } - - return fz_okay; } -static fz_error +static void linecap(struct sctx *s, fz_point a, fz_point b) { - fz_error error; float flatness = s->flatness; float linewidth = s->linewidth; int linecap = s->linecap; @@ -226,7 +195,7 @@ linecap(struct sctx *s, fz_point a, fz_point b) float dly = -dx * scale; if (linecap == BUTT) - return line(s, b.x - dlx, b.y - dly, b.x + dlx, b.y + dly); + line(s, b.x - dlx, b.y - dly, b.x + dlx, b.y + dly); if (linecap == ROUND) { @@ -241,39 +210,31 @@ linecap(struct sctx *s, fz_point a, fz_point b) float sth = sin(theta); float nx = b.x - dlx * cth - dly * sth; float ny = b.y - dly * cth + dlx * sth; - error = line(s, ox, oy, nx, ny); - if (error) return error; + line(s, ox, oy, nx, ny); ox = nx; oy = ny; } - error = line(s, ox, oy, b.x + dlx, b.y + dly); - if (error) return error; + line(s, ox, oy, b.x + dlx, b.y + dly); } if (linecap == SQUARE) { - error = line(s, b.x - dlx, b.y - dly, + line(s, b.x - dlx, b.y - dly, b.x - dlx - dly, b.y - dly + dlx); - if (error) return error; - error = line(s, b.x - dlx - dly, + line(s, b.x - dlx - dly, b.y - dly + dlx, b.x + dlx - dly, b.y + dly + dlx); - if (error) return error; - error = line(s, b.x + dlx - dly, + line(s, b.x + dlx - dly, b.y + dly + dlx, b.x + dlx, b.y + dly); - if (error) return error; } - - return fz_okay; } -static fz_error +static void linedot(struct sctx *s, fz_point a) { - fz_error error; float flatness = s->flatness; float linewidth = s->linewidth; int n = ceil(M_PI / (M_SQRT2 * sqrt(flatness / linewidth))); @@ -287,77 +248,53 @@ linedot(struct sctx *s, fz_point a) float sth = sin(theta); float nx = a.x - cth * linewidth; float ny = a.y + sth * linewidth; - error = line(s, ox, oy, nx, ny); - if (error) return error; + line(s, ox, oy, nx, ny); ox = nx; oy = ny; } - error = line(s, ox, oy, a.x - linewidth, a.y); - if (error) return error; - return fz_okay; + line(s, ox, oy, a.x - linewidth, a.y); } -static fz_error +static void strokeflush(struct sctx *s) { - fz_error error; - if (s->sn == 2) { - error = linecap(s, s->beg[1], s->beg[0]); - if (error) return error; - error = linecap(s, s->seg[0], s->seg[1]); - if (error) return error; + linecap(s, s->beg[1], s->beg[0]); + linecap(s, s->seg[0], s->seg[1]); } else if (s->dot) { - error = linedot(s, s->beg[0]); - if (error) return error; + linedot(s, s->beg[0]); } s->dot = 0; - - return fz_okay; } -static fz_error +static void strokemoveto(struct sctx *s, fz_point cur) { - fz_error error; - - error = strokeflush(s); - if (error) return error; - + strokeflush(s); s->seg[0] = cur; s->beg[0] = cur; s->sn = 1; s->bn = 1; - - return fz_okay; } -static fz_error +static void strokelineto(struct sctx *s, fz_point cur) { - fz_error error; - float dx = cur.x - s->seg[s->sn-1].x; float dy = cur.y - s->seg[s->sn-1].y; if (dx * dx + dy * dy < FLT_EPSILON) - { s->dot = 1; - return fz_okay; - } - error = linestroke(s, s->seg[s->sn-1], cur); - if (error) return error; + linestroke(s, s->seg[s->sn-1], cur); if (s->sn == 2) { - error = linejoin(s, s->seg[0], s->seg[1], cur); - if (error) return error; - + linejoin(s, s->seg[0], s->seg[1], cur); s->seg[0] = s->seg[1]; s->seg[1] = cur; } @@ -366,48 +303,36 @@ strokelineto(struct sctx *s, fz_point cur) s->seg[s->sn++] = cur; if (s->bn == 1) s->beg[s->bn++] = cur; - - return fz_okay; } -static fz_error +static void strokeclosepath(struct sctx *s) { - fz_error error; - if (s->sn == 2) { - error = strokelineto(s, s->beg[0]); - if (error) return error; - + strokelineto(s, s->beg[0]); if (s->seg[1].x == s->beg[0].x && s->seg[1].y == s->beg[0].y) - error = linejoin(s, s->seg[0], s->beg[0], s->beg[1]); + linejoin(s, s->seg[0], s->beg[0], s->beg[1]); else - error = linejoin(s, s->seg[1], s->beg[0], s->beg[1]); - if (error) return error; + linejoin(s, s->seg[1], s->beg[0], s->beg[1]); } - else if (s->dot) { - error = linedot(s, s->beg[0]); - if (error) return error; + linedot(s, s->beg[0]); } s->bn = 0; s->sn = 0; s->dot = 0; - - return fz_okay; } -static fz_error +static void strokebezier(struct sctx *s, float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd) { - fz_error error; float dmax; float xab, yab; float xbc, ybc; @@ -425,7 +350,8 @@ strokebezier(struct sctx *s, fz_point p; p.x = xd; p.y = yd; - return strokelineto(s, p); + strokelineto(s, p); + return; } xab = xa + xb; @@ -452,17 +378,13 @@ strokebezier(struct sctx *s, xabcd *= 0.125f; yabcd *= 0.125f; - error = strokebezier(s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd); - if (error) - return error; - - return strokebezier(s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd); + strokebezier(s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd); + strokebezier(s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd); } -fz_error -fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float linewidth) +void +fz_strokepath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness, float linewidth) { - fz_error error; struct sctx s; fz_point p0, p1, p2, p3; int i; @@ -482,9 +404,9 @@ fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, flo i = 0; if (path->len > 0 && path->els[0].k != FZ_MOVETO) - return fz_throw("path must begin with moveto"); + fz_warn("assert: path must begin with moveto"); - p0.x = p0.y = 0; /* FZ_MOVETO guarantees p0 to be set, silence compiler */ + p0.x = p0.y = 0; while (i < path->len) { @@ -493,18 +415,14 @@ fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, flo case FZ_MOVETO: p1.x = path->els[i++].v; p1.y = path->els[i++].v; - error = strokemoveto(&s, p1); - if (error) - return error; + strokemoveto(&s, p1); p0 = p1; break; case FZ_LINETO: p1.x = path->els[i++].v; p1.y = path->els[i++].v; - error = strokelineto(&s, p1); - if (error) - return error; + strokelineto(&s, p1); p0 = p1; break; @@ -515,51 +433,44 @@ fz_strokepath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, flo p2.y = path->els[i++].v; p3.x = path->els[i++].v; p3.y = path->els[i++].v; - error = strokebezier(&s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); - if (error) - return error; + strokebezier(&s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); p0 = p3; break; case FZ_CLOSEPATH: - error = strokeclosepath(&s); - if (error) - return error; + strokeclosepath(&s); break; } } - return strokeflush(&s); + strokeflush(&s); } -static fz_error +static void dashmoveto(struct sctx *s, fz_point a) { s->toggle = 1; s->offset = 0; - s->phase = s->dash->phase; + s->phase = s->dashphase; - while (s->phase >= s->dash->array[s->offset]) + while (s->phase >= s->dashlist[s->offset]) { s->toggle = !s->toggle; - s->phase -= s->dash->array[s->offset]; + s->phase -= s->dashlist[s->offset]; s->offset ++; - if (s->offset == s->dash->len) + if (s->offset == s->dashlen) s->offset = 0; } s->cur = a; if (s->toggle) - return strokemoveto(s, a); - - return fz_okay; + strokemoveto(s, a); } -static fz_error +static void dashlineto(struct sctx *s, fz_point b) { - fz_error error; float dx, dy; float total, used, ratio; fz_point a; @@ -571,24 +482,22 @@ dashlineto(struct sctx *s, fz_point b) total = sqrt(dx * dx + dy * dy); used = 0; - while (total - used > s->dash->array[s->offset] - s->phase) + while (total - used > s->dashlist[s->offset] - s->phase) { - used += s->dash->array[s->offset] - s->phase; + used += s->dashlist[s->offset] - s->phase; ratio = used / total; m.x = a.x + ratio * dx; m.y = a.y + ratio * dy; if (s->toggle) - error = strokelineto(s, m); + strokelineto(s, m); else - error = strokemoveto(s, m); - if (error) - return error; + strokemoveto(s, m); s->toggle = !s->toggle; s->phase = 0; s->offset ++; - if (s->offset == s->dash->len) + if (s->offset == s->dashlen) s->offset = 0; } @@ -597,19 +506,16 @@ dashlineto(struct sctx *s, fz_point b) s->cur = b; if (s->toggle) - return strokelineto(s, b); - - return fz_okay; + strokelineto(s, b); } -static fz_error +static void dashbezier(struct sctx *s, float xa, float ya, float xb, float yb, float xc, float yc, float xd, float yd) { - fz_error error; float dmax; float xab, yab; float xbc, ybc; @@ -627,7 +533,8 @@ dashbezier(struct sctx *s, fz_point p; p.x = xd; p.y = yd; - return dashlineto(s, p); + dashlineto(s, p); + return; } xab = xa + xb; @@ -654,15 +561,13 @@ dashbezier(struct sctx *s, xabcd *= 0.125f; yabcd *= 0.125f; - error = dashbezier(s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd); - if (error) return error; - return dashbezier(s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd); + dashbezier(s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd); + dashbezier(s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd); } -fz_error -fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float linewidth) +void +fz_dashpath(fz_gel *gel, fz_path *path, fz_matrix ctm, float flatness, float linewidth) { - fz_error error; struct sctx s; fz_point p0, p1, p2, p3, beg; int i; @@ -679,7 +584,9 @@ fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float s.bn = 0; s.dot = 0; - s.dash = path->dash; + s.dashlist = path->dashlist; + s.dashphase = path->dashphase; + s.dashlen = path->dashlen; s.toggle = 0; s.offset = 0; s.phase = 0; @@ -687,9 +594,9 @@ fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float i = 0; if (path->len > 0 && path->els[0].k != FZ_MOVETO) - return fz_throw("path must begin with moveto"); + fz_warn("assert: path must begin with moveto"); - p0.x = p0.y = 0; /* FZ_MOVETO guarantees p0 to be set, silence compiler */ + p0.x = p0.y = 0; while (i < path->len) { @@ -698,18 +605,14 @@ fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float case FZ_MOVETO: p1.x = path->els[i++].v; p1.y = path->els[i++].v; - error = dashmoveto(&s, p1); - if (error) - return error; + dashmoveto(&s, p1); beg = p0 = p1; break; case FZ_LINETO: p1.x = path->els[i++].v; p1.y = path->els[i++].v; - error = dashlineto(&s, p1); - if (error) - return error; + dashlineto(&s, p1); p0 = p1; break; @@ -720,20 +623,15 @@ fz_dashpath(fz_gel *gel, fz_pathnode *path, fz_matrix ctm, float flatness, float p2.y = path->els[i++].v; p3.x = path->els[i++].v; p3.y = path->els[i++].v; - error = dashbezier(&s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); - if (error) - return error; + dashbezier(&s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); p0 = p3; break; case FZ_CLOSEPATH: - error = dashlineto(&s, beg); - if (error) - return error; + dashlineto(&s, beg); break; } } - return strokeflush(&s); + strokeflush(&s); } - -- cgit v1.2.3