1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-05-11 11:33:56 +00:00

remove every part of FTGL that isn't necessary for Aquaria

This commit is contained in:
fgenesis 2025-03-04 03:55:46 +01:00
parent 36826bfec5
commit 586a94325e
26 changed files with 6 additions and 2205 deletions

View file

@ -4,54 +4,29 @@ include_directories(include)
set(FTGL_SRCS
include/FTBBox.h
include/FTBitmapGlyph.h
include/FTCharmap.h
include/FTCharToGlyphIndexMap.h
include/FTContour.h
include/FTExtrdGlyph.h
include/FTFace.h
include/FTFont.h
include/FTGL.h
include/FTGLBitmapFont.h
include/FTGLExtrdFont.h
include/FTGLOutlineFont.h
include/FTGLPixmapFont.h
include/FTGLPolygonFont.h
include/FTGLTextureFont.h
include/FTGlyph.h
include/FTGlyphContainer.h
include/FTLibrary.h
include/FTList.h
include/FTOutlineGlyph.h
include/FTPixmapGlyph.h
include/FTPoint.h
include/FTPolyGlyph.h
include/FTSize.h
include/FTTextureGlyph.h
include/FTVector.h
# include/FTVectoriser.h
src/FTBitmapGlyph.cpp
src/FTCharmap.cpp
src/FTContour.cpp
src/FTExtrdGlyph.cpp
src/FTFace.cpp
src/FTFont.cpp
src/FTGLBitmapFont.cpp
src/FTGLExtrdFont.cpp
src/FTGLOutlineFont.cpp
src/FTGLPixmapFont.cpp
src/FTGLPolygonFont.cpp
src/FTGLTextureFont.cpp
src/FTGlyph.cpp
src/FTGlyphContainer.cpp
src/FTLibrary.cpp
src/FTOutlineGlyph.cpp
src/FTPixmapGlyph.cpp
src/FTPoint.cpp
src/FTPolyGlyph.cpp
src/FTSize.cpp
src/FTTextureGlyph.cpp
# src/FTVectoriser.cpp
)
SET_SOURCE_FILES_PROPERTIES(

View file

@ -1,76 +0,0 @@
#ifndef __FTBitmapGlyph__
#define __FTBitmapGlyph__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "FTGL.h"
#include "FTGlyph.h"
/**
* FTBitmapGlyph is a specialisation of FTGlyph for creating bitmaps.
*
* It provides the interface between Freetype glyphs and their openGL
* Renderable counterparts. This is an abstract class and derived classes
* must implement the <code>Render</code> function.
*
* @see FTGlyphContainer
*
*/
class FTGL_EXPORT FTBitmapGlyph : public FTGlyph
{
public:
/**
* Constructor
*
* @param glyph The Freetype glyph to be processed
*/
FTBitmapGlyph( FT_GlyphSlot glyph);
/**
* Destructor
*/
virtual ~FTBitmapGlyph();
/**
* Renders this glyph at the current pen position.
*
* @param pen The current pen position.
* @return The advance distance for this glyph.
*/
virtual const FTPoint& Render( const FTPoint& pen);
private:
/**
* The width of the glyph 'image'
*/
unsigned int destWidth;
/**
* The height of the glyph 'image'
*/
unsigned int destHeight;
/**
* The pitch of the glyph 'image'
*/
unsigned int destPitch;
/**
* Vector from the pen position to the topleft corner of the bitmap
*/
FTPoint pos;
/**
* Pointer to the 'image' data
*/
unsigned char* data;
};
#endif // __FTBitmapGlyph__

View file

@ -1,88 +0,0 @@
#ifndef __FTContour__
#define __FTContour__
#include "FTPoint.h"
#include "FTVector.h"
#include "FTGL.h"
/**
* FTContour class is a container of points that describe a vector font
* outline. It is used as a container for the output of the bezier curve
* evaluator in FTVectoriser.
*
* @see FTOutlineGlyph
* @see FTPolyGlyph
* @see FTPoint
*/
class FTGL_EXPORT FTContour
{
public:
/**
* Constructor
*
* @param contour
* @param pointTags
* @param numberOfPoints
*/
FTContour( FT_Vector* contour, char* pointTags, unsigned int numberOfPoints);
/**
* Destructor
*/
~FTContour()
{
pointList.clear();
}
/**
* Return a point at index.
*
* @param index of the point in the curve.
* @return const point reference
*/
const FTPoint& Point( unsigned int index) const { return pointList[index];}
/**
* How many points define this contour
*
* @return the number of points in this contour
*/
size_t PointCount() const { return pointList.size();}
private:
/**
* Add a point to this contour. This function tests for duplicate
* points.
*
* @param point The point to be added to the contour.
*/
inline void AddPoint( FTPoint point);
inline void AddPoint( float x, float y);
/**
* De Casteljau (bezier) algorithm contributed by Jed Soane
* Evaluates a quadratic or conic (second degree) curve
*/
inline void evaluateQuadraticCurve();
/**
* De Casteljau (bezier) algorithm contributed by Jed Soane
* Evaluates a cubic (third degree) curve
*/
inline void evaluateCubicCurve();
/**
* The list of points in this contour
*/
typedef FTVector<FTPoint> PointVector;
PointVector pointList;
/**
* 2D array storing values of de Casteljau algorithm.
*/
float controlPoints[4][2];
};
#endif // __FTContour__

View file

@ -1,69 +0,0 @@
#ifndef __FTExtrdGlyph__
#define __FTExtrdGlyph__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "FTGL.h"
#include "FTGlyph.h"
class FTVectoriser;
/**
* FTExtrdGlyph is a specialisation of FTGlyph for creating tessellated
* extruded polygon glyphs.
*
* @see FTGlyphContainer
* @see FTVectoriser
*
*/
class FTGL_EXPORT FTExtrdGlyph : public FTGlyph
{
public:
/**
* Constructor. Sets the Error to Invalid_Outline if the glyph isn't an outline.
*
* @param glyph The Freetype glyph to be processed
* @param depth The distance along the z axis to extrude the glyph
* @param useDisplayList Enable or disable the use of Display Lists for this glyph
* <code>true</code> turns ON display lists.
* <code>false</code> turns OFF display lists.
*/
FTExtrdGlyph( FT_GlyphSlot glyph, float depth, bool useDisplayList);
/**
* Destructor
*/
virtual ~FTExtrdGlyph();
/**
* Renders this glyph at the current pen position.
*
* @param pen The current pen position.
* @return The advance distance for this glyph.
*/
virtual const FTPoint& Render( const FTPoint& pen);
private:
/**
* Calculate the normal vector to 2 points. This is 2D and ignores
* the z component. The normal will be normalised
*
* @param a
* @param b
* @return
*/
FTPoint GetNormal( const FTPoint &a, const FTPoint &b);
/**
* OpenGL display list
*/
GLuint glList;
};
#endif // __FTExtrdGlyph__

View file

@ -1,65 +0,0 @@
#ifndef __FTGLBitmapFont__
#define __FTGLBitmapFont__
#include "FTFont.h"
#include "FTGL.h"
class FTGlyph;
/**
* FTGLBitmapFont is a specialisation of the FTFont class for handling
* Bitmap fonts
*
* @see FTFont
*/
class FTGL_EXPORT FTGLBitmapFont : public FTFont
{
public:
/**
* Open and read a font file. Sets Error flag.
*
* @param fontFilePath font file path.
*/
FTGLBitmapFont( const char* fontFilePath);
/**
* Open and read a font from a buffer in memory. Sets Error flag.
*
* @param pBufferBytes the in-memory buffer
* @param bufferSizeInBytes the length of the buffer in bytes
*/
FTGLBitmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
/**
* Destructor
*/
~FTGLBitmapFont();
/**
* Renders a string of characters
*
* @param string 'C' style string to be output.
*/
void Render( const char* string);
/**
* Renders a string of characters
*
* @param string 'C' style wide string to be output.
*/
void Render( const wchar_t* string);
// attributes
private:
/**
* Construct a FTBitmapGlyph.
*
* @param g The glyph index NOT the char code.
* @return An FTBitmapGlyph or <code>null</code> on failure.
*/
inline virtual FTGlyph* MakeGlyph( unsigned int g);
};
#endif // __FTGLBitmapFont__

View file

@ -1,63 +0,0 @@
#ifndef __FTGLExtrdFont__
#define __FTGLExtrdFont__
#include "FTFont.h"
#include "FTGL.h"
class FTGlyph;
/**
* FTGLExtrdFont is a specialisation of the FTFont class for handling
* extruded Polygon fonts
*
* @see FTFont
* @see FTGLPolygonFont
*/
class FTGL_EXPORT FTGLExtrdFont : public FTFont
{
public:
/**
* Open and read a font file. Sets Error flag.
*
* @param fontFilePath font file path.
*/
FTGLExtrdFont( const char* fontFilePath);
/**
* Open and read a font from a buffer in memory. Sets Error flag.
*
* @param pBufferBytes the in-memory buffer
* @param bufferSizeInBytes the length of the buffer in bytes
*/
FTGLExtrdFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
/**
* Destructor
*/
~FTGLExtrdFont();
/**
* Set the extrusion distance for the font.
*
* @param d The extrusion distance.
*/
void Depth( float d) { depth = d;}
private:
/**
* Construct a FTPolyGlyph.
*
* @param glyphIndex The glyph index NOT the char code.
* @return An FTExtrdGlyph or <code>null</code> on failure.
*/
inline virtual FTGlyph* MakeGlyph( unsigned int glyphIndex);
/**
* The extrusion distance for the font.
*/
float depth;
};
#endif // __FTGLExtrdFont__

View file

@ -1,64 +0,0 @@
#ifndef __FTGLOutlineFont__
#define __FTGLOutlineFont__
#include "FTFont.h"
#include "FTGL.h"
class FTGlyph;
/**
* FTGLOutlineFont is a specialisation of the FTFont class for handling
* Vector Outline fonts
*
* @see FTFont
*/
class FTGL_EXPORT FTGLOutlineFont : public FTFont
{
public:
/**
* Open and read a font file. Sets Error flag.
*
* @param fontFilePath font file path.
*/
FTGLOutlineFont( const char* fontFilePath);
/**
* Open and read a font from a buffer in memory. Sets Error flag.
*
* @param pBufferBytes the in-memory buffer
* @param bufferSizeInBytes the length of the buffer in bytes
*/
FTGLOutlineFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
/**
* Destructor
*/
~FTGLOutlineFont();
/**
* Renders a string of characters
*
* @param string 'C' style string to be output.
*/
void Render( const char* string);
/**
* Renders a string of characters
*
* @param string wchar_t string to be output.
*/
void Render( const wchar_t* string);
private:
/**
* Construct a FTOutlineGlyph.
*
* @param g The glyph index NOT the char code.
* @return An FTOutlineGlyph or <code>null</code> on failure.
*/
inline virtual FTGlyph* MakeGlyph( unsigned int g);
};
#endif // __FTGLOutlineFont__

View file

@ -1,68 +0,0 @@
#ifndef __FTGLPixmapFont__
#define __FTGLPixmapFont__
#include "FTFont.h"
#include "FTGL.h"
class FTGlyph;
/**
* FTGLPixmapFont is a specialisation of the FTFont class for handling
* Pixmap (Grey Scale) fonts
*
* @see FTFont
*/
class FTGL_EXPORT FTGLPixmapFont : public FTFont
{
public:
/**
* Open and read a font file. Sets Error flag.
*
* @param fontFilePath font file path.
*/
FTGLPixmapFont( const char* fontFilePath);
/**
* Open and read a font from a buffer in memory. Sets Error flag.
*
* @param pBufferBytes the in-memory buffer
* @param bufferSizeInBytes the length of the buffer in bytes
*/
FTGLPixmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
/**
* Destructor
*/
~FTGLPixmapFont();
/**
* Renders a string of characters
*
* @param string 'C' style string to be output.
*/
void Render( const char* string);
/**
* Renders a string of characters
*
* @param string wchar_t string to be output.
*/
void Render( const wchar_t* string);
private:
/**
* Construct a FTPixmapGlyph.
*
* @param g The glyph index NOT the char code.
* @return An FTPixmapGlyph or <code>null</code> on failure.
*/
inline virtual FTGlyph* MakeGlyph( unsigned int g);
};
#endif // __FTGLPixmapFont__

View file

@ -1,53 +0,0 @@
#ifndef __FTGLPolygonFont__
#define __FTGLPolygonFont__
#include "FTFont.h"
#include "FTGL.h"
class FTGlyph;
/**
* FTGLPolygonFont is a specialisation of the FTFont class for handling
* tesselated Polygon Mesh fonts
*
* @see FTFont
*/
class FTGL_EXPORT FTGLPolygonFont : public FTFont
{
public:
/**
* Open and read a font file. Sets Error flag.
*
* @param fontFilePath font file path.
*/
FTGLPolygonFont( const char* fontFilePath);
/**
* Open and read a font from a buffer in memory. Sets Error flag.
*
* @param pBufferBytes the in-memory buffer
* @param bufferSizeInBytes the length of the buffer in bytes
*/
FTGLPolygonFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
/**
* Destructor
*/
~FTGLPolygonFont();
private:
/**
* Construct a FTPolyGlyph.
*
* @param g The glyph index NOT the char code.
* @return An FTPolyGlyph or <code>null</code> on failure.
*/
inline virtual FTGlyph* MakeGlyph( unsigned int g);
};
#endif // __FTGLPolygonFont__

View file

@ -52,7 +52,7 @@ class FTGL_EXPORT FTGlyphContainer
* @return The font index for the character.
*/
unsigned int FontIndex( const unsigned int characterCode ) const;
/**
* Adds a glyph to this glyph list.
*
@ -64,7 +64,7 @@ class FTGL_EXPORT FTGlyphContainer
/**
* Get a glyph from the glyph list
*
* @param characterCode The char code of the glyph NOT the glyph index
* @param characterCode The char code of the glyph NOT the glyph index
* @return An FTGlyph or <code>null</code> is it hasn't been
* loaded.
*/
@ -72,10 +72,10 @@ class FTGL_EXPORT FTGlyphContainer
/**
* Get the bounding box for a character.
* @param characterCode The char code of the glyph NOT the glyph index
* @param characterCode The char code of the glyph NOT the glyph index
*/
FTBBox BBox( const unsigned int characterCode) const;
/**
* Returns the kerned advance width for a glyph.
*
@ -84,7 +84,7 @@ class FTGL_EXPORT FTGlyphContainer
* @return advance width
*/
float Advance( const unsigned int characterCode, const unsigned int nextCharacterCode);
/**
* Renders a character
* @param characterCode the glyph to be Rendered
@ -93,7 +93,7 @@ class FTGL_EXPORT FTGlyphContainer
* @return The distance to advance the pen position after Rendering
*/
FTPoint Render( const unsigned int characterCode, const unsigned int nextCharacterCode, FTPoint penPosition);
/**
* Queries the Font for errors.
*

View file

@ -1,112 +0,0 @@
#ifndef __FTList__
#define __FTList__
#include "FTGL.h"
/**
* Provides a non-STL alternative to the STL list
*/
template <typename FT_LIST_ITEM_TYPE>
class FTGL_EXPORT FTList
{
public:
typedef FT_LIST_ITEM_TYPE value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef size_t size_type;
/**
* Constructor
*/
FTList()
: listSize(0),
tail(0)
{
tail = NULL;
head = new Node;
}
/**
* Destructor
*/
~FTList()
{
Node* next;
for( Node *walk = head; walk; walk = next)
{
next = walk->next;
delete walk;
}
}
/**
* Get the number of items in the list
*/
size_type size() const
{
return listSize;
}
/**
* Add an item to the end of the list
*/
void push_back( const value_type& item)
{
Node* node = new Node( item);
if( head->next == NULL)
{
head->next = node;
}
if( tail)
{
tail->next = node;
}
tail = node;
++listSize;
}
/**
* Get the item at the front of the list
*/
reference front() const
{
return head->next->payload;
}
/**
* Get the item at the end of the list
*/
reference back() const
{
return tail->payload;
}
private:
struct Node
{
Node()
: next(NULL)
{}
Node( const value_type& item)
: next(NULL)
{
payload = item;
}
Node* next;
value_type payload;
};
size_type listSize;
Node* head;
Node* tail;
};
#endif // __FTList__

View file

@ -1,57 +0,0 @@
#ifndef __FTOutlineGlyph__
#define __FTOutlineGlyph__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "FTGL.h"
#include "FTGlyph.h"
class FTVectoriser;
/**
* FTOutlineGlyph is a specialisation of FTGlyph for creating outlines.
*
* @see FTGlyphContainer
* @see FTVectoriser
*
*/
class FTGL_EXPORT FTOutlineGlyph : public FTGlyph
{
public:
/**
* Constructor. Sets the Error to Invalid_Outline if the glyphs isn't an outline.
*
* @param glyph The Freetype glyph to be processed
* @param useDisplayList Enable or disable the use of Display Lists for this glyph
* <code>true</code> turns ON display lists.
* <code>false</code> turns OFF display lists.
*/
FTOutlineGlyph( FT_GlyphSlot glyph, bool useDisplayList);
/**
* Destructor
*/
virtual ~FTOutlineGlyph();
/**
* Renders this glyph at the current pen position.
*
* @param pen The current pen position.
* @return The advance distance for this glyph.
*/
virtual const FTPoint& Render( const FTPoint& pen);
private:
/**
* OpenGL display list
*/
GLuint glList;
};
#endif // __FTOutlineGlyph__

View file

@ -1,68 +0,0 @@
#ifndef __FTPixmapGlyph__
#define __FTPixmapGlyph__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "FTGL.h"
#include "FTGlyph.h"
/**
* FTPixmapGlyph is a specialisation of FTGlyph for creating pixmaps.
*
* @see FTGlyphContainer
*
*/
class FTGL_EXPORT FTPixmapGlyph : public FTGlyph
{
public:
/**
* Constructor
*
* @param glyph The Freetype glyph to be processed
*/
FTPixmapGlyph( FT_GlyphSlot glyph);
/**
* Destructor
*/
virtual ~FTPixmapGlyph();
/**
* Renders this glyph at the current pen position.
*
* @param pen The current pen position.
* @return The advance distance for this glyph.
*/
virtual const FTPoint& Render( const FTPoint& pen);
// attributes
private:
/**
* The width of the glyph 'image'
*/
int destWidth;
/**
* The height of the glyph 'image'
*/
int destHeight;
/**
* Vector from the pen position to the topleft corner of the pixmap
*/
FTPoint pos;
/**
* Pointer to the 'image' data
*/
unsigned char* data;
};
#endif // __FTPixmapGlyph__

View file

@ -1,59 +0,0 @@
#ifndef __FTPolyGlyph__
#define __FTPolyGlyph__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "FTGL.h"
#include "FTGlyph.h"
class FTVectoriser;
/**
* FTPolyGlyph is a specialisation of FTGlyph for creating tessellated
* polygon glyphs.
*
* @see FTGlyphContainer
* @see FTVectoriser
*
*/
class FTGL_EXPORT FTPolyGlyph : public FTGlyph
{
public:
/**
* Constructor. Sets the Error to Invalid_Outline if the glyphs isn't an outline.
*
* @param glyph The Freetype glyph to be processed
* @param glyph The Freetype glyph to be processed
* @param useDisplayList Enable or disable the use of Display Lists for this glyph
* <code>true</code> turns ON display lists.
* <code>false</code> turns OFF display lists.
*/
FTPolyGlyph( FT_GlyphSlot glyph, bool useDisplayList);
/**
* Destructor
*/
virtual ~FTPolyGlyph();
/**
* Renders this glyph at the current pen position.
*
* @param pen The current pen position.
* @return The advance distance for this glyph.
*/
virtual const FTPoint& Render( const FTPoint& pen);
private:
/**
* OpenGL display list
*/
GLuint glList;
};
#endif // __FTPolyGlyph__

View file

@ -1,275 +0,0 @@
#ifndef __FTVectoriser__
#define __FTVectoriser__
#include "FTContour.h"
#include "FTList.h"
#include "FTPoint.h"
#include "FTVector.h"
#include "FTGL.h"
#ifndef CALLBACK
#define CALLBACK
#endif
/**
* FTTesselation captures points that are output by OpenGL's gluTesselator.
*/
class FTGL_EXPORT FTTesselation
{
public:
/**
* Default constructor
*/
FTTesselation( GLenum m)
: meshType(m)
{
pointList.reserve( 128);
}
/**
* Destructor
*/
~FTTesselation()
{
pointList.clear();
}
/**
* Add a point to the mesh.
*/
void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
{
pointList.push_back( FTPoint( x, y, z));
}
/**
* The number of points in this mesh
*/
size_t PointCount() const { return pointList.size();}
/**
*
*/
const FTPoint& Point( unsigned int index) const { return pointList[index];}
/**
* Return the OpenGL polygon type.
*/
GLenum PolygonType() const { return meshType;}
private:
/**
* Points generated by gluTesselator.
*/
typedef FTVector<FTPoint> PointVector;
PointVector pointList;
/**
* OpenGL primitive type from gluTesselator.
*/
GLenum meshType;
};
/**
* FTMesh is a container of FTTesselation's that make up a polygon glyph
*/
class FTGL_EXPORT FTMesh
{
typedef FTVector<FTTesselation*> TesselationVector;
typedef FTList<FTPoint> PointList;
public:
/**
* Default constructor
*/
FTMesh();
/**
* Destructor
*/
~FTMesh();
/**
* Add a point to the mesh
*/
void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
/**
* Create a combine point for the gluTesselator
*/
const FTGL_DOUBLE* Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
/**
* Begin a new polygon
*/
void Begin( GLenum meshType);
/**
* End a polygon
*/
void End();
/**
* Record a gluTesselation error
*/
void Error( GLenum e) { err = e;}
/**
* The number of tesselations in the mesh
*/
unsigned int TesselationCount() const { return tesselationList.size();}
/**
* Get a tesselation by index
*/
const FTTesselation* const Tesselation( unsigned int index) const;
/**
* Return the temporary point list. For testing only.
*/
const PointList& TempPointList() const { return tempPointList;}
/**
* Get the GL ERROR returned by the glu tesselator
*/
GLenum Error() const { return err;}
private:
/**
* The current sub mesh that we are constructing.
*/
FTTesselation* currentTesselation;
/**
* Holds each sub mesh that comprises this glyph.
*/
TesselationVector tesselationList;
/**
* Holds extra points created by gluTesselator. See ftglCombine.
*/
PointList tempPointList;
/**
* GL ERROR returned by the glu tesselator
*/
GLenum err;
};
const FTGL_DOUBLE FTGL_FRONT_FACING = 1.0;
const FTGL_DOUBLE FTGL_BACK_FACING = -1.0;
/**
* FTVectoriser class is a helper class that converts font outlines into
* point data.
*
* @see FTExtrdGlyph
* @see FTOutlineGlyph
* @see FTPolyGlyph
* @see FTContour
* @see FTPoint
*
*/
class FTGL_EXPORT FTVectoriser
{
public:
/**
* Constructor
*
* @param glyph The freetype glyph to be processed
*/
FTVectoriser( const FT_GlyphSlot glyph);
/**
* Destructor
*/
virtual ~FTVectoriser();
/**
* Build an FTMesh from the vector outline data.
*
* @param zNormal The direction of the z axis of the normal
* for this mesh
*/
void MakeMesh( FTGL_DOUBLE zNormal = FTGL_FRONT_FACING);
/**
* Get the current mesh.
*/
const FTMesh* const GetMesh() const { return mesh;}
/**
* Get the total count of points in this outline
*
* @return the number of points
*/
size_t PointCount();
/**
* Get the count of contours in this outline
*
* @return the number of contours
*/
size_t ContourCount() const { return ftContourCount;}
/**
* Return a contour at index
*
* @return the number of contours
*/
const FTContour* const Contour( unsigned int index) const;
/**
* Get the number of points in a specific contour in this outline
*
* @param c The contour index
* @return the number of points in contour[c]
*/
size_t ContourSize( int c) const { return contourList[c]->PointCount();}
/**
* Get the flag for the tesselation rule for this outline
*
* @return The contour flag
*/
int ContourFlag() const { return contourFlag;}
private:
/**
* Process the freetype outline data into contours of points
*/
void ProcessContours();
/**
* The list of contours in the glyph
*/
FTContour** contourList;
/**
* A Mesh for tesselations
*/
FTMesh* mesh;
/**
* The number of contours reported by Freetype
*/
short ftContourCount;
/**
* A flag indicating the tesselation rule for the glyph
*/
int contourFlag;
/**
* A Freetype outline
*/
FT_Outline outline;
};
#endif // __FTVectoriser__

View file

@ -1,148 +0,0 @@
#include "FTContour.h"
static const float BEZIER_STEP_SIZE = 0.2f;
void FTContour::AddPoint( FTPoint point)
{
if( pointList.empty() || point != pointList[pointList.size() - 1])
{
pointList.push_back( point);
}
}
void FTContour::AddPoint( float x, float y)
{
AddPoint( FTPoint( x, y, 0.0f));
}
void FTContour::evaluateQuadraticCurve()
{
for( unsigned int i = 0; i <= ( 1.0f / BEZIER_STEP_SIZE); i++)
{
float bezierValues[2][2];
float t = static_cast<float>(i) * BEZIER_STEP_SIZE;
bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0];
bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1];
bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0];
bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1];
bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0];
bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1];
AddPoint( bezierValues[0][0], bezierValues[0][1]);
}
}
void FTContour::evaluateCubicCurve()
{
for( unsigned int i = 0; i <= ( 1.0f / BEZIER_STEP_SIZE); i++)
{
float bezierValues[3][2];
float t = static_cast<float>(i) * BEZIER_STEP_SIZE;
bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0];
bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1];
bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0];
bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1];
bezierValues[2][0] = (1.0f - t) * controlPoints[2][0] + t * controlPoints[3][0];
bezierValues[2][1] = (1.0f - t) * controlPoints[2][1] + t * controlPoints[3][1];
bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0];
bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1];
bezierValues[1][0] = (1.0f - t) * bezierValues[1][0] + t * bezierValues[2][0];
bezierValues[1][1] = (1.0f - t) * bezierValues[1][1] + t * bezierValues[2][1];
bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0];
bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1];
AddPoint( bezierValues[0][0], bezierValues[0][1]);
}
}
FTContour::FTContour( FT_Vector* contour, char* pointTags, unsigned int numberOfPoints)
{
for( unsigned int pointIndex = 0; pointIndex < numberOfPoints; ++ pointIndex)
{
char pointTag = pointTags[pointIndex];
if( pointTag == FT_Curve_Tag_On || numberOfPoints < 2)
{
AddPoint( contour[pointIndex].x, contour[pointIndex].y);
continue;
}
FTPoint controlPoint( contour[pointIndex]);
FTPoint previousPoint = ( 0 == pointIndex)
? FTPoint( contour[numberOfPoints - 1])
: pointList[pointList.size() - 1];
FTPoint nextPoint = ( pointIndex == numberOfPoints - 1)
? pointList[0]
: FTPoint( contour[pointIndex + 1]);
if( pointTag == FT_Curve_Tag_Conic)
{
char nextPointTag = ( pointIndex == numberOfPoints - 1)
? pointTags[0]
: pointTags[pointIndex + 1];
while( nextPointTag == FT_Curve_Tag_Conic)
{
nextPoint = ( controlPoint + nextPoint) * 0.5f;
controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
controlPoints[1][0] = controlPoint.X(); controlPoints[1][1] = controlPoint.Y();
controlPoints[2][0] = nextPoint.X(); controlPoints[2][1] = nextPoint.Y();
evaluateQuadraticCurve();
++pointIndex;
previousPoint = nextPoint;
controlPoint = FTPoint( contour[pointIndex]);
nextPoint = ( pointIndex == numberOfPoints - 1)
? pointList[0]
: FTPoint( contour[pointIndex + 1]);
nextPointTag = ( pointIndex == numberOfPoints - 1)
? pointTags[0]
: pointTags[pointIndex + 1];
}
controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
controlPoints[1][0] = controlPoint.X(); controlPoints[1][1] = controlPoint.Y();
controlPoints[2][0] = nextPoint.X(); controlPoints[2][1] = nextPoint.Y();
evaluateQuadraticCurve();
continue;
}
if( pointTag == FT_Curve_Tag_Cubic)
{
FTPoint controlPoint2 = nextPoint;
FTPoint nextPoint = ( pointIndex == numberOfPoints - 2)
? pointList[0]
: FTPoint( contour[pointIndex + 2]);
controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
controlPoints[1][0] = controlPoint.X(); controlPoints[1][1] = controlPoint.Y();
controlPoints[2][0] = controlPoint2.X(); controlPoints[2][1] = controlPoint2.Y();
controlPoints[3][0] = nextPoint.X(); controlPoints[3][1] = nextPoint.Y();
evaluateCubicCurve();
++pointIndex;
continue;
}
}
}

