Quellcode durchsuchen

Start refactoring FreeType implementaiton. Start removing charset. Use lookup maps for glyphs and characters.

Michael Ragazzon vor 6 Jahren
Ursprung
Commit
bb411b159a

+ 2 - 3
Include/RmlUi/Core/FontFace.h

@@ -57,7 +57,7 @@ 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.
-    virtual SharedPtr<FontFaceHandle> GetHandle(const String& charset, int size) = 0;
+    virtual SharedPtr<FontFaceHandle> GetHandle(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.
@@ -69,8 +69,7 @@ protected:
 
 
 	bool release_stream;
 	bool release_stream;
 
 
-	typedef std::vector< SharedPtr<FontFaceHandle> > HandleList;
-	typedef UnorderedMap< int, HandleList > HandleMap;
+	typedef UnorderedMap< int, SharedPtr<FontFaceHandle> > HandleMap;
 	HandleMap handles;
 	HandleMap handles;
 };
 };
 
 

+ 2 - 5
Include/RmlUi/Core/FontGlyph.h

@@ -43,14 +43,11 @@ namespace Core {
 class FontGlyph
 class FontGlyph
 {
 {
 public:
 public:
-	FontGlyph() : character(CodePoint::Null), dimensions(0,0), bearing(0,0), advance(0), bitmap_data(nullptr),
+	FontGlyph() : dimensions(0,0), bearing(0,0), advance(0), bitmap_data(nullptr),
 		bitmap_dimensions(0,0)
 		bitmap_dimensions(0,0)
 	{
 	{
 	}
 	}
 
 
-	/// The unicode code point for this glyph.
-	CodePoint character;
-
 	/// The glyph's bounding box. Not to be confused with the dimensions of the glyph's bitmap!
 	/// The glyph's bounding box. Not to be confused with the dimensions of the glyph's bitmap!
 	Vector2i dimensions;
 	Vector2i dimensions;
 	/// The distance from the cursor (positioned vertically on the baseline) to the top-left corner
 	/// The distance from the cursor (positioned vertically on the baseline) to the top-left corner
@@ -67,7 +64,7 @@ public:
 	Vector2i bitmap_dimensions;
 	Vector2i bitmap_dimensions;
 };
 };
 
 
-typedef std::vector< FontGlyph > FontGlyphList;
+using FontGlyphMap = UnorderedMap<CodePoint, FontGlyph>;
 
 
 }
 }
 }
 }

+ 4 - 14
Include/RmlUi/Core/FreeType/FontProvider.h

@@ -35,21 +35,12 @@
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
 
 
-
-class FontEffect;
-class FontFaceHandle;
-class PropertyDictionary;
-
-namespace FreeType {
-
-class FontFamily;
-
 /**
 /**
     The font database contains all font families currently in use by RmlUi.
     The font database contains all font families currently in use by RmlUi.
     @author Peter Curry
     @author Peter Curry
  */
  */
 
 
-class RMLUICORE_API FontProvider : public Rml::Core::FontProvider
+class RMLUICORE_API FontProvider_FreeType : public Rml::Core::FontProvider
 {
 {
 public:
 public:
     static bool Initialise();
     static bool Initialise();
@@ -81,8 +72,8 @@ public:
     static bool LoadFontFace(const byte* data, int data_length, const String& family, Style::FontStyle style, Style::FontWeight weight);
     static bool LoadFontFace(const byte* data, int data_length, const String& family, Style::FontStyle style, Style::FontWeight weight);
 
 
 private:
 private:
-    FontProvider(void);
-    ~FontProvider(void);
+    FontProvider_FreeType(void);
+    ~FontProvider_FreeType(void);
 
 
     // Adds a loaded face to the appropriate font family.
     // Adds a loaded face to the appropriate font family.
     bool AddFace(void* face, const String& family, Style::FontStyle style, Style::FontWeight weight, bool release_stream);
     bool AddFace(void* face, const String& family, Style::FontStyle style, Style::FontWeight weight, bool release_stream);
@@ -91,10 +82,9 @@ private:
     // Loads a FreeType face from memory.
     // Loads a FreeType face from memory.
     void* LoadFace(const byte* data, int data_length, const String& source, bool local_data);
     void* LoadFace(const byte* data, int data_length, const String& source, bool local_data);
 
 
-    static FontProvider* instance;
+    static FontProvider_FreeType* instance;
 };
 };
 
 
-}
 }
 }
 }
 }
 
 

+ 6 - 6
Source/Core/FontDatabase.cpp

@@ -56,7 +56,7 @@ bool FontDatabase::Initialise()
 	{
 	{
 		new FontDatabase();
 		new FontDatabase();
 
 
-        if(!FreeType::FontProvider::Initialise())
+        if(!FontProvider_FreeType::Initialise())
             return false;
             return false;
 	}
 	}
 
 
