Cogs.Core
Public Member Functions | Public Attributes | List of all members
Cogs::Core::FontManager Class Reference

Font manager responsible for loading, processing and lifetime of Font resources. More...

#include <FontManager.h>

Inheritance diagram for Cogs::Core::FontManager:
Cogs::Core::ResourceManager< Font, FontLoadInfo > Cogs::Core::ResourceManagerBase Cogs::Core::IResourceManager

Public Member Functions

 FontManager (Context *context)
 Constructs a FontManager in the given context.
 
 ~FontManager () override
 Destructs the FontManaer.
 
void initialize () override
 Initialize the FontManager, creating default Font resources.
 
void clear () override
 Clear the FontManager, releasing all default Font resources.
 
COGSCORE_DLL_API FontHandle loadFont (const std::string &name, float size, ResourceId resourceId, ResourceLoadFlags flags=ResourceLoadFlags::None)
 Load a Font resource from the file resource with the given name.
 
FontHandle loadFont (const FontDefinition &definition, const ResourceId id, ResourceLoadFlags flags=ResourceLoadFlags::None)
 Load a Font resource from the given definition.
 
void getBakedCharacter (const Font *font, int characterIndex, float &x, float &y, Font::BakedCharacter &bakedCharacter) const
 Retrieve baked character information for rendering.
 
void handleLoad (FontLoadInfo *loadInfo) override
 Overridden to load Font resources.
 
ActivationResult handleActivation (FontHandle handle, Font *font) override
 Overridden to activate loaded font resources, triggering loading of the font Texture.
 
void handleDeletion (Font *font) override
 Handler for deletion of resources.
 
void handleFailedLoad (const FontLoadInfo *loadInfo) override
 Handle failed Font loads, logging and cleaning up.
 
virtual bool shouldMergeBySource () const override
 Checking unique handle should not be performed using resource path only. Handled in FontManager.
 
- Public Member Functions inherited from Cogs::Core::ResourceManager< Font, FontLoadInfo >
 ResourceManager (Context *context, Collections::ElementOffset capacity=1024)
 Constructs a resource manager with the given context.
 
 ~ResourceManager () override
 Destructs a resource manager, provided for destruction via base pointer.
 
void clear () override
 Clear the resource manager, cleaning up resources held by member handles.
 
void clearSwapping () override
 Clear the swap queue, ensuring indirect resource references are released.
 
ResourceHandle create ()
 Create a new resource.
 
ResourceHandle release (ResourceId resourceId)
 
ResourceHandle loadResource (FontLoadInfo *loadInfo)
 
ResourceProxy createLocked ()
 Creates a new resource, but returns a ResourceProxy for thread safe editing instead of a handle to the actual resource.
 
ResourceProxy lock (const ResourceHandle &handle)
 Takes the handle given and returns a resource proxy to edit the contents of the held resource safely on other threads than the main thread.
 
void unlockProxy (const ResourceHandle &handle, const ResourceHandle &proxy)
 Unlock the given resource proxy.
 
ResourceHandle generateHandle (ResourceBase *resource)
 Generate a handle to the given resource.
 
virtual void handleLoad (FontLoadInfo *)
 Handler for resource loading.
 
virtual void handleFailedLoad (const FontLoadInfo *)
 Handler for failed resource loads using the given loadInfo.
 
virtual ActivationResult handleActivation (ResourceHandle, Font *)
 Handler for activation of resources.
 
virtual void handleDeletion (Font *)
 Handler for deletion of resources.
 
Fontget (const ResourceHandleBase &handle)
 Resolve the given handle to a resource.
 
void processSwapping () override
 Process queued swap operations, exchanging resource contents of the destination resources by those indicated in the operation data.
 
ResourceHandle getHandle (const ResourceId id) const
 Get a resource handle to the resource with the given id.
 
void registerLoader (IResourceLoader< Font, FontLoadInfo > *loader)
 Register a resource loader capable of handling resources of the template type.
 
void destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo) override
 
FontLoadInfocreateLoadInfo ()
 
