Browse Source

Clean up font providers somewhat. There was a lot of duplicate code for no good reason, some of it inactive.
Also, the same class names but in a deeper namespace-style for derived classes really creates problems, didn't change this for now.
For some of the derived classes it makes little sense to use inheritance like here, the overall structure could need some updates.

Michael Ragazzon 6 years ago
parent
commit
70e9128969

+ 7 - 9
Source/Core/BitmapFont/FontFace.cpp

@@ -33,20 +33,19 @@
 
 namespace Rml {
 namespace Core {
-namespace BitmapFont {
 
-FontFace::FontFace(BitmapFontDefinitions *_face, Font::Style _style, Font::Weight _weight, bool _release_stream) : Rml::Core::FontFace(_style, _weight, _release_stream)
+BitmapFont::FontFace::FontFace(BitmapFontDefinitions *_face, Font::Style _style, Font::Weight _weight, bool _release_stream) : Rml::Core::FontFace(_style, _weight, _release_stream)
 {
 	face = _face;
 }
 
-FontFace::~FontFace()
+BitmapFont::FontFace::~FontFace()
 {
 	ReleaseFace();
 }
 
 // Returns a handle for positioning and rendering this face at the given size.
-Rml::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size)
+Rml::Core::FontFaceHandle* BitmapFont::FontFace::GetHandle(const String& _raw_charset, int size)
 {
 	UnicodeRangeList charset;
 
@@ -63,7 +62,7 @@ Rml::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int s
 			if (handles[i]->GetRawCharset() == _raw_charset)
 			{
 				handles[i]->AddReference();
-				return (FontFaceHandle*)handles[i];
+				return handles[i];
 			}
 		}
 
@@ -88,7 +87,7 @@ Rml::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int s
 			if (range_contained)
 			{
 				handles[i]->AddReference();
-				return (FontFaceHandle*)handles[i];
+				return handles[i];
 			}
 		}
 	}
@@ -101,7 +100,7 @@ Rml::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int s
 	}
 
 	// Construct and initialise the new handle.
-	FontFaceHandle* handle = new FontFaceHandle();
+	BitmapFont::FontFaceHandle* handle = new BitmapFont::FontFaceHandle();
 	if (!handle->Initialise(face, _raw_charset, size))
 	{
 		handle->RemoveReference();
@@ -121,11 +120,10 @@ Rml::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int s
 }
 
 // Releases the face's structure.
-void FontFace::ReleaseFace()
+void BitmapFont::FontFace::ReleaseFace()
 {
 	delete face;
 }
 
 }
 }
-}

+ 2 - 2
Source/Core/BitmapFont/FontFace.h

@@ -52,11 +52,11 @@ public:
 	/// @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.
-	Rml::Core::FontFaceHandle* GetHandle(const String& charset, int size);
+	Rml::Core::FontFaceHandle* GetHandle(const String& charset, int size) override;
 
 	/// 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();
+	void ReleaseFace() override;
 
 private:
 	BitmapFontDefinitions *face;

+ 18 - 144
Source/Core/BitmapFont/FontFaceHandle.cpp