View file

@ -1,174 +0,0 @@
#include <iostream>
#include <math.h>
#include "FTExtrdGlyph.h"
#include "FTVectoriser.h"
FTExtrdGlyph::FTExtrdGlyph( FT_GlyphSlot glyph, float depth, bool useDisplayList)
: FTGlyph( glyph),
glList(0)
{
bBox.SetDepth( -depth);
if( ft_glyph_format_outline != glyph->format)
{
err = 0x14; // Invalid_Outline
return;
}
FTVectoriser vectoriser( glyph);
if( ( vectoriser.ContourCount() < 1) || ( vectoriser.PointCount() < 3))
{
return;
}
unsigned int tesselationIndex;
if(useDisplayList)
{
glList = glGenLists(1);
glNewList( glList, GL_COMPILE);
}
vectoriser.MakeMesh( 1.0);
glNormal3d(0.0, 0.0, 1.0);
unsigned int horizontalTextureScale = glyph->face->size->metrics.x_ppem * 64;
unsigned int verticalTextureScale = glyph->face->size->metrics.y_ppem * 64;
const FTMesh* mesh = vectoriser.GetMesh();
for( tesselationIndex = 0; tesselationIndex < mesh->TesselationCount(); ++tesselationIndex)
{
const FTTesselation* subMesh = mesh->Tesselation( tesselationIndex);
unsigned int polyonType = subMesh->PolygonType();
glBegin( polyonType);
for( unsigned int pointIndex = 0; pointIndex < subMesh->PointCount(); ++pointIndex)
{
FTPoint point = subMesh->Point(pointIndex);
glTexCoord2f( point.X() / horizontalTextureScale,
point.Y() / verticalTextureScale);
glVertex3f( point.X() / 64.0f,
point.Y() / 64.0f,
0.0f);
}
glEnd();
}
vectoriser.MakeMesh( -1.0);
glNormal3d(0.0, 0.0, -1.0);
mesh = vectoriser.GetMesh();
for( tesselationIndex = 0; tesselationIndex < mesh->TesselationCount(); ++tesselationIndex)
{
const FTTesselation* subMesh = mesh->Tesselation( tesselationIndex);
unsigned int polyonType = subMesh->PolygonType();
glBegin( polyonType);
for( unsigned int pointIndex = 0; pointIndex < subMesh->PointCount(); ++pointIndex)
{
FTPoint point = subMesh->Point(pointIndex);
glTexCoord2f( subMesh->Point(pointIndex).X() / horizontalTextureScale,
subMesh->Point(pointIndex).Y() / verticalTextureScale);
glVertex3f( subMesh->Point( pointIndex).X() / 64.0f,
subMesh->Point( pointIndex).Y() / 64.0f,
-depth);
}
glEnd();
}
int contourFlag = vectoriser.ContourFlag();
for( size_t c = 0; c < vectoriser.ContourCount(); ++c)
{
const FTContour* contour = vectoriser.Contour(c);
unsigned int numberOfPoints = contour->PointCount();
glBegin( GL_QUAD_STRIP);
for( unsigned int j = 0; j <= numberOfPoints; ++j)
{
unsigned int pointIndex = ( j == numberOfPoints) ? 0 : j;
unsigned int nextPointIndex = ( pointIndex == numberOfPoints - 1) ? 0 : pointIndex + 1;
FTPoint point = contour->Point(pointIndex);
FTPoint normal = GetNormal( point, contour->Point(nextPointIndex));
if(normal != FTPoint( 0.0f, 0.0f, 0.0f))
{
glNormal3dv(static_cast<const FTGL_DOUBLE*>(normal));
}
if( contourFlag & ft_outline_reverse_fill)
{
glTexCoord2f( point.X() / horizontalTextureScale,
point.X() / verticalTextureScale);
glVertex3f( point.X() / 64.0f, point.Y() / 64.0f, 0.0f);
glVertex3f( point.X() / 64.0f, point.Y() / 64.0f, -depth);
}
else
{
glTexCoord2f( point.X() / horizontalTextureScale,
point.Y() / verticalTextureScale);
glVertex3f( point.X() / 64.0f, point.Y() / 64.0f, -depth);
glVertex3f( point.X() / 64.0f, point.Y() / 64.0f, 0.0f);
}
}
glEnd();
}
if(useDisplayList)
{
glEndList();
}
}
FTExtrdGlyph::~FTExtrdGlyph()
{
glDeleteLists( glList, 1);
}
const FTPoint& FTExtrdGlyph::Render( const FTPoint& pen)
{
glTranslatef( pen.X(), pen.Y(), 0);
if( glList)
{
glCallList( glList);
}
return advance;
}
FTPoint FTExtrdGlyph::GetNormal( const FTPoint &a, const FTPoint &b)
{
float vectorX = a.X() - b.X();
float vectorY = a.Y() - b.Y();
float length = sqrt( vectorX * vectorX + vectorY * vectorY );
if( length > 0.01f)
{
length = 1 / length;
}
else
{
length = 0.0f;
}
return FTPoint( -vectorY * length,
vectorX * length,
0.0f);
}

