Implemented tetrahedra, octahedra, dodecahedra, and icosahedra. Checked in on behalf...
[freeglut] / freeglut-1.3 / freeglut_font.c
index 26f7d63..59d70eb 100644 (file)
@@ -53,6 +53,8 @@ extern SFG_Font fgFontHelvetica12;
 extern SFG_Font fgFontHelvetica18;
 extern SFG_Font fgFontTimesRoman10;
 extern SFG_Font fgFontTimesRoman24;
+extern SFG_StrokeFont fgStrokeRoman;
+extern SFG_StrokeFont fgStrokeMonoRoman;
 
 /*
  * This is for GLUT binary compatibility, as suggested by Steve Baker
@@ -92,7 +94,29 @@ static SFG_Font* fghFontByID( void* font )
     /*
      * This probably is the library user's fault
      */
-    g_error( "font 0x%08x not found", font );
+    fgError( "font 0x%08x not found", font );
+
+    return 0;
+}
+
+/*
+ * Matches a font ID with a SFG_StrokeFont structure pointer.
+ * This was changed to match the GLUT header style.
+ */
+static SFG_StrokeFont* fghStrokeByID( void* font )
+{
+    /*
+     * Try matching the font ID and the font data structure
+     */
+    if( font == GLUT_STROKE_ROMAN ) return( &fgStrokeRoman );
+    if( font == GLUT_STROKE_MONO_ROMAN ) return( &fgStrokeMonoRoman );
+
+    /*
+     * This probably is the library user's fault
+     */
+    fgError( "stroke font 0x%08x not found", font );
+
+    return 0;
 }
 
 
@@ -103,7 +127,7 @@ static SFG_Font* fghFontByID( void* font )
  */
 void FGAPIENTRY glutBitmapCharacter( void* fontID, int character )
 {
-    const guchar* face;
+    const GLubyte* face;
 
     /*
      * First of all we'll need a font to use
@@ -113,7 +137,7 @@ void FGAPIENTRY glutBitmapCharacter( void* fontID, int character )
     /*
      * Make sure the character we want to output is valid
      */
-    freeglut_return_if_fail( character > 0 && character < 256 );
+    freeglut_return_if_fail( character >= 0 && character < 256 );
 
     /*
      * Then find the character we want to draw
@@ -151,6 +175,14 @@ void FGAPIENTRY glutBitmapCharacter( void* fontID, int character )
     glPopClientAttrib();
 }
 
+void FGAPIENTRY glutBitmapString( void* fontID, const char *string )
+{
+    int i;
+
+    for( i=0; i<strlen( string ); i++ )
+        glutBitmapCharacter( fontID, string[ i ] );
+}
+
 /*
  * Returns the width in pixels of a font's character
  */
@@ -177,10 +209,36 @@ int FGAPIENTRY glutBitmapWidth( void* fontID, int character )
  */
 void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
 {
+    const SFG_StrokeChar *schar;
+    const SFG_StrokeStrip *strip;
+    int i, j;
+
     /*
-     * Stroke fonts are not supported yet, use a bitmap font instead
+     * First of all we'll need a font to use
      */
-    glutBitmapCharacter( GLUT_BITMAP_8_BY_13, character );
+    SFG_StrokeFont* font = fghStrokeByID( fontID );
+
+    /*
+     * Make sure the character we want to output is valid
+     */
+    freeglut_return_if_fail( character >= 0 && character < font->Quantity );
+
+    schar = font->Characters[character];
+
+    freeglut_return_if_fail( schar );
+
+    strip = schar->Strips;
+
+    for (i = 0; i < schar->Number; i++, strip++)
+    {
+        glBegin(GL_LINE_STRIP);
+        for(j = 0; j < strip->Number; j++)
+        {
+            glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y);
+        }
+        glEnd();
+    }
+    glTranslatef(schar->Right, 0.0, 0.0);
 }
 
 /*
@@ -188,10 +246,22 @@ void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
  */
 int FGAPIENTRY glutStrokeWidth( void* fontID, int character )
 {
+    const SFG_StrokeChar *schar;
     /*
-     * Stroke fonts are not supported yet, use a bitmap font instead
+     * First of all we'll need a font to use
      */
-    return( glutBitmapWidth( GLUT_BITMAP_8_BY_13, character ) );
+    SFG_StrokeFont* font = fghStrokeByID( fontID );
+
+    /*
+     * Make sure the character we want to output is valid
+     */
+    freeglut_return_if_fail( character >= 0 && character < font->Quantity );
+
+    schar = font->Characters[character];
+
+    freeglut_return_if_fail( schar );
+
+    return (schar->Right);
 }
 
 /*
@@ -199,12 +269,12 @@ int FGAPIENTRY glutStrokeWidth( void* fontID, int character )
  */
 int FGAPIENTRY glutBitmapLength( void* fontID, const char* string )
 {
-    gint i, length = 0;
+    int i, length = 0;
 
     /*
      * Using glutBitmapWidth() function to calculate the result
      */
-    for( i=0; i<(gint) strlen( string ); i++ )
+    for( i=0; i<strlen( string ); i++ )
         length += glutBitmapWidth( fontID, string[ i ] );
 
     /*
@@ -218,12 +288,12 @@ int FGAPIENTRY glutBitmapLength( void* fontID, const char* string )
  */
 int FGAPIENTRY glutStrokeLength( void* fontID, const char* string )
 {
-    gint i, length = 0;
+    int i, length = 0;
 
     /*
      * Using glutStrokeWidth() function to calculate the result
      */
-    for( i=0; i<(gint) strlen( string ); i++ )
+    for( i=0; i<strlen( string ); i++ )
         length += glutStrokeWidth( fontID, string[ i ] );
 
     /*
@@ -251,13 +321,17 @@ int FGAPIENTRY glutBitmapHeight( void* fontID )
 /*
  * Returns the height of a stroke font
  */
-int FGAPIENTRY glutStrokeHeight( void* font )
+GLfloat FGAPIENTRY glutStrokeHeight( void* fontID )
 {
     /*
-     * Stroke fonts are currently not implemented.
-     * Using GLUT_BITMAP_8_BY_13 bitmap font instead
+     * See which font are we queried about
+     */
+    SFG_StrokeFont* font = fghStrokeByID( fontID );
+
+    /*
+     * Return the character set's height
      */
-    return( glutBitmapHeight( GLUT_BITMAP_8_BY_13 ) );
+    return( font->Height );
 }
 
 /*** END OF FILE ***/