00001 //=========================================================================== 00002 /* 00003 This file is part of the CHAI 3D visualization and haptics libraries. 00004 Copyright (C) 2003-2009 by CHAI 3D. All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License("GPL") version 2 00008 as published by the Free Software Foundation. 00009 00010 For using the CHAI 3D libraries with software that can not be combined 00011 with the GNU GPL, and for taking advantage of the additional benefits 00012 of our support services, please contact CHAI 3D about acquiring a 00013 Professional Edition License. 00014 00015 \author <http://www.chai3d.org> 00016 \author Dan Morris 00017 \version 2.0.0 $Rev: 251 $ 00018 */ 00019 //=========================================================================== 00020 00021 //--------------------------------------------------------------------------- 00022 #ifndef CFontH 00023 #define CFontH 00024 //--------------------------------------------------------------------------- 00025 #include "extras/CGlobals.h" 00026 #include <stdlib.h> 00027 #include <string.h> 00028 //--------------------------------------------------------------------------- 00030 #define CHAI_DEFAULT_FONT_FACE "Arial" 00032 #define CHAI_DEFAULT_FONT_SIZE 12.0f 00033 //--------------------------------------------------------------------------- 00034 00035 //=========================================================================== 00043 //=========================================================================== 00044 00045 //=========================================================================== 00058 //=========================================================================== 00059 class cFont 00060 { 00061 00062 public: 00063 00064 //----------------------------------------------------------------------- 00065 // CONSTRUCTOR & DESTRUCTOR: 00066 //----------------------------------------------------------------------- 00067 00069 cFont(); 00070 00072 virtual ~cFont() {} 00073 00074 00075 //----------------------------------------------------------------------- 00076 // METHODS: 00077 //----------------------------------------------------------------------- 00078 00080 static cFont* createFont(); 00081 00083 static cFont* createFont(const cFont* oldFont); 00084 00086 virtual int renderString(const char* a_str)=0; 00087 00089 virtual void setFontFace(const char* a_faceName); 00090 00092 virtual void getFontFace(char* a_faceName) const { strcpy(a_faceName,m_fontFace); } 00093 00095 virtual void setPointSize(const float& a_pointSize) { m_pointSize = a_pointSize; } 00096 00098 virtual float getPointSize() const { return m_pointSize; } 00099 00101 virtual int getCharacterWidth(const unsigned char& a_char); 00102 00103 protected: 00104 00105 //----------------------------------------------------------------------- 00106 // MEMBERS: 00107 //----------------------------------------------------------------------- 00108 00110 float m_pointSize; 00111 00113 char m_fontFace[255]; 00114 00116 int m_char_widths[255]; 00117 }; 00118 00119 00120 //=========================================================================== 00128 //=========================================================================== 00129 class cGLUTBitmapFont : public cFont 00130 { 00131 00132 public: 00133 00134 //----------------------------------------------------------------------- 00135 // CONSTRUCTOR & DESTRUCTOR: 00136 //----------------------------------------------------------------------- 00137 00139 cGLUTBitmapFont() { } 00140 00142 virtual ~cGLUTBitmapFont() { } 00143 00144 00145 //----------------------------------------------------------------------- 00146 // METHODS: 00147 //----------------------------------------------------------------------- 00148 00150 virtual int getCharacterWidth(const unsigned char& a_char); 00151 00156 virtual int renderString(const char* a_str); 00157 00158 00159 protected: 00160 00161 //----------------------------------------------------------------------- 00162 // METHODS: 00163 //----------------------------------------------------------------------- 00164 00166 int getBestFontMatch(); 00167 }; 00168 00169 00170 #if defined(_WIN32) 00171 00172 //=========================================================================== 00180 //=========================================================================== 00181 class cWin32BitmapFont : public cFont 00182 { 00183 00184 public: 00185 00186 //----------------------------------------------------------------------- 00187 // CONSTRUCTOR & DESTRUCTOR: 00188 //----------------------------------------------------------------------- 00189 00191 cWin32BitmapFont(); 00192 00194 virtual ~cWin32BitmapFont(); 00195 00196 00197 //----------------------------------------------------------------------- 00198 // METHODS: 00199 //----------------------------------------------------------------------- 00200 00205 virtual int renderString(const char* a_str); 00206 00208 virtual void setFontFace(const char* a_faceName); 00209 00211 virtual void setPointSize(const float& a_pointSize); 00212 00218 virtual LOGFONT* getLogFont() { return &m_logfont; } 00219 00224 bool m_solidFont; 00225 00227 virtual int getCharacterWidth(const unsigned char& a_char); 00228 00229 protected: 00230 00231 //----------------------------------------------------------------------- 00232 // MEMBERS: 00233 //----------------------------------------------------------------------- 00234 00236 int m_bitmap_font_base; 00237 00239 LOGFONT m_logfont; 00240 00242 float m_outlineFontDeviation; 00243 00245 float m_outlineFontExtrusion; 00246 00248 bool m_usePolygonsForOutlineFonts; 00249 00250 00251 //----------------------------------------------------------------------- 00252 // METHODS: 00253 //----------------------------------------------------------------------- 00254 00256 int initialize(); 00257 00259 int uninitialize(); 00260 }; 00261 00262 //--------------------------------------------------------------------------- 00263 #endif // _WIN32 00264 //--------------------------------------------------------------------------- 00265 #endif 00266 //---------------------------------------------------------------------------