Program Listing for File fonts.h

Return to documentation for file (blam\components\content\fonts\fonts.h)

#pragma once

#include <d2d1.h>
#include <map>
#include <Windows.h>

#ifndef BLAM
#define BLAM
#endif

#define FONTINFO_FILENAME "fontinfo.xml"
#define FONT_PACKAGE_EXTENSION ".bin"
#define FONT_PACKAGE_VERSION 1

enum FontGlyphFormat
{
    PNG
};

namespace Blam
{
    namespace Content
    {
        namespace Fonts
        {
            /*struct DWFontFile
            {
                UINT64 font_size;
                void* font_data;
                const char* key;
            };*/

            struct FontGlyph
            {
                //package info
                int data_offset;
                int data_length;

                //character info
                char character;

                //bitmap info
                short width;
                short height;
                FontGlyphFormat format;
                std::string path;
                std::string file_path;

                IWICBitmap* bitmap;
                void* bitmap_data;
            };

            struct Font
            {
                short package_version;
                std::string package_engine_version;
                bool is_font_package;
                int ttf_offset;
                int ttf_length;

                std::string id;
                short size;
                short charspacing;
                bool monospaced;
                short mono_width;
                short space_width;

                bool is_truetype;
                std::string ttf_path;
                std::string ttf_name;

                std::string path;
                std::string file_path;

                std::map<char, FontGlyph> glyph_list;
            };

            // Loads all fonts available in the engine's configured font directory
            BLAM void       LoadAllFonts();

            // Load a font from disk. Do NOT include full path to fontinfo.xml or the .bin extension - this is determined automatically.
            BLAM HRESULT    LoadFont(std::string path);

            // Reloads the specified font data from disk.
            BLAM HRESULT    ReloadFont(std::string id);

            // Retrieve the specified font based on its ID.
            BLAM Font*      GetFont(std::string id);

            // Retrieve the specified glyph based on its character
            BLAM FontGlyph* GetFontGlyph(Font* font, char glyph);

            // Gets whether or not a font exists with the specified ID
            BLAM bool       FontExists(std::string id);

            // Gets the list of all loaded fonts
            BLAM std::map<std::string, Font>* GetFontList();

            // Cleans up all font data
            BLAM void       Cleanup();
        }
    }
}