Pyrogenesis
trunk
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
source
graphics
Font.h
Go to the documentation of this file.
1
/* Copyright (C) 2013 Wildfire Games.
2
* This file is part of 0 A.D.
3
*
4
* 0 A.D. 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 2 of the License, or
7
* (at your option) any later version.
8
*
9
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef INCLUDED_FONT
19
#define INCLUDED_FONT
20
21
#include "
graphics/Texture.h
"
22
#include "
lib/res/handle.h
"
23
24
#include <map>
25
26
class
CStrW;
27
struct
UnifontGlyphData;
28
29
/**
30
* Storage for a bitmap font. Loaded by CFontManager.
31
*/
32
class
CFont
33
{
34
friend
class
CFontManager
;
35
CFont
() {}
36
public
:
37
struct
GlyphData
38
{
39
float
u0
,
v0
,
u1
,
v1
;
40
i16
x0
,
y0
,
x1
,
y1
;
41
i16
xadvance
;
42
u8
defined
;
43
};
44
45
/**
46
* Relatively efficient lookup of GlyphData from 16-bit Unicode codepoint.
47
* This is stored as a sparse 2D array, exploiting the knowledge that a font
48
* typically only supports a small number of 256-codepoint blocks, so most
49
* elements of m_Data will be NULL.
50
*/
51
class
GlyphMap
52
{
53
NONCOPYABLE
(
GlyphMap
);
54
public
:
55
GlyphMap
();
56
~
GlyphMap
();
57
void
set
(
u16
i,
const
GlyphData
& val);
58
59
const
GlyphData
*
get
(
u16
i)
const
60
{
61
if
(!m_Data[i >> 8])
62
return
NULL;
63
if
(!m_Data[i >> 8][i & 0xff].
defined
)
64
return
NULL;
65
return
&m_Data[i >> 8][i & 0xff];
66
}
67
68
private
:
69
GlyphData
* m_Data[256];
70
};
71
72
bool
HasRGB
()
const
{
return
m_HasRGB
; }
73
int
GetLineSpacing
()
const
{
return
m_LineSpacing
; }
74
int
GetHeight
()
const
{
return
m_Height
; }
75
int
GetCharacterWidth
(
wchar_t
c)
const
;
76
void
CalculateStringSize
(
const
wchar_t
*
string
,
int
& w,
int
& h)
const
;
77
void
GetGlyphBounds
(
float
&
x0
,
float
&
y0
,
float
&
x1
,
float
&
y1
)
const
78
{
79
x0 =
m_BoundsX0
;
80
y0 =
m_BoundsY0
;
81
x1 =
m_BoundsX1
;
82
y1 =
m_BoundsY1
;
83
}
84
const
GlyphMap
&
GetGlyphs
()
const
{
return
m_Glyphs
; }
85
CTexturePtr
GetTexture
()
const
{
return
m_Texture
; }
86
87
private
:
88
CTexturePtr
m_Texture
;
89
90
bool
m_HasRGB
;
// true if RGBA, false if ALPHA
91
92
GlyphMap
m_Glyphs
;
93
94
int
m_LineSpacing
;
95
int
m_Height
;
// height of a capital letter, roughly
96
97
// Bounding box of all glyphs
98
float
m_BoundsX0
;
99
float
m_BoundsY0
;
100
float
m_BoundsX1
;
101
float
m_BoundsY1
;
102
};
103
104
#endif // INCLUDED_FONT
NONCOPYABLE
#define NONCOPYABLE(className)
Indicates that a class is noncopyable (usually due to const or reference members, or because the clas...
Definition:
code_annotation.h:217
CFont::GlyphData::defined
u8 defined
Definition:
Font.h:42
CFont::GlyphData::x0
i16 x0
Definition:
Font.h:40
CFont::GetLineSpacing
int GetLineSpacing() const
Definition:
Font.h:73
Texture.h
u16
uint16_t u16
Definition:
types.h:38
CFont::GetGlyphs
const GlyphMap & GetGlyphs() const
Definition:
Font.h:84
CFont::GlyphData::y0
i16 y0
Definition:
Font.h:40
CFont::GetGlyphBounds
void GetGlyphBounds(float &x0, float &y0, float &x1, float &y1) const
Definition:
Font.h:77
CFont::HasRGB
bool HasRGB() const
Definition:
Font.h:72
u8
uint8_t u8
Definition:
types.h:37
CFont::GlyphData::x1
i16 x1
Definition:
Font.h:40
CFont::GetTexture
CTexturePtr GetTexture() const
Definition:
Font.h:85
handle.h
CFont::GlyphMap
Relatively efficient lookup of GlyphData from 16-bit Unicode codepoint.
Definition:
Font.h:51
CFont::GlyphData::u0
float u0
Definition:
Font.h:39
CFont::GlyphData::y1
i16 y1
Definition:
Font.h:40
CFont
Storage for a bitmap font.
Definition:
Font.h:32
CFont::m_BoundsX0
float m_BoundsX0
Definition:
Font.h:98
CFont::CalculateStringSize
void CalculateStringSize(const wchar_t *string, int &w, int &h) const
Definition:
Font.cpp:61
CFont::GlyphData::xadvance
i16 xadvance
Definition:
Font.h:41
CFont::m_HasRGB
bool m_HasRGB
Definition:
Font.h:90
CFont::m_Texture
CTexturePtr m_Texture
Definition:
Font.h:88
CFont::m_BoundsY0
float m_BoundsY0
Definition:
Font.h:99
CFontManager
Font manager: loads and caches bitmap fonts.
Definition:
FontManager.h:29
CFont::GlyphData::u1
float u1
Definition:
Font.h:39
CFont::GetHeight
int GetHeight() const
Definition:
Font.h:74
CFont::GlyphData::v1
float v1
Definition:
Font.h:39
CFont::m_Height
int m_Height
Definition:
Font.h:95
CFont::m_BoundsY1
float m_BoundsY1
Definition:
Font.h:101
CFont::GlyphData::v0
float v0
Definition:
Font.h:39
CFont::GlyphData
Definition:
Font.h:37
CFont::m_Glyphs
GlyphMap m_Glyphs
Definition:
Font.h:92
CTexturePtr
std::shared_ptr< CTexture > CTexturePtr
Definition:
Texture.h:22
CFont::m_BoundsX1
float m_BoundsX1
Definition:
Font.h:100
i16
int16_t i16
Definition:
types.h:33
CFont::GetCharacterWidth
int GetCharacterWidth(wchar_t c) const
Definition:
Font.cpp:48
CFont::m_LineSpacing
int m_LineSpacing
Definition:
Font.h:94
CFont::CFont
CFont()
Definition:
Font.h:35
Generated by
1.8.11