#pragma once #include "globalincs/pstypes.h" #include namespace font { /** * @struct TrueTypeFontData * * @brief True type font data to save data for already read fonts. * * Used to store the data of a true type font which can be used by multiple FTFont objects which are all using the same data. * * @author m!m * @date 24.11.2011 */ struct TrueTypeFontData { size_t size; // data; //= 0 && index < (int) fonts.size(), "Invalid font index %d given!", index); return fonts[index].get(); } /** * @brief Returns the index of the currently used font * * Returns the index the currently active font pointer has. * * @return The current font index. 0 by default, -1 when FontManager isn't initialized yet */ static int getCurrentFontIndex(); /** * @brief Returns a pointer to the current font * * Returns a pointer of the currently active font. * * @return Pointer of currently active font or @c NULL when no font is currently active */ static FSFont *getCurrentFont(); /** * @brief Returns the index of the font with the specified @c name. * * @param name The name which should be searched * @return The index or -1 when font could not be found */ static int getFontIndex(const SCP_string &name); /** * @brief Returns the index of the specified font pointer * * Searches through the internal font vector and returns the index for which @verbatim (*fontIterator) == font @endverbatim * is true. * * @param font The font which should be searched * @return The index of the font or -1 when font could not be found */ static int getFontIndex(FSFont *font); /** * @brief Returns the number of fonts currently saved in the manager * @return The number of fonts */ static int numberOfFonts(); /** * @brief Specifies if the font system is ready to be used for rendering text * @return @c true if ready (there is a current font), @c false if not */ static bool isReady(); /** * @brief Checks if the specified number is a valid font ID * @return @c true if the number can be used with #getFont(int), @c false otherwise */ static bool isFontNumberValid(int fontNumber); /** * @brief Sets the currently active font * @param font The font which should be used, may not be @c NULL * * @warning The integrity of the specified pointer is not checked */ static void setCurrentFont(FSFont *font); /** * @brief Loads a TrueType font * * Loads a TrueType font with the specified @c fileName and initializes it with the specified * @c size and @c type. The size can be changed later where the type is not changeable. * * @param fileName The name of the font file which should be loaded * @param fontSize The initial size of the font * @param type The type of the font * @return A FTGLFont pointer or @c NULL when font could not be loaded */ static NVGFont *loadNVGFont(const SCP_string &fileName, float fontSize = 12.0f); /** * @brief Loads an old VFNT font * * Loads the VFNT font with the specified @c fileName and returns it in form of a VFNTFont pointer * * @param fileName The name of the font file * @return The font pointer or @c null on error */ static VFNTFont *loadVFNTFont(const SCP_string &fileName); /** * @brief Loads old volition font data */ static font *loadFontOld(const SCP_string& name); /** * @brief Initializes the font system */ static void init(); /** * @brief Disposes the fonts saved in the class * * Cleans up the memory used by the font system and sets the current font to @c NULL */ static void close(); private: FontManager() { }; FontManager(const FontManager &) { }; ~FontManager() { } static SCP_map allocatedData; static SCP_map> vfntFontData; static SCP_vector> fonts; static FSFont *currentFont; }; }