]> icculus.org git repositories - dana/openbox.git/blob - glft/render.c
segs on shutdown, but renders characters, tho the glyph size info is incorrect still.
[dana/openbox.git] / glft / render.c
1 #include "render.h"
2 #include "font.h"
3 #include "debug.h"
4 #include <glib.h>
5 #include <GL/glx.h>
6
7 #include FT_OUTLINE_H
8
9 struct GlftWalkState {
10     int drawing;
11     float x, y;
12 };
13
14 static struct GlftWalkState state;
15
16 int GlftMoveToFunc(FT_Vector *to, void *user)
17 {
18     state.x = (to->x >> 6) + (to->x & 63)/64;
19     state.y = (to->y >> 6) + (to->y & 63)/64;
20     printf("move to %f:%f\n", state.x, state.y);
21     if (state.drawing) {
22         glEnd();
23         state.drawing = 0;
24     }
25     return 0;
26 }
27
28 int GlftLineToFunc(FT_Vector *to, void *user)
29 {
30     if (!state.drawing) {
31         glBegin(GL_LINES);
32         glVertex2f(state.x, state.y);
33     }
34     state.x = (to->x >> 6) + (to->x & 63)/64;
35     state.y = (to->y >> 6) + (to->y & 63)/64;
36     printf("line to %f:%f\n", state.x, state.y);
37     glVertex2f(state.x, state.y);
38     return 0;
39 }
40
41 int GlftConicToFunc(FT_Vector *c, FT_Vector *to, void *user)
42 {
43     GlftLineToFunc(to, user);
44     printf("conic the hedgehog!\n");
45     return 0;
46 }
47
48 int GlftCubicToFunc(FT_Vector *c1, FT_Vector *c2, FT_Vector *to, void 
49 *user)
50 {
51     GlftLineToFunc(to, user);
52     printf("cubic\n");
53     return 0;
54 }
55
56 FT_Outline_Funcs GlftFuncs = {
57     GlftMoveToFunc,
58     GlftLineToFunc,
59     GlftConicToFunc,
60     GlftCubicToFunc,
61     0,
62     0
63 };
64
65 void GlftRenderGlyph(FT_Face face, unsigned int dlist)
66 {
67     int err;
68     FT_GlyphSlot slot = face->glyph;
69
70     state.x = 0;
71     state.y = 0;
72     state.drawing = 0;
73
74     glNewList(dlist, GL_COMPILE);
75     err = FT_Outline_Decompose(&slot->outline, &GlftFuncs, NULL);
76     g_assert(!err);
77     if (state.drawing)
78         glEnd();
79     glEndList();
80 }
81
82 void GlftRenderString(struct GlftFont *font, const char *str, int bytes,
83                       int x, int y)
84 {
85     const char *c;
86     struct GlftGlyph *g;
87
88     if (!g_utf8_validate(str, bytes, NULL)) {
89         GlftDebug("Invalid UTF-8 in string\n");
90         return;
91     }
92
93     glPushMatrix();
94
95     c = str;
96     while (c) {
97         g = GlftFontGlyph(font, c);
98         if (g) {
99             glCallList(g->dlist);
100             glTranslatef(g->width, 0.0, 0.0);
101         } else
102             glTranslatef(font->max_advance_width, 0.0, 0.0);
103         c = g_utf8_next_char(c);
104         if (c - str >= bytes) break;
105     }
106
107     glPopMatrix();
108 }