View file

@ -1,67 +0,0 @@
#include "FTGLBitmapFont.h"
#include "FTBitmapGlyph.h"
FTGLBitmapFont::FTGLBitmapFont( const char* fontFilePath)
: FTFont( fontFilePath)
{}
FTGLBitmapFont::FTGLBitmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
: FTFont( pBufferBytes, bufferSizeInBytes)
{}
FTGLBitmapFont::~FTGLBitmapFont()
{}
FTGlyph* FTGLBitmapFont::MakeGlyph( unsigned int g)
{
FT_GlyphSlot ftGlyph = face.Glyph( g, FT_LOAD_DEFAULT);
if( ftGlyph)
{
FTBitmapGlyph* tempGlyph = new FTBitmapGlyph( ftGlyph);
return tempGlyph;
}
err = face.Error();
return NULL;
}
void FTGLBitmapFont::Render( const char* string)
{
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
glPushAttrib( GL_ENABLE_BIT);
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
glDisable( GL_BLEND);
FTFont::Render( string);
glPopAttrib();
glPopClientAttrib();
}
void FTGLBitmapFont::Render( const wchar_t* string)
{
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
glPushAttrib( GL_ENABLE_BIT);
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
glDisable( GL_BLEND);
FTFont::Render( string);
glPopAttrib();
glPopClientAttrib();
}

