Merged FTGL_1_3_2
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
diff --git a/include/FTFace.h b/include/FTFace.h
index 86924ca..89af2be 100755
--- a/include/FTFace.h
+++ b/include/FTFace.h
@@ -42,6 +42,16 @@ class FTGL_EXPORT FTFace
bool Open( const char* filename);
/**
+ * Read face data from an in-memory buffer.
+ *
+ * @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 Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes );
+
+ /**
* Disposes of the face
*/
void Close();
diff --git a/include/FTFont.h b/include/FTFont.h
index d87de19..df4c6a1 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -56,6 +56,20 @@ class FTGL_EXPORT FTFont
bool Open( const char* fontname, bool preCache = true);
/**
+ * Open and read a font from a buffer in memory.
+ *
+ * @param pBufferBytes the in-memory buffer
+ * @param bufferSizeInBytes the length of the buffer in bytes
+ * @param preCache A flag to indicate whether or not to build
+ * a complete set of glyphs at startup
+ * (<code>true</code>) or as prequired
+ * (<code>false</code>). Defaults to true.
+ * @return <code>true</code> if file has opened
+ * successfully.
+ */
+ virtual bool Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes, bool preCache = true);
+
+ /**
* Disposes of the font
*/
void Close();
diff --git a/include/FTGL.h b/include/FTGL.h
index 459a7a2..310ac8d 100755
--- a/include/FTGL.h
+++ b/include/FTGL.h
@@ -6,20 +6,26 @@
// Get this code and use it. It will open your eyes:)
// #define FTGL_DEBUG
-typedef double FTGL_DOUBLE;
-typedef float FTGL_FLOAT;
+typedef double FTGL_DOUBLE;
+typedef float FTGL_FLOAT;
#ifdef WIN32
- // stl stuff
- #pragma warning( disable : 4251 )
- #pragma warning( disable : 4275 )
- #pragma warning( disable : 4786 )
-#endif
+ // 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
-#ifndef WIN32
+#else
- // non windows, doesn't require nonesense as seen below :-)
+ // Non windows platforms - don't require nonsense as seen above :-)
#ifndef __gl_h_
#ifdef __APPLE_CC__
#include <OpenGL/gl.h>
@@ -31,57 +37,41 @@ typedef float FTGL_FLOAT;
#endif
- // required for compatibility with glext.h style function definitions of
+ // 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
-#else // WIN32
-
- // Under windows avoid including <windows.h>
- // to avoid name space pollution, but Win32's <GL/gl.h>
- // needs APIENTRY and WINGDIAPI defined properly.
- // F
- # if 0
- # define WIN32_LEAN_AND_MEAN
- # include <windows.h>
- # else
- // XXX This is from Win32's <windef.h>
- # ifndef APIENTRY
- # define GLUT_APIENTRY_DEFINED
- # if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
- # define APIENTRY __stdcall
- # else
- # define APIENTRY
- # endif
- # endif
- // XXX This is from Win32's <winnt.h>
- # ifndef CALLBACK
- # if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS)
- # define CALLBACK __stdcall
- # else
- # define CALLBACK
- # endif
- # endif
- // XXX This is from Win32's <wingdi.h> and <winnt.h>
- # ifndef WINGDIAPI
- # define GLUT_WINGDIAPI_DEFINED
- # define WINGDIAPI __declspec(dllimport)
- # endif
- // XXX This is from Win32's <ctype.h>
- # ifndef _WCHAR_T_DEFINED
- typedef unsigned short wchar_t;
- # define _WCHAR_T_DEFINED
- # endif
- # endif
+// Compiler-specific conditional compilation
+#ifdef _MSC_VER // MS Visual C++
- #ifndef __gl_h_
- #include <GL/gl.h>
- #include <GL/glu.h>
- #endif
+ // Disable various warning.
+ // 4786: template name too long
+ #pragma warning( disable : 4251 )
+ #pragma warning( disable : 4275 )
+ #pragma warning( disable : 4786 )
-#endif // WIN32
+ // 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
// lifted from glext.h, to remove dependancy on glext.h
@@ -93,17 +83,4 @@ typedef float FTGL_FLOAT;
#define GL_TEXTURE_3D_BINDING_EXT 0x806A
#endif
-
-#if defined(_MSC_VER)
- # ifdef FTGL_LIBRARY_STATIC // staticLib
- # define FTGL_EXPORT
- # elif FTGL_LIBRARY // dynamicLib
- # define FTGL_EXPORT __declspec(dllexport)
- # else
- # define FTGL_EXPORT __declspec(dllimport)
- # endif /* FTGL_LIBRARY */
-#else
- # define FTGL_EXPORT
-#endif
-
#endif // __FTGL__
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index 996c213..0f1e7c0 100755
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -45,6 +45,27 @@ bool FTFace::Open( const char* filename)
}
+bool FTFace::Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes )
+{
+ ftFace = new FT_Face;
+
+ // FIXME check library for errors
+ err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), pBufferBytes, bufferSizeInBytes, 0, ftFace);
+
+ if( err)
+ {
+ delete ftFace;
+ ftFace = 0;
+ return false;
+ }
+ else
+ {
+ charMap = new FTCharmap( *ftFace);
+ return true;
+ }
+}
+
+
void FTFace::Close()
{
if( ftFace)
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 250e8ef..edcfd42 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -44,6 +44,24 @@ bool FTFont::Open( const char* fontname, bool p)
}
+bool FTFont::Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes, bool p )
+{
+ preCache = p;
+
+ if( face.Open( pBufferBytes, bufferSizeInBytes ))
+ {
+ FT_Face* ftFace = face.Face();
+ numGlyphs = (*ftFace)->num_glyphs;
+
+ return true;
+ }
+ else
+ {
+ err = face.Error();
+ return false;
+ }
+}
+
void FTFont::Close()
{
delete glyphList;