Blamite Game Engine - blam!  00296.01.12.21.0102.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 FONTINFO_FILENAME "fontinfo.xml"
13 #define FONT_PACKAGE_EXTENSION ".bin"
14 #define FONT_PACKAGE_VERSION 2
15 
25 {
26  PNG
27 };
28 
29 namespace Blam
30 {
31  namespace Content
32  {
33  namespace Fonts
34  {
35  /*struct DWFontFile
36  {
37  UINT64 font_size;
38  void* font_data;
39  const char* key;
40  };*/
41 
45  struct FontGlyph
46  {
47  //package info
50 
51  //character info
52  char character;
53 
54  //bitmap info
55  short width;
56  short height;
58  std::string path;
59  std::string file_path;
60 
61  IWICBitmap* bitmap;
62  void* bitmap_data;
63  };
64 
68  struct Font
69  {
71  std::string package_engine_version;
73  int ttf_offset;
74  int ttf_length;
75 
76  std::string id;
77  short size;
78  short charspacing;
79  bool monospaced;
80  short mono_width;
81  short space_width;
82  short line_height;
83 
84  bool is_truetype;
85  std::string ttf_path;
86  std::string ttf_name;
87 
88  std::string path;
89  std::string file_path;
90 
97  std::map<char, FontGlyph> glyph_list;
98  };
99 
105  BLAM void LoadAllFonts();
106 
116  BLAM HRESULT LoadFont(std::string path);
117 
126  BLAM HRESULT ReloadFont(std::string id);
127 
135  BLAM Font* GetFont(std::string id);
136 
145  BLAM FontGlyph* GetFontGlyph(Font* font, char glyph);
146 
154  BLAM bool FontExists(std::string id);
155 
159  BLAM std::map<std::string, Font>* GetFontList();
160 
164  BLAM void Cleanup();
165  }
166  }
167 }
168 
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:18
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:57
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:85
Blam::Content::Fonts::Font::ttf_offset
int ttf_offset
The offset of the embedded TrueType font data within the font package.
Definition: fonts.h:73
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:71
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:78
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:49
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:59
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:48
Blam::Content::Fonts::Font::is_truetype
bool is_truetype
Whether or not the font is a TrueType based font.
Definition: fonts.h:84
Blam::Content::Fonts::FontGlyph
Structure to contain data for a Font Glyph.
Definition: fonts.h:45
FontGlyphFormat
FontGlyphFormat
Enumerator for the image format used in a given font glyph.
Definition: fonts.h:24
Blam::Content::Fonts::Font::ttf_length
int ttf_length
The length of the embedded TrueType font data.
Definition: fonts.h:74
Blam::Content::Fonts::Font::glyph_list
std::map< char, FontGlyph > glyph_list
The list of glyphs for this font.
Definition: fonts.h:97
PNG
@ PNG
Indicates the glyph originates from a .PNG image.
Definition: fonts.h:26
Blam::Content::Fonts::Font::size
short size
The size of the font.
Definition: fonts.h:77
Blam::Content::Fonts::Font::monospaced
bool monospaced
Whether or not to treat the font as a monospace font.
Definition: fonts.h:79
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:80
Blam::Content::Fonts::Font
Structure to contain data for a Font.
Definition: fonts.h:68
Blam::Content::Fonts::Font::is_font_package
bool is_font_package
Whether or not the data originates from a font package.
Definition: fonts.h:72
Blam::Content::Fonts::Font::path
std::string path
The path of the font package, excluding the file extension.
Definition: fonts.h:88
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:89
Blam::Content::Fonts::FontGlyph::width
short width
The width of the glyph image, in pixels.
Definition: fonts.h:55
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:62
Blam::Content::Fonts::Font::space_width
short space_width
The amount of space, in pixels, to use for the space character.
Definition: fonts.h:81
Blam::Content::Fonts::GetFontGlyph
BLAM FontGlyph * GetFontGlyph(Font *font, char glyph)
Retrieves a glyph from a font.
Definition: fonts.cpp:820
Blam::Content::Fonts::FontGlyph::character
char character
The character that the glyph represents.
Definition: fonts.h:52
Blam::Content::Fonts::Font::id
std::string id
The unique ID of the font.
Definition: fonts.h:76
Blam::Content::Fonts::Font::line_height
short line_height
The amount of space, in pixels, between each line.
Definition: fonts.h:82
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:86
Blam::Content::Fonts::FontGlyph::height
short height
The height of the glyph image, in pixels.
Definition: fonts.h:56
Blam::Content::Fonts::FontGlyph::bitmap
IWICBitmap * bitmap
The WIC bitmap for this glyph.
Definition: fonts.h:61
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:58
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:70