Added timer_callback sample for user callbacks
[freeglut] / src / fg_font.c
index 507397e..7502a0b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * freeglut_font.c
+ * fg_font.c
  *
  * Bitmap and stroke fonts displaying.
  *
@@ -37,7 +37,7 @@
 /* -- IMPORT DECLARATIONS -------------------------------------------------- */
 
 /*
- * These are the font faces defined in freeglut_font_data.c file:
+ * These are the font faces defined in fg_font_data.c file:
  */
 extern SFG_Font fgFontFixed8x13;
 extern SFG_Font fgFontFixed9x15;
@@ -56,7 +56,7 @@ extern SFG_StrokeFont fgStrokeMonoRoman;
  * Matches a font ID with a SFG_Font structure pointer.
  * This was changed to match the GLUT header style.
  */
-static SFG_Font* fghFontByID( void* font )
+SFG_Font* fghFontByID( void* font )
 {
     if( font == GLUT_BITMAP_8_BY_13        )
         return &fgFontFixed8x13;
@@ -73,7 +73,6 @@ static SFG_Font* fghFontByID( void* font )
     if( font == GLUT_BITMAP_TIMES_ROMAN_24 )
         return &fgFontTimesRoman24;
 
-    fgWarning( "font 0x%08x not found", font );
     return 0;
 }
 
@@ -88,7 +87,6 @@ static SFG_StrokeFont* fghStrokeByID( void* font )
     if( font == GLUT_STROKE_MONO_ROMAN )
         return &fgStrokeMonoRoman;
 
-    fgWarning( "stroke font 0x%08x not found", font );
     return 0;
 }
 
@@ -104,8 +102,12 @@ void FGAPIENTRY glutBitmapCharacter( void* fontID, int character )
     SFG_Font* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapCharacter" );
     font = fghFontByID( fontID );
