29 #define OGLFT_NO_SOLID 1 33 #define OGLFT_NO_SOLID 1 54 #ifndef OGLFT_NO_SOLID 64 #include FT_FREETYPE_H 67 #include FT_TRIGONOMETRY_H 116 static FT_Library & instance (
void);
144 Advance (
float dx = 0,
float dy = 0):dx_ (dx), dy_ (dy)
176 BBox ():x_min_ (0), y_min_ (0), x_max_ (0), y_max_ (0)
188 x_min_ = ft_bbox.xMin / 64.;
189 y_min_ = ft_bbox.yMin / 64.;
190 x_max_ = ft_bbox.xMax / 64.;
191 y_max_ = ft_bbox.yMax / 64.;
221 if (new_value < x_min_)
225 if (new_value < y_min_)
229 if (new_value > x_max_)
233 if (new_value > y_max_)
283 typedef DisplayLists::const_iterator
DLCI;
286 typedef DisplayLists::iterator
DLI;
340 FaceData (FT_Face face,
bool free_on_exit =
true):face_ (face),
372 GLfloat foreground_color_[4];
375 GLfloat background_color_[4];
402 typedef GlyphDLists::const_iterator
GDLCI;
406 typedef GlyphDLists::iterator
GDLI;
424 Face (
const char *filename,
float point_size = 12, FT_UInt resolution =
437 Face (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
443 virtual ~
Face (
void);
461 bool addAuxiliaryFace (
const char *filename);
471 bool addAuxiliaryFace (FT_Face face);
484 compile_mode_ = compile_mode;
492 return compile_mode_;
516 void setPointSize (
float point_size);
536 void setResolution (FT_UInt resolution);
577 void setForegroundColor (GLfloat red = 0.0,
579 GLfloat blue = 0.0, GLfloat alpha = 1.0);
588 void setForegroundColor (
const GLfloat foreground_color[4]);
596 void setForegroundColor (
const QRgb foreground_color);
603 return foreground_color_[
R];
610 return foreground_color_[
G];
617 return foreground_color_[
B];
624 return foreground_color_[
A];
636 void setBackgroundColor (GLfloat red = 1.0,
638 GLfloat blue = 1.0, GLfloat alpha = 0.0);
647 void setBackgroundColor (
const GLfloat background_color[4]);
655 void setBackgroundColor (
const QRgb background_color);
662 return background_color_[
R];
669 return background_color_[
G];
676 return background_color_[
B];
683 return background_color_[
A];
690 virtual void setCharacterRotationZ (GLfloat character_rotation_z) = 0;
695 virtual GLfloat characterRotationZ (
void)
const = 0;
702 void setCharacterRotationReference (
unsigned char c);
712 void setStringRotation (GLfloat string_rotation);
719 return string_rotation_;
727 horizontal_justification)
729 horizontal_justification_ = horizontal_justification;
737 return horizontal_justification_;
745 vertical_justification)
747 vertical_justification_ = vertical_justification;
755 return vertical_justification_;
767 character_display_lists_ = character_display_lists;
776 return character_display_lists_;
782 virtual double height (
void)
const = 0;
789 virtual BBox measure (
unsigned char c) = 0;
796 virtual BBox measure (QChar c) = 0;
803 virtual BBox measure (
const char *s);
810 virtual BBox measureRaw (
const char *s);
817 virtual BBox measure (
const QString & s);
824 virtual BBox measure (
const QString & format,
double number);
831 virtual BBox measureRaw (
const QString & s);
843 GLuint compile (
const char *s);
855 GLuint compile (
const QString & s);
864 GLuint compile (
unsigned char c);
873 GLuint compile (
const QChar c);
881 void draw (
const char *s);
889 void draw (
const QString & s);
897 void draw (
unsigned char c);
906 void draw (
const QChar c);
916 void draw (GLfloat x, GLfloat y,
unsigned char c);
926 void draw (GLfloat x, GLfloat y, GLfloat z,
unsigned char c);
936 void draw (GLfloat x, GLfloat y, QChar c);
946 void draw (GLfloat x, GLfloat y, GLfloat z, QChar c);
954 void draw (GLfloat x, GLfloat y,
const char *s);
962 void draw (GLfloat x, GLfloat y, GLfloat z,
const char *s);
970 void draw (GLfloat x, GLfloat y,
const QString & s);
978 void draw (GLfloat x, GLfloat y, GLfloat z,
const QString & s);
996 void draw (GLfloat x, GLfloat y,
const QString & format,
double number);
1015 void draw (GLfloat x, GLfloat y, GLfloat z,
const QString & format,
1024 return faces_.front ().face_->ascender;
1033 return faces_.front ().face_->descender;
1044 virtual GLuint compileGlyph (FT_Face face, FT_UInt glyph_index) = 0;
1049 virtual void renderGlyph (FT_Face face, FT_UInt glyph_index) = 0;
1053 virtual void setCharSize (
void) = 0;
1057 virtual void clearCaches (
void) = 0;
1062 virtual void setRotationOffset (
void) = 0;
1066 BBox measure_nominal (
const char *s);
1068 BBox measure_nominal (
const QString & s);
1069 QString format_number (
const QString & format,
double number);
1086 } character_rotation_;
1110 static const unsigned int DEFAULT_TESSELLATION_STEPS = 4;
1146 v_[
X] = v_[
Y] = v_[
Z] = 0.;
1160 v_[
X] = (double) (ft_v->x / 64) + (double) (ft_v->x % 64) / 64.;
1161 v_[
Y] = (double) (ft_v->y / 64) + (double) (ft_v->y % 64) / 64.;
1200 double length = sqrt (v_[
X] * v_[
X] + v_[
Y] * v_[
Y] + v_[
Z] * v_[
Z]);
1217 typedef VertexInfoList::const_iterator
VILCI;
1220 typedef VertexInfoList::iterator
VILI;
1249 Polygonal (
const char *filename,
float point_size = 12,
1250 FT_UInt resolution = 100);
1259 Polygonal (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
1278 void setTessellationSteps (
unsigned int tessellation_steps);
1286 return tessellation_steps_;
1293 void setCharacterRotationX (GLfloat character_rotation_x);
1299 void setCharacterRotationY (GLfloat character_rotation_y);
1305 void setCharacterRotationZ (GLfloat character_rotation_z);
1312 return character_rotation_.x_;
1320 return character_rotation_.y_;
1328 return character_rotation_.z_;
1337 void setColorTess (
ColorTess * color_tess);
1357 return texture_tess_;
1363 double height (
void)
const;
1370 BBox measure (
unsigned char c);
1377 BBox measure (
const QChar c);
1396 BBox measure (
const QString & format,
double number)
1404 void setCharSize (
void);
1405 void setRotationOffset (
void);
1406 GLuint compileGlyph (FT_Face face, FT_UInt glyph_index);
1408 void clearCaches (
void);
1439 Outline (
const char *filename,
float point_size = 12,
1440 FT_UInt resolution = 100);
1448 Outline (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
1456 void renderGlyph (FT_Face face, FT_UInt glyph_index);
1457 static int moveToCallback (FT_Vector * to,
Outline * outline);
1458 static int lineToCallback (FT_Vector * to,
Outline * outline);
1459 static int conicToCallback (FT_Vector * control, FT_Vector * to,
1461 static int cubicToCallback (FT_Vector * control1, FT_Vector * control2,
1462 FT_Vector * to,
Outline * outline);
1513 Filled (
const char *filename,
float point_size = 12,
1514 FT_UInt resolution = 100);
1522 Filled (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
1535 return extra_vertices_;
1539 void renderGlyph (FT_Face face, FT_UInt glyph_index);
1542 static int moveToCallback (FT_Vector * to,
Filled * filled);
1543 static int lineToCallback (FT_Vector * to,
Filled * filled);
1544 static int conicToCallback (FT_Vector * control, FT_Vector * to,
1546 static int cubicToCallback (FT_Vector * control1, FT_Vector * control2,
1547 FT_Vector * to,
Filled * filled);
1548 static void vertexCallback (
VertexInfo * vertex);
1549 static void beginCallback (GLenum which);
1550 static void endCallback (
void);
1551 static void combineCallback (GLdouble coords[3],
void *vertex_data[4],
1552 GLfloat weight[4],
void **out_data,
1554 static void errorCallback (GLenum error_code);
1557 #ifndef OGLFT_NO_SOLID 1598 static const unsigned int N_POLYLINE_PTS = 4;
1633 gleDouble point_array_[N_POLYLINE_PTS][3];
1644 Solid (
const char *filename,
float point_size = 12, FT_UInt resolution =
1654 Solid (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
1664 void setDepth (
double depth);
1671 return extrusion_.depth_;
1676 void assign (gleDouble a[3],
double x,
double y,
double z)
1684 void renderGlyph (FT_Face face, FT_UInt glyph_index);
1685 static int moveToCallback (FT_Vector * to,
Solid * solid);
1686 static int lineToCallback (FT_Vector * to,
Solid * solid);
1687 static int conicToCallback (FT_Vector * control, FT_Vector * to,
1689 static int cubicToCallback (FT_Vector * control1, FT_Vector * control2,
1690 FT_Vector * to,
Solid * solid);
1713 Raster (
const char *filename,
float point_size = 12, FT_UInt resolution =
1722 Raster (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
1731 void setCharacterRotationZ (GLfloat character_rotation_z);
1737 return character_rotation_z_;
1743 double height (
void)
const;
1750 BBox measure (
unsigned char c);
1757 BBox measure (
const QChar c);
1776 BBox measure (
const QString & format,
double number)
1784 GLuint compileGlyph (FT_Face face, FT_UInt glyph_index);
1785 void setCharSize (
void);
1786 void setRotationOffset (
void);
1787 void clearCaches (
void);
1820 Monochrome (
const char *filename,
float point_size = 12,
1821 FT_UInt resolution = 100);
1829 Monochrome (FT_Face face,
float point_size = 12, FT_UInt resolution =
1836 GLubyte * invertBitmap (
const FT_Bitmap & bitmap);
1837 void renderGlyph (FT_Face face, FT_UInt glyph_index);
1871 Grayscale (
const char *filename,
float point_size = 12,
1872 FT_UInt resolution = 100);
1880 Grayscale (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
1886 GLubyte * invertPixmap (
const FT_Bitmap & bitmap);
1887 void renderGlyph (FT_Face face, FT_UInt glyph_index);
1927 Translucent (
const char *filename,
float point_size = 12,
1928 FT_UInt resolution = 100);
1936 Translucent (FT_Face face,
float point_size = 12, FT_UInt resolution =
1945 GLubyte * invertPixmapWithAlpha (
const FT_Bitmap & bitmap);
1946 void renderGlyph (FT_Face face, FT_UInt glyph_index);
1961 } character_rotation_;
1992 typedef GlyphTexObjs::const_iterator
GTOCI;
1996 typedef GlyphTexObjs::iterator
GTOI;
2009 Texture (
const char *filename,
float point_size = 12,
2010 FT_UInt resolution = 100);
2019 Texture (FT_Face face,
float point_size = 12, FT_UInt resolution = 100);
2029 void setCharacterRotationX (GLfloat character_rotation_x);
2035 void setCharacterRotationY (GLfloat character_rotation_y);
2041 void setCharacterRotationZ (GLfloat character_rotation_z);
2048 return character_rotation_.x_;
2056 return character_rotation_.y_;
2064 return character_rotation_.z_;
2070 double height (
void)
const;
2077 BBox measure (
unsigned char c);
2084 BBox measure (
const QChar c);
2103 BBox measure (
const QString & format,
double number)
2118 unsigned int nearestPowerCeil (
unsigned int a);
2126 virtual void bindTexture (FT_Face face, FT_UInt glyph_index) = 0;
2130 void setCharSize (
void);
2131 void setRotationOffset (
void);
2132 GLuint compileGlyph (FT_Face face, FT_UInt glyph_index);
2133 void renderGlyph (FT_Face face, FT_UInt glyph_index);
2134 void clearCaches (
void);
2175 FT_UInt resolution = 100);
2184 FT_UInt resolution = 100);
2190 GLubyte * invertBitmap (
const FT_Bitmap & bitmap,
int *width,
2192 void bindTexture (FT_Face face, FT_UInt glyph_index);
2233 FT_UInt resolution = 100);
2242 FT_UInt resolution = 100);
2248 GLubyte * invertPixmap (
const FT_Bitmap & bitmap,
int *width,
2250 void bindTexture (FT_Face face, FT_UInt glyph_index);
2297 FT_UInt resolution = 100);
2306 FT_UInt resolution = 100);
2312 GLubyte * invertPixmap (
const FT_Bitmap & bitmap,
int *width,
2314 void bindTexture (FT_Face face, FT_UInt glyph_index);
BBox measure(const char *s)
Baseline alignment of text (default)
Render text as a filled polygons.
float x_max_
The right-most position at which "ink" appears.
GLuint texture_name_
< A bound texture name is an integer in OpenGL.
static FT_Library library_
VertexInfoList::const_iterator VILCI
A convenience definition of the iterator over the list of vertices.
The Blue component of a color.
DisplayLists::const_iterator DLCI
A convenience definition of an iterator for display list vectors.
std::map< FT_UInt, TextureInfo > GlyphTexObjs
Type of the cache of defined glyph to texture objects mapping.
Advance(float dx=0, float dy=0)
Default constructor. An otherwise uninitialized Advance contains zeros.
The Z component of space.
unsigned int tessellationSteps(void) const
GlyphTexObjs::iterator GTOI
float y_min_
the bottom-most position at which "ink" appears.
GLfloat characterRotationY(void) const
This is the base class of the polygonal styles: outline, filled and solid.
GLfloat foregroundAlpha(void) const
virtual BBox measure(unsigned char c)=0
GLfloat characterRotationZ(void) const
TextureTess * texture_tess_
GLfloat characterRotationY(void) const
The Red component of a color.
DisplayLists & characterDisplayLists(void)
float y_max_
The top-most position at which "ink" appears.
void setVerticalJustification(enum VerticalJustification vertical_justification)
DisplayLists::iterator DLI
A convenience definition of an iterator for display list vectors.
VertexInfo(double p[2], ColorTess *color_tess=0, TextureTess *texture_tess=0)
The FreeType library instance.
Render text as a polygon outline.
GlyphDLists::iterator GDLI
bool advance_
Does rendering text affect the MODELVIEW matrix?
float point_size_
Nominal point size.
Advance(FT_Vector v)
Initialize an advance from a FreeType advance member.
GLfloat characterRotationZ(void) const
Left justified justification of text.
bool active_
the other values.)
Render text as texture mapped grayscale quads.
ColorSpace
Who to credit? Newton? I'd consider these manifest constants.
FT_Face rotation_reference_face_
The rotation reference character could be in any face.
std::vector< FaceData > faces_
float dx_
Advance increment in the X direction.
Render text as a grayscale raster image.
GLfloat characterRotationX(void) const
GLfloat rotation_offset_y_
std::vector< glePoint2D > contour_normals_
Render text as a monochrome raster image.
Render text as a translucent raster image.
Descender alignment of text.
VertexInfo(double x, double y, ColorTess *color_tess=0, TextureTess *texture_tess=0)
glePoint2D(const VertexInfo &v)
FT_UInt resolution_
Display resolution in pixels per inch.
float dy_
Advance increment in the Y direction.
void setCompileMode(enum GlyphCompileMode compile_mode)
bool valid_
Did a font load OK?
VertexInfoList & extraVertices(void)
Compile new glyphs when seen for the first time.
GLfloat foregroundRed(void) const
GLfloat backgroundRed(void) const
void assign(gleDouble a[3], double x, double y, double z)
Render text as texture mapped translucent quads.
FT_Outline_Funcs interface_
FT_UInt rotation_reference_glyph_
Render text as solid letters.
GLfloat characterRotationX(void) const
void setCharacterDisplayLists(const DisplayLists &character_display_lists)
Render text as texture mapped monochrome quads.
The Alpha (or transparency) of a color.
void setHorizontalJustification(enum HorizontalJustification horizontal_justification)
BBox measure(const char *s)
TextureTess * texture_tess_
The projection component of space.
std::map< FT_UInt, GLuint > GlyphDLists
Type of the cache of defined glyph to display list mapping.
unsigned int tessellation_steps_
GlyphDLists::const_iterator GDLCI
GLfloat characterRotationZ(void) const
GLfloat backgroundAlpha(void) const
GlyphTexObjs glyph_texobjs_
Cache of defined glyph texture objects.
int width_
The 2**l width of the texture.
VertexInfoList extra_vertices_
A place to store any extra vertices generated by the Combine callback.
Data for the gleExtrusion routine.
GLfloat string_rotation_
Rotate an entire string in the Z plane.
The Y component of space.
GLfloat foregroundGreen(void) const
GLUtesselator * tess_obj_
Advance advance_
The (total) advancement.
The X component of space.
BBox measure(const char *s)
TextureTess * textureTess(void) const
GLfloat foregroundBlue(void) const
VertexInfoList::iterator VILI
A convenience definition of the iterator over the list of vertices.
Centered alignment of text.
A face (aka font) used to render text with OpenGL.
VertexInfo(ColorTess *color_tess=0, TextureTess *texture_tess=0)
The Green component of a color.
std::vector< glePoint2D > contour_
ColorTess * colorTess(void) const
Center justified alignment of text.
Coordinates
Thanks to DesCartes, I'd consider these manifest constants.
GLfloat backgroundGreen(void) const
BBox()
Default constructor is all zeros.
void setAdvance(bool advance)
glePoint2D(double x, double y)
GlyphDLists glyph_dlists_
Cache of defined glyph display lists.
All of OGLFT C++ objects are in this namespace.
GLfloat character_rotation_z_
void(* GLUTessCallback)(void)
Callback from GLU tessellation routines.
VertexInfo(FT_Vector *ft_v, ColorTess *color_tess=0, TextureTess *texture_tess=0)
FaceData(FT_Face face, bool free_on_exit=true)
GlyphTexObjs::const_iterator GTOCI
GLfloat backgroundBlue(void) const
float x_min_
The left-most position at which "ink" appears.
Natural origin alignment of text (default)
This is the base class of the texture style.
GLfloat stringRotation(void) const
std::vector< GLuint > DisplayLists
std::list< VertexInfo *> VertexInfoList
Normally, we will consider a list of vertices.
FT_Outline_Funcs interface_
Callbacks for FreeType glyph decomposition into outlines.
DisplayLists character_display_lists_