View file

@ -1,36 +0,0 @@
#include "FTGLExtrdFont.h"
#include "FTExtrdGlyph.h"
FTGLExtrdFont::FTGLExtrdFont( const char* fontFilePath)
: FTFont( fontFilePath),
depth( 0.0f)
{}
FTGLExtrdFont::FTGLExtrdFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
: FTFont( pBufferBytes, bufferSizeInBytes),
depth( 0.0f)
{}
FTGLExtrdFont::~FTGLExtrdFont()
{}
FTGlyph* FTGLExtrdFont::MakeGlyph( unsigned int glyphIndex)
{
FT_GlyphSlot ftGlyph = face.Glyph( glyphIndex, FT_LOAD_NO_HINTING);
if( ftGlyph)
{
FTExtrdGlyph* tempGlyph = new FTExtrdGlyph( ftGlyph, depth, useDisplayLists);
return tempGlyph;
}
err = face.Error();
return NULL;
}

View file

@ -1,67 +0,0 @@
#include "FTGLOutlineFont.h"
#include "FTOutlineGlyph.h"
FTGLOutlineFont::FTGLOutlineFont( const char* fontFilePath)
: FTFont( fontFilePath)
{}
FTGLOutlineFont::FTGLOutlineFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
: FTFont( pBufferBytes, bufferSizeInBytes)
{}
FTGLOutlineFont::~FTGLOutlineFont()
{}
FTGlyph* FTGLOutlineFont::MakeGlyph( unsigned int g)
{
FT_GlyphSlot ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING);
if( ftGlyph)
{
FTOutlineGlyph* tempGlyph = new FTOutlineGlyph( ftGlyph, useDisplayLists);
return tempGlyph;
}
err = face.Error();
return NULL;
}
void FTGLOutlineFont::Render( const char* string)
{
glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT);
glDisable( GL_TEXTURE_2D);
glEnable( GL_LINE_SMOOTH);
glHint( GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
FTFont::Render( string);
glPopAttrib();
}
void FTGLOutlineFont::Render( const wchar_t* string)
{
glPushAttrib( GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT);
glDisable( GL_TEXTURE_2D);
glEnable( GL_LINE_SMOOTH);
glHint( GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
FTFont::Render( string);
glPopAttrib();
}

View file

@ -1,84 +0,0 @@
#include "FTGLPixmapFont.h"
#include "FTPixmapGlyph.h"
FTGLPixmapFont::FTGLPixmapFont( const char* fontFilePath)
: FTFont( fontFilePath)
{}
FTGLPixmapFont::FTGLPixmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
: FTFont( pBufferBytes, bufferSizeInBytes)
{}
FTGLPixmapFont::~FTGLPixmapFont()
{}
FTGlyph* FTGLPixmapFont::MakeGlyph( unsigned int g)
{
FT_GlyphSlot ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING);
if( ftGlyph)
{
FTPixmapGlyph* tempGlyph = new FTPixmapGlyph( ftGlyph);
return tempGlyph;
}
err = face.Error();
return NULL;
}
void FTGLPixmapFont::Render( const char* string)
{
glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable( GL_TEXTURE_2D);
GLfloat ftglColour[4];
glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour);
glPixelTransferf(GL_RED_SCALE, ftglColour[0]);
glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]);
glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]);
glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]);
FTFont::Render( string);
glPopClientAttrib();
glPopAttrib();
}
void FTGLPixmapFont::Render( const wchar_t* string)
{
glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable( GL_TEXTURE_2D);
GLfloat ftglColour[4];
glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour);
glPixelTransferf(GL_RED_SCALE, ftglColour[0]);
glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]);
glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]);
glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]);
FTFont::Render( string);
glPopClientAttrib();
glPopAttrib();
}

