Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.blamite
The core library for the Blamite Game Engine.
fonts.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <d2d1.h>
4 #include <map>
5 #include <Windows.h>
6 #include <string>
7 #include <OGRE/OgreTextureGpu.h>
8 #include <OGRE/Overlay/OgreFont.h>
9 #include <Strings/components/classes/map/map.h>
10 #include <Strings/components/classes/vector/vector.h>
11 #include <Strings/components/diagnostics/errors/errors.h>
12 #include <Strings/components/resources/color/BlamColor.h>
13 
14 #ifndef BLAM
15 #define BLAM
16 #endif
17 
18 #define FONT_TABLE_FILE "font_table.txt"
19 
20 #define FONTINFO_FILENAME "fontinfo.xml"
21 #define FONT_PACKAGE_EXTENSION ".bin"
22 #define FONT_PACKAGE_VERSION 2
23 
25 {
26  Unknown,
27  Bitmap,
29  TrueType,
30  XMLBitmap,
33 };
34 
36 {
37 public:
38  char character = 0x00;
39 
40  bool override_filtering = false;
41  bool use_point_filtering = false;
42 
45 
48 
49  BlamVector4 uv = { 0, 0, 0, 0 };
50 
51  Ogre::TextureGpu* glyph_texture = nullptr;
52  Ogre::HlmsDatablock* glyph_datablock = nullptr;
53 
54  Ogre::HlmsDatablock* CreateCopiedDatablock();
55 };
56 
58 {
59 public:
60  std::string name = "";
61  std::string file_path = "";
63  BlamMap<char, BlamFontGlyph*> glyphs = BlamMap<char, BlamFontGlyph*>();
64 
65  bool monospace = false;
66  int monospace_width = 0;
67  int charspacing = 0;
68  int line_height = 0;
69  int space_width = 0;
70  bool use_point_filtering = false;
71 
74 
75  Ogre::TextureGpu* font_atlas = nullptr;
76  Ogre::HlmsDatablock* font_datablock = nullptr;
77  Ogre::FontPtr ttf_font;
78 
81 
82  BlamFontGlyph* GetGlyph(char character);
83  Ogre::HlmsDatablock* CreateCopiedDatablock();
84 };
85 
95 {
96  PNG
97 };
98 
100 {
101  /*struct DWFontFile
102  {
103  UINT64 font_size;
104  void* font_data;
105  const char* key;
106  };*/
107 
111  struct FontGlyph
112  {
113  //package info
116 
117  //character info
118  char character;
119 
120  //bitmap info
121  short width;
122  short height;
124  std::string path;
125  std::string file_path;
126 
127  IWICBitmap* bitmap;
128  void* bitmap_data;
129  };
130 
134  struct Font
135  {
141 
142  std::string id;
143  short size;
144  short charspacing;
145  bool monospaced;
146  short mono_width;
147  short space_width;
148  short line_height;
149 
150  bool is_truetype;
151  std::string ttf_path;
152  std::string ttf_name;
153 
154  std::string path;
155  std::string file_path;
156 
163  std::map<char, FontGlyph> glyph_list;
164  };
165 
171  BLAM void LoadAllFonts();
172 
182  BLAM HRESULT LoadFont(std::string path);
183 
192  BLAM HRESULT ReloadFont(std::string id);
193 
201  BLAM Font* GetFont(std::string id);
202 
212 
220  BLAM bool FontExists(std::string id);
221 
225  BLAM std::map<std::string, Font>* GetFontList();
226 
230  BLAM void Cleanup();
231 
232  namespace New
233  {
234  BLAM void LoadAllFonts();
235  BLAM BlamResult LoadFontDirectory(std::string directory);
236  BLAM BlamResult LoadFontPackage(std::string file);
237  BLAM BlamResult LoadFont(std::string font_name);
238  BLAM BlamMap<std::string, BlamFontPackage*> GetFontList();
239  BLAM bool FontExists(std::string id);
240  BLAM BlamFontPackage* GetFont(std::string id);
241  BLAM void Cleanup();
242  }
243 }
244 
Blam::Content::Fonts::ReloadFont
BLAM HRESULT ReloadFont(std::string id)
Reloads all data for the specified font.
Definition: fonts.cpp:867
Blam::Content::Fonts::FontGlyph::format
FontGlyphFormat format
The format of the glyph image data. See FontGlyphFormat for more details.
Definition: fonts.h:123
CleanupFontData
void CleanupFontData(std::string id)
Cleans up all data for the specified font.
Definition: fonts.cpp:846
BlamFontPackage::BlamFontPackage
BlamFontPackage()
Definition: BlamFontPackage.cpp:7
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:142
FontLoader.h
Blam::Content::Fonts::New::GetFontList
BLAM BlamMap< std::string, BlamFontPackage * > GetFontList()
Definition: fonts_new.cpp:652
font
io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels,...) font
Definition: README.txt:86
width
int width
Definition: bgfx.cpp:19
Blam::Content::Fonts::FontExists
BLAM bool FontExists(std::string id)
Checks whether or not a font is loaded.
Definition: fonts.cpp:26
Blam::Content::Fonts::Font::ttf_path
std::string ttf_path
The path to the TrueType font file.
Definition: fonts.h:151
BlamFontPackageType::TrueType
@ TrueType
Blam::Content::Fonts::Font::ttf_offset
int ttf_offset
The offset of the embedded TrueType font data within the font package.
Definition: fonts.h:139
BlamFontPackage::use_point_filtering
bool use_point_filtering
Definition: fonts.h:70
logger.h
BlamFontGlyph::glyph_texture
Ogre::TextureGpu * glyph_texture
Definition: fonts.h:51
glyph
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying glyph
Definition: ARPHICPL.TXT:16
BlamFontPackage::name
std::string name
Definition: fonts.h:60
BlamFontPackage
Definition: fonts.h:57
Blam::Content::Fonts::New::LoadAllFonts
BLAM void LoadAllFonts()
Definition: fonts_new.cpp:64
BlamFontGlyph::index_y
uint16_t index_y
Definition: fonts.h:47
BlamFontGlyph::glyph_datablock
Ogre::HlmsDatablock * glyph_datablock
Definition: fonts.h:52
BlamRendering::DirectX::D2D::MF
Namespace containing things relating to the MF font loader.
Definition: FontLoader.h:44
Blam::Content::Fonts::Font::package_engine_version
std::string package_engine_version
The minimum engine version to support the font package version specified.
Definition: fonts.h:137
BlamFontPackageType::Unknown
@ Unknown
FONT_PACKAGE_EXTENSION
#define FONT_PACKAGE_EXTENSION
Definition: fonts.h:21
BLAM
#define BLAM
Definition: fonts.h:15
BlamRendering::DirectX::D2D::GetD2DRenderTarget
BLAM ID2D1DeviceContext * GetD2DRenderTarget()
Retrieves the Direct2D render target.
Definition: render_manage.cpp:598
Blam::Content::Fonts::GetFontList
BLAM std::map< std::string, Font > * GetFontList()
Retrieves the list of loaded fonts.
Definition: fonts.cpp:835
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig()
Retrieves the engine configuration file.
Definition: compat.cpp:5
BlamFontPackage::file_path
std::string file_path
Definition: fonts.h:61
Blam::Cache::WriteFileToCache
std::string WriteFileToCache(void *data, int length, std::string id)
Writes a block of data to the cache as a file.
Definition: cache.cpp:12
BlamFontPackage::GetGlyph
BlamFontGlyph * GetGlyph(char character)
Definition: BlamFontPackage.cpp:25
BlamFontPackage::~BlamFontPackage
~BlamFontPackage()
Definition: BlamFontPackage.cpp:12
Blam::Content::Fonts::Cleanup
BLAM void Cleanup()
Clean-up all font data and free any allocated memory for font data.
Definition: fonts.cpp:887
BlamFontGlyph::use_point_filtering
bool use_point_filtering
Definition: fonts.h:41
Blam::Content::Fonts::GetFont
BLAM Font * GetFont(std::string id)
Retrieves a font from the list of loaded fonts.
Definition: fonts.cpp:806
BlamRendering::DirectX::WIC::CreateWICBitmapFromMemory
BLAM HRESULT CreateWICBitmapFromMemory(void *data, int size, IWICBitmap **bitmap_pointer)
Creates a WIC bitmap from a block of memory.
Definition: wic.cpp:173
Blam::Content::Fonts::Font::charspacing
short charspacing
The amount of space, in pixels, between each character.
Definition: fonts.h:144
Blam::Content::Fonts::FontGlyph::data_length
int data_length
The length of the glyph's image data. Only used in the case of a font package.
Definition: fonts.h:115
BlamEngineDataFolder::Fonts
@ Fonts
Directory used for game engine fonts. Defaults to ./maps/fonts/
BlamFontPackage::glyphs
BlamMap< char, BlamFontGlyph * > glyphs
Definition: fonts.h:63
rendering.h
Blam::Content::Fonts::LoadFont
BLAM HRESULT LoadFont(std::string path)
Load a font from disk.
Definition: fonts.cpp:46
drawing.h
Blam::Content::Fonts::FontGlyph::file_path
std::string file_path
The path of the glyph's image file. Only used in the case of an unpackaged font.
Definition: fonts.h:125
Blam::Content::Fonts::FontGlyph::data_offset
int data_offset
The file offset of the glyph's raw image data. Only used in the case of a font package.
Definition: fonts.h:114
Blam::Content::Fonts::New::GetFont
BLAM BlamFontPackage * GetFont(std::string id)
Definition: fonts_new.cpp:662
BlamFontPackage::glyphs_per_column
uint32_t glyphs_per_column
Definition: fonts.h:73
BlamFontGlyph::height
uint32_t height
Definition: fonts.h:44
Blam::Content::Fonts::Font::is_truetype
bool is_truetype
Whether or not the font is a TrueType based font.
Definition: fonts.h:150
NULL
Add a fourth parameter to bake specific font ranges NULL
Definition: README.txt:57
Blam::Content::Fonts::FontGlyph
Structure to contain data for a Font Glyph.
Definition: fonts.h:111
BlamFontPackage::monospace_width
int monospace_width
Definition: fonts.h:66
BlamFontGlyph::width
uint32_t width
Definition: fonts.h:43
BlamFontPackageType
BlamFontPackageType
Definition: fonts.h:24
BlamFontPackage::CreateCopiedDatablock
Ogre::HlmsDatablock * CreateCopiedDatablock()
Definition: BlamFontPackage.cpp:35
FontGlyphFormat
FontGlyphFormat
Enumerator for the image format used in a given font glyph.
Definition: fonts.h:94
BlamFontPackage::font_datablock
Ogre::HlmsDatablock * font_datablock
Definition: fonts.h:76
BlamFontGlyph
Definition: fonts.h:35
BlamRendering::DirectX::D2D::LoadFontFromFile
BLAM HRESULT LoadFontFromFile(std::string id, std::string file_path)
Loads a TrueType font from the specified file into the list of loaded font collections.
Definition: render_manage.cpp:555
errors.h
Blam::Content::Fonts::New::LoadFont
BLAM BlamResult LoadFont(std::string font_name)
Definition: fonts_new.cpp:647
Blam::Content::Fonts::Font::ttf_length
int ttf_length
The length of the embedded TrueType font data.
Definition: fonts.h:140
Blam::Content::Fonts::Font::glyph_list
std::map< char, FontGlyph > glyph_list
The list of glyphs for this font.
Definition: fonts.h:163
Blam::Content::Fonts::New::Cleanup
BLAM void Cleanup()
Definition: fonts_new.cpp:672
format
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting format
Definition: ARPHICPL.TXT:16
ENGINE_DATA_PATH
#define ENGINE_DATA_PATH(path)
Macro to quickly access a game engine data folder.
Definition: config.h:36
PNG
@ PNG
Indicates the glyph originates from a .PNG image.
Definition: fonts.h:96
BlamFontPackageType::XMLBitmapAtlas
@ XMLBitmapAtlas
BlamFontPackage::type
BlamFontPackageType type
Definition: fonts.h:62
BlamRendering::DirectX::D2D::GetD2DFactory
BLAM ID2D1Factory * GetD2DFactory()
Retrieves the Direct2D factory.
Definition: render_manage.cpp:603
BlamFontPackage::line_height
int line_height
Definition: fonts.h:68
BL_E_FONT_INVALID_DATA
#define BL_E_FONT_INVALID_DATA
Definition: errors.h:57
Blam::Content::Fonts::New::LoadFontPackage
BLAM BlamResult LoadFontPackage(std::string file)
Definition: fonts_new.cpp:69
BlamFontPackage::font_atlas
Ogre::TextureGpu * font_atlas
Definition: fonts.h:75
BlamFontPackageType::XMLBitmap
@ XMLBitmap
Blam::Content::Fonts::Font::size
short size
The size of the font.
Definition: fonts.h:143
BL_W_GLYPH_FILE_NOT_FOUND
#define BL_W_GLYPH_FILE_NOT_FOUND
Definition: errors.h:75
Blam::Content::Fonts::Font::monospaced
bool monospaced
Whether or not to treat the font as a monospace font.
Definition: fonts.h:145
BlamFontGlyph::character
char character
Definition: fonts.h:38
Blam::Content::Fonts::Font::mono_width
short mono_width
The width for each character to be. Extra space will be left as needed if the glyph width is too smal...
Definition: fonts.h:146
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
BlamFontPackage::monospace
bool monospace
Definition: fonts.h:65
it
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting changing font or adding deleting some characters in from glyph table PL means Public License Copyright Holder means whoever is named in the copyright or copyrights for the Font You means the or person redistributing or modifying the Font Freely Available means that you have the freedom to copy or modify the Font as well as redistribute copies of the Font under the same conditions you not price If you you can charge for this service Copying &Distribution You may copy and distribute verbatim copies of this Font in any without provided that you retain this license including modifying reordering converting changing font or adding deleting some characters in from glyph and copy and distribute such modifications under the terms of Section provided that the following conditions are such as by offering access to copy the modifications from a designated or distributing the modifications on a medium customarily used for software interchange c If the modified fonts normally reads commands interactively when you must cause it
Definition: ARPHICPL.TXT:36
Blam::Content::Fonts::Font
Structure to contain data for a Font.
Definition: fonts.h:134
FONT_TABLE_FILE
#define FONT_TABLE_FILE
Definition: fonts.h:18
BlamFontGlyph::uv
BlamVector4 uv
Definition: fonts.h:49
Blam::Content::Fonts::Font::is_font_package
bool is_font_package
Whether or not the data originates from a font package.
Definition: fonts.h:138
file
sock planetquake com All rights reserved Quake III Arena is a registered trademark of id Inc This level may be electronically distributed only at NO CHARGE to the recipient in its current MUST include this txt file
Definition: chiropteraDM.txt:95
Blam::Content::Fonts::Font::path
std::string path
The path of the font package, excluding the file extension.
Definition: fonts.h:154
Blam::Content::Fonts::Font::file_path
std::string file_path
The path to either the font package or the fontinfo.xml file for this font.
Definition: fonts.h:155
errors.h
BlamRendering::DirectX::WIC::CreateWICBitmapFromFile
BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap **bitmap_pointer)
Creates a WIC bitmap from a file.
Definition: wic.cpp:141
cache.h
BL_S_FONT_LOADED_OK_BAD_GLYPHS
#define BL_S_FONT_LOADED_OK_BAD_GLYPHS
Definition: errors.h:66
BlamFontGlyph::CreateCopiedDatablock
Ogre::HlmsDatablock * CreateCopiedDatablock()
Definition: BlamFontGlyph.cpp:7
Blam::Content::Fonts::FontGlyph::width
short width
The width of the glyph image, in pixels.
Definition: fonts.h:121
height
int height
Definition: bgfx.cpp:20
Blam::Content::Fonts::FontGlyph::bitmap_data
void * bitmap_data
The raw image data loaded from a font package. This must be available for the lifetime of the font,...
Definition: fonts.h:128
BlamFontGlyph::index_x
uint16_t index_x
Definition: fonts.h:46
resolve_glyph_character
bool resolve_glyph_character(std::string xml_glyph, char *character)
Identify the character of the font glyph from the XML attribute.
Definition: fonts.cpp:755
BlamFontPackageType::XMLTruetype
@ XMLTruetype
BlamFontPackageType::Bitmap
@ Bitmap
Blam::Content::Fonts::Font::space_width
short space_width
The amount of space, in pixels, to use for the space character.
Definition: fonts.h:147
config.h
Blam::Error::GetStringFromHResult
BLAM std::string GetStringFromHResult(HRESULT hr)
Converts a result handle to a string.
Definition: errors.cpp:120
BlamFontPackage::ttf_font
Ogre::FontPtr ttf_font
Definition: fonts.h:77
font_list
std::map< std::string, Font > font_list
Definition: fonts.cpp:23
GetGlyphFormatFromString
FontGlyphFormat GetGlyphFormatFromString(std::string format)
Evaluates a string into the appropriate FontGlyphFormat.
Definition: fonts.cpp:680
Blam::Content::Fonts::GetFontGlyph
BLAM FontGlyph * GetFontGlyph(Font *font, char glyph)
Retrieves a glyph from a font.
Definition: fonts.cpp:820
fonts.h
BlamFontPackage::glyphs_per_row
uint32_t glyphs_per_row
Definition: fonts.h:72
Blam::Content::Fonts
Definition: fonts.h:99
Blam::Content::Fonts::FontGlyph::character
char character
The character that the glyph represents.
Definition: fonts.h:118
BlamFontGlyph::override_filtering
bool override_filtering
Definition: fonts.h:40
Blam::Content::Fonts::Font::id
std::string id
The unique ID of the font.
Definition: fonts.h:142
Blam::Content::Fonts::Font::line_height
short line_height
The amount of space, in pixels, between each line.
Definition: fonts.h:148
BlamFontPackage::charspacing
int charspacing
Definition: fonts.h:67
Blam::Content::Fonts::New::LoadFontDirectory
BLAM BlamResult LoadFontDirectory(std::string directory)
Definition: fonts_new.cpp:74
Blam::Content::Fonts::Font::ttf_name
std::string ttf_name
The display name of the TrueType font file. TODO: Make this shit automated.
Definition: fonts.h:152
uint16_t
unsigned short uint16_t
Definition: stdint.h:16
Blam::Content::Fonts::New::FontExists
BLAM bool FontExists(std::string id)
Definition: fonts_new.cpp:657
Blam::Content::Fonts::FontGlyph::height
short height
The height of the glyph image, in pixels.
Definition: fonts.h:122
BlamFontPackage::space_width
int space_width
Definition: fonts.h:69
Blam::Content::Fonts::FontGlyph::bitmap
IWICBitmap * bitmap
The WIC bitmap for this glyph.
Definition: fonts.h:127
Blam::Content::Fonts::FontGlyph::path
std::string path
The path of the glyph's image file, relative to fontinfo.xml's location. Only used in the case of an ...
Definition: fonts.h:124
FONT_PACKAGE_VERSION
#define FONT_PACKAGE_VERSION
Definition: fonts.h:22
FONTINFO_FILENAME
#define FONTINFO_FILENAME
Definition: fonts.h:20
LoadGlyph
HRESULT LoadGlyph(char character, int width, int height, std::string bitmap_path, std::string format, Font *font)
Creates a FontGlyph from the provided data.
Definition: fonts.cpp:705
Blam::Content::Fonts::LoadAllFonts
BLAM void LoadAllFonts()
Loads all fonts available in the engine's configured font directory.
Definition: fonts.cpp:900
BlamFontPackageType::BitmapAtlas
@ BitmapAtlas
Blam::Content::Fonts::Font::package_version
short package_version
The version of the font package.
Definition: fonts.h:136