Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added RemoveFontProvider in FontDatabase.

Cleaned some files.
  • Loading branch information...
commit 4d3ddfe6a2f547b999fd98d4b5a6735c5c5e1295 1 parent 7e60bec
@gogoprog gogoprog authored
View
16 Include/Rocket/Core/FontDatabase.h
@@ -72,18 +72,22 @@ class ROCKETCORE_API FontDatabase
/// Removes a font effect from the font database's cache.
/// @param[in] The effect to release.
static void ReleaseFontEffect(const FontEffect* effect);
-
- /// Add a font provider to the database
- /// @param[in] The provider to add.
- static void AddFontProvider( FontProvider * provider );
+
+ /// Add a font provider to the database
+ /// @param[in] The provider to add.
+ static void AddFontProvider(FontProvider * provider);
+
+ /// Remove a font provider from the database
+ /// @param[in] The provider to remove.
+ static void RemoveFontProvider(FontProvider * provider);
private:
FontDatabase(void);
~FontDatabase(void);
- typedef std::vector< FontProvider *> FontProviderTable;
+ typedef std::vector< FontProvider *> FontProviderTable;
- static FontProviderTable font_provider_table;
+ static FontProviderTable font_provider_table;
static FontDatabase* instance;
};
View
101 Source/Core/BitmapFont/FontProvider.cpp
@@ -59,8 +59,8 @@ bool FontProvider::Initialise()
if (instance == NULL)
{
new FontProvider();
-
- FontDatabase::AddFontProvider( instance );
+
+ FontDatabase::AddFontProvider(instance);
}
return true;
@@ -73,6 +73,7 @@ void FontProvider::Shutdown()
for (FontFamilyMap::iterator i = instance->font_families.begin(); i != instance->font_families.end(); ++i)
delete (*i).second;
+ FontDatabase::RemoveFontProvider(instance);
delete instance;
}
}
@@ -80,34 +81,34 @@ 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)
{
- BM_Font *bm_font = (BM_Font*) instance->LoadFace(file_name);
-
- if (bm_font == NULL)
- {
- Log::Message(Log::LT_ERROR, "Failed to load font face from %s.", file_name.CString());
- return false;
- }
-
- Font::Style style = bm_font->Face.Style;
- Font::Weight weight = bm_font->Face.Weight;
-
- if (instance->AddFace(bm_font, bm_font->Face.FamilyName, style, weight, true))
- {
- Log::Message(Log::LT_INFO, "Loaded font face %s (from %s).", bm_font->Face.FamilyName.CString(), file_name.CString());
- return true;
- }
- else
- {
- Log::Message(Log::LT_ERROR, "Failed to load font face %s (from %s).", bm_font->Face.FamilyName.CString(), file_name.CString());
- return false;
- }
+ BM_Font *bm_font = (BM_Font*) instance->LoadFace(file_name);
+
+ if (bm_font == NULL)
+ {
+ Log::Message(Log::LT_ERROR, "Failed to load font face from %s.", file_name.CString());
+ return false;
+ }
+
+ Font::Style style = bm_font->Face.Style;
+ Font::Weight weight = bm_font->Face.Weight;
+
+ if (instance->AddFace(bm_font, bm_font->Face.FamilyName, style, weight, true))
+ {
+ Log::Message(Log::LT_INFO, "Loaded font face %s (from %s).", bm_font->Face.FamilyName.CString(), file_name.CString());
+ return true;
+ }
+ else
+ {
+ Log::Message(Log::LT_ERROR, "Failed to load font face %s (from %s).", bm_font->Face.FamilyName.CString(), file_name.CString());
+ return false;
+ }
}
// Loads a new font face.
bool FontProvider::LoadFontFace(const String& file_name, const String& family, Font::Style style, Font::Weight weight)
{
- BM_Font *bm_font = (BM_Font*) instance->LoadFace(file_name);
- if (bm_font == NULL)
+ BM_Font *bm_font = (BM_Font*) instance->LoadFace(file_name);
+ if (bm_font == NULL)
{
Log::Message(Log::LT_ERROR, "Failed to load font face from %s.", file_name.CString());
return false;
@@ -177,8 +178,8 @@ bool FontProvider::AddFace(void* face, const String& family, Font::Style style,
// Loads a FreeType face.
void* FontProvider::LoadFace(const String& file_name)
{
- BM_Font *bm_face = new BM_Font();
- FontParser parser( bm_face );
+ BM_Font *bm_face = new BM_Font();
+ FontParser parser( bm_face );
FileInterface* file_interface = GetFileInterface();
FileHandle handle = file_interface->Open(file_name);
@@ -188,43 +189,43 @@ void* FontProvider::LoadFace(const String& file_name)
return NULL;
}
- size_t length = file_interface->Length(handle);
+ size_t length = file_interface->Length(handle);
- byte* buffer = new byte[length];
- file_interface->Read(buffer, length, handle);
- file_interface->Close(handle);
+ byte* buffer = new byte[length];
+ file_interface->Read(buffer, length, handle);
+ file_interface->Close(handle);
- StreamMemory* stream = new StreamMemory( buffer, length );
- stream->SetSourceURL( file_name );
+ StreamMemory* stream = new StreamMemory( buffer, length );
+ stream->SetSourceURL( file_name );
- parser.Parse( stream );
+ parser.Parse( stream );
- URL
- file_url = file_name;
+ URL
+ file_url = file_name;
- bm_face->Face.Source = file_url.GetFileName();
- bm_face->Face.Directory = file_url.GetPath();
+ bm_face->Face.Source = file_url.GetFileName();
+ bm_face->Face.Directory = file_url.GetPath();
- return bm_face;
+ return bm_face;
}
// Loads a FreeType face from memory.
void* FontProvider::LoadFace(const byte* data, int data_length, const String& source, bool local_data)
{
- URL
- file_url = source + ".fnt";
+ URL
+ file_url = source + ".fnt";
- BM_Font *bm_face = new BM_Font();
- FontParser parser( bm_face );
- StreamMemory* stream = new StreamMemory( data, data_length );
- stream->SetSourceURL( file_url );
+ BM_Font *bm_face = new BM_Font();
+ FontParser parser( bm_face );
+ StreamMemory* stream = new StreamMemory( data, data_length );
+ stream->SetSourceURL( file_url );
- parser.Parse( stream );
+ parser.Parse( stream );
- bm_face->Face.Source = file_url.GetFileName();
- bm_face->Face.Directory = file_url.GetPath();
-
- return bm_face;
+ bm_face->Face.Source = file_url.GetFileName();
+ bm_face->Face.Directory = file_url.GetPath();
+
+ return bm_face;
}
}
View
54 Source/Core/FontDatabase.cpp
@@ -73,23 +73,23 @@ void FontDatabase::Shutdown()
// Returns a handle to a font face that can be used to position and render text.
FontFaceHandle* FontDatabase::GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size)
{
- size_t provider_index, provider_count;
-
- provider_count = font_provider_table.size();
-
- for( provider_index = 0; provider_index < provider_count; ++provider_index )
- {
- FontFaceHandle * face_handle;
-
- face_handle = font_provider_table[ provider_index ]->GetFontFaceHandle( family, charset, style, weight, size );
-
- if( face_handle )
- {
- return face_handle;
- }
- }
-
- return NULL;
+ size_t provider_index, provider_count;
+
+ provider_count = font_provider_table.size();
+
+ for(provider_index = 0; provider_index < provider_count; ++provider_index)
+ {
+ FontFaceHandle * face_handle;
+
+ face_handle = font_provider_table[ provider_index ]->GetFontFaceHandle(family, charset, style, weight, size);
+
+ if(face_handle)
+ {
+ return face_handle;
+ }
+ }
+
+ return NULL;
}
// Returns a font effect, either a newly-instanced effect from the factory or an identical shared
@@ -112,8 +112,8 @@ FontEffect* FontDatabase::GetFontEffect(const String& name, const PropertyDictio
PropertyList::iterator insert = sorted_properties.begin();
while (insert != sorted_properties.end() &&
- insert->first < property_iterator->first)
- ++insert;
+ insert->first < property_iterator->first)
+ ++insert;
sorted_properties.insert(insert, PropertyList::value_type(property_iterator->first, property_iterator->second.Get< String >()));
}
@@ -154,9 +154,21 @@ void FontDatabase::ReleaseFontEffect(const FontEffect* effect)
}
}
-void FontDatabase::AddFontProvider( FontProvider * provider )
+void FontDatabase::AddFontProvider(FontProvider * provider)
+{
+ instance->font_provider_table.push_back(provider);
+}
+
+void FontDatabase::RemoveFontProvider(FontProvider * provider)
{
- instance->font_provider_table.push_back( provider );
+ for(FontProviderTable::iterator i = instance->font_provider_table.begin(); i != instance->font_provider_table.end(); ++i)
+ {
+ if(*i == provider)
+ {
+ instance->font_provider_table.erase(i);
+ return;
+ }
+ }
}
}
View
6 Source/Core/FontFaceHandle.cpp
@@ -61,10 +61,12 @@ FontFaceHandle::FontFaceHandle()
FontFaceHandle::~FontFaceHandle()
{
for (FontGlyphMap::iterator i = glyphs.begin(); i != glyphs.end(); ++i)
- delete[] i->second.bitmap_data;
+ if (i->second.bitmap_data)
+ delete[] i->second.bitmap_data;
for (FontLayerMap::iterator i = layers.begin(); i != layers.end(); ++i)
- delete i->second;
+ if (i->second)
+ delete i->second;
}
// Returns the point size of this font face.
View
1  Source/Core/FreeType/FontProvider.cpp
@@ -87,6 +87,7 @@ void FontProvider::Shutdown()
ft_library = NULL;
}
+ FontDatabase::RemoveFontProvider(instance);
delete instance;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.