View file

@ -1,34 +0,0 @@
#include "FTGLPolygonFont.h"
#include "FTPolyGlyph.h"
FTGLPolygonFont::FTGLPolygonFont( const char* fontFilePath)
: FTFont( fontFilePath)
{}
FTGLPolygonFont::FTGLPolygonFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
: FTFont( pBufferBytes, bufferSizeInBytes)
{}
FTGLPolygonFont::~FTGLPolygonFont()
{}
FTGlyph* FTGLPolygonFont::MakeGlyph( unsigned int g)
{
FT_GlyphSlot ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING);
if( ftGlyph)
{
FTPolyGlyph* tempGlyph = new FTPolyGlyph( ftGlyph, useDisplayLists);
return tempGlyph;
}
err = face.Error();
return NULL;
}

View file

@ -1,67 +0,0 @@
#include "FTOutlineGlyph.h"
#include "FTVectoriser.h"
FTOutlineGlyph::FTOutlineGlyph( FT_GlyphSlot glyph, bool useDisplayList)
: FTGlyph( glyph),
glList(0)
{
if( ft_glyph_format_outline != glyph->format)
{
err = 0x14; // Invalid_Outline
return;
}
FTVectoriser vectoriser( glyph);
size_t numContours = vectoriser.ContourCount();
if ( ( numContours < 1) || ( vectoriser.PointCount() < 3))
{
return;
}
if(useDisplayList)
{
glList = glGenLists(1);
glNewList( glList, GL_COMPILE);
}
for( unsigned int c = 0; c < numContours; ++c)
{
const FTContour* contour = vectoriser.Contour(c);
glBegin( GL_LINE_LOOP);
for( unsigned int pointIndex = 0; pointIndex < contour->PointCount(); ++pointIndex)
{
FTPoint point = contour->Point(pointIndex);
glVertex2f( point.X() / 64.0f, point.Y() / 64.0f);
}
glEnd();
}
if(useDisplayList)
{
glEndList();
}
}
FTOutlineGlyph::~FTOutlineGlyph()
{
glDeleteLists( glList, 1);
}
const FTPoint& FTOutlineGlyph::Render( const FTPoint& pen)
{
glTranslatef( pen.X(), pen.Y(), 0.0f);
if( glList)
{
glCallList( glList);
}
return advance;
}

