Patryk Konopka 10 years ago
parent
commit
61443dacb2

+ 1 - 1
Build/cmake/FileList.cmake

@@ -36,7 +36,6 @@ set(Core_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutlineInstancer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutlineInstancer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadowInstancer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadowInstancer.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/FontFace.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontFaceHandle.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontFaceHandle.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontFaceLayer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontFaceLayer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFace.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFace.h
@@ -131,6 +130,7 @@ set(Core_PUB_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontDatabase.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontDatabase.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontEffect.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontEffect.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontEffectInstancer.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontEffectInstancer.h
+    ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontFace.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontFamily.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontFamily.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontGlyph.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontGlyph.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontProvider.h
     ${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontProvider.h

+ 6 - 9
Source/Core/FontFace.h → Include/Rocket/Core/FontFace.h

@@ -28,9 +28,7 @@
 #ifndef ROCKETCOREFONTFACE_H
 #ifndef ROCKETCOREFONTFACE_H
 #define ROCKETCOREFONTFACE_H
 #define ROCKETCOREFONTFACE_H
 
 
-#include "../../Include/Rocket/Core/Font.h"
-#include <ft2build.h>
-#include FT_FREETYPE_H
+#include "Font.h"
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
@@ -44,8 +42,8 @@ class FontFaceHandle;
 class FontFace
 class FontFace
 {
 {
 public:
 public:
-	FontFace(FT_Face face, Font::Style style, Font::Weight weight, bool release_stream);
-	~FontFace();
+    FontFace(Font::Style style, Font::Weight weight, bool release_stream);
+    virtual ~FontFace();
 
 
 	/// Returns the style of the font face.
 	/// Returns the style of the font face.
 	/// @return The font face's style.
 	/// @return The font face's style.
@@ -58,14 +56,13 @@ public:
 	/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
 	/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
 	/// @param[in] size The size of the desired handle, in points.
 	/// @param[in] size The size of the desired handle, in points.
 	/// @return The shared font handle.
 	/// @return The shared font handle.
-	FontFaceHandle* GetHandle(const String& charset, int size);
+    virtual FontFaceHandle* GetHandle(const String& charset, int size) = 0;
 
 
 	/// Releases the face's FreeType face structure. This will mean handles for new sizes cannot be constructed,
 	/// Releases the face's FreeType face structure. This will mean handles for new sizes cannot be constructed,
 	/// but existing ones can still be fetched.
 	/// but existing ones can still be fetched.
-	void ReleaseFace();
+    virtual void ReleaseFace() = 0;
 
 
-private:
-	FT_Face face;
+protected:
 	Font::Style style;
 	Font::Style style;
 	Font::Weight weight;
 	Font::Weight weight;
 
 

+ 4 - 4
Include/Rocket/Core/FontFamily.h

@@ -46,7 +46,7 @@ class FontFamily
 {
 {
 public:
 public:
 	FontFamily(const String& name);
 	FontFamily(const String& name);
-	~FontFamily();
+    virtual ~FontFamily();
 
 
 	/// Adds a new face to the family.
 	/// Adds a new face to the family.
 	/// @param[in] ft_face The previously loaded FreeType face.
 	/// @param[in] ft_face The previously loaded FreeType face.
@@ -54,7 +54,7 @@ public:
 	/// @param[in] weight The weight of the new face.
 	/// @param[in] weight The weight of the new face.
 	/// @param[in] release_stream True if the application must free the face's memory stream.
 	/// @param[in] release_stream True if the application must free the face's memory stream.
 	/// @return True if the face was loaded successfully, false otherwise.
 	/// @return True if the face was loaded successfully, false otherwise.
-    bool AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream);
+    virtual bool AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream) = 0;
 
 
 	/// Returns a handle to the most appropriate font in the family, at the correct size.
 	/// Returns a handle to the most appropriate font in the family, at the correct size.
 	/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
 	/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
@@ -62,9 +62,9 @@ public:
 	/// @param[in] weight The weight of the desired handle.
 	/// @param[in] weight The weight of the desired handle.
 	/// @param[in] size The size of desired handle, in points.
 	/// @param[in] size The size of desired handle, in points.
 	/// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
 	/// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
-	FontFaceHandle* GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size);
+    FontFaceHandle* GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size);
 
 
-private:
+protected:
 	String name;
 	String name;
 
 
 	typedef std::vector< FontFace* > FontFaceList;
 	typedef std::vector< FontFace* > FontFaceList;

+ 1 - 3
Include/Rocket/Core/FontProvider.h

@@ -56,12 +56,10 @@ public:
     /// @param[in] weight The weight of the desired font handle.
     /// @param[in] weight The weight of the desired font handle.
     /// @param[in] size The size of desired handle, in points.
     /// @param[in] size The size of desired handle, in points.
     /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
     /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
-    virtual FontFaceHandle* GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size) = 0;
+    FontFaceHandle* GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size);
 
 
 protected:
 protected:
 
 
-    FontFamily* GetFontFamily(const String& family);
-
     typedef std::map< String, FontFamily*, StringUtilities::StringComparei > FontFamilyMap;
     typedef std::map< String, FontFamily*, StringUtilities::StringComparei > FontFamilyMap;
     FontFamilyMap font_families;
     FontFamilyMap font_families;
 };
 };

