9 #define TOFLOAT(x) (((x) >> 6) + ((x) & 63)/64.0)
13 struct GlftWalkState {
18 static struct GlftWalkState state;
20 int GlftMoveToFunc(FT_Vector *to, void *user)
22 state.x = TOFLOAT(to->x);
23 state.y = TOFLOAT(to->y);
24 printf("move to %f:%f\n", state.x, state.y);
28 glBegin(GL_LINE_STRIP);
29 glVertex2f(state.x, state.y);
34 int GlftLineToFunc(FT_Vector *to, void *user)
36 state.x = TOFLOAT(to->x);
37 state.y = TOFLOAT(to->y);
38 glVertex2f(state.x, state.y);
39 printf("line to %f:%f\n", state.x, state.y);
43 int GlftConicToFunc(FT_Vector *c, FT_Vector *to, void *user)
47 for (t = 0, u = 1; t < 1.0; t += 1.0/TPOINTS, u = 1.0-t) {
48 x = u*u*state.x + 2*t*u*TOFLOAT(c->x) + t*t*TOFLOAT(to->x);
49 y = u*u*state.y + 2*t*u*TOFLOAT(c->y) + t*t*TOFLOAT(to->y);
52 state.x = TOFLOAT(to->x);
53 state.y = TOFLOAT(to->y);
54 glVertex2f(state.x, state.y);
55 printf("conic the hedgehog!\n");
59 int GlftCubicToFunc(FT_Vector *c1, FT_Vector *c2, FT_Vector *to, void
62 GlftLineToFunc(to, user);
67 FT_Outline_Funcs GlftFuncs = {
76 void GlftRenderGlyph(FT_Face face, unsigned int dlist)
79 FT_GlyphSlot slot = face->glyph;
85 glNewList(dlist, GL_COMPILE);
86 err = FT_Outline_Decompose(&slot->outline, &GlftFuncs, NULL);
93 void GlftRenderString(struct GlftFont *font, const char *str, int bytes,
99 if (!g_utf8_validate(str, bytes, NULL)) {
100 GlftDebug("Invalid UTF-8 in string\n");
107 while (c - str < bytes) {
108 g = GlftFontGlyph(font, c);
110 glCallList(g->dlist);
111 glTranslatef(g->width, 0.0, 0.0);
113 glTranslatef(font->max_advance_width, 0.0, 0.0);
114 c = g_utf8_next_char(c);
120 void GlftMeasureString(struct GlftFont *font,
129 if (!g_utf8_validate(str, bytes, NULL)) {
130 GlftDebug("Invalid UTF-8 in string\n");
138 while (c - str < bytes) {
139 g = GlftFontGlyph(font, c);
142 *h = MAX(g->height, *h);
144 *w += font->max_advance_width;
146 c = g_utf8_next_char(c);