Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.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 
24 
28 {
29  Unknown,
30  Bitmap,
31  BitmapAtlas,
32  TrueType,
33  XMLBitmap,
35  XMLTruetype,
36 };
37 
44 {
45 public:
46  char character = 0x00;
47 
48  bool override_filtering = false;
49 
53  bool use_point_filtering = false;
54 
57 
60 
61  BlamVector4 uv = { 0, 0, 0, 0 };
62 
63  Ogre::TextureGpu* glyph_texture = nullptr;
64  Ogre::HlmsDatablock* glyph_datablock = nullptr;
65 
77  Ogre::HlmsDatablock* CreateCopiedDatablock();
78 };
79 
87 {
88 public:
89  std::string name = "";
90  std::string file_path = "";
92  BlamMap<char, BlamFontGlyph*> glyphs = BlamMap<char, BlamFontGlyph*>();
93 
94  bool monospace = false;
95  int monospace_width = 0;
96  int charspacing = 0;
97  int line_height = 0;
98  int space_width = 0;
99  bool use_point_filtering = false;
100 
103 
104  Ogre::TextureGpu* font_atlas = nullptr;
105  Ogre::HlmsDatablock* font_datablock = nullptr;
106  Ogre::FontPtr ttf_font;
107 
113  BlamFontPackage();
114 
119 
128  BlamFontGlyph* GetGlyph(char character);
129 
141  Ogre::HlmsDatablock* CreateCopiedDatablock();
142 };
143 
150 {
154  BLAM void LoadAllFonts();
155 
163  BLAM BlamResult LoadFontDirectory(std::string directory);
164 
174  BLAM BlamResult LoadFontPackage(std::string file);
175 
179  BLAM BlamResult LoadFont(std::string font_name);
180 
188  BLAM BlamMap<std::string, BlamFontPackage*> GetFontList();
189 
197  BLAM bool FontExists(std::string id);
198 
206  BLAM BlamFontPackage* GetFont(std::string id);
207 
211  BLAM void Cleanup();
212 }
213 
Blam::Rendering::Materials::CreateDefaultUnlitDatablockForPrimitives
BLAM Ogre::HlmsUnlitDatablock * CreateDefaultUnlitDatablockForPrimitives(std::string id)
Creates a default Unlit datablock for use with 2D and 3D primitives.
Definition: materials.cpp:966
BlamFontPackage::BlamFontPackage
BlamFontPackage()
Constructor.
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:130
Blam::Rendering::Materials::CreateDefaultUnlitDatablock
BLAM Ogre::HlmsUnlitDatablock * CreateDefaultUnlitDatablock(std::string id)
Creates a default Unlit datablock.
Definition: materials.cpp:955
font
io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels,...) font
Definition: README.txt:86
Blam::Content::Fonts::FontExists
BLAM bool FontExists(std::string id)
Checks if a font package exists with a given name.
Definition: fonts.cpp:739
BlamFontPackageType::TrueType
@ TrueType
Indicates that the font package stores a TrueType (or similar) font directly.
BlamFontPackage::use_point_filtering
bool use_point_filtering
Whether or not glyphs in this font package should use point filtering or not.
Definition: fonts.h:99
logger.h
BlamFontGlyph::glyph_texture
Ogre::TextureGpu * glyph_texture
The texture for the glyph. Only used in non-atlas bitmap fonts.
Definition: fonts.h:63
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
The name/ID of the font. Must be unique.
Definition: fonts.h:89
BlamFontPackage
Class representing a Blamite font package.
Definition: fonts.h:86
BlamFontGlyph::index_y
uint16_t index_y
The Y index of the glyph within the font atlas texture.
Definition: fonts.h:59
BlamFontGlyph::glyph_datablock
Ogre::HlmsDatablock * glyph_datablock
The datablock for the glyph. Only used in non-atlas bitmap fonts.
Definition: fonts.h:64
BlamFontPackageType::Unknown
@ Unknown
Indicates the font package has an unknown type. Should generally be considered an error.
BLAM
#define BLAM
Definition: fonts.h:15
BlamFontPackage::file_path
std::string file_path
The file path of the font information or package file.
Definition: fonts.h:90
Blam::Content::Fonts::LoadFont
BLAM BlamResult LoadFont(std::string font_name)
Definition: fonts.cpp:729
BlamFontPackage::GetGlyph
BlamFontGlyph * GetGlyph(char character)
Retrieves font glyph information from a character.
Definition: BlamFontPackage.cpp:23
BlamFontPackage::~BlamFontPackage
~BlamFontPackage()
Destructor.
Definition: BlamFontPackage.cpp:12
Blam::Content::Fonts::Cleanup
BLAM void Cleanup()
Releases all font package data from memory.
Definition: fonts.cpp:754
BlamFontGlyph::use_point_filtering
bool use_point_filtering
Whether or not this glyph should use point filtering.
Definition: fonts.h:53
glyph_attribute_test_int
int glyph_attribute_test_int(bool *out_result, std::string glyph_name, std::string font_name, std::string attribute_name, rapidxml::xml_attribute<> *attribute)
A helper function used to check if a glyph attribute's value is an integer or not.
Definition: fonts.cpp:73
glyph_attribute_test_float
float glyph_attribute_test_float(bool *out_result, std::string glyph_name, std::string font_name, std::string attribute_name, rapidxml::xml_attribute<> *attribute)
A helper function used to check if a glyph attribute's value is a float or not.
Definition: fonts.cpp:106
BlamEngineDataFolder::Fonts
@ Fonts
Directory used for game engine fonts. Defaults to ./maps/fonts/
BlamFontPackage::glyphs
BlamMap< char, BlamFontGlyph * > glyphs
Map containing all glyphs within the font package.
Definition: fonts.h:92
Blam::Content::Fonts::GetFont
BLAM BlamFontPackage * GetFont(std::string id)
Retrieves a font package from its name.
Definition: fonts.cpp:744
rendering.h
BlamFontPackage::glyphs_per_column
uint32_t glyphs_per_column
The number of glyphs per column within the texture atlas. Only used in fonts that use a texture atlas...
Definition: fonts.h:102
BlamFontGlyph::height
uint32_t height
The height of the glyph texture.
Definition: fonts.h:56
BlamFontPackage::monospace_width
int monospace_width
The monospaced width of each character. Only used when monospace is set to true.
Definition: fonts.h:95
BlamFontGlyph::width
uint32_t width
The width of the glyph texture.
Definition: fonts.h:55
BlamFontPackageType
BlamFontPackageType
Enumerator listing all possible font package types.
Definition: fonts.h:27
BlamFontPackage::CreateCopiedDatablock
Ogre::HlmsDatablock * CreateCopiedDatablock()
Creates a copy of this glyph's datablock, intended to allow for it to be recolored on a per-instance ...
Definition: BlamFontPackage.cpp:33
Blam::Rendering::Textures::LoadTexture2D
BLAM Ogre::TextureGpu * LoadTexture2D(std::string id, void *pixel_data, int width, int height, Ogre::PixelFormatGpu format, int bytes_per_line)
Loads a 2D texture from data in memory.
Definition: textures.cpp:140
BlamFontPackage::font_datablock
Ogre::HlmsDatablock * font_datablock
The font atlas datablock. Only used in fonts that use a texture atlas.
Definition: fonts.h:105
BlamFontGlyph
Class representing a font glyph.
Definition: fonts.h:43
Blam::Content::Fonts::LoadFontPackage
BLAM BlamResult LoadFontPackage(std::string file)
Attempts to load a font package from a file.
Definition: fonts.cpp:151
ENGINE_DATA_PATH
#define ENGINE_DATA_PATH(path)
Macro to quickly access a game engine data folder.
Definition: config.h:34
font_map
BlamMap< std::string, BlamFontPackage * > font_map
Definition: fonts.cpp:18
BlamFontPackageType::XMLBitmapAtlas
@ XMLBitmapAtlas
Identical to #BitmapAtlas, but indicates that the font package is unpacked.
BlamFontPackage::type
BlamFontPackageType type
The format of the font pacakge. See BlamFontPackageType for details.
Definition: fonts.h:91
BlamFontPackage::line_height
int line_height
The height of each line of text, in pixels.
Definition: fonts.h:97
BlamFontPackage::font_atlas
Ogre::TextureGpu * font_atlas
The font atlas texture. Only used in fonts that use a texture atlas.
Definition: fonts.h:104
BlamFontPackageType::XMLBitmap
@ XMLBitmap
Identical to #Bitmap, but indicates that the font package is unpacked.
Blam::Content::Fonts::GetFontList
BLAM BlamMap< std::string, BlamFontPackage * > GetFontList()
Retrieves the map of all available fonts.
Definition: fonts.cpp:734
BlamFontGlyph::character
char character
The character that this glyph represents.
Definition: fonts.h:46
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
BlamFontPackage::monospace
bool monospace
Whether or not the font is monospaced.
Definition: fonts.h:94
BlamFontGlyph::uv
BlamVector4 uv
The UV coordinates of the font glyph.
Definition: fonts.h:61
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
BlamFontGlyph::CreateCopiedDatablock
Ogre::HlmsDatablock * CreateCopiedDatablock()
Creates a copy of this glyph's datablock, intended to allow for it to be recolored on a per-instance ...
Definition: BlamFontGlyph.cpp:7
BlamFontGlyph::index_x
uint16_t index_x
The X index of the glyph within the font atlas texture.
Definition: fonts.h:58
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:28
BlamFontPackageType::XMLTruetype
@ XMLTruetype
Identical to #Truetype, but indicates that the font package is unpacked.
Blam::Content::Fonts::LoadFontDirectory
BLAM BlamResult LoadFontDirectory(std::string directory)
Attempts to load an unpackaged (XML) font from a directory.
Definition: fonts.cpp:156
BlamFontPackageType::Bitmap
@ Bitmap
Indicates that the font package stores glyphs in separate bitmaps.
config.h
BlamFontPackage::ttf_font
Ogre::FontPtr ttf_font
Unused.
Definition: fonts.h:106
fonts.h
BlamFontPackage::glyphs_per_row
uint32_t glyphs_per_row
The number of glyphs per row within the texture atlas. Only used in fonts that use a texture atlas.
Definition: fonts.h:101
Blam::Content::Fonts
Namespace containing functions for interacting with font packages.
Definition: fonts.h:149
BlamFontGlyph::override_filtering
bool override_filtering
Whether or not to override the font package texture filtering mode.
Definition: fonts.h:48
BlamFontPackage::charspacing
int charspacing
The amount of spacing between each character, in pixels.
Definition: fonts.h:96
uint16_t
unsigned short uint16_t
Definition: stdint.h:16
BlamFontPackage::space_width
int space_width
The width of the space character, in pixels. Only used when monospace is false.
Definition: fonts.h:98
FONTINFO_FILENAME
#define FONTINFO_FILENAME
The default filename for XML (unpacked) font information.
Definition: fonts.h:20
Blam::Content::Fonts::LoadAllFonts
BLAM void LoadAllFonts()
Loads all available font packages within the fonts directory.
Definition: fonts.cpp:127
BlamFontPackageType::BitmapAtlas
@ BitmapAtlas
Indicates that the font package stores glyphs in a texture atlas bitmap.