1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#pragma once
#include "globalincs/pstypes.h"
#include "graphics/2d.h"
#include <limits>
namespace font
{
/**
* @brief Enum to specify the type of a font
*
* Specifies the type of a font object and can be used to implement font specific behavior
*/
enum FontType
{
VFNT_FONT, //!< A normal FreeSpace font
NVG_FONT, //!< A TrueType font as used by the NanoVG library
UNKNOWN_FONT, //!< An unknown font type. Probably means that an error happened
};
/**
* @brief Abstract font class.
*
* An abstract class which is the superclass of every font class
*
* @author m!m
* @date 23.11.2011
*/
class FSFont
{
private:
SCP_string name; //!< The name of this font
SCP_string filename; //!< The file name used to retrieve this font
protected:
float offsetTop; //!< The offset at the top of a line of text
float offsetBottom; //!< The offset at the bottom of a line of text
float _height;
float _ascender;
float _descender;
void checkFontMetrics();
public:
/**
* @brief Default constructor.
*
* @date 23.11.2011
*/
FSFont();
/**
* @brief Destructor.
*
* @date 23.11.2011
*/
virtual ~FSFont();
/**
* @brief Sets the name of this font.
*
* @date 23.11.2011
*
* @param newName The new name.
*/
void setName(const SCP_string& newName);
/**
* @brief Sets the filename of this font.
*
* @date 9.9.2020
*
* @param newName The new filename.
*/
void setFilename(const SCP_string& newName);
/**
* @brief Gets the name of this font.
*
* @date 23.11.2011
*
* @return The name.
*/
const SCP_string& getName() const;
/**
* @brief Gets the filename of this font.
*
* @date 9.9.2020
*
* @return The name.
*/
const SCP_string& getFilename() const;
/**
* @brief Gets the type of this font.
*
* The return value depends on the implementing subclass.
*
* @date 23.11.2011
*
* @return The type.
*
* @see FontType::VFNT_FONT
* @see FontType::FTGL_FONT
*/
virtual FontType getType() const = 0;
/**
* @brief Gets the height of this font in pixels with regard to font top and bottom offsets.
*
* @date 23.11.2011
*
* @return The height.
*/
float getHeight() const;
/**
* @brief Gets the height of this font in pixels without the top and bottom offsets.
*
* @date 29.1.2012
*
* @return The height.
*/
virtual float getTextHeight() const = 0;
/**
* @brief Gets a string size.
* Computes the size of the given string when it would be drawn by this font
*
* @date 23.11.2011
*
* @param [in] text If non-null, the text.
* @param textLen Length of the text. Use -1 if the string should be checked until the next \0 character.
* @param [out] width If non-null, the width.
* @param [out] height If non-null, the height.
*/
virtual void getStringSize(const char *text, size_t textLen = std::numeric_limits<size_t>::max(),
int resize_mode = -1, float *width = NULL, float *height = NULL) const = 0;
/**
* @brief Gets the offset of this font from the top of the drawing line
*
* @date 27.11.2012
*
* @return The top offset.
*/
float getTopOffset() const;
/**
* @brief Gets the offset of this font from the bottom of the end of the text to where the next line will start.
*
* @date 27.1.2012
*
* @return The bottom offset.
*/
float getBottomOffset() const;
/**
* @brief Sets the top offset for this font
*
* @date 27.1.2012
*
* @param newOffset The new top offset for this font
*/
void setTopOffset(float newOffset);
/**
* @brief Sets the bottom offset for this font
*
* @date 27.1.2012
*
* @param newOffset The new bottom offset for this font
*/
void setBottomOffset(float newOffset);
/**
* @brief Recomputes the font metrics
*/
virtual void computeFontMetrics();
/**
* @brief Gets the ascender value of this font
* @return The ascender value
*/
float getAscender();
/**
* @breif Gets the descender value of this font
* @return The descender value
*/
float getDescender();
};
}
|