- Public Member Functions inherited from Cogs::Core::ResourceManagerBase
 ResourceManagerBase (Context *context)
 
void initialize () override
 
void clear () override
 
void reportLeaks (std::string_view typeName)
 
std::string getReport ()
 Return a string with current resource usage.
 
bool checkPreloaded (ResourceLoadInfoBase *loadInfo)
 
ResourceHandleBase releaseInternal (ResourceId resourceId)
 Releases a resourceId -> ResourceHandle mapping.
 
ResourceHandleBase loadResourceInternal (ResourceLoadInfoBase *loadInfo)
 Load a resource using the given loadInfo.
 
void processLoading () final
 Process loading resources.
 
void setProcessed (ResourceLoadInfoBase *loadInfo, bool swapping=false)
 Signal the resource being loaded as done loading and ready for activation etc.
 
void activateResources () final
 
virtual void processDeletion () override
 Process resources pending deallocation.
 
void fillDeletionQueue (std::vector< ResourceBase * > &deletion)
 
void destroyLocked (ResourceBase *resource)
 
void safeDestroy (ResourceBase *resource)
 
ResourceId getNextResourceId () override
 Get the next unique resource id.
 
void resourceChanged (ResourceBase *resource) override
 
void resourceDeleted (ResourceBase *resource) override
 
void setResourceId (ResourceBase *resource, ResourceId id) override
 Assign the given id to a previously created resource.
 
void queueResource (ResourceLoadInfoBase *loadInfo)
 Re-queue the given loadInfo to defer loading to the next time the processLoading() phase is performed.
 
virtual void handleLoadInternal (ResourceLoadInfoBase *loadInfo)=0
 
virtual ActivationResult handleActivationInternal (ResourceHandleBase r, ResourceBase *resource)=0
 
virtual void handleDeletionInternal (ResourceBase *resource)=0
 
virtual void handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo)=0
 
virtual void destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo)=0
 
virtual bool shouldAutoReload () const
 
virtual bool shouldMergeBySource () const
 
virtual void handleReload (ResourceHandleBase)
 
std::vector< ResourceBase * > getAllocatedResources () const
 
ResourceHandleBase getOrCreate (ResourceId id)
 
ResourceHandleBase getByName (std::string_view name) const
 
ResourceHandleBase getBySource (std::string_view source) const
 
ResourceHandleBase createResource ()
 
virtual ResourceBasecreateInternal ()=0
 
virtual void destroyInternal (ResourceBase *resource)=0
 
virtual void destroyInternalLocked (ResourceBase *resource)=0
 
ResourceHandleBase generateHandle (ResourceBase *resource)
 
void clearUpdated ()
 
virtual int getUpdateQuota () const
 
size_t updatedResourceCount ()
 
size_t orphanedResourceCount ()
 
size_t allocatedResourceCount ()
 
virtual void initialize ()=0
 
virtual void clear ()=0
 
virtual void clearSwapping ()=0
 
virtual void processLoading ()=0
 
virtual void processSwapping ()=0
 
virtual void activateResources ()=0
 
virtual void processDeletion ()=0
 
virtual void resourceChanged (ResourceBase *resource)=0
 
virtual void resourceDeleted (ResourceBase *resource)=0
 
virtual ResourceId getNextResourceId ()=0
 
virtual void setResourceId (ResourceBase *resource, ResourceId id)=0
 

Public Attributes

ResourceId DefaultMonospaceFont = NoResourceId
 Id of the default monospace font.
 
ResourceId DefaultRegularFont = NoResourceId
 Id of the default font.
 
ResourceId DefaultBoldFont = NoResourceId
 Id of the default bold font.
 
FontHandle regularFont = FontHandle::NoHandle
 Handle to the regular font.
 
FontHandle boldFont = FontHandle::NoHandle
 Handle to the bold font.
 
std::unordered_map< FontDefinition, FontHandlesharedFonts
 

Additional Inherited Members

