MezzanineEngine
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Mezzanine
src
UI
font.cpp
1
//© Copyright 2010 - 2013 BlackTopp Studios Inc.
2
/* This file is part of The Mezzanine Engine.
3
4
The Mezzanine Engine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
The Mezzanine Engine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
/* The original authors have included a copy of the license specified above in the
18
'Docs' folder. See 'gpl.txt'
19
*/
20
/* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21
Build professional software and charge for their product.
22
23
However there are some practical restrictions, so if your project involves
24
any of the following you should contact us and we will try to work something
25
out:
26
- DRM or Copy Protection of any kind(except Copyrights)
27
- Software Patents You Do Not Wish to Freely License
28
- Any Kind of Linking to Non-GPL licensed Works
29
- Are Currently In Violation of Another Copyright Holder's GPL License
30
- If You want to change our code and not add a few hundred MB of stuff to
31
your distribution
32
33
These and other limitations could cause serious legal problems if you ignore
34
them, so it is best to simply contact us or the Free Software Foundation, if
35
you have any questions.
36
37
Joseph Toppi - toppij@gmail.com
38
John Blackwood - makoenergy02@gmail.com
39
*/
40
#ifndef _uifont_cpp
41
#define _uifont_cpp
42
43
#include "UI/font.h"
44
#include "UI/glyph.h"
45
#include "UI/textureatlas.h"
46
47
namespace
Mezzanine
48
{
49
namespace
UI
50
{
51
FontData::FontData
(
TextureAtlas
* ParentAtlas) :
52
Atlas(ParentAtlas),
53
SpaceLength(0),
54
LineHeight(0),
55
BaseLine(0),
56
LetterSpacing(0)
57
{ this->
GenerateWhitespaceGlyphs
(); }
58
59
FontData::~FontData
()
60
{
61
for
( GlyphIterator GlyphIt = this->
Glyphs
.begin() ; GlyphIt != this->
Glyphs
.end() ; ++GlyphIt )
62
{
63
delete
(*GlyphIt).second;
64
}
65
this->
Glyphs
.clear();
66
}
67
68
void
FontData::SetWhitespaceAtlasCoords
(
Glyph
* Whitespace)
69
{
70
Whitespace->
AtlasCoords
[UI::QC_TopLeft] =
Atlas
->
GetWhitePixel
();
71
Whitespace->
AtlasCoords
[UI::QC_TopRight] =
Atlas
->
GetWhitePixel
();
72
Whitespace->
AtlasCoords
[UI::QC_BottomLeft] =
Atlas
->
GetWhitePixel
();
73
Whitespace->
AtlasCoords
[UI::QC_BottomRight] =
Atlas
->
GetWhitePixel
();
74
}
75
76
void
FontData::GenerateWhitespaceGlyphs
()
77
{
78
Glyph
* WhiteSpace = NULL;
79
// Create a glyph for a space
80
WhiteSpace =
new
Glyph
(
this
,this->
Atlas
,
Glyph::Space
,this->
SpaceLength
,0);
81
this->
SetWhitespaceAtlasCoords
(WhiteSpace);
82
this->
_AddGlyph
(WhiteSpace);
83
// Create a glyph for a tab
84
WhiteSpace =
new
Glyph
(
this
,this->
Atlas
,
Glyph::HT
,this->
SpaceLength
* 4,0);
85
this->
SetWhitespaceAtlasCoords
(WhiteSpace);
86
this->
_AddGlyph
(WhiteSpace);
87
// Create a glyph for a vertical tab
88
WhiteSpace =
new
Glyph
(
this
,this->
Atlas
,
Glyph::VT
,this->
SpaceLength
* 4,0);
89
this->
SetWhitespaceAtlasCoords
(WhiteSpace);
90
this->
_AddGlyph
(WhiteSpace);
91
// Create a glyph for a line feed
92
WhiteSpace =
new
Glyph
(
this
,this->
Atlas
,
Glyph::LF
,0,0);
93
this->
SetWhitespaceAtlasCoords
(WhiteSpace);
94
this->
_AddGlyph
(WhiteSpace);
95
// Create a glyph for carriage return
96
WhiteSpace =
new
Glyph
(
this
,this->
Atlas
,
Glyph::CR
,0,0);
97
this->
SetWhitespaceAtlasCoords
(WhiteSpace);
98
this->
_AddGlyph
(WhiteSpace);
99
// Create a glyph for next line
100
WhiteSpace =
new
Glyph
(
this
,this->
Atlas
,
Glyph::NEL
,0,0);
101
this->
SetWhitespaceAtlasCoords
(WhiteSpace);
102
this->
_AddGlyph
(WhiteSpace);
103
}
104
105
106
107
///////////////////////////////////////////////////////////////////////////////
108
// Utility Methods
109
110
Real
FontData::GetSpaceLength
()
const
111
{
return
this->
SpaceLength
; }
112
113
Real
FontData::GetLineHeight
()
const
114
{
return
this->
LineHeight
; }
115
116
Real
FontData::GetBaseLine
()
const
117
{
return
this->
BaseLine
; }
118
119
Real
FontData::GetLetterSpacing
()
const
120
{
return
this->
LetterSpacing
; }
121
122
const
String
&
FontData::GetName
()
const
123
{
return
this->
FontName
; }
124
125
TextureAtlas
*
FontData::GetAtlas
()
const
126
{
return
this->
Atlas
; }
127
128
const
String
&
FontData::GetAtlasName
()
const
129
{
return
this->
Atlas
->
GetName
(); }
130
131
Glyph
*
FontData::GetGlyph
(
const
UInt32
& GlyphID)
const
132
{
133
ConstGlyphIterator GlyphIt = this->
Glyphs
.find(GlyphID);
134
if
( GlyphIt != this->
Glyphs
.end() )
return
(*GlyphIt).second;
135
else
return
NULL;
136
}
137
138
///////////////////////////////////////////////////////////////////////////////
139
// Internal Methods
140
141
void
FontData::_SetSpaceLength
(
const
Real
SL)
142
{ this->
SpaceLength
= SL; }
143
144
void
FontData::_SetLineHeight
(
const
Real
LH)
145
{ this->
LineHeight
= LH; }
146
147
void
FontData::_SetBaseLine
(
const
Real
BL)
148
{ this->
BaseLine
= BL; }
149
150
void
FontData::_SetLetterSpacing
(
const
Real
LS)
151
{ this->
LetterSpacing
= LS; }
152
153
void
FontData::_SetName
(
const
String
& Name)
154
{ this->
FontName
= Name; }
155
156
void
FontData::_AddGlyph
(
Glyph
* NewGlyph)
157
{
158
GlyphIterator GlyphIt = this->
Glyphs
.find(NewGlyph->
GlyphID
);
159
if
( GlyphIt == this->
Glyphs
.end() ) { this->
Glyphs
.insert(std::pair<UInt32,Glyph*>(NewGlyph->
GlyphID
,NewGlyph)); }
160
else
161
{
162
StringStream
ExceptionStream;
163
ExceptionStream <<
"Glyph of ID: "
<< NewGlyph->
GlyphID
<<
" already exists in Font: \""
<< this->
FontName
<<
"\"."
;
164
MEZZ_EXCEPTION(
Exception::II_DUPLICATE_IDENTITY_EXCEPTION
,ExceptionStream.str());
165
}
166
}
167
}
//UI
168
}
//Mezzanine
169
170
#endif
Generated on Mon Jan 6 2014 20:58:06 for MezzanineEngine by
1.8.4