fix round off error
authorDerek Foreman <manmower@gmail.com>
Thu, 29 May 2003 01:44:32 +0000 (01:44 +0000)
committerDerek Foreman <manmower@gmail.com>
Thu, 29 May 2003 01:44:32 +0000 (01:44 +0000)
add some interpolation for conics

glft/render.c

index d0465d0c070b15602662826f9ac3057f023629b5..22297e0ffc52cc286a4aa627359d80bda37101a4 100644 (file)
@@ -4,6 +4,10 @@
 #include <glib.h>
 #include <GL/glx.h>
 
+#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;