View file

@ -1,74 +0,0 @@
#include "FTPixmapGlyph.h"
FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph)
: FTGlyph( glyph),
destWidth(0),
destHeight(0),
data(0)
{
err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
if( err || ft_glyph_format_bitmap != glyph->format)
{
return;
}
FT_Bitmap bitmap = glyph->bitmap;
//check the pixel mode
//ft_pixel_mode_grays
int srcWidth = bitmap.width;
int srcHeight = bitmap.rows;
destWidth = srcWidth;
destHeight = srcHeight;
if( destWidth && destHeight)
{
data = new unsigned char[destWidth * destHeight * 2];
unsigned char* src = bitmap.buffer;
unsigned char* dest = data + ((destHeight - 1) * destWidth * 2);
size_t destStep = destWidth * 2 * 2;
for( int y = 0; y < srcHeight; ++y)
{
for( int x = 0; x < srcWidth; ++x)
{
*dest++ = static_cast<unsigned char>(255);
*dest++ = *src++;
}
dest -= destStep;
}
destHeight = srcHeight;
}
pos.X(glyph->bitmap_left);
pos.Y(srcHeight - glyph->bitmap_top);
}
FTPixmapGlyph::~FTPixmapGlyph()
{
delete [] data;
}
const FTPoint& FTPixmapGlyph::Render( const FTPoint& pen)
{
glBitmap( 0, 0, 0.0f, 0.0f, pen.X() + pos.X(), pen.Y() - pos.Y(), (const GLubyte*)0);
if( data)
{
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 2);
glDrawPixels( destWidth, destHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (const GLvoid*)data);
}
glBitmap( 0, 0, 0.0f, 0.0f, -pos.X(), pos.Y(), (const GLubyte*)0);
return advance;
}

