00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
00696
00701 virtual BBox measure ( const char* s );
00702 #ifndef OGLFT_NO_QT
00703
00708 virtual BBox measure ( const QString s );
00715 virtual BBox measure ( const QString& format, double number );
00716 #endif
00717
00727 GLuint compile ( const char* s );
00728 #ifndef OGLFT_NO_QT
00729
00739 GLuint compile ( const QString s );
00740 #endif
00741
00748 GLuint compile ( unsigned char c );
00749 #ifndef OGLFT_NO_QT
00750
00757 GLuint compile ( const QChar c );
00758 #endif
00759
00765 void draw ( const char* s );
00766 #ifndef OGLFT_NO_QT
00767
00773 void draw ( const QString s );
00774 #endif
00775
00781 void draw ( unsigned char c );
00782
00783 #ifndef OGLFT_NO_QT
00784
00790 void draw ( const QChar c );
00791 #endif
00792
00800 void draw ( GLfloat x, GLfloat y, unsigned char c );
00801 #ifndef OGLFT_NO_QT
00802
00810 void draw ( GLfloat x, GLfloat y, QChar c );
00811 #endif
00812
00818 void draw ( GLfloat x, GLfloat y, const char* s );
00819 #ifndef OGLFT_NO_QT
00820
00826 void draw ( GLfloat x, GLfloat y, const QString s );
00844 void draw ( GLfloat x, GLfloat y, const QString& format, double number );
00845 #endif
00846
00850 int ascender ( void ) { return faces_.front().face_->ascender; }
00851
00856 int descender ( void ) { return faces_.front().face_->descender; }
00857
00858 protected:
00859
00860
00866 virtual GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index ) = 0;
00867
00871 virtual void renderGlyph ( FT_Face face, FT_UInt glyph_index ) = 0;
00872
00875 virtual void setCharSize ( void ) = 0;
00876
00879 virtual void clearCaches ( void ) = 0;
00880
00884 virtual void setRotationOffset ( void ) = 0;
00885
00886 private:
00887 void init ( void );
00888 BBox measure_nominal ( const char* s );
00889 #ifndef OGLFT_NO_QT
00890 BBox measure_nominal ( const QString s );
00891 QString format_number ( const QString& format, double number );
00892 #endif
00893 };
00894
00896
00900 class Polygonal : public Face {
00901 protected:
00903 struct {
00904 bool active_;
00905 GLfloat x_, y_, z_;
00906 } character_rotation_;
00907
00911 unsigned int tessellation_steps_;
00912
00917 double delta_, delta2_, delta3_;
00918
00923 double vector_scale_;
00924
00926 FT_Outline_Funcs interface_;
00927
00930 static const unsigned int DEFAULT_TESSELLATION_STEPS = 4;
00931
00944 struct VertexInfo {
00945 double v_[3];
00946
00947
00948
00949
00952 ColorTess* color_tess_;
00953
00956 TextureTess* texture_tess_;
00957
00961 VertexInfo ( ColorTess* color_tess = 0, TextureTess* texture_tess = 0 )
00962 : color_tess_( color_tess ), texture_tess_( texture_tess )
00963 {
00964 v_[X] = v_[Y] = v_[Z] = 0.;
00965 }
00966
00974 VertexInfo ( FT_Vector* ft_v, ColorTess* color_tess = 0,
00975 TextureTess* texture_tess = 0 )
00976 : color_tess_( color_tess ), texture_tess_( texture_tess )
00977 {
00978 v_[X] = (double)( ft_v->x / 64 ) + (double)( ft_v->x % 64 ) / 64.;
00979 v_[Y] = (double)( ft_v->y / 64 ) + (double)( ft_v->y % 64 ) / 64.;
00980 v_[Z] = 0.;
00981 }
00982
00989 VertexInfo ( double p[2], ColorTess* color_tess = 0,
00990 TextureTess* texture_tess = 0 )
00991 : color_tess_( color_tess ), texture_tess_( texture_tess )
00992 {
00993 v_[X] = p[X];
00994 v_[Y] = p[Y];
00995 v_[Z] = 0.;
00996 }
00997
01005 VertexInfo ( double x, double y, ColorTess* color_tess = 0,
01006 TextureTess* texture_tess = 0 )
01007 : color_tess_( color_tess ), texture_tess_( texture_tess )
01008 {
01009 v_[X] = x;
01010 v_[Y] = y;
01011 v_[Z] = 0.;
01012 }
01013
01016 void normalize ( void )
01017 {
01018 double length = sqrt( v_[X] * v_[X] + v_[Y] * v_[Y] + v_[Z] * v_[Z] );
01019 v_[X] /= length;
01020 v_[Y] /= length;
01021 v_[Z] /= length;
01022 }
01023 };
01024
01029 VertexInfo last_vertex_;
01030
01032 typedef std::list< VertexInfo* > VertexInfoList;
01033
01035 typedef VertexInfoList::const_iterator VILCI;
01036
01038 typedef VertexInfoList::iterator VILI;
01039
01045 VertexInfoList vertices_;
01046
01049 bool contour_open_;
01050
01053 ColorTess* color_tess_;
01054
01057 TextureTess* texture_tess_;
01058
01059 public:
01067 Polygonal ( const char* filename, float point_size = 12,
01068 FT_UInt resolution = 100 );
01069
01077 Polygonal ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01078
01082 virtual ~Polygonal ( void );
01083
01096 void setTessellationSteps ( unsigned int tessellation_steps );
01097
01102 unsigned int tessellationSteps ( void ) const { return tessellation_steps_; }
01103
01108 void setCharacterRotationX ( GLfloat character_rotation_x );
01109
01114 void setCharacterRotationY ( GLfloat character_rotation_y );
01115
01120 void setCharacterRotationZ ( GLfloat character_rotation_z );
01121
01125 GLfloat characterRotationX ( void ) const { return character_rotation_.x_; }
01126
01130 GLfloat characterRotationY ( void ) const { return character_rotation_.y_; }
01131
01135 GLfloat characterRotationZ ( void ) const { return character_rotation_.z_; }
01136
01143 void setColorTess ( ColorTess* color_tess );
01147 ColorTess* colorTess ( void ) const { return color_tess_; }
01154 void setTextureTess ( TextureTess* texture_tess );
01158 TextureTess* textureTess ( void ) const { return texture_tess_; }
01159
01163 double height ( void ) const;
01164
01170 BBox measure ( unsigned char c );
01171 #ifndef OGLFT_NO_QT
01172
01177 BBox measure ( const QChar c );
01178 #endif
01179
01185 BBox measure ( const char* s ) { return Face::measure( s ); }
01186 #ifndef OGLFT_NO_QT
01187
01193 BBox measure ( const QString& format, double number )
01194 { return Face::measure( format, number ); }
01195 #endif
01196
01197 private:
01198 void init ( void );
01199 void setCharSize ( void );
01200 void setRotationOffset ( void );
01201 GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index );
01202 protected:
01203 void clearCaches ( void );
01204 };
01205
01207
01224 class Outline : public Polygonal {
01225 public:
01233 Outline ( const char* filename, float point_size = 12,
01234 FT_UInt resolution = 100 );
01242 Outline ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01243
01247 ~Outline ( void );
01248 private:
01249 void init ( void );
01250 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01251 static int moveToCallback ( FT_Vector* to, Outline* outline );
01252 static int lineToCallback ( FT_Vector* to, Outline* outline );
01253 static int conicToCallback ( FT_Vector* control, FT_Vector* to, Outline* outline );
01254 static int cubicToCallback ( FT_Vector* control1, FT_Vector* control2,
01255 FT_Vector* to, Outline* outline );
01256 };
01257
01259
01282 class Filled : public Polygonal {
01285 GLUtesselator* tess_obj_;
01286
01288 VertexInfoList extra_vertices_;
01289
01290 protected:
01295 GLfloat depth_offset_;
01296
01297 public:
01305 Filled ( const char* filename, float point_size = 12,
01306 FT_UInt resolution = 100 );
01314 Filled ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01319 virtual ~Filled ( void );
01320
01325 VertexInfoList& extraVertices ( void ) { return extra_vertices_; }
01326
01327 protected:
01328 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01329 private:
01330 void init ( void );
01331 static int moveToCallback ( FT_Vector* to, Filled* filled );
01332 static int lineToCallback ( FT_Vector* to, Filled* filled );
01333 static int conicToCallback ( FT_Vector* control, FT_Vector* to, Filled* filled);
01334 static int cubicToCallback ( FT_Vector* control1, FT_Vector* control2,
01335 FT_Vector* to, Filled* filled );
01336 static void vertexCallback ( VertexInfo* vertex );
01337 static void beginCallback ( GLenum which );
01338 static void endCallback ( void );
01339 static void combineCallback ( GLdouble coords[3], void* vertex_data[4],
01340 GLfloat weight[4], void** out_data,
01341 Filled* filled );
01342 static void errorCallback ( GLenum error_code );
01343 };
01344
01345 #ifndef OGLFT_NO_SOLID
01346
01347
01375 class Solid : public Filled {
01376 private:
01377
01382 FT_Outline_Funcs interface_;
01383
01385 static const unsigned int N_POLYLINE_PTS = 4;
01386
01388 struct glePoint2D {
01389 double p_[2];
01390 glePoint2D ( double p[2] ) { p_[X] = p[X]; p_[Y] = p[Y]; }
01391 glePoint2D ( double x, double y ) { p_[X] = x; p_[Y] = y; }
01392 glePoint2D ( const VertexInfo& v ) { p_[X] = v.v_[X]; p_[Y] = v.v_[Y]; }
01393 };
01394
01396 struct {
01397 double depth_;
01398 struct {
01399 int x_, y_;
01400 } normal_sign_;
01401 std::vector< glePoint2D > contour_;
01402 std::vector< glePoint2D > contour_normals_;
01403 gleDouble up_[3];
01404 int n_polyline_pts_;
01405 gleDouble point_array_[N_POLYLINE_PTS][3];
01406 } extrusion_;
01407
01408 public:
01416 Solid ( const char* filename, float point_size = 12, FT_UInt resolution = 100 );
01417
01425 Solid ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01426
01430 ~Solid ( void );
01435 void setDepth ( double depth );
01436
01440 double depth ( void ) const { return extrusion_.depth_; }
01441
01442 private:
01443
01444 void assign ( gleDouble a[3], double x, double y, double z )
01445 {
01446 a[X] = x;
01447 a[Y] = y;
01448 a[Z] = z;
01449 }
01450
01451 void init ( void );
01452 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01453 static int moveToCallback ( FT_Vector* to, Solid* solid );
01454 static int lineToCallback ( FT_Vector* to, Solid* solid );
01455 static int conicToCallback ( FT_Vector* control, FT_Vector* to, Solid* solid );
01456 static int cubicToCallback ( FT_Vector* control1, FT_Vector* control2,
01457 FT_Vector* to, Solid* solid );
01458 };
01459 #endif
01462
01466 class Raster : public Face {
01467 protected:
01470 GLfloat character_rotation_z_;
01471 public:
01479 Raster ( const char* filename, float point_size = 12, FT_UInt resolution = 100 );
01487 Raster ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01491 virtual ~Raster ( void );
01496 void setCharacterRotationZ ( GLfloat character_rotation_z );
01500 GLfloat characterRotationZ ( void ) const { return character_rotation_z_; }
01501
01505 double height ( void ) const;
01506
01512 BBox measure ( unsigned char c );
01513 #ifndef OGLFT_NO_QT
01514
01519 BBox measure ( const QChar c );
01520 #endif
01521
01527 BBox measure ( const char* s ) { return Face::measure( s ); }
01528 #ifndef OGLFT_NO_QT
01529
01535 BBox measure ( const QString& format, double number )
01536 { return Face::measure( format, number ); }
01537 #endif
01538
01539 private:
01540 void init ( void );
01541 GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index );
01542 void setCharSize ( void );
01543 void setRotationOffset ( void );
01544 void clearCaches ( void );
01545 };
01546
01548
01567 class Monochrome : public Raster {
01568 public:
01576 Monochrome ( const char* filename, float point_size = 12,
01577 FT_UInt resolution = 100 );
01585 Monochrome ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01589 ~Monochrome ( void );
01590 private:
01591 GLubyte* invertBitmap ( const FT_Bitmap& bitmap );
01592 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01593 };
01594
01596
01616 class Grayscale : public Raster {
01617 public:
01625 Grayscale ( const char* filename, float point_size = 12,
01626 FT_UInt resolution = 100 );
01634 Grayscale ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01638 ~Grayscale ( void );
01639 private:
01640 GLubyte* invertPixmap ( const FT_Bitmap& bitmap );
01641 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01642 };
01643
01645
01671 class Translucent : public Raster {
01672 public:
01680 Translucent ( const char* filename, float point_size = 12,
01681 FT_UInt resolution = 100 );
01689 Translucent ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01690
01694 ~Translucent ( void );
01695
01696 private:
01697 GLubyte* invertPixmapWithAlpha ( const FT_Bitmap& bitmap );
01698 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01699 };
01700
01702 class Texture : public Face {
01703 protected:
01705 struct {
01706 bool active_;
01707
01708 GLfloat x_,
01709 y_,
01710 z_;
01711 } character_rotation_;
01712
01719 struct TextureInfo {
01720 GLuint texture_name_;
01721 FT_Int left_bearing_,
01722 bottom_bearing_;
01723 int width_,
01724 height_;
01725 GLfloat texture_s_,
01726
01727 texture_t_;
01728
01729 FT_Vector advance_;
01730 };
01731
01733 typedef std::map< FT_UInt, TextureInfo > GlyphTexObjs;
01734
01737 typedef GlyphTexObjs::const_iterator GTOCI;
01738
01741 typedef GlyphTexObjs::iterator GTOI;
01742
01744 GlyphTexObjs glyph_texobjs_;
01745
01746 public:
01754 Texture ( const char* filename, float point_size = 12,
01755 FT_UInt resolution = 100 );
01756
01764 Texture ( FT_Face face, float point_size = 12, FT_UInt resolution = 100 );
01765
01769 virtual ~Texture ( void );
01774 void setCharacterRotationX ( GLfloat character_rotation_x );
01775
01780 void setCharacterRotationY ( GLfloat character_rotation_y );
01781
01786 void setCharacterRotationZ ( GLfloat character_rotation_z );
01787
01791 GLfloat characterRotationX ( void ) const { return character_rotation_.x_; }
01792
01796 GLfloat characterRotationY ( void ) const { return character_rotation_.y_; }
01797
01801 GLfloat characterRotationZ ( void ) const { return character_rotation_.z_; }
01802
01806 double height ( void ) const;
01807
01813 BBox measure ( unsigned char c );
01814 #ifndef OGLFT_NO_QT
01815
01820 BBox measure ( const QChar c );
01821 #endif
01822
01828 BBox measure ( const char* s ) { return Face::measure( s ); }
01829 #ifndef OGLFT_NO_QT
01830
01836 BBox measure ( const QString& format, double number )
01837 { return Face::measure( format, number ); }
01838 #endif
01839
01840 protected:
01849 unsigned int nearestPowerCeil ( unsigned int a );
01857 virtual void bindTexture ( FT_Face face, FT_UInt glyph_index ) = 0;
01858
01859 private:
01860 void init ( void );
01861 void setCharSize ( void );
01862 void setRotationOffset ( void );
01863 GLuint compileGlyph ( FT_Face face, FT_UInt glyph_index );
01864 void renderGlyph ( FT_Face face, FT_UInt glyph_index );
01865 void clearCaches ( void );
01866 };
01867
01869
01895 class MonochromeTexture : public Texture {
01896 public:
01904 MonochromeTexture ( const char* filename, float point_size = 12,
01905 FT_UInt resolution = 100 );
01913 MonochromeTexture ( FT_Face face, float point_size = 12,
01914 FT_UInt resolution = 100 );
01918 ~MonochromeTexture ( void );
01919 private:
01920 GLubyte* invertBitmap ( const FT_Bitmap& bitmap, int* width, int* height );
01921 void bindTexture ( FT_Face face, FT_UInt glyph_index );
01922 };
01923
01925
01951 class GrayscaleTexture : public Texture {
01952 public:
01960 GrayscaleTexture ( const char* filename, float point_size = 12,
01961 FT_UInt resolution = 100 );
01969 GrayscaleTexture ( FT_Face face, float point_size = 12,
01970 FT_UInt resolution = 100 );
01974 ~GrayscaleTexture ( void );
01975 private:
01976 GLubyte* invertPixmap ( const FT_Bitmap& bitmap, int* width, int* height );
01977 void bindTexture ( FT_Face face, FT_UInt glyph_index );
01978 };
01979
01981
02013 class TranslucentTexture : public Texture {
02014 public:
02022 TranslucentTexture ( const char* filename, float point_size = 12,
02023 FT_UInt resolution = 100 );
02031 TranslucentTexture ( FT_Face face, float point_size = 12,
02032 FT_UInt resolution = 100 );
02036 ~TranslucentTexture ( void );
02037 private:
02038 GLubyte* invertPixmap ( const FT_Bitmap& bitmap, int* width, int* height );
02039 void bindTexture ( FT_Face face, FT_UInt glyph_index );
02040 };
02041 }
02042 #endif