@@ -67,7 +67,7 @@ void FontDatabase::Shutdown()
 {
 {
 	if (instance != nullptr)
 	if (instance != nullptr)
 	{
 	{
-        FreeType::FontProvider::Shutdown();
+        FontProvider_FreeType::Shutdown();
 
 
 		delete instance;
 		delete instance;
 	}
 	}
@@ -76,25 +76,25 @@ void FontDatabase::Shutdown()
 // Loads a new font face.
 // Loads a new font face.
 bool FontDatabase::LoadFontFace(const String& file_name)
 bool FontDatabase::LoadFontFace(const String& file_name)
 {
 {
-	return FreeType::FontProvider::LoadFontFace(file_name);
+	return FontProvider_FreeType::LoadFontFace(file_name);
 }
 }
 
 
 // Adds a new font face to the database, ignoring any family, style and weight information stored in the face itself.
 // Adds a new font face to the database, ignoring any family, style and weight information stored in the face itself.
 bool FontDatabase::LoadFontFace(const String& file_name, const String& family, Style::FontStyle style, Style::FontWeight weight)
 bool FontDatabase::LoadFontFace(const String& file_name, const String& family, Style::FontStyle style, Style::FontWeight weight)
 {
 {
-	return FreeType::FontProvider::LoadFontFace(file_name, family, style, weight);
+	return FontProvider_FreeType::LoadFontFace(file_name, family, style, weight);
 }
 }
 
 
 // Adds a new font face to the database, loading from memory.
 // Adds a new font face to the database, loading from memory.
 bool FontDatabase::LoadFontFace(const byte* data, int data_length)
 bool FontDatabase::LoadFontFace(const byte* data, int data_length)
 {
 {
-	return FreeType::FontProvider::LoadFontFace(data, data_length);
+	return FontProvider_FreeType::LoadFontFace(data, data_length);
 }
 }
 
 
 // Adds a new font face to the database, loading from memory, ignoring any family, style and weight information stored in the face itself.
 // Adds a new font face to the database, loading from memory, ignoring any family, style and weight information stored in the face itself.
 bool FontDatabase::LoadFontFace(const byte* data, int data_length, const String& family, Style::FontStyle style, Style::FontWeight weight)
 bool FontDatabase::LoadFontFace(const byte* data, int data_length, const String& family, Style::FontStyle style, Style::FontWeight weight)
 {
 {
-	return FreeType::FontProvider::LoadFontFace(data, data_length, family, style, weight);
+	return FontProvider_FreeType::LoadFontFace(data, data_length, family, style, weight);
 }
 }
 
 
 // Returns a handle to a font face that can be used to position and render text.
 // Returns a handle to a font face that can be used to position and render text.

+ 37 - 38
Source/Core/FontFaceHandle.cpp

@@ -38,59 +38,51 @@ namespace Core {
 
 
 FontFaceHandle::FontFaceHandle()
 FontFaceHandle::FontFaceHandle()
 {
 {
-	size = 0;
-	average_advance = 0;
-	x_height = 0;
-	line_height = 0;
-	baseline = 0;
-
-	underline_position = 0;
-	underline_thickness = 0;
-
+	metrics = {};
 	base_layer = nullptr;
 	base_layer = nullptr;
 }
 }
 
 
 FontFaceHandle::~FontFaceHandle()
 FontFaceHandle::~FontFaceHandle()
 {
 {
-	for (FontGlyphList::iterator i = glyphs.begin(); i != glyphs.end(); ++i)
-		delete[] i->bitmap_data;
+	for (auto& pair : glyphs)
+		delete[] pair.second.bitmap_data;
 
 
-	for (FontLayerMap::iterator i = layers.begin(); i != layers.end(); ++i)
-		delete i->second;
+	for (auto& pair : layers)
+		delete pair.second;
 }
 }
 
 
 // Returns the point size of this font face.
 // Returns the point size of this font face.
 int FontFaceHandle::GetSize() const
 int FontFaceHandle::GetSize() const
 {
 {
-	return size;
+	return metrics.size;
 }
 }
 
 
 // Returns the average advance of all glyphs in this font face.
 // Returns the average advance of all glyphs in this font face.
 int FontFaceHandle::GetCharacterWidth() const
 int FontFaceHandle::GetCharacterWidth() const
 {
 {
-	return average_advance;
+	return metrics.average_advance;
 }
 }
 
 
 // Returns the pixel height of a lower-case x in this font face.
 // Returns the pixel height of a lower-case x in this font face.
 int FontFaceHandle::GetXHeight() const
 int FontFaceHandle::GetXHeight() const
 {
 {
-	return x_height;
+	return metrics.x_height;
 }
 }
 
 
 // Returns the default height between this font face's baselines.
 // Returns the default height between this font face's baselines.
 int FontFaceHandle::GetLineHeight() const
 int FontFaceHandle::GetLineHeight() const
 {
 {
-	return line_height;
+	return metrics.line_height;
 }
 }
 
 
 // Returns the font's baseline.
 // Returns the font's baseline.
 int FontFaceHandle::GetBaseline() const
 int FontFaceHandle::GetBaseline() const
 {
 {
-	return baseline;
+	return metrics.baseline;
 }
 }
 
 
 // Returns the font's glyphs.
 // Returns the font's glyphs.
-const FontGlyphList& FontFaceHandle::GetGlyphs() const
+const FontGlyphMap& FontFaceHandle::GetGlyphs() const
 {
 {
 	return glyphs;
 	return glyphs;
 }
 }
@@ -99,13 +91,15 @@ const FontGlyphList& FontFaceHandle::GetGlyphs() const
 int FontFaceHandle::GetStringWidth(const String& string, CodePoint prior_character) const
 int FontFaceHandle::GetStringWidth(const String& string, CodePoint prior_character) const
 {
 {
 	int width = 0;
 	int width = 0;
-	for (auto it = StringIteratorU8(string); it; ++it)
+	for (auto it_string = StringIteratorU8(string); it_string; ++it_string)
 	{
 	{
-		CodePoint code_point = *it;
+		CodePoint code_point = *it_string;
 
 
-		if ((size_t)code_point >= glyphs.size())
+		auto it_glyph = glyphs.find(code_point);
+		if (it_glyph == glyphs.end())
 			continue;
 			continue;
-		const FontGlyph &glyph = glyphs[(size_t)code_point];
+
+		const FontGlyph& glyph = it_glyph->second;
 
 
 		// Adjust the cursor for the kerning between this character and the previous one.
 		// Adjust the cursor for the kerning between this character and the previous one.
 		if (prior_character != CodePoint::Null)
 		if (prior_character != CodePoint::Null)
@@ -229,13 +223,15 @@ int FontFaceHandle::GenerateString(GeometryList& geometry, const String& string,
 		geometry[geometry_index].GetIndices().reserve(string.size() * 6);
 		geometry[geometry_index].GetIndices().reserve(string.size() * 6);
 		geometry[geometry_index].GetVertices().reserve(string.size() * 4);
 		geometry[geometry_index].GetVertices().reserve(string.size() * 4);
 
 
-		for (auto it = StringIteratorU8(string); it; ++it)
+		for (auto it_string = StringIteratorU8(string); it_string; ++it_string)
 		{
 		{
-			CodePoint code_point = *it;
+			CodePoint code_point = *it_string;
 
 
-			if ((size_t)code_point >= glyphs.size())
+			auto it_glyph = glyphs.find(code_point);
+			if (it_glyph == glyphs.end())
 				continue;
 				continue;
-			const FontGlyph &glyph = glyphs[(size_t)code_point];
+
+			const FontGlyph& glyph = it_glyph->second;
 
 
 			// Adjust the cursor for the kerning between this character and the previous one.
 			// Adjust the cursor for the kerning between this character and the previous one.
 			if (prior_character != CodePoint::Null)
 			if (prior_character != CodePoint::Null)
@@ -265,9 +261,9 @@ void FontFaceHandle::GenerateLine(Geometry* geometry, const Vector2f& position,
 	float offset;
 	float offset;
 	switch (height)
 	switch (height)
 	{
 	{
-	case Style::TextDecoration::Underline:       offset = -underline_position; break;
-	case Style::TextDecoration::Overline:        offset = -underline_position - (float)size; break;
-	case Style::TextDecoration::LineThrough:     offset = -0.65f * (float)x_height; break; // or maybe: -underline_position - (float)size * 0.5f
+	case Style::TextDecoration::Underline:       offset = -metrics.underline_position; break;
+	case Style::TextDecoration::Overline:        offset = -metrics.underline_position - (float)metrics.size; break;
+	case Style::TextDecoration::LineThrough:     offset = -0.65f * (float)metrics.x_height; break; // or maybe: -underline_position - (float)size * 0.5f
 	default: return;
 	default: return;
 	}
 	}
 
 
@@ -277,22 +273,25 @@ void FontFaceHandle::GenerateLine(Geometry* geometry, const Vector2f& position,
 		&line_vertices[0] + ((int)line_vertices.size() - 4),
 		&line_vertices[0] + ((int)line_vertices.size() - 4),
 		&line_indices[0] + ((int)line_indices.size() - 6),
 		&line_indices[0] + ((int)line_indices.size() - 6),
 		Vector2f(position.x, position.y + offset).Round(),
 		Vector2f(position.x, position.y + offset).Round(),
-		Vector2f((float) width, underline_thickness),
+		Vector2f((float) width, metrics.underline_thickness),
 		colour, 
 		colour, 
 		(int)line_vertices.size() - 4
 		(int)line_vertices.size() - 4
 	);
 	);
 }
 }
 
 
-// Returns the font face's raw charset (the charset range as a string).
-const String& FontFaceHandle::GetRawCharset() const
-{
-	return raw_charset;
+FontGlyphMap& FontFaceHandle::GetGlyphs() {
+	return glyphs;
+}
+
+FontMetrics& FontFaceHandle::GetMetrics() {
+	return metrics;
 }
 }
 
 
-// Returns the font face's charset.
-const UnicodeRangeList& FontFaceHandle::GetCharset() const
+void FontFaceHandle::GenerateBaseLayer()
 {
 {
-	return charset;
+	base_layer = GenerateLayer(nullptr);
+	layer_configurations.push_back(LayerConfiguration());
+	layer_configurations.back().push_back(base_layer);
 }
 }
 
 
 Rml::Core::FontFaceLayer* FontFaceHandle::CreateNewLayer()
 Rml::Core::FontFaceLayer* FontFaceHandle::CreateNewLayer()

+ 25 - 27
Source/Core/FontFaceHandle.h

@@ -45,6 +45,19 @@ class FontFaceLayer;
 	@author Peter Curry
 	@author Peter Curry
  */
  */
 
 
+struct FontMetrics {
+	// The average advance (in pixels) of all of this face's glyphs.
+	int average_advance;
+
+	int size;
+	int x_height;
+	int line_height;
+	int baseline;
+
+	float underline_position;
+	float underline_thickness;
+};
+
 class FontFaceHandle : public NonCopyMoveable
 class FontFaceHandle : public NonCopyMoveable
 {
 {
 public:
 public:
@@ -71,7 +84,7 @@ public:
 
 
 	/// Returns the font's glyphs.
 	/// Returns the font's glyphs.
 	/// @return The font's glyphs.
 	/// @return The font's glyphs.
-	const FontGlyphList& GetGlyphs() const;
+	const FontGlyphMap& GetGlyphs() const;
 
 
 	/// Returns the width a string will take up if rendered with this handle.
 	/// Returns the width a string will take up if rendered with this handle.
 	/// @param[in] string The string to measure.
 	/// @param[in] string The string to measure.
@@ -105,15 +118,15 @@ public:
 	/// @param[in] colour The colour to draw the line in.
 	/// @param[in] colour The colour to draw the line in.
 	void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Style::TextDecoration decoration_type, const Colourb& colour) const;
 	void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Style::TextDecoration decoration_type, const Colourb& colour) const;
 
 
-	/// Returns the font face's raw charset (the charset range as a string).
-	/// @return The font face's charset.
-	const String& GetRawCharset() const;
-	/// Returns the font face's charset.
-	/// @return The font face's charset.
-	const UnicodeRangeList& GetCharset() const;
-
 protected:
 protected:
 
 
+	FontGlyphMap& GetGlyphs();
+	FontMetrics& GetMetrics();
+
+	void GenerateBaseLayer();
+
+private:
+
 	virtual int GetKerning(CodePoint lhs, CodePoint rhs) const = 0;
 	virtual int GetKerning(CodePoint lhs, CodePoint rhs) const = 0;
 	virtual FontFaceLayer* CreateNewLayer();
 	virtual FontFaceLayer* CreateNewLayer();
 
 
@@ -122,7 +135,7 @@ protected:
 	typedef std::vector< int > GlyphKerningList;
 	typedef std::vector< int > GlyphKerningList;
 	typedef std::vector< GlyphKerningList > FontKerningList;
 	typedef std::vector< GlyphKerningList > FontKerningList;
 
 
-	FontGlyphList glyphs;
+	FontGlyphMap glyphs;
 	FontKerningList kerning;
 	FontKerningList kerning;
 
 
 	typedef SmallUnorderedMap< const FontEffect*, FontFaceLayer* > FontLayerMap;
 	typedef SmallUnorderedMap< const FontEffect*, FontFaceLayer* > FontLayerMap;
@@ -133,28 +146,13 @@ protected:
 	// The list of all font layers, index by the effect that instanced them.
 	// The list of all font layers, index by the effect that instanced them.
 	FontFaceLayer* base_layer;
 	FontFaceLayer* base_layer;
 	FontLayerMap layers;
 	FontLayerMap layers;
-	// Each font layer that generated geometry or textures, indexed by the respective generation
-	// key.
+	// Each font layer that generated geometry or textures, indexed by the respective generation key.
 	FontLayerCache layer_cache;
 	FontLayerCache layer_cache;
 
 
-	// All configurations currently in use on this handle. New configurations will be generated as
-	// required.
+	// All configurations currently in use on this handle. New configurations will be generated as required.
 	LayerConfigurationList layer_configurations;
 	LayerConfigurationList layer_configurations;
 
 
-	// The average advance (in pixels) of all of this face's glyphs.
-	int average_advance;
-
-	int size;
-	int x_height;
-	int line_height;
-	int baseline;
-
-	float underline_position;
-	float underline_thickness;
-
-	String raw_charset;
-	UnicodeRangeList charset;
-	unsigned int max_codepoint;
+	FontMetrics metrics;
 };
 };
 
 
 }
 }

+ 25 - 16
Source/Core/FontFaceLayer.cpp

@@ -51,7 +51,7 @@ bool FontFaceLayer::Initialise(const FontFaceHandle* _handle, SharedPtr<const Fo
 	if (effect)
 	if (effect)
 		colour = effect->GetColour();
 		colour = effect->GetColour();
 
 
-	const FontGlyphList& glyphs = handle->GetGlyphs();
+	const FontGlyphMap& glyphs = handle->GetGlyphs();
 
 
 	// Clone the geometry and textures from the clone layer.
 	// Clone the geometry and textures from the clone layer.
 	if (clone != nullptr)
 	if (clone != nullptr)
@@ -67,15 +67,14 @@ bool FontFaceLayer::Initialise(const FontFaceHandle* _handle, SharedPtr<const Fo
 		if (!deep_clone &&
 		if (!deep_clone &&
 			effect != nullptr)
 			effect != nullptr)
 		{
 		{
-			for (FontGlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i)
+			for (auto& pair : glyphs)
 			{
 			{
-				const FontGlyph& glyph = *i;
+				CodePoint code_point = pair.first;
+				const FontGlyph& glyph = pair.second;
 
 
-				if ((size_t)glyph.character >= characters.size())
-					continue;
+				RMLUI_ASSERT(characters.find(code_point) != characters.end());
 
 
-				// TODO: Use a look-up map instead (codepoints can get large!)
-				Character& character = characters[(size_t)glyph.character];
+				Character& character = characters[code_point];
 
 
 				Vector2i glyph_origin(Math::RealToInteger(character.origin.x), Math::RealToInteger(character.origin.y));
 				Vector2i glyph_origin(Math::RealToInteger(character.origin.x), Math::RealToInteger(character.origin.y));
 				Vector2i glyph_dimensions(Math::RealToInteger(character.dimensions.x), Math::RealToInteger(character.dimensions.y));
 				Vector2i glyph_dimensions(Math::RealToInteger(character.dimensions.x), Math::RealToInteger(character.dimensions.y));
@@ -93,10 +92,11 @@ bool FontFaceLayer::Initialise(const FontFaceHandle* _handle, SharedPtr<const Fo
 	else
 	else
 	{
 	{
 		// Initialise the texture layout for the glyphs.
 		// Initialise the texture layout for the glyphs.
-		characters.resize(glyphs.size(), Character());
-		for (FontGlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i)
+		characters.reserve(glyphs.size());
+		for (auto& pair : glyphs)
 		{
 		{
-			const FontGlyph& glyph = *i;
+			CodePoint code_point = pair.first;
+			const FontGlyph& glyph = pair.second;
 
 
 			Vector2i glyph_origin(0, 0);
 			Vector2i glyph_origin(0, 0);
 			Vector2i glyph_dimensions = glyph.bitmap_dimensions;
 			Vector2i glyph_dimensions = glyph.bitmap_dimensions;
@@ -111,10 +111,10 @@ bool FontFaceLayer::Initialise(const FontFaceHandle* _handle, SharedPtr<const Fo
 			Character character;
 			Character character;
 			character.origin = Vector2f((float) (glyph_origin.x + glyph.bearing.x), (float) (glyph_origin.y - glyph.bearing.y));
 			character.origin = Vector2f((float) (glyph_origin.x + glyph.bearing.x), (float) (glyph_origin.y - glyph.bearing.y));
 			character.dimensions = Vector2f((float) glyph_dimensions.x - glyph_origin.x, (float) glyph_dimensions.y - glyph_origin.y);
 			character.dimensions = Vector2f((float) glyph_dimensions.x - glyph_origin.x, (float) glyph_dimensions.y - glyph_origin.y);
-			characters[(size_t)glyph.character] = character;
+			characters[code_point] = character;
 
 
 			// Add the character's dimensions into the texture layout engine.
 			// Add the character's dimensions into the texture layout engine.
-			texture_layout.AddRectangle((int)glyph.character, glyph_dimensions - glyph_origin);
+			texture_layout.AddRectangle((int)code_point, glyph_dimensions - glyph_origin);
 		}
 		}
 
 
 		// Generate the texture layout; this will position the glyph rectangles efficiently and
 		// Generate the texture layout; this will position the glyph rectangles efficiently and
@@ -129,7 +129,9 @@ bool FontFaceLayer::Initialise(const FontFaceHandle* _handle, SharedPtr<const Fo
 		{
 		{
 			TextureLayoutRectangle& rectangle = texture_layout.GetRectangle(i);
 			TextureLayoutRectangle& rectangle = texture_layout.GetRectangle(i);
 			const TextureLayoutTexture& texture = texture_layout.GetTexture(rectangle.GetTextureIndex());
 			const TextureLayoutTexture& texture = texture_layout.GetTexture(rectangle.GetTextureIndex());
-			Character& character = characters[rectangle.GetId()];
+			CodePoint code_point = (CodePoint)rectangle.GetId();
+			RMLUI_ASSERT(characters.find(code_point) != characters.end());
+			Character& character = characters[code_point];
 
 
 			// Set the character's texture index.
 			// Set the character's texture index.
 			character.texture_index = rectangle.GetTextureIndex();
 			character.texture_index = rectangle.GetTextureIndex();
@@ -164,7 +166,7 @@ bool FontFaceLayer::GenerateTexture(const byte*& texture_data, Vector2i& texture
 		texture_id > texture_layout.GetNumTextures())
 		texture_id > texture_layout.GetNumTextures())
 		return false;
 		return false;
 
 
-	const FontGlyphList& glyphs = handle->GetGlyphs();
+	const FontGlyphMap& glyphs = handle->GetGlyphs();
 
 
 	// Generate the texture data.
 	// Generate the texture data.
 	texture_data = texture_layout.GetTexture(texture_id).AllocateTexture();
 	texture_data = texture_layout.GetTexture(texture_id).AllocateTexture();
@@ -173,12 +175,19 @@ bool FontFaceLayer::GenerateTexture(const byte*& texture_data, Vector2i& texture
 	for (int i = 0; i < texture_layout.GetNumRectangles(); ++i)
 	for (int i = 0; i < texture_layout.GetNumRectangles(); ++i)
 	{
 	{
 		TextureLayoutRectangle& rectangle = texture_layout.GetRectangle(i);
 		TextureLayoutRectangle& rectangle = texture_layout.GetRectangle(i);
-		Character& character = characters[rectangle.GetId()];	
+		CodePoint code_point = (CodePoint)rectangle.GetId();
+		RMLUI_ASSERT(characters.find(code_point) != characters.end());
+		
+		Character& character = characters[code_point];
 
 
 		if (character.texture_index != texture_id)
 		if (character.texture_index != texture_id)
 			continue;
 			continue;
 
 
-		const FontGlyph& glyph = glyphs[rectangle.GetId()];
+		auto it = glyphs.find((CodePoint)rectangle.GetId());
+		if (it == glyphs.end())
+			continue;
+
+		const FontGlyph& glyph = it->second;
 
 
 		if (effect == nullptr)
 		if (effect == nullptr)
 		{
 		{

+ 8 - 6
Source/Core/FontFaceLayer.h

@@ -75,10 +75,12 @@ public:
 	/// @param[in] colour The colour of the string.
 	/// @param[in] colour The colour of the string.
 	inline void GenerateGeometry(Geometry* geometry, const CodePoint character_code, const Vector2f& position, const Colourb& colour) const
 	inline void GenerateGeometry(Geometry* geometry, const CodePoint character_code, const Vector2f& position, const Colourb& colour) const
 	{
 	{
-		if ((size_t)character_code >= characters.size())
+		auto it = characters.find(character_code);
+		if (it == characters.end())
 			return;
 			return;
 
 
-		const Character& character = characters[(size_t)character_code];
+		const Character& character = it->second;
+
 		if (character.texture_index < 0)
 		if (character.texture_index < 0)
 			return;
 			return;
 
 
@@ -116,7 +118,7 @@ public:
 	/// @return The layer's colour.
 	/// @return The layer's colour.
 	const Colourb& GetColour() const;
 	const Colourb& GetColour() const;
 
 
-// protected:
+private:
 	struct Character
 	struct Character
 	{
 	{
 		Character() : texture_index(-1) { }
 		Character() : texture_index(-1) { }
@@ -132,15 +134,15 @@ public:
 		int texture_index;
 		int texture_index;
 	};
 	};
 
 
-	typedef std::vector< Character > CharacterList;
-	typedef std::vector< Texture > TextureList;
+	using CharacterMap = UnorderedMap<CodePoint, Character>;
+	using TextureList = std::vector<Texture>;
 
 
 	const FontFaceHandle* handle;
 	const FontFaceHandle* handle;
 	SharedPtr<const FontEffect> effect;
 	SharedPtr<const FontEffect> effect;
 
 
 	TextureLayout texture_layout;
 	TextureLayout texture_layout;
 
 
-	CharacterList characters;
+	CharacterMap characters;
 	TextureList textures;
 	TextureList textures;
 	Colourb colour;
 	Colourb colour;
 };
 };

+ 1 - 1
Source/Core/FontFamily.cpp

@@ -64,7 +64,7 @@ SharedPtr<FontFaceHandle> FontFamily::GetFaceHandle(const String& charset, Style
 	if (matching_face == nullptr)
 	if (matching_face == nullptr)
 		return nullptr;
 		return nullptr;
 
 
-	return matching_face->GetHandle(charset, size);
+	return matching_face->GetHandle(size);
 }
 }
 
 
 }
 }

+ 11 - 54
Source/Core/FreeType/FontFace.cpp

@@ -33,63 +33,25 @@
 
 
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
-namespace FreeType {
 
 
-FontFace::FontFace(FT_Face _face, Style::FontStyle _style, Style::FontWeight _weight, bool _release_stream) : Rml::Core::FontFace(_style, _weight, _release_stream)
+FontFace_FreeType::FontFace_FreeType(FT_Face _face, Style::FontStyle _style, Style::FontWeight _weight, bool _release_stream) : Rml::Core::FontFace(_style, _weight, _release_stream)
 {
 {
 	face = _face;
 	face = _face;
 }
 }
 
 
-FontFace::~FontFace()
+FontFace_FreeType::~FontFace_FreeType()
 {
 {
 	ReleaseFace();
 	ReleaseFace();
 }
 }
 
 
 // Returns a handle for positioning and rendering this face at the given size.
 // Returns a handle for positioning and rendering this face at the given size.
-SharedPtr<Rml::Core::FontFaceHandle> FontFace::GetHandle(const String& _raw_charset, int size)
+SharedPtr<Rml::Core::FontFaceHandle> FontFace_FreeType::GetHandle(int size)
 {
 {
 	UnicodeRangeList charset;
 	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)
-			{
-				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.c_str());
-			return nullptr;
-		}
-
-		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)
-			{
-				return handles[i];
-			}
-		}
-	}
+	auto it = handles.find(size);
+	if (it != handles.end())
+		return it->second;
 
 
 	// See if this face has been released.
 	// See if this face has been released.
 	if (!face)
 	if (!face)
@@ -99,24 +61,20 @@ SharedPtr<Rml::Core::FontFaceHandle> FontFace::GetHandle(const String& _raw_char
 	}
 	}
 
 
 	// Construct and initialise the new handle.
 	// Construct and initialise the new handle.
-	auto handle = std::make_shared<FontFaceHandle>();
-	if (!handle->Initialise(face, _raw_charset, size))
+	auto handle = std::make_shared<FontFaceHandle_FreeType>();
+	if (!handle->Initialise(face, size))
 	{
 	{
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
-	// 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);
+	// Save the new handle to the font face
+	handles[size] = handle;
 
 
 	return handle;
 	return handle;
 }
 }
 
 
 // Releases the face's FreeType face structure.
 // Releases the face's FreeType face structure.
-void FontFace::ReleaseFace()
+void FontFace_FreeType::ReleaseFace()
 {
 {
 	if (face != nullptr)
 	if (face != nullptr)
 	{
 	{
@@ -132,4 +90,3 @@ void FontFace::ReleaseFace()
 
 
 }
 }
 }
 }
-}

+ 5 - 6
Source/Core/FreeType/FontFace.h

@@ -35,24 +35,24 @@
 
 
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
-namespace FreeType {
+
 /**
 /**
 	@author Peter Curry
 	@author Peter Curry
  */
  */
 
 
 class FontFaceHandle;
 class FontFaceHandle;
 
 
-class FontFace : public Rml::Core::FontFace
+class FontFace_FreeType : public Rml::Core::FontFace
 {
 {
 public:
 public:
-	FontFace(FT_Face face, Style::FontStyle style, Style::FontWeight weight, bool release_stream);
-	~FontFace();
+	FontFace_FreeType(FT_Face face, Style::FontStyle style, Style::FontWeight weight, bool release_stream);
+	~FontFace_FreeType();
 
 
 	/// Returns a handle for positioning and rendering this face at the given 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] 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.
-	SharedPtr<Rml::Core::FontFaceHandle> GetHandle(const String& charset, int size) override;
+	SharedPtr<Rml::Core::FontFaceHandle> GetHandle(int size) override;
 
 
 	/// 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.
@@ -62,7 +62,6 @@ private:
 	FT_Face face;
 	FT_Face face;
 };
 };
 
 
-}
 }
 }
 }
 }
 
 

+ 86 - 94
Source/Core/FreeType/FontFaceHandle.cpp

@@ -35,29 +35,27 @@
 
 
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
-namespace FreeType {
 
 
+static void BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph);
+static void BuildGlyphMap(FT_Face ft_face, FontGlyphMap& glyphs);
+static void GenerateMetrics(FT_Face ft_face, const FontGlyphMap& glyphs, FontMetrics& metrics);
 
 
-FontFaceHandle::FontFaceHandle()
+
+FontFaceHandle_FreeType::FontFaceHandle_FreeType()
 {
 {
 	ft_face = nullptr;
 	ft_face = nullptr;
 }
 }
 
 
-FontFaceHandle::~FontFaceHandle()
+FontFaceHandle_FreeType::~FontFaceHandle_FreeType()
 {
 {
 }
 }
 
 
+
 // Initialises the handle so it is able to render text.
 // Initialises the handle so it is able to render text.
-bool FontFaceHandle::Initialise(FT_Face ft_face, const String& _charset, int _size)
+bool FontFaceHandle_FreeType::Initialise(FT_Face ft_face, int size)
 {
 {
-	size = _size;
-
-	raw_charset = _charset;
-	if (!UnicodeRange::BuildList(charset, raw_charset))
-	{
-		Log::Message(Log::LT_ERROR, "Invalid font charset '%s'.", raw_charset.c_str());
-		return false;
-	}
+	this->ft_face = ft_face;
+	GetMetrics().size = size;
 
 
 	// Set the character size on the font face.
 	// Set the character size on the font face.
 	FT_Error error = FT_Set_Char_Size(ft_face, 0, size << 6, 0, 0);
 	FT_Error error = FT_Set_Char_Size(ft_face, 0, size << 6, 0, 0);
@@ -67,65 +65,25 @@ bool FontFaceHandle::Initialise(FT_Face ft_face, const String& _charset, int _si
 		return false;
 		return false;
 	}
 	}
 
 
-	this->ft_face = ft_face;
-
-	// find the maximum character we are interested in
-	max_codepoint = 0;
-	for (size_t i = 0; i < charset.size(); ++i)
-		max_codepoint = Math::Max(max_codepoint, charset[i].max_codepoint);
-
 	// Construct the list of the characters specified by the charset.
 	// Construct the list of the characters specified by the charset.
-	glyphs.resize(max_codepoint+1, FontGlyph());
-	for (size_t i = 0; i < charset.size(); ++i)
-		BuildGlyphMap(charset[i]);
+	BuildGlyphMap(ft_face, GetGlyphs());
 
 
 	// Generate the metrics for the handle.
 	// Generate the metrics for the handle.
-	GenerateMetrics();
+	GenerateMetrics(ft_face, GetGlyphs(), GetMetrics());
 
 
 	// Generate the default layer and layer configuration.
 	// Generate the default layer and layer configuration.
-	base_layer = GenerateLayer(nullptr);
-	layer_configurations.push_back(LayerConfiguration());
-	layer_configurations.back().push_back(base_layer);
-
+	GenerateBaseLayer();
 
 
 	return true;
 	return true;
 }
 }
 
 
-void FontFaceHandle::GenerateMetrics()
+static void BuildGlyphMap(FT_Face ft_face, FontGlyphMap& glyphs)
 {
 {
-	line_height = ft_face->size->metrics.height >> 6;
-	baseline = line_height - (ft_face->size->metrics.ascender >> 6);
-
-	underline_position = FT_MulFix(ft_face->underline_position, ft_face->size->metrics.y_scale) / float(1 << 6);
-	underline_thickness = FT_MulFix(ft_face->underline_thickness, ft_face->size->metrics.y_scale) / float(1 << 6);
-	underline_thickness = Math::Max(underline_thickness, 1.0f);
+	// TODO: ASCII range for now
+	FT_ULong code_min = 32;
+	FT_ULong code_max = 126;
 
 
-	average_advance = 0;
-	unsigned int num_visible_glyphs = 0;
-	for (FontGlyphList::iterator i = glyphs.begin(); i != glyphs.end(); ++i)
-	{
-		if (i->advance)
-		{
-			average_advance += i->advance;
-			num_visible_glyphs++;
-		}
-	}
-
-	// Bring the total advance down to the average advance, but scaled up 10%, just to be on the safe side.
-	if (num_visible_glyphs)
-		average_advance = Math::RealToInteger((float) average_advance / (num_visible_glyphs * 0.9f));
-
-	// Determine the x-height of this font face.
-	int index = FT_Get_Char_Index(ft_face, 'x');
-	if (FT_Load_Glyph(ft_face, index, 0) == 0)
-		x_height = ft_face->glyph->metrics.height >> 6;
-	else
-		x_height = 0;
-}
-
-void FontFaceHandle::BuildGlyphMap(const UnicodeRange& unicode_range)
-{
-	for (FT_ULong character_code = (FT_ULong)(Math::Max< unsigned int >(unicode_range.min_codepoint, 32)); character_code <= unicode_range.max_codepoint; ++character_code)
+	for (FT_ULong character_code = code_min; character_code <= code_max; ++character_code)
 	{
 	{
 		int index = FT_Get_Char_Index(ft_face, character_code);
 		int index = FT_Get_Char_Index(ft_face, character_code);
 		if (index != 0)
 		if (index != 0)
@@ -145,14 +103,13 @@ void FontFaceHandle::BuildGlyphMap(const UnicodeRange& unicode_range)
 			}
 			}
 
 
 			FontGlyph glyph;
 			FontGlyph glyph;
-			glyph.character = (CodePoint)character_code;
 			BuildGlyph(glyph, ft_face->glyph);
 			BuildGlyph(glyph, ft_face->glyph);
-			glyphs[character_code] = glyph;
+			glyphs[(CodePoint)character_code] = glyph;
 		}
 		}
 	}
 	}
 }
 }
 
 
-void FontFaceHandle::BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph)
+static void BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph)
 {
 {
 	// Set the glyph's dimensions.
 	// Set the glyph's dimensions.
 	glyph.dimensions.x = ft_glyph->metrics.width >> 6;
 	glyph.dimensions.x = ft_glyph->metrics.width >> 6;
@@ -190,44 +147,44 @@ void FontFaceHandle::BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph)
 			switch (ft_glyph->bitmap.pixel_mode)
 			switch (ft_glyph->bitmap.pixel_mode)
 			{
 			{
 				// Unpack 1-bit data into 8-bit.
 				// Unpack 1-bit data into 8-bit.
-				case FT_PIXEL_MODE_MONO:
+			case FT_PIXEL_MODE_MONO:
+			{
+				for (int i = 0; i < glyph.bitmap_dimensions.y; ++i)
 				{
 				{
-					for (int i = 0; i < glyph.bitmap_dimensions.y; ++i)
+					int mask = 0x80;
+					byte* source_byte = source_bitmap;
+					for (int j = 0; j < glyph.bitmap_dimensions.x; ++j)
 					{
 					{
-						int mask = 0x80;
-						byte* source_byte = source_bitmap;
-						for (int j = 0; j < glyph.bitmap_dimensions.x; ++j)
+						if ((*source_byte & mask) == mask)
+							destination_bitmap[j] = 255;
+						else
+							destination_bitmap[j] = 0;
+
+						mask >>= 1;
+						if (mask <= 0)
 						{
 						{
-							if ((*source_byte & mask) == mask)
-								destination_bitmap[j] = 255;
-							else
-								destination_bitmap[j] = 0;
-
-							mask >>= 1;
-							if (mask <= 0)
-							{
-								mask = 0x80;
-								++source_byte;
-							}
+							mask = 0x80;
+							++source_byte;
 						}
 						}
-
-						destination_bitmap += glyph.bitmap_dimensions.x;
-						source_bitmap += ft_glyph->bitmap.pitch;
 					}
 					}
+
+					destination_bitmap += glyph.bitmap_dimensions.x;
+					source_bitmap += ft_glyph->bitmap.pitch;
 				}
 				}
-				break;
+			}
+			break;
 
 
-				// Directly copy 8-bit data.
-				case FT_PIXEL_MODE_GRAY:
+			// Directly copy 8-bit data.
+			case FT_PIXEL_MODE_GRAY:
+			{
+				for (int i = 0; i < glyph.bitmap_dimensions.y; ++i)
 				{
 				{
-					for (int i = 0; i < glyph.bitmap_dimensions.y; ++i)
-					{
-						memcpy(destination_bitmap, source_bitmap, glyph.bitmap_dimensions.x);
-						destination_bitmap += glyph.bitmap_dimensions.x;
-						source_bitmap += ft_glyph->bitmap.pitch;
-					}
+					memcpy(destination_bitmap, source_bitmap, glyph.bitmap_dimensions.x);
+					destination_bitmap += glyph.bitmap_dimensions.x;
+					source_bitmap += ft_glyph->bitmap.pitch;
 				}
 				}
-				break;
+			}
+			break;
 			}
 			}
 		}
 		}
 	}
 	}
