Commit 3413b9a19a709d67c0e51f703c9e4f8e97f7148a

henry 2002-06-12T08:56:42

Merged FTGL_1_3_2

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;