View file

@ -1,78 +0,0 @@
#include "FTPolyGlyph.h"
#include "FTVectoriser.h"
FTPolyGlyph::FTPolyGlyph( FT_GlyphSlot glyph, bool useDisplayList)
: FTGlyph( glyph),
glList(0)
{
if( ft_glyph_format_outline != glyph->format)
{
err = 0x14; // Invalid_Outline
return;
}
FTVectoriser vectoriser( glyph);
if(( vectoriser.ContourCount() < 1) || ( vectoriser.PointCount() < 3))
{
return;
}
unsigned int horizontalTextureScale = glyph->face->size->metrics.x_ppem * 64;
unsigned int verticalTextureScale = glyph->face->size->metrics.y_ppem * 64;
vectoriser.MakeMesh( 1.0);
if( useDisplayList)
{
glList = glGenLists( 1);
glNewList( glList, GL_COMPILE);
}
const FTMesh* mesh = vectoriser.GetMesh();
for( unsigned int index = 0; index < mesh->TesselationCount(); ++index)
{
const FTTesselation* subMesh = mesh->Tesselation( index);
unsigned int polyonType = subMesh->PolygonType();
glBegin( polyonType);
for( unsigned int pointIndex = 0; pointIndex < subMesh->PointCount(); ++pointIndex)
{
FTPoint point = subMesh->Point(pointIndex);
glTexCoord2f( point.X() / horizontalTextureScale,
point.Y() / verticalTextureScale);
glVertex3f( point.X() / 64.0f,
point.Y() / 64.0f,
0.0f);
}
glEnd();
}
if(useDisplayList)
{
glEndList();
}
}
FTPolyGlyph::~FTPolyGlyph()
{
glDeleteLists( glList, 1);
}
const FTPoint& FTPolyGlyph::Render( const FTPoint& pen)
{
glTranslatef( pen.X(), pen.Y(), 0.0f);
if( glList)
{
glCallList( glList);
}
return advance;
}

