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);
27 glBegin(GL_LINE_STRIP);
28 glVertex2f(state.x, state.y);
33 int GlftLineToFunc(FT_Vector *to, void *user)
35 state.x = TOFLOAT(to->x);
36 state.y = TOFLOAT(to->y);
37 glVertex2f(state.x, state.y);
41 int GlftConicToFunc(FT_Vector *c, FT_Vector *to, void *user)
45 for (t = 0, u = 1; t < 1.0; t += 1.0/TPOINTS, u = 1.0-t) {
46 x = u*u*state.x + 2*t*u*TOFLOAT(c->x) + t*t*TOFLOAT(to->x);
47 y = u*u*state.y + 2*t*u*TOFLOAT(c->y) + t*t*TOFLOAT(to->y);
50 state.x = TOFLOAT(to->x);
51 state.y = TOFLOAT(to->y);
52 glVertex2f(state.x, state.y);
56 int GlftCubicToFunc(FT_Vector *c1, FT_Vector *c2, FT_Vector *to, void
59 GlftLineToFunc(to, user);
60 g_message("cubic not currently rendered properly\n");
64 FT_Outline_Funcs GlftFuncs = {
73 void GlftRenderGlyph(FT_Face face, unsigned int dlist)
76 FT_GlyphSlot slot = face->glyph;
82 glNewList(dlist, GL_COMPILE);
83 err = FT_Outline_Decompose(&slot->outline, &GlftFuncs, NULL);
90 void GlftRenderString(struct GlftFont *font, const char *str, int bytes,
94 struct GlftGlyph *g, *p = NULL;
96 if (!g_utf8_validate(str, bytes, NULL)) {
97 GlftDebug("Invalid UTF-8 in string\n");
104 while (c - str < bytes) {
105 g = GlftFontGlyph(font, c);
107 glTranslatef(GlftFontAdvance(font, p, g), 0.0, 0.0);
108 glCallList(g->dlist);
110 glTranslatef(font->max_advance_width, 0.0, 0.0);
112 c = g_utf8_next_char(c);
118 void GlftMeasureString(struct GlftFont *font,
125 struct GlftGlyph *g, *p = NULL;
127 if (!g_utf8_validate(str, bytes, NULL)) {
128 GlftDebug("Invalid UTF-8 in string\n");
136 while (c - str < bytes) {
137 g = GlftFontGlyph(font, c);
139 *w += GlftFontAdvance(font, p, g);
140 *h = MAX(g->height, *h);
142 *w += font->max_advance_width;
144 c = g_utf8_next_char(c);