@@ -235,7 +192,42 @@ void FontFaceHandle::BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph)
 		glyph.bitmap_data = nullptr;
 		glyph.bitmap_data = nullptr;
 }
 }
 
 
-int FontFaceHandle::GetKerning(CodePoint lhs, CodePoint rhs) const
+
+static void GenerateMetrics(FT_Face ft_face, const FontGlyphMap& glyphs, FontMetrics& metrics)
+{
+	metrics.line_height = ft_face->size->metrics.height >> 6;
+	metrics.baseline = metrics.line_height - (ft_face->size->metrics.ascender >> 6);
+
+	metrics.underline_position = FT_MulFix(ft_face->underline_position, ft_face->size->metrics.y_scale) / float(1 << 6);
+	metrics.underline_thickness = FT_MulFix(ft_face->underline_thickness, ft_face->size->metrics.y_scale) / float(1 << 6);
+	metrics.underline_thickness = Math::Max(metrics.underline_thickness, 1.0f);
+
+	metrics.average_advance = 0;
+	unsigned int num_visible_glyphs = 0;
+	for (auto it = glyphs.begin(); it != glyphs.end(); ++it)
+	{
+		const FontGlyph& glyph = it->second;
+		if (glyph.advance)
+		{
+			metrics.average_advance += glyph.advance;
+			num_visible_glyphs++;
+		}
+	}
+
+	// Bring the total advance down to the average advance, but scaled up 10%, just to be on the safe side.
+	if (num_visible_glyphs)
+		metrics.average_advance = Math::RealToInteger((float)metrics.average_advance / (num_visible_glyphs * 0.9f));
+
+	// Determine the x-height of this font face.
+	int index = FT_Get_Char_Index(ft_face, 'x');
+	if (FT_Load_Glyph(ft_face, index, 0) == 0)
+		metrics.x_height = ft_face->glyph->metrics.height >> 6;
+	else
+		metrics.x_height = 0;
+}
+
+
+int FontFaceHandle_FreeType::GetKerning(CodePoint lhs, CodePoint rhs) const
 {
 {
 	if (!FT_HAS_KERNING(ft_face))
 	if (!FT_HAS_KERNING(ft_face))
 		return 0;
 		return 0;
@@ -257,6 +249,6 @@ int FontFaceHandle::GetKerning(CodePoint lhs, CodePoint rhs) const
 	return kerning;
 	return kerning;
 }
 }
 
 