- Public Types inherited from Cogs::Core::ResourceManager< Font, FontLoadInfo >
using ResourceHandle = ResourceHandle_t< Font >
 Type of handle used to hold resources.
 
using ResourceProxy = ResourceProxy< Font, ResourceManager >
 Type of resource proxy objects, specialized on the type of resource.
 
- Protected Member Functions inherited from Cogs::Core::ResourceManager< Font, FontLoadInfo >
FontcreateInternal () override
 
void destroyInternal (ResourceBase *resource) override
 
void handleLoadInternal (ResourceLoadInfoBase *loadInfo) override
 
ActivationResult handleActivationInternal (ResourceHandleBase r, ResourceBase *resource) override
 
void handleDeletionInternal (ResourceBase *resource) override
 
void handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo) override
 
IResourceLoader< Font, FontLoadInfo > * findLoader (const FontLoadInfo *loadInfo)
 Find a loader capable of loading the resource given by loadInfo.
 
- Protected Member Functions inherited from Cogs::Core::ResourceManagerBase
ResourceHandleBase getResourceHandle (ResourceId id) const
 Get existing resource handle.
 
bool isValidResource (ResourceId id) const
 Check if resource handle points to.
 
virtual void postProcessLoading ()
 Hook for resource managers to run code at the tail of processLoading.
 
- Protected Attributes inherited from Cogs::Core::ResourceManager< Font, FontLoadInfo >
Mutex swapMutex
 
Collections::Pool< Fontresources
 
std::vector< IResourceLoader< Font, FontLoadInfo > * > loaders
 
std::deque< SwapOperation > swapQueue
 
ResourceHandle defaultResource
 
- Protected Attributes inherited from Cogs::Core::ResourceManagerBase
std::unique_ptr< ResourceManagerBaseStoragestorage
 
Contextcontext = nullptr
 
ResourceTypes resourceType = ResourceTypes::Unknown
 

Detailed Description

Font manager responsible for loading, processing and lifetime of Font resources.

Definition at line 39 of file FontManager.h.

Constructor & Destructor Documentation

◆ FontManager()

Cogs::Core::FontManager::FontManager ( Context context)
inlineexplicit

Constructs a FontManager in the given context.

Definition at line 43 of file FontManager.h.

◆ ~FontManager()

Cogs::Core::FontManager::~FontManager ( )
override

Destructs the FontManaer.

Definition at line 20 of file FontManager.cpp.

Member Function Documentation

◆ clear()

void Cogs::Core::FontManager::clear ( )
overridevirtual

◆ getBakedCharacter()

void Cogs::Core::FontManager::getBakedCharacter ( const Font font,
int  characterIndex,
float &  x,
float &  y,
Font::BakedCharacter bakedCharacter 
) const

Retrieve baked character information for rendering.

Definition at line 165 of file FontManager.cpp.

◆ handleActivation()

Cogs::Core::ActivationResult Cogs::Core::FontManager::handleActivation ( FontHandle  handle,
Font font 
)
overridevirtual

Overridden to activate loaded font resources, triggering loading of the font Texture.

Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.

Definition at line 181 of file FontManager.cpp.

References Cogs::Core::Dependency, Cogs::Core::Failure, Cogs::Core::HandleIsValid(), Cogs::Core::None, and Cogs::Core::Success.

◆ handleDeletion()

void Cogs::Core::FontManager::handleDeletion ( Font )
overridevirtual

Handler for deletion of resources.

Should be overridden by derived resource managers to handle resource deletion, for example Textures needing to be removed from the renderer when the texture is no longer used by any materials or fonts.

This handler is invoked for all orphaned resources during the processDeletion() processing phase.

processDeletion() will invoke the destroy() function, which in turn invokes the deletion handler.

Parameters
resourcePointer to the resource being deleted.

Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.

Definition at line 210 of file FontManager.cpp.

References Cogs::Core::Resident.

◆ handleFailedLoad()

void Cogs::Core::FontManager::handleFailedLoad ( const FontLoadInfo loadInfo)
overridevirtual

