1/*
2 * LegacyClonk
3 *
4 * Copyright (c) RedWolf Design
5 * Copyright (c) 2004, Sven2
6 * Copyright (c) 2017-2020, The LegacyClonk Team and contributors
7 *
8 * Distributed under the terms of the ISC license; see accompanying file
9 * "COPYING" for details.
10 *
11 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12 * See accompanying file "TRADEMARK" for details.
13 *
14 * To redistribute this file separately, substitute the full license texts
15 * for the above references.
16 */
17
18// engine font loading
19
20#pragma once
21
22#include "C4ForwardDeclarations.h"
23#include "StdBuf.h"
24#include "StdFile.h"
25
26#include <vector>
27
28class C4Group;
29class C4GroupSet;
30class C4Config;
31class CStdFont;
32
33// font definition to be read
34class C4FontDef
35{
36public:
37 StdStrBuf Name; // font name
38 int32_t iSize; // average font height of base font
39 StdStrBuf LogFont; // very small font used for log messages
40 StdStrBuf SmallFont; // pretty small font used in tiny dialogs
41 StdStrBuf Font; // base font used for anything
42 StdStrBuf CaptionFont; // caption font used in GUI
43 StdStrBuf TitleFont; // font used to draw the loader caption
44
45 C4FontDef() : iSize(0) {}
46 void CompileFunc(StdCompiler *pComp);
47};
48
49// holder class for loaded ttf fonts
50class C4VectorFont
51{
52protected:
53 StdStrBuf Name;
54 StdBuf Data;
55 CStdVectorFont *pFont;
56 char FileName[_MAX_PATH + 1]; // file name of temprarily extracted file
57 bool fIsTempFile; // if set, the file resides at the temp path and is to be deleted
58
59public:
60 C4VectorFont *pNext; // next font
61
62 C4VectorFont() : pFont(nullptr), fIsTempFile(false), pNext(nullptr) { *FileName = 0; }
63 ~C4VectorFont(); // dtor - releases font and deletes temp file
64
65 bool Init(C4Group &hGrp, const char *szFilename, C4Config &rCfg); // load font from group
66 bool Init(const char *szFacename, int32_t iSize, uint32_t dwWeight, const char *szCharSet); // load system font specified by face name
67
68 friend class C4FontLoader;
69};
70
71// font loader
72class C4FontLoader
73{
74protected:
75 std::vector<C4FontDef> FontDefs; // array of loaded font definitions
76 C4VectorFont *pVectorFonts; // vector fonts loaded and extracted to temp store
77
78public:
79 // enum of different fonts used in the clonk engine
80 enum FontType { C4FT_Log, C4FT_MainSmall, C4FT_Main, C4FT_Caption, C4FT_Title };
81
82public:
83 C4FontLoader() : pVectorFonts(nullptr) {}
84 ~C4FontLoader() { Clear(); }
85
86 void Clear(); // clear loaded fonts
87 size_t LoadDefs(C4Group &hGroup, C4Config &rCfg); // load font definitions from group file; return number of loaded font defs
88 void AddVectorFont(C4VectorFont *pAddFont); // adds a new font to the list
89
90 bool InitFont(CStdFont &rFont, C4VectorFont *pFont, int32_t iSize, uint32_t dwWeight, bool fDoShadow);
91 // init a font class of the given type
92 // iSize is always the size of the normal font, which is adjusted for larger (title) and smaller (log) font types
93 bool InitFont(CStdFont &rFont, const char *szFontName, FontType eType, int32_t iSize, C4GroupSet *pGfxGroups, bool fDoShadow = true);
94};
95