Fonts in Libstk are drawn using the Freetype2 Rendering engine, in this engine rendering glyphs is quite expensive, to counter this we are employing a cached glyph system in which we cache the rendered glyphs for one single font and font property set in system memory.
For caching there are multiple layers involved. The lowest layer is the font
class, this class
is responsible for Driving the rendering engine, and caching single glyph images. Each instance of the font class is constructed
with a set of properties describing all aspects of font rendering, font size, the font name and attributes. (outline only, italic or bold)
The next higher layer is the font manager, this is a singleton object which manages all instances of the font class, this is done to avoid creating font objects with the same properties multiple times, which would duplicate the caching effort in multiple places and waste memory. The user interacts with the singleton by calling a single function called get_font which takes a font property set as its sole argument and returns a shared_ptr to the right font class instances with the corresponding property set, it is very important that the user stores this shared_ptr as long as he is using this set of font properties to draw text, when the returned shared_ptr is destroyed (goes out of scope) the associated font objects will be destroyed except when there are multiple users of the same object.