-}
+
 }
 }
 }
 }

+ 5 - 14
Source/Core/FreeType/FontFaceHandle.h

@@ -41,38 +41,29 @@
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
 
 
-namespace FreeType {
-
 /**
 /**
 	@author Peter Curry
 	@author Peter Curry
  */
  */
 
 
-class FontFaceHandle : public Rml::Core::FontFaceHandle
+class FontFaceHandle_FreeType : public Rml::Core::FontFaceHandle
 {
 {
 public:
 public:
-	FontFaceHandle();
-	virtual ~FontFaceHandle();
+	FontFaceHandle_FreeType();
+	virtual ~FontFaceHandle_FreeType();
 
 
 	/// Initialises the handle so it is able to render text.
 	/// Initialises the handle so it is able to render text.
 	/// @param[in] ft_face The FreeType face that this handle is rendering.
 	/// @param[in] ft_face The FreeType face that this handle is rendering.
 	/// @param[in] charset The comma-separated list of unicode ranges this handle must support.
 	/// @param[in] charset The comma-separated list of unicode ranges this handle must support.
 	/// @param[in] size The size, in points, of the face this handle should render at.
 	/// @param[in] size The size, in points, of the face this handle should render at.
 	/// @return True if the handle initialised successfully and is ready for rendering, false if an error occured.
 	/// @return True if the handle initialised successfully and is ready for rendering, false if an error occured.
-	bool Initialise(FT_Face ft_face, const String& charset, int size);
-
-protected:
-	int GetKerning(CodePoint lhs, CodePoint rhs) const override;
+	bool Initialise(FT_Face ft_face, int size);
 
 
 private:
 private:
-	void GenerateMetrics(void);
-
-	void BuildGlyphMap(const UnicodeRange& unicode_range);
-	void BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph);
+	int GetKerning(CodePoint lhs, CodePoint rhs) const override;
 
 
 	FT_Face ft_face;
 	FT_Face ft_face;
 };
 };
 
 