+ 0 - 11
Include/Rocket/Core/FreeType/FontProvider.h

@@ -80,17 +80,6 @@ public:
     /// @return True if the face was loaded successfully, false otherwise.
     /// @return True if the face was loaded successfully, false otherwise.
     static bool LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight);
     static bool LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight);
 
 
-    /// Returns a handle to a font face that can be used to position and render text. This will return the closest match
-    /// it can find, but in the event a font family is requested that does not exist, NULL will be returned instead of a
-    /// valid handle.
-    /// @param[in] family The family of the desired font handle.
-    /// @param[in] charset The set of characters required in the font face, as a comma-separated list of unicode ranges.
-    /// @param[in] style The style of the desired font handle.
-    /// @param[in] weight The weight of the desired font handle.
-    /// @param[in] size The size of desired handle, in points.
-    /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
-    virtual FontFaceHandle* GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size);
-
 private:
 private:
     FontProvider(void);
     FontProvider(void);
     ~FontProvider(void);
     ~FontProvider(void);

+ 3 - 0
Source/Core/FontDatabase.cpp

@@ -37,6 +37,7 @@ namespace Rocket {
 namespace Core {
 namespace Core {
 
 
 FontDatabase* FontDatabase::instance = NULL;
 FontDatabase* FontDatabase::instance = NULL;
+FontDatabase::FontProviderTable FontDatabase::font_provider_table;
 
 
 typedef std::map< String, FontEffect* > FontEffectCache;
 typedef std::map< String, FontEffect* > FontEffectCache;
 FontEffectCache font_effect_cache;
 FontEffectCache font_effect_cache;
@@ -113,6 +114,8 @@ FontFaceHandle* FontDatabase::GetFontFaceHandle(const String& family, const Stri
     {
     {
         FontFaceHandle * face_handle = font_provider_table[ provider_index ]->GetFontFaceHandle(family, charset, style, weight, size);
         FontFaceHandle * face_handle = font_provider_table[ provider_index ]->GetFontFaceHandle(family, charset, style, weight, size);
 
 
+        Log::Message(Log::LT_WARNING, "%x", face_handle );
+
         if(face_handle)
         if(face_handle)
         {
         {
             return face_handle;
             return face_handle;

+ 2 - 95
Source/Core/FontFace.cpp

@@ -26,16 +26,15 @@
  */
  */
 
 
 #include "precompiled.h"
 #include "precompiled.h"
-#include "FontFace.h"
+#include "../../Include/Rocket/Core/FontFace.h"
 #include "FontFaceHandle.h"
 #include "FontFaceHandle.h"
 #include "../../Include/Rocket/Core/Log.h"
 #include "../../Include/Rocket/Core/Log.h"
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 
 
-FontFace::FontFace(FT_Face _face, Font::Style _style, Font::Weight _weight, bool _release_stream)
+FontFace::FontFace(Font::Style _style, Font::Weight _weight, bool _release_stream)
 {
 {
-	face = _face;
 	style = _style;
 	style = _style;
 	weight = _weight;
 	weight = _weight;
 
 
@@ -50,8 +49,6 @@ FontFace::~FontFace()
 		for (size_t i = 0; i < handle_list.size(); ++i)
 		for (size_t i = 0; i < handle_list.size(); ++i)
 			handle_list[i]->RemoveReference();
 			handle_list[i]->RemoveReference();
 	}
 	}
-
-	ReleaseFace();
 }
 }
 
 
 // Returns the style of the font face.
 // Returns the style of the font face.
@@ -66,95 +63,5 @@ Font::Weight FontFace::GetWeight() const
 	return weight;
 	return weight;
 }
 }
 
 
-// Returns a handle for positioning and rendering this face at the given size.
-FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size)
-{
-	UnicodeRangeList charset;
-
-	HandleMap::iterator iterator = handles.find(size);
-	if (iterator != handles.end())
-	{
-		const HandleList& handles = (*iterator).second;
-
-		// Check all the handles if their charsets match the requested one exactly (ie, were specified by the same
-		// string).
-		String raw_charset(_raw_charset);
-		for (size_t i = 0; i < handles.size(); ++i)
-		{
-			if (handles[i]->GetRawCharset() == _raw_charset)
-			{
-				handles[i]->AddReference();
-				return handles[i];
-			}
-		}
-
-		// Check all the handles if their charsets contain the requested charset.
-		if (!UnicodeRange::BuildList(charset, raw_charset))
-		{
-			Log::Message(Log::LT_ERROR, "Invalid font charset '%s'.", _raw_charset.CString());
-			return NULL;
-		}
-
-		for (size_t i = 0; i < handles.size(); ++i)
-		{
-			bool range_contained = true;
-
-			const UnicodeRangeList& handle_charset = handles[i]->GetCharset();
-			for (size_t j = 0; j < charset.size() && range_contained; ++j)
-			{
-				if (!charset[j].IsContained(handle_charset))
-					range_contained = false;
-			}
-
-			if (range_contained)
-			{
-				handles[i]->AddReference();
-				return handles[i];
-			}
-		}
-	}
-
-	// See if this face has been released.
-	if (face == NULL)
-	{
-		Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle.");
-		return NULL;
-	}
-
-	// Construct and initialise the new handle.
-	FontFaceHandle* handle = new FontFaceHandle();
-	if (!handle->Initialise(face, _raw_charset, size))
-	{
-		handle->RemoveReference();
-		return NULL;
-	}
-
-	// Save the handle, and add a reference for the callee. The initial reference will be removed when the font face
-	// releases it.
-	if (iterator != handles.end())
-		(*iterator).second.push_back(handle);
-	else
-		handles[size] = HandleList(1, handle);
-
-	handle->AddReference();
-
-	return handle;
-}
-
-// Releases the face's FreeType face structure.
-void FontFace::ReleaseFace()
-{
-	if (face != NULL)
-	{
-		FT_Byte* face_memory = face->stream->base;
-		FT_Done_Face(face);
-
-		if (release_stream)
-			delete[] face_memory;
-
-		face = NULL;
-	}
-}
-
 }
 }
 }
 }

