mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-13 06:21:29 -10:00
This allows to use standard TrueType Fonts for text rendering in FSO. It uses the NanoVG library which provides the ability of drawing 2D shapes. This library is used for most 2D operations now and can also be used directly by using the PathRenderer class.
69 lines
1.4 KiB
C++
69 lines
1.4 KiB
C++
#include "graphics/software/FSFont.h"
|
|
|
|
namespace font
|
|
{
|
|
FSFont::FSFont() : name(SCP_string("<Invalid>")), offsetTop(0.0f), offsetBottom(0.0f)
|
|
{
|
|
}
|
|
|
|
FSFont::~FSFont()
|
|
{
|
|
}
|
|
|
|
void FSFont::setBottomOffset(float offset)
|
|
{
|
|
Assertion(offset >= 0.0f, "Bottom offset for font %s has to be larger than zero but it is %f",
|
|
this->getName().c_str(), offset);
|
|
|
|
this->offsetBottom = offset;
|
|
}
|
|
|
|
void FSFont::setTopOffset(float offset)
|
|
{
|
|
Assertion(offset >= 0.0f, "Top offset for font %s has to be larger than zero but it is %f",
|
|
this->getName().c_str(), offset);
|
|
|
|
this->offsetTop = offset;
|
|
}
|
|
|
|
void FSFont::setName(const SCP_string &newName)
|
|
{
|
|
this->name = newName;
|
|
}
|
|
|
|
float FSFont::getBottomOffset() const
|
|
{
|
|
return this->offsetBottom;
|
|
}
|
|
|
|
float FSFont::getTopOffset() const
|
|
{
|
|
return this->offsetTop;
|
|
}
|
|
|
|
float FSFont::getHeight() const
|
|
{
|
|
#ifndef NDEBUG
|
|
if (!heightChecked)
|
|
{
|
|
float height = this->getTextHeight() + this->offsetTop + this->offsetBottom;
|
|
|
|
if (height <= 0.0f)
|
|
{
|
|
Warning(LOCATION, "The height of font %s has an invalid height of %f, must be greater than zero!",
|
|
getName().c_str(), height);
|
|
}
|
|
|
|
// HACK: This function is const but to disable the warning in the future we need to change a variable
|
|
const_cast<FSFont *>(this)->heightChecked = true;
|
|
}
|
|
#endif
|
|
return this->getTextHeight() + this->offsetTop + this->offsetBottom;
|
|
}
|
|
|
|
const SCP_string &FSFont::getName() const
|
|
{
|
|
return this->name;
|
|
}
|
|
}
|