rejigged the advance and render functions to make them sleaner...not really
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
diff --git a/include/FTFont.h b/include/FTFont.h
index 945ff1d..b872872 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -182,6 +182,23 @@ class FTGL_EXPORT FTFont
virtual bool MakeGlyphList();
/**
+ * Get the advance width for a character.
+ *
+ * @param chr current character
+ * @param nextChr next character
+ * @return advance width
+ */
+ float doAdvance( const unsigned int chr, const unsigned int nextChr);
+
+ /**
+ * Render a character
+ *
+ * @param chr current character
+ * @param nextChr next character
+ */
+ void doRender( const unsigned int chr, const unsigned int nextChr);
+
+ /**
* Current face object
*/
FTFace face;
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 3bec273..2bac506 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -2,9 +2,9 @@
#include "FTFont.h"
#include "FTGlyphContainer.h"
#include "FTGlyph.h" // for FTBbox
-#include "FTGL.h"
-
-//#include "mmgr.h"
+#ifdef FTGL_DEBUG
+ #include "mmgr.h"
+#endif
FTFont::FTFont()
@@ -110,7 +110,7 @@ int FTFont::Descender() const
void FTFont::BBox( const char* string,
int& llx, int& lly, int& llz, int& urx, int& ury, int& urz)
{
- const unsigned char* c = (unsigned char*)string; // This is ugly, what is the c++ way?
+ const unsigned char* c = (unsigned char*)string;
llx = lly = llz = urx = ury = urz = 0;
FTBBox bbox;
@@ -146,7 +146,7 @@ void FTFont::BBox( const char* string,
void FTFont::BBox( const wchar_t* string,
int& llx, int& lly, int& llz, int& urx, int& ury, int& urz)
{
- const wchar_t* c = string; // wchar_t IS unsigned?
+ const wchar_t* c = string;
llx = lly = llz = urx = ury = urz = 0;
FTBBox bbox;
@@ -182,18 +182,12 @@ void FTFont::BBox( const wchar_t* string,
float FTFont::Advance( const wchar_t* string)
{
- const wchar_t* c = string; // wchar_t IS unsigned?
+ const wchar_t* c = string;
float width = 0;
while( *c)
{
- if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
- {
- unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
- glyphList->Add( MakeGlyph( g), g);
- }
-
- width += glyphList->Advance( *c, *(c + 1));
+ width += doAdvance( *c, *(c + 1));
++c;
}
@@ -203,18 +197,12 @@ float FTFont::Advance( const wchar_t* string)
float FTFont::Advance( const char* string)
{
- const unsigned char* c = (unsigned char*)string; // This is ugly, what is the c++ way?
+ const unsigned char* c = (unsigned char*)string;
float width = 0;
while( *c)
{
- if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
- {
- unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
- glyphList->Add( MakeGlyph( g), g);
- }
-
- width += glyphList->Advance( *c, *(c + 1));
+ width += doAdvance( *c, *(c + 1));
++c;
}
@@ -222,24 +210,26 @@ float FTFont::Advance( const char* string)
}
+float FTFont::doAdvance( const unsigned int chr, const unsigned int nextChr)
+{
+ if( !glyphList->Glyph( chr))
+ {
+ unsigned int g = face.CharIndex( chr);
+ glyphList->Add( MakeGlyph( g), g);
+ }
+
+ return glyphList->Advance( chr, nextChr);
+}
+
+
void FTFont::render( const char* string )
{
- const unsigned char* c = (unsigned char*)string; // This is ugly, what is the c++ way?
- FT_Vector kernAdvance;
+ const unsigned char* c = (unsigned char*)string;
pen.x = 0; pen.y = 0;
while( *c)
{
- if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
- {
- unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
- glyphList->Add( MakeGlyph( g), g);
- }
-
- kernAdvance = glyphList->render( *c, *(c + 1), pen);
-
- pen.x += kernAdvance.x;
- pen.y += kernAdvance.y;
+ doRender( *c, *(c + 1));
++c;
}
}
@@ -247,23 +237,28 @@ void FTFont::render( const char* string )
void FTFont::render( const wchar_t* string )
{
- const wchar_t* c = string; // wchar_t IS unsigned?
- FT_Vector kernAdvance;
+ const wchar_t* c = string;
pen.x = 0; pen.y = 0;
while( *c)
{
- if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
- {
- unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
- glyphList->Add( MakeGlyph( g), g);
- }
-
- kernAdvance = glyphList->render( *c, *(c + 1), pen);
-
- pen.x += kernAdvance.x;
- pen.y += kernAdvance.y;
+ doRender( *c, *(c + 1));
++c;
}
}
+
+void FTFont::doRender( const unsigned int chr, const unsigned int nextChr)
+{
+ if( !glyphList->Glyph( chr))
+ {
+ unsigned int g = face.CharIndex( chr);
+ glyphList->Add( MakeGlyph( g), g);
+ }
+
+ FT_Vector kernAdvance = glyphList->render( chr, nextChr, pen);
+
+ pen.x += kernAdvance.x;
+ pen.y += kernAdvance.y;
+}
+