Line data Source code
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 : #include "precompiled.h"
19 : #include "FontMetrics.h"
20 :
21 : #include "graphics/Font.h"
22 : #include "graphics/FontManager.h"
23 : #include "ps/Filesystem.h"
24 : #include "ps/CLogger.h"
25 : #include "renderer/Renderer.h"
26 :
27 3083 : CFontMetrics::CFontMetrics(CStrIntern font)
28 : {
29 3083 : m_Font = g_Renderer.GetFontManager().LoadFont(font);
30 3083 : }
31 :
32 748 : int CFontMetrics::GetLineSpacing() const
33 : {
34 : // Return some arbitrary default if the font failed to load, so that the
35 : // user of CFontMetrics doesn't have to care about failures
36 748 : if (!m_Font)
37 0 : return 12;
38 748 : return m_Font->GetLineSpacing();
39 : }
40 :
41 1189 : int CFontMetrics::GetHeight() const
42 : {
43 1189 : if (!m_Font)
44 0 : return 6;
45 1189 : return m_Font->GetHeight();
46 : }
47 :
48 1148 : int CFontMetrics::GetCharacterWidth(wchar_t c) const
49 : {
50 1148 : if (!m_Font)
51 0 : return 6;
52 1148 : return m_Font->GetCharacterWidth(c);
53 : }
54 :
55 1937 : void CFontMetrics::CalculateStringSize(const wchar_t* string, int& w, int& h) const
56 : {
57 1937 : if (!m_Font)
58 0 : w = h = 0;
59 : else
60 1937 : m_Font->CalculateStringSize(string, w, h);
61 1940 : }
|