FontStyle.h

Go to the documentation of this file.
00001 
00003 //    Copyright 2004, SenseGraphics AB
00004 //
00005 //    This file is part of H3D API.
00006 //
00007 //    H3D API is free software; you can redistribute it and/or modify
00008 //    it under the terms of the GNU General Public License as published by
00009 //    the Free Software Foundation; either version 2 of the License, or
00010 //    (at your option) any later version.
00011 //
00012 //    H3D API is distributed in the hope that it will be useful,
00013 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //    GNU General Public License for more details.
00016 //
00017 //    You should have received a copy of the GNU General Public License
00018 //    along with H3D API; if not, write to the Free Software
00019 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 //    A commercial license is also available. Please contact us at 
00022 //    www.sensegraphics.com for more information.
00023 //
00024 //
00028 //
00030 #ifndef __FONTSTYLE_H__
00031 #define __FONTSTYLE_H__
00032 
00033 #include "X3DFontStyleNode.h"
00034 #include "SFString.h"
00035 #include "MFString.h"
00036 #include "SFBool.h"
00037 #include "SFFloat.h"
00038 
00039 #if defined( HAVE_FREETYPE ) && defined( HAVE_FTGL )
00040 #ifdef _MSC_VER
00041 #pragma comment( lib, "ftgl_dynamic_MTD.lib" )
00042 #endif
00043 #include <FTGLTextureFont.h>
00044 #endif
00045 
00046 namespace H3D {
00047 
00157   class H3DAPI_API FontStyle : public X3DFontStyleNode {
00158   public:
00160     H3D_VALUE_EXCEPTION( string, InvalidFontStyleStyle );
00162     H3D_VALUE_EXCEPTION( string, InvalidFontStyleJustify );
00164     H3D_VALUE_EXCEPTION( string, InvalidFontStyleRenderType );
00165 
00167     FontStyle( Inst< SFNode   > _metadata    = 0,
00168                Inst< MFString > _family      = 0,
00169                Inst< SFBool   > _horizontal  = 0,
00170                Inst< MFString > _justify     = 0,
00171                Inst< SFString > _language    = 0,
00172                Inst< SFBool   > _leftToRight = 0,
00173                Inst< SFFloat  > _size        = 0,
00174                Inst< SFFloat  > _spacing     = 0,
00175                Inst< SFString > _style       = 0,
00176                Inst< SFBool   > _topToBottom = 0,
00177                Inst< SFString > _renderType  = 0 );
00178 #if defined( HAVE_FREETYPE ) && defined( HAVE_FTGL )
00182     virtual void buildFonts();
00183 
00186     virtual bool isTopToBottom() {
00187       return topToBottom->getValue();
00188     }
00189 
00192     virtual bool isLeftToRight() {
00193       return leftToRight->getValue();
00194     }
00195 
00198     virtual H3DFloat getSpacing() { 
00199       return spacing->getValue();
00200     }
00201 
00203     virtual Alignment getAlignment() {
00204       if( horizontal->getValue() )
00205         return HORIZONTAL;
00206       else
00207         return VERTICAL;
00208     }
00209     
00211     virtual void renderChar( unsigned char c ) {
00212       char t[2];  t[0]=c; t[1]='\0';
00213       glPushMatrix();
00214       H3DFloat s = size->getValue();
00215       H3DFloat default_size = font->Ascender() - font->Descender();
00216       H3DFloat scale_factor = s / default_size;
00217       glScalef( scale_factor, scale_factor, scale_factor );
00218 
00219       if( renderType->getValue() == "TEXTURE" ) {
00220         glEnable( GL_TEXTURE_2D);
00221         glEnable( GL_ALPHA_TEST );
00222         glAlphaFunc (GL_GREATER, 0);
00223       }
00224       
00225       glNormal3f( 0, 0, 1 );
00226       font->Render( t );
00227       
00228       if( renderType->getValue() == "TEXTURE" ) {
00229         glDisable( GL_ALPHA_TEST );
00230         glDisable( GL_TEXTURE_2D);
00231       }
00232       glPopMatrix();
00233     }
00234     
00237     virtual H3DFloat ascender() {
00238       H3DFloat default_size = font->Ascender() - font->Descender();
00239       H3DFloat scale_factor = size->getValue() / default_size;
00240       return font->Ascender() * scale_factor;
00241     }
00242 
00245     virtual H3DFloat descender() {
00246       H3DFloat default_size = font->Ascender() - font->Descender();
00247       H3DFloat scale_factor = size->getValue() / default_size;
00248       return font->Descender() * scale_factor;
00249     }
00250 
00253     virtual Vec3f charDimensions( unsigned char c ) {
00254       
00255       H3DFloat default_size = font->Ascender() - font->Descender();
00256       H3DFloat scale_factor = size->getValue() / default_size;
00257       char t[2];  t[0]=c; t[1]='\0';
00258       float llx, lly, llz, urx, ury, urz;
00259       font->BBox( t, llx, lly, llz, urx, ury, urz );
00260 
00261       return Vec3f(font->Advance(t),
00262                    font->Ascender()-font->Descender(),
00263                    llz-urz) * scale_factor;
00264 
00265     }
00266 
00268     virtual Justification getMajorJustification();
00269 
00271     virtual Justification getMinorJustification();
00272 
00273 #endif
00282     auto_ptr< MFString >  family;
00283 
00291     auto_ptr< SFBool   >  horizontal;
00292 
00301     auto_ptr< MFString >  justify;
00302 
00308     auto_ptr< SFString >  language;
00309 
00319     auto_ptr< SFBool   >  leftToRight;
00320 
00328     auto_ptr< SFFloat  >  size;
00329 
00337     auto_ptr< SFFloat  >  spacing;
00338 
00348     auto_ptr< SFString >  style;
00349 
00359     auto_ptr< SFBool >  topToBottom;
00360 
00369     auto_ptr< SFString > renderType;
00370 
00372     static H3DNodeDatabase database;
00373   protected:
00374 #if defined( HAVE_FREETYPE ) && defined( HAVE_FTGL )
00377     FTFont *font;   
00378 #endif
00379   };
00380 }
00381 
00382 #endif

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5