Blamite Game Engine - Blam (Core)
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 
7 #ifndef BLAM
8 #define BLAM
9 #endif
10 
11 #define FONTINFO_FILENAME "fontinfo.xml"
12 #define FONT_PACKAGE_EXTENSION ".bin"
13 #define FONT_PACKAGE_VERSION 2
14 
24 {
25  PNG
26 };
27 
28 namespace Blam
29 {
30  namespace Content
31  {
32  namespace Fonts
33  {
34  /*struct DWFontFile
35  {
36  UINT64 font_size;
37  void* font_data;
38  const char* key;
39  };*/
40 
44  struct FontGlyph
45  {
46  //package info
49 
50  //character info
51  char character;
52 
53  //bitmap info
54  short width;
55  short height;
57  std::string path;
58  std::string file_path;
59 
60  IWICBitmap* bitmap;
61  void* bitmap_data;
62  };
63 
67  struct Font
68  {
70  std::string package_engine_version;
72  int ttf_offset;
73  int ttf_length;
74 
75  std::string id;
76  short size;
77  short charspacing;
78  bool monospaced;
79  short mono_width;
80  short space_width;
81  short line_height;
82 
83  bool is_truetype;
84  std::string ttf_path;
85  std::string ttf_name;
86 
87  std::string path;
88  std::string file_path;
89 
96  std::map<char, FontGlyph> glyph_list;
97  };
98 
104  BLAM void LoadAllFonts();
105 
115  BLAM HRESULT LoadFont(std::string path);
116 
125  BLAM HRESULT ReloadFont(std::string id);
126 
134  BLAM Font* GetFont(std::string id);
135 
144  BLAM FontGlyph* GetFontGlyph(Font* font, char glyph);
145 
153  BLAM bool FontExists(std::string id);
154 
158  BLAM std::map<std::string, Font>* GetFontList();
159 
163  BLAM void Cleanup();
164  }
165  }
166 }
167 
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:17
Blam::Content::Fonts::ReloadFont
BLAM HRESULT ReloadFont(std::string id)
Reloads all data for the specified font.
Definition: fonts.cpp:856
Blam::Content::Fonts::FontGlyph::format
FontGlyphFormat format
The format of the glyph image data. See FontGlyphFormat for more details.
Definition: fonts.h:56
Blam::Content::Fonts::FontExists
BLAM bool FontExists(std::string id)
Checks whether or not a font is loaded.
Definition: fonts.cpp:24
Blam::Content::Fonts::Font::ttf_path
std::string ttf_path
The path to the TrueType font file.
Definition: fonts.h:84
Blam::Content::Fonts::Font::ttf_offset
int ttf_offset
The offset of the embedded TrueType font data within the font package.
Definition: fonts.h:72
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:70
BLAM
#define BLAM
Definition: fonts.h:8
Blam::Content::Fonts::GetFontList
BLAM std::map< std::string, Font > * GetFontList()
Retrieves the list of loaded fonts.
Definition: fonts.cpp:824
Blam::Content::Fonts::Cleanup
BLAM void Cleanup()
Clean-up all font data and free any allocated memory for font data.
Definition: fonts.cpp:876
Blam::Content::Fonts::GetFont
BLAM Font * GetFont(std::string id)
Retrieves a font from the list of loaded fonts.
Definition: fonts.cpp:795
Blam::Content::Fonts::Font::charspacing
short charspacing
The amount of space, in pixels, between each character.
Definition: fonts.h:77
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:48
Blam::Content::Fonts::LoadFont
BLAM HRESULT LoadFont(std::string path)
Load a font from disk.
Definition: fonts.cpp:44
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:58
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:47
Blam::Content::Fonts::Font::is_truetype
bool is_truetype
Whether or not the font is a TrueType based font.
Definition: fonts.h:83
Blam::Content::Fonts::FontGlyph
Structure to contain data for a Font Glyph.
Definition: fonts.h:44
FontGlyphFormat
FontGlyphFormat
Enumerator for the image format used in a given font glyph.
Definition: fonts.h:23
Blam::Content::Fonts::Font::ttf_length
int ttf_length
The length of the embedded TrueType font data.
Definition: fonts.h:73
Blam::Content::Fonts::Font::glyph_list
std::map< char, FontGlyph > glyph_list
The list of glyphs for this font.
Definition: fonts.h:96
PNG
@ PNG
Indicates the glyph originates from a .PNG image.
Definition: fonts.h:25
Blam::Content::Fonts::Font::size
short size
The size of the font.
Definition: fonts.h:76
Blam::Content::Fonts::Font::monospaced
bool monospaced
Whether or not to treat the font as a monospace font.
Definition: fonts.h:78
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:79
Blam::Content::Fonts::Font
Structure to contain data for a Font.
Definition: fonts.h:67
Blam::Content::Fonts::Font::is_font_package
bool is_font_package
Whether or not the data originates from a font package.
Definition: fonts.h:71
Blam::Content::Fonts::Font::path
std::string path
The path of the font package, excluding the file extension.
Definition: fonts.h:87
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:88
Blam::Content::Fonts::FontGlyph::width
short width
The width of the glyph image, in pixels.
Definition: fonts.h:54
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:61
Blam::Content::Fonts::Font::space_width
short space_width
The amount of space, in pixels, to use for the space character.
Definition: fonts.h:80
Blam::Content::Fonts::GetFontGlyph
BLAM FontGlyph * GetFontGlyph(Font *font, char glyph)
Retrieves a glyph from a font.
Definition: fonts.cpp:809
Blam::Content::Fonts::FontGlyph::character
char character
The character that the glyph represents.
Definition: fonts.h:51
Blam::Content::Fonts::Font::id
std::string id
The unique ID of the font.
Definition: fonts.h:75
Blam::Content::Fonts::Font::line_height
short line_height
The amount of space, in pixels, between each line.
Definition: fonts.h:81
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:85
Blam::Content::Fonts::FontGlyph::height
short height
The height of the glyph image, in pixels.
Definition: fonts.h:55
Blam::Content::Fonts::FontGlyph::bitmap
IWICBitmap * bitmap
The WIC bitmap for this glyph.
Definition: fonts.h:60
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:57
Blam::Content::Fonts::LoadAllFonts
BLAM void LoadAllFonts()
Loads all fonts available in the engine's configured font directory.
Definition: fonts.cpp:889
Blam::Content::Fonts::Font::package_version
short package_version
The version of the font package.
Definition: fonts.h:69