Browse Source

Add initialize and shutdown procedures to font engine interface, resolves #583

Michael Ragazzon 1 year ago
parent
commit
64b36dc477

+ 6 - 0
Include/RmlUi/Core/FontEngineInterface.h

@@ -49,6 +49,12 @@ public:
 	FontEngineInterface();
 	virtual ~FontEngineInterface();
 
+	/// Called when RmlUi is being initialized.
+	virtual void Initialize();
+
+	/// Called when RmlUi is being shut down.
+	virtual void Shutdown();
+
 	/// Called by RmlUi when it wants to load a font face from file.
 	/// @param[in] file_name The file to load the face from.
 	/// @param[in] fallback_face True to use this font face for unknown characters in other font faces.

+ 2 - 2
Samples/basic/bitmapfont/src/FontEngineInterfaceBitmap.cpp

@@ -30,12 +30,12 @@
 #include "FontEngineBitmap.h"
 #include <RmlUi/Core.h>
 
-FontEngineInterfaceBitmap::FontEngineInterfaceBitmap()
+void FontEngineInterfaceBitmap::Initialize()
 {
 	FontProviderBitmap::Initialise();
 }
 
-FontEngineInterfaceBitmap::~FontEngineInterfaceBitmap()
+void FontEngineInterfaceBitmap::Shutdown()
 {
 	FontProviderBitmap::Shutdown();
 }

+ 5 - 2
Samples/basic/bitmapfont/src/FontEngineInterfaceBitmap.h

@@ -53,8 +53,11 @@ using Rml::TextShapingContext;
 
 class FontEngineInterfaceBitmap : public Rml::FontEngineInterface {
 public:
-	FontEngineInterfaceBitmap();
-	virtual ~FontEngineInterfaceBitmap();
+	/// Called when RmlUi is being initialized.
+	void Initialize() override;
+
+	/// Called when RmlUi is being shut down.
+	void Shutdown() override;
 
 	/// Called by RmlUi when it wants to load a font face from file.
 	bool LoadFontFace(const String& file_name, bool fallback_face, FontWeight weight) override;

+ 0 - 3
Samples/basic/bitmapfont/src/main.cpp

@@ -118,9 +118,6 @@ int main(int /*argc*/, char** /*argv*/)
 	// Shutdown RmlUi.
 	Rml::Shutdown();
 
-	// Destroy the font interface before taking down the shell, this way font textures are properly released through the render interface.
-	font_interface.reset();
-
 	Backend::Shutdown();
 	Shell::Shutdown();
 

+ 9 - 6
Source/Core/Core.cpp

@@ -116,10 +116,6 @@ bool Initialise()
 #endif
 	}
 
-	EventSpecificationInterface::Initialize();
-
-	TextureDatabase::Initialise();
-
 	if (!font_interface)
 	{
 #ifndef RMLUI_NO_FONT_INTERFACE_DEFAULT
@@ -131,6 +127,12 @@ bool Initialise()
 #endif
 	}
 
+	EventSpecificationInterface::Initialize();
+
+	TextureDatabase::Initialise();
+
+	font_interface->Initialize();
+
 	StyleSheetSpecification::Initialise();
 	StyleSheetParser::Initialise();
 	StyleSheetFactory::Initialise();
@@ -171,17 +173,18 @@ void Shutdown()
 	StyleSheetParser::Shutdown();
 	StyleSheetSpecification::Shutdown();
 
-	font_interface = nullptr;
-	default_font_interface.reset();
+	font_interface->Shutdown();
 
 	TextureDatabase::Shutdown();
 
 	initialised = false;
 
+	font_interface = nullptr;
 	render_interface = nullptr;
 	file_interface = nullptr;
 	system_interface = nullptr;
 
+	default_font_interface.reset();
 	default_file_interface.reset();
 
 	Log::Shutdown();

+ 3 - 4
Source/Core/FontEngineDefault/FontEngineInterfaceDefault.cpp

@@ -32,12 +32,12 @@
 
 namespace Rml {
 
-FontEngineInterfaceDefault::FontEngineInterfaceDefault()
+void FontEngineInterfaceDefault::Initialize()
 {
 	FontProvider::Initialise();
 }
 
-FontEngineInterfaceDefault::~FontEngineInterfaceDefault()
+void FontEngineInterfaceDefault::Shutdown()
 {
 	FontProvider::Shutdown();
 }
@@ -82,8 +82,7 @@ int FontEngineInterfaceDefault::GenerateString(FontFaceHandle handle, FontEffect
 	const Vector2f& position, const Colourb& colour, float opacity, const TextShapingContext& text_shaping_context, GeometryList& geometry)
 {
 	auto handle_default = reinterpret_cast<FontFaceHandleDefault*>(handle);
-	return handle_default->GenerateString(geometry, string, position, colour, opacity, text_shaping_context.letter_spacing,
-		(int)font_effects_handle);
+	return handle_default->GenerateString(geometry, string, position, colour, opacity, text_shaping_context.letter_spacing, (int)font_effects_handle);
 }
 
 int FontEngineInterfaceDefault::GetVersion(FontFaceHandle handle)

+ 5 - 2
Source/Core/FontEngineDefault/FontEngineInterfaceDefault.h

@@ -34,8 +34,11 @@ namespace Rml {
 
 class RMLUICORE_API FontEngineInterfaceDefault : public FontEngineInterface {
 public:
-	FontEngineInterfaceDefault();
-	virtual ~FontEngineInterfaceDefault();
+	/// Called when RmlUi is being initialized.
+	void Initialize() override;
+
+	/// Called when RmlUi is being shut down.
+	void Shutdown() override;
 
 	/// Adds a new font face to the database. The face's family, style and weight will be determined from the face itself.
 	bool LoadFontFace(const String& file_name, bool fallback_face, Style::FontWeight weight) override;

+ 4 - 0
Source/Core/FontEngineInterface.cpp

@@ -34,6 +34,10 @@ FontEngineInterface::FontEngineInterface() {}
 
 FontEngineInterface::~FontEngineInterface() {}
 
+void FontEngineInterface::Initialize() {}
+
+void FontEngineInterface::Shutdown() {}
+
 bool FontEngineInterface::LoadFontFace(const String& /*file_path*/, bool /*fallback_face*/, Style::FontWeight /*weight*/)
 {
 	return false;