diff -r 512c2df5efc8 lib/irrlicht/include/IGUIEnvironment.h
--- a/lib/irrlicht/include/IGUIEnvironment.h	Tue Aug 26 16:36:19 2008 +0200
+++ b/lib/irrlicht/include/IGUIEnvironment.h	Tue Aug 26 23:39:12 2008 +0200
@@ -33,6 +33,7 @@
 namespace gui
 {
 
+class IGUIFontFactory;
 class IGUIElement;
 class IGUIFont;
 class IGUISpriteBank;
@@ -145,13 +146,13 @@
 	See IReferenceCounted::drop() for more information. */
 	virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type) = 0;
 
-	//! Returns pointer to the font with the specified filename.
+	//! Returns pointer to the font with the specified fontname (usually a filename).
 	/** Loads the font if it was not loaded before.
 	\param filename Filename of the Font.
 	\return Pointer to the font. Returns 0 if the font could not be loaded.
 	This pointer should not be dropped. See IReferenceCounted::drop() for
 	more information. */
-	virtual IGUIFont* getFont(const c8* filename) = 0;
+	virtual IGUIFont* getFont(const c8* fontname) = 0;
 
 	//! Returns the default built-in font.
 	/** \return Pointer to the default built-in font.
@@ -493,6 +494,17 @@
 	//! Adds a GUI Element by its name
 	virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0) = 0;
 
+	//! Adds a font factory to the gui environment.
+	/** Use this to extend the gui environment with new fonts  which it should be
+	able to create automaticly, for example when loading data from xml files. */
+	virtual void registerGUIFontFactory(IGUIFontFactory* factoryToAdd) = 0;
+
+	//! Returns amount of registered font factories.
+	virtual s32 getRegisteredGUIFontFactoryCount() = 0;
+
+	//! Returns a font factory by index
+	virtual IGUIFontFactory* getGUIFontFactory(s32 index) = 0;
+
 	//! Saves the current gui into a file.
 	//! \param filename Name of the file.
 	//! \param start The GUIElement to start with. Root if 0.
diff -r 512c2df5efc8 lib/irrlicht/include/IGUIFont.h
--- a/lib/irrlicht/include/IGUIFont.h	Tue Aug 26 16:36:19 2008 +0200
+++ b/lib/irrlicht/include/IGUIFont.h	Tue Aug 26 23:39:12 2008 +0200
@@ -8,6 +8,7 @@
 #include "IReferenceCounted.h"
 #include "SColor.h"
 #include "rect.h"
+#include "irrString.h"
 
 namespace irr
 {
@@ -83,6 +84,15 @@
 
 	//! Returns the distance between letters
 	virtual s32 getKerningHeight() const = 0;
+	
+	//! Access the font name
+	core::stringc & getName()
+	{
+		return Name;
+	}
+
+protected:
+	core::stringc Name;	
 };
 
 } // end namespace gui
diff -r 512c2df5efc8 lib/irrlicht/include/IGUIFontFactory.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/irrlicht/include/IGUIFontFactory.h	Tue Aug 26 23:39:12 2008 +0200
@@ -0,0 +1,42 @@
+// Copyright (C) 2002-2007 Nikolaus Gebhardt
+// This file is part of the "Irrlicht Engine".
+// For conditions of distribution and use, see copyright notice in irrlicht.h
+
+#ifndef __I_GUI_FONT_FACTORY_H_INCLUDED__
+#define __I_GUI_FONT_FACTORY_H_INCLUDED__
+
+#include "IReferenceCounted.h"
+#include "EGUIElementTypes.h"
+
+namespace irr
+{
+
+
+namespace gui
+{
+	class IGUIFont;
+	
+	//!	Interface making it possible to dynamicly create fonts
+	/** To be able to add custom fonts to Irrlicht and to make it possible for the 
+	scene manager to save and load them, simply implement this interface and register it 
+	in your gui environment via IGUIEnvironment::registerGUIFontFactory.
+	Note: When implementing your own font factory, don't call IGUIEnvironment::grab() to
+	increase the reference counter of the environment. This is not necessary because the
+	it will grab() the factory anyway, and otherwise cyclic references will be created.
+	*/
+	class IGUIFontFactory : public virtual IReferenceCounted
+	{
+	public:
+		virtual ~IGUIFontFactory() {};
+
+		//! adds a font to the GUI Environment based on its name
+		/** \param fontName: Usually filename of the font to add. But specific factories might use this name otherwise.
+		\return Returns pointer to the new font or null if not successful. */
+		virtual IGUIFont* addGUIFont(const c8* fontName) = 0;
+	};
+
+
+} // end namespace gui
+} // end namespace irr
+
+#endif // __I_GUI_FONT_FACTORY_H_INCLUDED__
diff -r 512c2df5efc8 lib/irrlicht/include/irrlicht.h
--- a/lib/irrlicht/include/irrlicht.h	Tue Aug 26 16:36:19 2008 +0200
+++ b/lib/irrlicht/include/irrlicht.h	Tue Aug 26 23:39:12 2008 +0200
@@ -65,6 +65,7 @@
 #include "IGUIElement.h"
 #include "IGUIElementFactory.h"
 #include "IGUIEnvironment.h"
