mirror of
https://github.com/Relintai/sfw.git
synced 2024-12-20 21:06:49 +01:00
Removed stbi include from font.h.
This commit is contained in:
parent
98822c4b5a
commit
6dd8f13545
@ -165,7 +165,7 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
unsigned char *bitmap = (unsigned char *)bitmap_data.ptrw();
|
||||
|
||||
int charCount = sorted[sorted.size() - 1] - sorted[0] + 1; // 0xEFFFF;
|
||||
_cdata = (stbtt_packedchar *)calloc(1, sizeof(stbtt_packedchar) * charCount);
|
||||
stbtt_packedchar *cdata = memnew_arr(stbtt_packedchar, charCount);
|
||||
_iter2cp = memnew_arr(unsigned int, charCount);
|
||||
_cp2iter = memnew_arr(unsigned int, charCount);
|
||||
for (int i = 0; i < charCount; ++i) {
|
||||
@ -179,8 +179,10 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
|
||||
for (int i = 0, end = sorted.size() - 1; i < end; ++i) {
|
||||
unsigned glyph = sorted[i];
|
||||
if (!stbtt_FindGlyphIndex(&info, glyph))
|
||||
if (!stbtt_FindGlyphIndex(&info, glyph)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
_begin = glyph;
|
||||
break;
|
||||
}
|
||||
@ -198,10 +200,11 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
end = sorted[++i];
|
||||
}
|
||||
|
||||
if (begin < _begin)
|
||||
if (begin < _begin) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stbtt_PackFontRange(&pc, (const unsigned char *)ttf_data, 0, _font_size, begin, end - begin + 1, (stbtt_packedchar *)_cdata + begin - _begin)) {
|
||||
if (stbtt_PackFontRange(&pc, (const unsigned char *)ttf_data, 0, _font_size, begin, end - begin + 1, cdata + begin - _begin)) {
|
||||
for (uint64_t cp = begin; cp <= end; ++cp) {
|
||||
// unicode->index runtime lookup
|
||||
_cp2iter[cp - _begin] = count;
|
||||
@ -211,6 +214,7 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
ERR_PRINT("!Failed to pack atlas font. Likely out of texture mem.");
|
||||
}
|
||||
}
|
||||
|
||||
stbtt_PackEnd(&pc);
|
||||
_num_glyphs = count;
|
||||
|
||||
@ -234,9 +238,11 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
int max_y1 = 0;
|
||||
for (unsigned int i = 0; i < _num_glyphs; i++) {
|
||||
int cp = _iter2cp[i];
|
||||
if (cp == 0xFFFD)
|
||||
if (cp == 0xFFFD) {
|
||||
continue;
|
||||
stbtt_packedchar *cd = &_cdata[cp - _begin];
|
||||
}
|
||||
|
||||
stbtt_packedchar *cd = &cdata[cp - _begin];
|
||||
if (cd->y1 > max_y1) {
|
||||
max_y1 = cd->y1;
|
||||
}
|
||||
@ -272,7 +278,7 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
continue;
|
||||
}
|
||||
|
||||
stbtt_packedchar *cd = &_cdata[cp - _begin];
|
||||
stbtt_packedchar *cd = &cdata[cp - _begin];
|
||||
|
||||
TextureOffset offset;
|
||||
|
||||
@ -281,6 +287,11 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
offset.x1 = cd->x1 / (double)_width;
|
||||
offset.y1 = cd->y1 / (double)_height;
|
||||
|
||||
offset.x0_orig = cd->x0;
|
||||
offset.y0_orig = cd->y0;
|
||||
offset.x1_orig = cd->x1;
|
||||
offset.y1_orig = cd->y1;
|
||||
|
||||
offset.xoff = cd->xoff;
|
||||
offset.yoff = cd->yoff;
|
||||
offset.xoff2 = cd->xoff2;
|
||||
@ -290,6 +301,8 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
||||
_texture_offsets.write[i] = offset;
|
||||
}
|
||||
|
||||
memdelete_arr(cdata);
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,6 @@
|
||||
#include "core/ustring.h"
|
||||
#include "font_material.h"
|
||||
|
||||
// TODO figure out how to forward declare stbtt_packedchar
|
||||
#include "3rd_stb_truetype.h"
|
||||
|
||||
class Image;
|
||||
class Texture;
|
||||
class Mesh;
|
||||
@ -87,7 +84,6 @@ public:
|
||||
protected:
|
||||
// character info
|
||||
// filled up by stb_truetype.h
|
||||
stbtt_packedchar *_cdata;
|
||||
unsigned _num_glyphs;
|
||||
unsigned *_cp2iter;
|
||||
unsigned *_iter2cp;
|
||||
@ -118,6 +114,11 @@ protected:
|
||||
float x1;
|
||||
float y1;
|
||||
|
||||
float x0_orig;
|
||||
float y0_orig;
|
||||
float x1_orig;
|
||||
float y1_orig;
|
||||
|
||||
float xoff;
|
||||
float xoff2;
|
||||
float xadvance;
|
||||
|
Loading…
Reference in New Issue
Block a user