+ 1 - 10
Source/Core/FontFamily.cpp

@@ -27,7 +27,7 @@
 
 
 #include "precompiled.h"
 #include "precompiled.h"
 #include "../../Include/Rocket/Core/FontFamily.h"
 #include "../../Include/Rocket/Core/FontFamily.h"
-#include "FontFace.h"
+#include "../../Include/Rocket/Core/FontFace.h"
 
 
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
@@ -42,15 +42,6 @@ FontFamily::~FontFamily()
 		delete font_faces[i];
 		delete font_faces[i];
 }
 }
 
 
-// Adds a new face to the family.
-bool FontFamily::AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream)
-{
-    FontFace* face = new FontFace((FT_Face)ft_face, style, weight, release_stream);
-	font_faces.push_back(face);
-
-	return true;
-}
-
 // Returns a handle to the most appropriate font in the family, at the correct size.
 // Returns a handle to the most appropriate font in the family, at the correct size.
 FontFaceHandle* FontFamily::GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size)
 FontFaceHandle* FontFamily::GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size)
 {
 {

+ 5 - 10
Source/Core/FontProvider.cpp

@@ -31,19 +31,14 @@
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 
 
-FontFamily* FontProvider::GetFontFamily(const String& family)
+// Returns a handle to a font face that can be used to position and render text.
+Rocket::Core::FontFaceHandle* FontProvider::GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size)
 {
 {
-    FontFamily* font_family = NULL;
     FontFamilyMap::iterator iterator = font_families.find(family);
     FontFamilyMap::iterator iterator = font_families.find(family);
-    if (iterator != font_families.end())
-        font_family = (*iterator).second;
-    else
-    {
-        font_family = new FontFamily(family);
-        font_families[family] = font_family;
-    }
+    if (iterator == font_families.end())
+        return NULL;
 
 
-    return font_family;
+    return (*iterator).second->GetFaceHandle(charset, style, weight, size);
 }
 }
 
 
 }
 }

