nomlib
Loading...
Searching...
No Matches
BMFont.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_GRAPHICS_FONTS_BMFONT_HPP
30#define NOMLIB_GRAPHICS_FONTS_BMFONT_HPP
31
32#include <fstream>
33#include <sstream>
34#include <vector>
35
36#include "export.hpp"
37#include "nomlib/config.hpp"
38#include "nomlib/graphics/fonts/IFont.hpp"
39#include "nomlib/graphics/fonts/FontMetrics.hpp"
40#include "nomlib/graphics/fonts/FontPage.hpp"
41
42namespace nom {
43
47struct NOM_EXPORT BMFontKerningPair
48{
53
58
61 int x_offset = 0;
62};
63
64NOM_EXPORT
65std::ostream& operator <<(std::ostream& os, const BMFontKerningPair& k);
66
67struct NOM_EXPORT BMFontPage
68{
72 int id = 0;
73
79 std::string filename;
80};
81
82class NOM_EXPORT BMFont: public IFont
83{
84 public:
85 typedef BMFont self_type;
86
89
91 virtual ~BMFont();
92
93 IFont* clone() const override;
94
95 bool valid() const override;
96
97 IFont::FontType type() const override;
98
100 const Image* image(uint32 character_size) const override;
101
104 const Glyph& glyph(uint32 codepoint, uint32 character_size) const override;
105
107 int spacing(uint32 character_size) const override;
108
116 int kerning(uint32 first_char, uint32 second_char, uint32 character_size) const override;
117
119 int hinting() const override;
120
122 uint32 font_style() const override;
123
125 const Size2i& page_size(uint32 page) const;
126
128 int newline(uint32 character_size) const override;
129
130 const FontMetrics& metrics() const override;
131
132 int point_size() const;
133
134 bool use_kerning() const;
135
137 bool set_point_size(int) override;
138
140 bool set_hinting(int) override;
141
143 bool set_outline(int) override;
144
146 void set_font_style(uint32) override;
147
151 void set_font_kerning(bool state) override;
152
153 bool load(const std::string& filename) override;
154
160 bool parse_ascii_file(std::istream& fp);
161
162 private:
166 bool build(uint32 character_size);
167
169 void parse_string(const std::string& key, std::string& value);
170
177
184
190 mutable GlyphPage pages_;
191
196
197 BMFontPage page_;
198
200 std::vector<BMFontKerningPair> kernings_;
201
204};
205
206} // namespace nom
207
208#endif // include guard defined
209
void parse_string(const std::string &key, std::string &value)
bool set_outline(int) override
bool build(uint32 character_size)
Create the texture atlas from the parsed font metrics.
int point_size_
The point size of the font.
Definition BMFont.hpp:195
const Size2i & page_size(uint32 page) const
bool set_hinting(int) override
int hinting() const override
const Glyph & glyph(uint32 codepoint, uint32 character_size) const override
BMFont()
Default constructor.
int spacing(uint32 character_size) const override
void set_font_style(uint32) override
bool use_kerning_
Usage state of kerning pair offsets.
Definition BMFont.hpp:203
void set_font_kerning(bool state) override
Set the use of kerning for the font.
bool set_point_size(int) override
GlyphPage pages_
Definition BMFont.hpp:190
std::vector< BMFontKerningPair > kernings_
Kerning pairs.
Definition BMFont.hpp:200
FontMetrics metrics_
The glyph characteristics for the font in use.
Definition BMFont.hpp:183
uint32 font_style() const override
bool load(const std::string &filename) override
virtual ~BMFont()
Destructor.
bool parse_ascii_file(std::istream &fp)
Read an input source that conforms to the BMFont file spec.
const Image * image(uint32 character_size) const override
Size2i page_size_
The total dimensions – width and height in integer pixels – of the texture atlas used to hold the gly...
Definition BMFont.hpp:176
int newline(uint32 character_size) const override
int kerning(uint32 first_char, uint32 second_char, uint32 character_size) const override
Obtain the kerning pair offsets between two glyphs.
Bitmap storage container.
Definition Image.hpp:49
The kerning information is used to adjust the distance between certain characters,...
Definition BMFont.hpp:48
int second_char_id
The second glyph identifier.
Definition BMFont.hpp:57
int first_char_id
The first glyph identifier.
Definition BMFont.hpp:52
int x_offset
How much the x position should be adjusted when drawing the second character immediately following th...
Definition BMFont.hpp:61
std::string filename
The texture file name for the page.
Definition BMFont.hpp:79
Container structure for global font metric data.
Container structure for font data.
Definition Glyph.hpp:45