From: Derek Foreman Date: Thu, 29 May 2003 01:44:32 +0000 (+0000) Subject: fix round off error X-Git-Tag: gl2~44 X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=3eafebd89527c86573c2fa91b9d6353a61bfc9ee;p=dana%2Fopenbox.git fix round off error add some interpolation for conics --- diff --git a/glft/render.c b/glft/render.c index d0465d0c..22297e0f 100644 --- a/glft/render.c +++ b/glft/render.c @@ -4,6 +4,10 @@ #include #include +#define TPOINTS 15.0 + +#define TOFLOAT(x) (((x) >> 6) + ((x) & 63)/64.0) + #include FT_OUTLINE_H struct GlftWalkState { @@ -15,8 +19,8 @@ static struct GlftWalkState state; int GlftMoveToFunc(FT_Vector *to, void *user) { - state.x = (to->x >> 6) + (to->x & 63)/64; - state.y = (to->y >> 6) + (to->y & 63)/64; + state.x = TOFLOAT(to->x); + state.y = TOFLOAT(to->y); printf("move to %f:%f\n", state.x, state.y); if (state.drawing) { glEnd(); @@ -33,8 +37,8 @@ int GlftLineToFunc(FT_Vector *to, void *user) state.drawing = 1; } else glVertex2f(state.x, state.y); - state.x = (to->x >> 6) + (to->x & 63)/64; - state.y = (to->y >> 6) + (to->y & 63)/64; + state.x = TOFLOAT(to->x); + state.y = TOFLOAT(to->y); printf("line to %f:%f\n", state.x, state.y); glVertex2f(state.x, state.y); return 0; @@ -42,7 +46,16 @@ int GlftLineToFunc(FT_Vector *to, void *user) int GlftConicToFunc(FT_Vector *c, FT_Vector *to, void *user) { - GlftLineToFunc(to, user); + float t, u, x, y; + + for (t = 0, u = 1; t < 1.0; t += 1.0/TPOINTS, u = 1.0-t) { + x = u*u*state.x + 2*t*u*TOFLOAT(c->x) + t*t*TOFLOAT(to->x); + y = u*u*state.y + 2*t*u*TOFLOAT(c->y) + t*t*TOFLOAT(to->y); +/*printf("cone to %f, %f (%f, %f)\n", x, y, t, u);*/ + glVertex2f(x, y); + } + state.x = TOFLOAT(to->x); + state.y = TOFLOAT(to->y); printf("conic the hedgehog!\n"); return 0; } @@ -85,7 +98,7 @@ void GlftRenderString(struct GlftFont *font, const char *str, int bytes, int x, int y) { const char *c; - struct GlftGlyph *g, *n; + struct GlftGlyph *g; if (!g_utf8_validate(str, bytes, NULL)) { GlftDebug("Invalid UTF-8 in string\n"); @@ -97,10 +110,9 @@ void GlftRenderString(struct GlftFont *font, const char *str, int bytes, c = str; while (c - str < bytes) { g = GlftFontGlyph(font, c); - n = (c - str < bytes - 1) ? GlftFontGlyph(font, c+1) : 0; if (g) { glCallList(g->dlist); - if (n) glTranslatef(GlftFontAdvance(font, g, n), 0.0, 0.0); + glTranslatef(g->width, 0.0, 0.0); } else glTranslatef(font->max_advance_width, 0.0, 0.0); c = g_utf8_next_char(c); @@ -116,7 +128,7 @@ void GlftMeasureString(struct GlftFont *font, int *h) { const char *c; - struct GlftGlyph *g, *n; + struct GlftGlyph *g; if (!g_utf8_validate(str, bytes, NULL)) { GlftDebug("Invalid UTF-8 in string\n"); @@ -129,9 +141,8 @@ void GlftMeasureString(struct GlftFont *font, c = str; while (c - str < bytes) { g = GlftFontGlyph(font, c); - n = (c - str < bytes - 1) ? GlftFontGlyph(font, c+1) : 0; if (g) { - *w += GlftFontAdvance(font, g, n); + *w += g->width; *h = MAX(g->height, *h); } else { *w += font->max_advance_width;