Initial font rework.

This commit is contained in:
Relintai 2024-01-03 19:30:49 +01:00
parent 82853c99f2
commit 2c358a1466
2 changed files with 5218 additions and 2169 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,12 @@
#ifndef FONT_RENDERER_H
#define FONT_RENDERER_H
// -----------------------------------------------------------------------------
// font framework
// font framework originally from FWK
// - rlyeh, public domain
#include "object/object.h"
// font size tags
#define FONT_H1 "\1" // largest
#define FONT_H2 "\2"
@ -39,6 +44,10 @@
#define FONT_BASELINE "\\_"
#define FONT_BOTTOM "\\v"
class TextRenderer : public Object {
SFW_OBJECT(TextRenderer, Object);
public:
// font flags
enum FONT_FLAGS {
// font atlas size
@ -78,23 +87,31 @@ typedef struct font_metrics_t {
} font_metrics_t;
// configures
API void font_face(const char *face_tag, const char *filename_ttf, float font_size, unsigned flags);
API void font_face_from_mem(const char *tag, const void *ttf_buffer, unsigned ttf_len, float font_size, unsigned flags);
API void font_scales(const char *face_tag, float h1, float h2, float h3, float h4, float h5, float h6);
API void font_color(const char *color_tag, uint32_t color);
void font_face(const char *face_tag, const char *filename_ttf, float font_size, unsigned flags);
void font_face_from_mem(const char *tag, const void *ttf_buffer, unsigned ttf_len, float font_size, unsigned flags);
void font_scales(const char *face_tag, float h1, float h2, float h3, float h4, float h5, float h6);
void font_color(const char *color_tag, uint32_t color);
// commands
API vec2 font_xy();
API void font_goto(float x, float y);
API vec2 font_print(const char *text);
API vec2 font_rect(const char *text);
API font_metrics_t font_metrics(const char *text);
vec2 font_xy();
void font_goto(float x, float y);
vec2 font_print(const char *text);
vec2 font_rect(const char *text);
font_metrics_t font_metrics(const char *text);
// void font_clip(vec2 topleft, vec2 bottomright);
// void font_wrap(vec2 topleft, vec2 bottomright);
// syntax highlighting
API void* font_colorize(const char *text, const char *comma_types, const char *comma_keywords); // comma separated tokens. expensive, please cache result.
API vec2 font_highlight(const char *text, const void *colors);
void *font_colorize(const char *text, const char *comma_types, const char *comma_keywords); // comma separated tokens. expensive, please cache result.
vec2 font_highlight(const char *text, const void *colors);
// ui
API void ui_font();
void ui_font();
static TextRenderer *get_singleton();
protected:
static TextRenderer *_singleton;
};
#endif