+#include "IGUIFontFactory.h"
 #include "IGUIFileOpenDialog.h"
 #include "IGUIFont.h"
 #include "IGUIFontBitmap.h"
diff -r 512c2df5efc8 lib/irrlicht/source/Irrlicht/CGUIEnvironment.cpp
--- a/lib/irrlicht/source/Irrlicht/CGUIEnvironment.cpp	Tue Aug 26 16:36:19 2008 +0200
+++ b/lib/irrlicht/source/Irrlicht/CGUIEnvironment.cpp	Tue Aug 26 23:39:12 2008 +0200
@@ -37,6 +37,8 @@
 #include "CDefaultGUIElementFactory.h"
 #include "IWriteFile.h"
 #include "IXMLWriter.h"
+#include "IGUIFontFactory.h"
+
 
 #include "BuiltInFont.h"
 #include "os.h"
@@ -151,6 +153,8 @@
 	// remove all factories
 	for (i=0; i<GUIElementFactoryList.size(); ++i)
 		GUIElementFactoryList[i]->drop();
+	for (i=0; i<GUIFontFactoryList.size(); ++i)
+		GUIFontFactoryList[i]->drop();	
 }
 
 
@@ -623,6 +627,31 @@
 u32 CGUIEnvironment::getRegisteredGUIElementFactoryCount() const
 {
 	return GUIElementFactoryList.size();
+}
+
+//! Adds a font factory to the gui environment.
+void CGUIEnvironment::registerGUIFontFactory(IGUIFontFactory* factoryToAdd)
+{
+	if (factoryToAdd)
+	{
+		factoryToAdd->grab();
+		GUIFontFactoryList.push_back(factoryToAdd);
+	}
+}
+
+//! Returns amount of registered font factories.
+s32 CGUIEnvironment::getRegisteredGUIFontFactoryCount()
+{
+	return GUIFontFactoryList.size();
+}
+
+//! Returns a font factory by index
+IGUIFontFactory* CGUIEnvironment::getGUIFontFactory(s32 index)
+{
+	if (index>=0 && index<(int)GUIFontFactoryList.size())
+		return GUIFontFactoryList[index];
+
+	return 0;
 }
 
 
@@ -1304,75 +1333,84 @@
 	s32 index = Fonts.binary_search(f);
 	if (index != -1)
 		return Fonts[index].Font;
-
-	// font doesn't exist, attempt to load it
-
-	// does the file exist?
-
-	if (!FileSystem->existFile(filename))
+	
+	// check if one of the factories can create it
+	for (s32 i=0; i<(int)GUIFontFactoryList.size() && !ifont; ++i)
 	{
-		os::Printer::log("Could not load font because the file does not exist", f.Filename.c_str(), ELL_ERROR);
-		return 0;
+		ifont = GUIFontFactoryList[i]->addGUIFont(filename);
 	}
 
