Elaztek Developer Hub
Blamite Game Engine - blam!  00346.12.11.21.0529.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 
8 #ifndef BLAM
9 #define BLAM
10 #endif
11 
12 #define FONT_TABLE_FILE "font_table.txt"
13 
14 #define FONTINFO_FILENAME "fontinfo.xml"
15 #define FONT_PACKAGE_EXTENSION ".bin"
16 #define FONT_PACKAGE_VERSION 2
17 
27 {
28  PNG
29 };
30 
31 namespace Blam
32 {
33  namespace Content
34  {
35  namespace Fonts
36  {
37  /*struct DWFontFile
38  {
39  UINT64 font_size;
40  void* font_data;
41  const char* key;
42  };*/
43 
47  struct FontGlyph
48  {
49  //package info
52 
53  //character info
54  char character;
55 
56  //bitmap info
57  short width;
58  short height;
60  std::string path;
61  std::string file_path;
62 
63  IWICBitmap* bitmap;
64  void* bitmap_data;
65  };
66 
70  struct Font
71  {
73  std::string package_engine_version;
75  int ttf_offset;
76  int ttf_length;
77 
78  std::string id;
79  short size;
80  short charspacing;
81  bool monospaced;
82  short mono_width;
83  short space_width;
84  short line_height;
85 
86  bool is_truetype;
87  std::string ttf_path;
88  std::string ttf_name;
89 
90  std::string path;
91  std::string file_path;
92 
99  std::map<char, FontGlyph> glyph_list;
100  };
101 
107  BLAM void LoadAllFonts();
108 
118  BLAM HRESULT LoadFont(std::string path);
119 
128  BLAM HRESULT ReloadFont(std::string id);
129 
137  BLAM Font* GetFont(std::string id);
138 
147  BLAM FontGlyph* GetFontGlyph(Font* font, char glyph);
148 
156  BLAM bool FontExists(std::string id);
157 
161  BLAM std::map<std::string, Font>* GetFontList();
162 
166  BLAM void Cleanup();
167  }
168  }
169 }
170 
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:21
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:59
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:87
Blam::Content::Fonts::Font::ttf_offset
int ttf_offset
The offset of the embedded TrueType font data within the font package.
Definition: fonts.h:75
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:73
BLAM
#define BLAM
Definition: fonts.h:9
Blam::Content::Fonts::GetFontList
BLAM std::map< std::string, Font > * GetFontList()
Retrieves the list of loaded fonts.
Definition: fonts.cpp:835
Blam::Content::Fonts::Cleanup
BLAM void Cleanup()
Clean-up all font data and free any allocated memory for font data.
Definition: fonts.cpp:887
Blam::Content::Fonts::GetFont
BLAM Font * GetFont(std::string id)
Retrieves a font from the list of loaded fonts.
Definition: fonts.cpp:806
Blam::Content::Fonts::Font::charspacing
short charspacing
The amount of space, in pixels, between each character.
Definition: fonts.h:80
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:51
BlamEngineDataFolder::Fonts
@ Fonts
Directory used for game engine fonts. Defaults to ./maps/fonts/
Blam::Content::Fonts::LoadFont
BLAM HRESULT LoadFont(std::string path)
Load a font from disk.
Definition: fonts.cpp:46
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:61
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:50
Blam::Content::Fonts::Font::is_truetype
bool is_truetype
Whether or not the font is a TrueType based font.
Definition: fonts.h:86
Blam::Content::Fonts::FontGlyph
Structure to contain data for a Font Glyph.
Definition: fonts.h:47
FontGlyphFormat
FontGlyphFormat
Enumerator for the image format used in a given font glyph.
Definition: fonts.h:26
Blam::Content::Fonts::Font::ttf_length
int ttf_length
The length of the embedded TrueType font data.
Definition: fonts.h:76
Blam::Content::Fonts::Font::glyph_list
std::map< char, FontGlyph > glyph_list
The list of glyphs for this font.
Definition: fonts.h:99
PNG
@ PNG
Indicates the glyph originates from a .PNG image.
Definition: fonts.h:28
Blam::Content::Fonts::Font::size
short size
The size of the font.
Definition: fonts.h:79
Blam::Content::Fonts::Font::monospaced
bool monospaced
Whether or not to treat the font as a monospace font.
Definition: fonts.h:81
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:82
Blam::Content::Fonts::Font
Structure to contain data for a Font.
Definition: fonts.h:70
Blam::Content::Fonts::Font::is_font_package
bool is_font_package
Whether or not the data originates from a font package.
Definition: fonts.h:74
Blam::Content::Fonts::Font::path
std::string path
The path of the font package, excluding the file extension.
Definition: fonts.h:90
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:91
Blam::Content::Fonts::FontGlyph::width
short width
The width of the glyph image, in pixels.
Definition: fonts.h:57
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:64
Blam::Content::Fonts::Font::space_width
short space_width
The amount of space, in pixels, to use for the space character.
Definition: fonts.h:83
Blam::Content::Fonts::GetFontGlyph
BLAM FontGlyph * GetFontGlyph(Font *font, char glyph)
Retrieves a glyph from a font.
Definition: fonts.cpp:820
BlamEngineDataFolder::Content
@ Content
Directory containing general-purpose resources. Defaults to ./content/
Blam::Content::Fonts::FontGlyph::character
char character
The character that the glyph represents.
Definition: fonts.h:54
Blam::Content::Fonts::Font::id
std::string id
The unique ID of the font.
Definition: fonts.h:78
Blam::Content::Fonts::Font::line_height
short line_height
The amount of space, in pixels, between each line.
Definition: fonts.h:84
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:88
font
io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels,...) font
Definition: README.txt:86
Blam::Content::Fonts::FontGlyph::height
short height
The height of the glyph image, in pixels.
Definition: fonts.h:58
Blam::Content::Fonts::FontGlyph::bitmap
IWICBitmap * bitmap
The WIC bitmap for this glyph.
Definition: fonts.h:63
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:60
Blam::Content::Fonts::LoadAllFonts
BLAM void LoadAllFonts()
Loads all fonts available in the engine's configured font directory.
Definition: fonts.cpp:900
Blam::Content::Fonts::Font::package_version
short package_version
The version of the font package.
Definition: fonts.h:72