-}
 }
 }
 }
 }
 
 

+ 4 - 4
Source/Core/FreeType/FontFamily.cpp

@@ -33,20 +33,20 @@
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
 
 
-FreeType::FontFamily::FontFamily(const String& name) : Rml::Core::FontFamily(name)
+FontFamily_FreeType::FontFamily_FreeType(const String& name) : Rml::Core::FontFamily(name)
 {
 {
 
 
 }
 }
 
 
-FreeType::FontFamily::~FontFamily()
+FontFamily_FreeType::~FontFamily_FreeType()
 {
 {
 
 
 }
 }
 
 
 // Adds a new face to the family.
 // Adds a new face to the family.
-bool FreeType::FontFamily::AddFace(void* ft_face, Style::FontStyle style, Style::FontWeight weight, bool release_stream)
+bool FontFamily_FreeType::AddFace(void* ft_face, Style::FontStyle style, Style::FontWeight weight, bool release_stream)
 {
 {
-	FontFace* face = new FreeType::FontFace((FT_Face)ft_face, style, weight, release_stream);
+	FontFace_FreeType* face = new FontFace_FreeType((FT_Face)ft_face, style, weight, release_stream);
 	font_faces.push_back(face);
 	font_faces.push_back(face);
 
 
 	return true;
 	return true;

+ 3 - 9
Source/Core/FreeType/FontFamily.h

@@ -36,20 +36,15 @@
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
 
 
-class FontFace;
-class FontFaceHandle;
-
 /**
 /**
 	@author Peter Curry
 	@author Peter Curry
  */
  */
 
 
-namespace FreeType {
-
-class FontFamily : public Rml::Core::FontFamily
+class FontFamily_FreeType : public Rml::Core::FontFamily
 {
 {
 public:
 public:
-	FontFamily(const String& name);
-	~FontFamily();
+	FontFamily_FreeType(const String& name);
+	~FontFamily_FreeType();
 
 
 	/// 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.
@@ -60,7 +55,6 @@ public:
 	bool AddFace(void* ft_face, Style::FontStyle style, Style::FontWeight weight, bool release_stream) override;
 	bool AddFace(void* ft_face, Style::FontStyle style, Style::FontWeight weight, bool release_stream) override;
 };
 };
 
 
-}
 }
 }
 }
 }
 
 

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

