LCOV - code coverage report
Current view: top level - source/graphics - FontMetrics.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 19 20 95.0 %
Date: 2026-12-03 01:19:39 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : 
      20             : #include "FontMetrics.h"
      21             : 
      22             : #include "graphics/Font.h"
      23             : #include "graphics/FontManager.h"
      24             : #include "ps/CStrIntern.h"
      25             : #include "renderer/Renderer.h"
      26             : 
      27         974 : CFontMetrics::CFontMetrics(CStrIntern font)
      28         974 :     : CFontMetrics(font, CStrIntern())
      29             : {
      30         974 : }
      31             : 
      32        2642 : CFontMetrics::CFontMetrics(CStrIntern font, CStrIntern locale)
      33             : {
      34        2642 :     m_Font = g_Renderer.GetFontManager().LoadFont(font, locale);
      35        2642 : }
      36             : 
      37         647 : float CFontMetrics::GetHeight() const
      38             : {
      39         647 :     if (!m_Font)
      40             :         return 6;
      41         647 :     return m_Font->GetHeight();
      42             : }
      43             : 
      44         970 : float CFontMetrics::GetCharacterWidth(wchar_t c) const
      45             : {
      46         970 :     if (!m_Font)
      47             :         return 6;
      48         970 :     return m_Font->GetCharacterWidth(c);
      49             : }
      50             : 
      51        1670 : void CFontMetrics::CalculateStringSize(const wchar_t* string, float& w, float& h) const
      52             : {
      53        1670 :     if (!m_Font)
      54           0 :         w = h = 0;
      55             :     else
      56        1670 :         m_Font->CalculateStringSize(string, w, h);
      57        1670 : }
      58             : 
      59        1031 : float CFontMetrics::GetCapHeight() const
      60             : {
      61        1031 :     if (!m_Font)
      62             :         return 0.0f;
      63        1031 :     return m_Font->GetCapHeight();
      64             : }

Generated by: LCOV version 1.16