Handle failed Font loads, logging and cleaning up.

Reimplemented from Cogs::Core::ResourceManager< Font, FontLoadInfo >.

Definition at line 176 of file FontManager.cpp.

References Cogs::Core::ResourceLoadInfoBase::resourcePath.

◆ handleLoad()

void Cogs::Core::FontManager::handleLoad ( FontLoadInfo loadInfo)
overridevirtual

◆ initialize()

void Cogs::Core::FontManager::initialize ( )
overridevirtual

Initialize the FontManager, creating default Font resources.

Implements Cogs::Core::IResourceManager.

Definition at line 25 of file FontManager.cpp.

◆ loadFont() [1/2]

Cogs::Core::FontHandle Cogs::Core::FontManager::loadFont ( const FontDefinition definition,
const ResourceId  id,
ResourceLoadFlags  flags = ResourceLoadFlags::None 
)

Load a Font resource from the given definition.

Parameters
definitionDefinition of the Font to load.
resourceIdResource identifier to assign to the Font. If a Font resource with the same identifier already exists, the contents will be loaded into the existing resource.
flagsOptional loading flags
Returns
Handle to the destination Font resource.

Definition at line 61 of file FontManager.cpp.

References Cogs::Core::FontLoadInfo::definition, Cogs::Core::Dependency, Cogs::Core::FontDefinition::fontFamily, Cogs::Core::FontDefinition::fontSize, Cogs::Core::ResourceLoadInfoBase::loadFlags, Cogs::Core::ResourceLoadInfoBase::resourceId, Cogs::Core::ResourceLoadInfoBase::resourceName, and Cogs::Core::ResourceLoadInfoBase::resourcePath.

◆ loadFont() [2/2]

Cogs::Core::FontHandle Cogs::Core::FontManager::loadFont ( const std::string &  name,
float  size,
ResourceId  resourceId,
ResourceLoadFlags  flags = ResourceLoadFlags::None 
)

Load a Font resource from the file resource with the given name.

Parameters
nameName of a Font file resource to load from.
sizeSize of the Font resource in points.
resourceIdResource identifier to assign to the Font. If a Font resource with the same identifier already exists, the contents will be loaded into the existing resource.
flagsOptional loading flags
Returns
Handle to the destination Font resource.

Definition at line 56 of file FontManager.cpp.

References Cogs::Core::FontDefinition::fontFamily.

◆ shouldMergeBySource()

virtual bool Cogs::Core::FontManager::shouldMergeBySource ( ) const
inlineoverridevirtual

Checking unique handle should not be performed using resource path only. Handled in FontManager.

Reimplemented from Cogs::Core::ResourceManagerBase.

Definition at line 94 of file FontManager.h.

Member Data Documentation

◆ boldFont

FontHandle Cogs::Core::FontManager::boldFont = FontHandle::NoHandle

Handle to the bold font.

Definition at line 110 of file FontManager.h.

◆ DefaultBoldFont

ResourceId Cogs::Core::FontManager::DefaultBoldFont = NoResourceId

Id of the default bold font.

Definition at line 104 of file FontManager.h.

◆ DefaultMonospaceFont

ResourceId Cogs::Core::FontManager::DefaultMonospaceFont = NoResourceId

Id of the default monospace font.

Definition at line 98 of file FontManager.h.

◆ DefaultRegularFont

ResourceId Cogs::Core::FontManager::DefaultRegularFont = NoResourceId

Id of the default font.

Definition at line 101 of file FontManager.h.

Referenced by Cogs::Core::Text3DSystem::update().

◆ regularFont

FontHandle Cogs::Core::FontManager::regularFont = FontHandle::NoHandle

Handle to the regular font.

Definition at line 107 of file FontManager.h.

◆ sharedFonts

std::unordered_map<FontDefinition, FontHandle> Cogs::Core::FontManager::sharedFonts

Map of shared font resources, since Fonts with the same definition can share the same underlying resource.

Definition at line 114 of file FontManager.h.


The documentation for this class was generated from the following files: