Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

OGLFT.h

00001 // -*- c++ -*-
00002 /*
00003  * OGLFT: A library for drawing text with OpenGL using the FreeType library
00004  * Copyright (C) 2002 lignum Computing, Inc. <oglft@lignumcomputing.com>
00005  * $Id: OGLFT.h,v 1.14 2003/10/01 14:21:34 allen Exp $
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library 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 GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 #ifndef OGLFT_H
00023 #define OGLFT_H
00024 
00025 #include <cmath>
00026 #include <map>
00027 #include <list>
00028 #include <vector>
00029 #ifdef HAVE_MPATROL
00030 #include <mpdebug.h>
00031 #endif
00032 #include <GL/gl.h>
00033 #include <GL/glu.h>
00034 
00035 #ifndef OGLFT_NO_SOLID
00036 #include <GL/gle.h>
00037 #endif
00038 
00039 #ifndef OGLFT_NO_QT
00040 #include <qstring.h>
00041 #include <qcolor.h>
00042 #endif
00043 
00044 #include <ft2build.h>
00045 #include FT_FREETYPE_H
00046 #include FT_GLYPH_H
00047 #include FT_OUTLINE_H
00048 #include FT_TRIGONOMETRY_H
00049 
00051 
00052 namespace OGLFT {
00053 
00055   enum Coordinates {
00056     X, 
00057     Y, 
00058     Z, 
00059     W  
00060   };
00061 
00063   enum ColorSpace {
00064     R, 
00065     G, 
00066     B, 
00067     A, 
00068   };
00069 
00071   typedef void (*GLUTessCallback)();
00072 
00074 
00081   class Library {
00082   public:
00088     static FT_Library& instance ( void );
00089 
00090   protected:
00096     Library ( void );
00100     ~Library( void );
00101 
00102   private:
00103     static Library library;
00104     static FT_Library library_;
00105   };
00106 
00110   struct Advance {
00111     float dx_;  
00112     float dy_;  
00113 
00115     Advance ( float dx = 0, float dy = 0 ) : dx_( dx ), dy_( dy )
00116     {}
00117 
00119     Advance ( FT_Vector v )
00120     {
00121       dx_ = v.x / 64.;
00122       dy_ = v.y / 64.;
00123     }
00124 
00127     Advance& operator+= ( const FT_Vector v )
00128     {
00129       dx_ += v.x / 64.;
00130       dy_ += v.y / 64.;
00131       return *this;
00132     }
00133   };
00134 
00137   struct BBox {
00138     float x_min_;     
00139     float y_min_;     
00140     float x_max_;     
00141     float y_max_;     
00142     Advance advance_; 
00143 
00145     BBox () : x_min_( 0 ), y_min_( 0 ), x_max_( 0 ), y_max_( 0 )
00146     {}
00147 
00154     BBox ( FT_BBox ft_bbox )
00155     {
00156       x_min_ = ft_bbox.xMin / 64.;
00157       y_min_ = ft_bbox.yMin / 64.;
00158       x_max_ = ft_bbox.xMax / 64.;
00159       y_max_ = ft_bbox.yMax / 64.;
00160     }
00161 
00165     BBox& operator*= ( double k )
00166     {
00167       x_min_ *= k;
00168       y_min_ *= k;
00169       x_max_ *= k;
00170       y_max_ *= k;
00171       advance_.dx_ *= k;
00172       advance_.dy_ *= k;
00173 
00174       return *this;
00175     }
00176 
00184     BBox& operator+= ( const BBox& b )
00185     {
00186       float new_value;
00187 
00188       new_value = b.x_min_ + advance_.dx_;
00189       if ( new_value < x_min_ ) x_min_ = new_value;
00190 
00191       new_value = b.y_min_ + advance_.dy_;
00192       if ( new_value < y_min_ ) y_min_ = new_value;
00193 
00194       new_value = b.x_max_ + advance_.dx_;
00195       if ( new_value > x_max_ ) x_max_ = new_value;
00196 
00197       new_value = b.y_max_ + advance_.dy_;
00198       if ( new_value > y_max_ ) y_max_ = new_value;
00199 
00200       advance_.dx_ += b.advance_.dx_;
00201       advance_.dy_ += b.advance_.dy_;
00202 
00203       return *this;
00204     }
00205   };
00206 
00210   class ColorTess {
00211   public:
00217     virtual GLfloat* color ( GLdouble* p ) = 0;
00218   };
00219 
00223   class TextureTess {
00224   public:
00230     virtual GLfloat* texCoord ( GLdouble* p ) = 0;
00231   };
00232 
00235   typedef std::vector<GLuint> DisplayLists;
00236 
00238   typedef DisplayLists::const_iterator DLCI;
00239 
00241   typedef DisplayLists::iterator DLI;
00242 
00244 
00248   class Face {
00249   public:
00252     enum HorizontalJustification {
00253       LEFT,   
00254       ORIGIN, 
00255       CENTER, 
00256       RIGHT   
00257     };
00258 
00261     enum VerticalJustification {
00262       BOTTOM,   
00263       BASELINE, 
00264       MIDDLE,   
00265       TOP       
00266     };
00267 
00274     enum GlyphCompileMode {
00275       COMPILE,    
00276       IMMEDIATE   
00277     };
00278 
00279   private:
00287     struct FaceData {
00288       FT_Face face_;
00289       bool free_on_exit_;
00290       FaceData ( FT_Face face, bool free_on_exit = true )
00291         : face_( face ), free_on_exit_( free_on_exit )
00292       {}
00293     };
00294   protected:
00298     std::vector< FaceData > faces_;
00299 
00301     bool valid_;
00302 
00304     enum GlyphCompileMode compile_mode_;
00305 
00307     float point_size_;
00308 
00310     FT_UInt resolution_;
00311 
00313     bool advance_;
00314 
00320     GLfloat foreground_color_[4];
00321 
00323     GLfloat background_color_[4];
00324 
00326     enum HorizontalJustification horizontal_justification_;
00327     
00329     enum VerticalJustification vertical_justification_;
00330 
00332     GLfloat string_rotation_;
00333 
00336     FT_UInt rotation_reference_glyph_;
00337 
00339     FT_Face rotation_reference_face_;
00340 
00343     GLfloat rotation_offset_y_;
00344 
00346     typedef std::map< FT_UInt, GLuint > GlyphDLists;
00347 
00350     typedef GlyphDLists::const_iterator GDLCI;
00351 
00354     typedef GlyphDLists::iterator GDLI;
00355 
00357     GlyphDLists glyph_dlists_;
00358 
00361     DisplayLists character_display_lists_;
00362 
00363   public:
00372     Face ( const char* filename, float point_size = 12, FT_UInt resolution = 100 );
00373 
00384     Face ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
00385 
00390     virtual ~Face ( void );
00391 
00396     bool isValid ( void ) const { return valid_; }
00397 
00405     bool addAuxiliaryFace ( const char* filename );
00406 
00415     bool addAuxiliaryFace ( FT_Face face );
00416 
00426     void setCompileMode ( enum GlyphCompileMode compile_mode )
00427     {
00428       compile_mode_ = compile_mode;
00429     }
00430 
00434     enum GlyphCompileMode compileMode ( void ) const { return compile_mode_; }
00435 
00457     void setPointSize ( float point_size );
00458       
00462     float pointSize ( void ) { return point_size_; }
00463 
00474     void setResolution ( FT_UInt resolution );
00475       
00479     FT_UInt resolution ( void ) { return resolution_; }
00480 
00490     void setAdvance ( bool advance ) { advance_ = advance; }
00491 
00495     bool advance ( void ) const { return advance_; }
00496 
00506     void setForegroundColor ( GLfloat red = 0.0,
00507                               GLfloat green = 0.0,
00508                               GLfloat blue = 0.0,
00509                               GLfloat alpha = 1.0 );
00510 
00518     void setForegroundColor ( const GLfloat foreground_color[4] );
00519 #ifndef OGLFT_NO_QT
00520 
00526     void setForegroundColor ( const QRgb foreground_color );
00527 #endif /* OGLFT_NO_QT */
00528 
00531     GLfloat foregroundRed ( void ) const { return foreground_color_[R]; }
00535     GLfloat foregroundGreen ( void ) const { return foreground_color_[G]; }
00539     GLfloat foregroundBlue ( void ) const { return foreground_color_[B]; }
00543     GLfloat foregroundAlpha ( void ) const { return foreground_color_[A]; }
00544 
00554     void setBackgroundColor ( GLfloat red = 1.0,
00555                               GLfloat green = 1.0,
00556                               GLfloat blue = 1.0,
00557                               GLfloat alpha = 0.0 );
00558 
00566     void setBackgroundColor ( const GLfloat background_color[4] );
00567 #ifndef OGLFT_NO_QT
00568 
00574     void setBackgroundColor ( const QRgb background_color );
00575 #endif /* OGLFT_NO_QT */
00576 
00579     GLfloat backgroundRed ( void ) const { return background_color_[R]; }
00583     GLfloat backgroundGreen ( void ) const { return background_color_[G]; }
00587     GLfloat backgroundBlue ( void ) const { return background_color_[B]; }
00591     GLfloat backgroundAlpha ( void ) const { return background_color_[A]; }
00592 
00597     virtual void setCharacterRotationZ ( GLfloat character_rotation_z ) = 0;
00598 
00602     virtual GLfloat characterRotationZ ( void ) const = 0;
00603 
00609     void setCharacterRotationReference ( unsigned char c );
00610 
00619     void setStringRotation ( GLfloat string_rotation );
00620 
00624     GLfloat stringRotation ( void ) const { return string_rotation_; }
00625 
00630     void setHorizontalJustification ( enum HorizontalJustification
00631                                       horizontal_justification )
00632     {
00633       horizontal_justification_ = horizontal_justification;
00634     }
00635 
00639     enum HorizontalJustification horizontalJustification ( void ) const
00640     { return horizontal_justification_; }
00641 
00646     void setVerticalJustification ( enum VerticalJustification
00647                                     vertical_justification )
00648     {
00649       vertical_justification_ = vertical_justification;
00650     }
00651 
00655     enum VerticalJustification verticaljustification ( void )
00656       const { return vertical_justification_; }
00657 
00665     void setCharacterDisplayLists ( const DisplayLists& character_display_lists )
00666     {
00667       character_display_lists_ = character_display_lists;
00668     }
00669 
00674     DisplayLists& characterDisplayLists ( void )
00675     { return character_display_lists_; }
00676 
00680     virtual double height ( void ) const = 0;
00681 
00687     virtual BBox measure ( unsigned char c ) = 0;
00688 #ifndef OGLFT_NO_QT
00689 
00694     virtual BBox measure ( QChar c ) = 0;
00695 #endif /* OGLFT_NO_QT */
00696 
00701     virtual BBox measure ( const char* s );
00708     virtual BBox measureRaw ( const char* s );
00709 #ifndef OGLFT_NO_QT
00710 
00715     virtual BBox measure ( const QString& s );
00722     virtual BBox measure ( const QString& format, double number );
00729     virtual BBox measureRaw ( const QString& s );
00730 #endif /* OGLFT_NO_QT */
00731 
00741     GLuint compile ( const char* s );
00742 #ifndef OGLFT_NO_QT
00743 
00753     GLuint compile ( const QString& s );
00754 #endif /* OGLFT_NO_QT */
00755 
00762     GLuint compile ( unsigned char c );
00763 #ifndef OGLFT_NO_QT
00764 
00771     GLuint compile ( const QChar c );
00772 #endif /* OGLFT_NO_QT */
00773 
00779     void draw ( const char* s );
00780 #ifndef OGLFT_NO_QT
00781 
00787     void draw ( const QString& s );
00788 #endif /* OGLFT_NO_QT */
00789 
00795     void draw ( unsigned char c );
00796 
00797 #ifndef OGLFT_NO_QT
00798 
00804     void draw ( const QChar c );
00805 #endif /* OGLFT_NO_QT */
00806 
00814     void draw ( GLfloat x, GLfloat y, unsigned char c );
00824     void draw ( GLfloat x, GLfloat y, GLfloat z, unsigned char c );
00825 #ifndef OGLFT_NO_QT
00826 
00834     void draw ( GLfloat x, GLfloat y, QChar c );
00844     void draw ( GLfloat x, GLfloat y, GLfloat z, QChar c );
00845 #endif /* OGLFT_NO_QT */
00846 
00852     void draw ( GLfloat x, GLfloat y, const char* s );
00860     void draw ( GLfloat x, GLfloat y, GLfloat z, const char* s );
00861 #ifndef OGLFT_NO_QT
00862 
00868     void draw ( GLfloat x, GLfloat y, const QString& s );
00876     void draw ( GLfloat x, GLfloat y, GLfloat z, const QString& s );
00894     void draw ( GLfloat x, GLfloat y, const QString& format, double number );
00913     void draw ( GLfloat x, GLfloat y, GLfloat z, const QString& format,
00914                 double number );
00915 #endif /* OGLFT_NO_QT */
00916 
00920     int ascender ( void ) { return faces_.front().face_->ascender; }
00921 
00926     int descender ( void ) { return faces_.front().face_->descender; }
00927 
00928   protected:
00929     // The various styles override these routines
00930 
00936     virtual GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index ) = 0;
00937 
00941     virtual void renderGlyph ( FT_Face face, FT_UInt glyph_index ) = 0;
00942 
00945     virtual void setCharSize ( void ) = 0;
00946 
00949     virtual void clearCaches ( void ) = 0;
00950 
00954     virtual void setRotationOffset ( void ) = 0;
00955 
00956   private:
00957     void init ( void );
00958     BBox measure_nominal ( const char* s );
00959 #ifndef OGLFT_NO_QT
00960     BBox measure_nominal ( const QString& s );
00961     QString format_number ( const QString& format, double number );
00962 #endif /* OGLFT_NO_QT */
00963   };
00964 
00966 
00970   class Polygonal : public Face {
00971   protected:
00973     struct {
00974       bool active_;
00975       GLfloat x_, y_, z_;
00976     } character_rotation_;
00977 
00981     unsigned int tessellation_steps_;
00982 
00987     double delta_, delta2_, delta3_;
00988 
00993     double vector_scale_;
00994 
00996     FT_Outline_Funcs interface_;
00997 
01000     static const unsigned int DEFAULT_TESSELLATION_STEPS = 4;
01001 
01014     struct VertexInfo {
01015       double v_[3]; 
01016 
01017 
01018 
01019 
01022       ColorTess* color_tess_;
01023 
01026       TextureTess* texture_tess_;
01027 
01031       VertexInfo ( ColorTess* color_tess = 0, TextureTess* texture_tess = 0 )
01032         : color_tess_( color_tess ), texture_tess_( texture_tess )
01033       {
01034         v_[X] = v_[Y] = v_[Z] = 0.;
01035       }
01036 
01044       VertexInfo ( FT_Vector* ft_v, ColorTess* color_tess = 0,
01045                    TextureTess* texture_tess = 0 )
01046         : color_tess_( color_tess ), texture_tess_( texture_tess )
01047       {
01048         v_[X] = (double)( ft_v->x / 64 ) + (double)( ft_v->x % 64 ) / 64.;
01049         v_[Y] = (double)( ft_v->y / 64 ) + (double)( ft_v->y % 64 ) / 64.;
01050         v_[Z] = 0.;
01051       }
01052 
01059       VertexInfo ( double p[2], ColorTess* color_tess = 0,
01060                    TextureTess* texture_tess = 0 )
01061         : color_tess_( color_tess ), texture_tess_( texture_tess )
01062       {
01063         v_[X] = p[X];
01064         v_[Y] = p[Y];
01065         v_[Z] = 0.;
01066       }
01067 
01075       VertexInfo ( double x, double y, ColorTess* color_tess = 0,
01076                    TextureTess* texture_tess = 0 )
01077         : color_tess_( color_tess ), texture_tess_( texture_tess )
01078       {
01079         v_[X] = x;
01080         v_[Y] = y;
01081         v_[Z] = 0.;
01082       }
01083 
01086       void normalize ( void )
01087       {
01088         double length = sqrt( v_[X] * v_[X] + v_[Y] * v_[Y] + v_[Z] * v_[Z] );
01089         v_[X] /= length;
01090         v_[Y] /= length;
01091         v_[Z] /= length;
01092       }
01093     };
01094 
01099     VertexInfo last_vertex_;
01100 
01102     typedef std::list< VertexInfo* > VertexInfoList;
01103 
01105     typedef VertexInfoList::const_iterator VILCI;
01106 
01108     typedef VertexInfoList::iterator VILI;
01109 
01115     VertexInfoList vertices_;
01116 
01119     bool contour_open_;
01120 
01123     ColorTess* color_tess_;
01124 
01127     TextureTess* texture_tess_;
01128 
01129   public:
01137     Polygonal ( const char* filename, float point_size = 12,
01138                 FT_UInt resolution = 100 );
01139 
01147     Polygonal ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01148 
01152     virtual ~Polygonal ( void );
01153 
01166     void setTessellationSteps ( unsigned int tessellation_steps );
01167 
01172     unsigned int tessellationSteps ( void ) const { return tessellation_steps_; }
01173 
01178     void setCharacterRotationX ( GLfloat character_rotation_x );
01179 
01184     void setCharacterRotationY ( GLfloat character_rotation_y );
01185 
01190     void setCharacterRotationZ ( GLfloat character_rotation_z );
01191 
01195     GLfloat characterRotationX ( void ) const { return character_rotation_.x_; }
01196 
01200     GLfloat characterRotationY ( void ) const { return character_rotation_.y_; }
01201 
01205     GLfloat characterRotationZ ( void ) const { return character_rotation_.z_; }
01206 
01213     void setColorTess ( ColorTess* color_tess );
01217     ColorTess* colorTess ( void ) const { return color_tess_; }
01224     void setTextureTess ( TextureTess* texture_tess );
01228     TextureTess* textureTess ( void ) const { return texture_tess_; }
01229 
01233     double height ( void ) const;
01234 
01240     BBox measure ( unsigned char c );
01241 #ifndef OGLFT_NO_QT
01242 
01247     BBox measure ( const QChar c );
01248 #endif /* OGLFT_NO_QT */
01249 
01255     BBox measure ( const char* s ) { return Face::measure( s ); }
01256 #ifndef OGLFT_NO_QT
01257 
01263     BBox measure ( const QString& format, double number )
01264     { return Face::measure( format, number ); }
01265 #endif /* OGLFT_NO_QT */
01266 
01267   private:
01268     void init ( void );
01269     void setCharSize ( void );
01270     void setRotationOffset ( void );
01271     GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index );
01272   protected:
01273     void clearCaches ( void );
01274   };
01275 
01277 
01294   class Outline : public Polygonal {
01295   public:
01303     Outline ( const char* filename, float point_size = 12,
01304               FT_UInt resolution = 100 );
01312     Outline ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01313 
01317     ~Outline ( void );
01318   private:
01319     void init ( void );
01320     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01321     static int moveToCallback ( FT_Vector* to, Outline* outline );
01322     static int lineToCallback ( FT_Vector* to, Outline* outline );
01323     static int conicToCallback ( FT_Vector* control, FT_Vector* to, Outline* outline );
01324     static int cubicToCallback ( FT_Vector* control1, FT_Vector* control2,
01325                                  FT_Vector* to, Outline* outline );
01326   };
01327 
01329 
01352   class Filled : public Polygonal {
01355     GLUtesselator* tess_obj_;
01356 
01358     VertexInfoList extra_vertices_;
01359 
01360   protected:
01365     GLfloat depth_offset_;
01366 
01367   public:
01375     Filled ( const char* filename, float point_size = 12,
01376              FT_UInt resolution = 100 );
01384     Filled ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01389     virtual ~Filled ( void );
01390 
01395     VertexInfoList& extraVertices ( void ) { return extra_vertices_; }
01396 
01397   protected:
01398     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01399   private:
01400     void init ( void );
01401     static int moveToCallback ( FT_Vector* to, Filled* filled );
01402     static int lineToCallback ( FT_Vector* to, Filled* filled );
01403     static int conicToCallback ( FT_Vector* control, FT_Vector* to, Filled* filled);
01404     static int cubicToCallback ( FT_Vector* control1, FT_Vector* control2,
01405                                  FT_Vector* to, Filled* filled );
01406     static void vertexCallback ( VertexInfo* vertex );
01407     static void beginCallback ( GLenum which );
01408     static void endCallback ( void );
01409     static void combineCallback ( GLdouble coords[3], void* vertex_data[4],
01410                                   GLfloat weight[4], void** out_data,
01411                                   Filled* filled );
01412     static void errorCallback ( GLenum error_code );
01413   };
01414 
01415 #ifndef OGLFT_NO_SOLID
01416 
01417 
01445   class Solid : public Filled {
01446   private:
01447 
01452     FT_Outline_Funcs interface_;
01453 
01455     static const unsigned int N_POLYLINE_PTS = 4;
01456 
01458     struct glePoint2D {
01459       double p_[2];
01460       glePoint2D ( double p[2] ) { p_[X] = p[X]; p_[Y] = p[Y]; }
01461       glePoint2D ( double x, double y ) { p_[X] = x; p_[Y] = y; }
01462       glePoint2D ( const VertexInfo& v ) { p_[X] = v.v_[X]; p_[Y] = v.v_[Y]; }
01463     };
01464 
01466     struct {
01467       double depth_;
01468       struct {
01469         int x_, y_;
01470       } normal_sign_;
01471       std::vector< glePoint2D > contour_;
01472       std::vector< glePoint2D > contour_normals_;
01473       gleDouble up_[3];
01474       int n_polyline_pts_;
01475       gleDouble point_array_[N_POLYLINE_PTS][3];
01476     } extrusion_;
01477 
01478   public:
01486     Solid ( const char* filename, float point_size = 12, FT_UInt resolution = 100 );
01487 
01495     Solid ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01496 
01500     ~Solid ( void );
01505     void setDepth ( double depth );
01506       
01510     double depth ( void ) const { return extrusion_.depth_; }
01511 
01512   private:
01513     // It would be nice if C/C++ had real matrix notation (like Perl!)
01514     void assign ( gleDouble a[3], double x, double y, double z )
01515     {
01516       a[X] = x;
01517       a[Y] = y;
01518       a[Z] = z;
01519     }
01520 
01521     void init ( void );
01522     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01523     static int moveToCallback ( FT_Vector* to, Solid* solid );
01524     static int lineToCallback ( FT_Vector* to, Solid* solid );
01525     static int conicToCallback ( FT_Vector* control, FT_Vector* to, Solid* solid );
01526     static int cubicToCallback ( FT_Vector* control1, FT_Vector* control2,
01527                                  FT_Vector* to, Solid* solid );
01528   };
01529 #endif /* OGLFT_NO_SOLID */
01532 
01536   class Raster : public Face {
01537   protected:
01540     GLfloat character_rotation_z_;
01541   public:
01549     Raster ( const char* filename, float point_size = 12, FT_UInt resolution = 100 );
01557     Raster ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01561     virtual ~Raster ( void );
01566     void setCharacterRotationZ ( GLfloat character_rotation_z );
01570     GLfloat characterRotationZ ( void ) const { return character_rotation_z_; }
01571 
01575     double height ( void ) const;
01576 
01582     BBox measure ( unsigned char c );
01583 #ifndef OGLFT_NO_QT
01584 
01589     BBox measure ( const QChar c );
01590 #endif /* OGLFT_NO_QT */
01591 
01597     BBox measure ( const char* s ) { return Face::measure( s ); }
01598 #ifndef OGLFT_NO_QT
01599 
01605     BBox measure ( const QString& format, double number )
01606     { return Face::measure( format, number ); }
01607 #endif /* OGLFT_NO_QT */
01608 
01609   private:
01610     void init ( void );
01611     GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index );
01612     void setCharSize ( void );
01613     void setRotationOffset ( void );
01614     void clearCaches ( void );
01615   };
01616 
01618 
01637   class Monochrome : public Raster {
01638   public:
01646     Monochrome ( const char* filename, float point_size = 12,
01647                  FT_UInt resolution = 100 );
01655     Monochrome ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01659     ~Monochrome ( void );
01660   private:
01661     GLubyte* invertBitmap ( const FT_Bitmap& bitmap );
01662     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01663   };
01664 
01666 
01686   class Grayscale : public Raster {
01687   public:
01695     Grayscale ( const char* filename, float point_size = 12,
01696                 FT_UInt resolution = 100 );
01704     Grayscale ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01708     ~Grayscale ( void );
01709   private:
01710     GLubyte* invertPixmap ( const FT_Bitmap& bitmap );
01711     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01712   };
01713 
01715 
01741   class Translucent : public Raster {
01742   public:
01750     Translucent ( const char* filename, float point_size = 12,
01751                   FT_UInt resolution = 100 );
01759     Translucent ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01760 
01764     ~Translucent ( void );
01765 
01766   private:
01767     GLubyte* invertPixmapWithAlpha ( const FT_Bitmap& bitmap );
01768     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01769   };
01770 
01772   class Texture : public Face {
01773   protected:
01775     struct {
01776       bool active_; 
01777 
01778       GLfloat x_,   
01779         y_,         
01780         z_;         
01781     } character_rotation_;
01782 
01789     struct TextureInfo {
01790       GLuint texture_name_;  
01791       FT_Int left_bearing_,  
01792         bottom_bearing_;     
01793       int width_,            
01794         height_;             
01795       GLfloat texture_s_,    
01796 
01797         texture_t_;          
01798 
01799       FT_Vector advance_;    
01800     };
01801 
01803     typedef std::map< FT_UInt, TextureInfo > GlyphTexObjs;
01804 
01807     typedef GlyphTexObjs::const_iterator GTOCI;
01808 
01811     typedef GlyphTexObjs::iterator GTOI;
01812 
01814     GlyphTexObjs glyph_texobjs_;
01815 
01816   public:
01824     Texture ( const char* filename, float point_size = 12,
01825               FT_UInt resolution = 100 );
01826 
01834     Texture ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01835 
01839     virtual ~Texture ( void );
01844     void setCharacterRotationX ( GLfloat character_rotation_x );
01845 
01850     void setCharacterRotationY ( GLfloat character_rotation_y );
01851 
01856     void setCharacterRotationZ ( GLfloat character_rotation_z );
01857 
01861     GLfloat characterRotationX ( void ) const { return character_rotation_.x_; }
01862 
01866     GLfloat characterRotationY ( void ) const { return character_rotation_.y_; }
01867 
01871     GLfloat characterRotationZ ( void ) const { return character_rotation_.z_; }
01872 
01876     double height ( void ) const;
01877 
01883     BBox measure ( unsigned char c );
01884 #ifndef OGLFT_NO_QT
01885 
01890     BBox measure ( const QChar c );
01891 #endif /* OGLFT_NO_QT */
01892 
01898     BBox measure ( const char* s ) { return Face::measure( s ); }
01899 #ifndef OGLFT_NO_QT
01900 
01906     BBox measure ( const QString& format, double number )
01907     { return Face::measure( format, number ); }
01908 #endif /* OGLFT_NO_QT */
01909 
01910   protected:
01919     unsigned int nearestPowerCeil ( unsigned int a );
01927     virtual void bindTexture ( FT_Face face, FT_UInt glyph_index ) = 0;
01928 
01929   private:
01930     void init ( void );
01931     void setCharSize ( void );
01932     void setRotationOffset ( void );
01933     GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index );
01934     void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01935     void clearCaches ( void );
01936   };
01937 
01939 
01965   class MonochromeTexture : public Texture {
01966   public:
01974     MonochromeTexture ( const char* filename, float point_size = 12,
01975                         FT_UInt resolution = 100 );
01983     MonochromeTexture ( FT_Face face, float point_size = 12,
01984                         FT_UInt resolution = 100 );
01988     ~MonochromeTexture ( void );
01989   private:
01990     GLubyte* invertBitmap ( const FT_Bitmap& bitmap, int* width, int* height );
01991     void bindTexture ( FT_Face face, FT_UInt glyph_index );
01992   };
01993 
01995 
02021   class GrayscaleTexture : public Texture {
02022   public:
02030     GrayscaleTexture ( const char* filename, float point_size = 12,
02031                        FT_UInt resolution = 100 );
02039     GrayscaleTexture ( FT_Face face, float point_size = 12,
02040                        FT_UInt resolution = 100 );
02044     ~GrayscaleTexture ( void );
02045   private:
02046     GLubyte* invertPixmap ( const FT_Bitmap& bitmap, int* width, int* height );
02047     void bindTexture ( FT_Face face, FT_UInt glyph_index );
02048   };
02049 
02051 
02083   class TranslucentTexture : public Texture {
02084   public:
02092     TranslucentTexture ( const char* filename, float point_size = 12,
02093                          FT_UInt resolution = 100 );
02101     TranslucentTexture ( FT_Face face, float point_size = 12,
02102                          FT_UInt resolution = 100 );
02106     ~TranslucentTexture ( void );
02107   private:
02108     GLubyte* invertPixmap ( const FT_Bitmap& bitmap, int* width, int* height );
02109     void bindTexture ( FT_Face face, FT_UInt glyph_index );
02110   };
02111 } // Close OGLFT namespace
02112 #endif /* OGLFT_H */

Generated on Wed Oct 1 10:39:03 2003 for OGLFT by doxygen1.2.18