Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / glut / fbdev / stroke.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 * Copyright (C) 1995-2006 Brian Paul
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22 * Library for glut using mesa fbdev driver
23 *
24 * Written by Sean D'Epagnier (c) 2006
25 *
26 * To improve on this library, maybe support subwindows or overlays,
27 * I (sean at depagnier dot com) will do my best to help.
28 */
29
30 #include <GL/glut.h>
31 #include "glutstroke.h"
32
33 void glutStrokeCharacter(GLUTstrokeFont font, int c)
34 {
35 const StrokeCharRec *ch;
36 const StrokeRec *stroke;
37 const CoordRec *coord;
38 StrokeFontPtr fontinfo = (StrokeFontPtr) font;
39 int i, j;
40
41 if (c < 0 || c >= fontinfo->num_chars)
42 return;
43 ch = &(fontinfo->ch[c]);
44 if (ch) {
45 for (i = ch->num_strokes, stroke = ch->stroke;
46 i > 0; i--, stroke++) {
47 glBegin(GL_LINE_STRIP);
48 for (j = stroke->num_coords, coord = stroke->coord;
49 j > 0; j--, coord++) {
50 glVertex2f(coord->x, coord->y);
51 }
52 glEnd();
53 }
54 glTranslatef(ch->right, 0.0, 0.0);
55 }
56 }
57
58 int glutStrokeWidth(GLUTstrokeFont font, int c)
59 {
60 StrokeFontPtr fontinfo;
61 const StrokeCharRec *ch;
62
63 fontinfo = (StrokeFontPtr) font;
64
65 if (c < 0 || c >= fontinfo->num_chars)
66 return 0;
67 ch = &(fontinfo->ch[c]);
68 if (ch)
69 return ch->right;
70
71 return 0;
72 }
73
74 int glutStrokeLength(GLUTstrokeFont font, const unsigned char *string)
75 {
76 int length = 0;
77
78 for (; *string; string++)
79 length += glutStrokeWidth(font, *string);
80 return length;
81 }