+ 139 - 160
Source/Core/FreeType/FontFace.cpp

@@ -1,160 +1,139 @@
-///*
-// * This source file is part of libRocket, the HTML/CSS Interface Middleware
-// *
-// * For the latest information, see http://www.librocket.com
-// *
-// * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
-// *
-// * 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 "../precompiled.h"
-//#include "FontFace.h"
-//#include "FontFaceHandle.h"
-//#include "../../Include/Rocket/Core/Log.h"
-
-//namespace Rocket {
-//namespace Core {
-
-//FontFace::FontFace(FT_Face _face, Font::Style _style, Font::Weight _weight, bool _release_stream)
-//{
-//	face = _face;
-//	style = _style;
-//	weight = _weight;
-
-//	release_stream = _release_stream;
-//}
-
-//FontFace::~FontFace()
-//{
-//	for (HandleMap::iterator iterator = handles.begin(); iterator != handles.end(); ++iterator)
-//	{
-//		HandleList& handle_list = (*iterator).second;
-//		for (size_t i = 0; i < handle_list.size(); ++i)
-//			handle_list[i]->RemoveReference();
-//	}
-
-//	ReleaseFace();
-//}
-
-//// Returns the style of the font face.
-//Font::Style FontFace::GetStyle() const
-//{
-//	return style;
-//}
-
-//// Returns the weight of the font face.
-//Font::Weight FontFace::GetWeight() const
-//{
-//	return weight;
-//}
-
-//// Returns a handle for positioning and rendering this face at the given size.
-//FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size)
-//{
-//	UnicodeRangeList charset;
-
-//	HandleMap::iterator iterator = handles.find(size);
-//	if (iterator != handles.end())
-//	{
-//		const HandleList& handles = (*iterator).second;
-
-//		// Check all the handles if their charsets match the requested one exactly (ie, were specified by the same
-//		// string).
-//		String raw_charset(_raw_charset);
-//		for (size_t i = 0; i < handles.size(); ++i)
-//		{
-//			if (handles[i]->GetRawCharset() == _raw_charset)
-//			{
-//				handles[i]->AddReference();
-//				return handles[i];
-//			}
-//		}
-
-//		// Check all the handles if their charsets contain the requested charset.
-//		if (!UnicodeRange::BuildList(charset, raw_charset))
-//		{
-//			Log::Message(Log::LT_ERROR, "Invalid font charset '%s'.", _raw_charset.CString());
-//			return NULL;
-//		}
-
-//		for (size_t i = 0; i < handles.size(); ++i)
-//		{
-//			bool range_contained = true;
-
-//			const UnicodeRangeList& handle_charset = handles[i]->GetCharset();
-//			for (size_t j = 0; j < charset.size() && range_contained; ++j)
-//			{
-//				if (!charset[j].IsContained(handle_charset))
-//					range_contained = false;
-//			}
-
-//			if (range_contained)
-//			{
-//				handles[i]->AddReference();
-//				return handles[i];
-//			}
-//		}
-//	}
-
-//	// See if this face has been released.
-//	if (face == NULL)
-//	{
-//		Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle.");
-//		return NULL;
-//	}
-
-//	// Construct and initialise the new handle.
-//	FontFaceHandle* handle = new FontFaceHandle();
-//	if (!handle->Initialise(face, _raw_charset, size))
-//	{
-//		handle->RemoveReference();
-//		return NULL;
-//	}
-
-//	// Save the handle, and add a reference for the callee. The initial reference will be removed when the font face
-//	// releases it.
-//	if (iterator != handles.end())
-//		(*iterator).second.push_back(handle);
-//	else
-//		handles[size] = HandleList(1, handle);
-
-//	handle->AddReference();
-
-//	return handle;
-//}
-
-//// Releases the face's FreeType face structure.
-//void FontFace::ReleaseFace()
-//{
-//	if (face != NULL)
-//	{
-//		FT_Byte* face_memory = face->stream->base;
-//		FT_Done_Face(face);
-
-//		if (release_stream)
-//			delete[] face_memory;
-
-//		face = NULL;
-//	}
-//}
-
-//}
-//}
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * 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 "../precompiled.h"
+#include "FontFace.h"
+#include "../FontFaceHandle.h"
+#include "../../../Include/Rocket/Core/Log.h"
+
+namespace Rocket {
+namespace Core {
+namespace FreeType {
+
+FontFace::FontFace(FT_Face _face, Font::Style _style, Font::Weight _weight, bool _release_stream) : Rocket::Core::FontFace(_style, _weight, _release_stream)
+{
+    face = _face;
+}
+
+FontFace::~FontFace()
+{
+    ReleaseFace();
+}
+
+// Returns a handle for positioning and rendering this face at the given size.
+FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size)
+{
+    UnicodeRangeList charset;
+
+    HandleMap::iterator iterator = handles.find(size);
+    if (iterator != handles.end())
+    {
+        const HandleList& handles = (*iterator).second;
+
+        // Check all the handles if their charsets match the requested one exactly (ie, were specified by the same
+        // string).
+        String raw_charset(_raw_charset);
+        for (size_t i = 0; i < handles.size(); ++i)
+        {
+            if (handles[i]->GetRawCharset() == _raw_charset)
+            {
+                handles[i]->AddReference();
+                return handles[i];
+            }
+        }
+
+        // Check all the handles if their charsets contain the requested charset.
+        if (!UnicodeRange::BuildList(charset, raw_charset))
+        {
+            Log::Message(Log::LT_ERROR, "Invalid font charset '%s'.", _raw_charset.CString());
+            return NULL;
+        }
+
+        for (size_t i = 0; i < handles.size(); ++i)
+        {
+            bool range_contained = true;
+
+            const UnicodeRangeList& handle_charset = handles[i]->GetCharset();
+            for (size_t j = 0; j < charset.size() && range_contained; ++j)
+            {
+                if (!charset[j].IsContained(handle_charset))
+                    range_contained = false;
+            }
+
+            if (range_contained)
+            {
+                handles[i]->AddReference();
+                return handles[i];
+            }
+        }
+    }
+
+    // See if this face has been released.
+    if (face == NULL)
+    {
+        Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle.");
+        return NULL;
+    }
+
+    // Construct and initialise the new handle.
+    FontFaceHandle* handle = new FontFaceHandle();
+    if (!handle->Initialise(face, _raw_charset, size))
+    {
+        handle->RemoveReference();
+        return NULL;
+    }
+
+    // Save the handle, and add a reference for the callee. The initial reference will be removed when the font face
+    // releases it.
+    if (iterator != handles.end())
+        (*iterator).second.push_back(handle);
+    else
+        handles[size] = HandleList(1, handle);
+
+    handle->AddReference();
+
+    return handle;
+}
+
+// Releases the face's FreeType face structure.
+void FontFace::ReleaseFace()
+{
+    if (face != NULL)
+    {
+        FT_Byte* face_memory = face->stream->base;
+        FT_Done_Face(face);
+
+        if (release_stream)
+            delete[] face_memory;
+
+        face = NULL;
+    }
+}
+
+}
+}
+}

