themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / glut_font.cxx
blobd2eb65d0c04649ed12cc12918273922ad15afd65
1 //
2 // "$Id: glut_font.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // GLUT font routines for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
27 // The stroked text code was copied from FreeGLUT 2.4.0 which carries
28 // the following notice:
30 // Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
33 // (sort of) emulation of Glut's bitmap drawing functions, using FL's
34 // font stuff. Not all the fonts match!
36 #include <config.h>
37 #if HAVE_GL
38 # include <FL/glut.H>
40 Fl_Glut_Bitmap_Font glutBitmap9By15 = {FL_SCREEN, 15};
41 Fl_Glut_Bitmap_Font glutBitmap8By13 = {FL_SCREEN, 13};
42 Fl_Glut_Bitmap_Font glutBitmapTimesRoman10 = {FL_TIMES, 10};
43 Fl_Glut_Bitmap_Font glutBitmapTimesRoman24 = {FL_TIMES, 24};
44 Fl_Glut_Bitmap_Font glutBitmapHelvetica10 = {FL_HELVETICA, 10};
45 Fl_Glut_Bitmap_Font glutBitmapHelvetica12 = {FL_HELVETICA, 12};
46 Fl_Glut_Bitmap_Font glutBitmapHelvetica18 = {FL_HELVETICA, 18};
48 void glutBitmapCharacter(void* font, int character) {
49 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size);
50 char a[1]; a[0] = character;
51 gl_draw(a,1);
54 int glutBitmapHeight(void* font) {
55 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size);
56 return gl_height();
59 int glutBitmapLength(void *font, const unsigned char *string) {
60 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size);
61 const char *s = (const char*)string;
62 return int(gl_width(s)+.5);
65 void glutBitmapString(void *font, const unsigned char *string) {
66 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size);
67 const char *s = (const char*)string;
68 gl_draw(s);
71 int glutBitmapWidth(void* font, int character) {
72 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size);
73 return int(gl_width(character)+.5);
78 * Draw a stroke character
80 void glutStrokeCharacter(void* fontID, int character) {
81 const Fl_Glut_StrokeChar *schar;
82 const Fl_Glut_StrokeStrip *strip;
83 int i, j;
84 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID;
86 if (character < 0 || character >= font->Quantity) return;
88 schar = font->Characters[character];
89 if (!schar) return;
91 strip = schar->Strips;
93 for (i = 0; i < schar->Number; i++, strip++)
95 glBegin(GL_LINE_STRIP);
96 for (j = 0; j < strip->Number; j++)
97 glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y);
98 glEnd();
101 glTranslatef(schar->Right, 0.0, 0.0);
104 void glutStrokeString(void* fontID, const unsigned char *string) {
105 unsigned char c;
106 int i, j;
107 float length = 0.0;
108 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID;
110 if (!string || ! *string) return;
113 * Step through the string, drawing each character.
114 * A newline will simply translate the next character's insertion
115 * point back to the start of the line and down one line.
117 while ((c = *string++) != 0) {
118 if (c < font->Quantity) {
119 if (c == '\n') {
120 glTranslatef(-length, -(float)(font->Height), 0.0);
121 length = 0.0;
122 } else {
123 /* Not an EOL, draw the bitmap character */
124 const Fl_Glut_StrokeChar *schar = font->Characters[c];
125 if (schar) {
126 const Fl_Glut_StrokeStrip *strip = schar->Strips;
128 for (i = 0; i < schar->Number; i++, strip++) {
129 glBegin(GL_LINE_STRIP);
130 for (j = 0; j < strip->Number; j++)
131 glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y);
132 glEnd();
135 length += schar->Right;
136 glTranslatef(schar->Right, 0.0, 0.0);
144 * Return the width in pixels of a stroke character
146 int glutStrokeWidth( void* fontID, int character )
148 const Fl_Glut_StrokeChar *schar;
149 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID;
150 if (character < 0 || character >= font->Quantity) return 0;
151 schar = font->Characters[ character ];
153 return schar ? (int)(schar->Right + 0.5) : 0;
157 * Return the width of a string drawn using a stroke font
159 int glutStrokeLength(void* fontID, const unsigned char* string) {
160 unsigned char c;
161 float length = 0.0;
162 float this_line_length = 0.0;
163 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID;
165 if (!string || ! *string) return 0;
167 while ((c = *string++) != 0) {
168 if (c < font->Quantity) {
169 if (c == '\n') {
170 /* EOL; reset the length of this line */
171 if (length < this_line_length) length = this_line_length;
172 this_line_length = 0.0;
173 } else {
174 /* Not an EOL, increment the length of this line */
175 const Fl_Glut_StrokeChar *schar = font->Characters[c];
176 if (schar) this_line_length += schar->Right;
181 if (length < this_line_length) length = this_line_length;
183 return (int)(length + 0.5);
187 * Returns the height of a stroke font
189 GLfloat glutStrokeHeight(void* fontID) {
190 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID;
191 return font->Height;
194 #endif // HAVE_GL
197 // End of "$Id: glut_font.cxx 7903 2010-11-28 21:06:39Z matt $".