+    if (!font)
+    {
+        fgWarning("glutBitmapCharacter: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
+        return;
+    }
     freeglut_return_if_fail( ( character >= 1 )&&( character < 256 ) );
-    freeglut_return_if_fail( font );
 
     /*
      * Find the character we want to draw (???)
@@ -135,7 +137,11 @@ void FGAPIENTRY glutBitmapString( void* fontID, const unsigned char *string )
     SFG_Font* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapString" );
     font = fghFontByID( fontID );
-    freeglut_return_if_fail( font );
+    if (!font)
+    {
+        fgWarning("glutBitmapString: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
+        return;
+    }
     if ( !string || ! *string )
         return;
 
@@ -182,9 +188,13 @@ int FGAPIENTRY glutBitmapWidth( void* fontID, int character )
 {
     SFG_Font* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapWidth" );
-    font = fghFontByID( fontID );
     freeglut_return_val_if_fail( character > 0 && character < 256, 0 );
-    freeglut_return_val_if_fail( font, 0 );
+    font = fghFontByID( fontID );
+    if (!font)
+    {
+        fgWarning("glutBitmapWidth: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
+        return 0;
+    }
     return *( font->Characters[ character ] );
 }
 
@@ -198,7 +208,11 @@ int FGAPIENTRY glutBitmapLength( void* fontID, const unsigned char* string )
     SFG_Font* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapLength" );
     font = fghFontByID( fontID );
-    freeglut_return_val_if_fail( font, 0 );
+    if (!font)
+    {
+        fgWarning("glutBitmapLength: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
+        return 0;
+    }
     if ( !string || ! *string )
         return 0;
 
@@ -227,7 +241,11 @@ int FGAPIENTRY glutBitmapHeight( void* fontID )
     SFG_Font* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutBitmapHeight" );
     font = fghFontByID( fontID );
-    freeglut_return_val_if_fail( font, 0 );
+    if (!font)
+    {
+        fgWarning("glutBitmapHeight: bitmap font 0x%08x not found. Make sure you're not passing a stroke font.\n",fontID);
+        return 0;
+    }
     return font->Height;
 }
 
@@ -242,9 +260,13 @@ void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
     SFG_StrokeFont* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeCharacter" );
     font = fghStrokeByID( fontID );
+    if (!font)
+    {
+        fgWarning("glutStrokeCharacter: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
+        return;
+    }
     freeglut_return_if_fail( character >= 0 );
     freeglut_return_if_fail( character < font->Quantity );
-    freeglut_return_if_fail( font );
 
     schar = font->Characters[ character ];
     freeglut_return_if_fail( schar );
@@ -256,10 +278,14 @@ void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
         for( j = 0; j < strip->Number; j++ )
             glVertex2f( strip->Vertices[ j ].X, strip->Vertices[ j ].Y );
         glEnd( );
-                               glBegin( GL_POINTS );
-        for( j = 0; j < strip->Number; j++ )
-            glVertex2f( strip->Vertices[ j ].X, strip->Vertices[ j ].Y );
-                               glEnd( );
+        
+        if (fgState.StrokeFontDrawJoinDots)
+        {
+            glBegin( GL_POINTS );
+            for( j = 0; j < strip->Number; j++ )
+                glVertex2f( strip->Vertices[ j ].X, strip->Vertices[ j ].Y );
+            glEnd( );
+        }
     }
     glTranslatef( schar->Right, 0.0, 0.0 );
 }
@@ -272,7 +298,11 @@ void FGAPIENTRY glutStrokeString( void* fontID, const unsigned char *string )
     SFG_StrokeFont* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeString" );
     font = fghStrokeByID( fontID );
-    freeglut_return_if_fail( font );
+    if (!font)
+    {
+        fgWarning("glutStrokeString: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
+        return;
+    }
     if ( !string || ! *string )
         return;
 
@@ -316,35 +346,47 @@ void FGAPIENTRY glutStrokeString( void* fontID, const unsigned char *string )
 /*
  * Return the width in pixels of a stroke character
  */
-int FGAPIENTRY glutStrokeWidth( void* fontID, int character )
+GLfloat FGAPIENTRY glutStrokeWidthf( void* fontID, int character )
 {
     const SFG_StrokeChar *schar;
     SFG_StrokeFont* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeWidth" );
     font = fghStrokeByID( fontID );
+    if (!font)
+    {
+        fgWarning("glutStrokeWidth: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
+        return 0;
+    }
     freeglut_return_val_if_fail( ( character >= 0 ) &&
                                  ( character < font->Quantity ),
                                  0
     );
-    freeglut_return_val_if_fail( font, 0 );
     schar = font->Characters[ character ];
     freeglut_return_val_if_fail( schar, 0 );
 
-    return ( int )( schar->Right + 0.5 );
+    return schar->Right;
+}
+int FGAPIENTRY glutStrokeWidth(void* fontID, int character)
+{
+    return ( int )( glutStrokeWidthf(fontID,character) + 0.5f );
 }
 
 /*
  * Return the width of a string drawn using a stroke font
  */
-int FGAPIENTRY glutStrokeLength( void* fontID, const unsigned char* string )
+GLfloat FGAPIENTRY glutStrokeLengthf( void* fontID, const unsigned char* string )
 {
     unsigned char c;
-    float length = 0.0;
-    float this_line_length = 0.0;
+    GLfloat length = 0.0;
+    GLfloat this_line_length = 0.0;
     SFG_StrokeFont* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeLength" );
     font = fghStrokeByID( fontID );
-    freeglut_return_val_if_fail( font, 0 );
+    if (!font)
+    {
+        fgWarning("glutStrokeLength: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
+        return 0;
+    }
     if ( !string || ! *string )
         return 0;
 
@@ -366,7 +408,11 @@ int FGAPIENTRY glutStrokeLength( void* fontID, const unsigned char* string )
         }
     if( length < this_line_length )
         length = this_line_length;
-    return( int )( length + 0.5 );
+    return length;
+}
+int FGAPIENTRY glutStrokeLength( void* fontID, const unsigned char* string )
+{
+    return( int )( glutStrokeLengthf(fontID,string) + 0.5f );
 }
 
 /*
@@ -377,7 +423,11 @@ GLfloat FGAPIENTRY glutStrokeHeight( void* fontID )
     SFG_StrokeFont* font;
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeHeight" );
     font = fghStrokeByID( fontID );
-    freeglut_return_val_if_fail( font, 0.0 );
+    if (!font)
+    {
+        fgWarning("glutStrokeHeight: stroke font 0x%08x not found. Make sure you're not passing a bitmap font.\n",fontID);
+        return 0.f;
+    }
     return font->Height;
 }