+ 58 - 71
Source/Core/FreeType/FontFace.h

@@ -1,82 +1,69 @@
-///*
-// * This source file is part of libRocket, the HTML/CSS Interface Middleware
-// *
-// * For the latest information, see http://www.librocket.com
-// *
-// * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
-// *
-// * 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.
-// *
-// */
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * 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 ROCKETCOREFONTFACE_H
-//#define ROCKETCOREFONTFACE_H
+#ifndef ROCKETCOREFREETYPEFONTFACE_H
+#define ROCKETCOREFREETYPEFONTFACE_H
 
 
-//#include "../../../Include/Rocket/Core/Font.h"
-//#include <ft2build.h>
-//#include FT_FREETYPE_H
+#include "../../../Include/Rocket/Core/FontFace.h"
+#include <ft2build.h>
+#include FT_FREETYPE_H
 
 
-//namespace Rocket {
-//namespace Core {
+namespace Rocket {
+namespace Core {
 
 
-//class FontFaceHandle;
+class FontFaceHandle;
 
 
-///**
-//	@author Peter Curry
-// */
+namespace FreeType {
+/**
+    @author Peter Curry
+ */
 
 
-//class FontFace
-//{
-//public:
-//	FontFace(FT_Face face, Font::Style style, Font::Weight weight, bool release_stream);
-//	~FontFace();
+class FontFace : public Rocket::Core::FontFace
+{
+public:
+    FontFace(FT_Face face, Font::Style style, Font::Weight weight, bool release_stream);
+    ~FontFace();
 
 
-//	/// Returns the style of the font face.
-//	/// @return The font face's style.
-//	Font::Style GetStyle() const;
-//	/// Returns the weight of the font face.
-//	/// @return The font face's weight.
-//	Font::Weight GetWeight() const;
+    /// Returns a handle for positioning and rendering this face at the given size.
+    /// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
+    /// @param[in] size The size of the desired handle, in points.
+    /// @return The shared font handle.
+    FontFaceHandle* GetHandle(const String& charset, int size);
 
 
-//	/// Returns a handle for positioning and rendering this face at the given size.
-//	/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
-//	/// @param[in] size The size of the desired handle, in points.
-//	/// @return The shared font handle.
-//	FontFaceHandle* GetHandle(const String& charset, int size);
+    /// Releases the face's FreeType face structure. This will mean handles for new sizes cannot be constructed,
+    /// but existing ones can still be fetched.
+    void ReleaseFace();
 
 
-//	/// Releases the face's FreeType face structure. This will mean handles for new sizes cannot be constructed,
-//	/// but existing ones can still be fetched.
-//	void ReleaseFace();
+private:
+    FT_Face face;
+};
 
 
-//private:
-//	FT_Face face;
-//	Font::Style style;
-//	Font::Weight weight;
+}
+}
+}
 
 
-//	bool release_stream;
-
-//	typedef std::vector< FontFaceHandle* > HandleList;
-//	typedef std::map< int, HandleList > HandleMap;
-//	HandleMap handles;
-//};
-
-//}
-//}
-
-//#endif
+#endif

