1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #include "precompiled.h"
21 #include "graphics/FontManager.h"
22 #include "ps/Filesystem.h"
23 #include "ps/CLogger.h"
24 #include "renderer/Renderer.h"
29 CFont::GlyphMap::GlyphMap()
31 memset(m_Data
, 0, sizeof(m_Data
));
34 CFont::GlyphMap::~GlyphMap()
36 for (size_t i
= 0; i
< ARRAY_SIZE(m_Data
); i
++)
40 void CFont::GlyphMap::set(u16 i
, const GlyphData
& val
)
43 m_Data
[i
>> 8] = new GlyphData
[256]();
44 m_Data
[i
>> 8][i
& 0xff] = val
;
45 m_Data
[i
>> 8][i
& 0xff].defined
= 1;
48 int CFont::GetCharacterWidth(wchar_t c
) const
50 const GlyphData
* g
= m_Glyphs
.get(c
);
53 g
= m_Glyphs
.get(0xFFFD); // Use the missing glyph symbol
61 void CFont::CalculateStringSize(const wchar_t* string
, int& width
, int& height
) const
66 // Compute the width as the width of the longest line.
68 for (const wchar_t* c
= string
; *c
!= '\0'; c
++)
70 const GlyphData
* g
= m_Glyphs
.get(*c
);
73 g
= m_Glyphs
.get(0xFFFD); // Use the missing glyph symbol
76 lineWidth
+= g
->xadvance
; // Add the character's advance distance
80 height
+= m_LineSpacing
;
81 width
= std::max(width
, lineWidth
);
85 width
= std::max(width
, lineWidth
);