mirror of
https://github.com/Relintai/sfw.git
synced 2025-01-30 22:59:17 +01:00
Initial font rework.
This commit is contained in:
parent
82853c99f2
commit
2c358a1466
File diff suppressed because it is too large
Load Diff
@ -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,8 +44,12 @@
|
||||
#define FONT_BASELINE "\\_"
|
||||
#define FONT_BOTTOM "\\v"
|
||||
|
||||
// font flags
|
||||
enum FONT_FLAGS {
|
||||
class TextRenderer : public Object {
|
||||
SFW_OBJECT(TextRenderer, Object);
|
||||
|
||||
public:
|
||||
// font flags
|
||||
enum FONT_FLAGS {
|
||||
// font atlas size
|
||||
FONT_512 = 0x0,
|
||||
FONT_1024 = 0x1,
|
||||
@ -65,36 +74,44 @@ enum FONT_FLAGS {
|
||||
FONT_RU = 0x100000, // Cyrillic + ext A/B
|
||||
FONT_TH = 0x200000, // Thai
|
||||
FONT_VI = 0x400000, // Vietnamese
|
||||
FONT_CJK = FONT_ZH|FONT_JP|FONT_KR,
|
||||
FONT_CJK = FONT_ZH | FONT_JP | FONT_KR,
|
||||
|
||||
// FONT_DEFAULTS = FONT_512 | FONT_NO_OVERSAMPLE | FONT_ASCII,
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct font_metrics_t {
|
||||
typedef struct font_metrics_t {
|
||||
float ascent; // max distance above baseline for all glyphs
|
||||
float descent; // max distance below baseline for all glyphs
|
||||
float linegap; // distance betwen ascent of next line and descent of current line
|
||||
float linedist; // distance between the baseline of two lines (ascent - descent + linegap)
|
||||
} 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);
|
||||
// configures
|
||||
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);
|
||||
// void font_clip(vec2 topleft, vec2 bottomright);
|
||||
// void font_wrap(vec2 topleft, vec2 bottomright);
|
||||
// commands
|
||||
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);
|
||||
// syntax highlighting
|
||||
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();
|
||||
// ui
|
||||
void ui_font();
|
||||
|
||||
static TextRenderer *get_singleton();
|
||||
|
||||
protected:
|
||||
static TextRenderer *_singleton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user