@@ -37,29 +37,28 @@
 
 
 namespace Rml {
 namespace Rml {
 namespace Core {
 namespace Core {
-namespace FreeType {
 
 
-FontProvider* FontProvider::instance = nullptr;
+FontProvider_FreeType* FontProvider_FreeType::instance = nullptr;
 
 
 static FT_Library ft_library = nullptr;
 static FT_Library ft_library = nullptr;
 
 
-FontProvider::FontProvider()
+FontProvider_FreeType::FontProvider_FreeType()
 {
 {
 	RMLUI_ASSERT(instance == nullptr);
 	RMLUI_ASSERT(instance == nullptr);
 	instance = this;
 	instance = this;
 }
 }
 
 
-FontProvider::~FontProvider()
+FontProvider_FreeType::~FontProvider_FreeType()
 {
 {
 	RMLUI_ASSERT(instance == this);
 	RMLUI_ASSERT(instance == this);
 	instance = nullptr;
 	instance = nullptr;
 }
 }
 
 
-bool FontProvider::Initialise()
+bool FontProvider_FreeType::Initialise()
 {
 {
 	if (instance == nullptr)
 	if (instance == nullptr)
 	{
 	{
-		new FontProvider();
+		new FontProvider_FreeType();
 
 
 		FontDatabase::AddFontProvider(instance);
 		FontDatabase::AddFontProvider(instance);
 
 
@@ -75,7 +74,7 @@ bool FontProvider::Initialise()
 	return true;
 	return true;
 }
 }
 
 
-void FontProvider::Shutdown()
+void FontProvider_FreeType::Shutdown()
 {
 {
 	if (instance != nullptr)
 	if (instance != nullptr)
 	{
 	{
@@ -95,7 +94,7 @@ void FontProvider::Shutdown()
 }
 }
 
 
 // Loads a new font face.
 // Loads a new font face.
-bool FontProvider::LoadFontFace(const String& file_name)
+bool FontProvider_FreeType::LoadFontFace(const String& file_name)
 {
 {
 	FT_Face ft_face = (FT_Face) instance->LoadFace(file_name);
 	FT_Face ft_face = (FT_Face) instance->LoadFace(file_name);
 	if (ft_face == nullptr)
 	if (ft_face == nullptr)
@@ -120,7 +119,7 @@ bool FontProvider::LoadFontFace(const String& file_name)
 }
 }
 
 
 // Adds a new font face to the database, ignoring any family, style and weight information stored in the face itself.
 // Adds a new font face to the database, ignoring any family, style and weight information stored in the face itself.
-bool FontProvider::LoadFontFace(const String& file_name, const String& family, Style::FontStyle style, Style::FontWeight weight)
+bool FontProvider_FreeType::LoadFontFace(const String& file_name, const String& family, Style::FontStyle style, Style::FontWeight weight)
 {
 {
 	FT_Face ft_face = (FT_Face) instance->LoadFace(file_name);
 	FT_Face ft_face = (FT_Face) instance->LoadFace(file_name);
 	if (ft_face == nullptr)
 	if (ft_face == nullptr)
@@ -142,7 +141,7 @@ bool FontProvider::LoadFontFace(const String& file_name, const String& family, S
 }
 }
 
 
 // Adds a new font face to the database, loading from memory.
 // Adds a new font face to the database, loading from memory.
-bool FontProvider::LoadFontFace(const byte* data, int data_length)
+bool FontProvider_FreeType::LoadFontFace(const byte* data, int data_length)
 {
 {
 	FT_Face ft_face = (FT_Face) instance->LoadFace(data, data_length, "memory", false);
 	FT_Face ft_face = (FT_Face) instance->LoadFace(data, data_length, "memory", false);
 	if (ft_face == nullptr)
 	if (ft_face == nullptr)
@@ -167,7 +166,7 @@ bool FontProvider::LoadFontFace(const byte* data, int data_length)
 }
 }
 
 
 // Adds a new font face to the database, loading from memory, ignoring any family, style and weight information stored in the face itself.
 // Adds a new font face to the database, loading from memory, ignoring any family, style and weight information stored in the face itself.
-bool FontProvider::LoadFontFace(const byte* data, int data_length, const String& family, Style::FontStyle style, Style::FontWeight weight)
+bool FontProvider_FreeType::LoadFontFace(const byte* data, int data_length, const String& family, Style::FontStyle style, Style::FontWeight weight)
 {
 {
 	FT_Face ft_face = (FT_Face) instance->LoadFace(data, data_length, "memory", false);
 	FT_Face ft_face = (FT_Face) instance->LoadFace(data, data_length, "memory", false);
 	if (ft_face == nullptr)
 	if (ft_face == nullptr)
@@ -189,16 +188,16 @@ bool FontProvider::LoadFontFace(const byte* data, int data_length, const String&
 }
 }
 
 
 // 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, Style::FontStyle style, Style::FontWeight weight, bool release_stream)
+bool FontProvider_FreeType::AddFace(void* face, const String& family, Style::FontStyle style, Style::FontWeight weight, bool release_stream)
 {
 {
 	String family_lower = StringUtilities::ToLower(family);
 	String family_lower = StringUtilities::ToLower(family);
-	FontFamily* font_family = nullptr;
+	FontFamily_FreeType* font_family = nullptr;
 	FontFamilyMap::iterator iterator = font_families.find(family_lower);
 	FontFamilyMap::iterator iterator = font_families.find(family_lower);
 	if (iterator != font_families.end())
 	if (iterator != font_families.end())
-		font_family = (FontFamily*)(*iterator).second;
+		font_family = (FontFamily_FreeType*)(*iterator).second;
 	else
 	else
 	{
 	{
-		font_family = new FontFamily(family_lower);
+		font_family = new FontFamily_FreeType(family_lower);
 		font_families[family_lower] = font_family;
 		font_families[family_lower] = font_family;
 	}
 	}
 
 
@@ -206,7 +205,7 @@ bool FontProvider::AddFace(void* face, const String& family, Style::FontStyle st
 }
 }
 
 
 // Loads a FreeType face.
 // Loads a FreeType face.
-void* FontProvider::LoadFace(const String& file_name)
+void* FontProvider_FreeType::LoadFace(const String& file_name)
 {
 {
 	FileInterface* file_interface = GetFileInterface();
 	FileInterface* file_interface = GetFileInterface();
 	FileHandle handle = file_interface->Open(file_name);
 	FileHandle handle = file_interface->Open(file_name);
@@ -226,7 +225,7 @@ void* FontProvider::LoadFace(const String& file_name)
 }
 }
 
 
 // Loads a FreeType face from memory.
 // Loads a FreeType face from memory.
-void* FontProvider::LoadFace(const byte* data, int data_length, const String& source, bool local_data)
+void* FontProvider_FreeType::LoadFace(const byte* data, int data_length, const String& source, bool local_data)
 {
 {
 	FT_Face face = nullptr;
 	FT_Face face = nullptr;
 	int error = FT_New_Memory_Face(ft_library, (const FT_Byte*) data, data_length, 0, &face);
 	int error = FT_New_Memory_Face(ft_library, (const FT_Byte*) data, data_length, 0, &face);
@@ -259,4 +258,3 @@ void* FontProvider::LoadFace(const byte* data, int data_length, const String& so
 
 
 }
 }
 }
 }
-}