00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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