2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-08-28 00:08:30 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
#include "Font.h"
|
|
|
|
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/graphics/unifont.h"
|
2004-08-28 00:08:30 +02:00
|
|
|
|
2010-07-04 12:15:53 +02:00
|
|
|
#include "ps/ConfigDB.h"
|
|
|
|
#include "ps/Filesystem.h"
|
2004-08-28 00:08:30 +02:00
|
|
|
#include "ps/CLogger.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2010-05-30 15:42:56 +02:00
|
|
|
const wchar_t* DefaultFont = L"sans-10";
|
2004-08-28 00:08:30 +02:00
|
|
|
|
2011-02-17 21:08:20 +01:00
|
|
|
CFont::CFont(const CStrW& name)
|
2004-08-28 00:08:30 +02:00
|
|
|
{
|
2012-01-29 21:04:21 +01:00
|
|
|
h = unifont_load(g_VFS, name);
|
2004-08-28 00:08:30 +02:00
|
|
|
|
2012-01-29 21:04:21 +01:00
|
|
|
// Found it
|
|
|
|
if (h > 0)
|
|
|
|
return;
|
2004-08-28 00:08:30 +02:00
|
|
|
|
2012-01-29 21:04:21 +01:00
|
|
|
// Not found as a font -- give up and use the default.
|
|
|
|
LOGERROR(L"Failed to find font '%ls'", name.c_str());
|
|
|
|
h = unifont_load(g_VFS, DefaultFont);
|
|
|
|
// Assume this worked
|
2004-08-28 00:08:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CFont::~CFont()
|
|
|
|
{
|
|
|
|
unifont_unload(h);
|
|
|
|
}
|
|
|
|
|
2012-01-30 01:27:23 +01:00
|
|
|
bool CFont::HasRGB()
|
|
|
|
{
|
|
|
|
return unifont_has_rgb(h);
|
2004-08-28 00:08:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CFont::GetLineSpacing()
|
|
|
|
{
|
|
|
|
return unifont_linespacing(h);
|
|
|
|
}
|
|
|
|
|
2004-10-14 12:10:43 +02:00
|
|
|
int CFont::GetHeight()
|
|
|
|
{
|
|
|
|
return unifont_height(h);
|
|
|
|
}
|
|
|
|
|
2005-12-12 20:19:30 +01:00
|
|
|
int CFont::GetCharacterWidth(wchar_t c)
|
2004-11-25 00:47:48 +01:00
|
|
|
{
|
|
|
|
return unifont_character_width(h, c);
|
|
|
|
}
|
|
|
|
|
2012-02-25 18:14:47 +01:00
|
|
|
void CFont::CalculateStringSize(const wchar_t* string, int& width, int& height)
|
2004-08-28 00:08:30 +02:00
|
|
|
{
|
2012-02-25 18:14:47 +01:00
|
|
|
unifont_stringsize(h, string, width, height);
|
2004-09-06 13:18:22 +02:00
|
|
|
}
|
2012-02-15 22:53:13 +01:00
|
|
|
|
|
|
|
const std::map<u16, UnifontGlyphData>& CFont::GetGlyphs()
|
|
|
|
{
|
|
|
|
return unifont_get_glyphs(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle CFont::GetTexture()
|
|
|
|
{
|
|
|
|
return unifont_get_texture(h);
|
2012-06-13 22:43:56 +02:00
|
|
|
}
|