nomlib
Loading...
Searching...
No Matches
BitmapFont.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
8Portions Copyright (c) 2004-2013 Lazy Foo' Productions [1]
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions are met:
13
141. Redistributions of source code must retain the above copyright notice, this
15 list of conditions and the following disclaimer.
162. Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
311. http://lazyfoo.net/SDL_tutorials/lesson30/index.php
32
33******************************************************************************/
34#ifndef NOMLIB_SDL2_BITMAP_FONT_HEADERS
35#define NOMLIB_SDL2_BITMAP_FONT_HEADERS
36
37#include <iostream>
38#include <string>
39#include <sstream>
40
41#include "nomlib/config.hpp"
42#include "nomlib/math/Color4.hpp"
43#include "nomlib/graphics/fonts/IFont.hpp"
44#include "nomlib/graphics/fonts/FontMetrics.hpp"
45#include "nomlib/graphics/fonts/FontPage.hpp"
46
47// Dump glyph bounding coordinates
48//#define NOM_DEBUG_SDL2_BITMAP_FONT
49
50namespace nom {
51
52// Forward declarations
53class Image;
54
55class BitmapFont: public IFont
56{
57 public:
58 typedef BitmapFont self_type;
59 typedef self_type* RawPtr;
60 typedef std::shared_ptr<self_type> SharedPtr;
61
63 BitmapFont ( void );
64
66 ~BitmapFont ( void );
67
69 BitmapFont ( const BitmapFont& copy );
70
72 IFont::raw_ptr clone( void ) const override;
73
75 bool valid ( void ) const override;
76
77 enum IFont::FontType type ( void ) const override;
78
79 const Image* image(uint32 character_size) const override;
80
85 sint spacing ( uint32 character_size ) const override;
86
92 int newline( uint32 character_size ) const override;
93
99 int kerning( uint32 first_char, uint32 second_char, uint32 character_size ) const override;
100
106 int hinting( void ) const override;
107
111 uint32 font_style( void ) const override;
112
119 const Glyph& glyph ( uint32 codepoint, uint32 character_size ) const override;
120
126 bool set_point_size ( sint size ) override;
127
131 bool set_hinting( int type ) override;
132
134 bool set_outline( int ) override;
135
139 void set_font_style( uint32 style ) override;
140
144 void set_font_kerning(bool state) override;
145
147 bool load( const std::string& filename ) override;
148
152 const FontMetrics& metrics( void ) const override;
153
154 private:
159 bool build ( uint32 character_size );
160
161 const GlyphPage& pages ( void ) const;
162
163 sint sheet_width ( void ) const;
164 sint sheet_height ( void ) const;
165
167 const enum IFont::FontType type_;
168
171
174
177 mutable GlyphPage pages_;
178
181
186 Color4i color_mask_;
187};
188
189} // namespace nom
190
191#endif // include guard defined
sint spacing(uint32 character_size) const override
Obtain text character spacing width in pixels.
IFont::raw_ptr clone(void) const override
Construct a clone of the existing instance.
sint sheet_width_
Width – in pixels – of overall texture atlas sheet.
uint32 font_style(void) const override
Get the rendering style of the font.
int hinting(void) const override
Get the font's hinting style.
bool set_point_size(sint size) override
Set a new font point size.
const Glyph & glyph(uint32 codepoint, uint32 character_size) const override
Obtain a glyph.
sint sheet_height_
Height – in pixels – of overall texture atlas sheet.
int kerning(uint32 first_char, uint32 second_char, uint32 character_size) const override
Obtain the kerning pair offsets between two glyphs.
void set_font_style(uint32 style) override
Set the rendering style of the font.
enum IFont::FontType type_
The type of font we are.
bool set_hinting(int type) override
Set the requested font hinting style.
BitmapFont(void)
Default constructor.
const FontMetrics & metrics(void) const override
Obtain information about the loaded font.
Color4i color_mask_
The pixel color found at the texture atlas position 0, 0 is used as a color mask – to filter out non-...
void set_font_kerning(bool state) override
Set the use of kerning for the font.
bool load(const std::string &filename) override
Loads a new bitmap font from a file.
bool build(uint32 character_size)
~BitmapFont(void)
Destructor.
FontMetrics metrics_
General font metric data, such as the proper value for newline spacing.
BitmapFont(const BitmapFont &copy)
Copy constructor.
bool valid(void) const override
Validity check.
bool set_outline(int) override
int newline(uint32 character_size) const override
Obtain font's line spacing.
Bitmap storage container.
Definition Image.hpp:48
Container structure for global font metric data.
Container structure for font data.
Definition Glyph.hpp:44