summaryrefslogtreecommitdiff
path: root/src/ftgl
diff options
context:
space:
mode:
authorscuri <scuri>2010-06-21 22:55:10 +0000
committerscuri <scuri>2010-06-21 22:55:10 +0000
commit37a92b86d13e89d0dcec92be6d23ceced29dbc36 (patch)
treefaff61ef668379212b4ed948934533c3f2fe308b /src/ftgl
parenta124216ee05a5d63ea8fcdafcd050ad1fadf0b09 (diff)
*** empty log message ***
Diffstat (limited to 'src/ftgl')
-rw-r--r--src/ftgl/FTBuffer.cpp69
-rw-r--r--src/ftgl/FTCharToGlyphIndexMap.h155
-rw-r--r--src/ftgl/FTCharmap.cpp106
-rw-r--r--src/ftgl/FTCharmap.h165
-rw-r--r--src/ftgl/FTContour.cpp245
-rw-r--r--src/ftgl/FTContour.h209
-rw-r--r--src/ftgl/FTFace.cpp232
-rw-r--r--src/ftgl/FTFace.h181
-rw-r--r--src/ftgl/FTFont/FTBitmapFont.cpp106
-rw-r--r--src/ftgl/FTFont/FTBitmapFontImpl.h62
-rw-r--r--src/ftgl/FTFont/FTBufferFont.cpp349
-rw-r--r--src/ftgl/FTFont/FTBufferFontImpl.h81
-rw-r--r--src/ftgl/FTFont/FTExtrudeFont.cpp89
-rw-r--r--src/ftgl/FTFont/FTExtrudeFontImpl.h81
-rw-r--r--src/ftgl/FTFont/FTFont.cpp552
-rw-r--r--src/ftgl/FTFont/FTFontGlue.cpp227
-rw-r--r--src/ftgl/FTFont/FTFontImpl.h162
-rw-r--r--src/ftgl/FTFont/FTOutlineFont.cpp129
-rw-r--r--src/ftgl/FTFont/FTOutlineFontImpl.h73
-rw-r--r--src/ftgl/FTFont/FTPixmapFont.cpp131
-rw-r--r--src/ftgl/FTFont/FTPixmapFontImpl.h60
-rw-r--r--src/ftgl/FTFont/FTPolygonFont.cpp89
-rw-r--r--src/ftgl/FTFont/FTPolygonFontImpl.h60
-rw-r--r--src/ftgl/FTFont/FTTextureFont.cpp267
-rw-r--r--src/ftgl/FTFont/FTTextureFontImpl.h152
-rw-r--r--src/ftgl/FTGL/FTBBox.h180
-rw-r--r--src/ftgl/FTGL/FTBitmapGlyph.h82
-rw-r--r--src/ftgl/FTGL/FTBuffer.h127
-rw-r--r--src/ftgl/FTGL/FTBufferFont.h99
-rw-r--r--src/ftgl/FTGL/FTBufferGlyph.h69
-rw-r--r--src/ftgl/FTGL/FTExtrdGlyph.h104
-rw-r--r--src/ftgl/FTGL/FTFont.h584
-rw-r--r--src/ftgl/FTGL/FTGLBitmapFont.h103
-rw-r--r--src/ftgl/FTGL/FTGLExtrdFont.h105
-rw-r--r--src/ftgl/FTGL/FTGLOutlineFont.h103
-rw-r--r--src/ftgl/FTGL/FTGLPixmapFont.h103
-rw-r--r--src/ftgl/FTGL/FTGLPolygonFont.h104
-rw-r--r--src/ftgl/FTGL/FTGLTextureFont.h103
-rw-r--r--src/ftgl/FTGL/FTGlyph.h201
-rw-r--r--src/ftgl/FTGL/FTLayout.h192
-rw-r--r--src/ftgl/FTGL/FTOutlineGlyph.h94
-rw-r--r--src/ftgl/FTGL/FTPixmapGlyph.h82
-rw-r--r--src/ftgl/FTGL/FTPoint.h274
-rw-r--r--src/ftgl/FTGL/FTPolyGlyph.h98
-rw-r--r--src/ftgl/FTGL/FTSimpleLayout.h191
-rw-r--r--src/ftgl/FTGL/FTTextureGlyph.h99
-rw-r--r--src/ftgl/FTGL/ftgl.h135
-rw-r--r--src/ftgl/FTGlyph/FTBitmapGlyph.cpp128
-rw-r--r--src/ftgl/FTGlyph/FTBitmapGlyphImpl.h71
-rw-r--r--src/ftgl/FTGlyph/FTBufferGlyph.cpp121
-rw-r--r--src/ftgl/FTGlyph/FTBufferGlyphImpl.h52
-rw-r--r--src/ftgl/FTGlyph/FTExtrudeGlyph.cpp265
-rw-r--r--src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h69
-rw-r--r--src/ftgl/FTGlyph/FTGlyph.cpp112
-rw-r--r--src/ftgl/FTGlyph/FTGlyphGlue.cpp198
-rw-r--r--src/ftgl/FTGlyph/FTGlyphImpl.h64
-rw-r--r--src/ftgl/FTGlyph/FTOutlineGlyph.cpp149
-rw-r--r--src/ftgl/FTGlyph/FTOutlineGlyphImpl.h69
-rw-r--r--src/ftgl/FTGlyph/FTPixmapGlyph.cpp139
-rw-r--r--src/ftgl/FTGlyph/FTPixmapGlyphImpl.h67
-rw-r--r--src/ftgl/FTGlyph/FTPolygonGlyph.cpp156
-rw-r--r--src/ftgl/FTGlyph/FTPolygonGlyphImpl.h66
-rw-r--r--src/ftgl/FTGlyph/FTTextureGlyph.cpp153
-rw-r--r--src/ftgl/FTGlyph/FTTextureGlyphImpl.h88
-rw-r--r--src/ftgl/FTGlyphContainer.cpp119
-rw-r--r--src/ftgl/FTGlyphContainer.h155
-rw-r--r--src/ftgl/FTInternals.h145
-rw-r--r--src/ftgl/FTLayout/FTLayout.cpp80
-rw-r--r--src/ftgl/FTLayout/FTLayoutGlue.cpp171
-rw-r--r--src/ftgl/FTLayout/FTLayoutImpl.h56
-rw-r--r--src/ftgl/FTLayout/FTSimpleLayout.cpp460
-rw-r--r--src/ftgl/FTLayout/FTSimpleLayoutImpl.h225
-rw-r--r--src/ftgl/FTLibrary.cpp91
-rw-r--r--src/ftgl/FTLibrary.h122
-rw-r--r--src/ftgl/FTList.h137
-rw-r--r--src/ftgl/FTPoint.cpp58
-rw-r--r--src/ftgl/FTSize.cpp123
-rw-r--r--src/ftgl/FTSize.h164
-rw-r--r--src/ftgl/FTUnicode.h237
-rw-r--r--src/ftgl/FTVector.h215
-rw-r--r--src/ftgl/FTVectoriser.cpp328
-rw-r--r--src/ftgl/FTVectoriser.h313
-rw-r--r--src/ftgl/config.h10
83 files changed, 12440 insertions, 0 deletions
diff --git a/src/ftgl/FTBuffer.cpp b/src/ftgl/FTBuffer.cpp
new file mode 100644
index 0000000..3815bb1
--- /dev/null
+++ b/src/ftgl/FTBuffer.cpp
@@ -0,0 +1,69 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+
+FTBuffer::FTBuffer()
+ : width(0),
+ height(0),
+ pixels(0),
+ pos(FTPoint())
+{
+}
+
+
+FTBuffer::~FTBuffer()
+{
+ if(pixels)
+ {
+ delete[] pixels;
+ }
+}
+
+
+void FTBuffer::Size(int w, int h)
+{
+ if(w == width && h == height)
+ {
+ return;
+ }
+
+ if(w * h != width * height)
+ {
+ if(pixels)
+ {
+ delete[] pixels;
+ }
+ pixels = new unsigned char[w * h];
+ }
+
+ memset(pixels, 0, w * h);
+ width = w;
+ height = h;
+}
+
diff --git a/src/ftgl/FTCharToGlyphIndexMap.h b/src/ftgl/FTCharToGlyphIndexMap.h
new file mode 100644
index 0000000..3aa10a1
--- /dev/null
+++ b/src/ftgl/FTCharToGlyphIndexMap.h
@@ -0,0 +1,155 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTCharToGlyphIndexMap__
+#define __FTCharToGlyphIndexMap__
+
+#include <stdlib.h>
+
+#include "FTGL/ftgl.h"
+
+/**
+ * Provides a non-STL alternative to the STL map<unsigned long, unsigned long>
+ * which maps character codes to glyph indices inside FTCharmap.
+ *
+ * Implementation:
+ * - NumberOfBuckets buckets are considered.
+ * - Each bucket has BucketSize entries.
+ * - When the glyph index for the character code C has to be stored, the
+ * bucket this character belongs to is found using 'C div BucketSize'.
+ * If this bucket has not been allocated yet, do it now.
+ * The entry in the bucked is found using 'C mod BucketSize'.
+ * If it is set to IndexNotFound, then the glyph entry has not been set.
+ * - Try to mimic the calls made to the STL map API.
+ *
+ * Caveats:
+ * - The glyph index is now a signed long instead of unsigned long, so
+ * the special value IndexNotFound (= -1) can be used to specify that the
+ * glyph index has not been stored yet.
+ */
+class FTCharToGlyphIndexMap
+{
+ public:
+
+ typedef unsigned long CharacterCode;
+ typedef signed long GlyphIndex;
+
+ enum
+ {
+ NumberOfBuckets = 256,
+ BucketSize = 256,
+ IndexNotFound = -1
+ };
+
+ FTCharToGlyphIndexMap()
+ {
+ this->Indices = 0;
+ }
+
+ virtual ~FTCharToGlyphIndexMap()
+ {
+ if(this->Indices)
+ {
+ // Free all buckets
+ this->clear();
+
+ // Free main structure
+ delete [] this->Indices;
+ this->Indices = 0;
+ }
+ }
+
+ void clear()
+ {
+ if(this->Indices)
+ {
+ for(int i = 0; i < FTCharToGlyphIndexMap::NumberOfBuckets; i++)
+ {
+ if(this->Indices[i])
+ {
+ delete [] this->Indices[i];
+ this->Indices[i] = 0;
+ }
+ }
+ }
+ }
+
+ const GlyphIndex find(CharacterCode c)
+ {
+ if(!this->Indices)
+ {
+ return 0;
+ }
+
+ // Find position of char code in buckets
+ div_t pos = div(c, FTCharToGlyphIndexMap::BucketSize);
+
+ if(!this->Indices[pos.quot])
+ {
+ return 0;
+ }
+
+ const FTCharToGlyphIndexMap::GlyphIndex *ptr = &this->Indices[pos.quot][pos.rem];
+ if(*ptr == FTCharToGlyphIndexMap::IndexNotFound)
+ {
+ return 0;
+ }
+
+ return *ptr;
+ }
+
+ void insert(CharacterCode c, GlyphIndex g)
+ {
+ if(!this->Indices)
+ {
+ this->Indices = new GlyphIndex* [FTCharToGlyphIndexMap::NumberOfBuckets];
+ for(int i = 0; i < FTCharToGlyphIndexMap::NumberOfBuckets; i++)
+ {
+ this->Indices[i] = 0;
+ }
+ }
+
+ // Find position of char code in buckets
+ div_t pos = div(c, FTCharToGlyphIndexMap::BucketSize);
+
+ // Allocate bucket if does not exist yet
+ if(!this->Indices[pos.quot])
+ {
+ this->Indices[pos.quot] = new GlyphIndex [FTCharToGlyphIndexMap::BucketSize];
+ for(int i = 0; i < FTCharToGlyphIndexMap::BucketSize; i++)
+ {
+ this->Indices[pos.quot][i] = FTCharToGlyphIndexMap::IndexNotFound;
+ }
+ }
+
+ this->Indices[pos.quot][pos.rem] = g;
+ }
+
+ private:
+ GlyphIndex** Indices;
+};
+
+
+#endif // __FTCharToGlyphIndexMap__
diff --git a/src/ftgl/FTCharmap.cpp b/src/ftgl/FTCharmap.cpp
new file mode 100644
index 0000000..64a2180
--- /dev/null
+++ b/src/ftgl/FTCharmap.cpp
@@ -0,0 +1,106 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTFace.h"
+#include "FTCharmap.h"
+
+
+FTCharmap::FTCharmap(FTFace* face)
+: ftFace(*(face->Face())),
+ err(0)
+{
+ if(!ftFace->charmap)
+ {
+ if(!ftFace->num_charmaps)
+ {
+ // This face doesn't even have one charmap!
+ err = 0x96; // Invalid_CharMap_Format
+ return;
+ }
+
+ err = FT_Set_Charmap(ftFace, ftFace->charmaps[0]);
+ }
+
+ ftEncoding = ftFace->charmap->encoding;
+
+ for(unsigned int i = 0; i < FTCharmap::MAX_PRECOMPUTED; i++)
+ {
+ charIndexCache[i] = FT_Get_Char_Index(ftFace, i);
+ }
+}
+
+
+FTCharmap::~FTCharmap()
+{
+ charMap.clear();
+}
+
+
+bool FTCharmap::CharMap(FT_Encoding encoding)
+{
+ if(ftEncoding == encoding)
+ {
+ err = 0;
+ return true;
+ }
+
+ err = FT_Select_Charmap(ftFace, encoding);
+
+ if(!err)
+ {
+ ftEncoding = encoding;
+ charMap.clear();
+ }
+
+ return !err;
+}
+
+
+unsigned int FTCharmap::GlyphListIndex(const unsigned int characterCode)
+{
+ return charMap.find(characterCode);
+}
+
+
+unsigned int FTCharmap::FontIndex(const unsigned int characterCode)
+{
+ if(characterCode < FTCharmap::MAX_PRECOMPUTED)
+ {
+ return charIndexCache[characterCode];
+ }
+
+ return FT_Get_Char_Index(ftFace, characterCode);
+}
+
+
+void FTCharmap::InsertIndex(const unsigned int characterCode,
+ const size_t containerIndex)
+{
+ charMap.insert(characterCode, static_cast<FTCharToGlyphIndexMap::GlyphIndex>(containerIndex));
+}
+
diff --git a/src/ftgl/FTCharmap.h b/src/ftgl/FTCharmap.h
new file mode 100644
index 0000000..f4ce867
--- /dev/null
+++ b/src/ftgl/FTCharmap.h
@@ -0,0 +1,165 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTCharmap__
+#define __FTCharmap__
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "FTGL/ftgl.h"
+#include "FTCharToGlyphIndexMap.h"
+
+
+/**
+ * FTCharmap takes care of specifying the encoding for a font and mapping
+ * character codes to glyph indices.
+ *
+ * It doesn't preprocess all indices, only on an as needed basis. This may
+ * seem like a performance penalty but it is quicker than using the 'raw'
+ * freetype calls and will save significant amounts of memory when dealing
+ * with unicode encoding
+ *
+ * @see "Freetype 2 Documentation"
+ *
+ */
+
+class FTFace;
+
+class FTCharmap
+{
+ public:
+ /**
+ * Constructor
+ */
+ FTCharmap(FTFace* face);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTCharmap();
+
+ /**
+ * Queries for the current character map code.
+ *
+ * @return The current character map code.
+ */
+ FT_Encoding Encoding() const { return ftEncoding; }
+
+ /**
+ * Sets the character map for the face. If an error occurs the object is not modified.
+ * Valid encodings as at Freetype 2.0.4
+ * ft_encoding_none
+ * ft_encoding_symbol
+ * ft_encoding_unicode
+ * ft_encoding_latin_2
+ * ft_encoding_sjis
+ * ft_encoding_gb2312
+ * ft_encoding_big5
+ * ft_encoding_wansung
+ * ft_encoding_johab
+ * ft_encoding_adobe_standard
+ * ft_encoding_adobe_expert
+ * ft_encoding_adobe_custom
+ * ft_encoding_apple_roman
+ *
+ * @param encoding the Freetype encoding symbol. See above.
+ * @return <code>true</code> if charmap was valid and set
+ * correctly.
+ */
+ bool CharMap(FT_Encoding encoding);
+
+ /**
+ * Get the FTGlyphContainer index of the input character.
+ *
+ * @param characterCode The character code of the requested glyph in
+ * the current encoding eg apple roman.
+ * @return The FTGlyphContainer index for the character or zero
+ * if it wasn't found
+ */
+ unsigned int GlyphListIndex(const unsigned int characterCode);
+
+ /**
+ * Get the font glyph index of the input character.
+ *
+ * @param characterCode The character code of the requested glyph in
+ * the current encoding eg apple roman.
+ * @return The glyph index for the character.
+ */
+ unsigned int FontIndex(const unsigned int characterCode);
+
+ /**
+ * Set the FTGlyphContainer index of the character code.
+ *
+ * @param characterCode The character code of the requested glyph in
+ * the current encoding eg apple roman.
+ * @param containerIndex The index into the FTGlyphContainer of the
+ * character code.
+ */
+ void InsertIndex(const unsigned int characterCode,
+ const size_t containerIndex);
+
+ /**
+ * Queries for errors.
+ *
+ * @return The current error code. Zero means no error.
+ */
+ FT_Error Error() const { return err; }
+
+ private:
+ /**
+ * Current character map code.
+ */
+ FT_Encoding ftEncoding;
+
+ /**
+ * The current Freetype face.
+ */
+ const FT_Face ftFace;
+
+ /**
+ * A structure that maps glyph indices to character codes
+ *
+ * < character code, face glyph index>
+ */
+ typedef FTCharToGlyphIndexMap CharacterMap;
+ CharacterMap charMap;
+
+ /**
+ * Precomputed font indices.
+ */
+ static const unsigned int MAX_PRECOMPUTED = 128;
+ unsigned int charIndexCache[MAX_PRECOMPUTED];
+
+ /**
+ * Current error code.
+ */
+ FT_Error err;
+};
+
+
+#endif // __FTCharmap__
diff --git a/src/ftgl/FTContour.cpp b/src/ftgl/FTContour.cpp
new file mode 100644
index 0000000..cef1f3b
--- /dev/null
+++ b/src/ftgl/FTContour.cpp
@@ -0,0 +1,245 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTContour.h"
+
+#include <math.h>
+
+static const unsigned int BEZIER_STEPS = 5;
+
+
+void FTContour::AddPoint(FTPoint point)
+{
+ if(pointList.empty() || (point != pointList[pointList.size() - 1]
+ && point != pointList[0]))
+ {
+ pointList.push_back(point);
+ }
+}
+
+
+void FTContour::AddOutsetPoint(FTPoint point)
+{
+ outsetPointList.push_back(point);
+}
+
+
+void FTContour::AddFrontPoint(FTPoint point)
+{
+ frontPointList.push_back(point);
+}
+
+
+void FTContour::AddBackPoint(FTPoint point)
+{
+ backPointList.push_back(point);
+}
+
+
+void FTContour::evaluateQuadraticCurve(FTPoint A, FTPoint B, FTPoint C)
+{
+ for(unsigned int i = 1; i < BEZIER_STEPS; i++)
+ {
+ float t = static_cast<float>(i) / BEZIER_STEPS;
+
+ FTPoint U = (1.0f - t) * A + t * B;
+ FTPoint V = (1.0f - t) * B + t * C;
+
+ AddPoint((1.0f - t) * U + t * V);
+ }
+}
+
+
+void FTContour::evaluateCubicCurve(FTPoint A, FTPoint B, FTPoint C, FTPoint D)
+{
+ for(unsigned int i = 0; i < BEZIER_STEPS; i++)
+ {
+ float t = static_cast<float>(i) / BEZIER_STEPS;
+
+ FTPoint U = (1.0f - t) * A + t * B;
+ FTPoint V = (1.0f - t) * B + t * C;
+ FTPoint W = (1.0f - t) * C + t * D;
+
+ FTPoint M = (1.0f - t) * U + t * V;
+ FTPoint N = (1.0f - t) * V + t * W;
+
+ AddPoint((1.0f - t) * M + t * N);
+ }
+}
+
+
+// This function is a bit tricky. Given a path ABC, it returns the
+// coordinates of the outset point facing B on the left at a distance
+// of 64.0.
+// M
+// - - - - - - X
+// ^ / '
+// | 64.0 / '
+// X---->-----X ==> X--v-------X '
+// A B \ A B \ .>'
+// \ \<' 64.0
+// \ \ .
+// \ \ .
+// C X C X
+//
+FTPoint FTContour::ComputeOutsetPoint(FTPoint A, FTPoint B, FTPoint C)
+{
+ /* Build the rotation matrix from 'ba' vector */
+ FTPoint ba = (A - B).Normalise();
+ FTPoint bc = C - B;
+
+ /* Rotate bc to the left */
+ FTPoint tmp(bc.X() * -ba.X() + bc.Y() * -ba.Y(),
+ bc.X() * ba.Y() + bc.Y() * -ba.X());
+
+ /* Compute the vector bisecting 'abc' */
+ FTGL_DOUBLE norm = sqrt(tmp.X() * tmp.X() + tmp.Y() * tmp.Y());
+ FTGL_DOUBLE dist = 64.0 * sqrt((norm - tmp.X()) / (norm + tmp.X()));
+ tmp.X(tmp.Y() < 0.0 ? dist : -dist);
+ tmp.Y(64.0);
+
+ /* Rotate the new bc to the right */
+ return FTPoint(tmp.X() * -ba.X() + tmp.Y() * ba.Y(),
+ tmp.X() * -ba.Y() + tmp.Y() * -ba.X());
+}
+
+
+void FTContour::SetParity(int parity)
+{
+ size_t size = PointCount();
+ FTPoint vOutset;
+
+ if(((parity & 1) && clockwise) || (!(parity & 1) && !clockwise))
+ {
+ // Contour orientation is wrong! We must reverse all points.
+ // FIXME: could it be worth writing FTVector::reverse() for this?
+ for(size_t i = 0; i < size / 2; i++)
+ {
+ FTPoint tmp = pointList[i];
+ pointList[i] = pointList[size - 1 - i];
+ pointList[size - 1 -i] = tmp;
+ }
+
+ clockwise = !clockwise;
+ }
+
+ for(size_t i = 0; i < size; i++)
+ {
+ size_t prev, cur, next;
+
+ prev = (i + size - 1) % size;
+ cur = i;
+ next = (i + size + 1) % size;
+
+ vOutset = ComputeOutsetPoint(Point(prev), Point(cur), Point(next));
+ AddOutsetPoint(vOutset);
+ }
+}
+
+
+FTContour::FTContour(FT_Vector* contour, char* tags, unsigned int n)
+{
+ FTPoint prev, cur(contour[(n - 1) % n]), next(contour[0]);
+ FTPoint a, b = next - cur;
+ double olddir, dir = atan2((next - cur).Y(), (next - cur).X());
+ double angle = 0.0;
+
+ // See http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-6.html
+ // for a full description of FreeType tags.
+ for(unsigned int i = 0; i < n; i++)
+ {
+ prev = cur;
+ cur = next;
+ next = FTPoint(contour[(i + 1) % n]);
+ olddir = dir;
+ dir = atan2((next - cur).Y(), (next - cur).X());
+
+ // Compute our path's new direction.
+ double t = dir - olddir;
+ if(t < -M_PI) t += 2 * M_PI;
+ if(t > M_PI) t -= 2 * M_PI;
+ angle += t;
+
+ // Only process point tags we know.
+ if(n < 2 || FT_CURVE_TAG(tags[i]) == FT_Curve_Tag_On)
+ {
+ AddPoint(cur);
+ }
+ else if(FT_CURVE_TAG(tags[i]) == FT_Curve_Tag_Conic)
+ {
+ FTPoint prev2 = prev, next2 = next;
+
+ // Previous point is either the real previous point (an "on"
+ // point), or the midpoint between the current one and the
+ // previous "conic off" point.
+ if(FT_CURVE_TAG(tags[(i - 1 + n) % n]) == FT_Curve_Tag_Conic)
+ {
+ prev2 = (cur + prev) * 0.5;
+ AddPoint(prev2);
+ }
+
+ // Next point is either the real next point or the midpoint.
+ if(FT_CURVE_TAG(tags[(i + 1) % n]) == FT_Curve_Tag_Conic)
+ {
+ next2 = (cur + next) * 0.5;
+ }
+
+ evaluateQuadraticCurve(prev2, cur, next2);
+ }
+ else if(FT_CURVE_TAG(tags[i]) == FT_Curve_Tag_Cubic
+ && FT_CURVE_TAG(tags[(i + 1) % n]) == FT_Curve_Tag_Cubic)
+ {
+ evaluateCubicCurve(prev, cur, next,
+ FTPoint(contour[(i + 2) % n]));
+ }
+ }
+
+ // If final angle is positive (+2PI), it's an anti-clockwise contour,
+ // otherwise (-2PI) it's clockwise.
+ clockwise = (angle < 0.0);
+}
+
+
+void FTContour::buildFrontOutset(float outset)
+{
+ for(size_t i = 0; i < PointCount(); ++i)
+ {
+ AddFrontPoint(Point(i) + Outset(i) * outset);
+ }
+}
+
+
+void FTContour::buildBackOutset(float outset)
+{
+ for(size_t i = 0; i < PointCount(); ++i)
+ {
+ AddBackPoint(Point(i) + Outset(i) * outset);
+ }
+}
+
diff --git a/src/ftgl/FTContour.h b/src/ftgl/FTContour.h
new file mode 100644
index 0000000..4cfff6c
--- /dev/null
+++ b/src/ftgl/FTContour.h
@@ -0,0 +1,209 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTContour__
+#define __FTContour__
+
+#include "FTGL/ftgl.h"
+
+#include "FTVector.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 FTPolygonGlyph
+ * @see FTPoint
+ */
+class FTContour
+{
+ public:
+ /**
+ * Constructor
+ *
+ * @param contour
+ * @param pointTags
+ * @param numberOfPoints
+ */
+ FTContour(FT_Vector* contour, char* pointTags, unsigned int numberOfPoints);
+
+ /**
+ * Destructor
+ */
+ ~FTContour()
+ {
+ pointList.clear();
+ outsetPointList.clear();
+ frontPointList.clear();
+ backPointList.clear();
+ }
+
+ /**
+ * Return a point at index.
+ *
+ * @param index of the point in the curve.
+ * @return const point reference
+ */
+ const FTPoint& Point(size_t index) const { return pointList[index]; }
+
+ /**
+ * Return a point at index.
+ *
+ * @param index of the point in the outset curve.
+ * @return const point reference
+ */
+ const FTPoint& Outset(size_t index) const { return outsetPointList[index]; }
+
+ /**
+ * Return a point at index of the front outset contour.
+ *
+ * @param index of the point in the curve.
+ * @return const point reference
+ */
+ const FTPoint& FrontPoint(size_t index) const
+ {
+ if(frontPointList.size() == 0)
+ return Point(index);
+ return frontPointList[index];
+ }
+
+
+ /**
+ * Return a point at index of the back outset contour.
+ *
+ * @param index of the point in the curve.
+ * @return const point reference
+ */
+ const FTPoint& BackPoint(size_t index) const
+ {
+ if(backPointList.size() == 0)
+ return Point(index);
+ return backPointList[index];
+ }
+
+ /**
+ * How many points define this contour
+ *
+ * @return the number of points in this contour
+ */
+ size_t PointCount() const { return pointList.size(); }
+
+ /**
+ * Make sure the glyph has the proper parity and create the front/back
+ * outset contour.
+ *
+ * @param parity The contour's parity within the glyph.
+ */
+ void SetParity(int parity);
+
+ // FIXME: this should probably go away.
+ void buildFrontOutset(float outset);
+ void buildBackOutset(float outset);
+
+ 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);
+
+ /**
+ * Add a point to this contour. This function tests for duplicate
+ * points.
+ *
+ * @param point The point to be added to the contour.
+ */
+ inline void AddOutsetPoint(FTPoint point);
+
+ /*
+ * Add a point to this outset contour. This function tests for duplicate
+ * points.
+ *
+ * @param point The point to be added to the contour outset.
+ */
+ inline void AddFrontPoint(FTPoint point);
+ inline void AddBackPoint(FTPoint point);
+
+ /**
+ * De Casteljau (bezier) algorithm contributed by Jed Soane
+ * Evaluates a quadratic or conic (second degree) curve
+ */
+ inline void evaluateQuadraticCurve(FTPoint, FTPoint, FTPoint);
+
+ /**
+ * De Casteljau (bezier) algorithm contributed by Jed Soane
+ * Evaluates a cubic (third degree) curve
+ */
+ inline void evaluateCubicCurve(FTPoint, FTPoint, FTPoint, FTPoint);
+
+ /**
+ * Compute the vector norm
+ */
+ inline FTGL_DOUBLE NormVector(const FTPoint &v);
+
+ /**
+ * Compute a rotation matrix from a vector
+ */
+ inline void RotationMatrix(const FTPoint &a, const FTPoint &b, FTGL_DOUBLE *matRot, FTGL_DOUBLE *invRot);
+
+ /**
+ * Matrix and vector multiplication
+ */
+ inline void MultMatrixVect(FTGL_DOUBLE *mat, FTPoint &v);
+
+ /**
+ * Compute the vector bisecting from a vector 'v' and a distance 'd'
+ */
+ inline void ComputeBisec(FTPoint &v);
+
+ /**
+ * Compute the outset point coordinates
+ */
+ inline FTPoint ComputeOutsetPoint(FTPoint a, FTPoint b, FTPoint c);
+
+ /**
+ * The list of points in this contour
+ */
+ typedef FTVector<FTPoint> PointVector;
+ PointVector pointList;
+ PointVector outsetPointList;
+ PointVector frontPointList;
+ PointVector backPointList;
+
+ /**
+ * Is this contour clockwise or anti-clockwise?
+ */
+ bool clockwise;
+};
+
+#endif // __FTContour__
+
diff --git a/src/ftgl/FTFace.cpp b/src/ftgl/FTFace.cpp
new file mode 100644
index 0000000..542c521
--- /dev/null
+++ b/src/ftgl/FTFace.cpp
@@ -0,0 +1,232 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTFace.h"
+#include "FTLibrary.h"
+
+#include FT_TRUETYPE_TABLES_H
+
+FTFace::FTFace(const char* fontFilePath, bool precomputeKerning)
+: numGlyphs(0),
+ fontEncodingList(0),
+ kerningCache(0),
+ err(0)
+{
+ const FT_Long DEFAULT_FACE_INDEX = 0;
+ ftFace = new FT_Face;
+
+ err = FT_New_Face(*FTLibrary::Instance().GetLibrary(), fontFilePath,
+ DEFAULT_FACE_INDEX, ftFace);
+ if(err)
+ {
+ delete ftFace;
+ ftFace = 0;
+ return;
+ }
+
+ numGlyphs = (*ftFace)->num_glyphs;
+ hasKerningTable = (FT_HAS_KERNING((*ftFace)) != 0);
+
+ if(hasKerningTable && precomputeKerning)
+ {
+ BuildKerningCache();
+ }
+}
+
+
+FTFace::FTFace(const unsigned char *pBufferBytes, size_t bufferSizeInBytes,
+ bool precomputeKerning)
+: numGlyphs(0),
+ fontEncodingList(0),
+ kerningCache(0),
+ err(0)
+{
+ const FT_Long DEFAULT_FACE_INDEX = 0;
+ ftFace = new FT_Face;
+
+ err = FT_New_Memory_Face(*FTLibrary::Instance().GetLibrary(),
+ (FT_Byte const *)pBufferBytes, (FT_Long)bufferSizeInBytes,
+ DEFAULT_FACE_INDEX, ftFace);
+ if(err)
+ {
+ delete ftFace;
+ ftFace = 0;
+ return;
+ }
+
+ numGlyphs = (*ftFace)->num_glyphs;
+ hasKerningTable = (FT_HAS_KERNING((*ftFace)) != 0);
+
+ if(hasKerningTable && precomputeKerning)
+ {
+ BuildKerningCache();
+ }
+}
+
+
+FTFace::~FTFace()
+{
+ if(kerningCache)
+ {
+ delete[] kerningCache;
+ }
+
+ if(ftFace)
+ {
+ FT_Done_Face(*ftFace);
+ delete ftFace;
+ ftFace = 0;
+ }
+}
+
+
+bool FTFace::Attach(const char* fontFilePath)
+{
+ err = FT_Attach_File(*ftFace, fontFilePath);
+ return !err;
+}
+
+
+bool FTFace::Attach(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+{
+ FT_Open_Args open;
+
+ open.flags = FT_OPEN_MEMORY;
+ open.memory_base = (FT_Byte const *)pBufferBytes;
+ open.memory_size = (FT_Long)bufferSizeInBytes;
+
+ err = FT_Attach_Stream(*ftFace, &open);
+ return !err;
+}
+
+
+const FTSize& FTFace::Size(const unsigned int size, const unsigned int res)
+{
+ charSize.CharSize(ftFace, size, res, res);
+ err = charSize.Error();
+
+ return charSize;
+}
+
+
+unsigned int FTFace::CharMapCount() const
+{
+ return (*ftFace)->num_charmaps;
+}
+
+
+FT_Encoding* FTFace::CharMapList()
+{
+ if(0 == fontEncodingList)
+ {
+ fontEncodingList = new FT_Encoding[CharMapCount()];
+ for(size_t i = 0; i < CharMapCount(); ++i)
+ {
+ fontEncodingList[i] = (*ftFace)->charmaps[i]->encoding;
+ }
+ }
+
+ return fontEncodingList;
+}
+
+
+FTPoint FTFace::KernAdvance(unsigned int index1, unsigned int index2)
+{
+ float x, y;
+
+ if(!hasKerningTable || !index1 || !index2)
+ {
+ return FTPoint(0.0f, 0.0f);
+ }
+
+ if(kerningCache && index1 < FTFace::MAX_PRECOMPUTED
+ && index2 < FTFace::MAX_PRECOMPUTED)
+ {
+ x = kerningCache[2 * (index2 * FTFace::MAX_PRECOMPUTED + index1)];
+ y = kerningCache[2 * (index2 * FTFace::MAX_PRECOMPUTED + index1) + 1];
+ return FTPoint(x, y);
+ }
+
+ FT_Vector kernAdvance;
+ kernAdvance.x = kernAdvance.y = 0;
+
+ err = FT_Get_Kerning(*ftFace, index1, index2, ft_kerning_unfitted,
+ &kernAdvance);
+ if(err)
+ {
+ return FTPoint(0.0f, 0.0f);
+ }
+
+ x = static_cast<float>(kernAdvance.x) / 64.0f;
+ y = static_cast<float>(kernAdvance.y) / 64.0f;
+
+ return FTPoint(x, y);
+}
+
+
+FT_GlyphSlot FTFace::Glyph(unsigned int index, FT_Int load_flags)
+{
+ err = FT_Load_Glyph(*ftFace, index, load_flags);
+ if(err)
+ {
+ return NULL;
+ }
+
+ return (*ftFace)->glyph;
+}
+
+
+void FTFace::BuildKerningCache()
+{
+ FT_Vector kernAdvance;
+ kernAdvance.x = 0;
+ kernAdvance.y = 0;
+ kerningCache = new float[FTFace::MAX_PRECOMPUTED
+ * FTFace::MAX_PRECOMPUTED * 2];
+ for(unsigned int j = 0; j < FTFace::MAX_PRECOMPUTED; j++)
+ {
+ for(unsigned int i = 0; i < FTFace::MAX_PRECOMPUTED; i++)
+ {
+ err = FT_Get_Kerning(*ftFace, i, j, ft_kerning_unfitted,
+ &kernAdvance);
+ if(err)
+ {
+ delete[] kerningCache;
+ kerningCache = NULL;
+ return;
+ }
+
+ kerningCache[2 * (j * FTFace::MAX_PRECOMPUTED + i)] =
+ static_cast<float>(kernAdvance.x) / 64.0f;
+ kerningCache[2 * (j * FTFace::MAX_PRECOMPUTED + i) + 1] =
+ static_cast<float>(kernAdvance.y) / 64.0f;
+ }
+ }
+}
+
diff --git a/src/ftgl/FTFace.h b/src/ftgl/FTFace.h
new file mode 100644
index 0000000..0e903b5
--- /dev/null
+++ b/src/ftgl/FTFace.h
@@ -0,0 +1,181 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTFace__
+#define __FTFace__
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "FTGL/ftgl.h"
+
+#include "FTSize.h"
+
+/**
+ * FTFace class provides an abstraction layer for the Freetype Face.
+ *
+ * @see "Freetype 2 Documentation"
+ *
+ */
+class FTFace
+{
+ public:
+ /**
+ * Opens and reads a face file. Error is set.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTFace(const char* fontFilePath, bool precomputeKerning = true);
+
+ /**
+ * Read face data from an in-memory buffer. Error is set.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTFace(const unsigned char *pBufferBytes, size_t bufferSizeInBytes,
+ bool precomputeKerning = true);
+
+ /**
+ * Destructor
+ *
+ * Disposes of the current Freetype Face.
+ */
+ virtual ~FTFace();
+
+ /**
+ * Attach auxilliary file to font (e.g., font metrics).
+ *
+ * @param fontFilePath auxilliary font file path.
+ * @return <code>true</code> if file has opened
+ * successfully.
+ */
+ bool Attach(const char* fontFilePath);
+
+ /**
+ * Attach auxilliary data to font (e.g., font metrics) from memory
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ * @return <code>true</code> if file has opened
+ * successfully.
+ */
+ bool Attach(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Get the freetype face object..
+ *
+ * @return pointer to an FT_Face.
+ */
+ FT_Face* Face() const { return ftFace; }
+
+ /**
+ * Sets the char size for the current face.
+ *
+ * This doesn't guarantee that the size was set correctly. Clients
+ * should check errors.
+ *
+ * @param size the face size in points (1/72 inch)
+ * @param res the resolution of the target device.
+ * @return <code>FTSize</code> object
+ */
+ const FTSize& Size(const unsigned int size, const unsigned int res);
+
+ /**
+ * Get the number of character maps in this face.
+ *
+ * @return character map count.
+ */
+ unsigned int CharMapCount() const;
+
+ /**
+ * Get a list of character maps in this face.
+ *
+ * @return pointer to the first encoding.
+ */
+ FT_Encoding* CharMapList();
+
+ /**
+ * Gets the kerning vector between two glyphs
+ */
+ FTPoint KernAdvance(unsigned int index1, unsigned int index2);
+
+ /**
+ * Loads and creates a Freetype glyph.
+ */
+ FT_GlyphSlot Glyph(unsigned int index, FT_Int load_flags);
+
+ /**
+ * Gets the number of glyphs in the current face.
+ */
+ unsigned int GlyphCount() const { return numGlyphs; }
+
+ /**
+ * Queries for errors.
+ *
+ * @return The current error code.
+ */
+ FT_Error Error() const { return err; }
+
+ private:
+ /**
+ * The Freetype face
+ */
+ FT_Face* ftFace;
+
+ /**
+ * The size object associated with this face
+ */
+ FTSize charSize;
+
+ /**
+ * The number of glyphs in this face
+ */
+ int numGlyphs;
+
+ FT_Encoding* fontEncodingList;
+
+ /**
+ * This face has kerning tables
+ */
+ bool hasKerningTable;
+
+ /**
+ * If this face has kerning tables, we can cache them.
+ */
+ void BuildKerningCache();
+ static const unsigned int MAX_PRECOMPUTED = 128;
+ float *kerningCache;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+};
+
+
+#endif // __FTFace__
diff --git a/src/ftgl/FTFont/FTBitmapFont.cpp b/src/ftgl/FTFont/FTBitmapFont.cpp
new file mode 100644
index 0000000..ebf3f1e
--- /dev/null
+++ b/src/ftgl/FTFont/FTBitmapFont.cpp
@@ -0,0 +1,106 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTBitmapFontImpl.h"
+
+
+//
+// FTBitmapFont
+//
+
+
+FTBitmapFont::FTBitmapFont(char const *fontFilePath) :
+ FTFont(new FTBitmapFontImpl(this, fontFilePath))
+{}
+
+
+FTBitmapFont::FTBitmapFont(unsigned char const *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTBitmapFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTBitmapFont::~FTBitmapFont()
+{}
+
+
+FTGlyph* FTBitmapFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ return new FTBitmapGlyph(ftGlyph);
+}
+
+
+//
+// FTBitmapFontImpl
+//
+
+
+template <typename T>
+inline FTPoint FTBitmapFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ // Protect GL_BLEND
+ glPushAttrib(GL_COLOR_BUFFER_BIT);
+
+ // Protect glPixelStorei() calls (also in FTBitmapGlyphImpl::RenderImpl)
+ glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+
+ glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glDisable(GL_BLEND);
+
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
+
+ glPopClientAttrib();
+ glPopAttrib();
+
+ return tmp;
+}
+
+
+FTPoint FTBitmapFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTBitmapFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
diff --git a/src/ftgl/FTFont/FTBitmapFontImpl.h b/src/ftgl/FTFont/FTBitmapFontImpl.h
new file mode 100644
index 0000000..7f733d6
--- /dev/null
+++ b/src/ftgl/FTFont/FTBitmapFontImpl.h
@@ -0,0 +1,62 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTBitmapFontImpl__
+#define __FTBitmapFontImpl__
+
+#include "FTFontImpl.h"
+
+class FTGlyph;
+
+class FTBitmapFontImpl : public FTFontImpl
+{
+ friend class FTBitmapFont;
+
+ protected:
+ FTBitmapFontImpl(FTFont *ftFont, const char* fontFilePath) :
+ FTFontImpl(ftFont, fontFilePath) {};
+
+ FTBitmapFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes) {};
+
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ private:
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
+};
+
+#endif // __FTBitmapFontImpl__
+
diff --git a/src/ftgl/FTFont/FTBufferFont.cpp b/src/ftgl/FTFont/FTBufferFont.cpp
new file mode 100644
index 0000000..e48e2ab
--- /dev/null
+++ b/src/ftgl/FTFont/FTBufferFont.cpp
@@ -0,0 +1,349 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <wchar.h>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTBufferFontImpl.h"
+
+
+//
+// FTBufferFont
+//
+
+
+FTBufferFont::FTBufferFont(char const *fontFilePath) :
+ FTFont(new FTBufferFontImpl(this, fontFilePath))
+{}
+
+
+FTBufferFont::FTBufferFont(unsigned char const *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTBufferFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTBufferFont::~FTBufferFont()
+{}
+
+
+FTGlyph* FTBufferFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ FTBufferFontImpl *myimpl = dynamic_cast<FTBufferFontImpl *>(impl);
+ if(!myimpl)
+ {
+ return NULL;
+ }
+
+ return myimpl->MakeGlyphImpl(ftGlyph);
+}
+
+
+//
+// FTBufferFontImpl
+//
+
+
+FTBufferFontImpl::FTBufferFontImpl(FTFont *ftFont, const char* fontFilePath) :
+ FTFontImpl(ftFont, fontFilePath),
+ buffer(new FTBuffer())
+{
+ load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+
+ glGenTextures(BUFFER_CACHE_SIZE, idCache);
+
+ for(int i = 0; i < BUFFER_CACHE_SIZE; i++)
+ {
+ stringCache[i] = NULL;
+ glBindTexture(GL_TEXTURE_2D, idCache[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ }
+
+ lastString = 0;
+}
+
+
+FTBufferFontImpl::FTBufferFontImpl(FTFont *ftFont,
+ const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+ buffer(new FTBuffer())
+{
+ load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+
+ glGenTextures(BUFFER_CACHE_SIZE, idCache);
+
+ for(int i = 0; i < BUFFER_CACHE_SIZE; i++)
+ {
+ stringCache[i] = NULL;
+ glBindTexture(GL_TEXTURE_2D, idCache[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ }
+
+ lastString = 0;
+}
+
+
+FTBufferFontImpl::~FTBufferFontImpl()
+{
+ glDeleteTextures(BUFFER_CACHE_SIZE, idCache);
+
+ for(int i = 0; i < BUFFER_CACHE_SIZE; i++)
+ {
+ if(stringCache[i])
+ {
+ free(stringCache[i]);
+ }
+ }
+
+ delete buffer;
+}
+
+
+FTGlyph* FTBufferFontImpl::MakeGlyphImpl(FT_GlyphSlot ftGlyph)
+{
+ return new FTBufferGlyph(ftGlyph, buffer);
+}
+
+
+bool FTBufferFontImpl::FaceSize(const unsigned int size,
+ const unsigned int res)
+{
+ for(int i = 0; i < BUFFER_CACHE_SIZE; i++)
+ {
+ if(stringCache[i])
+ {
+ free(stringCache[i]);
+ stringCache[i] = NULL;
+ }
+ }
+
+ return FTFontImpl::FaceSize(size, res);
+}
+
+
+static inline GLuint NextPowerOf2(GLuint in)
+{
+ in -= 1;
+
+ in |= in >> 16;
+ in |= in >> 8;
+ in |= in >> 4;
+ in |= in >> 2;
+ in |= in >> 1;
+
+ return in + 1;
+}
+
+
+inline int StringCompare(void const *a, char const *b, int len)
+{
+ return len < 0 ? strcmp((char const *)a, b)
+ : strncmp((char const *)a, b, len);
+}
+
+
+inline int StringCompare(void const *a, wchar_t const *b, int len)
+{
+ return len < 0 ? wcscmp((wchar_t const *)a, b)
+ : wcsncmp((wchar_t const *)a, b, len);
+}
+
+
+inline char *StringCopy(char const *s, int len)
+{
+ if(len < 0)
+ {
+ return strdup(s);
+ }
+ else
+ {
+#ifdef HAVE_STRNDUP
+ return strndup(s, len);
+#else
+ char *s2 = (char*)malloc(len + 1);
+ memcpy(s2, s, len);
+ s2[len] = 0;
+ return s2;
+#endif
+ }
+}
+
+
+inline wchar_t *StringCopy(wchar_t const *s, int len)
+{
+ if(len < 0)
+ {
+#if defined HAVE_WCSDUP
+ return wcsdup(s);
+#else
+ len = (int)wcslen(s);
+#endif
+ }
+
+ wchar_t *s2 = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
+ memcpy(s2, s, len * sizeof(wchar_t));
+ s2[len] = 0;
+ return s2;
+}
+
+
+template <typename T>
+inline FTPoint FTBufferFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ const float padding = 3.0f;
+ int width, height, texWidth, texHeight;
+ int cacheIndex = -1;
+ bool inCache = false;
+
+ // Protect blending functions, GL_BLEND and GL_TEXTURE_2D
+ glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
+
+ // Protect glPixelStorei() calls
+ glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+
+ glEnable(GL_BLEND);
+ glEnable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+
+ // Search whether the string is already in a texture we uploaded
+ for(int n = 0; n < BUFFER_CACHE_SIZE; n++)
+ {
+ int i = (lastString + n + BUFFER_CACHE_SIZE) % BUFFER_CACHE_SIZE;
+
+ if(stringCache[i] && !StringCompare(stringCache[i], string, len))
+ {
+ cacheIndex = i;
+ inCache = true;
+ break;
+ }
+ }
+
+ // If the string was not found, we need to put it in the cache and compute
+ // its new bounding box.
+ if(!inCache)
+ {
+ // FIXME: this cache is not very efficient. We should first expire
+ // strings that are not used very often.
+ cacheIndex = lastString;
+ lastString = (lastString + 1) % BUFFER_CACHE_SIZE;
+
+ if(stringCache[cacheIndex])
+ {
+ free(stringCache[cacheIndex]);
+ }
+ // FIXME: only the first N bytes are copied; we want the first N chars.
+ stringCache[cacheIndex] = StringCopy(string, len);
+ bboxCache[cacheIndex] = BBox(string, len, FTPoint(), spacing);
+ }
+
+ FTBBox bbox = bboxCache[cacheIndex];
+
+ width = static_cast<int>(bbox.Upper().X() - bbox.Lower().X()
+ + padding + padding + 0.5);
+ height = static_cast<int>(bbox.Upper().Y() - bbox.Lower().Y()
+ + padding + padding + 0.5);
+
+ texWidth = NextPowerOf2(width);
+ texHeight = NextPowerOf2(height);
+
+ glBindTexture(GL_TEXTURE_2D, idCache[cacheIndex]);
+
+ // If the string was not found, we need to render the text in a new
+ // texture buffer, then upload it to the OpenGL layer.
+ if(!inCache)
+ {
+ buffer->Size(texWidth, texHeight);
+ buffer->Pos(FTPoint(padding, padding) - bbox.Lower());
+
+ advanceCache[cacheIndex] =
+ FTFontImpl::Render(string, len, FTPoint(), spacing, renderMode);
+
+ glBindTexture(GL_TEXTURE_2D, idCache[cacheIndex]);
+
+ glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ /* TODO: use glTexSubImage2D later? */
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texWidth, texHeight, 0,
+ GL_ALPHA, GL_UNSIGNED_BYTE, (GLvoid *)buffer->Pixels());
+
+ buffer->Size(0, 0);
+ }
+
+ FTPoint low = position + bbox.Lower();
+ FTPoint up = position + bbox.Upper();
+
+ glBegin(GL_QUADS);
+ glNormal3f(0.0f, 0.0f, 1.0f);
+ glTexCoord2f(padding / texWidth,
+ (texHeight - height + padding) / texHeight);
+ glVertex2f(low.Xf(), up.Yf());
+ glTexCoord2f(padding / texWidth,
+ (texHeight - padding) / texHeight);
+ glVertex2f(low.Xf(), low.Yf());
+ glTexCoord2f((width - padding) / texWidth,
+ (texHeight - padding) / texHeight);
+ glVertex2f(up.Xf(), low.Yf());
+ glTexCoord2f((width - padding) / texWidth,
+ (texHeight - height + padding) / texHeight);
+ glVertex2f(up.Xf(), up.Yf());
+ glEnd();
+
+ glPopClientAttrib();
+ glPopAttrib();
+
+ return position + advanceCache[cacheIndex];
+}
+
+
+FTPoint FTBufferFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTBufferFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
diff --git a/src/ftgl/FTFont/FTBufferFontImpl.h b/src/ftgl/FTFont/FTBufferFontImpl.h
new file mode 100644
index 0000000..15557f6
--- /dev/null
+++ b/src/ftgl/FTFont/FTBufferFontImpl.h
@@ -0,0 +1,81 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTBufferFontImpl__
+#define __FTBufferFontImpl__
+
+#include "FTFontImpl.h"
+
+class FTGlyph;
+class FTBuffer;
+
+class FTBufferFontImpl : public FTFontImpl
+{
+ friend class FTBufferFont;
+
+ protected:
+ FTBufferFontImpl(FTFont *ftFont, const char* fontFilePath);
+
+ FTBufferFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ virtual ~FTBufferFontImpl();
+
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ virtual bool FaceSize(const unsigned int size,
+ const unsigned int res);
+
+ private:
+ /**
+ * Create an FTBufferGlyph object for the base class.
+ */
+ FTGlyph* MakeGlyphImpl(FT_GlyphSlot ftGlyph);
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
+
+ /* Pixel buffer */
+ FTBuffer *buffer;
+
+ static const int BUFFER_CACHE_SIZE = 16;
+ /* Texture IDs */
+ GLuint idCache[BUFFER_CACHE_SIZE];
+ void *stringCache[BUFFER_CACHE_SIZE];
+ FTBBox bboxCache[BUFFER_CACHE_SIZE];
+ FTPoint advanceCache[BUFFER_CACHE_SIZE];
+ int lastString;
+};
+
+#endif // __FTBufferFontImpl__
+
diff --git a/src/ftgl/FTFont/FTExtrudeFont.cpp b/src/ftgl/FTFont/FTExtrudeFont.cpp
new file mode 100644
index 0000000..9e8eb72
--- /dev/null
+++ b/src/ftgl/FTFont/FTExtrudeFont.cpp
@@ -0,0 +1,89 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTExtrudeFontImpl.h"
+
+
+//
+// FTExtrudeFont
+//
+
+
+FTExtrudeFont::FTExtrudeFont(char const *fontFilePath) :
+ FTFont(new FTExtrudeFontImpl(this, fontFilePath))
+{}
+
+
+FTExtrudeFont::FTExtrudeFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTExtrudeFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTExtrudeFont::~FTExtrudeFont()
+{}
+
+
+FTGlyph* FTExtrudeFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ FTExtrudeFontImpl *myimpl = dynamic_cast<FTExtrudeFontImpl *>(impl);
+ if(!myimpl)
+ {
+ return NULL;
+ }
+
+ return new FTExtrudeGlyph(ftGlyph, myimpl->depth, myimpl->front,
+ myimpl->back, myimpl->useDisplayLists);
+}
+
+
+//
+// FTExtrudeFontImpl
+//
+
+
+FTExtrudeFontImpl::FTExtrudeFontImpl(FTFont *ftFont, const char* fontFilePath)
+: FTFontImpl(ftFont, fontFilePath),
+ depth(0.0f), front(0.0f), back(0.0f)
+{
+ load_flags = FT_LOAD_NO_HINTING;
+}
+
+
+FTExtrudeFontImpl::FTExtrudeFontImpl(FTFont *ftFont,
+ const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+: FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+ depth(0.0f), front(0.0f), back(0.0f)
+{
+ load_flags = FT_LOAD_NO_HINTING;
+}
+
diff --git a/src/ftgl/FTFont/FTExtrudeFontImpl.h b/src/ftgl/FTFont/FTExtrudeFontImpl.h
new file mode 100644
index 0000000..c2ddf27
--- /dev/null
+++ b/src/ftgl/FTFont/FTExtrudeFontImpl.h
@@ -0,0 +1,81 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTExtrudeFontImpl__
+#define __FTExtrudeFontImpl__
+
+#include "FTFontImpl.h"
+
+class FTGlyph;
+
+class FTExtrudeFontImpl : public FTFontImpl
+{
+ friend class FTExtrudeFont;
+
+ protected:
+ FTExtrudeFontImpl(FTFont *ftFont, const char* fontFilePath);
+
+ FTExtrudeFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Set the extrusion distance for the font.
+ *
+ * @param d The extrusion distance.
+ */
+ virtual void Depth(float d) { depth = d; }
+
+ /**
+ * Set the outset distance for the font. Only implemented by
+ * FTOutlineFont, FTPolygonFont and FTExtrudeFont
+ *
+ * @param o The outset distance.
+ */
+ virtual void Outset(float o) { front = back = o; }
+
+ /**
+ * Set the outset distance for the font. Only implemented by
+ * FTExtrudeFont
+ *
+ * @param f The front outset distance.
+ * @param b The back outset distance.
+ */
+ virtual void Outset(float f, float b) { front = f; back = b; }
+
+ private:
+ /**
+ * The extrusion distance for the font.
+ */
+ float depth;
+
+ /**
+ * The outset distance (front and back) for the font.
+ */
+ float front, back;
+};
+
+#endif // __FTExtrudeFontImpl__
+
diff --git a/src/ftgl/FTFont/FTFont.cpp b/src/ftgl/FTFont/FTFont.cpp
new file mode 100644
index 0000000..a7206fb
--- /dev/null
+++ b/src/ftgl/FTFont/FTFont.cpp
@@ -0,0 +1,552 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTInternals.h"
+#include "FTUnicode.h"
+
+#include "FTFontImpl.h"
+
+#include "FTBitmapFontImpl.h"
+#include "FTExtrudeFontImpl.h"
+#include "FTOutlineFontImpl.h"
+#include "FTPixmapFontImpl.h"
+#include "FTPolygonFontImpl.h"
+#include "FTTextureFontImpl.h"
+
+#include "FTGlyphContainer.h"
+#include "FTFace.h"
+
+
+//
+// FTFont
+//
+
+
+FTFont::FTFont(char const *fontFilePath)
+{
+ impl = new FTFontImpl(this, fontFilePath);
+}
+
+
+FTFont::FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+{
+ impl = new FTFontImpl(this, pBufferBytes, bufferSizeInBytes);
+}
+
+
+FTFont::FTFont(FTFontImpl *pImpl)
+{
+ impl = pImpl;
+}
+
+
+FTFont::~FTFont()
+{
+ delete impl;
+}
+
+
+bool FTFont::Attach(const char* fontFilePath)
+{
+ return impl->Attach(fontFilePath);
+}
+
+
+bool FTFont::Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+{
+ return impl->Attach(pBufferBytes, bufferSizeInBytes);
+}
+
+
+bool FTFont::FaceSize(const unsigned int size, const unsigned int res)
+{
+ return impl->FaceSize(size, res);
+}
+
+
+unsigned int FTFont::FaceSize() const
+{
+ return impl->FaceSize();
+}
+
+
+void FTFont::Depth(float depth)
+{
+ return impl->Depth(depth);
+}
+
+
+void FTFont::Outset(float outset)
+{
+ return impl->Outset(outset);
+}
+
+
+void FTFont::Outset(float front, float back)
+{
+ return impl->Outset(front, back);
+}
+
+
+void FTFont::GlyphLoadFlags(FT_Int flags)
+{
+ return impl->GlyphLoadFlags(flags);
+}
+
+
+bool FTFont::CharMap(FT_Encoding encoding)
+{
+ return impl->CharMap(encoding);
+}
+
+
+unsigned int FTFont::CharMapCount() const
+{
+ return impl->CharMapCount();
+}
+
+
+FT_Encoding* FTFont::CharMapList()
+{
+ return impl->CharMapList();
+}
+
+
+void FTFont::UseDisplayList(bool useList)
+{
+ return impl->UseDisplayList(useList);
+}
+
+
+float FTFont::Ascender() const
+{
+ return impl->Ascender();
+}
+
+
+float FTFont::Descender() const
+{
+ return impl->Descender();
+}
+
+
+float FTFont::LineHeight() const
+{
+ return impl->LineHeight();
+}
+
+
+FTPoint FTFont::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
+{
+ return impl->Render(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTFont::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
+{
+ return impl->Render(string, len, position, spacing, renderMode);
+}
+
+
+float FTFont::Advance(const char * string, const int len, FTPoint spacing)
+{
+ return impl->Advance(string, len, spacing);
+}
+
+
+float FTFont::Advance(const wchar_t * string, const int len, FTPoint spacing)
+{
+ return impl->Advance(string, len, spacing);
+}
+
+
+FTBBox FTFont::BBox(const char *string, const int len,
+ FTPoint position, FTPoint spacing)
+{
+ return impl->BBox(string, len, position, spacing);
+}
+
+
+FTBBox FTFont::BBox(const wchar_t *string, const int len,
+ FTPoint position, FTPoint spacing)
+{
+ return impl->BBox(string, len, position, spacing);
+}
+
+
+FT_Error FTFont::Error() const
+{
+ return impl->err;
+}
+
+
+//
+// FTFontImpl
+//
+
+
+FTFontImpl::FTFontImpl(FTFont *ftFont, char const *fontFilePath) :
+ face(fontFilePath),
+ useDisplayLists(true),
+ load_flags(FT_LOAD_DEFAULT),
+ intf(ftFont),
+ glyphList(0)
+{
+ err = face.Error();
+ if(err == 0)
+ {
+ glyphList = new FTGlyphContainer(&face);
+ }
+}
+
+
+FTFontImpl::FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ face(pBufferBytes, bufferSizeInBytes),
+ useDisplayLists(true),
+ load_flags(FT_LOAD_DEFAULT),
+ intf(ftFont),
+ glyphList(0)
+{
+ err = face.Error();
+ if(err == 0)
+ {
+ glyphList = new FTGlyphContainer(&face);
+ }
+}
+
+
+FTFontImpl::~FTFontImpl()
+{
+ if(glyphList)
+ {
+ delete glyphList;
+ }
+}
+
+
+bool FTFontImpl::Attach(const char* fontFilePath)
+{
+ if(!face.Attach(fontFilePath))
+ {
+ err = face.Error();
+ return false;
+ }
+
+ err = 0;
+ return true;
+}
+
+
+bool FTFontImpl::Attach(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+{
+ if(!face.Attach(pBufferBytes, bufferSizeInBytes))
+ {
+ err = face.Error();
+ return false;
+ }
+
+ err = 0;
+ return true;
+}
+
+
+bool FTFontImpl::FaceSize(const unsigned int size, const unsigned int res)
+{
+ if(glyphList != NULL)
+ {
+ delete glyphList;
+ glyphList = NULL;
+ }
+
+ charSize = face.Size(size, res);
+ err = face.Error();
+
+ if(err != 0)
+ {
+ return false;
+ }
+
+ glyphList = new FTGlyphContainer(&face);
+ return true;
+}
+
+
+unsigned int FTFontImpl::FaceSize() const
+{
+ return charSize.CharSize();
+}
+
+
+void FTFontImpl::Depth(float depth)
+{
+ ;
+}
+
+
+void FTFontImpl::Outset(float outset)
+{
+ ;
+}
+
+
+void FTFontImpl::Outset(float front, float back)
+{
+ ;
+}
+
+
+void FTFontImpl::GlyphLoadFlags(FT_Int flags)
+{
+ load_flags = flags;
+}
+
+
+bool FTFontImpl::CharMap(FT_Encoding encoding)
+{
+ bool result = glyphList->CharMap(encoding);
+ err = glyphList->Error();
+ return result;
+}
+
+
+unsigned int FTFontImpl::CharMapCount() const
+{
+ return face.CharMapCount();
+}
+
+
+FT_Encoding* FTFontImpl::CharMapList()
+{
+ return face.CharMapList();
+}
+
+
+void FTFontImpl::UseDisplayList(bool useList)
+{
+ useDisplayLists = useList;
+}
+
+
+float FTFontImpl::Ascender() const
+{
+ return charSize.Ascender();
+}
+
+
+float FTFontImpl::Descender() const
+{
+ return charSize.Descender();
+}
+
+
+float FTFontImpl::LineHeight() const
+{
+ return charSize.Height();
+}
+
+
+template <typename T>
+inline FTBBox FTFontImpl::BBoxI(const T* string, const int len,
+ FTPoint position, FTPoint spacing)
+{
+ FTBBox totalBBox;
+
+ /* Only compute the bounds if string is non-empty. */
+ if(string && ('\0' != string[0]))
+ {
+ // for multibyte - we can't rely on sizeof(T) == character
+ FTUnicodeStringItr<T> ustr(string);
+ unsigned int thisChar = *ustr++;
+ unsigned int nextChar = *ustr;
+
+ if(CheckGlyph(thisChar))
+ {
+ totalBBox = glyphList->BBox(thisChar);
+ totalBBox += position;
+
+ position += FTPoint(glyphList->Advance(thisChar, nextChar), 0.0);
+ }
+
+ /* Expand totalBox by each glyph in string */
+ for(int i = 1; (len < 0 && *ustr) || (len >= 0 && i < len); i++)
+ {
+ thisChar = *ustr++;
+ nextChar = *ustr;
+
+ if(CheckGlyph(thisChar))
+ {
+ position += spacing;
+
+ FTBBox tempBBox = glyphList->BBox(thisChar);
+ tempBBox += position;
+ totalBBox |= tempBBox;
+
+ position += FTPoint(glyphList->Advance(thisChar, nextChar),
+ 0.0);
+ }
+ }
+ }
+
+ return totalBBox;
+}
+
+
+FTBBox FTFontImpl::BBox(const char *string, const int len,
+ FTPoint position, FTPoint spacing)
+{
+ /* The chars need to be unsigned because they are cast to int later */
+ return BBoxI((const unsigned char *)string, len, position, spacing);
+}
+
+
+FTBBox FTFontImpl::BBox(const wchar_t *string, const int len,
+ FTPoint position, FTPoint spacing)
+{
+ return BBoxI(string, len, position, spacing);
+}
+
+
+template <typename T>
+inline float FTFontImpl::AdvanceI(const T* string, const int len,
+ FTPoint spacing)
+{
+ float advance = 0.0f;
+ FTUnicodeStringItr<T> ustr(string);
+
+ for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++)
+ {
+ unsigned int thisChar = *ustr++;
+ unsigned int nextChar = *ustr;
+
+ if(CheckGlyph(thisChar))
+ {
+ advance += glyphList->Advance(thisChar, nextChar);
+ }
+
+ if(nextChar)
+ {
+ advance += spacing.Xf();
+ }
+ }
+
+ return advance;
+}
+
+
+float FTFontImpl::Advance(const char* string, const int len, FTPoint spacing)
+{
+ /* The chars need to be unsigned because they are cast to int later */
+ return AdvanceI((const unsigned char *)string, len, spacing);
+}
+
+
+float FTFontImpl::Advance(const wchar_t* string, const int len, FTPoint spacing)
+{
+ return AdvanceI(string, len, spacing);
+}
+
+
+template <typename T>
+inline FTPoint FTFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ // for multibyte - we can't rely on sizeof(T) == character
+ FTUnicodeStringItr<T> ustr(string);
+
+ for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++)
+ {
+ unsigned int thisChar = *ustr++;
+ unsigned int nextChar = *ustr;
+
+ if(CheckGlyph(thisChar))
+ {
+ position += glyphList->Render(thisChar, nextChar,
+ position, renderMode);
+ }
+
+ if(nextChar)
+ {
+ position += spacing;
+ }
+ }
+
+ return position;
+}
+
+
+FTPoint FTFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
+{
+ return RenderI((const unsigned char *)string,
+ len, position, spacing, renderMode);
+}
+
+
+FTPoint FTFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing, int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+bool FTFontImpl::CheckGlyph(const unsigned int characterCode)
+{
+ if(glyphList->Glyph(characterCode))
+ {
+ return true;
+ }
+
+ unsigned int glyphIndex = glyphList->FontIndex(characterCode);
+ FT_GlyphSlot ftSlot = face.Glyph(glyphIndex, load_flags);
+ if(!ftSlot)
+ {
+ err = face.Error();
+ return false;
+ }
+
+ FTGlyph* tempGlyph = intf->MakeGlyph(ftSlot);
+ if(!tempGlyph)
+ {
+ if(0 == err)
+ {
+ err = 0x13;
+ }
+
+ return false;
+ }
+
+ glyphList->Add(tempGlyph, characterCode);
+
+ return true;
+}
+
diff --git a/src/ftgl/FTFont/FTFontGlue.cpp b/src/ftgl/FTFont/FTFontGlue.cpp
new file mode 100644
index 0000000..b23e787
--- /dev/null
+++ b/src/ftgl/FTFont/FTFontGlue.cpp
@@ -0,0 +1,227 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTInternals.h"
+
+static const FTPoint static_ftpoint;
+static const FTBBox static_ftbbox;
+
+FTGL_BEGIN_C_DECLS
+
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLfont* cname cargs \
+ { \
+ cxxname *f = new cxxname cxxarg; \
+ if(f->Error()) \
+ { \
+ delete f; \
+ return NULL; \
+ } \
+ FTGLfont *ftgl = (FTGLfont *)malloc(sizeof(FTGLfont)); \
+ ftgl->ptr = f; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
+ }
+
+// FTBitmapFont::FTBitmapFont();
+C_TOR(ftglCreateBitmapFont, (const char *fontname),
+ FTBitmapFont, (fontname), FONT_BITMAP);
+
+// FTBufferFont::FTBufferFont();
+C_TOR(ftglCreateBufferFont, (const char *fontname),
+ FTBufferFont, (fontname), FONT_BUFFER);
+
+// FTExtrudeFont::FTExtrudeFont();
+C_TOR(ftglCreateExtrudeFont, (const char *fontname),
+ FTExtrudeFont, (fontname), FONT_EXTRUDE);
+
+// FTOutlineFont::FTOutlineFont();
+C_TOR(ftglCreateOutlineFont, (const char *fontname),
+ FTOutlineFont, (fontname), FONT_OUTLINE);
+
+// FTPixmapFont::FTPixmapFont();
+C_TOR(ftglCreatePixmapFont, (const char *fontname),
+ FTPixmapFont, (fontname), FONT_PIXMAP);
+
+// FTPolygonFont::FTPolygonFont();
+C_TOR(ftglCreatePolygonFont, (const char *fontname),
+ FTPolygonFont, (fontname), FONT_POLYGON);
+
+// FTTextureFont::FTTextureFont();
+C_TOR(ftglCreateTextureFont, (const char *fontname),
+ FTTextureFont, (fontname), FONT_TEXTURE);
+
+// FTCustomFont::FTCustomFont();
+class FTCustomFont : public FTFont
+{
+public:
+ FTCustomFont(char const *fontFilePath, void *p,
+ FTGLglyph * (*makeglyph) (FT_GlyphSlot, void *))
+ : FTFont(fontFilePath),
+ data(p),
+ makeglyphCallback(makeglyph)
+ {}
+
+ ~FTCustomFont()
+ {}
+
+ FTGlyph* MakeGlyph(FT_GlyphSlot slot)
+ {
+ FTGLglyph *g = makeglyphCallback(slot, data);
+ FTGlyph *glyph = g->ptr;
+ // XXX: we no longer need g, and no one will free it for us. Not
+ // very elegant, and we need to make sure no one else will try to
+ // use it.
+ free(g);
+ return glyph;
+ }
+
+private:
+ void *data;
+ FTGLglyph *(*makeglyphCallback) (FT_GlyphSlot, void *);
+};
+
+C_TOR(ftglCreateCustomFont, (char const *fontFilePath, void *data,
+ FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *)),
+ FTCustomFont, (fontFilePath, data, makeglyphCallback), FONT_CUSTOM);
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!f || !f->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ return f->ptr->cxxname cxxarg; \
+ }
+
+// FTFont::~FTFont();
+void ftglDestroyFont(FTGLfont *f)
+{
+ if(!f || !f->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return;
+ }
+ delete f->ptr;
+ free(f);
+}
+
+// bool FTFont::Attach(const char* fontFilePath);
+C_FUN(int, ftglAttachFile, (FTGLfont *f, const char* path),
+ return 0, Attach, (path));
+
+// bool FTFont::Attach(const unsigned char *pBufferBytes,
+// size_t bufferSizeInBytes);
+C_FUN(int, ftglAttachData, (FTGLfont *f, const unsigned char *p, size_t s),
+ return 0, Attach, (p, s));
+
+// void FTFont::GlyphLoadFlags(FT_Int flags);
+C_FUN(void, ftglSetFontGlyphLoadFlags, (FTGLfont *f, FT_Int flags),
+ return, GlyphLoadFlags, (flags));
+
+// bool FTFont::CharMap(FT_Encoding encoding);
+C_FUN(int, ftglSetFontCharMap, (FTGLfont *f, FT_Encoding enc),
+ return 0, CharMap, (enc));
+
+// unsigned int FTFont::CharMapCount();
+C_FUN(unsigned int, ftglGetFontCharMapCount, (FTGLfont *f),
+ return 0, CharMapCount, ());
+
+// FT_Encoding* FTFont::CharMapList();
+C_FUN(FT_Encoding *, ftglGetFontCharMapList, (FTGLfont* f),
+ return NULL, CharMapList, ());
+
+// virtual bool FTFont::FaceSize(const unsigned int size,
+// const unsigned int res = 72);
+C_FUN(int, ftglSetFontFaceSize, (FTGLfont *f, unsigned int s, unsigned int r),
+ return 0, FaceSize, (s, r > 0 ? r : 72));
+
+// unsigned int FTFont::FaceSize() const;
+// XXX: need to call FaceSize() as FTFont::FaceSize() because of FTGLTexture
+C_FUN(unsigned int, ftglGetFontFaceSize, (FTGLfont *f),
+ return 0, FTFont::FaceSize, ());
+
+// virtual void FTFont::Depth(float depth);
+C_FUN(void, ftglSetFontDepth, (FTGLfont *f, float d), return, Depth, (d));
+
+// virtual void FTFont::Outset(float front, float back);
+C_FUN(void, ftglSetFontOutset, (FTGLfont *f, float front, float back),
+ return, FTFont::Outset, (front, back));
+
+// void FTFont::UseDisplayList(bool useList);
+C_FUN(void, ftglSetFontDisplayList, (FTGLfont *f, int l),
+ return, UseDisplayList, (l != 0));
+
+// float FTFont::Ascender() const;
+C_FUN(float, ftglGetFontAscender, (FTGLfont *f), return 0.f, Ascender, ());
+
+// float FTFont::Descender() const;
+C_FUN(float, ftglGetFontDescender, (FTGLfont *f), return 0.f, Descender, ());
+
+// float FTFont::LineHeight() const;
+C_FUN(float, ftglGetFontLineHeight, (FTGLfont *f), return 0.f, LineHeight, ());
+
+// void FTFont::BBox(const char* string, float& llx, float& lly, float& llz,
+// float& urx, float& ury, float& urz);
+extern "C++" {
+C_FUN(static FTBBox, _ftglGetFontBBox, (FTGLfont *f, char const *s, int len),
+ return static_ftbbox, BBox, (s, len));
+}
+
+void ftglGetFontBBox(FTGLfont *f, const char* s, int len, float c[6])
+{
+ FTBBox ret = _ftglGetFontBBox(f, s, len);
+ FTPoint lower = ret.Lower(), upper = ret.Upper();
+ c[0] = lower.Xf(); c[1] = lower.Yf(); c[2] = lower.Zf();
+ c[3] = upper.Xf(); c[4] = upper.Yf(); c[5] = upper.Zf();
+}
+
+// float FTFont::Advance(const char* string);
+C_FUN(float, ftglGetFontAdvance, (FTGLfont *f, char const *s),
+ return 0.0, Advance, (s));
+
+// virtual void Render(const char* string, int renderMode);
+extern "C++" {
+C_FUN(static FTPoint, _ftglRenderFont, (FTGLfont *f, char const *s, int len,
+ FTPoint pos, FTPoint spacing, int mode),
+ return static_ftpoint, Render, (s, len, pos, spacing, mode));
+}
+
+void ftglRenderFont(FTGLfont *f, const char *s, int mode)
+{
+ _ftglRenderFont(f, s, -1, FTPoint(), FTPoint(), mode);
+}
+
+// FT_Error FTFont::Error() const;
+C_FUN(FT_Error, ftglGetFontError, (FTGLfont *f), return -1, Error, ());
+
+FTGL_END_C_DECLS
+
diff --git a/src/ftgl/FTFont/FTFontImpl.h b/src/ftgl/FTFont/FTFontImpl.h
new file mode 100644
index 0000000..36c3bf8
--- /dev/null
+++ b/src/ftgl/FTFont/FTFontImpl.h
@@ -0,0 +1,162 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTFontImpl__
+#define __FTFontImpl__
+
+#include "FTGL/ftgl.h"
+
+#include "FTFace.h"
+
+class FTGlyphContainer;
+class FTGlyph;
+
+class FTFontImpl
+{
+ friend class FTFont;
+
+ protected:
+ FTFontImpl(FTFont *ftFont, char const *fontFilePath);
+
+ FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ virtual ~FTFontImpl();
+
+ virtual bool Attach(const char* fontFilePath);
+
+ virtual bool Attach(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ virtual void GlyphLoadFlags(FT_Int flags);
+
+ virtual bool CharMap(FT_Encoding encoding);
+
+ virtual unsigned int CharMapCount() const;
+
+ virtual FT_Encoding* CharMapList();
+
+ virtual void UseDisplayList(bool useList);
+
+ virtual float Ascender() const;
+
+ virtual float Descender() const;
+
+ virtual float LineHeight() const;
+
+ virtual bool FaceSize(const unsigned int size,
+ const unsigned int res);
+
+ virtual unsigned int FaceSize() const;
+
+ virtual void Depth(float depth);
+
+ virtual void Outset(float outset);
+
+ virtual void Outset(float front, float back);
+
+ virtual FTBBox BBox(const char *s, const int len, FTPoint, FTPoint);
+
+ virtual FTBBox BBox(const wchar_t *s, const int len, FTPoint, FTPoint);
+
+ virtual float Advance(const char *s, const int len, FTPoint);
+
+ virtual float Advance(const wchar_t *s, const int len, FTPoint);
+
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint, FTPoint, int);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint, FTPoint, int);
+
+ /**
+ * Current face object
+ */
+ FTFace face;
+
+ /**
+ * Current size object
+ */
+ FTSize charSize;
+
+ /**
+ * Flag to enable or disable the use of Display Lists inside FTGL
+ * <code>true</code> turns ON display lists.
+ * <code>false</code> turns OFF display lists.
+ */
+ bool useDisplayLists;
+
+ /**
+ * The default glyph loading flags.
+ */
+ FT_Int load_flags;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+
+ private:
+ /**
+ * A link back to the interface of which we are the implementation.
+ */
+ FTFont *intf;
+
+ /**
+ * Check that the glyph at <code>chr</code> exist. If not load it.
+ *
+ * @param chr character index
+ * @return <code>true</code> if the glyph can be created.
+ */
+ bool CheckGlyph(const unsigned int chr);
+
+ /**
+ * An object that holds a list of glyphs
+ */
+ FTGlyphContainer* glyphList;
+
+ /**
+ * Current pen or cursor position;
+ */
+ FTPoint pen;
+
+ /* Internal generic BBox() implementation */
+ template <typename T>
+ inline FTBBox BBoxI(const T *s, const int len,
+ FTPoint position, FTPoint spacing);
+
+ /* Internal generic Advance() implementation */
+ template <typename T>
+ inline float AdvanceI(const T *s, const int len, FTPoint spacing);
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
+};
+
+#endif // __FTFontImpl__
+
diff --git a/src/ftgl/FTFont/FTOutlineFont.cpp b/src/ftgl/FTFont/FTOutlineFont.cpp
new file mode 100644
index 0000000..9ebc9a0
--- /dev/null
+++ b/src/ftgl/FTFont/FTOutlineFont.cpp
@@ -0,0 +1,129 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTOutlineFontImpl.h"
+
+
+//
+// FTOutlineFont
+//
+
+
+FTOutlineFont::FTOutlineFont(char const *fontFilePath) :
+ FTFont(new FTOutlineFontImpl(this, fontFilePath))
+{}
+
+
+FTOutlineFont::FTOutlineFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTOutlineFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTOutlineFont::~FTOutlineFont()
+{}
+
+
+FTGlyph* FTOutlineFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ FTOutlineFontImpl *myimpl = dynamic_cast<FTOutlineFontImpl *>(impl);
+ if(!myimpl)
+ {
+ return NULL;
+ }
+
+ return new FTOutlineGlyph(ftGlyph, myimpl->outset,
+ myimpl->useDisplayLists);
+}
+
+
+//
+// FTOutlineFontImpl
+//
+
+
+FTOutlineFontImpl::FTOutlineFontImpl(FTFont *ftFont, const char* fontFilePath)
+: FTFontImpl(ftFont, fontFilePath),
+ outset(0.0f)
+{
+ load_flags = FT_LOAD_NO_HINTING;
+}
+
+
+FTOutlineFontImpl::FTOutlineFontImpl(FTFont *ftFont,
+ const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+: FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+ outset(0.0f)
+{
+ load_flags = FT_LOAD_NO_HINTING;
+}
+
+
+template <typename T>
+inline FTPoint FTOutlineFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ // Protect GL_TEXTURE_2D, glHint(), GL_LINE_SMOOTH and blending functions
+ 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
+
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
+
+ glPopAttrib();
+
+ return tmp;
+}
+
+
+FTPoint FTOutlineFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTOutlineFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
diff --git a/src/ftgl/FTFont/FTOutlineFontImpl.h b/src/ftgl/FTFont/FTOutlineFontImpl.h
new file mode 100644
index 0000000..38b4d26
--- /dev/null
+++ b/src/ftgl/FTFont/FTOutlineFontImpl.h
@@ -0,0 +1,73 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTOutlineFontImpl__
+#define __FTOutlineFontImpl__
+
+#include "FTFontImpl.h"
+
+class FTGlyph;
+
+class FTOutlineFontImpl : public FTFontImpl
+{
+ friend class FTOutlineFont;
+
+ protected:
+ FTOutlineFontImpl(FTFont *ftFont, const char* fontFilePath);
+
+ FTOutlineFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Set the outset distance for the font. Only implemented by
+ * FTOutlineFont, FTPolygonFont and FTExtrudeFont
+ *
+ * @param outset The outset distance.
+ */
+ virtual void Outset(float o) { outset = o; }
+
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ private:
+ /**
+ * The outset distance for the font.
+ */
+ float outset;
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
+};
+
+#endif // __FTOutlineFontImpl__
+
diff --git a/src/ftgl/FTFont/FTPixmapFont.cpp b/src/ftgl/FTFont/FTPixmapFont.cpp
new file mode 100644
index 0000000..5638ac8
--- /dev/null
+++ b/src/ftgl/FTFont/FTPixmapFont.cpp
@@ -0,0 +1,131 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTPixmapFontImpl.h"
+
+
+//
+// FTPixmapFont
+//
+
+
+FTPixmapFont::FTPixmapFont(char const *fontFilePath) :
+ FTFont(new FTPixmapFontImpl(this, fontFilePath))
+{}
+
+
+FTPixmapFont::FTPixmapFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTPixmapFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTPixmapFont::~FTPixmapFont()
+{}
+
+
+FTGlyph* FTPixmapFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ return new FTPixmapGlyph(ftGlyph);
+}
+
+
+//
+// FTPixmapFontImpl
+//
+
+
+FTPixmapFontImpl::FTPixmapFontImpl(FTFont *ftFont, const char* fontFilePath)
+: FTFontImpl(ftFont, fontFilePath)
+{
+ load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+}
+
+
+FTPixmapFontImpl::FTPixmapFontImpl(FTFont *ftFont,
+ const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+: FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes)
+{
+ load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+}
+
+
+template <typename T>
+inline FTPoint FTPixmapFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ // Protect GL_TEXTURE_2D and GL_BLEND, glPixelTransferf(), and blending
+ // functions.
+ glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
+
+ // Protect glPixelStorei() calls (made by FTPixmapGlyphImpl::RenderImpl).
+ 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]);
+
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
+
+ glPopClientAttrib();
+ glPopAttrib();
+
+ return tmp;
+}
+
+
+FTPoint FTPixmapFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTPixmapFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
diff --git a/src/ftgl/FTFont/FTPixmapFontImpl.h b/src/ftgl/FTFont/FTPixmapFontImpl.h
new file mode 100644
index 0000000..321f4a6
--- /dev/null
+++ b/src/ftgl/FTFont/FTPixmapFontImpl.h
@@ -0,0 +1,60 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTPixmapFontImpl__
+#define __FTPixmapFontImpl__
+
+#include "FTFontImpl.h"
+
+class FTGlyph;
+
+class FTPixmapFontImpl : public FTFontImpl
+{
+ friend class FTPixmapFont;
+
+ protected:
+ FTPixmapFontImpl(FTFont *ftFont, const char* fontFilePath);
+
+ FTPixmapFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ private:
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
+};
+
+#endif // __FTPixmapFontImpl__
+
diff --git a/src/ftgl/FTFont/FTPolygonFont.cpp b/src/ftgl/FTFont/FTPolygonFont.cpp
new file mode 100644
index 0000000..83c3ad1
--- /dev/null
+++ b/src/ftgl/FTFont/FTPolygonFont.cpp
@@ -0,0 +1,89 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTPolygonFontImpl.h"
+
+
+//
+// FTPolygonFont
+//
+
+
+FTPolygonFont::FTPolygonFont(char const *fontFilePath) :
+ FTFont(new FTPolygonFontImpl(this, fontFilePath))
+{}
+
+
+FTPolygonFont::FTPolygonFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTPolygonFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTPolygonFont::~FTPolygonFont()
+{}
+
+
+FTGlyph* FTPolygonFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ FTPolygonFontImpl *myimpl = dynamic_cast<FTPolygonFontImpl *>(impl);
+ if(!myimpl)
+ {
+ return NULL;
+ }
+
+ return new FTPolygonGlyph(ftGlyph, myimpl->outset,
+ myimpl->useDisplayLists);
+}
+
+
+//
+// FTPolygonFontImpl
+//
+
+
+FTPolygonFontImpl::FTPolygonFontImpl(FTFont *ftFont, const char* fontFilePath)
+: FTFontImpl(ftFont, fontFilePath),
+ outset(0.0f)
+{
+ load_flags = FT_LOAD_NO_HINTING;
+}
+
+
+FTPolygonFontImpl::FTPolygonFontImpl(FTFont *ftFont,
+ const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+: FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+ outset(0.0f)
+{
+ load_flags = FT_LOAD_NO_HINTING;
+}
+
diff --git a/src/ftgl/FTFont/FTPolygonFontImpl.h b/src/ftgl/FTFont/FTPolygonFontImpl.h
new file mode 100644
index 0000000..47b35a6
--- /dev/null
+++ b/src/ftgl/FTFont/FTPolygonFontImpl.h
@@ -0,0 +1,60 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTPolygonFontImpl__
+#define __FTPolygonFontImpl__
+
+#include "FTFontImpl.h"
+
+class FTGlyph;
+
+class FTPolygonFontImpl : public FTFontImpl
+{
+ friend class FTPolygonFont;
+
+ protected:
+ FTPolygonFontImpl(FTFont *ftFont, const char* fontFilePath);
+
+ FTPolygonFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Set the outset distance for the font. Only implemented by
+ * FTOutlineFont, FTPolygonFont and FTExtrudeFont
+ *
+ * @param depth The outset distance.
+ */
+ virtual void Outset(float o) { outset = o; }
+
+ private:
+ /**
+ * The outset distance (front and back) for the font.
+ */
+ float outset;
+};
+
+#endif // __FTPolygonFontImpl__
+
diff --git a/src/ftgl/FTFont/FTTextureFont.cpp b/src/ftgl/FTFont/FTTextureFont.cpp
new file mode 100644
index 0000000..4e385ea
--- /dev/null
+++ b/src/ftgl/FTFont/FTTextureFont.cpp
@@ -0,0 +1,267 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <cassert>
+#include <string> // For memset
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+
+#include "../FTGlyph/FTTextureGlyphImpl.h"
+#include "./FTTextureFontImpl.h"
+
+
+//
+// FTTextureFont
+//
+
+
+FTTextureFont::FTTextureFont(char const *fontFilePath) :
+ FTFont(new FTTextureFontImpl(this, fontFilePath))
+{}
+
+
+FTTextureFont::FTTextureFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes) :
+ FTFont(new FTTextureFontImpl(this, pBufferBytes, bufferSizeInBytes))
+{}
+
+
+FTTextureFont::~FTTextureFont()
+{}
+
+
+FTGlyph* FTTextureFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+ FTTextureFontImpl *myimpl = dynamic_cast<FTTextureFontImpl *>(impl);
+ if(!myimpl)
+ {
+ return NULL;
+ }
+
+ return myimpl->MakeGlyphImpl(ftGlyph);
+}
+
+
+//
+// FTTextureFontImpl
+//
+
+
+static inline GLuint NextPowerOf2(GLuint in)
+{
+ in -= 1;
+
+ in |= in >> 16;
+ in |= in >> 8;
+ in |= in >> 4;
+ in |= in >> 2;
+ in |= in >> 1;
+
+ return in + 1;
+}
+
+
+FTTextureFontImpl::FTTextureFontImpl(FTFont *ftFont, const char* fontFilePath)
+: FTFontImpl(ftFont, fontFilePath),
+ maximumGLTextureSize(0),
+ textureWidth(0),
+ textureHeight(0),
+ glyphHeight(0),
+ glyphWidth(0),
+ padding(3),
+ xOffset(0),
+ yOffset(0)
+{
+ load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+ remGlyphs = numGlyphs = face.GlyphCount();
+}
+
+
+FTTextureFontImpl::FTTextureFontImpl(FTFont *ftFont,
+ const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes)
+: FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+ maximumGLTextureSize(0),
+ textureWidth(0),
+ textureHeight(0),
+ glyphHeight(0),
+ glyphWidth(0),
+ padding(3),
+ xOffset(0),
+ yOffset(0)
+{
+ load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+ remGlyphs = numGlyphs = face.GlyphCount();
+}
+
+
+FTTextureFontImpl::~FTTextureFontImpl()
+{
+ if(textureIDList.size())
+ {
+ glDeleteTextures((GLsizei)textureIDList.size(),
+ (const GLuint*)&textureIDList[0]);
+ }
+}
+
+
+FTGlyph* FTTextureFontImpl::MakeGlyphImpl(FT_GlyphSlot ftGlyph)
+{
+ glyphHeight = static_cast<int>(charSize.Height() + 0.5);
+ glyphWidth = static_cast<int>(charSize.Width() + 0.5);
+
+ if(glyphHeight < 1) glyphHeight = 1;
+ if(glyphWidth < 1) glyphWidth = 1;
+
+ if(textureIDList.empty())
+ {
+ textureIDList.push_back(CreateTexture());
+ xOffset = yOffset = padding;
+ }
+
+ if(xOffset > (textureWidth - glyphWidth))
+ {
+ xOffset = padding;
+ yOffset += glyphHeight;
+
+ if(yOffset > (textureHeight - glyphHeight))
+ {
+ textureIDList.push_back(CreateTexture());
+ yOffset = padding;
+ }
+ }
+
+ FTTextureGlyph* tempGlyph = new FTTextureGlyph(ftGlyph, textureIDList[textureIDList.size() - 1],
+ xOffset, yOffset, textureWidth, textureHeight);
+ xOffset += static_cast<int>(tempGlyph->BBox().Upper().X() - tempGlyph->BBox().Lower().X() + padding + 0.5);
+
+ --remGlyphs;
+
+ return tempGlyph;
+}
+
+
+void FTTextureFontImpl::CalculateTextureSize()
+{
+ if(!maximumGLTextureSize)
+ {
+ maximumGLTextureSize = 1024;
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&maximumGLTextureSize);
+ assert(maximumGLTextureSize); // If you hit this then you have an invalid OpenGL context.
+ }
+
+ textureWidth = NextPowerOf2((remGlyphs * glyphWidth) + (padding * 2));
+ textureWidth = textureWidth > maximumGLTextureSize ? maximumGLTextureSize : textureWidth;
+
+ int h = static_cast<int>((textureWidth - (padding * 2)) / glyphWidth + 0.5);
+
+ textureHeight = NextPowerOf2(((numGlyphs / h) + 1) * glyphHeight);
+ textureHeight = textureHeight > maximumGLTextureSize ? maximumGLTextureSize : textureHeight;
+}
+
+
+GLuint FTTextureFontImpl::CreateTexture()
+{
+ CalculateTextureSize();
+
+ int totalMemory = textureWidth * textureHeight;
+ unsigned char* textureMemory = new unsigned char[totalMemory];
+ memset(textureMemory, 0, totalMemory);
+
+ GLuint textID;
+ glGenTextures(1, (GLuint*)&textID);
+
+ glBindTexture(GL_TEXTURE_2D, textID);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight,
+ 0, GL_ALPHA, GL_UNSIGNED_BYTE, textureMemory);
+
+ delete [] textureMemory;
+
+ return textID;
+}
+
+
+bool FTTextureFontImpl::FaceSize(const unsigned int size, const unsigned int res)
+{
+ if(!textureIDList.empty())
+ {
+ glDeleteTextures((GLsizei)textureIDList.size(), (const GLuint*)&textureIDList[0]);
+ textureIDList.clear();
+ remGlyphs = numGlyphs = face.GlyphCount();
+ }
+
+ return FTFontImpl::FaceSize(size, res);
+}
+
+
+template <typename T>
+inline FTPoint FTTextureFontImpl::RenderI(const T* string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ // Protect GL_TEXTURE_2D, GL_BLEND and blending functions
+ glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
+
+ glEnable(GL_TEXTURE_2D);
+
+ FTTextureGlyphImpl::ResetActiveTexture();
+
+ FTPoint tmp = FTFontImpl::Render(string, len,
+ position, spacing, renderMode);
+
+ glPopAttrib();
+
+ return tmp;
+}
+
+
+FTPoint FTTextureFontImpl::Render(const char * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
+
+FTPoint FTTextureFontImpl::Render(const wchar_t * string, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode)
+{
+ return RenderI(string, len, position, spacing, renderMode);
+}
+
diff --git a/src/ftgl/FTFont/FTTextureFontImpl.h b/src/ftgl/FTFont/FTTextureFontImpl.h
new file mode 100644
index 0000000..c9cf22b
--- /dev/null
+++ b/src/ftgl/FTFont/FTTextureFontImpl.h
@@ -0,0 +1,152 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTTextureFontImpl__
+#define __FTTextureFontImpl__
+
+#include "FTFontImpl.h"
+
+#include "FTVector.h"
+
+class FTTextureGlyph;
+
+class FTTextureFontImpl : public FTFontImpl
+{
+ friend class FTTextureFont;
+
+ protected:
+ FTTextureFontImpl(FTFont *ftFont, const char* fontFilePath);
+
+ FTTextureFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ virtual ~FTTextureFontImpl();
+
+ /**
+ * Set the char size for the current face.
+ *
+ * @param size the face size in points (1/72 inch)
+ * @param res the resolution of the target device.
+ * @return <code>true</code> if size was set correctly
+ */
+ virtual bool FaceSize(const unsigned int size,
+ const unsigned int res = 72);
+
+ virtual FTPoint Render(const char *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ virtual FTPoint Render(const wchar_t *s, const int len,
+ FTPoint position, FTPoint spacing,
+ int renderMode);
+
+ private:
+ /**
+ * Create an FTTextureGlyph object for the base class.
+ */
+ FTGlyph* MakeGlyphImpl(FT_GlyphSlot ftGlyph);
+
+ /**
+ * Get the size of a block of memory required to layout the glyphs
+ *
+ * Calculates a width and height based on the glyph sizes and the
+ * number of glyphs. It over estimates.
+ */
+ inline void CalculateTextureSize();
+
+ /**
+ * Creates a 'blank' OpenGL texture object.
+ *
+ * The format is GL_ALPHA and the params are
+ * GL_TEXTURE_WRAP_S = GL_CLAMP
+ * GL_TEXTURE_WRAP_T = GL_CLAMP
+ * GL_TEXTURE_MAG_FILTER = GL_LINEAR
+ * GL_TEXTURE_MIN_FILTER = GL_LINEAR
+ * Note that mipmapping is NOT used
+ */
+ inline GLuint CreateTexture();
+
+ /**
+ * The maximum texture dimension on this OpenGL implemetation
+ */
+ GLsizei maximumGLTextureSize;
+
+ /**
+ * The minimum texture width required to hold the glyphs
+ */
+ GLsizei textureWidth;
+
+ /**
+ * The minimum texture height required to hold the glyphs
+ */
+ GLsizei textureHeight;
+
+ /**
+ *An array of texture ids
+ */
+ FTVector<GLuint> textureIDList;
+
+ /**
+ * The max height for glyphs in the current font
+ */
+ int glyphHeight;
+
+ /**
+ * The max width for glyphs in the current font
+ */
+ int glyphWidth;
+
+ /**
+ * A value to be added to the height and width to ensure that
+ * glyphs don't overlap in the texture
+ */
+ unsigned int padding;
+
+ /**
+ *
+ */
+ unsigned int numGlyphs;
+
+ /**
+ */
+ unsigned int remGlyphs;
+
+ /**
+ */
+ int xOffset;
+
+ /**
+ */
+ int yOffset;
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline FTPoint RenderI(const T *s, const int len,
+ FTPoint position, FTPoint spacing, int mode);
+};
+
+#endif // __FTTextureFontImpl__
+
diff --git a/src/ftgl/FTGL/FTBBox.h b/src/ftgl/FTGL/FTBBox.h
new file mode 100644
index 0000000..858ff7a
--- /dev/null
+++ b/src/ftgl/FTGL/FTBBox.h
@@ -0,0 +1,180 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTBBox__
+#define __FTBBox__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTBBox is a convenience class for handling bounding boxes.
+ */
+class FTGL_EXPORT FTBBox
+{
+ public:
+ /**
+ * Default constructor. Bounding box is set to zero.
+ */
+ FTBBox()
+ : lower(0.0f, 0.0f, 0.0f),
+ upper(0.0f, 0.0f, 0.0f)
+ {}
+
+ /**
+ * Constructor.
+ */
+ FTBBox(float lx, float ly, float lz, float ux, float uy, float uz)
+ : lower(lx, ly, lz),
+ upper(ux, uy, uz)
+ {}
+
+ /**
+ * Constructor.
+ */
+ FTBBox(FTPoint l, FTPoint u)
+ : lower(l),
+ upper(u)
+ {}
+
+ /**
+ * Constructor. Extracts a bounding box from a freetype glyph. Uses
+ * the control box for the glyph. <code>FT_Glyph_Get_CBox()</code>
+ *
+ * @param glyph A freetype glyph
+ */
+ FTBBox(FT_GlyphSlot glyph)
+ : lower(0.0f, 0.0f, 0.0f),
+ upper(0.0f, 0.0f, 0.0f)
+ {
+ FT_BBox bbox;
+ FT_Outline_Get_CBox(&(glyph->outline), &bbox);
+
+ lower.X(static_cast<float>(bbox.xMin) / 64.0f);
+ lower.Y(static_cast<float>(bbox.yMin) / 64.0f);
+ lower.Z(0.0f);
+ upper.X(static_cast<float>(bbox.xMax) / 64.0f);
+ upper.Y(static_cast<float>(bbox.yMax) / 64.0f);
+ upper.Z(0.0f);
+ }
+
+ /**
+ * Destructor
+ */
+ ~FTBBox()
+ {}
+
+ /**
+ * Mark the bounds invalid by setting all lower dimensions greater
+ * than the upper dimensions.
+ */
+ void Invalidate()
+ {
+ lower = FTPoint(1.0f, 1.0f, 1.0f);
+ upper = FTPoint(-1.0f, -1.0f, -1.0f);
+ }
+
+ /**
+ * Determines if this bounding box is valid.
+ *
+ * @return True if all lower values are <= the corresponding
+ * upper values.
+ */
+ bool IsValid()
+ {
+ return lower.X() <= upper.X()
+ && lower.Y() <= upper.Y()
+ && lower.Z() <= upper.Z();
+ }
+
+ /**
+ * Move the Bounding Box by a vector.
+ *
+ * @param vector The vector to move the bbox in 3D space.
+ */
+ FTBBox& operator += (const FTPoint vector)
+ {
+ lower += vector;
+ upper += vector;
+
+ return *this;
+ }
+
+ /**
+ * Combine two bounding boxes. The result is the smallest bounding
+ * box containing the two original boxes.
+ *
+ * @param bbox The bounding box to merge with the second one.
+ */
+ FTBBox& operator |= (const FTBBox& bbox)
+ {
+ if(bbox.lower.X() < lower.X()) lower.X(bbox.lower.X());
+ if(bbox.lower.Y() < lower.Y()) lower.Y(bbox.lower.Y());
+ if(bbox.lower.Z() < lower.Z()) lower.Z(bbox.lower.Z());
+ if(bbox.upper.X() > upper.X()) upper.X(bbox.upper.X());
+ if(bbox.upper.Y() > upper.Y()) upper.Y(bbox.upper.Y());
+ if(bbox.upper.Z() > upper.Z()) upper.Z(bbox.upper.Z());
+
+ return *this;
+ }
+
+ void SetDepth(float depth)
+ {
+ if(depth > 0)
+ upper.Z(lower.Z() + depth);
+ else
+ lower.Z(upper.Z() + depth);
+ }
+
+
+ inline FTPoint const Upper() const
+ {
+ return upper;
+ }
+
+
+ inline FTPoint const Lower() const
+ {
+ return lower;
+ }
+
+ private:
+ /**
+ * The bounds of the box
+ */
+ FTPoint lower, upper;
+};
+
+#endif //__cplusplus
+
+#endif // __FTBBox__
+
diff --git a/src/ftgl/FTGL/FTBitmapGlyph.h b/src/ftgl/FTGL/FTBitmapGlyph.h
new file mode 100644
index 0000000..f8ef87f
--- /dev/null
+++ b/src/ftgl/FTGL/FTBitmapGlyph.h
@@ -0,0 +1,82 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTBitmapGlyph__
+#define __FTBitmapGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTBitmapGlyph is a specialisation of FTGlyph for creating bitmaps.
+ */
+class FTGL_EXPORT FTBitmapGlyph : public FTGlyph
+{
+ public:
+ /**
+ * Constructor
+ *
+ * @param glyph The Freetype glyph to be processed
+ */
+ FTBitmapGlyph(FT_GlyphSlot glyph);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTBitmapGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialisation of FTGLglyph for creating bitmaps.
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreateBitmapGlyph(FT_GlyphSlot glyph);
+
+FTGL_END_C_DECLS
+
+#endif // __FTBitmapGlyph__
+
diff --git a/src/ftgl/FTGL/FTBuffer.h b/src/ftgl/FTGL/FTBuffer.h
new file mode 100644
index 0000000..11f33b5
--- /dev/null
+++ b/src/ftgl/FTGL/FTBuffer.h
@@ -0,0 +1,127 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning Please use <FTGL/ftgl.h> instead of <FTBuffer.h>.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTBuffer__
+#define __FTBuffer__
+
+#ifdef __cplusplus
+
+/**
+ * FTBuffer is a helper class for pixel buffers.
+ *
+ * It provides the interface between FTBufferFont and FTBufferGlyph to
+ * optimise rendering operations.
+ *
+ * @see FTBufferGlyph
+ * @see FTBufferFont
+ */
+class FTGL_EXPORT FTBuffer
+{
+ public:
+ /**
+ * Default constructor.
+ */
+ FTBuffer();
+
+ /**
+ * Destructor
+ */
+ ~FTBuffer();
+
+ /**
+ * Get the pen's position in the buffer.
+ *
+ * @return The pen's position as an FTPoint object.
+ */
+ inline FTPoint Pos() const
+ {
+ return pos;
+ }
+
+ /**
+ * Set the pen's position in the buffer.
+ *
+ * @param arg An FTPoint object with the desired pen's position.
+ */
+ inline void Pos(FTPoint arg)
+ {
+ pos = arg;
+ }
+
+ /**
+ * Set the buffer's size.
+ *
+ * @param w The buffer's desired width, in pixels.
+ * @param h The buffer's desired height, in pixels.
+ */
+ void Size(int w, int h);
+
+ /**
+ * Get the buffer's width.
+ *
+ * @return The buffer's width, in pixels.
+ */
+ inline int Width() const { return width; }
+
+ /**
+ * Get the buffer's height.
+ *
+ * @return The buffer's height, in pixels.
+ */
+ inline int Height() const { return height; }
+
+ /**
+ * Get the buffer's direct pixel buffer.
+ *
+ * @return A read-write pointer to the buffer's pixels.
+ */
+ inline unsigned char *Pixels() const { return pixels; }
+
+ private:
+ /**
+ * Buffer's width and height.
+ */
+ int width, height;
+
+ /**
+ * Buffer's pixel buffer.
+ */
+ unsigned char *pixels;
+
+ /**
+ * Buffer's internal pen position.
+ */
+ FTPoint pos;
+};
+
+#endif //__cplusplus
+
+#endif // __FTBuffer__
+
diff --git a/src/ftgl/FTGL/FTBufferFont.h b/src/ftgl/FTGL/FTBufferFont.h
new file mode 100644
index 0000000..15d358d
--- /dev/null
+++ b/src/ftgl/FTGL/FTBufferFont.h
@@ -0,0 +1,99 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning Please use <FTGL/ftgl.h> instead of <FTBufferFont.h>.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTBufferFont__
+#define __FTBufferFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTBufferFont is a specialisation of the FTFont class for handling
+ * memory buffer fonts.
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTBufferFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTBufferFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTBufferFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ ~FTBufferFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling memory buffer fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateBufferFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTBufferFont__
+
diff --git a/src/ftgl/FTGL/FTBufferGlyph.h b/src/ftgl/FTGL/FTBufferGlyph.h
new file mode 100644
index 0000000..cb7b3ed
--- /dev/null
+++ b/src/ftgl/FTGL/FTBufferGlyph.h
@@ -0,0 +1,69 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning Please use <FTGL/ftgl.h> instead of <FTBufferGlyph.h>.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTBufferGlyph__
+#define __FTBufferGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTBufferGlyph is a specialisation of FTGlyph for memory buffer rendering.
+ */
+class FTGL_EXPORT FTBufferGlyph : public FTGlyph
+{
+ public:
+ /**
+ * Constructor
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @param buffer An FTBuffer object in which to render the glyph.
+ */
+ FTBufferGlyph(FT_GlyphSlot glyph, FTBuffer *buffer);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTBufferGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#endif //__cplusplus
+
+#endif // __FTBufferGlyph__
+
diff --git a/src/ftgl/FTGL/FTExtrdGlyph.h b/src/ftgl/FTGL/FTExtrdGlyph.h
new file mode 100644
index 0000000..c1eaa54
--- /dev/null
+++ b/src/ftgl/FTGL/FTExtrdGlyph.h
@@ -0,0 +1,104 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTExtrudeGlyph__
+#define __FTExtrudeGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTExtrudeGlyph is a specialisation of FTGlyph for creating tessellated
+ * extruded polygon glyphs.
+ */
+class FTGL_EXPORT FTExtrudeGlyph : 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 frontOutset outset contour size
+ * @param backOutset outset contour size
+ * @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.
+ */
+ FTExtrudeGlyph(FT_GlyphSlot glyph, float depth, float frontOutset,
+ float backOutset, bool useDisplayList);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTExtrudeGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#define FTExtrdGlyph FTExtrudeGlyph
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialisation of FTGLglyph for creating tessellated
+ * extruded polygon glyphs.
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @param depth The distance along the z axis to extrude the glyph
+ * @param frontOutset outset contour size
+ * @param backOutset outset contour size
+ * @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.
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreateExtrudeGlyph(FT_GlyphSlot glyph, float depth,
+ float frontOutset, float backOutset,
+ int useDisplayList);
+
+FTGL_END_C_DECLS
+
+#endif // __FTExtrudeGlyph__
+
diff --git a/src/ftgl/FTGL/FTFont.h b/src/ftgl/FTGL/FTFont.h
new file mode 100644
index 0000000..0799fff
--- /dev/null
+++ b/src/ftgl/FTGL/FTFont.h
@@ -0,0 +1,584 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTFont__
+#define __FTFont__
+
+#ifdef __cplusplus
+
+class FTFontImpl;
+
+/**
+ * FTFont is the public interface for the FTGL library.
+ *
+ * Specific font classes are derived from this class. It uses the helper
+ * classes FTFace and FTSize to access the Freetype library. This class
+ * is abstract and deriving classes must implement the protected
+ * <code>MakeGlyph</code> function to create glyphs of the
+ * appropriate type.
+ *
+ * It is good practice after using these functions to test the error
+ * code returned. <code>FT_Error Error()</code>. Check the freetype file
+ * fterrdef.h for error definitions.
+ *
+ * @see FTFace
+ * @see FTSize
+ */
+class FTGL_EXPORT FTFont
+{
+ protected:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTFont(char const *fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
+
+ private:
+ /* Allow our internal subclasses to access the private constructor */
+ friend class FTBitmapFont;
+ friend class FTBufferFont;
+ friend class FTExtrudeFont;
+ friend class FTOutlineFont;
+ friend class FTPixmapFont;
+ friend class FTPolygonFont;
+ friend class FTTextureFont;
+
+ /**
+ * Internal FTGL FTFont constructor. For private use only.
+ *
+ * @param pImpl Internal implementation object. Will be destroyed
+ * upon FTFont deletion.
+ */
+ FTFont(FTFontImpl *pImpl);
+
+ public:
+ virtual ~FTFont();
+
+ /**
+ * Attach auxilliary file to font e.g font metrics.
+ *
+ * Note: not all font formats implement this function.
+ *
+ * @param fontFilePath auxilliary font file path.
+ * @return <code>true</code> if file has been attached
+ * successfully.
+ */
+ virtual bool Attach(const char* fontFilePath);
+
+ /**
+ * Attach auxilliary data to font e.g font metrics, from memory.
+ *
+ * Note: not all font formats implement this function.
+ *
+ * @param pBufferBytes the in-memory buffer.
+ * @param bufferSizeInBytes the length of the buffer in bytes.
+ * @return <code>true</code> if file has been attached
+ * successfully.
+ */
+ virtual bool Attach(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Set the glyph loading flags. By default, fonts use the most
+ * sensible flags when loading a font's glyph using FT_Load_Glyph().
+ * This function allows to override the default flags.
+ *
+ * @param flags The glyph loading flags.
+ */
+ virtual void GlyphLoadFlags(FT_Int flags);
+
+ /**
+ * Set the character map for the face.
+ *
+ * @param encoding Freetype enumerate for char map code.
+ * @return <code>true</code> if charmap was valid and
+ * set correctly.
+ */
+ virtual bool CharMap(FT_Encoding encoding);
+
+ /**
+ * Get the number of character maps in this face.
+ *
+ * @return character map count.
+ */
+ virtual unsigned int CharMapCount() const;
+
+ /**
+ * Get a list of character maps in this face.
+ *
+ * @return pointer to the first encoding.
+ */
+ virtual FT_Encoding* CharMapList();
+
+ /**
+ * Set the char size for the current face.
+ *
+ * @param size the face size in points (1/72 inch)
+ * @param res the resolution of the target device.
+ * @return <code>true</code> if size was set correctly
+ */
+ virtual bool FaceSize(const unsigned int size,
+ const unsigned int res = 72);
+
+ /**
+ * Get the current face size in points (1/72 inch).
+ *
+ * @return face size
+ */
+ virtual unsigned int FaceSize() const;
+
+ /**
+ * Set the extrusion distance for the font. Only implemented by
+ * FTExtrudeFont
+ *
+ * @param depth The extrusion distance.
+ */
+ virtual void Depth(float depth);
+
+ /**
+ * Set the outset distance for the font. Only implemented by
+ * FTOutlineFont, FTPolygonFont and FTExtrudeFont
+ *
+ * @param outset The outset distance.
+ */
+ virtual void Outset(float outset);
+
+ /**
+ * Set the front and back outset distances for the font. Only
+ * implemented by FTExtrudeFont
+ *
+ * @param front The front outset distance.
+ * @param back The back outset distance.
+ */
+ virtual void Outset(float front, float back);
+
+ /**
+ * Enable or disable the use of Display Lists inside FTGL
+ *
+ * @param useList <code>true</code> turns ON display lists.
+ * <code>false</code> turns OFF display lists.
+ */
+ virtual void UseDisplayList(bool useList);
+
+ /**
+ * Get the global ascender height for the face.
+ *
+ * @return Ascender height
+ */
+ virtual float Ascender() const;
+
+ /**
+ * Gets the global descender height for the face.
+ *
+ * @return Descender height
+ */
+ virtual float Descender() const;
+
+ /**
+ * Gets the line spacing for the font.
+ *
+ * @return Line height
+ */
+ virtual float LineHeight() const;
+
+ /**
+ * Get the bounding box for a string.
+ *
+ * @param string A char buffer.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
+ * @return The corresponding bounding box.
+ */
+ virtual FTBBox BBox(const char *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ FTPoint spacing = FTPoint());
+
+ /**
+ * Get the bounding box for a string (deprecated).
+ *
+ * @param string A char buffer.
+ * @param llx Lower left near x coordinate.
+ * @param lly Lower left near y coordinate.
+ * @param llz Lower left near z coordinate.
+ * @param urx Upper right far x coordinate.
+ * @param ury Upper right far y coordinate.
+ * @param urz Upper right far z coordinate.
+ */
+ void BBox(const char* string, float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
+ {
+ FTBBox b = BBox(string);
+ llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
+ urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
+ }
+
+ /**
+ * Get the bounding box for a string.
+ *
+ * @param string A wchar_t buffer.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
+ * @return The corresponding bounding box.
+ */
+ virtual FTBBox BBox(const wchar_t *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ FTPoint spacing = FTPoint());
+
+ /**
+ * Get the bounding box for a string (deprecated).
+ *
+ * @param string A wchar_t buffer.
+ * @param llx Lower left near x coordinate.
+ * @param lly Lower left near y coordinate.
+ * @param llz Lower left near z coordinate.
+ * @param urx Upper right far x coordinate.
+ * @param ury Upper right far y coordinate.
+ * @param urz Upper right far z coordinate.
+ */
+ void BBox(const wchar_t* string, float& llx, float& lly, float& llz,
+ float& urx, float& ury, float& urz)
+ {
+ FTBBox b = BBox(string);
+ llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
+ urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
+ }
+
+ /**
+ * Get the advance for a string.
+ *
+ * @param string 'C' style string to be checked.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
+ * @return The string's advance width.
+ */
+ virtual float Advance(const char* string, const int len = -1,
+ FTPoint spacing = FTPoint());
+
+ /**
+ * Get the advance for a string.
+ *
+ * @param string A wchar_t string
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been checked (optional).
+ * @return The string's advance width.
+ */
+ virtual float Advance(const wchar_t* string, const int len = -1,
+ FTPoint spacing = FTPoint());
+
+ /**
+ * Render a string of characters.
+ *
+ * @param string 'C' style string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been displayed (optional).
+ * @param renderMode Render mode to use for display (optional).
+ * @return The new pen position after the last character was output.
+ */
+ virtual FTPoint Render(const char* string, const int len = -1,
+ FTPoint position = FTPoint(),
+ FTPoint spacing = FTPoint(),
+ int renderMode = FTGL::RENDER_ALL);
+
+ /**
+ * Render a string of characters
+ *
+ * @param string wchar_t string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param spacing A displacement vector to add after each character
+ * has been displayed (optional).
+ * @param renderMode Render mode to use for display (optional).
+ * @return The new pen position after the last character was output.
+ */
+ virtual FTPoint Render(const wchar_t *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ FTPoint spacing = FTPoint(),
+ int renderMode = FTGL::RENDER_ALL);
+
+ /**
+ * Queries the Font for errors.
+ *
+ * @return The current error code.
+ */
+ virtual FT_Error Error() const;
+
+ protected:
+ /* Allow impl to access MakeGlyph */
+ friend class FTFontImpl;
+
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0;
+
+ private:
+ /**
+ * Internal FTGL FTFont implementation object. For private use only.
+ */
+ FTFontImpl *impl;
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * FTGLfont is the public interface for the FTGL library.
+ *
+ * It is good practice after using these functions to test the error
+ * code returned. <code>FT_Error Error()</code>. Check the freetype file
+ * fterrdef.h for error definitions.
+ */
+struct _FTGLFont;
+typedef struct _FTGLfont FTGLfont;
+
+/**
+ * Create a custom FTGL font object.
+ *
+ * @param fontFilePath The font file name.
+ * @param data A pointer to private data that will be passed to callbacks.
+ * @param makeglyphCallback A glyph-making callback function.
+ * @return An FTGLfont* object.
+ */
+FTGL_EXPORT FTGLfont *ftglCreateCustomFont(char const *fontFilePath,
+ void *data,
+ FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *));
+
+/**
+ * Destroy an FTGL font object.
+ *
+ * @param font An FTGLfont* object.
+ */
+FTGL_EXPORT void ftglDestroyFont(FTGLfont* font);
+
+/**
+ * Attach auxilliary file to font e.g. font metrics.
+ *
+ * Note: not all font formats implement this function.
+ *
+ * @param font An FTGLfont* object.
+ * @param path Auxilliary font file path.
+ * @return 1 if file has been attached successfully.
+ */
+FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path);
+
+/**
+ * Attach auxilliary data to font, e.g. font metrics, from memory.
+ *
+ * Note: not all font formats implement this function.
+ *
+ * @param font An FTGLfont* object.
+ * @param data The in-memory buffer.
+ * @param size The length of the buffer in bytes.
+ * @return 1 if file has been attached successfully.
+ */
+FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data,
+ size_t size);
+
+/**
+ * Set the character map for the face.
+ *
+ * @param font An FTGLfont* object.
+ * @param encoding Freetype enumerate for char map code.
+ * @return 1 if charmap was valid and set correctly.
+ */
+FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding);
+
+/**
+ * Get the number of character maps in this face.
+ *
+ * @param font An FTGLfont* object.
+ * @return character map count.
+ */
+FTGL_EXPORT unsigned int ftglGetFontCharMapCount(FTGLfont* font);
+
+/**
+ * Get a list of character maps in this face.
+ *
+ * @param font An FTGLfont* object.
+ * @return pointer to the first encoding.
+ */
+FTGL_EXPORT FT_Encoding* ftglGetFontCharMapList(FTGLfont* font);
+
+/**
+ * Set the char size for the current face.
+ *
+ * @param font An FTGLfont* object.
+ * @param size The face size in points (1/72 inch).
+ * @param res The resolution of the target device, or 0 to use the default
+ * value of 72.
+ * @return 1 if size was set correctly.
+ */
+FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size,
+ unsigned int res);
+
+/**
+ * Get the current face size in points (1/72 inch).
+ *
+ * @param font An FTGLfont* object.
+ * @return face size
+ */
+FTGL_EXPORT unsigned int ftglGetFontFaceSize(FTGLfont* font);
+
+/**
+ * Set the extrusion distance for the font. Only implemented by
+ * FTExtrudeFont.
+ *
+ * @param font An FTGLfont* object.
+ * @param depth The extrusion distance.
+ */
+FTGL_EXPORT void ftglSetFontDepth(FTGLfont* font, float depth);
+
+/**
+ * Set the outset distance for the font. Only FTOutlineFont, FTPolygonFont
+ * and FTExtrudeFont implement front outset. Only FTExtrudeFont implements
+ * back outset.
+ *
+ * @param font An FTGLfont* object.
+ * @param front The front outset distance.
+ * @param back The back outset distance.
+ */
+FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back);
+
+/**
+ * Enable or disable the use of Display Lists inside FTGL.
+ *
+ * @param font An FTGLfont* object.
+ * @param useList 1 turns ON display lists.
+ * 0 turns OFF display lists.
+ */
+FTGL_EXPORT void ftglSetFontDisplayList(FTGLfont* font, int useList);
+
+/**
+ * Get the global ascender height for the face.
+ *
+ * @param font An FTGLfont* object.
+ * @return Ascender height
+ */
+FTGL_EXPORT float ftglGetFontAscender(FTGLfont* font);
+
+/**
+ * Gets the global descender height for the face.
+ *
+ * @param font An FTGLfont* object.
+ * @return Descender height
+ */
+FTGL_EXPORT float ftglGetFontDescender(FTGLfont* font);
+
+/**
+ * Gets the line spacing for the font.
+ *
+ * @param font An FTGLfont* object.
+ * @return Line height
+ */
+FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font);
+
+/**
+ * Get the bounding box for a string.
+ *
+ * @param font An FTGLfont* object.
+ * @param string A char buffer
+ * @param len The length of the string. If < 0 then all characters will be
+ * checked until a null character is encountered (optional).
+ * @param bounds An array of 6 float values where the bounding box's lower
+ * left near and upper right far 3D coordinates will be stored.
+ */
+FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string,
+ int len, float bounds[6]);
+
+/**
+ * Get the advance width for a string.
+ *
+ * @param font An FTGLfont* object.
+ * @param string A char string.
+ * @return Advance width
+ */
+FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string);
+
+/**
+ * Render a string of characters.
+ *
+ * @param font An FTGLfont* object.
+ * @param string Char string to be output.
+ * @param mode Render mode to display.
+ */
+FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode);
+
+/**
+ * Query a font for errors.
+ *
+ * @param font An FTGLfont* object.
+ * @return The current error code.
+ */
+FTGL_EXPORT FT_Error ftglGetFontError(FTGLfont* font);
+
+FTGL_END_C_DECLS
+
+#endif // __FTFont__
+
diff --git a/src/ftgl/FTGL/FTGLBitmapFont.h b/src/ftgl/FTGL/FTGLBitmapFont.h
new file mode 100644
index 0000000..d2fb1ba
--- /dev/null
+++ b/src/ftgl/FTGL/FTGLBitmapFont.h
@@ -0,0 +1,103 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTBitmapFont__
+#define __FTBitmapFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTBitmapFont is a specialisation of the FTFont class for handling
+ * Bitmap fonts
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTBitmapFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTBitmapFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTBitmapFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ ~FTBitmapFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#define FTGLBitmapFont FTBitmapFont
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling bitmap fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateBitmapFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTBitmapFont__
+
diff --git a/src/ftgl/FTGL/FTGLExtrdFont.h b/src/ftgl/FTGL/FTGLExtrdFont.h
new file mode 100644
index 0000000..47d6714
--- /dev/null
+++ b/src/ftgl/FTGL/FTGLExtrdFont.h
@@ -0,0 +1,105 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTExtrudeFont__
+#define __FTExtrudeFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTExtrudeFont is a specialisation of the FTFont class for handling
+ * extruded Polygon fonts
+ *
+ * @see FTFont
+ * @see FTPolygonFont
+ */
+class FTGL_EXPORT FTExtrudeFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTExtrudeFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTExtrudeFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ ~FTExtrudeFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#define FTGLExtrdFont FTExtrudeFont
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling extruded poygon fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ * @see ftglCreatePolygonFont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateExtrudeFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTExtrudeFont__
+
diff --git a/src/ftgl/FTGL/FTGLOutlineFont.h b/src/ftgl/FTGL/FTGLOutlineFont.h
new file mode 100644
index 0000000..bbf62da
--- /dev/null
+++ b/src/ftgl/FTGL/FTGLOutlineFont.h
@@ -0,0 +1,103 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTOutlineFont__
+#define __FTOutlineFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTOutlineFont is a specialisation of the FTFont class for handling
+ * Vector Outline fonts
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTOutlineFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTOutlineFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTOutlineFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ ~FTOutlineFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#define FTGLOutlineFont FTOutlineFont
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling vector outline fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateOutlineFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTOutlineFont__
+
diff --git a/src/ftgl/FTGL/FTGLPixmapFont.h b/src/ftgl/FTGL/FTGLPixmapFont.h
new file mode 100644
index 0000000..c90b9c5
--- /dev/null
+++ b/src/ftgl/FTGL/FTGLPixmapFont.h
@@ -0,0 +1,103 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTPixmapFont__
+#define __FTPixmapFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTPixmapFont is a specialisation of the FTFont class for handling
+ * Pixmap (Grey Scale) fonts
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTPixmapFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTPixmapFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTPixmapFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ ~FTPixmapFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#define FTGLPixmapFont FTPixmapFont
+
+#endif // __cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling pixmap (grey scale) fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreatePixmapFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTPixmapFont__
+
diff --git a/src/ftgl/FTGL/FTGLPolygonFont.h b/src/ftgl/FTGL/FTGLPolygonFont.h
new file mode 100644
index 0000000..1dab097
--- /dev/null
+++ b/src/ftgl/FTGL/FTGLPolygonFont.h
@@ -0,0 +1,104 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTPolygonFont__
+#define __FTPolygonFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTPolygonFont is a specialisation of the FTFont class for handling
+ * tesselated Polygon Mesh fonts
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTPolygonFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTPolygonFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTPolygonFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ ~FTPolygonFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#define FTGLPolygonFont FTPolygonFont
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling tesselated polygon
+ * mesh fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreatePolygonFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTPolygonFont__
+
diff --git a/src/ftgl/FTGL/FTGLTextureFont.h b/src/ftgl/FTGL/FTGLTextureFont.h
new file mode 100644
index 0000000..03991e9
--- /dev/null
+++ b/src/ftgl/FTGL/FTGLTextureFont.h
@@ -0,0 +1,103 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTTextureFont__
+#define __FTTextureFont__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTTextureFont is a specialisation of the FTFont class for handling
+ * Texture mapped fonts
+ *
+ * @see FTFont
+ */
+class FTGL_EXPORT FTTextureFont : public FTFont
+{
+ public:
+ /**
+ * Open and read a font file. Sets Error flag.
+ *
+ * @param fontFilePath font file path.
+ */
+ FTTextureFont(const char* fontFilePath);
+
+ /**
+ * Open and read a font from a buffer in memory. Sets Error flag.
+ * The buffer is owned by the client and is NOT copied by FTGL. The
+ * pointer must be valid while using FTGL.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ */
+ FTTextureFont(const unsigned char *pBufferBytes,
+ size_t bufferSizeInBytes);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTTextureFont();
+
+ protected:
+ /**
+ * Construct a glyph of the correct type.
+ *
+ * Clients must override the function and return their specialised
+ * FTGlyph.
+ *
+ * @param slot A FreeType glyph slot.
+ * @return An FT****Glyph or <code>null</code> on failure.
+ */
+ virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
+};
+
+#define FTGLTextureFont FTTextureFont
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialised FTGLfont object for handling texture-mapped fonts.
+ *
+ * @param file The font file name.
+ * @return An FTGLfont* object.
+ *
+ * @see FTGLfont
+ */
+FTGL_EXPORT FTGLfont *ftglCreateTextureFont(const char *file);
+
+FTGL_END_C_DECLS
+
+#endif // __FTTextureFont__
+
diff --git a/src/ftgl/FTGL/FTGlyph.h b/src/ftgl/FTGL/FTGlyph.h
new file mode 100644
index 0000000..a5023b2
--- /dev/null
+++ b/src/ftgl/FTGL/FTGlyph.h
@@ -0,0 +1,201 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTGlyph__
+#define __FTGlyph__
+
+#ifdef __cplusplus
+
+class FTGlyphImpl;
+
+/**
+ * FTGlyph is the base class for FTGL glyphs.
+ *
+ * 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 FTBBox
+ * @see FTPoint
+ */
+class FTGL_EXPORT FTGlyph
+{
+ protected:
+ /**
+ * Create a glyph.
+ *
+ * @param glyph The Freetype glyph to be processed
+ */
+ FTGlyph(FT_GlyphSlot glyph);
+
+ private:
+ /**
+ * Internal FTGL FTGlyph constructor. For private use only.
+ *
+ * @param pImpl Internal implementation object. Will be destroyed
+ * upon FTGlyph deletion.
+ */
+ FTGlyph(FTGlyphImpl *pImpl);
+
+ /* Allow our internal subclasses to access the private constructor */
+ friend class FTBitmapGlyph;
+ friend class FTBufferGlyph;
+ friend class FTExtrudeGlyph;
+ friend class FTOutlineGlyph;
+ friend class FTPixmapGlyph;
+ friend class FTPolygonGlyph;
+ friend class FTTextureGlyph;
+
+ public:
+ /**
+ * Destructor
+ */
+ virtual ~FTGlyph();
+
+ /**
+ * Renders this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode) = 0;
+
+ /**
+ * Return the advance width for this glyph.
+ *
+ * @return advance width.
+ */
+ virtual float Advance() const;
+
+ /**
+ * Return the bounding box for this glyph.
+ *
+ * @return bounding box.
+ */
+ virtual const FTBBox& BBox() const;
+
+ /**
+ * Queries for errors.
+ *
+ * @return The current error code.
+ */
+ virtual FT_Error Error() const;
+
+ private:
+ /**
+ * Internal FTGL FTGlyph implementation object. For private use only.
+ */
+ FTGlyphImpl *impl;
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * FTGLglyph is the base class for FTGL glyphs.
+ *
+ * It provides the interface between Freetype glyphs and their openGL
+ * renderable counterparts. This is an abstract class and derived classes
+ * must implement the ftglRenderGlyph() function.
+ */
+struct _FTGLGlyph;
+typedef struct _FTGLglyph FTGLglyph;
+
+/**
+ * Create a custom FTGL glyph object.
+ * FIXME: maybe get rid of "base" and have advanceCallback etc. functions
+ *
+ * @param base The base FTGLglyph* to subclass.
+ * @param data A pointer to private data that will be passed to callbacks.
+ * @param renderCallback A rendering callback function.
+ * @param destroyCallback A callback function to be called upon destruction.
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreateCustomGlyph(FTGLglyph *base, void *data,
+ void (*renderCallback) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *),
+ void (*destroyCallback) (FTGLglyph *, void *));
+
+/**
+ * Destroy an FTGL glyph object.
+ *
+ * @param glyph An FTGLglyph* object.
+ */
+FTGL_EXPORT void ftglDestroyGlyph(FTGLglyph *glyph);
+
+/**
+ * Render a glyph at the current pen position and compute the corresponding
+ * advance.
+ *
+ * @param glyph An FTGLglyph* object.
+ * @param penx The current pen's X position.
+ * @param peny The current pen's Y position.
+ * @param renderMode Render mode to display
+ * @param advancex A pointer to an FTGL_DOUBLE where to write the advance's X
+ * component.
+ * @param advancey A pointer to an FTGL_DOUBLE where to write the advance's Y
+ * component.
+ */
+FTGL_EXPORT void ftglRenderGlyph(FTGLglyph *glyph, FTGL_DOUBLE penx,
+ FTGL_DOUBLE peny, int renderMode,
+ FTGL_DOUBLE *advancex, FTGL_DOUBLE *advancey);
+/**
+ * Return the advance for a glyph.
+ *
+ * @param glyph An FTGLglyph* object.
+ * @return The advance's X component.
+ */
+FTGL_EXPORT float ftglGetGlyphAdvance(FTGLglyph *glyph);
+
+/**
+ * Return the bounding box for a glyph.
+ *
+ * @param glyph An FTGLglyph* object.
+ * @param bounds An array of 6 float values where the bounding box's lower
+ * left near and upper right far 3D coordinates will be stored.
+ */
+FTGL_EXPORT void ftglGetGlyphBBox(FTGLglyph *glyph, float bounds[6]);
+
+/**
+ * Query a glyph for errors.
+ *
+ * @param glyph An FTGLglyph* object.
+ * @return The current error code.
+ */
+FTGL_EXPORT FT_Error ftglGetGlyphError(FTGLglyph* glyph);
+
+FTGL_END_C_DECLS
+
+#endif // __FTGlyph__
+
diff --git a/src/ftgl/FTGL/FTLayout.h b/src/ftgl/FTGL/FTLayout.h
new file mode 100644
index 0000000..329b98a
--- /dev/null
+++ b/src/ftgl/FTGL/FTLayout.h
@@ -0,0 +1,192 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTLayout__
+#define __FTLayout__
+
+#ifdef __cplusplus
+
+
+class FTLayoutImpl;
+
+/**
+ * FTLayout is the interface for layout managers that render text.
+ *
+ * Specific layout manager classes are derived from this class. This class
+ * is abstract and deriving classes must implement the protected
+ * <code>Render</code> methods to render formatted text and
+ * <code>BBox</code> methods to determine the bounding box of output text.
+ *
+ * @see FTFont
+ * @see FTBBox
+ */
+class FTGL_EXPORT FTLayout
+{
+ protected:
+ FTLayout();
+
+ private:
+ /**
+ * Internal FTGL FTLayout constructor. For private use only.
+ *
+ * @param pImpl Internal implementation object. Will be destroyed
+ * upon FTLayout deletion.
+ */
+ FTLayout(FTLayoutImpl *pImpl);
+
+ /* Allow our internal subclasses to access the private constructor */
+ friend class FTSimpleLayout;
+
+ public:
+ /**
+ * Destructor
+ */
+ virtual ~FTLayout();
+
+ /**
+ * Get the bounding box for a formatted string.
+ *
+ * @param string A char string.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @return The corresponding bounding box.
+ */
+ virtual FTBBox BBox(const char* string, const int len = -1,
+ FTPoint position = FTPoint()) = 0;
+
+ /**
+ * Get the bounding box for a formatted string.
+ *
+ * @param string A wchar_t string.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @return The corresponding bounding box.
+ */
+ virtual FTBBox BBox(const wchar_t* string, const int len = -1,
+ FTPoint position = FTPoint()) = 0;
+
+ /**
+ * Render a string of characters.
+ *
+ * @param string 'C' style string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param renderMode Render mode to display (optional)
+ */
+ virtual void Render(const char *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ int renderMode = FTGL::RENDER_ALL) = 0;
+
+ /**
+ * Render a string of characters.
+ *
+ * @param string wchar_t string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param renderMode Render mode to display (optional)
+ */
+ virtual void Render(const wchar_t *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ int renderMode = FTGL::RENDER_ALL) = 0;
+
+ /**
+ * Queries the Layout for errors.
+ *
+ * @return The current error code.
+ */
+ virtual FT_Error Error() const;
+
+ private:
+ /**
+ * Internal FTGL FTLayout implementation object. For private use only.
+ */
+ FTLayoutImpl *impl;
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * FTGLlayout is the interface for layout managers that render text.
+ */
+struct _FTGLlayout;
+typedef struct _FTGLlayout FTGLlayout;
+
+/**
+ * Destroy an FTGL layout object.
+ *
+ * @param layout An FTGLlayout* object.
+ */
+FTGL_EXPORT void ftglDestroyLayout(FTGLlayout* layout);
+
+/**
+ * Get the bounding box for a string.
+ *
+ * @param layout An FTGLlayout* object.
+ * @param string A char buffer
+ * @param bounds An array of 6 float values where the bounding box's lower
+ * left near and upper right far 3D coordinates will be stored.
+ */
+FTGL_EXPORT void ftglGetLayoutBBox(FTGLlayout *layout, const char* string,
+ float bounds[6]);
+
+/**
+ * Render a string of characters.
+ *
+ * @param layout An FTGLlayout* object.
+ * @param string Char string to be output.
+ * @param mode Render mode to display.
+ */
+FTGL_EXPORT void ftglRenderLayout(FTGLlayout *layout, const char *string,
+ int mode);
+
+/**
+ * Query a layout for errors.
+ *
+ * @param layout An FTGLlayout* object.
+ * @return The current error code.
+ */
+FTGL_EXPORT FT_Error ftglGetLayoutError(FTGLlayout* layout);
+
+FTGL_END_C_DECLS
+
+#endif /* __FTLayout__ */
+
diff --git a/src/ftgl/FTGL/FTOutlineGlyph.h b/src/ftgl/FTGL/FTOutlineGlyph.h
new file mode 100644
index 0000000..2919139
--- /dev/null
+++ b/src/ftgl/FTGL/FTOutlineGlyph.h
@@ -0,0 +1,94 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTOutlineGlyph__
+#define __FTOutlineGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTOutlineGlyph is a specialisation of FTGlyph for creating outlines.
+ */
+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 outset outset distance
+ * @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, float outset, bool useDisplayList);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTOutlineGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialisation of FTGLglyph for creating outlines.
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @param outset outset contour size
+ * @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.
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreateOutlineGlyph(FT_GlyphSlot glyph, float outset,
+ int useDisplayList);
+
+FTGL_END_C_DECLS
+
+#endif // __FTOutlineGlyph__
+
diff --git a/src/ftgl/FTGL/FTPixmapGlyph.h b/src/ftgl/FTGL/FTPixmapGlyph.h
new file mode 100644
index 0000000..d9a317f
--- /dev/null
+++ b/src/ftgl/FTGL/FTPixmapGlyph.h
@@ -0,0 +1,82 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTPixmapGlyph__
+#define __FTPixmapGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTPixmapGlyph is a specialisation of FTGlyph for creating pixmaps.
+ */
+class FTGL_EXPORT FTPixmapGlyph : public FTGlyph
+{
+ public:
+ /**
+ * Constructor
+ *
+ * @param glyph The Freetype glyph to be processed
+ */
+ FTPixmapGlyph(FT_GlyphSlot glyph);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTPixmapGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialisation of FTGLglyph for creating pixmaps.
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreatePixmapGlyph(FT_GlyphSlot glyph);
+
+FTGL_END_C_DECLS
+
+#endif // __FTPixmapGlyph__
+
diff --git a/src/ftgl/FTGL/FTPoint.h b/src/ftgl/FTGL/FTPoint.h
new file mode 100644
index 0000000..fef4af6
--- /dev/null
+++ b/src/ftgl/FTGL/FTPoint.h
@@ -0,0 +1,274 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTPoint__
+#define __FTPoint__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTPoint class is a basic 3-dimensional point or vector.
+ */
+class FTGL_EXPORT FTPoint
+{
+ public:
+ /**
+ * Default constructor. Point is set to zero.
+ */
+ inline FTPoint()
+ {
+ values[0] = 0;
+ values[1] = 0;
+ values[2] = 0;
+ }
+
+ /**
+ * Constructor. Z coordinate is set to zero if unspecified.
+ *
+ * @param x First component
+ * @param y Second component
+ * @param z Third component
+ */
+ inline FTPoint(const FTGL_DOUBLE x, const FTGL_DOUBLE y,
+ const FTGL_DOUBLE z = 0)
+ {
+ values[0] = x;
+ values[1] = y;
+ values[2] = z;
+ }
+
+ /**
+ * Constructor. This converts an FT_Vector to an FTPoint
+ *
+ * @param ft_vector A freetype vector
+ */
+ inline FTPoint(const FT_Vector& ft_vector)
+ {
+ values[0] = ft_vector.x;
+ values[1] = ft_vector.y;
+ values[2] = 0;
+ }
+
+ /**
+ * Normalise a point's coordinates. If the coordinates are zero,
+ * the point is left untouched.
+ *
+ * @return A vector of norm one.
+ */
+ FTPoint Normalise();
+
+
+ /**
+ * Operator += In Place Addition.
+ *
+ * @param point
+ * @return this plus point.
+ */
+ inline FTPoint& operator += (const FTPoint& point)
+ {
+ values[0] += point.values[0];
+ values[1] += point.values[1];
+ values[2] += point.values[2];
+
+ return *this;
+ }
+
+ /**
+ * Operator +
+ *
+ * @param point
+ * @return this plus point.
+ */
+ inline FTPoint operator + (const FTPoint& point) const
+ {
+ FTPoint temp;
+ temp.values[0] = values[0] + point.values[0];
+ temp.values[1] = values[1] + point.values[1];
+ temp.values[2] = values[2] + point.values[2];
+
+ return temp;
+ }
+
+ /**
+ * Operator -= In Place Substraction.
+ *
+ * @param point
+ * @return this minus point.
+ */
+ inline FTPoint& operator -= (const FTPoint& point)
+ {
+ values[0] -= point.values[0];
+ values[1] -= point.values[1];
+ values[2] -= point.values[2];
+
+ return *this;
+ }
+
+ /**
+ * Operator -
+ *
+ * @param point
+ * @return this minus point.
+ */
+ inline FTPoint operator - (const FTPoint& point) const
+ {
+ FTPoint temp;
+ temp.values[0] = values[0] - point.values[0];
+ temp.values[1] = values[1] - point.values[1];
+ temp.values[2] = values[2] - point.values[2];
+
+ return temp;
+ }
+
+ /**
+ * Operator * Scalar multiplication
+ *
+ * @param multiplier
+ * @return <code>this</code> multiplied by <code>multiplier</code>.
+ */
+ inline FTPoint operator * (double multiplier) const
+ {
+ FTPoint temp;
+ temp.values[0] = values[0] * multiplier;
+ temp.values[1] = values[1] * multiplier;
+ temp.values[2] = values[2] * multiplier;
+
+ return temp;
+ }
+
+
+ /**
+ * Operator * Scalar multiplication
+ *
+ * @param point
+ * @param multiplier
+ * @return <code>multiplier</code> multiplied by <code>point</code>.
+ */
+ inline friend FTPoint operator * (double multiplier, FTPoint& point)
+ {
+ return point * multiplier;
+ }
+
+
+ /**
+ * Operator * Scalar product
+ *
+ * @param a First vector.
+ * @param b Second vector.
+ * @return <code>a.b</code> scalar product.
+ */
+ inline friend double operator * (FTPoint &a, FTPoint& b)
+ {
+ return a.values[0] * b.values[0]
+ + a.values[1] * b.values[1]
+ + a.values[2] * b.values[2];
+ }
+
+
+ /**
+ * Operator ^ Vector product
+ *
+ * @param point Second point
+ * @return this vector point.
+ */
+ inline FTPoint operator ^ (const FTPoint& point)
+ {
+ FTPoint temp;
+ temp.values[0] = values[1] * point.values[2]
+ - values[2] * point.values[1];
+ temp.values[1] = values[2] * point.values[0]
+ - values[0] * point.values[2];
+ temp.values[2] = values[0] * point.values[1]
+ - values[1] * point.values[0];
+ return temp;
+ }
+
+
+ /**
+ * Operator == Tests for equality
+ *
+ * @param a
+ * @param b
+ * @return true if a & b are equal
+ */
+ friend bool operator == (const FTPoint &a, const FTPoint &b);
+
+
+ /**
+ * Operator != Tests for non equality
+ *
+ * @param a
+ * @param b
+ * @return true if a & b are not equal
+ */
+ friend bool operator != (const FTPoint &a, const FTPoint &b);
+
+
+ /**
+ * Cast to FTGL_DOUBLE*
+ */
+ inline operator const FTGL_DOUBLE*() const
+ {
+ return values;
+ }
+
+
+ /**
+ * Setters
+ */
+ inline void X(FTGL_DOUBLE x) { values[0] = x; };
+ inline void Y(FTGL_DOUBLE y) { values[1] = y; };
+ inline void Z(FTGL_DOUBLE z) { values[2] = z; };
+
+
+ /**
+ * Getters
+ */
+ inline FTGL_DOUBLE X() const { return values[0]; };
+ inline FTGL_DOUBLE Y() const { return values[1]; };
+ inline FTGL_DOUBLE Z() const { return values[2]; };
+ inline FTGL_FLOAT Xf() const { return static_cast<FTGL_FLOAT>(values[0]); };
+ inline FTGL_FLOAT Yf() const { return static_cast<FTGL_FLOAT>(values[1]); };
+ inline FTGL_FLOAT Zf() const { return static_cast<FTGL_FLOAT>(values[2]); };
+
+ private:
+ /**
+ * The point data
+ */
+ FTGL_DOUBLE values[3];
+};
+
+#endif //__cplusplus
+
+#endif // __FTPoint__
+
diff --git a/src/ftgl/FTGL/FTPolyGlyph.h b/src/ftgl/FTGL/FTPolyGlyph.h
new file mode 100644
index 0000000..ce3b000
--- /dev/null
+++ b/src/ftgl/FTGL/FTPolyGlyph.h
@@ -0,0 +1,98 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTPolygonGlyph__
+#define __FTPolygonGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTPolygonGlyph is a specialisation of FTGlyph for creating tessellated
+ * polygon glyphs.
+ */
+class FTGL_EXPORT FTPolygonGlyph : 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 outset The outset distance
+ * @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.
+ */
+ FTPolygonGlyph(FT_GlyphSlot glyph, float outset, bool useDisplayList);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTPolygonGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#define FTPolyGlyph FTPolygonGlyph
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialisation of FTGLglyph for creating tessellated
+ * polygon glyphs.
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @param outset outset contour size
+ * @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.
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreatePolygonGlyph(FT_GlyphSlot glyph, float outset,
+ int useDisplayList);
+
+FTGL_END_C_DECLS
+
+#endif // __FTPolygonGlyph__
+
diff --git a/src/ftgl/FTGL/FTSimpleLayout.h b/src/ftgl/FTGL/FTSimpleLayout.h
new file mode 100644
index 0000000..c778b18
--- /dev/null
+++ b/src/ftgl/FTGL/FTSimpleLayout.h
@@ -0,0 +1,191 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTSimpleLayout__
+#define __FTSimpleLayout__
+
+#ifdef __cplusplus
+
+
+class FTFont;
+
+/**
+ * FTSimpleLayout is a specialisation of FTLayout for simple text boxes.
+ *
+ * This class has basic support for text wrapping, left, right and centered
+ * alignment, and text justification.
+ *
+ * @see FTLayout
+ */
+class FTGL_EXPORT FTSimpleLayout : public FTLayout
+{
+ public:
+ /**
+ * Initializes line spacing to 1.0, alignment to
+ * ALIGN_LEFT and wrap to 100.0
+ */
+ FTSimpleLayout();
+
+ /**
+ * Destructor
+ */
+ ~FTSimpleLayout();
+
+ /**
+ * Get the bounding box for a formatted string.
+ *
+ * @param string A char string.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @return The corresponding bounding box.
+ */
+ virtual FTBBox BBox(const char* string, const int len = -1,
+ FTPoint position = FTPoint());
+
+ /**
+ * Get the bounding box for a formatted string.
+ *
+ * @param string A wchar_t string.
+ * @param len The length of the string. If < 0 then all characters
+ * will be checked until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @return The corresponding bounding box.
+ */
+ virtual FTBBox BBox(const wchar_t* string, const int len = -1,
+ FTPoint position = FTPoint());
+
+ /**
+ * Render a string of characters.
+ *
+ * @param string 'C' style string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param renderMode Render mode to display (optional)
+ */
+ virtual void Render(const char *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ int renderMode = FTGL::RENDER_ALL);
+
+ /**
+ * Render a string of characters.
+ *
+ * @param string wchar_t string to be output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered
+ * (optional).
+ * @param position The pen position of the first character (optional).
+ * @param renderMode Render mode to display (optional)
+ */
+ virtual void Render(const wchar_t *string, const int len = -1,
+ FTPoint position = FTPoint(),
+ int renderMode = FTGL::RENDER_ALL);
+
+ /**
+ * Set the font to use for rendering the text.
+ *
+ * @param fontInit A pointer to the new font. The font is
+ * referenced by this but will not be
+ * disposed of when this is deleted.
+ */
+ void SetFont(FTFont *fontInit);
+
+ /**
+ * @return The current font.
+ */
+ FTFont *GetFont();
+
+ /**
+ * The maximum line length for formatting text.
+ *
+ * @param LineLength The new line length.
+ */
+ void SetLineLength(const float LineLength);
+
+ /**
+ * @return The current line length.
+ */
+ float GetLineLength() const;
+
+ /**
+ * The text alignment mode used to distribute
+ * space within a line or rendered text.
+ *
+ * @param Alignment The new alignment mode.
+ */
+ void SetAlignment(const FTGL::TextAlignment Alignment);
+
+ /**
+ * @return The text alignment mode.
+ */
+ FTGL::TextAlignment GetAlignment() const;
+
+ /**
+ * Sets the line height.
+ *
+ * @param LineSpacing The height of each line of text expressed as
+ * a percentage of the current fonts line height.
+ */
+ void SetLineSpacing(const float LineSpacing);
+
+ /**
+ * @return The line spacing.
+ */
+ float GetLineSpacing() const;
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+FTGL_EXPORT FTGLlayout *ftglCreateSimpleLayout(void);
+
+FTGL_EXPORT void ftglSetLayoutFont(FTGLlayout *, FTGLfont*);
+FTGL_EXPORT FTGLfont *ftglGetLayoutFont(FTGLlayout *);
+
+FTGL_EXPORT void ftglSetLayoutLineLength(FTGLlayout *, const float);
+FTGL_EXPORT float ftglGetLayoutLineLength(FTGLlayout *);
+
+FTGL_EXPORT void ftglSetLayoutAlignment(FTGLlayout *, const int);
+FTGL_EXPORT int ftglGetLayoutAlignement(FTGLlayout *);
+
+FTGL_EXPORT void ftglSetLayoutLineSpacing(FTGLlayout *, const float);
+FTGL_EXPORT float ftglGetLayoutLineSpacing(FTGLlayout *);
+
+FTGL_END_C_DECLS
+
+#endif /* __FTSimpleLayout__ */
+
diff --git a/src/ftgl/FTGL/FTTextureGlyph.h b/src/ftgl/FTGL/FTTextureGlyph.h
new file mode 100644
index 0000000..ec545f3
--- /dev/null
+++ b/src/ftgl/FTGL/FTTextureGlyph.h
@@ -0,0 +1,99 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
+# include <FTGL/ftgl.h>
+#endif
+
+#ifndef __FTTextureGlyph__
+#define __FTTextureGlyph__
+
+#ifdef __cplusplus
+
+
+/**
+ * FTTextureGlyph is a specialisation of FTGlyph for creating texture
+ * glyphs.
+ */
+class FTGL_EXPORT FTTextureGlyph : public FTGlyph
+{
+ public:
+ /**
+ * Constructor
+ *
+ * @param glyph The Freetype glyph to be processed
+ * @param id The id of the texture that this glyph will be
+ * drawn in
+ * @param xOffset The x offset into the parent texture to draw
+ * this glyph
+ * @param yOffset The y offset into the parent texture to draw
+ * this glyph
+ * @param width The width of the parent texture
+ * @param height The height (number of rows) of the parent texture
+ */
+ FTTextureGlyph(FT_GlyphSlot glyph, int id, int xOffset, int yOffset,
+ int width, int height);
+
+ /**
+ * Destructor
+ */
+ virtual ~FTTextureGlyph();
+
+ /**
+ * Render this glyph at the current pen position.
+ *
+ * @param pen The current pen position.
+ * @param renderMode Render mode to display
+ * @return The advance distance for this glyph.
+ */
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
+};
+
+#endif //__cplusplus
+
+FTGL_BEGIN_C_DECLS
+
+/**
+ * Create a specialisation of FTGLglyph for creating pixmaps.
+ *
+ * @param glyph The Freetype glyph to be processed.
+ * @param id The id of the texture that this glyph will be drawn in.
+ * @param xOffset The x offset into the parent texture to draw this glyph.
+ * @param yOffset The y offset into the parent texture to draw this glyph.
+ * @param width The width of the parent texture.
+ * @param height The height (number of rows) of the parent texture.
+ * @return An FTGLglyph* object.
+ */
+FTGL_EXPORT FTGLglyph *ftglCreateTextureGlyph(FT_GlyphSlot glyph, int id,
+ int xOffset, int yOffset,
+ int width, int height);
+
+FTGL_END_C_DECLS
+
+#endif // __FTTextureGlyph__
+
diff --git a/src/ftgl/FTGL/ftgl.h b/src/ftgl/FTGL/ftgl.h
new file mode 100644
index 0000000..f5d043c
--- /dev/null
+++ b/src/ftgl/FTGL/ftgl.h
@@ -0,0 +1,135 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __ftgl__
+#define __ftgl__
+
+/* We need the Freetype headers */
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+#include FT_OUTLINE_H
+
+/* Floating point types used by the library */
+typedef double FTGL_DOUBLE;
+typedef float FTGL_FLOAT;
+
+/* Macros used to declare C-linkage types and symbols */
+#ifdef __cplusplus
+# define FTGL_BEGIN_C_DECLS extern "C" { namespace FTGL {
+# define FTGL_END_C_DECLS } }
+#else
+# define FTGL_BEGIN_C_DECLS
+# define FTGL_END_C_DECLS
+#endif
+
+#ifdef __cplusplus
+namespace FTGL
+{
+ typedef enum
+ {
+ RENDER_FRONT = 0x0001,
+ RENDER_BACK = 0x0002,
+ RENDER_SIDE = 0x0004,
+ RENDER_ALL = 0xffff
+ } RenderMode;
+
+ typedef enum
+ {
+ ALIGN_LEFT = 0,
+ ALIGN_CENTER = 1,
+ ALIGN_RIGHT = 2,
+ ALIGN_JUSTIFY = 3
+ } TextAlignment;
+}
+#else
+# define FTGL_RENDER_FRONT 0x0001
+# define FTGL_RENDER_BACK 0x0002
+# define FTGL_RENDER_SIDE 0x0004
+# define FTGL_RENDER_ALL 0xffff
+
+# define FTGL_ALIGN_LEFT 0
+# define FTGL_ALIGN_CENTER 1
+# define FTGL_ALIGN_RIGHT 2
+# define FTGL_ALIGN_JUSTIFY 3
+#endif
+
+// Compiler-specific conditional compilation
+#ifdef _MSC_VER // MS Visual C++
+
+ // Disable various warning.
+ // 4786: template name too long
+ #pragma warning(disable : 4251)
+ #pragma warning(disable : 4275)
+ #pragma warning(disable : 4786)
+
+ // The following definitions control how symbols are exported.
+ // If the target is a static library ensure that FTGL_LIBRARY_STATIC
+ // is defined. If building a dynamic library (ie DLL) ensure the
+ // FTGL_LIBRARY macro is defined, as it will mark symbols for
+ // export. If compiling a project to _use_ the _dynamic_ library
+ // version of the library, no definition is required.
+ #ifdef FTGL_LIBRARY_STATIC // static lib - no special export required
+ # define FTGL_EXPORT
+ #elif FTGL_LIBRARY // dynamic lib - must export/import symbols appropriately.
+ # define FTGL_EXPORT __declspec(dllexport)
+ #else
+ # define FTGL_EXPORT __declspec(dllimport)
+ #endif
+
+#else
+ // Compiler that is not MS Visual C++.
+ // Ensure that the export symbol is defined (and blank)
+ #define FTGL_EXPORT
+#endif
+
+#include <FTGL/FTPoint.h>
+#include <FTGL/FTBBox.h>
+#include <FTGL/FTBuffer.h>
+
+#include <FTGL/FTGlyph.h>
+#include <FTGL/FTBitmapGlyph.h>
+#include <FTGL/FTBufferGlyph.h>
+#include <FTGL/FTExtrdGlyph.h>
+#include <FTGL/FTOutlineGlyph.h>
+#include <FTGL/FTPixmapGlyph.h>
+#include <FTGL/FTPolyGlyph.h>
+#include <FTGL/FTTextureGlyph.h>
+
+#include <FTGL/FTFont.h>
+#include <FTGL/FTGLBitmapFont.h>
+#include <FTGL/FTBufferFont.h>
+#include <FTGL/FTGLExtrdFont.h>
+#include <FTGL/FTGLOutlineFont.h>
+#include <FTGL/FTGLPixmapFont.h>
+#include <FTGL/FTGLPolygonFont.h>
+#include <FTGL/FTGLTextureFont.h>
+
+#include <FTGL/FTLayout.h>
+#include <FTGL/FTSimpleLayout.h>
+
+#endif // __ftgl__
diff --git a/src/ftgl/FTGlyph/FTBitmapGlyph.cpp b/src/ftgl/FTGlyph/FTBitmapGlyph.cpp
new file mode 100644
index 0000000..989c890
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBitmapGlyph.cpp
@@ -0,0 +1,128 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <string>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTBitmapGlyphImpl.h"
+
+
+//
+// FTGLBitmapGlyph
+//
+
+
+FTBitmapGlyph::FTBitmapGlyph(FT_GlyphSlot glyph) :
+ FTGlyph(new FTBitmapGlyphImpl(glyph))
+{}
+
+
+FTBitmapGlyph::~FTBitmapGlyph()
+{}
+
+
+const FTPoint& FTBitmapGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTBitmapGlyphImpl *myimpl = dynamic_cast<FTBitmapGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLBitmapGlyphImpl
+//
+
+
+FTBitmapGlyphImpl::FTBitmapGlyphImpl(FT_GlyphSlot glyph)
+: FTGlyphImpl(glyph),
+ destWidth(0),
+ destHeight(0),
+ data(0)
+{
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_MONO);
+ if(err || ft_glyph_format_bitmap != glyph->format)
+ {
+ return;
+ }
+
+ FT_Bitmap bitmap = glyph->bitmap;
+
+ unsigned int srcWidth = bitmap.width;
+ unsigned int srcHeight = bitmap.rows;
+ unsigned int srcPitch = bitmap.pitch;
+
+ destWidth = srcWidth;
+ destHeight = srcHeight;
+ destPitch = srcPitch;
+
+ if(destWidth && destHeight)
+ {
+ data = new unsigned char[destPitch * destHeight];
+ unsigned char* dest = data + ((destHeight - 1) * destPitch);
+
+ unsigned char* src = bitmap.buffer;
+
+ for(unsigned int y = 0; y < srcHeight; ++y)
+ {
+ memcpy(dest, src, srcPitch);
+ dest -= destPitch;
+ src += srcPitch;
+ }
+ }
+
+ pos = FTPoint(glyph->bitmap_left, static_cast<int>(srcHeight) - glyph->bitmap_top, 0.0);
+}
+
+
+FTBitmapGlyphImpl::~FTBitmapGlyphImpl()
+{
+ delete [] data;
+}
+
+
+const FTPoint& FTBitmapGlyphImpl::RenderImpl(const FTPoint& pen, int renderMode)
+{
+ if(data)
+ {
+ float dx, dy;
+
+ dx = pen.Xf() + pos.Xf();
+ dy = pen.Yf() - pos.Yf();
+
+ glBitmap(0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, destPitch * 8);
+ glBitmap(destWidth, destHeight, 0.0f, 0.0, 0.0, 0.0,
+ (const GLubyte*)data);
+ glBitmap(0, 0, 0.0f, 0.0f, -dx, -dy, (const GLubyte*)0);
+ }
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTBitmapGlyphImpl.h b/src/ftgl/FTGlyph/FTBitmapGlyphImpl.h
new file mode 100644
index 0000000..c61a679
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBitmapGlyphImpl.h
@@ -0,0 +1,71 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTBitmapGlyphImpl__
+#define __FTBitmapGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTBitmapGlyphImpl : public FTGlyphImpl
+{
+ friend class FTBitmapGlyph;
+
+ protected:
+ FTBitmapGlyphImpl(FT_GlyphSlot glyph);
+
+ virtual ~FTBitmapGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ 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 // __FTBitmapGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTBufferGlyph.cpp b/src/ftgl/FTGlyph/FTBufferGlyph.cpp
new file mode 100644
index 0000000..7a78b0e
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBufferGlyph.cpp
@@ -0,0 +1,121 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <string>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTBufferGlyphImpl.h"
+
+
+//
+// FTGLBufferGlyph
+//
+
+
+FTBufferGlyph::FTBufferGlyph(FT_GlyphSlot glyph, FTBuffer *buffer) :
+ FTGlyph(new FTBufferGlyphImpl(glyph, buffer))
+{}
+
+
+FTBufferGlyph::~FTBufferGlyph()
+{}
+
+
+const FTPoint& FTBufferGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTBufferGlyphImpl *myimpl = dynamic_cast<FTBufferGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLBufferGlyphImpl
+//
+
+
+FTBufferGlyphImpl::FTBufferGlyphImpl(FT_GlyphSlot glyph, FTBuffer *p)
+: FTGlyphImpl(glyph),
+ has_bitmap(false),
+ buffer(p)
+{
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
+ if(err || glyph->format != ft_glyph_format_bitmap)
+ {
+ return;
+ }
+
+ bitmap = glyph->bitmap;
+ pixels = new unsigned char[bitmap.pitch * bitmap.rows];
+ memcpy(pixels, bitmap.buffer, bitmap.pitch * bitmap.rows);
+
+ if(bitmap.width && bitmap.rows)
+ {
+ has_bitmap = true;
+ corner = FTPoint(glyph->bitmap_left, glyph->bitmap_top);
+ }
+}
+
+
+FTBufferGlyphImpl::~FTBufferGlyphImpl()
+{
+ delete[] pixels;
+}
+
+
+const FTPoint& FTBufferGlyphImpl::RenderImpl(const FTPoint& pen, int renderMode)
+{
+ if(has_bitmap)
+ {
+ FTPoint pos(buffer->Pos() + pen + corner);
+ int dx = (int)(pos.Xf() + 0.5f);
+ int dy = buffer->Height() - (int)(pos.Yf() + 0.5f);
+ unsigned char * dest = buffer->Pixels() + dx + dy * buffer->Width();
+
+ for(int y = 0; y < bitmap.rows; y++)
+ {
+ // FIXME: change the loop bounds instead of doing this test
+ if(y + dy < 0 || y + dy >= buffer->Height()) continue;
+
+ for(int x = 0; x < bitmap.width; x++)
+ {
+ if(x + dx < 0 || x + dx >= buffer->Width()) continue;
+
+ unsigned char p = pixels[y * bitmap.pitch + x];
+
+ if(p)
+ {
+ dest[y * buffer->Width() + x] = p;
+ }
+ }
+ }
+ }
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTBufferGlyphImpl.h b/src/ftgl/FTGlyph/FTBufferGlyphImpl.h
new file mode 100644
index 0000000..5a15049
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBufferGlyphImpl.h
@@ -0,0 +1,52 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTBufferGlyphImpl__
+#define __FTBufferGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTBufferGlyphImpl : public FTGlyphImpl
+{
+ friend class FTBufferGlyph;
+
+ protected:
+ FTBufferGlyphImpl(FT_GlyphSlot glyph, FTBuffer *p);
+
+ virtual ~FTBufferGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ bool has_bitmap;
+ FT_Bitmap bitmap;
+ unsigned char *pixels;
+ FTPoint corner;
+
+ FTBuffer *buffer;
+};
+
+#endif // __FTBufferGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTExtrudeGlyph.cpp b/src/ftgl/FTGlyph/FTExtrudeGlyph.cpp
new file mode 100644
index 0000000..df0496e
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTExtrudeGlyph.cpp
@@ -0,0 +1,265 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <iostream>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTExtrudeGlyphImpl.h"
+#include "FTVectoriser.h"
+
+
+//
+// FTGLExtrudeGlyph
+//
+
+
+FTExtrudeGlyph::FTExtrudeGlyph(FT_GlyphSlot glyph, float depth,
+ float frontOutset, float backOutset,
+ bool useDisplayList) :
+ FTGlyph(new FTExtrudeGlyphImpl(glyph, depth, frontOutset, backOutset,
+ useDisplayList))
+{}
+
+
+FTExtrudeGlyph::~FTExtrudeGlyph()
+{}
+
+
+const FTPoint& FTExtrudeGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTExtrudeGlyphImpl *myimpl = dynamic_cast<FTExtrudeGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLExtrudeGlyphImpl
+//
+
+
+FTExtrudeGlyphImpl::FTExtrudeGlyphImpl(FT_GlyphSlot glyph, float _depth,
+ float _frontOutset, float _backOutset,
+ bool useDisplayList)
+: FTGlyphImpl(glyph),
+ vectoriser(0),
+ glList(0)
+{
+ bBox.SetDepth(-_depth);
+
+ if(ft_glyph_format_outline != glyph->format)
+ {
+ err = 0x14; // Invalid_Outline
+ return;
+ }
+
+ vectoriser = new FTVectoriser(glyph);
+
+ if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
+ {
+ delete vectoriser;
+ vectoriser = NULL;
+ return;
+ }
+
+ hscale = glyph->face->size->metrics.x_ppem * 64;
+ vscale = glyph->face->size->metrics.y_ppem * 64;
+ depth = _depth;
+ frontOutset = _frontOutset;
+ backOutset = _backOutset;
+
+ if(useDisplayList)
+ {
+ glList = glGenLists(3);
+
+ /* Front face */
+ glNewList(glList + 0, GL_COMPILE);
+ RenderFront();
+ glEndList();
+
+ /* Back face */
+ glNewList(glList + 1, GL_COMPILE);
+ RenderBack();
+ glEndList();
+
+ /* Side face */
+ glNewList(glList + 2, GL_COMPILE);
+ RenderSide();
+ glEndList();
+
+ delete vectoriser;
+ vectoriser = NULL;
+ }
+}
+
+
+FTExtrudeGlyphImpl::~FTExtrudeGlyphImpl()
+{
+ if(glList)
+ {
+ glDeleteLists(glList, 3);
+ }
+ else if(vectoriser)
+ {
+ delete vectoriser;
+ }
+}
+
+
+const FTPoint& FTExtrudeGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ glTranslatef(pen.Xf(), pen.Yf(), pen.Zf());
+ if(glList)
+ {
+ if(renderMode & FTGL::RENDER_FRONT)
+ glCallList(glList + 0);
+ if(renderMode & FTGL::RENDER_BACK)
+ glCallList(glList + 1);
+ if(renderMode & FTGL::RENDER_SIDE)
+ glCallList(glList + 2);
+ }
+ else if(vectoriser)
+ {
+ if(renderMode & FTGL::RENDER_FRONT)
+ RenderFront();
+ if(renderMode & FTGL::RENDER_BACK)
+ RenderBack();
+ if(renderMode & FTGL::RENDER_SIDE)
+ RenderSide();
+ }
+ glTranslatef(-pen.Xf(), -pen.Yf(), -pen.Zf());
+
+ return advance;
+}
+
+
+void FTExtrudeGlyphImpl::RenderFront()
+{
+ vectoriser->MakeMesh(1.0, 1, frontOutset);
+ glNormal3d(0.0, 0.0, 1.0);
+
+ const FTMesh *mesh = vectoriser->GetMesh();
+ for(unsigned int j = 0; j < mesh->TesselationCount(); ++j)
+ {
+ const FTTesselation* subMesh = mesh->Tesselation(j);
+ unsigned int polygonType = subMesh->PolygonType();
+
+ glBegin(polygonType);
+ for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+ {
+ FTPoint pt = subMesh->Point(i);
+
+ glTexCoord2f(pt.Xf() / hscale,
+ pt.Yf() / vscale);
+
+ glVertex3f(pt.Xf() / 64.0f,
+ pt.Yf() / 64.0f,
+ 0.0f);
+ }
+ glEnd();
+ }
+}
+
+
+void FTExtrudeGlyphImpl::RenderBack()
+{
+ vectoriser->MakeMesh(-1.0, 2, backOutset);
+ glNormal3d(0.0, 0.0, -1.0);
+
+ const FTMesh *mesh = vectoriser->GetMesh();
+ for(unsigned int j = 0; j < mesh->TesselationCount(); ++j)
+ {
+ const FTTesselation* subMesh = mesh->Tesselation(j);
+ unsigned int polygonType = subMesh->PolygonType();
+
+ glBegin(polygonType);
+ for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+ {
+ FTPoint pt = subMesh->Point(i);
+
+ glTexCoord2f(subMesh->Point(i).Xf() / hscale,
+ subMesh->Point(i).Yf() / vscale);
+
+ glVertex3f(subMesh->Point(i).Xf() / 64.0f,
+ subMesh->Point(i).Yf() / 64.0f,
+ -depth);
+ }
+ glEnd();
+ }
+}
+
+
+void FTExtrudeGlyphImpl::RenderSide()
+{
+ int contourFlag = vectoriser->ContourFlag();
+
+ for(size_t c = 0; c < vectoriser->ContourCount(); ++c)
+ {
+ const FTContour* contour = vectoriser->Contour(c);
+ size_t n = contour->PointCount();
+
+ if(n < 2)
+ {
+ continue;
+ }
+
+ glBegin(GL_QUAD_STRIP);
+ for(size_t j = 0; j <= n; ++j)
+ {
+ size_t cur = (j == n) ? 0 : j;
+ size_t next = (cur == n - 1) ? 0 : cur + 1;
+
+ FTPoint frontPt = contour->FrontPoint(cur);
+ FTPoint nextPt = contour->FrontPoint(next);
+ FTPoint backPt = contour->BackPoint(cur);
+
+ FTPoint normal = FTPoint(0.f, 0.f, 1.f) ^ (frontPt - nextPt);
+ if(normal != FTPoint(0.0f, 0.0f, 0.0f))
+ {
+ glNormal3dv(static_cast<const FTGL_DOUBLE*>(normal.Normalise()));
+ }
+
+ glTexCoord2f(frontPt.Xf() / hscale, frontPt.Yf() / vscale);
+
+ if(contourFlag & ft_outline_reverse_fill)
+ {
+ glVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, 0.0f);
+ glVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, -depth);
+ }
+ else
+ {
+ glVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, -depth);
+ glVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, 0.0f);
+ }
+ }
+ glEnd();
+ }
+}
+
diff --git a/src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h b/src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h
new file mode 100644
index 0000000..7c547c7
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h
@@ -0,0 +1,69 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTExtrudeGlyphImpl__
+#define __FTExtrudeGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTVectoriser;
+
+class FTExtrudeGlyphImpl : public FTGlyphImpl
+{
+ friend class FTExtrudeGlyph;
+
+ protected:
+ FTExtrudeGlyphImpl(FT_GlyphSlot glyph, float depth, float frontOutset,
+ float backOutset, bool useDisplayList);
+
+ virtual ~FTExtrudeGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Private rendering methods.
+ */
+ void RenderFront();
+ void RenderBack();
+ void RenderSide();
+
+ /**
+ * Private rendering variables.
+ */
+ unsigned int hscale, vscale;
+ float depth;
+ float frontOutset, backOutset;
+ FTVectoriser *vectoriser;
+
+ /**
+ * OpenGL display list
+ */
+ GLuint glList;
+};
+
+#endif // __FTExtrudeGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTGlyph.cpp b/src/ftgl/FTGlyph/FTGlyph.cpp
new file mode 100644
index 0000000..4d3dff6
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTGlyph.cpp
@@ -0,0 +1,112 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTGlyphImpl.h"
+
+
+//
+// FTGlyph
+//
+
+
+FTGlyph::FTGlyph(FT_GlyphSlot glyph)
+{
+ impl = new FTGlyphImpl(glyph);
+}
+
+
+FTGlyph::FTGlyph(FTGlyphImpl *pImpl)
+{
+ impl = pImpl;
+}
+
+
+FTGlyph::~FTGlyph()
+{
+ delete impl;
+}
+
+
+float FTGlyph::Advance() const
+{
+ return impl->Advance();
+}
+
+
+const FTBBox& FTGlyph::BBox() const
+{
+ return impl->BBox();
+}
+
+
+FT_Error FTGlyph::Error() const
+{
+ return impl->Error();
+}
+
+
+//
+// FTGlyphImpl
+//
+
+
+FTGlyphImpl::FTGlyphImpl(FT_GlyphSlot glyph, bool useList) : err(0)
+{
+ if(glyph)
+ {
+ bBox = FTBBox(glyph);
+ advance = FTPoint(glyph->advance.x / 64.0f,
+ glyph->advance.y / 64.0f);
+ }
+}
+
+
+FTGlyphImpl::~FTGlyphImpl()
+{}
+
+
+float FTGlyphImpl::Advance() const
+{
+ return advance.Xf();
+}
+
+
+const FTBBox& FTGlyphImpl::BBox() const
+{
+ return bBox;
+}
+
+
+FT_Error FTGlyphImpl::Error() const
+{
+ return err;
+}
+
diff --git a/src/ftgl/FTGlyph/FTGlyphGlue.cpp b/src/ftgl/FTGlyph/FTGlyphGlue.cpp
new file mode 100644
index 0000000..0fbbc01
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTGlyphGlue.cpp
@@ -0,0 +1,198 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+
+static const FTPoint static_ftpoint;
+static const FTBBox static_ftbbox;
+
+FTGL_BEGIN_C_DECLS
+
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLglyph* cname cargs \
+ { \
+ cxxname *g = new cxxname cxxarg; \
+ if(g->Error()) \
+ { \
+ delete g; \
+ return NULL; \
+ } \
+ FTGLglyph *ftgl = (FTGLglyph *)malloc(sizeof(FTGLglyph)); \
+ ftgl->ptr = g; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
+ }
+
+// FTBitmapGlyph::FTBitmapGlyph();
+C_TOR(ftglCreateBitmapGlyph, (FT_GlyphSlot glyph),
+ FTBitmapGlyph, (glyph), GLYPH_BITMAP);
+
+// FTBufferGlyph::FTBufferGlyph();
+// FIXME: not implemented
+
+// FTExtrudeGlyph::FTExtrudeGlyph();
+C_TOR(ftglCreateExtrudeGlyph, (FT_GlyphSlot glyph, float depth,
+ float frontOutset, float backOutset, int useDisplayList),
+ FTExtrudeGlyph, (glyph, depth, frontOutset, backOutset, (useDisplayList != 0)),
+ GLYPH_EXTRUDE);
+
+// FTOutlineGlyph::FTOutlineGlyph();
+C_TOR(ftglCreateOutlineGlyph, (FT_GlyphSlot glyph, float outset,
+ int useDisplayList),
+ FTOutlineGlyph, (glyph, outset, (useDisplayList != 0)), GLYPH_OUTLINE);
+
+// FTPixmapGlyph::FTPixmapGlyph();
+C_TOR(ftglCreatePixmapGlyph, (FT_GlyphSlot glyph),
+ FTPixmapGlyph, (glyph), GLYPH_PIXMAP);
+
+// FTPolygonGlyph::FTPolygonGlyph();
+C_TOR(ftglCreatePolygonGlyph, (FT_GlyphSlot glyph, float outset,
+ int useDisplayList),
+ FTPolygonGlyph, (glyph, outset, (useDisplayList != 0)), GLYPH_POLYGON);
+
+// FTTextureGlyph::FTTextureGlyph();
+C_TOR(ftglCreateTextureGlyph, (FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height),
+ FTTextureGlyph, (glyph, id, xOffset, yOffset, width, height),
+ GLYPH_TEXTURE);
+
+// FTCustomGlyph::FTCustomGlyph();
+class FTCustomGlyph : public FTGlyph
+{
+public:
+ FTCustomGlyph(FTGLglyph *base, void *p,
+ void (*render) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *),
+ void (*destroy) (FTGLglyph *, void *))
+ : FTGlyph((FT_GlyphSlot)0),
+ baseGlyph(base),
+ data(p),
+ renderCallback(render),
+ destroyCallback(destroy)
+ {}
+
+ ~FTCustomGlyph()
+ {
+ destroyCallback(baseGlyph, data);
+ }
+
+ float Advance() const { return baseGlyph->ptr->Advance(); }
+
+ const FTPoint& Render(const FTPoint& pen, int renderMode)
+ {
+ FTGL_DOUBLE advancex, advancey;
+ renderCallback(baseGlyph, data, pen.X(), pen.Y(), renderMode,
+ &advancex, &advancey);
+ advance = FTPoint(advancex, advancey);
+ return advance;
+ }
+
+ const FTBBox& BBox() const { return baseGlyph->ptr->BBox(); }
+
+ FT_Error Error() const { return baseGlyph->ptr->Error(); }
+
+private:
+ FTPoint advance;
+ FTGLglyph *baseGlyph;
+ void *data;
+ void (*renderCallback) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *);
+ void (*destroyCallback) (FTGLglyph *, void *);
+};
+
+C_TOR(ftglCreateCustomGlyph, (FTGLglyph *base, void *data,
+ void (*renderCallback) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *),
+ void (*destroyCallback) (FTGLglyph *, void *)),
+ FTCustomGlyph, (base, data, renderCallback, destroyCallback),
+ GLYPH_CUSTOM);
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!g || !g->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ return g->ptr->cxxname cxxarg; \
+ }
+
+// FTGlyph::~FTGlyph();
+void ftglDestroyGlyph(FTGLglyph *g)
+{
+ if(!g || !g->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return;
+ }
+ delete g->ptr;
+ free(g);
+}
+
+// const FTPoint& FTGlyph::Render(const FTPoint& pen, int renderMode);
+extern "C++" {
+C_FUN(static const FTPoint&, _ftglRenderGlyph, (FTGLglyph *g,
+ const FTPoint& pen, int renderMode),
+ return static_ftpoint, Render, (pen, renderMode));
+}
+
+void ftglRenderGlyph(FTGLglyph *g, FTGL_DOUBLE penx, FTGL_DOUBLE peny,
+ int renderMode, FTGL_DOUBLE *advancex,
+ FTGL_DOUBLE *advancey)
+{
+ FTPoint pen(penx, peny);
+ FTPoint ret = _ftglRenderGlyph(g, pen, renderMode);
+ *advancex = ret.X();
+ *advancey = ret.Y();
+}
+
+// float FTGlyph::Advance() const;
+C_FUN(float, ftglGetGlyphAdvance, (FTGLglyph *g), return 0.0, Advance, ());
+
+// const FTBBox& FTGlyph::BBox() const;
+extern "C++" {
+C_FUN(static const FTBBox&, _ftglGetGlyphBBox, (FTGLglyph *g),
+ return static_ftbbox, BBox, ());
+}
+
+void ftglGetGlyphBBox(FTGLglyph *g, float bounds[6])
+{
+ FTBBox ret = _ftglGetGlyphBBox(g);
+ FTPoint lower = ret.Lower(), upper = ret.Upper();
+ bounds[0] = lower.Xf(); bounds[1] = lower.Yf(); bounds[2] = lower.Zf();
+ bounds[3] = upper.Xf(); bounds[4] = upper.Yf(); bounds[5] = upper.Zf();
+}
+
+// FT_Error FTGlyph::Error() const;
+C_FUN(FT_Error, ftglGetGlyphError, (FTGLglyph *g), return -1, Error, ());
+
+FTGL_END_C_DECLS
+
diff --git a/src/ftgl/FTGlyph/FTGlyphImpl.h b/src/ftgl/FTGlyph/FTGlyphImpl.h
new file mode 100644
index 0000000..37ea96f
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTGlyphImpl.h
@@ -0,0 +1,64 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTGlyphImpl__
+#define __FTGlyphImpl__
+
+#include "FTGL/ftgl.h"
+
+class FTGlyphImpl
+{
+ friend class FTGlyph;
+
+ protected:
+ FTGlyphImpl(FT_GlyphSlot glyph, bool useDisplayList = true);
+
+ virtual ~FTGlyphImpl();
+
+ float Advance() const;
+
+ const FTBBox& BBox() const;
+
+ FT_Error Error() const;
+
+ /**
+ * The advance distance for this glyph
+ */
+ FTPoint advance;
+
+ /**
+ * The bounding box of this glyph.
+ */
+ FTBBox bBox;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+};
+
+#endif // __FTGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTOutlineGlyph.cpp b/src/ftgl/FTGlyph/FTOutlineGlyph.cpp
new file mode 100644
index 0000000..48e11f7
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTOutlineGlyph.cpp
@@ -0,0 +1,149 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTOutlineGlyphImpl.h"
+#include "FTVectoriser.h"
+
+
+//
+// FTGLOutlineGlyph
+//
+
+
+FTOutlineGlyph::FTOutlineGlyph(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList) :
+ FTGlyph(new FTOutlineGlyphImpl(glyph, outset, useDisplayList))
+{}
+
+
+FTOutlineGlyph::~FTOutlineGlyph()
+{}
+
+
+const FTPoint& FTOutlineGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTOutlineGlyphImpl *myimpl = dynamic_cast<FTOutlineGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLOutlineGlyphImpl
+//
+
+
+FTOutlineGlyphImpl::FTOutlineGlyphImpl(FT_GlyphSlot glyph, float _outset,
+ bool useDisplayList)
+: FTGlyphImpl(glyph),
+ glList(0)
+{
+ if(ft_glyph_format_outline != glyph->format)
+ {
+ err = 0x14; // Invalid_Outline
+ return;
+ }
+
+ vectoriser = new FTVectoriser(glyph);
+
+ if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
+ {
+ delete vectoriser;
+ vectoriser = NULL;
+ return;
+ }
+
+ outset = _outset;
+
+ if(useDisplayList)
+ {
+ glList = glGenLists(1);
+ glNewList(glList, GL_COMPILE);
+
+ DoRender();
+
+ glEndList();
+
+ delete vectoriser;
+ vectoriser = NULL;
+ }
+}
+
+
+FTOutlineGlyphImpl::~FTOutlineGlyphImpl()
+{
+ if(glList)
+ {
+ glDeleteLists(glList, 1);
+ }
+ else if(vectoriser)
+ {
+ delete vectoriser;
+ }
+}
+
+
+const FTPoint& FTOutlineGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ glTranslatef(pen.Xf(), pen.Yf(), pen.Zf());
+ if(glList)
+ {
+ glCallList(glList);
+ }
+ else if(vectoriser)
+ {
+ DoRender();
+ }
+ glTranslatef(-pen.Xf(), -pen.Yf(), -pen.Zf());
+
+ return advance;
+}
+
+
+void FTOutlineGlyphImpl::DoRender()
+{
+ for(unsigned int c = 0; c < vectoriser->ContourCount(); ++c)
+ {
+ const FTContour* contour = vectoriser->Contour(c);
+
+ glBegin(GL_LINE_LOOP);
+ for(unsigned int i = 0; i < contour->PointCount(); ++i)
+ {
+ FTPoint point = FTPoint(contour->Point(i).X() + contour->Outset(i).X() * outset,
+ contour->Point(i).Y() + contour->Outset(i).Y() * outset,
+ 0);
+ glVertex2f(point.Xf() / 64.0f, point.Yf() / 64.0f);
+ }
+ glEnd();
+ }
+}
+
diff --git a/src/ftgl/FTGlyph/FTOutlineGlyphImpl.h b/src/ftgl/FTGlyph/FTOutlineGlyphImpl.h
new file mode 100644
index 0000000..ead4b12
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTOutlineGlyphImpl.h
@@ -0,0 +1,69 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTOutlineGlyphImpl__
+#define __FTOutlineGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTVectoriser;
+
+class FTOutlineGlyphImpl : public FTGlyphImpl
+{
+ friend class FTOutlineGlyph;
+
+ protected:
+ FTOutlineGlyphImpl(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList);
+
+ virtual ~FTOutlineGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Private rendering method.
+ */
+ void DoRender();
+
+ /**
+ * Private rendering variables.
+ */
+ FTVectoriser *vectoriser;
+
+ /**
+ * Private rendering variables.
+ */
+ float outset;
+
+ /**
+ * OpenGL display list
+ */
+ GLuint glList;
+};
+
+#endif // __FTOutlineGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTPixmapGlyph.cpp b/src/ftgl/FTGlyph/FTPixmapGlyph.cpp
new file mode 100644
index 0000000..5301e43
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPixmapGlyph.cpp
@@ -0,0 +1,139 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTPixmapGlyphImpl.h"
+
+
+//
+// FTGLPixmapGlyph
+//
+
+
+FTPixmapGlyph::FTPixmapGlyph(FT_GlyphSlot glyph) :
+ FTGlyph(new FTPixmapGlyphImpl(glyph))
+{}
+
+
+FTPixmapGlyph::~FTPixmapGlyph()
+{}
+
+
+const FTPoint& FTPixmapGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTPixmapGlyphImpl *myimpl = dynamic_cast<FTPixmapGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLPixmapGlyphImpl
+//
+
+
+FTPixmapGlyphImpl::FTPixmapGlyphImpl(FT_GlyphSlot glyph)
+: FTGlyphImpl(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);
+}
+
+
+FTPixmapGlyphImpl::~FTPixmapGlyphImpl()
+{
+ delete [] data;
+}
+
+
+const FTPoint& FTPixmapGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ if(data)
+ {
+ float dx, dy;
+
+ dx = floor(pen.Xf() + pos.Xf());
+ dy = floor(pen.Yf() - pos.Yf());
+
+ glBitmap(0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
+ 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, -dx, -dy, (const GLubyte*)0);
+ }
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTPixmapGlyphImpl.h b/src/ftgl/FTGlyph/FTPixmapGlyphImpl.h
new file mode 100644
index 0000000..8331469
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPixmapGlyphImpl.h
@@ -0,0 +1,67 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTPixmapGlyphImpl__
+#define __FTPixmapGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTPixmapGlyphImpl : public FTGlyphImpl
+{
+ friend class FTPixmapGlyph;
+
+ protected:
+ FTPixmapGlyphImpl(FT_GlyphSlot glyph);
+
+ virtual ~FTPixmapGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ 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 // __FTPixmapGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTPolygonGlyph.cpp b/src/ftgl/FTGlyph/FTPolygonGlyph.cpp
new file mode 100644
index 0000000..6db3581
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPolygonGlyph.cpp
@@ -0,0 +1,156 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTPolygonGlyphImpl.h"
+#include "FTVectoriser.h"
+
+
+//
+// FTGLPolyGlyph
+//
+
+
+FTPolygonGlyph::FTPolygonGlyph(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList) :
+ FTGlyph(new FTPolygonGlyphImpl(glyph, outset, useDisplayList))
+{}
+
+
+FTPolygonGlyph::~FTPolygonGlyph()
+{}
+
+
+const FTPoint& FTPolygonGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTPolygonGlyphImpl *myimpl = dynamic_cast<FTPolygonGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLPolyGlyphImpl
+//
+
+
+FTPolygonGlyphImpl::FTPolygonGlyphImpl(FT_GlyphSlot glyph, float _outset,
+ bool useDisplayList)
+: FTGlyphImpl(glyph),
+ glList(0)
+{
+ if(ft_glyph_format_outline != glyph->format)
+ {
+ err = 0x14; // Invalid_Outline
+ return;
+ }
+
+ vectoriser = new FTVectoriser(glyph);
+
+ if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
+ {
+ delete vectoriser;
+ vectoriser = NULL;
+ return;
+ }
+
+
+ hscale = glyph->face->size->metrics.x_ppem * 64;
+ vscale = glyph->face->size->metrics.y_ppem * 64;
+ outset = _outset;
+
+ if(useDisplayList)
+ {
+ glList = glGenLists(1);
+ glNewList(glList, GL_COMPILE);
+
+ DoRender();
+
+ glEndList();
+
+ delete vectoriser;
+ vectoriser = NULL;
+ }
+}
+
+
+FTPolygonGlyphImpl::~FTPolygonGlyphImpl()
+{
+ if(glList)
+ {
+ glDeleteLists(glList, 1);
+ }
+ else if(vectoriser)
+ {
+ delete vectoriser;
+ }
+}
+
+
+const FTPoint& FTPolygonGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ glTranslatef(pen.Xf(), pen.Yf(), pen.Zf());
+ if(glList)
+ {
+ glCallList(glList);
+ }
+ else if(vectoriser)
+ {
+ DoRender();
+ }
+ glTranslatef(-pen.Xf(), -pen.Yf(), -pen.Zf());
+
+ return advance;
+}
+
+
+void FTPolygonGlyphImpl::DoRender()
+{
+ vectoriser->MakeMesh(1.0, 1, outset);
+
+ const FTMesh *mesh = vectoriser->GetMesh();
+
+ for(unsigned int t = 0; t < mesh->TesselationCount(); ++t)
+ {
+ const FTTesselation* subMesh = mesh->Tesselation(t);
+ unsigned int polygonType = subMesh->PolygonType();
+
+ glBegin(polygonType);
+ for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+ {
+ FTPoint point = subMesh->Point(i);
+ glTexCoord2f(point.Xf() / hscale, point.Yf() / vscale);
+ glVertex3f(point.Xf() / 64.0f, point.Yf() / 64.0f, 0.0f);
+ }
+ glEnd();
+ }
+}
+
diff --git a/src/ftgl/FTGlyph/FTPolygonGlyphImpl.h b/src/ftgl/FTGlyph/FTPolygonGlyphImpl.h
new file mode 100644
index 0000000..e353391
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPolygonGlyphImpl.h
@@ -0,0 +1,66 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTPolygonGlyphImpl__
+#define __FTPolygonGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTVectoriser;
+
+class FTPolygonGlyphImpl : public FTGlyphImpl
+{
+ friend class FTPolygonGlyph;
+
+ public:
+ FTPolygonGlyphImpl(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList);
+
+ virtual ~FTPolygonGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Private rendering method.
+ */
+ void DoRender();
+
+ /**
+ * Private rendering variables.
+ */
+ unsigned int hscale, vscale;
+ FTVectoriser *vectoriser;
+ float outset;
+
+ /**
+ * OpenGL display list
+ */
+ GLuint glList;
+};
+
+#endif // __FTPolygonGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTTextureGlyph.cpp b/src/ftgl/FTGlyph/FTTextureGlyph.cpp
new file mode 100644
index 0000000..a9cf2e8
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTTextureGlyph.cpp
@@ -0,0 +1,153 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTTextureGlyphImpl.h"
+
+
+//
+// FTGLTextureGlyph
+//
+
+
+FTTextureGlyph::FTTextureGlyph(FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height) :
+ FTGlyph(new FTTextureGlyphImpl(glyph, id, xOffset, yOffset, width, height))
+{}
+
+
+FTTextureGlyph::~FTTextureGlyph()
+{}
+
+
+const FTPoint& FTTextureGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTTextureGlyphImpl *myimpl = dynamic_cast<FTTextureGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLTextureGlyphImpl
+//
+
+
+GLint FTTextureGlyphImpl::activeTextureID = 0;
+
+FTTextureGlyphImpl::FTTextureGlyphImpl(FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height)
+: FTGlyphImpl(glyph),
+ destWidth(0),
+ destHeight(0),
+ glTextureID(id)
+{
+ /* FIXME: need to propagate the render mode all the way down to
+ * here in order to get FT_RENDER_MODE_MONO aliased fonts.
+ */
+
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
+ if(err || glyph->format != ft_glyph_format_bitmap)
+ {
+ return;
+ }
+
+ FT_Bitmap bitmap = glyph->bitmap;
+
+ destWidth = bitmap.width;
+ destHeight = bitmap.rows;
+
+ if(destWidth && destHeight)
+ {
+ glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+ glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glBindTexture(GL_TEXTURE_2D, glTextureID);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
+
+ glPopClientAttrib();
+ }
+
+
+// 0
+// +----+
+// | |
+// | |
+// | |
+// +----+
+// 1
+
+ uv[0].X(static_cast<float>(xOffset) / static_cast<float>(width));
+ uv[0].Y(static_cast<float>(yOffset) / static_cast<float>(height));
+ uv[1].X(static_cast<float>(xOffset + destWidth) / static_cast<float>(width));
+ uv[1].Y(static_cast<float>(yOffset + destHeight) / static_cast<float>(height));
+
+ corner = FTPoint(glyph->bitmap_left, glyph->bitmap_top);
+}
+
+
+FTTextureGlyphImpl::~FTTextureGlyphImpl()
+{}
+
+
+const FTPoint& FTTextureGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ float dx, dy;
+
+ if(activeTextureID != glTextureID)
+ {
+ glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID);
+ activeTextureID = glTextureID;
+ }
+
+ dx = floor(pen.Xf() + corner.Xf());
+ dy = floor(pen.Yf() + corner.Yf());
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(uv[0].Xf(), uv[0].Yf());
+ glVertex2f(dx, dy);
+
+ glTexCoord2f(uv[0].Xf(), uv[1].Yf());
+ glVertex2f(dx, dy - destHeight);
+
+ glTexCoord2f(uv[1].Xf(), uv[1].Yf());
+ glVertex2f(dx + destWidth, dy - destHeight);
+
+ glTexCoord2f(uv[1].Xf(), uv[0].Yf());
+ glVertex2f(dx + destWidth, dy);
+ glEnd();
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTTextureGlyphImpl.h b/src/ftgl/FTGlyph/FTTextureGlyphImpl.h
new file mode 100644
index 0000000..793af04
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTTextureGlyphImpl.h
@@ -0,0 +1,88 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTTextureGlyphImpl__
+#define __FTTextureGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTTextureGlyphImpl : public FTGlyphImpl
+{
+ friend class FTTextureGlyph;
+ friend class FTTextureFontImpl;
+
+ protected:
+ FTTextureGlyphImpl(FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height);
+
+ virtual ~FTTextureGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Reset the currently active texture to zero to get into a known
+ * state before drawing a string. This is to get round possible
+ * threading issues.
+ */
+ static void ResetActiveTexture() { activeTextureID = 0; }
+
+ /**
+ * 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 corner;
+
+ /**
+ * The texture co-ords of this glyph within the texture.
+ */
+ FTPoint uv[2];
+
+ /**
+ * The texture index that this glyph is contained in.
+ */
+ int glTextureID;
+
+ /**
+ * The texture index of the currently active texture
+ *
+ * We keep track of the currently active texture to try to reduce the
+ * number of texture bind operations.
+ */
+ static GLint activeTextureID;
+};
+
+#endif // __FTTextureGlyphImpl__
+
diff --git a/src/ftgl/FTGlyphContainer.cpp b/src/ftgl/FTGlyphContainer.cpp
new file mode 100644
index 0000000..54c1de4
--- /dev/null
+++ b/src/ftgl/FTGlyphContainer.cpp
@@ -0,0 +1,119 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTGlyphContainer.h"
+#include "FTFace.h"
+#include "FTCharmap.h"
+
+
+FTGlyphContainer::FTGlyphContainer(FTFace* f)
+: face(f),
+ err(0)
+{
+ glyphs.push_back(NULL);
+ charMap = new FTCharmap(face);
+}
+
+
+FTGlyphContainer::~FTGlyphContainer()
+{
+ GlyphVector::iterator it;
+ for(it = glyphs.begin(); it != glyphs.end(); ++it)
+ {
+ delete *it;
+ }
+
+ glyphs.clear();
+ delete charMap;
+}
+
+
+bool FTGlyphContainer::CharMap(FT_Encoding encoding)
+{
+ bool result = charMap->CharMap(encoding);
+ err = charMap->Error();
+ return result;
+}
+
+
+unsigned int FTGlyphContainer::FontIndex(const unsigned int charCode) const
+{
+ return charMap->FontIndex(charCode);
+}
+
+
+void FTGlyphContainer::Add(FTGlyph* tempGlyph, const unsigned int charCode)
+{
+ charMap->InsertIndex(charCode, glyphs.size());
+ glyphs.push_back(tempGlyph);
+}
+
+
+const FTGlyph* const FTGlyphContainer::Glyph(const unsigned int charCode) const
+{
+ unsigned int index = charMap->GlyphListIndex(charCode);
+ return glyphs[index];
+}
+
+
+FTBBox FTGlyphContainer::BBox(const unsigned int charCode) const
+{
+ return Glyph(charCode)->BBox();
+}
+
+
+float FTGlyphContainer::Advance(const unsigned int charCode,
+ const unsigned int nextCharCode)
+{
+ unsigned int left = charMap->FontIndex(charCode);
+ unsigned int right = charMap->FontIndex(nextCharCode);
+
+ return face->KernAdvance(left, right).Xf() + Glyph(charCode)->Advance();
+}
+
+
+FTPoint FTGlyphContainer::Render(const unsigned int charCode,
+ const unsigned int nextCharCode,
+ FTPoint penPosition, int renderMode)
+{
+ unsigned int left = charMap->FontIndex(charCode);
+ unsigned int right = charMap->FontIndex(nextCharCode);
+
+ FTPoint kernAdvance = face->KernAdvance(left, right);
+
+ if(!face->Error())
+ {
+ unsigned int index = charMap->GlyphListIndex(charCode);
+ kernAdvance += glyphs[index]->Render(penPosition, renderMode);
+ }
+
+ return kernAdvance;
+}
+
diff --git a/src/ftgl/FTGlyphContainer.h b/src/ftgl/FTGlyphContainer.h
new file mode 100644
index 0000000..d4bbb74
--- /dev/null
+++ b/src/ftgl/FTGlyphContainer.h
@@ -0,0 +1,155 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTGlyphContainer__
+#define __FTGlyphContainer__
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+#include "FTGL/ftgl.h"
+
+#include "FTVector.h"
+
+class FTFace;
+class FTGlyph;
+class FTCharmap;
+
+/**
+ * FTGlyphContainer holds the post processed FTGlyph objects.
+ *
+ * @see FTGlyph
+ */
+class FTGlyphContainer
+{
+ typedef FTVector<FTGlyph*> GlyphVector;
+ public:
+ /**
+ * Constructor
+ *
+ * @param face The Freetype face
+ */
+ FTGlyphContainer(FTFace* face);
+
+ /**
+ * Destructor
+ */
+ ~FTGlyphContainer();
+
+ /**
+ * Sets the character map for the face.
+ *
+ * @param encoding the Freetype encoding symbol. See above.
+ * @return <code>true</code> if charmap was valid
+ * and set correctly
+ */
+ bool CharMap(FT_Encoding encoding);
+
+ /**
+ * Get the font index of the input character.
+ *
+ * @param characterCode The character code of the requested glyph in the
+ * current encoding eg apple roman.
+ * @return The font index for the character.
+ */
+ unsigned int FontIndex(const unsigned int characterCode) const;
+
+ /**
+ * Adds a glyph to this glyph list.
+ *
+ * @param glyph The FTGlyph to be inserted into the container
+ * @param characterCode The char code of the glyph NOT the glyph index.
+ */
+ void Add(FTGlyph* glyph, const unsigned int characterCode);
+
+ /**
+ * Get a glyph from the glyph list
+ *
+ * @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.
+ */
+ const FTGlyph* const Glyph(const unsigned int characterCode) const;
+
+ /**
+ * Get the bounding box for a character.
+ * @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.
+ *
+ * @param characterCode glyph index of the character
+ * @param nextCharacterCode the next glyph in a string
+ * @return advance width
+ */
+ float Advance(const unsigned int characterCode,
+ const unsigned int nextCharacterCode);
+
+ /**
+ * Renders a character
+ * @param characterCode the glyph to be Rendered
+ * @param nextCharacterCode the next glyph in the string. Used for kerning.
+ * @param penPosition the position to Render the glyph
+ * @param renderMode Render mode to display
+ * @return The distance to advance the pen position after Rendering
+ */
+ FTPoint Render(const unsigned int characterCode,
+ const unsigned int nextCharacterCode,
+ FTPoint penPosition, int renderMode);
+
+ /**
+ * Queries the Font for errors.
+ *
+ * @return The current error code.
+ */
+ FT_Error Error() const { return err; }
+
+ private:
+ /**
+ * The FTGL face
+ */
+ FTFace* face;
+
+ /**
+ * The Character Map object associated with the current face
+ */
+ FTCharmap* charMap;
+
+ /**
+ * A structure to hold the glyphs
+ */
+ GlyphVector glyphs;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+};
+
+
+#endif // __FTGlyphContainer__
diff --git a/src/ftgl/FTInternals.h b/src/ftgl/FTInternals.h
new file mode 100644
index 0000000..61e1f94
--- /dev/null
+++ b/src/ftgl/FTInternals.h
@@ -0,0 +1,145 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTINTERNALS_H__
+#define __FTINTERNALS_H__
+
+#include "FTGL/ftgl.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+
+// Fixes for deprecated identifiers in 2.1.5
+#ifndef FT_OPEN_MEMORY
+ #define FT_OPEN_MEMORY (FT_Open_Flags)1
+#endif
+
+#ifndef FT_RENDER_MODE_MONO
+ #define FT_RENDER_MODE_MONO ft_render_mode_mono
+#endif
+
+#ifndef FT_RENDER_MODE_NORMAL
+ #define FT_RENDER_MODE_NORMAL ft_render_mode_normal
+#endif
+
+
+#ifdef WIN32
+
+ // Under windows avoid including <windows.h> is overrated.
+ // Sure, it can be avoided and "name space pollution" can be
+ // avoided, but why? It really doesn't make that much difference
+ // these days.
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+
+ #ifndef __gl_h_
+ #include <GL/gl.h>
+ #include <GL/glu.h>
+ #endif
+
+#else
+
+ // Non windows platforms - don't require nonsense as seen above :-)
+ #ifndef __gl_h_
+ #ifdef SDL_main
+ #include "SDL_opengl.h"
+ #elif __APPLE_CC__
+ #include <OpenGL/gl.h>
+ #include <OpenGL/glu.h>
+ #else
+ #include <GL/gl.h>
+ #if defined (__sun__) && !defined (__sparc__)
+ #include <mesa/glu.h>
+ #else
+ #include <GL/glu.h>
+ #endif
+ #endif
+
+ #endif
+
+ // Required for compatibility with glext.h style function definitions of
+ // OpenGL extensions, such as in src/osg/Point.cpp.
+ #ifndef APIENTRY
+ #define APIENTRY
+ #endif
+#endif
+
+FTGL_BEGIN_C_DECLS
+
+typedef enum
+{
+ GLYPH_CUSTOM,
+ GLYPH_BITMAP,
+ GLYPH_BUFFER,
+ GLYPH_PIXMAP,
+ GLYPH_OUTLINE,
+ GLYPH_POLYGON,
+ GLYPH_EXTRUDE,
+ GLYPH_TEXTURE,
+} GlyphType;
+
+struct _FTGLglyph
+{
+ FTGlyph *ptr;
+ FTGL::GlyphType type;
+};
+
+typedef enum
+{
+ FONT_CUSTOM,
+ FONT_BITMAP,
+ FONT_BUFFER,
+ FONT_PIXMAP,
+ FONT_OUTLINE,
+ FONT_POLYGON,
+ FONT_EXTRUDE,
+ FONT_TEXTURE,
+} FontType;
+
+struct _FTGLfont
+{
+ FTFont *ptr;
+ FTGL::FontType type;
+};
+
+typedef enum
+{
+ LAYOUT_SIMPLE,
+} LayoutType;
+
+struct _FTGLlayout
+{
+ FTLayout *ptr;
+ FTGLfont *font;
+ FTGL::LayoutType type;
+};
+
+FTGL_END_C_DECLS
+
+#endif //__FTINTERNALS_H__
+
diff --git a/src/ftgl/FTLayout/FTLayout.cpp b/src/ftgl/FTLayout/FTLayout.cpp
new file mode 100644
index 0000000..d4298bd
--- /dev/null
+++ b/src/ftgl/FTLayout/FTLayout.cpp
@@ -0,0 +1,80 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "../FTFont/FTFontImpl.h"
+#include "./FTLayoutImpl.h"
+
+
+//
+// FTLayout
+//
+
+
+FTLayout::FTLayout()
+{
+ impl = new FTLayoutImpl();
+}
+
+
+FTLayout::FTLayout(FTLayoutImpl *pImpl)
+{
+ impl = pImpl;
+}
+
+
+FTLayout::~FTLayout()
+{
+ delete impl;
+}
+
+
+FT_Error FTLayout::Error() const
+{
+ return impl->err;
+}
+
+
+//
+// FTLayoutImpl
+//
+
+
+FTLayoutImpl::FTLayoutImpl() :
+ err(0)
+{
+ ;
+}
+
+
+FTLayoutImpl::~FTLayoutImpl()
+{
+ ;
+}
+
diff --git a/src/ftgl/FTLayout/FTLayoutGlue.cpp b/src/ftgl/FTLayout/FTLayoutGlue.cpp
new file mode 100644
index 0000000..60f428d
--- /dev/null
+++ b/src/ftgl/FTLayout/FTLayoutGlue.cpp
@@ -0,0 +1,171 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTInternals.h"
+
+static const FTBBox static_ftbbox;
+
+FTGL_BEGIN_C_DECLS
+
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLlayout* cname cargs \
+ { \
+ cxxname *l = new cxxname cxxarg; \
+ if(l->Error()) \
+ { \
+ delete l; \
+ return NULL; \
+ } \
+ FTGLlayout *ftgl = (FTGLlayout *)malloc(sizeof(FTGLlayout)); \
+ ftgl->ptr = l; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
+ }
+
+// FTSimpleLayout::FTSimpleLayout();
+C_TOR(ftglCreateSimpleLayout, (), FTSimpleLayout, (), LAYOUT_SIMPLE);
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!l || !l->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ return l->ptr->cxxname cxxarg; \
+ }
+
+// FTLayout::~FTLayout();
+void ftglDestroyLayout(FTGLlayout *l)
+{
+ if(!l || !l->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return;
+ }
+ delete l->ptr;
+ free(l);
+}
+
+// virtual FTBBox FTLayout::BBox(const char* string)
+extern "C++" {
+C_FUN(static FTBBox, _ftgGetlLayoutBBox, (FTGLlayout *l, const char *s),
+ return static_ftbbox, BBox, (s));
+}
+
+void ftgGetlLayoutBBox(FTGLlayout *l, const char * s, float c[6])
+{
+ FTBBox ret = _ftgGetlLayoutBBox(l, s);
+ FTPoint lower = ret.Lower(), upper = ret.Upper();
+ c[0] = lower.Xf(); c[1] = lower.Yf(); c[2] = lower.Zf();
+ c[3] = upper.Xf(); c[4] = upper.Yf(); c[5] = upper.Zf();
+}
+
+// virtual void FTLayout::Render(const char* string, int renderMode);
+C_FUN(void, ftglRenderLayout, (FTGLlayout *l, const char *s, int r),
+ return, Render, (s, r));
+
+// FT_Error FTLayout::Error() const;
+C_FUN(FT_Error, ftglGetLayoutError, (FTGLlayout *l), return -1, Error, ());
+
+// void FTSimpleLayout::SetFont(FTFont *fontInit)
+void ftglSetLayoutFont(FTGLlayout *l, FTGLfont *font)
+{
+ if(!l || !l->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return;
+ }
+ if(l->type != FTGL::LAYOUT_SIMPLE)
+ {
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
+ __FUNCTION__, l->type);
+ }
+ l->font = font;
+ return dynamic_cast<FTSimpleLayout*>(l->ptr)->SetFont(font->ptr);
+}
+
+// FTFont *FTSimpleLayout::GetFont()
+FTGLfont *ftglGetLayoutFont(FTGLlayout *l)
+{
+ if(!l || !l->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return NULL;
+ }
+ if(l->type != FTGL::LAYOUT_SIMPLE)
+ {
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
+ __FUNCTION__, l->type);
+ }
+ return l->font;
+}
+
+#undef C_FUN
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!l || !l->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ if(l->type != FTGL::LAYOUT_SIMPLE) \
+ { \
+ fprintf(stderr, "FTGL warning: %s not implemented for %d\n", \
+ __FUNCTION__, l->type); \
+ cxxerr; \
+ } \
+ return dynamic_cast<FTSimpleLayout*>(l->ptr)->cxxname cxxarg; \
+ }
+
+// void FTSimpleLayout::SetLineLength(const float LineLength);
+C_FUN(void, ftglSetLayoutLineLength, (FTGLlayout *l, const float length),
+ return, SetLineLength, (length));
+
+// float FTSimpleLayout::GetLineLength() const
+C_FUN(float, ftglGetLayoutLineLength, (FTGLlayout *l),
+ return 0.0f, GetLineLength, ());
+
+// void FTSimpleLayout::SetAlignment(const TextAlignment Alignment)
+C_FUN(void, ftglSetLayoutAlignment, (FTGLlayout *l, const int a),
+ return, SetAlignment, ((FTGL::TextAlignment)a));
+
+// TextAlignment FTSimpleLayout::GetAlignment() const
+C_FUN(int, ftglGetLayoutAlignement, (FTGLlayout *l),
+ return FTGL::ALIGN_LEFT, GetAlignment, ());
+
+// void FTSimpleLayout::SetLineSpacing(const float LineSpacing)
+C_FUN(void, ftglSetLayoutLineSpacing, (FTGLlayout *l, const float f),
+ return, SetLineSpacing, (f));
+
+FTGL_END_C_DECLS
+
diff --git a/src/ftgl/FTLayout/FTLayoutImpl.h b/src/ftgl/FTLayout/FTLayoutImpl.h
new file mode 100644
index 0000000..85df50d
--- /dev/null
+++ b/src/ftgl/FTLayout/FTLayoutImpl.h
@@ -0,0 +1,56 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTLayoutImpl__
+#define __FTLayoutImpl__
+
+#include "FTSize.h"
+#include "FTGlyphContainer.h"
+
+
+class FTLayoutImpl
+{
+ friend class FTLayout;
+
+ protected:
+ FTLayoutImpl();
+
+ virtual ~FTLayoutImpl();
+
+ protected:
+ /**
+ * Current pen or cursor position;
+ */
+ FTPoint pen;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+};
+
+#endif // __FTLayoutImpl__
+
diff --git a/src/ftgl/FTLayout/FTSimpleLayout.cpp b/src/ftgl/FTLayout/FTSimpleLayout.cpp
new file mode 100644
index 0000000..b5a7beb
--- /dev/null
+++ b/src/ftgl/FTLayout/FTSimpleLayout.cpp
@@ -0,0 +1,460 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <ctype.h>
+#include <wctype.h>
+
+#include "FTInternals.h"
+#include "FTUnicode.h"
+
+#include "FTGlyphContainer.h"
+#include "FTSimpleLayoutImpl.h"
+
+
+//
+// FTSimpleLayout
+//
+
+
+FTSimpleLayout::FTSimpleLayout() :
+ FTLayout(new FTSimpleLayoutImpl())
+{}
+
+
+FTSimpleLayout::~FTSimpleLayout()
+{}
+
+
+FTBBox FTSimpleLayout::BBox(const char *string, const int len, FTPoint pos)
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->BBox(string, len, pos);
+}
+
+
+FTBBox FTSimpleLayout::BBox(const wchar_t *string, const int len, FTPoint pos)
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->BBox(string, len, pos);
+}
+
+
+void FTSimpleLayout::Render(const char *string, const int len, FTPoint pos,
+ int renderMode)
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->Render(string, len, pos,
+ renderMode);
+}
+
+
+void FTSimpleLayout::Render(const wchar_t* string, const int len, FTPoint pos,
+ int renderMode)
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->Render(string, len, pos,
+ renderMode);
+}
+
+
+void FTSimpleLayout::SetFont(FTFont *fontInit)
+{
+ dynamic_cast<FTSimpleLayoutImpl*>(impl)->currentFont = fontInit;
+}
+
+
+FTFont *FTSimpleLayout::GetFont()
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->currentFont;
+}
+
+
+void FTSimpleLayout::SetLineLength(const float LineLength)
+{
+ dynamic_cast<FTSimpleLayoutImpl*>(impl)->lineLength = LineLength;
+}
+
+
+float FTSimpleLayout::GetLineLength() const
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->lineLength;
+}
+
+
+void FTSimpleLayout::SetAlignment(const FTGL::TextAlignment Alignment)
+{
+ dynamic_cast<FTSimpleLayoutImpl*>(impl)->alignment = Alignment;
+}
+
+
+FTGL::TextAlignment FTSimpleLayout::GetAlignment() const
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->alignment;
+}
+
+
+void FTSimpleLayout::SetLineSpacing(const float LineSpacing)
+{
+ dynamic_cast<FTSimpleLayoutImpl*>(impl)->lineSpacing = LineSpacing;
+}
+
+
+float FTSimpleLayout::GetLineSpacing() const
+{
+ return dynamic_cast<FTSimpleLayoutImpl*>(impl)->lineSpacing;
+}
+
+
+//
+// FTSimpleLayoutImpl
+//
+
+
+FTSimpleLayoutImpl::FTSimpleLayoutImpl()
+{
+ currentFont = NULL;
+ lineLength = 100.0f;
+ alignment = FTGL::ALIGN_LEFT;
+ lineSpacing = 1.0f;
+}
+
+
+template <typename T>
+inline FTBBox FTSimpleLayoutImpl::BBoxI(const T* string, const int len,
+ FTPoint position)
+{
+ FTBBox tmp;
+
+ WrapText(string, len, position, 0, &tmp);
+
+ return tmp;
+}
+
+
+FTBBox FTSimpleLayoutImpl::BBox(const char *string, const int len,
+ FTPoint position)
+{
+ return BBoxI(string, len, position);
+}
+
+
+FTBBox FTSimpleLayoutImpl::BBox(const wchar_t *string, const int len,
+ FTPoint position)
+{
+ return BBoxI(string, len, position);
+}
+
+
+template <typename T>
+inline void FTSimpleLayoutImpl::RenderI(const T *string, const int len,
+ FTPoint position, int renderMode)
+{
+ pen = FTPoint(0.0f, 0.0f);
+ WrapText(string, len, position, renderMode, NULL);
+}
+
+
+void FTSimpleLayoutImpl::Render(const char *string, const int len,
+ FTPoint position, int renderMode)
+{
+ RenderI(string, len, position, renderMode);
+}
+
+
+void FTSimpleLayoutImpl::Render(const wchar_t* string, const int len,
+ FTPoint position, int renderMode)
+{
+ RenderI(string, len, position, renderMode);
+}
+
+
+template <typename T>
+inline void FTSimpleLayoutImpl::WrapTextI(const T *buf, const int len,
+ FTPoint position, int renderMode,
+ FTBBox *bounds)
+{
+ FTUnicodeStringItr<T> breakItr(buf); // points to the last break character
+ FTUnicodeStringItr<T> lineStart(buf); // points to the line start
+ float nextStart = 0.0; // total width of the current line
+ float breakWidth = 0.0; // width of the line up to the last word break
+ float currentWidth = 0.0; // width of all characters on the current line
+ float prevWidth; // width of all characters but the current glyph
+ float wordLength = 0.0; // length of the block since the last break char
+ int charCount = 0; // number of characters so far on the line
+ int breakCharCount = 0; // number of characters before the breakItr
+ float glyphWidth, advance;
+ FTBBox glyphBounds;
+
+ // Reset the pen position
+ pen.Y(0);
+
+ // If we have bounds mark them invalid
+ if(bounds)
+ {
+ bounds->Invalidate();
+ }
+
+ // Scan the input for all characters that need output
+ FTUnicodeStringItr<T> prevItr(buf);
+ for (FTUnicodeStringItr<T> itr(buf); *itr; prevItr = itr++, charCount++)
+ {
+ // Find the width of the current glyph
+ glyphBounds = currentFont->BBox(itr.getBufferFromHere(), 1);
+ glyphWidth = glyphBounds.Upper().Xf() - glyphBounds.Lower().Xf();
+
+ advance = currentFont->Advance(itr.getBufferFromHere(), 1);
+ prevWidth = currentWidth;
+ // Compute the width of all glyphs up to the end of buf[i]
+ currentWidth = nextStart + glyphWidth;
+ // Compute the position of the next glyph
+ nextStart += advance;
+
+ // See if the current character is a space, a break or a regular character
+ if((currentWidth > lineLength) || (*itr == '\n'))
+ {
+ // A non whitespace character has exceeded the line length. Or a
+ // newline character has forced a line break. Output the last
+ // line and start a new line after the break character.
+ // If we have not yet found a break, break on the last character
+ if(breakItr == lineStart || (*itr == '\n'))
+ {
+ // Break on the previous character
+ breakItr = prevItr;
+ breakCharCount = charCount - 1;
+ breakWidth = prevWidth;
+ // None of the previous words will be carried to the next line
+ wordLength = 0;
+ // If the current character is a newline discard its advance
+ if(*itr == '\n') advance = 0;
+ }
+
+ float remainingWidth = lineLength - breakWidth;
+
+ // Render the current substring
+ FTUnicodeStringItr<T> breakChar = breakItr;
+ // move past the break character and don't count it on the next line either
+ ++breakChar; --charCount;
+ // If the break character is a newline do not render it
+ if(*breakChar == '\n')
+ {
+ ++breakChar; --charCount;
+ }
+
+ OutputWrapped(lineStart.getBufferFromHere(), breakCharCount,
+ //breakItr.getBufferFromHere() - lineStart.getBufferFromHere(),
+ position, renderMode, remainingWidth, bounds);
+
+ // Store the start of the next line
+ lineStart = breakChar;
+ // TODO: Is Height() the right value here?
+ pen -= FTPoint(0, currentFont->LineHeight() * lineSpacing);
+ // The current width is the width since the last break
+ nextStart = wordLength + advance;
+ wordLength += advance;
+ currentWidth = wordLength + advance;
+ // Reset the safe break for the next line
+ breakItr = lineStart;
+ charCount -= breakCharCount;
+ }
+ else if(iswspace(*itr))
+ {
+ // This is the last word break position
+ wordLength = 0;
+ breakItr = itr;
+ breakCharCount = charCount;
+
+ // Check to see if this is the first whitespace character in a run
+ if(buf == itr.getBufferFromHere() || !iswspace(*prevItr))
+ {
+ // Record the width of the start of the block
+ breakWidth = currentWidth;
+ }
+ }
+ else
+ {
+ wordLength += advance;
+ }
+ }
+
+ float remainingWidth = lineLength - currentWidth;
+ // Render any remaining text on the last line
+ // Disable justification for the last row
+ if(alignment == FTGL::ALIGN_JUSTIFY)
+ {
+ alignment = FTGL::ALIGN_LEFT;
+ OutputWrapped(lineStart.getBufferFromHere(), -1, position, renderMode,
+ remainingWidth, bounds);
+ alignment = FTGL::ALIGN_JUSTIFY;
+ }
+ else
+ {
+ OutputWrapped(lineStart.getBufferFromHere(), -1, position, renderMode,
+ remainingWidth, bounds);
+ }
+}
+
+
+void FTSimpleLayoutImpl::WrapText(const char *buf, const int len,
+ FTPoint position, int renderMode,
+ FTBBox *bounds)
+{
+ WrapTextI(buf, len, position, renderMode, bounds);
+}
+
+
+void FTSimpleLayoutImpl::WrapText(const wchar_t* buf, const int len,
+ FTPoint position, int renderMode,
+ FTBBox *bounds)
+{
+ WrapTextI(buf, len, position, renderMode, bounds);
+}
+
+
+template <typename T>
+inline void FTSimpleLayoutImpl::OutputWrappedI(const T *buf, const int len,
+ FTPoint position, int renderMode,
+ const float remaining,
+ FTBBox *bounds)
+{
+ float distributeWidth = 0.0;
+ // Align the text according as specified by Alignment
+ switch (alignment)
+ {
+ case FTGL::ALIGN_LEFT:
+ pen.X(0);
+ break;
+ case FTGL::ALIGN_CENTER:
+ pen.X(remaining / 2);
+ break;
+ case FTGL::ALIGN_RIGHT:
+ pen.X(remaining);
+ break;
+ case FTGL::ALIGN_JUSTIFY:
+ pen.X(0);
+ distributeWidth = remaining;
+ break;
+ }
+
+ // If we have bounds expand them by the line's bounds, otherwise render
+ // the line.
+ if(bounds)
+ {
+ FTBBox temp = currentFont->BBox(buf, len);
+
+ // Add the extra space to the upper x dimension
+ temp = FTBBox(temp.Lower() + pen,
+ temp.Upper() + pen + FTPoint(distributeWidth, 0));
+
+ // See if this is the first area to be added to the bounds
+ if(bounds->IsValid())
+ {
+ *bounds |= temp;
+ }
+ else
+ {
+ *bounds = temp;
+ }
+ }
+ else
+ {
+ RenderSpace(buf, len, position, renderMode, distributeWidth);
+ }
+}
+
+
+void FTSimpleLayoutImpl::OutputWrapped(const char *buf, const int len,
+ FTPoint position, int renderMode,
+ const float remaining, FTBBox *bounds)
+{
+ OutputWrappedI(buf, len, position, renderMode, remaining, bounds);
+}
+
+
+void FTSimpleLayoutImpl::OutputWrapped(const wchar_t *buf, const int len,
+ FTPoint position, int renderMode,
+ const float remaining, FTBBox *bounds)
+{
+ OutputWrappedI(buf, len, position, renderMode, remaining, bounds);
+}
+
+
+template <typename T>
+inline void FTSimpleLayoutImpl::RenderSpaceI(const T *string, const int len,
+ FTPoint position, int renderMode,
+ const float extraSpace)
+{
+ float space = 0.0;
+
+ // If there is space to distribute, count the number of spaces
+ if(extraSpace > 0.0)
+ {
+ int numSpaces = 0;
+
+ // Count the number of space blocks in the input
+ FTUnicodeStringItr<T> prevItr(string), itr(string);
+ for(int i = 0; ((len < 0) && *itr) || ((len >= 0) && (i <= len));
+ ++i, prevItr = itr++)
+ {
+ // If this is the end of a space block, increment the counter
+ if((i > 0) && !iswspace(*itr) && iswspace(*prevItr))
+ {
+ numSpaces++;
+ }
+ }
+
+ space = extraSpace/numSpaces;
+ }
+
+ // Output all characters of the string
+ FTUnicodeStringItr<T> prevItr(string), itr(string);
+ for(int i = 0; ((len < 0) && *itr) || ((len >= 0) && (i <= len));
+ ++i, prevItr = itr++)
+ {
+ // If this is the end of a space block, distribute the extra space
+ // inside it
+ if((i > 0) && !iswspace(*itr) && iswspace(*prevItr))
+ {
+ pen += FTPoint(space, 0);
+ }
+
+ pen = currentFont->Render(itr.getBufferFromHere(), 1, pen, FTPoint(), renderMode);
+ }
+}
+
+
+void FTSimpleLayoutImpl::RenderSpace(const char *string, const int len,
+ FTPoint position, int renderMode,
+ const float extraSpace)
+{
+ RenderSpaceI(string, len, position, renderMode, extraSpace);
+}
+
+
+void FTSimpleLayoutImpl::RenderSpace(const wchar_t *string, const int len,
+ FTPoint position, int renderMode,
+ const float extraSpace)
+{
+ RenderSpaceI(string, len, position, renderMode, extraSpace);
+}
+
diff --git a/src/ftgl/FTLayout/FTSimpleLayoutImpl.h b/src/ftgl/FTLayout/FTSimpleLayoutImpl.h
new file mode 100644
index 0000000..96a074d
--- /dev/null
+++ b/src/ftgl/FTLayout/FTSimpleLayoutImpl.h
@@ -0,0 +1,225 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTSimpleLayoutImpl__
+#define __FTSimpleLayoutImpl__
+
+#include "FTLayoutImpl.h"
+
+
+class FTFont;
+
+class FTSimpleLayoutImpl : public FTLayoutImpl
+{
+ friend class FTSimpleLayout;
+
+ protected:
+ FTSimpleLayoutImpl();
+
+ virtual ~FTSimpleLayoutImpl() {};
+
+ virtual FTBBox BBox(const char* string, const int len,
+ FTPoint position);
+
+ virtual FTBBox BBox(const wchar_t* string, const int len,
+ FTPoint position);
+
+ virtual void Render(const char *string, const int len,
+ FTPoint position, int renderMode);
+
+ virtual void Render(const wchar_t *string, const int len,
+ FTPoint position, int renderMode);
+
+ /**
+ * Render a string of characters and distribute extra space amongst
+ * the whitespace regions of the string.
+ *
+ * @param string A buffer of wchar_t characters to output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered.
+ * @param position TODO
+ * @param renderMode Render mode to display
+ * @param extraSpace The amount of extra space to distribute amongst
+ * the characters.
+ */
+ virtual void RenderSpace(const char *string, const int len,
+ FTPoint position, int renderMode,
+ const float extraSpace);
+
+ /**
+ * Render a string of characters and distribute extra space amongst
+ * the whitespace regions of the string.
+ *
+ * @param string A buffer of wchar_t characters to output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered.
+ * @param position TODO
+ * @param renderMode Render mode to display
+ * @param extraSpace The amount of extra space to distribute amongst
+ * the characters.
+ */
+ virtual void RenderSpace(const wchar_t *string, const int len,
+ FTPoint position, int renderMode,
+ const float extraSpace);
+
+ private:
+ /**
+ * Either render a string of characters and wrap lines
+ * longer than a threshold or compute the bounds
+ * of a string of characters when wrapped. The functionality
+ * of this method is exposed by the BBoxWrapped and
+ * RenderWrapped methods.
+ *
+ * @param buf A char string to output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered.
+ * @param position TODO
+ * @param renderMode Render mode to display
+ * @param bounds A pointer to a bounds object. If non null
+ * the bounds of the text when laid out
+ * will be stored in bounds. If null the
+ * text will be rendered.
+ */
+ virtual void WrapText(const char *buf, const int len,
+ FTPoint position, int renderMode,
+ FTBBox *bounds);
+
+ /**
+ * Either render a string of characters and wrap lines
+ * longer than a threshold or compute the bounds
+ * of a string of characters when wrapped. The functionality
+ * of this method is exposed by the BBoxWrapped and
+ * RenderWrapped methods.
+ *
+ * @param buf A wchar_t style string to output.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered.
+ * @param position TODO
+ * @param renderMode Render mode to display
+ * @param bounds A pointer to a bounds object. If non null
+ * the bounds of the text when laid out
+ * will be stored in bounds. If null the
+ * text will be rendered.
+ */
+ virtual void WrapText(const wchar_t *buf, const int len,
+ FTPoint position, int renderMode,
+ FTBBox *bounds);
+
+ /**
+ * A helper method used by WrapText to either output the text or
+ * compute it's bounds.
+ *
+ * @param buf A pointer to an array of character data.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered.
+ * @param position TODO
+ * @param renderMode Render mode to display
+ * @param RemainingWidth The amount of extra space left on the line.
+ * @param bounds A pointer to a bounds object. If non null the
+ * bounds will be initialized or expanded by the
+ * bounds of the line. If null the text will be
+ * rendered. If the bounds are invalid (lower > upper)
+ * they will be initialized. Otherwise they
+ * will be expanded.
+ */
+ void OutputWrapped(const char *buf, const int len,
+ FTPoint position, int renderMode,
+ const float RemainingWidth, FTBBox *bounds);
+
+ /**
+ * A helper method used by WrapText to either output the text or
+ * compute it's bounds.
+ *
+ * @param buf A pointer to an array of character data.
+ * @param len The length of the string. If < 0 then all characters
+ * will be displayed until a null character is encountered.
+ * @param position TODO
+ * @param renderMode Render mode to display
+ * @param RemainingWidth The amount of extra space left on the line.
+ * @param bounds A pointer to a bounds object. If non null the
+ * bounds will be initialized or expanded by the
+ * bounds of the line. If null the text will be
+ * rendered. If the bounds are invalid (lower > upper)
+ * they will be initialized. Otherwise they
+ * will be expanded.
+ */
+ void OutputWrapped(const wchar_t *buf, const int len,
+ FTPoint position, int renderMode,
+ const float RemainingWidth, FTBBox *bounds);
+
+ /**
+ * The font to use for rendering the text. The font is
+ * referenced by this but will not be disposed of when this
+ * is deleted.
+ */
+ FTFont *currentFont;
+
+ /**
+ * The maximum line length for formatting text.
+ */
+ float lineLength;
+
+ /**
+ * The text alignment mode used to distribute
+ * space within a line or rendered text.
+ */
+ FTGL::TextAlignment alignment;
+
+ /**
+ * The height of each line of text expressed as
+ * a percentage of the font's line height.
+ */
+ float lineSpacing;
+
+ /* Internal generic BBox() implementation */
+ template <typename T>
+ inline FTBBox BBoxI(const T* string, const int len, FTPoint position);
+
+ /* Internal generic Render() implementation */
+ template <typename T>
+ inline void RenderI(const T* string, const int len,
+ FTPoint position, int renderMode);
+
+ /* Internal generic RenderSpace() implementation */
+ template <typename T>
+ inline void RenderSpaceI(const T* string, const int len,
+ FTPoint position, int renderMode,
+ const float extraSpace);
+
+ /* Internal generic WrapText() implementation */
+ template <typename T>
+ void WrapTextI(const T* buf, const int len, FTPoint position,
+ int renderMode, FTBBox *bounds);
+
+ /* Internal generic OutputWrapped() implementation */
+ template <typename T>
+ void OutputWrappedI(const T* buf, const int len, FTPoint position,
+ int renderMode, const float RemainingWidth,
+ FTBBox *bounds);
+};
+
+#endif // __FTSimpleLayoutImpl__
+
diff --git a/src/ftgl/FTLibrary.cpp b/src/ftgl/FTLibrary.cpp
new file mode 100644
index 0000000..66074c3
--- /dev/null
+++ b/src/ftgl/FTLibrary.cpp
@@ -0,0 +1,91 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTLibrary.h"
+
+
+const FTLibrary& FTLibrary::Instance()
+{
+ static FTLibrary ftlib;
+ return ftlib;
+}
+
+
+FTLibrary::~FTLibrary()
+{
+ if(library != 0)
+ {
+ FT_Done_FreeType(*library);
+
+ delete library;
+ library= 0;
+ }
+
+// if(manager != 0)
+// {
+// FTC_Manager_Done(manager);
+//
+// delete manager;
+// manager= 0;
+// }
+}
+
+
+FTLibrary::FTLibrary()
+: library(0),
+ err(0)
+{
+ Initialise();
+}
+
+
+bool FTLibrary::Initialise()
+{
+ if(library != 0)
+ return true;
+
+ library = new FT_Library;
+
+ err = FT_Init_FreeType(library);
+ if(err)
+ {
+ delete library;
+ library = 0;
+ return false;
+ }
+
+// FTC_Manager* manager;
+//
+// if(FTC_Manager_New(lib, 0, 0, 0, my_face_requester, 0, manager)
+// {
+// delete manager;
+// manager= 0;
+// return false;
+// }
+
+ return true;
+}
diff --git a/src/ftgl/FTLibrary.h b/src/ftgl/FTLibrary.h
new file mode 100644
index 0000000..951fecc
--- /dev/null
+++ b/src/ftgl/FTLibrary.h
@@ -0,0 +1,122 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTLibrary__
+#define __FTLibrary__
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+//#include FT_CACHE_H
+
+#include "FTGL/ftgl.h"
+
+
+/**
+ * FTLibrary class is the global accessor for the Freetype library.
+ *
+ * This class encapsulates the Freetype Library. This is a singleton class
+ * and ensures that only one FT_Library is in existence at any one time.
+ * All constructors are private therefore clients cannot create or
+ * instantiate this class themselves and must access it's methods via the
+ * static <code>FTLibrary::Instance()</code> function.
+ *
+ * Just because this class returns a valid <code>FTLibrary</code> object
+ * doesn't mean that the Freetype Library has been successfully initialised.
+ * Clients should check for errors. You can initialse the library AND check
+ * for errors using the following code...
+ * <code>err = FTLibrary::Instance().Error();</code>
+ *
+ * @see "Freetype 2 Documentation"
+ *
+ */
+class FTLibrary
+{
+ public:
+ /**
+ * Global acces point to the single FTLibrary object.
+ *
+ * @return The global <code>FTLibrary</code> object.
+ */
+ static const FTLibrary& Instance();
+
+ /**
+ * Gets a pointer to the native Freetype library.
+ *
+ * @return A handle to a FreeType library instance.
+ */
+ const FT_Library* const GetLibrary() const { return library; }
+
+ /**
+ * Queries the library for errors.
+ *
+ * @return The current error code.
+ */
+ FT_Error Error() const { return err; }
+
+ /**
+ * Destructor
+ *
+ * Disposes of the Freetype library
+ */
+ ~FTLibrary();
+
+ private:
+ /**
+ * Default constructors.
+ *
+ * Made private to stop clients creating there own FTLibrary
+ * objects.
+ */
+ FTLibrary();
+ FTLibrary(const FT_Library&){}
+ FTLibrary& operator=(const FT_Library&) { return *this; }
+
+ /**
+ * Initialises the Freetype library
+ *
+ * Even though this function indicates success via the return value,
+ * clients can't see this so must check the error codes. This function
+ * is only ever called by the default c_stor
+ *
+ * @return <code>true</code> if the Freetype library was
+ * successfully initialised, <code>false</code>
+ * otherwise.
+ */
+ bool Initialise();
+
+ /**
+ * Freetype library handle.
+ */
+ FT_Library* library;
+// FTC_Manager* manager;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+
+};
+
+#endif // __FTLibrary__
diff --git a/src/ftgl/FTList.h b/src/ftgl/FTList.h
new file mode 100644
index 0000000..1440667
--- /dev/null
+++ b/src/ftgl/FTList.h
@@ -0,0 +1,137 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTList__
+#define __FTList__
+
+#include "FTGL/ftgl.h"
+
+/**
+* Provides a non-STL alternative to the STL list
+ */
+template <typename FT_LIST_ITEM_TYPE>
+class 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__
+
diff --git a/src/ftgl/FTPoint.cpp b/src/ftgl/FTPoint.cpp
new file mode 100644
index 0000000..cc02e5a
--- /dev/null
+++ b/src/ftgl/FTPoint.cpp
@@ -0,0 +1,58 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "FTGL/ftgl.h"
+
+bool operator == (const FTPoint &a, const FTPoint &b)
+{
+ return((a.values[0] == b.values[0]) && (a.values[1] == b.values[1]) && (a.values[2] == b.values[2]));
+}
+
+
+bool operator != (const FTPoint &a, const FTPoint &b)
+{
+ return((a.values[0] != b.values[0]) || (a.values[1] != b.values[1]) || (a.values[2] != b.values[2]));
+}
+
+
+FTPoint FTPoint::Normalise()
+{
+ double norm = sqrt(values[0] * values[0]
+ + values[1] * values[1]
+ + values[2] * values[2]);
+ if(norm == 0.0)
+ {
+ return *this;
+ }
+
+ FTPoint temp(values[0] / norm, values[1] / norm, values[2] / norm);
+ return temp;
+}
+
diff --git a/src/ftgl/FTSize.cpp b/src/ftgl/FTSize.cpp
new file mode 100644
index 0000000..49f1596
--- /dev/null
+++ b/src/ftgl/FTSize.cpp
@@ -0,0 +1,123 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTSize.h"
+
+
+FTSize::FTSize()
+: ftFace(0),
+ ftSize(0),
+ size(0),
+ xResolution(0),
+ yResolution(0),
+ err(0)
+{}
+
+
+FTSize::~FTSize()
+{}
+
+
+bool FTSize::CharSize(FT_Face* face, unsigned int pointSize, unsigned int xRes, unsigned int yRes)
+{
+ if(size != pointSize || xResolution != xRes || yResolution != yRes)
+ {
+ err = FT_Set_Char_Size(*face, 0L, pointSize * 64, xResolution, yResolution);
+
+ if(!err)
+ {
+ ftFace = face;
+ size = pointSize;
+ xResolution = xRes;
+ yResolution = yRes;
+ ftSize = (*ftFace)->size;
+ }
+ }
+
+ return !err;
+}
+
+
+unsigned int FTSize::CharSize() const
+{
+ return size;
+}
+
+
+float FTSize::Ascender() const
+{
+ return ftSize == 0 ? 0.0f : static_cast<float>(ftSize->metrics.ascender) / 64.0f;
+}
+
+
+float FTSize::Descender() const
+{
+ return ftSize == 0 ? 0.0f : static_cast<float>(ftSize->metrics.descender) / 64.0f;
+}
+
+
+float FTSize::Height() const
+{
+ if(0 == ftSize)
+ {
+ return 0.0f;
+ }
+
+ if(FT_IS_SCALABLE((*ftFace)))
+ {
+ return ((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * ((float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM);
+ }
+ else
+ {
+ return static_cast<float>(ftSize->metrics.height) / 64.0f;
+ }
+}
+
+
+float FTSize::Width() const
+{
+ if(0 == ftSize)
+ {
+ return 0.0f;
+ }
+
+ if(FT_IS_SCALABLE((*ftFace)))
+ {
+ return ((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * (static_cast<float>(ftSize->metrics.x_ppem) / static_cast<float>((*ftFace)->units_per_EM));
+ }
+ else
+ {
+ return static_cast<float>(ftSize->metrics.max_advance) / 64.0f;
+ }
+}
+
+
+float FTSize::Underline() const
+{
+ return 0.0f;
+}
+
diff --git a/src/ftgl/FTSize.h b/src/ftgl/FTSize.h
new file mode 100644
index 0000000..4ba2666
--- /dev/null
+++ b/src/ftgl/FTSize.h
@@ -0,0 +1,164 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTSize__
+#define __FTSize__
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include "FTGL/ftgl.h"
+
+
+
+/**
+ * FTSize class provides an abstraction layer for the Freetype Size.
+ *
+ * @see "Freetype 2 Documentation"
+ *
+ */
+class FTSize
+{
+ public:
+ /**
+ * Default Constructor
+ */
+ FTSize();
+
+ /**
+ * Destructor
+ */
+ virtual ~FTSize();
+
+ /**
+ * Sets the char size for the current face.
+ *
+ * This doesn't guarantee that the size was set correctly. Clients
+ * should check errors. If an error does occur the size object isn't modified.
+ *
+ * @param face Parent face for this size object
+ * @param point_size the face size in points (1/72 inch)
+ * @param x_resolution the horizontal resolution of the target device.
+ * @param y_resolution the vertical resolution of the target device.
+ * @return <code>true</code> if the size has been set. Clients should check Error() for more information if this function returns false()
+ */
+ bool CharSize(FT_Face* face, unsigned int point_size,
+ unsigned int x_resolution, unsigned int y_resolution);
+
+ /**
+ * get the char size for the current face.
+ *
+ * @return The char size in points
+ */
+ unsigned int CharSize() const;
+
+ /**
+ * Gets the global ascender height for the face in pixels.
+ *
+ * @return Ascender height
+ */
+ float Ascender() const;
+
+ /**
+ * Gets the global descender height for the face in pixels.
+ *
+ * @return Ascender height
+ */
+ float Descender() const;
+
+ /**
+ * Gets the global face height for the face.
+ *
+ * If the face is scalable this returns the height of the global
+ * bounding box which ensures that any glyph will be less than or
+ * equal to this height. If the font isn't scalable there is no
+ * guarantee that glyphs will not be taller than this value.
+ *
+ * @return height in pixels.
+ */
+ float Height() const;
+
+ /**
+ * Gets the global face width for the face.
+ *
+ * If the face is scalable this returns the width of the global
+ * bounding box which ensures that any glyph will be less than or
+ * equal to this width. If the font isn't scalable this value is
+ * the max_advance for the face.
+ *
+ * @return width in pixels.
+ */
+ float Width() const;
+
+ /**
+ * Gets the underline position for the face.
+ *
+ * @return underline position in pixels
+ */
+ float Underline() const;
+
+ /**
+ * Queries for errors.
+ *
+ * @return The current error code.
+ */
+ FT_Error Error() const { return err; }
+
+ private:
+ /**
+ * The current Freetype face that this FTSize object relates to.
+ */
+ FT_Face* ftFace;
+
+ /**
+ * The Freetype size.
+ */
+ FT_Size ftSize;
+
+ /**
+ * The size in points.
+ */
+ unsigned int size;
+
+ /**
+ * The horizontal resolution.
+ */
+ unsigned int xResolution;
+
+ /**
+ * The vertical resolution.
+ */
+ unsigned int yResolution;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+
+};
+
+#endif // __FTSize__
+
diff --git a/src/ftgl/FTUnicode.h b/src/ftgl/FTUnicode.h
new file mode 100644
index 0000000..6c74100
--- /dev/null
+++ b/src/ftgl/FTUnicode.h
@@ -0,0 +1,237 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Daniel Remenak <dtremenak@users.sourceforge.net>
+ *
+ * Portions derived from ConvertUTF.c Copyright (C) 2001-2004 Unicode, Inc
+ * Unicode, Inc. hereby grants the right to freely use the information
+ * supplied in this file in the creation of products supporting the
+ * Unicode Standard, and to make copies of this file in any form
+ * for internal or external distribution as long as this notice
+ * remains attached.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTUnicode__
+#define __FTUnicode__
+
+/**
+ * Provides a way to easily walk multibyte unicode strings in the various
+ * Unicode encodings (UTF-8, UTF-16, UTF-32, UCS-2, and UCS-4). Encodings
+ * with elements larger than one byte must already be in the correct endian
+ * order for the current architecture.
+ */
+template <typename T>
+class FTUnicodeStringItr
+{
+public:
+ /**
+ * Constructor. Also reads the first character and stores it.
+ *
+ * @param string The buffer to iterate. No copy is made.
+ */
+ FTUnicodeStringItr(const T* string) : curPos(string), nextPos(string)
+ {
+ (*this)++;
+ };
+
+ /**
+ * Pre-increment operator. Reads the next unicode character and sets
+ * the state appropriately.
+ * Note - not protected against overruns.
+ */
+ FTUnicodeStringItr& operator++()
+ {
+ curPos = nextPos;
+ // unicode handling
+ switch (sizeof(T))
+ {
+ case 1: // UTF-8
+ // get this character
+ readUTF8(); break;
+ case 2: // UTF-16
+ readUTF16(); break;
+ case 4: // UTF-32
+ // fall through
+ default: // error condition really, but give it a shot anyway
+ curChar = *nextPos++;
+ }
+ return *this;
+ }
+
+ /**
+ * Post-increment operator. Reads the next character and sets
+ * the state appropriately.
+ * Note - not protected against overruns.
+ */
+ FTUnicodeStringItr operator++(int)
+ {
+ FTUnicodeStringItr temp = *this;
+ ++*this;
+ return temp;
+ }
+
+ /**
+ * Equality operator. Two FTUnicodeStringItrs are considered equal
+ * if they have the same current buffer and buffer position.
+ */
+ bool operator==(const FTUnicodeStringItr& right) const
+ {
+ if (curPos == right.getBufferFromHere())
+ return true;
+ return false;
+ }
+
+ /**
+ * Dereference operator.
+ *
+ * @return The unicode codepoint of the character currently pointed
+ * to by the FTUnicodeStringItr.
+ */
+ unsigned int operator*() const
+ {
+ return curChar;
+ }
+
+ /**
+ * Buffer-fetching getter. You can use this to retreive the buffer
+ * starting at the currently-iterated character for functions which
+ * require a Unicode string as input.
+ */
+ const T* getBufferFromHere() const { return curPos; }
+
+private:
+ /**
+ * Helper function for reading a single UTF8 character from the string.
+ * Updates internal state appropriately.
+ */
+ void readUTF8();
+
+ /**
+ * Helper function for reading a single UTF16 character from the string.
+ * Updates internal state appropriately.
+ */
+ void readUTF16();
+
+ /**
+ * The buffer position of the first element in the current character.
+ */
+ const T* curPos;
+
+ /**
+ * The character stored at the current buffer position (prefetched on
+ * increment, so there's no penalty for dereferencing more than once).
+ */
+ unsigned int curChar;
+
+ /**
+ * The buffer position of the first element in the next character.
+ */
+ const T* nextPos;
+
+ // unicode magic numbers
+ static const char utf8bytes[256];
+ static const unsigned long offsetsFromUTF8[6];
+ static const unsigned long highSurrogateStart;
+ static const unsigned long highSurrogateEnd;
+ static const unsigned long lowSurrogateStart;
+ static const unsigned long lowSurrogateEnd;
+ static const unsigned long highSurrogateShift;
+ static const unsigned long lowSurrogateBase;
+};
+
+/* The first character in a UTF8 sequence indicates how many bytes
+ * to read (among other things) */
+template <typename T>
+const char FTUnicodeStringItr<T>::utf8bytes[256] = {
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4,5,5,5,5,6,6,6,6
+};
+
+/* Magic values subtracted from a buffer value during UTF8 conversion.
+ * This table contains as many values as there might be trailing bytes
+ * in a UTF-8 sequence. */
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
+ 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
+
+// get a UTF8 character; leave the tracking pointer at the start of the
+// next character
+// not protected against invalid UTF8
+template <typename T>
+inline void FTUnicodeStringItr<T>::readUTF8()
+{
+ unsigned int ch = 0;
+ unsigned int extraBytesToRead = utf8bytes[(unsigned char)(*nextPos)];
+ // falls through
+ switch (extraBytesToRead)
+ {
+ case 6: ch += *nextPos++; ch <<= 6; /* remember, illegal UTF-8 */
+ case 5: ch += *nextPos++; ch <<= 6; /* remember, illegal UTF-8 */
+ case 4: ch += *nextPos++; ch <<= 6;
+ case 3: ch += *nextPos++; ch <<= 6;
+ case 2: ch += *nextPos++; ch <<= 6;
+ case 1: ch += *nextPos++;
+ }
+ ch -= offsetsFromUTF8[extraBytesToRead-1];
+ curChar = ch;
+}
+
+// Magic numbers for UTF-16 conversions
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::highSurrogateStart = 0xD800;
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::highSurrogateEnd = 0xDBFF;
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::lowSurrogateStart = 0xDC00;
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::lowSurrogateEnd = 0xDFFF;
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::highSurrogateShift = 10;
+template <typename T>
+const unsigned long FTUnicodeStringItr<T>::lowSurrogateBase = 0x0010000UL;
+
+template <typename T>
+inline void FTUnicodeStringItr<T>::readUTF16()
+{
+ unsigned int ch = *nextPos++;
+ // if we have the first half of the surrogate pair
+ if (ch >= highSurrogateStart && ch <= highSurrogateEnd)
+ {
+ unsigned int ch2 = *curPos;
+ // complete the surrogate pair
+ if (ch2 >= lowSurrogateStart && ch2 <= lowSurrogateEnd)
+ {
+ ch = ((ch - highSurrogateStart) << highSurrogateShift)
+ + (ch2 - lowSurrogateStart) + lowSurrogateBase;
+ ++nextPos;
+ }
+ }
+ curChar = ch;
+}
+
+#endif
diff --git a/src/ftgl/FTVector.h b/src/ftgl/FTVector.h
new file mode 100644
index 0000000..ceac72a
--- /dev/null
+++ b/src/ftgl/FTVector.h
@@ -0,0 +1,215 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTVector__
+#define __FTVector__
+
+#include "FTGL/ftgl.h"
+
+/**
+ * Provides a non-STL alternative to the STL vector
+ */
+template <typename FT_VECTOR_ITEM_TYPE>
+class FTVector
+{
+ public:
+ typedef FT_VECTOR_ITEM_TYPE value_type;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef value_type* iterator;
+ typedef const value_type* const_iterator;
+ typedef size_t size_type;
+
+ FTVector()
+ {
+ Capacity = Size = 0;
+ Items = 0;
+ }
+
+
+ virtual ~FTVector()
+ {
+ clear();
+ }
+
+ FTVector& operator =(const FTVector& v)
+ {
+ reserve(v.capacity());
+
+ iterator ptr = begin();
+ const_iterator vbegin = v.begin();
+ const_iterator vend = v.end();
+
+ while(vbegin != vend)
+ {
+ *ptr++ = *vbegin++;
+ }
+
+ Size = v.size();
+ return *this;
+ }
+
+ size_type size() const
+ {
+ return Size;
+ }
+
+ size_type capacity() const
+ {
+ return Capacity;
+ }
+
+ iterator begin()
+ {
+ return Items;
+ }
+
+ const_iterator begin() const
+ {
+ return Items;
+ }
+
+ iterator end()
+ {
+ return begin() + size();
+ }
+
+ const_iterator end() const
+ {
+ return begin() + size();
+ }
+
+ bool empty() const
+ {
+ return size() == 0;
+ }
+
+ reference operator [](size_type pos)
+ {
+ return(*(begin() + pos));
+ }
+
+ const_reference operator [](size_type pos) const
+ {
+ return *(begin() + pos);
+ }
+
+ void clear()
+ {
+ if(Capacity)
+ {
+ delete [] Items;
+ Capacity = Size = 0;
+ Items = 0;
+ }
+ }
+
+ void reserve(size_type n)
+ {
+ if(capacity() < n)
+ {
+ expand(n);
+ }
+ }
+
+ void push_back(const value_type& x)
+ {
+ if(size() == capacity())
+ {
+ expand();
+ }
+
+ (*this)[size()] = x;
+ ++Size;
+ }
+
+ void resize(size_type n, value_type x)
+ {
+ if(n == size())
+ {
+ return;
+ }
+
+ reserve(n);
+ iterator ibegin, iend;
+
+ if(n >= Size)
+ {
+ ibegin = this->end();
+ iend = this->begin() + n;
+ }
+ else
+ {
+ ibegin = this->begin() + n;
+ iend = this->end();
+ }
+
+ while(ibegin != iend)
+ {
+ *ibegin++ = x;
+ }
+
+ Size = n;
+ }
+
+
+ private:
+ void expand(size_type capacity_hint = 0)
+ {
+ size_type new_capacity = (capacity() == 0) ? 256 : capacity() * 2;
+ if(capacity_hint)
+ {
+ while(new_capacity < capacity_hint)
+ {
+ new_capacity *= 2;
+ }
+ }
+
+ value_type *new_items = new value_type[new_capacity];
+
+ iterator ibegin = this->begin();
+ iterator iend = this->end();
+ value_type *ptr = new_items;
+
+ while(ibegin != iend)
+ {
+ *ptr++ = *ibegin++;
+ }
+
+ if(Capacity)
+ {
+ delete [] Items;
+ }
+
+ Items = new_items;
+ Capacity = new_capacity;
+ }
+
+ size_type Capacity;
+ size_type Size;
+ value_type* Items;
+};
+
+#endif // __FTVector__
diff --git a/src/ftgl/FTVectoriser.cpp b/src/ftgl/FTVectoriser.cpp
new file mode 100644
index 0000000..ea5c571
--- /dev/null
+++ b/src/ftgl/FTVectoriser.cpp
@@ -0,0 +1,328 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTInternals.h"
+#include "FTVectoriser.h"
+
+#ifndef CALLBACK
+#define CALLBACK
+#endif
+
+#if defined __APPLE_CC__ && __APPLE_CC__ < 5465
+ typedef GLvoid (*GLUTesselatorFunction) (...);
+#elif defined WIN32 && !defined __CYGWIN__
+ typedef GLvoid (CALLBACK *GLUTesselatorFunction) ();
+#else
+ typedef GLvoid (*GLUTesselatorFunction) ();
+#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(size_t 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(int i = 0; i < ftContourCount; ++i)
+ {
+ FT_Vector* pointList = &outline.points[startIndex];
+ char* tagList = &outline.tags[startIndex];
+
+ endIndex = outline.contours[i];
+ contourLength = (endIndex - startIndex) + 1;
+
+ FTContour* contour = new FTContour(pointList, tagList, contourLength);
+
+ contourList[i] = contour;
+
+ startIndex = endIndex + 1;
+ }
+
+ // Compute each contour's parity. FIXME: see if FT_Outline_Get_Orientation
+ // can do it for us.
+ for(int i = 0; i < ftContourCount; i++)
+ {
+ FTContour *c1 = contourList[i];
+
+ // 1. Find the leftmost point.
+ FTPoint leftmost(65536.0, 0.0);
+
+ for(size_t n = 0; n < c1->PointCount(); n++)
+ {
+ FTPoint p = c1->Point(n);
+ if(p.X() < leftmost.X())
+ {
+ leftmost = p;
+ }
+ }
+
+ // 2. Count how many other contours we cross when going further to
+ // the left.
+ int parity = 0;
+
+ for(int j = 0; j < ftContourCount; j++)
+ {
+ if(j == i)
+ {
+ continue;
+ }
+
+ FTContour *c2 = contourList[j];
+
+ for(size_t n = 0; n < c2->PointCount(); n++)
+ {
+ FTPoint p1 = c2->Point(n);
+ FTPoint p2 = c2->Point((n + 1) % c2->PointCount());
+
+ /* FIXME: combinations of >= > <= and < do not seem stable */
+ if((p1.Y() < leftmost.Y() && p2.Y() < leftmost.Y())
+ || (p1.Y() >= leftmost.Y() && p2.Y() >= leftmost.Y())
+ || (p1.X() > leftmost.X() && p2.X() > leftmost.X()))
+ {
+ continue;
+ }
+ else if(p1.X() < leftmost.X() && p2.X() < leftmost.X())
+ {
+ parity++;
+ }
+ else
+ {
+ FTPoint a = p1 - leftmost;
+ FTPoint b = p2 - leftmost;
+ if(b.X() * a.Y() > b.Y() * a.X())
+ {
+ parity++;
+ }
+ }
+ }
+ }
+
+ // 3. Make sure the glyph has the proper parity.
+ c1->SetParity(parity);
+ }
+}
+
+
+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(size_t index) const
+{
+ return (index < ContourCount()) ? contourList[index] : NULL;
+}
+
+
+void FTVectoriser::MakeMesh(FTGL_DOUBLE zNormal, int outsetType, float outsetSize)
+{
+ 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)
+ {
+ /* Build the */
+ switch(outsetType)
+ {
+ case 1 : contourList[c]->buildFrontOutset(outsetSize); break;
+ case 2 : contourList[c]->buildBackOutset(outsetSize); break;
+ }
+ const FTContour* contour = contourList[c];
+
+
+ gluTessBeginContour(tobj);
+ for(size_t p = 0; p < contour->PointCount(); ++p)
+ {
+ const FTGL_DOUBLE* d;
+ switch(outsetType)
+ {
+ case 1: d = contour->FrontPoint(p); break;
+ case 2: d = contour->BackPoint(p); break;
+ case 0: default: d = contour->Point(p); break;
+ }
+ // XXX: gluTessVertex doesn't modify the data but does not
+ // specify "const" in its prototype, so we cannot cast to
+ // a const type.
+ gluTessVertex(tobj, (GLdouble *)d, (GLvoid *)d);
+ }
+
+ gluTessEndContour(tobj);
+ }
+ gluTessEndPolygon(tobj);
+
+ gluDeleteTess(tobj);
+}
+
diff --git a/src/ftgl/FTVectoriser.h b/src/ftgl/FTVectoriser.h
new file mode 100644
index 0000000..942aea1
--- /dev/null
+++ b/src/ftgl/FTVectoriser.h
@@ -0,0 +1,313 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTVectoriser__
+#define __FTVectoriser__
+
+#include "FTGL/ftgl.h"
+
+#include "FTContour.h"
+#include "FTList.h"
+#include "FTVector.h"
+
+
+#ifndef CALLBACK
+#define CALLBACK
+#endif
+
+
+/**
+ * FTTesselation captures points that are output by OpenGL's gluTesselator.
+ */
+class 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 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
+ */
+ size_t TesselationCount() const { return tesselationList.size(); }
+
+ /**
+ * Get a tesselation by index
+ */
+ const FTTesselation* const Tesselation(size_t 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 FTExtrudeGlyph
+ * @see FTOutlineGlyph
+ * @see FTPolygonGlyph
+ * @see FTContour
+ * @see FTPoint
+ *
+ */
+class 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
+ * FIXME: change the following for a constant
+ * @param outsetType Specify the outset type contour
+ * 0 : Original
+ * 1 : Front
+ * 2 : Back
+ * @param outsetSize Specify the outset size contour
+ */
+ void MakeMesh(FTGL_DOUBLE zNormal = FTGL_FRONT_FACING, int outsetType = 0, float outsetSize = 0.0f);
+
+ /**
+ * 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(size_t 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
+ *
+ * @param front front outset distance
+ * @param back back outset distance
+ */
+ 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__
diff --git a/src/ftgl/config.h b/src/ftgl/config.h
new file mode 100644
index 0000000..109a1ae
--- /dev/null
+++ b/src/ftgl/config.h
@@ -0,0 +1,10 @@
+// GLUT
+//#define HAVE_GL_GLUT_H
+
+// M_PI and friends on VC
+#define _USE_MATH_DEFINES
+
+// quell spurious "'this': used in base member initializer list" warnings
+#ifdef _MSC_VER
+#pragma warning(disable: 4355)
+#endif