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 "nomlib/config.hpp"
37#include "nomlib/graphics/fonts/IFont.hpp"
38#include "nomlib/graphics/fonts/FontMetrics.hpp"
39#include "nomlib/graphics/fonts/FontPage.hpp"
40
41namespace nom {
42
47{
52
57
60 int x_offset = 0;
61};
62
63std::ostream& operator <<(std::ostream& os, const BMFontKerningPair& k);
64
66{
70 int id = 0;
71
77 std::string filename;
78};
79
80class BMFont: public IFont
81{
82 public:
83 typedef BMFont self_type;
84
87
89 virtual ~BMFont();
90
91 IFont* clone() const override;
92
93 bool valid() const override;
94
95 IFont::FontType type() const override;
96
98 const Image* image(uint32 character_size) const override;
99
102 const Glyph& glyph(uint32 codepoint, uint32 character_size) const override;
103
105 int spacing(uint32 character_size) const override;
106
114 int kerning(uint32 first_char, uint32 second_char, uint32 character_size) const override;
115
117 int hinting() const override;
118
120 uint32 font_style() const override;
121
123 const Size2i& page_size(uint32 page) const;
124
126 int newline(uint32 character_size) const override;
127
128 const FontMetrics& metrics() const override;
129
130 int point_size() const;
131
132 bool use_kerning() const;
133
135 bool set_point_size(int) override;
136
138 bool set_hinting(int) override;
139
141 bool set_outline(int) override;
142
144 void set_font_style(uint32) override;
145
149 void set_font_kerning(bool state) override;
150
151 bool load(const std::string& filename) override;
152
158 bool parse_ascii_file(std::istream& fp);
159
160 private:
164 bool build(uint32 character_size);
165
167 void parse_string(const std::string& key, std::string& value);
168
175
182
188 mutable GlyphPage pages_;
189
194
195 BMFontPage page_;
196
198 std::vector<BMFontKerningPair> kernings_;
199
202};
203
204} // namespace nom
205
206#endif // include guard defined
207
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:193
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:201
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:188
std::vector< BMFontKerningPair > kernings_
Kerning pairs.
Definition BMFont.hpp:198
FontMetrics metrics_
The glyph characteristics for the font in use.
Definition BMFont.hpp:181
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:174
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:48
The kerning information is used to adjust the distance between certain characters,...
Definition BMFont.hpp:47
int second_char_id
The second glyph identifier.
Definition BMFont.hpp:56
int first_char_id
The first glyph identifier.
Definition BMFont.hpp:51
int x_offset
How much the x position should be adjusted when drawing the second character immediately following th...
Definition BMFont.hpp:60
std::string filename
The texture file name for the page.
Definition BMFont.hpp:77
Container structure for global font metric data.
Container structure for font data.
Definition Glyph.hpp:44