2025-05-16 16:02:40 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2013-10-18 08:53:07 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2013-10-18 08:53:07 -07:00
|
|
|
* 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.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2013-10-18 08:53:07 -07:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2013-10-18 08:53:07 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
|
2013-10-18 08:53:07 -07:00
|
|
|
#include "FontMetrics.h"
|
|
|
|
|
|
|
|
|
|
#include "graphics/Font.h"
|
|
|
|
|
#include "graphics/FontManager.h"
|
2025-07-06 11:15:27 -07:00
|
|
|
#include "ps/CStrIntern.h"
|
2013-10-18 08:53:07 -07:00
|
|
|
#include "renderer/Renderer.h"
|
|
|
|
|
|
2013-10-18 09:15:42 -07:00
|
|
|
CFontMetrics::CFontMetrics(CStrIntern font)
|
2025-07-02 06:43:04 -07:00
|
|
|
: CFontMetrics(font, CStrIntern())
|
2013-10-18 08:53:07 -07:00
|
|
|
{
|
2025-07-02 06:43:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CFontMetrics::CFontMetrics(CStrIntern font, CStrIntern locale)
|
|
|
|
|
{
|
|
|
|
|
m_Font = g_Renderer.GetFontManager().LoadFont(font, locale);
|
2013-10-18 08:53:07 -07:00
|
|
|
}
|
|
|
|
|
|
2025-05-16 16:02:40 -07:00
|
|
|
float CFontMetrics::GetHeight() const
|
2013-10-18 08:53:07 -07:00
|
|
|
{
|
|
|
|
|
if (!m_Font)
|
|
|
|
|
return 6;
|
|
|
|
|
return m_Font->GetHeight();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-16 16:02:40 -07:00
|
|
|
float CFontMetrics::GetCharacterWidth(wchar_t c) const
|
2013-10-18 08:53:07 -07:00
|
|
|
{
|
|
|
|
|
if (!m_Font)
|
|
|
|
|
return 6;
|
|
|
|
|
return m_Font->GetCharacterWidth(c);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-16 16:02:40 -07:00
|
|
|
void CFontMetrics::CalculateStringSize(const wchar_t* string, float& w, float& h) const
|
2013-10-18 08:53:07 -07:00
|
|
|
{
|
|
|
|
|
if (!m_Font)
|
|
|
|
|
w = h = 0;
|
|
|
|
|
else
|
|
|
|
|
m_Font->CalculateStringSize(string, w, h);
|
|
|
|
|
}
|
2025-05-28 20:37:37 -07:00
|
|
|
|
2025-11-03 10:12:21 -08:00
|
|
|
float CFontMetrics::GetCapHeight() const
|
2025-05-28 20:37:37 -07:00
|
|
|
{
|
|
|
|
|
if (!m_Font)
|
|
|
|
|
return 0.0f;
|
|
|
|
|
return m_Font->GetCapHeight();
|
|
|
|
|
}
|