@@ -34,31 +34,22 @@
 
 namespace Rml {
 namespace Core {
-namespace BitmapFont {
 
-
-FontFaceHandle::FontFaceHandle()
+BitmapFont::FontFaceHandle::FontFaceHandle()
 {
-	size = 0;
-	average_advance = 0;
-	x_height = 0;
-	line_height = 0;
-	baseline = 0;
-
-	underline_position = 0;
-	underline_thickness = 0;
-
-	base_layer = NULL;
+	bm_face = nullptr;
+	texture_width = 0;
+	texture_height = 0;
 }
 
-FontFaceHandle::~FontFaceHandle()
+BitmapFont::FontFaceHandle::~FontFaceHandle()
 {
 }
 
 // Initialises the handle so it is able to render text.
-bool FontFaceHandle::Initialise(BitmapFontDefinitions *bm_face, const String& _charset, int _size)
+bool BitmapFont::FontFaceHandle::Initialise(BitmapFontDefinitions *_bm_face, const String& _charset, int _size)
 {
-	this->bm_face = bm_face;
+	bm_face = _bm_face;
 	size = _size;
 	line_height = _size;
 	texture_width = bm_face->CommonCharactersInfo.ScaleWidth;
@@ -95,142 +86,20 @@ bool FontFaceHandle::Initialise(BitmapFontDefinitions *bm_face, const String& _c
 	GenerateMetrics(bm_face);
 
 	// Generate the default layer and layer configuration.
-	base_layer = GenerateLayer(NULL);
+	base_layer = GenerateLayer(nullptr);
 	layer_configurations.push_back(LayerConfiguration());
 	layer_configurations.back().push_back(base_layer);
 
 	return true;
 }
 
-// Returns the width a string will take up if rendered with this handle.
-int FontFaceHandle::GetStringWidth(const WString& string, word prior_character) const
-{
-	int width = 0;
-
-	for (size_t i = 0; i < string.size(); i++)
-	{
-		word character_code = string[i];
-
-		if (character_code >= glyphs.size())
-			continue;
-		const FontGlyph &glyph = glyphs[character_code];
-
-		// Adjust the cursor for the kerning between this character and the previous one.
-		if (prior_character != 0)
-			width += GetKerning(prior_character, string[i]);
-		// Adjust the cursor for this character's advance.
-		width += glyph.advance;
-
-		prior_character = character_code;
-	}
-
-	return width;
-}
-
-// Generates the texture data for a layer (for the texture database).
-bool FontFaceHandle::GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, Rml::Core::FontEffect* layer_id, int texture_id)
-{
-	FontLayerMap::iterator layer_iterator = layers.find(layer_id);
-	if (layer_iterator == layers.end())
-		return false;
-
-	return layer_iterator->second->GenerateTexture(texture_data, texture_dimensions, texture_id);
-}
-
-// Generates the geometry required to render a single line of text.
-int FontFaceHandle::GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration_index) const
-{
-	int geometry_index = 0;
-	int line_width = 0;
-
-	RMLUI_ASSERT(layer_configuration_index >= 0);
-	RMLUI_ASSERT(layer_configuration_index < (int) layer_configurations.size());
-
-	// Fetch the requested configuration and generate the geometry for each one.
-	const LayerConfiguration& layer_configuration = layer_configurations[layer_configuration_index];
-	for (size_t i = 0; i < layer_configuration.size(); ++i)
-	{
-		Rml::Core::FontFaceLayer* layer = layer_configuration[i];
-
-		Colourb layer_colour;
-		if (layer == base_layer)
-			layer_colour = colour;
-		else
-			layer_colour = layer->GetColour();
-
-		// Resize the geometry list if required.
-		if ((int) geometry.size() < geometry_index + layer->GetNumTextures())
-			geometry.resize(geometry_index + layer->GetNumTextures());
-
-		// Bind the textures to the geometries.
-		for (int i = 0; i < layer->GetNumTextures(); ++i)
-			geometry[geometry_index + i].SetTexture(layer->GetTexture(i));
-
-		line_width = 0;
-		word prior_character = 0;
-
-		const word* string_iterator = string.c_str();
-		const word* string_end = string.c_str() + string.size();
-
-		for (; string_iterator != string_end; string_iterator++)
-		{
-			if (*string_iterator >= glyphs.size())
-				continue;
-			const FontGlyph &glyph = glyphs[*string_iterator];
-
-			// Adjust the cursor for the kerning between this character and the previous one.
-			if (prior_character != 0)
-				line_width += GetKerning(prior_character, *string_iterator);
-
-			layer->GenerateGeometry(&geometry[geometry_index], *string_iterator, Vector2f(position.x + line_width, position.y), layer_colour);
-
-			line_width += glyph.advance;
-			prior_character = *string_iterator;
-		}
-
-		geometry_index += layer->GetNumTextures();
-	}
-
-	// Cull any excess geometry from a previous generation.
-	geometry.resize(geometry_index);
-
-	return line_width;
-}
-
-// Generates the geometry required to render a line above, below or through a line of text.
-void FontFaceHandle::GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const
-{
-	std::vector< Vertex >& line_vertices = geometry->GetVertices();
-	std::vector< int >& line_indices = geometry->GetIndices();
-
-	float offset;
-	switch (height)
-	{
-		case Font::UNDERLINE:			offset = -underline_position; break;
-		case Font::OVERLINE:			// where to place? offset = -line_height - underline_position; break;
-		case Font::STRIKE_THROUGH:		// where to place? offset = -line_height * 0.5f; break;
-		default:						return;
-	}
-
-	line_vertices.resize(line_vertices.size() + 4);
-	line_indices.resize(line_indices.size() + 6);
-	GeometryUtilities::GenerateQuad(
-		&line_vertices[0] + ((int)line_vertices.size() - 4),
-		&line_indices[0] + ((int)line_indices.size() - 6),
-		Vector2f(position.x, position.y + offset), 
-		Vector2f((float) width, underline_thickness), 
-		colour,
-		(int)line_vertices.size() - 4
-	);
-}
-
 // Destroys the handle.
-void FontFaceHandle::OnReferenceDeactivate()
+void BitmapFont::FontFaceHandle::OnReferenceDeactivate()
 {
 	delete this;
 }
 
-void FontFaceHandle::GenerateMetrics(BitmapFontDefinitions *bm_face)
+void BitmapFont::FontFaceHandle::GenerateMetrics(BitmapFontDefinitions *bm_face)
 {
 	line_height = bm_face->CommonCharactersInfo.LineHeight;
 	baseline = bm_face->CommonCharactersInfo.BaseLine;
@@ -256,7 +125,7 @@ void FontFaceHandle::GenerateMetrics(BitmapFontDefinitions *bm_face)
 		x_height = 0;
 }
 
-void FontFaceHandle::BuildGlyphMap(BitmapFontDefinitions *bm_face, const UnicodeRange& unicode_range)
+void BitmapFont::FontFaceHandle::BuildGlyphMap(BitmapFontDefinitions *bm_face, const UnicodeRange& unicode_range)
 {
 	glyphs.resize(unicode_range.max_codepoint + 1);
 
@@ -276,7 +145,7 @@ void FontFaceHandle::BuildGlyphMap(BitmapFontDefinitions *bm_face, const Unicode
 	}
 }
 
-void Rml::Core::BitmapFont::FontFaceHandle::BuildGlyph(FontGlyph& glyph, CharacterInfo *bm_glyph)
+void BitmapFont::FontFaceHandle::BuildGlyph(FontGlyph& glyph, CharacterInfo *bm_glyph)
 {
 	// Set the glyph's dimensions.
 	glyph.dimensions.x = bm_glyph->Width;
@@ -296,7 +165,7 @@ void Rml::Core::BitmapFont::FontFaceHandle::BuildGlyph(FontGlyph& glyph, Charact
 	glyph.bitmap_data = NULL;
 }
 
-int Rml::Core::BitmapFont::FontFaceHandle::GetKerning(word lhs, word rhs) const
+int BitmapFont::FontFaceHandle::GetKerning(word lhs, word rhs) const
 {
 	if( bm_face != NULL)
 	{
@@ -306,6 +175,11 @@ int Rml::Core::BitmapFont::FontFaceHandle::GetKerning(word lhs, word rhs) const
 	return 0;
 }
 
+Rml::Core::FontFaceLayer* BitmapFont::FontFaceHandle::CreateNewLayer()
+{
+	return new BitmapFont::FontFaceLayer();
 }
+
+
 }
 }

+ 2 - 33
Source/Core/BitmapFont/FontFaceHandle.h

@@ -54,41 +54,8 @@ public:
 	virtual ~FontFaceHandle();
 
 	/// Initialises the handle so it is able to render text.
-	/// @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] 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.
 	bool Initialise(BitmapFontDefinitions *bm_face, const String& charset, int size);
 
-	/// Returns the width a string will take up if rendered with this handle.
-	/// @param[in] string The string to measure.
-	/// @param[in] prior_character The optionally-specified character that immediately precedes the string. This may have an impact on the string width due to kerning.
-	/// @return The width, in pixels, this string will occupy if rendered with this handle.
-	int GetStringWidth(const WString& string, word prior_character = 0) const override;
-
-	/// Generates the texture data for a layer (for the texture database).
-	/// @param[out] texture_data The pointer to be set to the generated texture data.
-	/// @param[out] texture_dimensions The dimensions of the texture.
-	/// @param[in] layer_id The id of the layer to request the texture data from.
-	/// @param[in] texture_id The index of the texture within the layer to generate.
-	bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id) override;
-
-	/// Generates the geometry required to render a single line of text.
-	/// @param[out] geometry An array of geometries to generate the geometry into.
-	/// @param[in] string The string to render.
-	/// @param[in] position The position of the baseline of the first character to render.
-	/// @param[in] colour The colour to render the text.
-	/// @return The width, in pixels, of the string geometry.
-	int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const override;
-
-	/// Generates the geometry required to render a line above, below or through a line of text.
-	/// @param[out] geometry The geometry to append the newly created geometry into.
-	/// @param[in] position The position of the baseline of the lined text.
-	/// @param[in] width The width of the string to line.
-	/// @param[in] height The height to render the line at.
-	/// @param[in] colour The colour to draw the line in.
-	void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const override;
-
 	const String & GetTextureSource() const
 	{
 		return texture_source;
@@ -108,6 +75,8 @@ protected:
 	/// Destroys the handle.
 	void OnReferenceDeactivate() override;
 
+	Rml::Core::FontFaceLayer* CreateNewLayer() override;
+
 private:
 	void GenerateMetrics(BitmapFontDefinitions *bm_face);
 

+ 4 - 6
Source/Core/BitmapFont/FontFaceLayer.cpp

@@ -32,20 +32,19 @@
 
 namespace Rml {
 namespace Core {
-namespace BitmapFont {
 
-FontFaceLayer::FontFaceLayer() : Rml::Core::FontFaceLayer()
+BitmapFont::FontFaceLayer::FontFaceLayer() : Rml::Core::FontFaceLayer()
 {
 	handle = NULL;
 	effect = NULL;
 }
 
-FontFaceLayer::~FontFaceLayer()
+BitmapFont::FontFaceLayer::~FontFaceLayer()
 {
 }
 
 // Generates the character and texture data for the layer.
-bool FontFaceLayer::Initialise(const Rml::Core::FontFaceHandle* _handle, std::shared_ptr<const FontEffect> _effect, const Rml::Core::FontFaceLayer* clone, bool deep_clone)
+bool BitmapFont::FontFaceLayer::Initialise(const Rml::Core::FontFaceHandle* _handle, std::shared_ptr<const FontEffect> _effect, const Rml::Core::FontFaceLayer* clone, bool deep_clone)
 {
 	(void)(_effect);
 
@@ -118,11 +117,10 @@ bool FontFaceLayer::Initialise(const Rml::Core::FontFaceHandle* _handle, std::sh
 }
 
 // Generates the texture data for a layer (for the texture database).
-bool FontFaceLayer::GenerateTexture(const byte*& texture_data, Vector2i& texture_dimensions, int texture_id)
+bool BitmapFont::FontFaceLayer::GenerateTexture(const byte*& texture_data, Vector2i& texture_dimensions, int texture_id)
 {
 	return true;
 }
 
 }
 }
-}

+ 4 - 6
Source/Core/BitmapFont/FontFamily.cpp

@@ -32,20 +32,19 @@
 
 namespace Rml {
 namespace Core {
-namespace BitmapFont {
 
-FontFamily::FontFamily(const String& name) : Rml::Core::FontFamily(name)
+BitmapFont::FontFamily::FontFamily(const String& name) : Rml::Core::FontFamily(name)
 {
 }
 
-FontFamily::~FontFamily()
+BitmapFont::FontFamily::~FontFamily()
 {
 }
 
 // Adds a new face to the family.
-bool FontFamily::AddFace( void *bm_face, Font::Style style, Font::Weight weight, bool release_stream)
+bool BitmapFont::FontFamily::AddFace( void *bm_face, Font::Style style, Font::Weight weight, bool release_stream)
 {
-	Rml::Core::FontFace* face = new FontFace((BitmapFontDefinitions*)bm_face, style, weight, release_stream);
+	Rml::Core::FontFace* face = new BitmapFont::FontFace((BitmapFontDefinitions*)bm_face, style, weight, release_stream);
 	font_faces.push_back(face);
 
 	return true;
@@ -53,4 +52,3 @@ bool FontFamily::AddFace( void *bm_face, Font::Style style, Font::Weight weight,
 
 }
 }
-}

+ 1 - 1
Source/Core/BitmapFont/FontFamily.h

@@ -57,7 +57,7 @@ public:
 	/// @param[in] weight The weight of the new face.
 	/// @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.
-	bool AddFace( void *bm_face, Font::Style style, Font::Weight weight, bool release_stream);
+	bool AddFace( void *bm_face, Font::Style style, Font::Weight weight, bool release_stream) override;
 };
 
 }

+ 9 - 9
Source/Core/BitmapFont/FontParser.cpp

@@ -31,9 +31,8 @@
 
 namespace Rml {
 namespace Core {
-namespace BitmapFont {
 
-FontParser::FontParser( BitmapFontDefinitions *face )
+BitmapFont::FontParser::FontParser( BitmapFontDefinitions *face )
 	: BaseXMLParser()
 {
 	bm_face = face;
@@ -41,12 +40,12 @@ FontParser::FontParser( BitmapFontDefinitions *face )
 	kern_id = 0;
 }
 
-FontParser::~FontParser()
+BitmapFont::FontParser::~FontParser()
 {
 }
 
 // Called when the parser finds the beginning of an element tag.
-void FontParser::HandleElementStart(const String& name, const XMLAttributes& attributes)
+void BitmapFont::FontParser::HandleElementStart(const String& name, const XMLAttributes& attributes)
 {
 	if ( name == "info" )
 	{
@@ -68,7 +67,8 @@ void FontParser::HandleElementStart(const String& name, const XMLAttributes& att
 	else if ( name == "chars" )
 	{
 		bm_face->CommonCharactersInfo.CharacterCount = Get(attributes, "count", 0);
-		bm_face->CharactersInfo = new CharacterInfo[ Get(attributes, "count", 0) ];
+		// Memory @leak ?
+		bm_face->CharactersInfo = new BitmapFont::CharacterInfo[ Get(attributes, "count", 0) ];
 	}
 	else if ( name == "char" )
 	{
@@ -86,7 +86,8 @@ void FontParser::HandleElementStart(const String& name, const XMLAttributes& att
 	else if ( name == "kernings" )
 	{
 		bm_face->CommonCharactersInfo.KerningCount = Get(attributes, "count", 0);
-		bm_face->KerningsInfo = new KerningInfo[ Get(attributes, "count", 0) ];
+		// Memory @leak ?
+		bm_face->KerningsInfo = new BitmapFont::KerningInfo[ Get(attributes, "count", 0) ];
 	}
 	else if ( name == "kerning" )
 	{
@@ -99,17 +100,16 @@ void FontParser::HandleElementStart(const String& name, const XMLAttributes& att
 }
 
 // Called when the parser finds the end of an element tag.
-void FontParser::HandleElementEnd(const String& RMLUI_UNUSED_PARAMETER(name))
+void BitmapFont::FontParser::HandleElementEnd(const String& RMLUI_UNUSED_PARAMETER(name))
 {
 	RMLUI_UNUSED(name);
 }
 
 // Called when the parser encounters data.
-void FontParser::HandleData(const String& RMLUI_UNUSED_PARAMETER(data))
+void BitmapFont::FontParser::HandleData(const String& RMLUI_UNUSED_PARAMETER(data))
 {
 	RMLUI_UNUSED(data);
 }
 
 }
 }
-}

+ 3 - 4
Source/Core/BitmapFont/FontParser.h

@@ -33,7 +33,6 @@
 #include <RmlUi/Core/Types.h>
 #include <RmlUi/Core/Dictionary.h>
 #include "BitmapFontDefinitions.h"
-#include <set>
 
 namespace Rml {
 namespace Core {
@@ -50,11 +49,11 @@ class FontParser : public BaseXMLParser
 		virtual ~FontParser();
 
 		/// Called when the parser finds the beginning of an element tag.
-		virtual void HandleElementStart(const String& name, const XMLAttributes& attributes);
+		void HandleElementStart(const String& name, const XMLAttributes& attributes) override;
 		/// Called when the parser finds the end of an element tag.
-		virtual void HandleElementEnd(const String& name);
+		void HandleElementEnd(const String& name) override;
 		/// Called when the parser encounters data.
-		virtual void HandleData(const String& data);
+		void HandleData(const String& data) override;
 
 	private:
 		FontParser();

+ 18 - 22
Source/Core/BitmapFont/FontProvider.cpp

@@ -38,24 +38,22 @@
 
 namespace Rml {
 namespace Core {
-namespace BitmapFont {
 
+BitmapFont::FontProvider* BitmapFont::FontProvider::instance = NULL;
 
-FontProvider* FontProvider::instance = NULL;
-
-FontProvider::FontProvider()
+BitmapFont::FontProvider::FontProvider()
 {
 	RMLUI_ASSERT(instance == NULL);
 	instance = this;
 }
 
-FontProvider::~FontProvider()
+BitmapFont::FontProvider::~FontProvider()
 {
 	RMLUI_ASSERT(instance == this);
 	instance = NULL;
 }
 
-bool FontProvider::Initialise()
+bool BitmapFont::FontProvider::Initialise()
 {
 	if (instance == NULL)
 	{
@@ -67,7 +65,7 @@ bool FontProvider::Initialise()
 	return true;
 }
 
-void FontProvider::Shutdown()
+void BitmapFont::FontProvider::Shutdown()
 {
 	if (instance != NULL)
 	{
@@ -78,9 +76,9 @@ void FontProvider::Shutdown()
 }
 
 // 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)
+bool BitmapFont::FontProvider::LoadFontFace(const String& file_name)
 {
-	BitmapFontDefinitions *bm_font = (BitmapFontDefinitions*) instance->LoadFace(file_name);
+	BitmapFont::BitmapFontDefinitions *bm_font = (BitmapFont::BitmapFontDefinitions*) instance->LoadFace(file_name);
 
 	if (bm_font == NULL)
 	{
@@ -106,9 +104,9 @@ bool FontProvider::LoadFontFace(const String& file_name)
 }
 
 // Loads a new font face.
-bool FontProvider::LoadFontFace(const String& file_name, const String& family, Font::Style style, Font::Weight weight)
+bool BitmapFont::FontProvider::LoadFontFace(const String& file_name, const String& family, Font::Style style, Font::Weight weight)
 {
-	BitmapFontDefinitions *bm_font = (BitmapFontDefinitions*) instance->LoadFace(file_name);
+	BitmapFont::BitmapFontDefinitions *bm_font = (BitmapFont::BitmapFontDefinitions*) instance->LoadFace(file_name);
 	if (bm_font == NULL)
 	{
 		Log::Message(Log::LT_ERROR, "Failed to load font face from %s.", file_name.c_str());
@@ -129,21 +127,21 @@ bool FontProvider::LoadFontFace(const String& file_name, const String& family, F
 	return true;
 }
 
-bool FontProvider::LoadFontFace(const byte* data, int data_length)
+bool BitmapFont::FontProvider::LoadFontFace(const byte* data, int data_length)
 {
 	// TODO: Loading from memory
 	return false;
 }
 
 // Adds a new font face to the database, loading from memory.
-bool FontProvider::LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight)
+bool BitmapFont::FontProvider::LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight)
 {
 	// TODO Loading from memory
 	return false;
 }
 
 // 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 BitmapFont::FontProvider::AddFace(void* face, const String& family, Font::Style style, Font::Weight weight, bool release_stream)
 {
 	String family_lower = ToLower(family);
 	Rml::Core::FontFamily* font_family = NULL;
@@ -157,14 +155,13 @@ bool FontProvider::AddFace(void* face, const String& family, Font::Style style,
 	}
 
 	return font_family->AddFace((BitmapFontDefinitions *) face, style, weight, release_stream);
-	return true;
 }
 
 // Loads a FreeType face.
-void* FontProvider::LoadFace(const String& file_name)
+void* BitmapFont::FontProvider::LoadFace(const String& file_name)
 {
-	BitmapFontDefinitions *bm_face = new BitmapFontDefinitions();
-	FontParser parser( bm_face );
+	BitmapFont::BitmapFontDefinitions *bm_face = new BitmapFont::BitmapFontDefinitions();
+	BitmapFont::FontParser parser( bm_face );
 
 	FileInterface* file_interface = GetFileInterface();
 	FileHandle handle = file_interface->Open(file_name);
@@ -190,12 +187,12 @@ void* FontProvider::LoadFace(const String& file_name)
 }
 
 // Loads a FreeType face from memory.
-void* FontProvider::LoadFace(const byte* data, int data_length, const String& source, bool local_data)
+void* BitmapFont::FontProvider::LoadFace(const byte* data, int data_length, const String& source, bool local_data)
 {
 	URL file_url = source + ".fnt";
 
-	BitmapFontDefinitions *bm_face = new BitmapFontDefinitions();
-	FontParser parser( bm_face );
+	BitmapFont::BitmapFontDefinitions *bm_face = new BitmapFont::BitmapFontDefinitions();
+	BitmapFont::FontParser parser( bm_face );
 	StreamMemory* stream = new StreamMemory( data, data_length );
 	stream->SetSourceURL( file_url );
 
@@ -207,4 +204,3 @@ void* FontProvider::LoadFace(const byte* data, int data_length, const String& so
 
 }
 }
-}

+ 25 - 11
Source/Core/FontFaceHandle.cpp

@@ -47,7 +47,7 @@ FontFaceHandle::FontFaceHandle()
 	underline_position = 0;
 	underline_thickness = 0;
 
-	base_layer = NULL;
+	base_layer = nullptr;
 }
 
 FontFaceHandle::~FontFaceHandle()
@@ -217,6 +217,8 @@ int FontFaceHandle::GenerateString(GeometryList& geometry, const WString& string
 		// Resize the geometry list if required.
 		if ((int) geometry.size() < geometry_index + layer->GetNumTextures())
 			geometry.resize(geometry_index + layer->GetNumTextures());
+		
+		RMLUI_ASSERT(!geometry.empty());
 
 		// Bind the textures to the geometries.
 		for (int i = 0; i < layer->GetNumTextures(); ++i)
@@ -225,23 +227,23 @@ int FontFaceHandle::GenerateString(GeometryList& geometry, const WString& string
 		line_width = 0;
 		word prior_character = 0;
 
-		const word* string_iterator = string.c_str();
-		const word* string_end = string.c_str() + string.size();
+		geometry[geometry_index].GetIndices().reserve(string.size() * 6);
+		geometry[geometry_index].GetVertices().reserve(string.size() * 4);
 
-		for (; string_iterator != string_end; string_iterator++)
+		for (const word character : string)
 		{
-			if (*string_iterator >= glyphs.size())
+			if (character >= glyphs.size())
 				continue;
-			const FontGlyph &glyph = glyphs[*string_iterator];
+			const FontGlyph &glyph = glyphs[character];
 
 			// Adjust the cursor for the kerning between this character and the previous one.
 			if (prior_character != 0)
-				line_width += GetKerning(prior_character, *string_iterator);
+				line_width += GetKerning(prior_character, character);
 
-			layer->GenerateGeometry(&geometry[geometry_index], *string_iterator, Vector2f(position.x + line_width, position.y), layer_colour);
+			layer->GenerateGeometry(&geometry[geometry_index], character, Vector2f(position.x + line_width, position.y), layer_colour);
 
 			line_width += glyph.advance;
-			prior_character = *string_iterator;
+			prior_character = character;
 		}
 
 		geometry_index += layer->GetNumTextures();
@@ -270,7 +272,14 @@ void FontFaceHandle::GenerateLine(Geometry* geometry, const Vector2f& position,
 
 	line_vertices.resize(line_vertices.size() + 4);
 	line_indices.resize(line_indices.size() + 6);
-	GeometryUtilities::GenerateQuad(&line_vertices[0] + (line_vertices.size() - 4), &line_indices[0] + (line_indices.size() - 6), Vector2f(position.x, position.y + offset).Round(), Vector2f((float) width, underline_thickness), colour, (int)line_vertices.size() - 4);
+	GeometryUtilities::GenerateQuad(
+		&line_vertices[0] + ((int)line_vertices.size() - 4),
+		&line_indices[0] + ((int)line_indices.size() - 6),
+		Vector2f(position.x, position.y + offset).Round(),
+		Vector2f((float) width, underline_thickness),
+		colour, 
+		(int)line_vertices.size() - 4
+	);
 }
 
 // Returns the font face's raw charset (the charset range as a string).
@@ -291,6 +300,11 @@ void FontFaceHandle::OnReferenceDeactivate()
 	delete this;
 }
 
+Rml::Core::FontFaceLayer* FontFaceHandle::CreateNewLayer()
+{
+	return new Rml::Core::FontFaceLayer();
+}
+
 // Generates (or shares) a layer derived from a font effect.
 FontFaceLayer* FontFaceHandle::GenerateLayer(const std::shared_ptr<const FontEffect>& font_effect)
 {
@@ -299,7 +313,7 @@ FontFaceLayer* FontFaceHandle::GenerateLayer(const std::shared_ptr<const FontEff
 	if (i != layers.end())
 		return i->second;
 
-	FontFaceLayer* layer = new FontFaceLayer();
+	FontFaceLayer* layer = CreateNewLayer();
 	layers[font_effect.get()] = layer;
 
 	if (!font_effect)

+ 9 - 7
Source/Core/FontFaceHandle.h

@@ -79,18 +79,18 @@ public:
 	/// @param[in] string The string to measure.
 	/// @param[in] prior_character The optionally-specified character that immediately precedes the string. This may have an impact on the string width due to kerning.
 	/// @return The width, in pixels, this string will occupy if rendered with this handle.
-	virtual int GetStringWidth(const WString& string, word prior_character = 0) const = 0;
+	int GetStringWidth(const WString& string, word prior_character = 0) const;
 
 	/// Generates, if required, the layer configuration for a given array of font effects.
 	/// @param[in] font_effects The list of font effects to generate the configuration for.
 	/// @return The index to use when generating geometry using this configuration.
-	virtual int GenerateLayerConfiguration(const FontEffectList& font_effects);
+	int GenerateLayerConfiguration(const FontEffectList& font_effects);
 	/// Generates the texture data for a layer (for the texture database).
 	/// @param[out] texture_data The pointer to be set to the generated texture data.
 	/// @param[out] texture_dimensions The dimensions of the texture.
 	/// @param[in] layer_id The id of the layer to request the texture data from.
 	/// @param[in] texture_id The index of the texture within the layer to generate.
-	virtual bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id) = 0;
+	bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id);
 
 	/// Generates the geometry required to render a single line of text.
 	/// @param[out] geometry An array of geometries to generate the geometry into.
@@ -98,14 +98,14 @@ public:
 	/// @param[in] position The position of the baseline of the first character to render.
 	/// @param[in] colour The colour to render the text.
 	/// @return The width, in pixels, of the string geometry.
-	virtual int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const = 0;
+	int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const;
 	/// Generates the geometry required to render a line above, below or through a line of text.
 	/// @param[out] geometry The geometry to append the newly created geometry into.
 	/// @param[in] position The position of the baseline of the lined text.
 	/// @param[in] width The width of the string to line.
 	/// @param[in] height The height to render the line at.
 	/// @param[in] colour The colour to draw the line in.
-	virtual void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const = 0;
+	void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const;
 
 	/// Returns the font face's raw charset (the charset range as a string).
 	/// @return The font face's charset.
@@ -115,10 +115,12 @@ public:
 	const UnicodeRangeList& GetCharset() const;
 
 protected:
-	/// Destroys the handle.
 	void OnReferenceDeactivate() override;
-	FontFaceLayer* GenerateLayer(const std::shared_ptr<const FontEffect>& font_effect);
+
 	virtual int GetKerning(word lhs, word rhs) const = 0;
+	virtual FontFaceLayer* CreateNewLayer();
+
+	FontFaceLayer* GenerateLayer(const std::shared_ptr<const FontEffect>& font_effect);
 
 	typedef std::vector< int > GlyphKerningList;
 	typedef std::vector< GlyphKerningList > FontKerningList;

+ 2 - 2
Source/Core/FreeType/FontFace.h

@@ -52,11 +52,11 @@ public:
 	/// @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.
-	Rml::Core::FontFaceHandle* GetHandle(const String& charset, int size);
+	Rml::Core::FontFaceHandle* GetHandle(const String& charset, int size) override;
 
 	/// 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();
+	void ReleaseFace() override;
 
 private:
 	FT_Face face;

+ 2 - 120
Source/Core/FreeType/FontFaceHandle.cpp

@@ -40,7 +40,7 @@ namespace FreeType {
 
 FontFaceHandle::FontFaceHandle()
 {
-	ft_face = NULL;
+	ft_face = nullptr;
 }
 
 FontFaceHandle::~FontFaceHandle()
@@ -83,7 +83,7 @@ bool FontFaceHandle::Initialise(FT_Face ft_face, const String& _charset, int _si
 	GenerateMetrics();
 
 	// Generate the default layer and layer configuration.
-	base_layer = GenerateLayer(NULL);
+	base_layer = GenerateLayer(nullptr);
 	layer_configurations.push_back(LayerConfiguration());
 	layer_configurations.back().push_back(base_layer);
 
@@ -91,124 +91,6 @@ bool FontFaceHandle::Initialise(FT_Face ft_face, const String& _charset, int _si
 	return true;
 }
 
-// Returns the width a string will take up if rendered with this handle.
-int FontFaceHandle::GetStringWidth(const WString& string, word prior_character) const
-{
-	int width = 0;
-
-	for (size_t i = 0; i < string.size(); i++)
-	{
-		word character_code = string[i];
-
-		if (character_code >= glyphs.size())
-			continue;
-		const FontGlyph &glyph = glyphs[character_code];
-
-		// Adjust the cursor for the kerning between this character and the previous one.
-		if (prior_character != 0)
-			width += GetKerning(prior_character, string[i]);
-		// Adjust the cursor for this character's advance.
-		width += glyph.advance;
-
-		prior_character = character_code;
-	}
-
-	return width;
-}
-
-// Generates the texture data for a layer (for the texture database).
-bool FontFaceHandle::GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id)
-{
-	FontLayerMap::iterator layer_iterator = layers.find(layer_id);
-	if (layer_iterator == layers.end())
-		return false;
-
-	return layer_iterator->second->GenerateTexture(texture_data, texture_dimensions, texture_id);
-}
-
-// Generates the geometry required to render a single line of text.
-int FontFaceHandle::GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration_index) const
-{
-	int geometry_index = 0;
-	int line_width = 0;
-
-	RMLUI_ASSERT(layer_configuration_index >= 0);
-	RMLUI_ASSERT(layer_configuration_index < (int) layer_configurations.size());
-
-	// Fetch the requested configuration and generate the geometry for each one.
-	const LayerConfiguration& layer_configuration = layer_configurations[layer_configuration_index];
-	for (size_t i = 0; i < layer_configuration.size(); ++i)
-	{
-		FontFaceLayer* layer = layer_configuration[i];
-
-		Colourb layer_colour;
-		if (layer == base_layer)
-			layer_colour = colour;
-		else
-			layer_colour = layer->GetColour();
-
-		// Resize the geometry list if required.
-		if ((int) geometry.size() < geometry_index + layer->GetNumTextures())
-			geometry.resize(geometry_index + layer->GetNumTextures());
-
-		// Bind the textures to the geometries.
-		for (int i = 0; i < layer->GetNumTextures(); ++i)
-			geometry[geometry_index + i].SetTexture(layer->GetTexture(i));
-
-		line_width = 0;
-		word prior_character = 0;
-
-		const word* string_iterator = string.c_str();
-		const word* string_end = string.c_str() + string.size();
-
-		geometry[geometry_index].GetIndices().reserve(string.size() * 6);
-		geometry[geometry_index].GetVertices().reserve(string.size() * 4);
-
-		for (; string_iterator != string_end; string_iterator++)
-		{
-			if (*string_iterator >= glyphs.size())
-				continue;
-			const FontGlyph &glyph = glyphs[*string_iterator];
-
-			// Adjust the cursor for the kerning between this character and the previous one.
-			if (prior_character != 0)
-				line_width += GetKerning(prior_character, *string_iterator);
-
-			layer->GenerateGeometry(&geometry[geometry_index], *string_iterator, Vector2f(position.x + line_width, position.y), layer_colour);
-
-			line_width += glyph.advance;
-			prior_character = *string_iterator;
-		}
-
-		geometry_index += layer->GetNumTextures();
-	}
-
-	// Cull any excess geometry from a previous generation.
-	geometry.resize(geometry_index);
-
-	return line_width;
-}
-
-// Generates the geometry required to render a line above, below or through a line of text.
-void FontFaceHandle::GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const
-{
-	std::vector< Vertex >& line_vertices = geometry->GetVertices();
-	std::vector< int >& line_indices = geometry->GetIndices();
-
-	float offset;
-	switch (height)
-	{
-		case Font::UNDERLINE:			offset = -underline_position; break;
-		case Font::OVERLINE:			// where to place? offset = -line_height - underline_position; break;
-		case Font::STRIKE_THROUGH:		// where to place? offset = -line_height * 0.5f; break;
-		default:						return;
-	}
-
-	line_vertices.resize(line_vertices.size() + 4);
-	line_indices.resize(line_indices.size() + 6);
-	GeometryUtilities::GenerateQuad(&line_vertices[0] + (line_vertices.size() - 4), &line_indices[0] + (line_indices.size() - 6), Vector2f(position.x, position.y + offset).Round(), Vector2f((float) width, underline_thickness), colour, (int)line_vertices.size() - 4);
-}
-
 // Destroys the handle.
 void FontFaceHandle::OnReferenceDeactivate()
 {

+ 0 - 30
Source/Core/FreeType/FontFaceHandle.h

@@ -43,8 +43,6 @@
 namespace Rml {
 namespace Core {
 
-class FontFaceLayer;
-
 namespace FreeType {
 
 /**
@@ -64,34 +62,6 @@ public:
 	/// @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);
 
-	/// Returns the width a string will take up if rendered with this handle.
-	/// @param[in] string The string to measure.
-	/// @param[in] prior_character The optionally-specified character that immediately precedes the string. This may have an impact on the string width due to kerning.
-	/// @return The width, in pixels, this string will occupy if rendered with this handle.
-	int GetStringWidth(const WString& string, word prior_character = 0) const override;
-
-	/// Generates the texture data for a layer (for the texture database).
-	/// @param[out] texture_data The pointer to be set to the generated texture data.
-	/// @param[out] texture_dimensions The dimensions of the texture.
-	/// @param[in] layer_id The id of the layer to request the texture data from.
-	/// @param[in] texture_id The index of the texture within the layer to generate.
-	bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, FontEffect* layer_id, int texture_id) override;
-
-	/// Generates the geometry required to render a single line of text.
-	/// @param[out] geometry An array of geometries to generate the geometry into.
-	/// @param[in] string The string to render.
-	/// @param[in] position The position of the baseline of the first character to render.
-	/// @param[in] colour The colour to render the text.
-	/// @return The width, in pixels, of the string geometry.
-	int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const override;
-	/// Generates the geometry required to render a line above, below or through a line of text.
-	/// @param[out] geometry The geometry to append the newly created geometry into.
-	/// @param[in] position The position of the baseline of the lined text.
-	/// @param[in] width The width of the string to line.
-	/// @param[in] height The height to render the line at.
-	/// @param[in] colour The colour to draw the line in.
-	void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const override;
-
 protected:
 	/// Destroys the handle.
 	void OnReferenceDeactivate() override;

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

@@ -32,23 +32,21 @@
 
 namespace Rml {
 namespace Core {
-namespace FreeType
-{
 
-FontFamily::FontFamily(const String& name) : Rml::Core::FontFamily(name)
+FreeType::FontFamily::FontFamily(const String& name) : Rml::Core::FontFamily(name)
 {
 
 }
 
-FontFamily::~FontFamily()
+FreeType::FontFamily::~FontFamily()
 {
 
 }
 
 // Adds a new face to the family.
-bool FontFamily::AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream)
+bool FreeType::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);
+	FontFace* face = new FreeType::FontFace((FT_Face)ft_face, style, weight, release_stream);
 	font_faces.push_back(face);
 
 	return true;
@@ -56,4 +54,3 @@ bool FontFamily::AddFace(void* ft_face, Font::Style style, Font::Weight weight,
 
 }
 }
-}

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

@@ -58,7 +58,7 @@ public:
 	/// @param[in] weight The weight of the new face.
 	/// @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.
-	bool AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream);
+	bool AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream) override;
 };
 
 }