mirror of
https://github.com/Relintai/sfw.git
synced 2025-01-09 21:19:36 +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();
|
unsigned char *bitmap = (unsigned char *)bitmap_data.ptrw();
|
||||||
|
|
||||||
int charCount = sorted[sorted.size() - 1] - sorted[0] + 1; // 0xEFFFF;
|
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);
|
_iter2cp = memnew_arr(unsigned int, charCount);
|
||||||
_cp2iter = memnew_arr(unsigned int, charCount);
|
_cp2iter = memnew_arr(unsigned int, charCount);
|
||||||
for (int i = 0; i < charCount; ++i) {
|
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) {
|
for (int i = 0, end = sorted.size() - 1; i < end; ++i) {
|
||||||
unsigned glyph = sorted[i];
|
unsigned glyph = sorted[i];
|
||||||
if (!stbtt_FindGlyphIndex(&info, glyph))
|
if (!stbtt_FindGlyphIndex(&info, glyph)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
_begin = glyph;
|
_begin = glyph;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -198,10 +200,11 @@ void Font::font_face_from_mem(const void *ttf_data, uint32_t ttf_len, float font
|
|||||||
end = sorted[++i];
|
end = sorted[++i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin < _begin)
|
if (begin < _begin) {
|
||||||
continue;
|
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) {
|
for (uint64_t cp = begin; cp <= end; ++cp) {
|
||||||
// unicode->index runtime lookup
|
// unicode->index runtime lookup
|
||||||
_cp2iter[cp - _begin] = count;
|
_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.");
|
ERR_PRINT("!Failed to pack atlas font. Likely out of texture mem.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stbtt_PackEnd(&pc);
|
stbtt_PackEnd(&pc);
|
||||||
_num_glyphs = count;
|
_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;
|
int max_y1 = 0;
|
||||||
for (unsigned int i = 0; i < _num_glyphs; i++) {
|
for (unsigned int i = 0; i < _num_glyphs; i++) {
|
||||||
int cp = _iter2cp[i];
|
int cp = _iter2cp[i];
|
||||||
if (cp == 0xFFFD)
|
if (cp == 0xFFFD) {
|
||||||
continue;
|
continue;
|
||||||
stbtt_packedchar *cd = &_cdata[cp - _begin];
|
}
|
||||||
|
|
||||||
|
stbtt_packedchar *cd = &cdata[cp - _begin];
|
||||||
if (cd->y1 > max_y1) {
|
if (cd->y1 > max_y1) {
|
||||||
max_y1 = cd->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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
stbtt_packedchar *cd = &_cdata[cp - _begin];
|
stbtt_packedchar *cd = &cdata[cp - _begin];
|
||||||
|
|
||||||
TextureOffset offset;
|
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.x1 = cd->x1 / (double)_width;
|
||||||
offset.y1 = cd->y1 / (double)_height;
|
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.xoff = cd->xoff;
|
||||||
offset.yoff = cd->yoff;
|
offset.yoff = cd->yoff;
|
||||||
offset.xoff2 = cd->xoff2;
|
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;
|
_texture_offsets.write[i] = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memdelete_arr(cdata);
|
||||||
|
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@
|
|||||||
#include "core/ustring.h"
|
#include "core/ustring.h"
|
||||||
#include "font_material.h"
|
#include "font_material.h"
|
||||||
|
|
||||||
// TODO figure out how to forward declare stbtt_packedchar
|
|
||||||
#include "3rd_stb_truetype.h"
|
|
||||||
|
|
||||||
class Image;
|
class Image;
|
||||||
class Texture;
|
class Texture;
|
||||||
class Mesh;
|
class Mesh;
|
||||||
@ -87,7 +84,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// character info
|
// character info
|
||||||
// filled up by stb_truetype.h
|
// filled up by stb_truetype.h
|
||||||
stbtt_packedchar *_cdata;
|
|
||||||
unsigned _num_glyphs;
|
unsigned _num_glyphs;
|
||||||
unsigned *_cp2iter;
|
unsigned *_cp2iter;
|
||||||
unsigned *_iter2cp;
|
unsigned *_iter2cp;
|
||||||
@ -118,6 +114,11 @@ protected:
|
|||||||
float x1;
|
float x1;
|
||||||
float y1;
|
float y1;
|
||||||
|
|
||||||
|
float x0_orig;
|
||||||
|
float y0_orig;
|
||||||
|
float x1_orig;
|
||||||
|
float y1_orig;
|
||||||
|
|
||||||
float xoff;
|
float xoff;
|
||||||
float xoff2;
|
float xoff2;
|
||||||
float xadvance;
|
float xadvance;
|
||||||
|
Loading…
Reference in New Issue
Block a user