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
|
#include "graphics/software/VFNTFont.h"
#include "graphics/software/font_internal.h"
namespace font
{
VFNTFont::VFNTFont(font *fnt) : FSFont()
{
Assertion(fnt != NULL, "Invalid font passed to constructor of VFNTFont!");
this->fontPtr = fnt;
setName(SCP_string(fnt->filename));
}
VFNTFont::~VFNTFont()
{
}
FontType VFNTFont::getType() const
{
return VFNT_FONT;
}
float VFNTFont::getTextHeight() const
{
return i2fl(fontPtr->h);
}
font *VFNTFont::getFontData()
{
return this->fontPtr;
}
extern int get_char_width_old(font* fnt, ubyte c1, ubyte c2, int *width, int* spacing);
void VFNTFont::getStringSize(const char *text, size_t textSize, int /* resize_mode */, float *w1, float *h1) const
{
int longest_width;
int width, spacing;
int w, h;
w = 0;
h = text == nullptr ? 0 : fl2i(this->getHeight());
longest_width = 0;
// Maintain old behavior where textLen was an int
int textLen = static_cast<int>(textSize);
bool checkLength = textLen >= 0;
if (text != nullptr && textLen != 0)
{
while (*text)
{
// Process one or more
while (*text == '\n')
{
text++;
if (checkLength)
{
textLen--;
if (textLen <= 0)
break;
}
if (*text)
{
h += fl2i(this->getHeight());
}
w = 0;
}
if (*text == 0)
{
break;
}
get_char_width_old(fontPtr, text[0], text[1], &width, &spacing);
w += spacing;
if (w > longest_width)
longest_width = w;
text++;
if (checkLength)
{
textLen--;
if (textLen <= 0)
break;
}
}
}
if (h1)
*h1 = i2fl(h);
if (w1)
*w1 = i2fl(longest_width);
}
font::font() : kern_data(NULL),
char_data(NULL),
pixel_data(NULL),
bm_data(NULL),
bm_u(NULL),
bm_v(NULL)
{
}
font::~font()
{
if (this->kern_data) {
vm_free(this->kern_data);
this->kern_data = NULL;
}
if (this->char_data) {
vm_free(this->char_data);
this->char_data = NULL;
}
if (this->pixel_data) {
vm_free(this->pixel_data);
this->pixel_data = NULL;
}
if (this->bm_data) {
vm_free(this->bm_data);
this->bm_data = NULL;
}
if (this->bm_u) {
vm_free(this->bm_u);
this->bm_u = NULL;
}
if (this->bm_v) {
vm_free(this->bm_v);
this->bm_v = NULL;
}
}
}
|