1 #pragma once
2 
3 #include "globalincs/pstypes.h"
4 
5 #include "graphics/software/FSFont.h"
6 #include "graphics/software/FontManager.h"
7 
8 namespace font
9 {
10 	const int FONT1 = 0;	//<! The first loaded font. Used to be hardcoded to reference font01.vf in retail
11 	const int FONT2 = 1;	//<! The second loaded font. Used to be hardcoded to reference font02.vf in retail
12 	const int FONT3 = 2;	//<! The third loaded font. Used to be hardcoded to reference font03.vf in retail
13 
14 	struct font;
15 
16 	/**
17 	* @brief Parses the first font name
18 	*
19 	* Parses the first font name in the font table and stuffs it into @c firstFont
20 	*
21 	* @param firstFont The SCP_string which should contain the name
22 	*/
23 	void stuff_first(SCP_string &firstFont);
24 
25 	/**
26 	* Crops a string if required to force it to not exceed max_width pixels when printed.
27 	* Does this by dropping characters at the end of the string and adding '...' to the end.
28 	*
29 	* @param str		string to crop.  Modifies this string directly
30 	* @param max_str	max characters allowed in str
31 	* @param max_width number of pixels to limit string to (less than or equal to).
32 	* @return			The width of the string
33 	*/
34 	int force_fit_string(char *str, int max_str, int max_width);
35 
36 	/**
37 	* @brief Inites the font system
38 	*
39 	* Initializes the font system by setting up the FontManager, parse the font table(s) and
40 	* set the current font id to 0.
41 	*/
42 	void init();
43 
44 	/**
45 	* @brief Closes the Font system
46 	*
47 	* Deallocates all allocated memory for the fonts and the respective font data.
48 	*/
49 	void close();
50 
51 	/**
52 	* Retrieves the font which is located at index @c font_num and sets this font
53 	* as the current font
54 	* @param font_num The new font number, may not be an illegal font number
55 	*/
set_font(int fontnum)56 	inline void set_font(int fontnum)
57 	{
58 		FontManager::setCurrentFont(FontManager::getFont(fontnum));
59 	}
60 
61 	/**
62 	* @brief Parses a font number
63 	*
64 	* Parses a font using either the font name or the font index and returns the font index
65 	* If the font could not be parsed because of a syntax error, -1 is returned instead
66 	*
67 	* @return The font index or -1 on error
68 	*/
69 	int parse_font();
70 
71 	/**
72 	* @brief The currently active font index
73 	* @return The font index or -1 when the FontManager hasnt't been initialized yet
74 	*/
get_current_fontnum()75 	inline int get_current_fontnum()
76 	{
77 		return FontManager::getCurrentFontIndex();
78 	}
79 
80 	/**
81 	* @brief The current font object
82 	*
83 	* @return The current font object or NULL when not yet ready
84 	*/
85 	FSFont *get_current_font();
86 
87 	/**
88 	* @brief Retrieves a font by index
89 	*
90 	* Gets a font by index into the internal font vector
91 	*
92 	* @param fontNum The index which should be returned
93 	* @return A font pointer or NULL of the index is not valid
94 	*/
get_font(int fontNum)95 	inline FSFont *get_font(int fontNum)
96 	{
97 		return FontManager::getFont(fontNum);
98 	}
99 
100 	/**
101 	* @brief Retrieves a font by name
102 	*
103 	* @param name The name which should be searched
104 	* @return The font pointer or NULL if no font with that name could be found
105 	*/
106 	FSFont *get_font(const SCP_string& name);
107 
108 	/**
109 	* @brief Retrieves a font by filename
110 	*
111 	* @param filename The filename which should be searched
112 	* @return The font pointer or nullptr if no font with that filename could be found
113 	*/
114 	FSFont *get_font_by_filename(const SCP_string& filename);
115 }
116