|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: glut_font.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // GLUT font routines for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 // The stroked text code was copied from FreeGLUT 2.4.0 which carries 00028 // the following notice: 00029 // 00030 // Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. 00031 // 00032 00033 // (sort of) emulation of Glut's bitmap drawing functions, using FL's 00034 // font stuff. Not all the fonts match! 00035 00036 #include <config.h> 00037 #if HAVE_GL 00038 # include <FL/glut.H> 00039 00040 Fl_Glut_Bitmap_Font glutBitmap9By15 = {FL_SCREEN, 15}; 00041 Fl_Glut_Bitmap_Font glutBitmap8By13 = {FL_SCREEN, 13}; 00042 Fl_Glut_Bitmap_Font glutBitmapTimesRoman10 = {FL_TIMES, 10}; 00043 Fl_Glut_Bitmap_Font glutBitmapTimesRoman24 = {FL_TIMES, 24}; 00044 Fl_Glut_Bitmap_Font glutBitmapHelvetica10 = {FL_HELVETICA, 10}; 00045 Fl_Glut_Bitmap_Font glutBitmapHelvetica12 = {FL_HELVETICA, 12}; 00046 Fl_Glut_Bitmap_Font glutBitmapHelvetica18 = {FL_HELVETICA, 18}; 00047 00048 void glutBitmapCharacter(void* font, int character) { 00049 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size); 00050 char a[1]; a[0] = character; 00051 gl_draw(a,1); 00052 } 00053 00054 int glutBitmapHeight(void* font) { 00055 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size); 00056 return gl_height(); 00057 } 00058 00059 int glutBitmapLength(void *font, const unsigned char *string) { 00060 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size); 00061 const char *s = (const char*)string; 00062 return int(gl_width(s)+.5); 00063 } 00064 00065 void glutBitmapString(void *font, const unsigned char *string) { 00066 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size); 00067 const char *s = (const char*)string; 00068 gl_draw(s); 00069 } 00070 00071 int glutBitmapWidth(void* font, int character) { 00072 gl_font(((Fl_Glut_Bitmap_Font *)font)->font,((Fl_Glut_Bitmap_Font *)font)->size); 00073 return int(gl_width(character)+.5); 00074 } 00075 00076 00077 /* 00078 * Draw a stroke character 00079 */ 00080 void glutStrokeCharacter(void* fontID, int character) { 00081 const Fl_Glut_StrokeChar *schar; 00082 const Fl_Glut_StrokeStrip *strip; 00083 int i, j; 00084 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID; 00085 00086 if (character < 0 || character >= font->Quantity) return; 00087 00088 schar = font->Characters[character]; 00089 if (!schar) return; 00090 00091 strip = schar->Strips; 00092 00093 for (i = 0; i < schar->Number; i++, strip++) 00094 { 00095 glBegin(GL_LINE_STRIP); 00096 for (j = 0; j < strip->Number; j++) 00097 glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y); 00098 glEnd(); 00099 } 00100 00101 glTranslatef(schar->Right, 0.0, 0.0); 00102 } 00103 00104 void glutStrokeString(void* fontID, const unsigned char *string) { 00105 unsigned char c; 00106 int i, j; 00107 float length = 0.0; 00108 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID; 00109 00110 if (!string || ! *string) return; 00111 00112 /* 00113 * Step through the string, drawing each character. 00114 * A newline will simply translate the next character's insertion 00115 * point back to the start of the line and down one line. 00116 */ 00117 while ((c = *string++) != 0) { 00118 if (c < font->Quantity) { 00119 if (c == '\n') { 00120 glTranslatef(-length, -(float)(font->Height), 0.0); 00121 length = 0.0; 00122 } else { 00123 /* Not an EOL, draw the bitmap character */ 00124 const Fl_Glut_StrokeChar *schar = font->Characters[c]; 00125 if (schar) { 00126 const Fl_Glut_StrokeStrip *strip = schar->Strips; 00127 00128 for (i = 0; i < schar->Number; i++, strip++) { 00129 glBegin(GL_LINE_STRIP); 00130 for (j = 0; j < strip->Number; j++) 00131 glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y); 00132 glEnd(); 00133 } 00134 00135 length += schar->Right; 00136 glTranslatef(schar->Right, 0.0, 0.0); 00137 } 00138 } 00139 } 00140 } 00141 } 00142 00143 /* 00144 * Return the width in pixels of a stroke character 00145 */ 00146 int glutStrokeWidth( void* fontID, int character ) 00147 { 00148 const Fl_Glut_StrokeChar *schar; 00149 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID; 00150 if (character < 0 || character >= font->Quantity) return 0; 00151 schar = font->Characters[ character ]; 00152 00153 return schar ? (int)(schar->Right + 0.5) : 0; 00154 } 00155 00156 /* 00157 * Return the width of a string drawn using a stroke font 00158 */ 00159 int glutStrokeLength(void* fontID, const unsigned char* string) { 00160 unsigned char c; 00161 float length = 0.0; 00162 float this_line_length = 0.0; 00163 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID; 00164 00165 if (!string || ! *string) return 0; 00166 00167 while ((c = *string++) != 0) { 00168 if (c < font->Quantity) { 00169 if (c == '\n') { 00170 /* EOL; reset the length of this line */ 00171 if (length < this_line_length) length = this_line_length; 00172 this_line_length = 0.0; 00173 } else { 00174 /* Not an EOL, increment the length of this line */ 00175 const Fl_Glut_StrokeChar *schar = font->Characters[c]; 00176 if (schar) this_line_length += schar->Right; 00177 } 00178 } 00179 } 00180 00181 if (length < this_line_length) length = this_line_length; 00182 00183 return (int)(length + 0.5); 00184 } 00185 00186 /* 00187 * Returns the height of a stroke font 00188 */ 00189 GLfloat glutStrokeHeight(void* fontID) { 00190 Fl_Glut_StrokeFont* font = (Fl_Glut_StrokeFont *)fontID; 00191 return font->Height; 00192 } 00193 00194 #endif // HAVE_GL 00195 00196 // 00197 // End of "$Id: glut_font.cxx 7903 2010-11-28 21:06:39Z matt $". 00198 //