-	io::IXMLReader *xml = FileSystem->createXMLReader(filename);
-	if (xml)
-	{
-		// this is an XML font, but we need to know what type
-		EGUI_FONT_TYPE t = EGFT_CUSTOM;
-
-		bool found=false;
-		while(xml->read() && !found)
+	// try the traditional way (without factories, but we could maybe add a default factory for this someday)
+	if ( !ifont )
+	{	
+		// font doesn't exist, attempt to load it
+	
+		// does the file exist?
+	
+		if (!FileSystem->existFile(filename))
 		{
-			if (xml->getNodeType() == io::EXN_ELEMENT)
+			os::Printer::log("Could not load font because the file does not exist", f.Filename.c_str(), ELL_ERROR);
+			return 0;
+		}
+	
+		io::IXMLReader *xml = FileSystem->createXMLReader(filename);
+		if (xml)
+		{
+			// this is an XML font, but we need to know what type
+			EGUI_FONT_TYPE t = EGFT_CUSTOM;
+	
+			bool found=false;
+			while(xml->read() && !found)
 			{
-				if (core::stringw(L"font") == xml->getNodeName())
+				if (xml->getNodeType() == io::EXN_ELEMENT)
 				{
-					if (core::stringw(L"vector") == xml->getAttributeValue(L"type"))
+					if (core::stringw(L"font") == xml->getNodeName())
 					{
-						t = EGFT_VECTOR;
-						found=true;
+						if (core::stringw(L"vector") == xml->getAttributeValue(L"type"))
+						{
+							t = EGFT_VECTOR;
+							found=true;
+						}
+						else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type"))
+						{
+							t = EGFT_BITMAP;
+							found=true;
+						}
+						else found=true;
 					}
-					else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type"))
-					{
-						t = EGFT_BITMAP;
-						found=true;
-					}
-					else found=true;
 				}
 			}
+	
+			if (t==EGFT_BITMAP)
+			{
+				CGUIFont* font = new CGUIFont(this, filename);
+				ifont = (IGUIFont*)font;
+				// change working directory, for loading textures
+				core::stringc workingDir = FileSystem->getWorkingDirectory();
+				FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.Filename).c_str());
+	
+				// load the font
+				if (!font->load(xml))
+				{
+					font->drop();
+					font  = 0;
+					ifont = 0;
+				}
+				// change working dir back again
+				FileSystem->changeWorkingDirectoryTo( workingDir.c_str());
+			}
+			else if (t==EGFT_VECTOR)
+			{
+				// todo: vector fonts
+				os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.Filename.c_str(), ELL_ERROR);
+	
+				//CGUIFontVector* font = new CGUIFontVector(Driver);
+				//ifont = (IGUIFont*)font;
+				//if (!font->load(xml))
+			}
+			xml->drop();
 		}
-
-		if (t==EGFT_BITMAP)
-		{
-			CGUIFont* font = new CGUIFont(this, filename);
-			ifont = (IGUIFont*)font;
-			// change working directory, for loading textures
-			core::stringc workingDir = FileSystem->getWorkingDirectory();
-			FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.Filename).c_str());
-
-			// load the font
-			if (!font->load(xml))
-			{
-				font->drop();
-				font  = 0;
-				ifont = 0;
-			}
-			// change working dir back again
-			FileSystem->changeWorkingDirectoryTo( workingDir.c_str());
-		}
-		else if (t==EGFT_VECTOR)
-		{
-			// todo: vector fonts
-			os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.Filename.c_str(), ELL_ERROR);
-
-			//CGUIFontVector* font = new CGUIFontVector(Driver);
-			//ifont = (IGUIFont*)font;
-			//if (!font->load(xml))
-		}
-		xml->drop();
 	}
-
 
 	if (!ifont)
 	{
@@ -1387,7 +1425,7 @@
 	}
 
 	// add to fonts.
-
+	ifont->getName() = filename;
 	f.Font = ifont;
 	Fonts.push_back(f);
 
diff -r 512c2df5efc8 lib/irrlicht/source/Irrlicht/CGUIEnvironment.h
--- a/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h	Tue Aug 26 16:36:19 2008 +0200
+++ b/lib/irrlicht/source/Irrlicht/CGUIEnvironment.h	Tue Aug 26 23:39:12 2008 +0200
@@ -198,6 +198,17 @@
 
 	//! Adds a GUI Element by its name
 	virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0);
+	
+	//! Adds a font factory to the gui environment.
+	/** Use this to extend the gui environment with new fonts  which it should be
+	able to create automaticly, for example when loading data from xml files. */
+	virtual void registerGUIFontFactory(IGUIFontFactory* factoryToAdd);
+
+	//! Returns amount of registered font factories.
+	virtual s32 getRegisteredGUIFontFactoryCount();
+
+	//! Returns a font factory by index
+	virtual IGUIFontFactory* getGUIFontFactory(s32 index);
 
 	//! Saves the current gui into a file.
 	/** \param filename: Name of the file.
@@ -265,6 +276,7 @@
 			return (Filename < other.Filename);
 		}
 	};
+	core::array<IGUIFontFactory*> GUIFontFactoryList;
 
 	struct SToolTip
 	{
