Files
prosperon/font.h
2025-11-26 12:52:56 -06:00

70 lines
1.2 KiB
C

#ifndef FONT_H
#define FONT_H
#include "render.h"
#include "HandmadeMath.h"
#include "cell.h"
#include <SDL3/SDL.h>
#include "render.h"
typedef enum {
LEFT,
RIGHT,
CENTER,
JUSTIFY
} TEXT_ALIGN;
typedef enum {
WORD,
CHARACTER
} TEXT_BREAK;
struct text_vert {
HMM_Vec2 pos;
HMM_Vec2 uv;
HMM_Vec4 color;
};
typedef struct text_vert text_vert;
struct text_char {
rect pos;
rect uv;
HMM_Vec4 color;
};
struct shader;
struct window;
struct character {
float advance;
rect quad;
rect uv;
float xoff;
float yoff;
float width;
float height;
};
// text data
struct sFont {
uint32_t height; /* in pixels */
float ascent; // pixels
float descent; // pixels
float linegap; //pixels
float line_height; // pixels
struct character Characters[256];
SDL_Surface *surface;
};
typedef struct sFont font;
typedef struct Character glyph;
void font_free(JSRuntime *rt,font *f);
struct sFont *MakeFont(void *data, size_t len, int height);
struct text_vert *renderText(const char *text, HMM_Vec2 pos, font *f, colorf color, float wrap, TEXT_BREAK breakAt, TEXT_ALIGN align, float letter_spacing);
HMM_Vec2 measure_text(const char *text, font *f, float letterSpacing, float wrap, TEXT_BREAK breakAt, TEXT_ALIGN align);
#endif