+ 58 - 79
Source/Core/FreeType/FontFamily.cpp

@@ -1,79 +1,58 @@
-///*
-// * This source file is part of libRocket, the HTML/CSS Interface Middleware
-// *
-// * For the latest information, see http://www.librocket.com
-// *
-// * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
-// *
-// * 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 "precompiled.h"
-//#include "FontFamily.h"
-//#include "FontFace.h"
-
-//namespace Rocket {
-//namespace Core {
-
-//FontFamily::FontFamily(const String& name) : name(name)
-//{
-//}
-
-//FontFamily::~FontFamily()
-//{
-//	for (size_t i = 0; i < font_faces.size(); ++i)
-//		delete font_faces[i];
-//}
-
-//// Adds a new face to the family.
-//bool FontFamily::AddFace(FT_Face ft_face, Font::Style style, Font::Weight weight, bool release_stream)
-//{
-//	FontFace* face = new FontFace(ft_face, style, weight, release_stream);
-//	font_faces.push_back(face);
-
-//	return true;
-//}
-
-//// Returns a handle to the most appropriate font in the family, at the correct size.
-//FontFaceHandle* FontFamily::GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size)
-//{
-//	// Search for a face of the same style, and match the weight as closely as we can.
-//	FontFace* matching_face = NULL;
-//	for (size_t i = 0; i < font_faces.size(); i++)
-//	{
-//		// If we've found a face matching the style, then ... great! We'll match it regardless of the weight. However,
-//		// if it's a perfect match, then we'll stop looking altogether.
-//		if (font_faces[i]->GetStyle() == style)
-//		{
-//			matching_face = font_faces[i];
-
-//			if (font_faces[i]->GetWeight() == weight)
-//				break;
-//		}
-//	}
-
-//	if (matching_face == NULL)
-//		return NULL;
-
-//	return matching_face->GetHandle(charset, size);
-//}
-
-//}
-//}
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ *
+ * 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 "../precompiled.h"
+#include "FontFamily.h"
+#include "FontFace.h"
+
+namespace Rocket {
+namespace Core {
+namespace FreeType
+{
+
+FontFamily::FontFamily(const String& name) : Rocket::Core::FontFamily(name)
+{
+
+}
+
+FontFamily::~FontFamily()
+{
+
+}
+
+// Adds a new face to the family.
+bool FontFamily::AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream)
+{
+    FontFace* face = new FontFace((FT_Face)ft_face, style, weight, release_stream);
+    font_faces.push_back(face);
+
+    return true;
+}
+
+}
+}
+}

+ 1 - 15
Source/Core/FreeType/FontFamily.h

@@ -57,21 +57,7 @@ public:
     /// @param[in] weight The weight of the new face.
     /// @param[in] weight The weight of the new face.
     /// @param[in] release_stream True if the application must free the face's memory stream.
     /// @param[in] release_stream True if the application must free the face's memory stream.
     /// @return True if the face was loaded successfully, false otherwise.
     /// @return True if the face was loaded successfully, false otherwise.
-    bool AddFace(FT_Face ft_face, Font::Style style, Font::Weight weight, bool release_stream);
-
-    /// Returns a handle to the most appropriate font in the family, at the correct size.
-    /// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
-    /// @param[in] style The style of the desired handle.
-    /// @param[in] weight The weight of the desired handle.
-    /// @param[in] size The size of desired handle, in points.
-    /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
-    FontFaceHandle* GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size);
-
-private:
-    String name;
-
-    typedef std::vector< FontFace* > FontFaceList;
-    FontFaceList font_faces;
+    bool AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream);
 };
 };
 
 
 }
 }

+ 5 - 16
Source/Core/FreeType/FontProvider.cpp

@@ -183,28 +183,17 @@ bool FontProvider::LoadFontFace(const byte* data, int data_length, const String&
     }
     }
 }
 }
 
 
-// Returns a handle to a font face that can be used to position and render text.
-Rocket::Core::FontFaceHandle* FontProvider::GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size)
-{
-    FontFamilyMap::iterator iterator = instance->font_families.find(family);
-    if (iterator == instance->font_families.end())
-        return NULL;
-
-    return (*iterator).second->GetFaceHandle(charset, style, weight, size);
-}
-
-
 // Adds a loaded face to the appropriate font family.
 // Adds a loaded face to the appropriate font family.
 bool FontProvider::AddFace(void* face, const String& family, Font::Style style, Font::Weight weight, bool release_stream)
 bool FontProvider::AddFace(void* face, const String& family, Font::Style style, Font::Weight weight, bool release_stream)
 {
 {
-    Rocket::Core::FontFamily* font_family = NULL;
-    FontFamilyMap::iterator iterator = instance->font_families.find(family);
-    if (iterator != instance->font_families.end())
-        font_family = (*iterator).second;
+    FontFamily* font_family = NULL;
+    FontFamilyMap::iterator iterator = font_families.find(family);
+    if (iterator != font_families.end())
+        font_family = (FontFamily*)(*iterator).second;
     else
     else
     {
     {
         font_family = new FontFamily(family);
         font_family = new FontFamily(family);
-        instance->font_families[family] = font_family;
+        font_families[family] = font_family;
     }
     }
 
 
     return font_family->AddFace((FT_Face) face, style, weight, release_stream);
     return font_family->AddFace((FT_Face) face, style, weight, release_stream);