View file

@ -1,228 +0,0 @@
#include "FTVectoriser.h"
#include "FTGL.h"
#ifndef CALLBACK
#define CALLBACK
#endif
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
typedef void (*GLUTesselatorFunction)();
#elif defined(__APPLE_CC__)
typedef void (*GLUTesselatorFunction)();
#elif defined( __mips ) || defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __sun ) || defined (__CYGWIN__)
typedef GLvoid (*GLUTesselatorFunction)();
#elif defined ( WIN32)
typedef GLvoid (CALLBACK *GLUTesselatorFunction)( );
#else
#error "Error - need to define type GLUTesselatorFunction for this platform/compiler"
#endif
void CALLBACK ftglError( GLenum errCode, FTMesh* mesh)
{
mesh->Error( errCode);
}
void CALLBACK ftglVertex( void* data, FTMesh* mesh)
{
FTGL_DOUBLE* vertex = static_cast<FTGL_DOUBLE*>(data);
mesh->AddPoint( vertex[0], vertex[1], vertex[2]);
}
void CALLBACK ftglCombine( FTGL_DOUBLE coords[3], void* vertex_data[4], GLfloat weight[4], void** outData, FTMesh* mesh)
{
const FTGL_DOUBLE* vertex = static_cast<const FTGL_DOUBLE*>(coords);
*outData = const_cast<FTGL_DOUBLE*>(mesh->Combine( vertex[0], vertex[1], vertex[2]));
}
void CALLBACK ftglBegin( GLenum type, FTMesh* mesh)
{
mesh->Begin( type);
}
void CALLBACK ftglEnd( FTMesh* mesh)
{
mesh->End();
}
FTMesh::FTMesh()
: currentTesselation(0),
err(0)
{
tesselationList.reserve( 16);
}
FTMesh::~FTMesh()
{
for( size_t t = 0; t < tesselationList.size(); ++t)
{
delete tesselationList[t];
}
tesselationList.clear();
}
void FTMesh::AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
{
currentTesselation->AddPoint( x, y, z);
}
const FTGL_DOUBLE* FTMesh::Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
{
tempPointList.push_back( FTPoint( x, y,z));
return static_cast<const FTGL_DOUBLE*>(tempPointList.back());
}
void FTMesh::Begin( GLenum meshType)
{
currentTesselation = new FTTesselation( meshType);
}
void FTMesh::End()
{
tesselationList.push_back( currentTesselation);
}
const FTTesselation* const FTMesh::Tesselation( unsigned int index) const
{
return ( index < tesselationList.size()) ? tesselationList[index] : NULL;
}
FTVectoriser::FTVectoriser( const FT_GlyphSlot glyph)
: contourList(0),
mesh(0),
ftContourCount(0),
contourFlag(0)
{
if( glyph)
{
outline = glyph->outline;
ftContourCount = outline.n_contours;
contourList = 0;
contourFlag = outline.flags;
ProcessContours();
}
}
FTVectoriser::~FTVectoriser()
{
for( size_t c = 0; c < ContourCount(); ++c)
{
delete contourList[c];
}
delete [] contourList;
delete mesh;
}
void FTVectoriser::ProcessContours()
{
short contourLength = 0;
short startIndex = 0;
short endIndex = 0;
contourList = new FTContour*[ftContourCount];
for( short contourIndex = 0; contourIndex < ftContourCount; ++contourIndex)
{
FT_Vector* pointList = &outline.points[startIndex];
char* tagList = &outline.tags[startIndex];
endIndex = outline.contours[contourIndex];
contourLength = ( endIndex - startIndex) + 1;
FTContour* contour = new FTContour( pointList, tagList, contourLength);
contourList[contourIndex] = contour;
startIndex = endIndex + 1;
}
}
size_t FTVectoriser::PointCount()
{
size_t s = 0;
for( size_t c = 0; c < ContourCount(); ++c)
{
s += contourList[c]->PointCount();
}
return s;
}
const FTContour* const FTVectoriser::Contour( unsigned int index) const
{
return ( index < ContourCount()) ? contourList[index] : NULL;
}
void FTVectoriser::MakeMesh( FTGL_DOUBLE zNormal)
{
if( mesh)
{
delete mesh;
}
mesh = new FTMesh;
GLUtesselator* tobj = gluNewTess();
gluTessCallback( tobj, GLU_TESS_BEGIN_DATA, (GLUTesselatorFunction)ftglBegin);
gluTessCallback( tobj, GLU_TESS_VERTEX_DATA, (GLUTesselatorFunction)ftglVertex);
gluTessCallback( tobj, GLU_TESS_COMBINE_DATA, (GLUTesselatorFunction)ftglCombine);
gluTessCallback( tobj, GLU_TESS_END_DATA, (GLUTesselatorFunction)ftglEnd);
gluTessCallback( tobj, GLU_TESS_ERROR_DATA, (GLUTesselatorFunction)ftglError);
if( contourFlag & ft_outline_even_odd_fill) // ft_outline_reverse_fill
{
gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
}
else
{
gluTessProperty( tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
}
gluTessProperty( tobj, GLU_TESS_TOLERANCE, 0);
gluTessNormal( tobj, 0.0f, 0.0f, zNormal);
gluTessBeginPolygon( tobj, mesh);
for( size_t c = 0; c < ContourCount(); ++c)
{
const FTContour* contour = contourList[c];
gluTessBeginContour( tobj);
for( size_t p = 0; p < contour->PointCount(); ++p)
{
const FTGL_DOUBLE* d = contour->Point(p);
gluTessVertex( tobj, (GLdouble*)d, (GLdouble*)d);
}
gluTessEndContour( tobj);
}
gluTessEndPolygon( tobj);
gluDeleteTess( tobj);
}