Completely remove usage of stb_truetype
This commit is contained in:
parent
91a82d8ae4
commit
fa06862177
|
@ -2,7 +2,6 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "stb_truetype.h"
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "font_renderer.h"
|
#include "font_renderer.h"
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ typedef struct GlyphSet GlyphSet;
|
||||||
|
|
||||||
struct RenFont {
|
struct RenFont {
|
||||||
void *data;
|
void *data;
|
||||||
stbtt_fontinfo stbfont;
|
|
||||||
GlyphSet *sets[MAX_GLYPHSET];
|
GlyphSet *sets[MAX_GLYPHSET];
|
||||||
float size;
|
float size;
|
||||||
int height;
|
int height;
|
||||||
|
@ -161,28 +159,6 @@ RenFont* ren_load_font(const char *filename, float size) {
|
||||||
font = check_alloc(calloc(1, sizeof(RenFont)));
|
font = check_alloc(calloc(1, sizeof(RenFont)));
|
||||||
font->size = size;
|
font->size = size;
|
||||||
|
|
||||||
/* load font into buffer */
|
|
||||||
fp = fopen(filename, "rb");
|
|
||||||
if (!fp) { return NULL; }
|
|
||||||
/* get size */
|
|
||||||
fseek(fp, 0, SEEK_END); int buf_size = ftell(fp); fseek(fp, 0, SEEK_SET);
|
|
||||||
/* load */
|
|
||||||
font->data = check_alloc(malloc(buf_size));
|
|
||||||
int _ = fread(font->data, 1, buf_size, fp); (void) _;
|
|
||||||
fclose(fp);
|
|
||||||
fp = NULL;
|
|
||||||
|
|
||||||
/* init stbfont */
|
|
||||||
int ok = stbtt_InitFont(&font->stbfont, font->data, 0);
|
|
||||||
if (!ok) { goto fail; }
|
|
||||||
|
|
||||||
// FIXME: remove, font's height is recalculated using new FontRenderer.
|
|
||||||
/* get height and scale */
|
|
||||||
int ascent, descent, linegap;
|
|
||||||
stbtt_GetFontVMetrics(&font->stbfont, &ascent, &descent, &linegap);
|
|
||||||
float scale = stbtt_ScaleForMappingEmToPixels(&font->stbfont, size);
|
|
||||||
font->height = (ascent - descent + linegap) * scale + 0.5;
|
|
||||||
|
|
||||||
font->renderer = FontRendererNew(FONT_RENDERER_HINTING);
|
font->renderer = FontRendererNew(FONT_RENDERER_HINTING);
|
||||||
// FIXME check for errors
|
// FIXME check for errors
|
||||||
FontRendererLoadFont(font->renderer, filename);
|
FontRendererLoadFont(font->renderer, filename);
|
||||||
|
@ -194,12 +170,6 @@ RenFont* ren_load_font(const char *filename, float size) {
|
||||||
g['\n'].x1 = g['\n'].x0;
|
g['\n'].x1 = g['\n'].x0;
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
|
|
||||||
fail:
|
|
||||||
if (fp) { fclose(fp); }
|
|
||||||
if (font) { free(font->data); }
|
|
||||||
free(font);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -211,7 +181,6 @@ void ren_free_font(RenFont *font) {
|
||||||
free(set);
|
free(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(font->data);
|
|
||||||
FontRendererFree(font->renderer);
|
FontRendererFree(font->renderer);
|
||||||
free(font);
|
free(font);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue