home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
-
- #include <aux.h>
- #include <auxPrivate.h>
-
-
- /*************************************************************************
- * Text Gloabal variables
- **************************************************************************/
-
- GLint nextFontId = ZERO;
-
- /**************************************************************************
- * auxNewFont() - Create a usable font from glXUseXfont()
- **************************************************************************/
-
- GLint
- auxNewFont( char *fontName )
- {
- GLint count;
- FontInfo *new;
- GLenum err;
-
- new = (FontInfo *) malloc( sizeof( FontInfo ) );
-
- new->fontId = nextFontId++;
- new->xFontInfo = (XFontStruct *) NULL;
- new->listBase = ZERO;
- new->firstChar = ZERO;
- new->prev = (FontInfo *) NULL;
- new->next = (FontInfo *) NULL;
-
- if ( !fontHead )
- fontHead = new;
- else {
- new->next = fontHead;
- fontHead->prev = new;
- fontHead = new;
- }
-
- new->xFontInfo = XLoadQueryFont( auxState.display, fontName );
-
- if ( !new->xFontInfo ) /* safety check.. at least you get a font */
- new->xFontInfo = XLoadQueryFont( auxState.display, "fixed" );
-
- if ( !new->xFontInfo->min_byte1 && !new->xFontInfo->max_byte1 ) {
- count = new->xFontInfo->max_char_or_byte2;
- } else {
- printf( "\n\tUnable to figure out font bullshit\n" );
- return MINUS_ONE;
- }
-
- new->listBase = glGenLists(count);
- if ( new->listBase == 0 && ((err = glGetError()) != GL_NO_ERROR) )
- printf( "auxNewFont: %s\n", gluErrorString(err) );
-
- #ifdef DEBUG
- printf( "auxNewFont: listbase = %d, count = %d\n",
- new->listBase, count );
- #endif
- glXUseXFont( new->xFontInfo->fid, 0, count, new->listBase );
- if ((err = glGetError()) != GL_NO_ERROR)
- printf( "auxNewFont: %s\n", gluErrorString(err) );
-
- return new->fontId;
- }
-
-
- /**************************************************************************
- * auxRenderFontString() - Print an ASCII text string in given font
- **************************************************************************/
-
- GLvoid
- auxRenderFontString( GLint fontId, char *str )
- {
- FontInfo *tmpFont = fontHead;
- GLenum err;
-
- long oldlistbase;
-
- while ( tmpFont )
- if ( tmpFont->fontId == fontId )
- break;
- else
- tmpFont = tmpFont->next;
-
- if ( !tmpFont )
- return;
-
- glPushAttrib( GL_LIST_BIT );
- glListBase( tmpFont->listBase );
- glCallLists( strlen( str ), GL_UNSIGNED_BYTE, (GLubyte *)str );
- glPopAttrib();
- }
-
-
- /**************************************************************************
- * auxFontStringLength() - Return the length of an ASCII text string
- * in pixels for a particular font. Return MINUS_ONE if passed
- * an illegal font.
- **************************************************************************/
-
- GLint
- auxFontStringLength( GLint fontId, char *str )
- {
- char *ch;
- GLint strLength = ZERO;
- FontInfo *tmpFont = fontHead;
-
- while ( tmpFont )
- if ( tmpFont->fontId == fontId )
- break;
- else
- tmpFont = tmpFont->next;
-
- if ( !tmpFont )
- return MINUS_ONE;
-
- for ( ch = str; *ch; ch++ ) {
- int perCharWidth, perFontWidth, width;
- perCharWidth = tmpFont->xFontInfo->per_char[*ch].width;
- perFontWidth = tmpFont->xFontInfo->max_bounds.width;
- width = ( perCharWidth > perFontWidth ) ? perCharWidth : perFontWidth;
- strLength += width;
- }
-
- return strLength;
- }
-