aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Font/TTF.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics/Font/TTF.cpp')
-rw-r--r--src/libjin/Graphics/Font/TTF.cpp45
1 files changed, 10 insertions, 35 deletions
diff --git a/src/libjin/Graphics/Font/TTF.cpp b/src/libjin/Graphics/Font/TTF.cpp
index 5c77e7f..ff4dcc7 100644
--- a/src/libjin/Graphics/Font/TTF.cpp
+++ b/src/libjin/Graphics/Font/TTF.cpp
@@ -55,12 +55,12 @@ namespace graphics
free(raw.data);
}
- TTF* TTFData::createTTF(unsigned ttfsize)
+ TTF* TTFData::createTTF(unsigned fontSize)
{
TTF* ttf;
try
{
- ttf = new TTF(this, ttfsize);
+ ttf = new TTF(this, fontSize);
}
catch (...)
{
@@ -150,31 +150,6 @@ namespace graphics
const int TTF::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
const int TTF::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
- /* utf8 byte string to unicode codepoint */
- static const char* utf8toCodepoint(const char *p, Codepoint *res) {
- unsigned x, mask, shift;
- switch (*p & 0xf0) {
- case 0xf0: mask = 0x07; shift = 18; break;
- case 0xe0: mask = 0x0f; shift = 12; break;
- case 0xc0:
- case 0xd0: mask = 0x1f; shift = 6; break;
- default:
- *res = *p;
- return p + 1;
- }
- x = (*p & mask) << shift;
- do {
- if (*(++p) == '\0') {
- *res = x;
- return p;
- }
- shift -= 6;
- x |= (*p & 0x3f) << shift;
- } while (shift);
- *res = x;
- return p + 1;
- }
-
/* little endian unicode */
static const char* unicodeLittleEndian(const char* p, unsigned* res)
{
@@ -195,11 +170,11 @@ namespace graphics
}
TTF::TTF(TTFData* f, unsigned int fontSize)
- : cursor(0, 0)
+ : Font(fontSize)
+ , cursor(0, 0)
, ttf(f)
- , ttfsize(fontSize)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
ttf->getVMetrics(&baseline, &descent);
estimateSize();
ttf->popTTFsize();
@@ -341,7 +316,7 @@ namespace graphics
int TTF::getCharWidth(int c)
{
int adw, lsb;
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
ttf->getHMetrics(c, &adw, &lsb);
ttf->popTTFsize();
return adw;
@@ -354,7 +329,7 @@ namespace graphics
int TTF::getTextWidth(const Content& t, int spacing)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
int res = 0;
int tmp = 0;
for (Codepoint c : t)
@@ -376,7 +351,7 @@ namespace graphics
int TTF::getTextHeight(const Content& t, int lineheight)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
int res = 0;
bool newline = true;
for (Codepoint c : t)
@@ -396,7 +371,7 @@ namespace graphics
void TTF::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing)
{
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
*w = 0;
*h = 0;
int tmp = 0;
@@ -426,7 +401,7 @@ namespace graphics
TTF::TTFGlyph& TTF::bakeGlyph(unsigned int character)
{
int w, h, xoff, yoff;
- ttf->pushTTFsize(ttfsize);
+ ttf->pushTTFsize(fontSize);
GLuint atlas = atlases.back();
const Color* bitmap = ttf->getCodepointBitmap(character, &w, &h, &xoff, &yoff);
int adw, lsb;