Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Font.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 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 "Font.h"
20 
22 
23 #include "ps/Filesystem.h"
24 #include "ps/CLogger.h"
25 
26 #include <map>
27 #include <string>
28 
29 const wchar_t* DefaultFont = L"sans-10";
30 
31 CFont::CFont(const CStrW& name)
32 {
33  h = unifont_load(g_VFS, name);
34 
35  // Found it
36  if (h > 0)
37  return;
38 
39  // Not found as a font -- give up and use the default.
40  LOGERROR(L"Failed to find font '%ls'", name.c_str());
42  // Assume this worked
43 }
44 
46 {
48 }
49 
51 {
52  return unifont_has_rgb(h);
53 }
54 
56 {
57  return unifont_linespacing(h);
58 }
59 
61 {
62  return unifont_height(h);
63 }
64 
66 {
67  return unifont_character_width(h, c);
68 }
69 
70 void CFont::CalculateStringSize(const wchar_t* string, int& width, int& height)
71 {
72  unifont_stringsize(h, string, width, height);
73 }
74 
75 const std::map<u16, UnifontGlyphData>& CFont::GetGlyphs()
76 {
77  return unifont_get_glyphs(h);
78 }
79 
81 {
82  return unifont_get_texture(h);
83 }
int GetLineSpacing()
Definition: Font.cpp:55
bool unifont_has_rgb(const Handle h)
Definition: unifont.cpp:228
const glyphmap & unifont_get_glyphs(const Handle h)
Definition: unifont.cpp:276
void CalculateStringSize(const wchar_t *string, int &w, int &h)
Definition: Font.cpp:70
#define LOGERROR
Definition: CLogger.h:35
CFont(const CStrW &name)
Definition: Font.cpp:31
int unifont_linespacing(const Handle h)
Definition: unifont.cpp:214
Handle h
Definition: Font.h:43
int GetCharacterWidth(wchar_t c)
Definition: Font.cpp:65
int unifont_character_width(const Handle h, wchar_t c)
Definition: unifont.cpp:237
Status unifont_stringsize(const Handle h, const wchar_t *text, int &width, int &height)
Determine pixel extents of a string.
Definition: unifont.cpp:248
Handle GetTexture()
Definition: Font.cpp:80
int GetHeight()
Definition: Font.cpp:60
i64 Handle
`handle&#39; representing a reference to a resource (sound, texture, etc.)
Definition: handle.h:41
Handle unifont_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load a font.
Definition: unifont.cpp:201
int unifont_height(const Handle h)
Definition: unifont.cpp:221
const std::map< u16, UnifontGlyphData > & GetGlyphs()
Definition: Font.cpp:75
Status unifont_unload(Handle &h)
Release a handle to a previously loaded font (subject to reference counting).
Definition: unifont.cpp:207
const wchar_t * DefaultFont
Definition: Font.cpp:29
Handle unifont_get_texture(const Handle h)
Definition: unifont.cpp:289
~CFont()
Definition: Font.cpp:45
PIVFS g_VFS
Definition: Filesystem.cpp:30
bool HasRGB()
Definition: Font.cpp:50