Initial project import

This commit is contained in:
Agila Forge Importer committed 2026-07-13 15:20:32 +00:00
commit 23f2d29e32
11957 files changed
+1754577

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
## Description
`fontstash` is a thin wrapper over <https://github.com/memononen/fontstash>,
which in turn is a light-weight online font texture atlas builder written in C.
It uses stb_truetype to render fonts on demand to a texture atlas
+18
View File
@@ -0,0 +1,18 @@
module fontstash
#define FONS_USE_FREETYPE 1
// Windows fontstash forces stb_truetype in thirdparty/fontstash/fontstash.h,
// so adding freetype link flags here only creates a stale linker dependency.
#flag linux -I/usr/include/freetype2
#flag darwin -I/usr/local/include/freetype2
// brew on m1
#flag darwin -I/opt/homebrew/include/freetype2
#flag darwin -L/opt/homebrew/lib
// MacPorts
#flag darwin -I/opt/local/include/freetype2
#flag darwin -L/opt/local/lib
#flag freebsd -I/usr/local/include/freetype2
#flag freebsd -Wl -L/usr/local/lib
#flag linux -lfreetype
#flag darwin -lfreetype
#flag darwin -lpng -lbz2 -lz
+272
View File
@@ -0,0 +1,272 @@
module fontstash
#flag -I @VEXEROOT/thirdparty/fontstash
@[use_once]
#define FONTSTASH_IMPLEMENTATION
$if gcboehm ? {
#define FONTSTASH_MALLOC GC_MALLOC
#define FONTSTASH_REALLOC GC_REALLOC
#define FONTSTASH_FREE GC_FREE
#define FONTSTASH_MALLOC_ATOMIC GC_MALLOC_ATOMIC
}
#include "fontstash.h"
#flag darwin -I/usr/local/Cellar/freetype/2.10.2/include/freetype2
$if windows {
$if tinyc {
#flag @VEXEROOT/thirdparty/tcc/lib/openlibm.o
}
} $else {
#flag -lm
}
pub type Context = C.FONScontext
//#flag -lfreetype
pub const invalid = C.FONS_INVALID
// create_internal returns a fontstash Context allocated on the heap.
//
// See also: delete_internal
@[inline]
pub fn create_internal(params &C.FONSparams) &Context {
return C.fonsCreateInternal(params)
}
// delete_internal deletes and free memory of `s` fontstash Context.
//
// See also: create_internal
@[inline]
pub fn delete_internal(s &Context) {
C.fonsDeleteInternal(s)
}
// set_error_callback sets `callback` as a function to be called if fontstash
// encounter any errors. `uptr` can be used to pass custom userdata.
@[inline]
pub fn (s &Context) set_error_callback(callback fn (voidptr, int, int), uptr voidptr) {
C.fonsSetErrorCallback(s, callback, uptr)
}
// get_atlas_size returns the current size of the texture atlas which
// the font is rendered to.
@[inline]
pub fn (s &Context) get_atlas_size() (int, int) {
mut width := 0
mut height := 0
C.fonsGetAtlasSize(s, &width, &height)
return width, height
}
// expand_atlas expands the font texture atlas size to `width` x `height`.
@[inline]
pub fn (s &Context) expand_atlas(width int, height int) int {
return C.fonsExpandAtlas(s, width, height)
}
// reset_atlas resets `width` x `height` of the font texture atlas.
@[inline]
pub fn (s &Context) reset_atlas(width int, height int) int {
return C.fonsResetAtlas(s, width, height)
}
// get_font_by_name returns the id of the font with `name` or
// `fontstash.invalid` if no font with `name` could be found.
@[inline]
pub fn (s &Context) get_font_by_name(name string) int {
return C.fonsGetFontByName(s, &char(name.str))
}
// add_fallback_font adds a fallback font to the `base` font id in the Context.
// `fallback` is expected to be the id of a previous, successfully, added font.
// add_fallback_font returns `1` on success, `0` otherwise.
@[inline]
pub fn (s &Context) add_fallback_font(base int, fallback int) int {
return C.fonsAddFallbackFont(s, base, fallback)
}
// add_font_mem adds the font data located in memory to the Context.
// `name` is the human readable name for the font.
// `free_data` indicates if `data` should be freed after the font is added.
// The function returns the id of the font on success, `fontstash.invalid` otherwise.
@[inline]
pub fn (s &Context) add_font_mem(name string, data []u8, free_data bool) int {
return C.fonsAddFontMem(s, &char(name.str), data.data, data.len, int(free_data))
}
// push_state pushes a new state on the state stack.
// A state holds the current attributes of the rendering,
// attributes are things like color, size, the font in use, blur effect etc.
//
// See also: pop_state
// See also: clear_state
// See also: set_size
// See also: set_color
// See also: set_spacing
// See also: set_blur
// See also: set_align
// See also: set_font
@[inline]
pub fn (s &Context) push_state() {
C.fonsPushState(s)
}
// pop_state pops the current state from the state stack.
//
// See also: push_state
// See also: clear_state
@[inline]
pub fn (s &Context) pop_state() {
C.fonsPopState(s)
}
// clear_state clears the current state.
//
// See also: push_state
// See also: pop_state
@[inline]
pub fn (s &Context) clear_state() {
C.fonsClearState(s)
}
// set_size sets the font size to `size` on the active state.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_size(size f32) {
C.fonsSetSize(s, size)
}
// set_color sets the font color to `color` on the active state.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_color(color u32) {
C.fonsSetColor(s, color)
}
// set_spacing sets the font spacing to `spacing` on the active state.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_spacing(spacing f32) {
C.fonsSetSpacing(s, spacing)
}
// set_blur sets the font blur effect to `blur` on the active state.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_blur(blur f32) {
C.fonsSetBlur(s, blur)
}
// set_align sets the font aligning to `align` on the active state.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_align(align int) {
C.fonsSetAlign(s, int(align))
}
// set_alignment sets the font aligning to the `align` flags.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_alignment(align Align) {
C.fonsSetAlign(s, int(align))
}
// set_font sets the font used for this render on the active state.
// `font_id` is the id of the loaded font.
//
// See also: push_state
// See also: pop_state
// See also: clear_state
@[inline]
pub fn (s &Context) set_font(font_id int) {
C.fonsSetFont(s, font_id)
}
// draw_text draws the `text` string at position `x`,`y`.
// The function returns the `x` coordinate of the resulting render.
@[inline]
pub fn (s &Context) draw_text(x f32, y f32, text string) f32 {
return C.fonsDrawText(s, x, y, &char(text.str), &char(unsafe { nil }))
}
// text_bounds fills the `bounds` argument with the pixel dimensions
// of the rendered `text` at position `x`,`y`.
//
// `bounds` is expected to be of type `mut bounds := [4]f32{}`.
// Call example: `ctx.text_bounds(0, 0, 'example', &bounds[0])`.
// `bounds[0]` is the `x` coordinate of the top-left point.
// `bounds[1]` is the `y` coordinate of the top-left point.
// `bounds[2]` is the `x` coordinate of the bottom-right point.
// `bounds[3]` is the `y` coordinate of the bottom-right point.
@[inline]
pub fn (s &Context) text_bounds(x f32, y f32, text string, bounds &f32) f32 {
return C.fonsTextBounds(s, x, y, &char(text.str), &char(unsafe { nil }), bounds)
}
// line_bounds fills `miny` and `maxy` with the values of the `minimum`
// and `maximum` line bounds respectively.
@[inline]
pub fn (s &Context) line_bounds(y f32, miny &f32, maxy &f32) {
C.fonsLineBounds(s, y, miny, maxy)
}
// vert_metrics assigns the respective values of `ascender`, `descender` and `lineh`.
@[inline]
pub fn (s &Context) vert_metrics(ascender &f32, descender &f32, lineh &f32) {
C.fonsVertMetrics(s, ascender, descender, lineh)
}
// text_iter_init initializes the text iterator `iter`.
@[inline]
pub fn (s &Context) text_iter_init(iter &C.FONStextIter, x f32, y f32, str &char, end &char) int {
return C.fonsTextIterInit(s, iter, x, y, str, end)
}
// text_iter_next advances `iter` to the next `quad`.
@[inline]
pub fn (s &Context) text_iter_next(iter &C.FONStextIter, quad &C.FONSquad) int {
return C.fonsTextIterNext(s, iter, quad)
}
// get_texture_data returns the current Context's raw texture data.
// `width` and `height` is assigned the size of the texture dimensions.
@[inline]
pub fn (s &Context) get_texture_data(width &int, height &int) &u8 {
return &u8(C.fonsGetTextureData(s, width, height))
}
// validate_texture fills the `dirty` argument with the pixel dimensions
// of the dirty rectangle of the Context's raw texture, if any.
//
// `dirty` is expected to be of type `mut dirty := [4]int{}`.
// Call example: `is_dirty := ctx.validate_texture(&dirty[0])`.
// The function returns `1` if the texture has a dirty rectangle, `0` otherwise.
@[inline]
pub fn (s &Context) validate_texture(dirty &int) int {
return C.fonsValidateTexture(s, dirty)
}
// draw_debug draws the stash texture for debugging.
@[inline]
pub fn (s &Context) draw_debug(x f32, y f32) {
C.fonsDrawDebug(s, x, y)
}
+31
View File
@@ -0,0 +1,31 @@
module fontstash
@[flag]
pub enum Flags {
top_left
bottom_left
}
@[flag]
pub enum Align {
// Horizontal align
left // Default
center
right
// Vertical align
top
middle
bottom
baseline // Default
}
pub enum ErrorCode {
// Font atlas is full.
atlas_full = 1
// Scratch memory used to render glyphs is full, requested size reported in 'val', you may need to bump up FONS_SCRATCH_BUF_SIZE.
scratch_full = 2
// Calls to fonsPushState has created too large stack, if you need deep state stack bump up FONS_MAX_STATES.
states_overflow = 3
// Trying to pop too many states fonsPopState().
states_underflow = 4
}
@@ -0,0 +1,53 @@
module fontstash
// Constructor and destructor.
fn C.fonsCreateInternal(params &C.FONSparams) &C.FONScontext
fn C.fonsDeleteInternal(s &C.FONScontext)
fn C.fonsSetErrorCallback(s &C.FONScontext, callback fn (voidptr, int, int), uptr voidptr)
// Returns current atlas size.
fn C.fonsGetAtlasSize(s &C.FONScontext, width &int, height &int)
// Expands the atlas size.
fn C.fonsExpandAtlas(s &C.FONScontext, width i32, height i32) i32
// Resets the whole stash.
fn C.fonsResetAtlas(s &C.FONScontext, width i32, height i32) i32
// Add fonts
fn C.fonsGetFontByName(s &C.FONScontext, name &char) i32
fn C.fonsAddFallbackFont(s &C.FONScontext, base i32, fallback i32) i32
fn C.fonsAddFontMem(s &C.FONScontext, name &char, data &u8, dataSize i32, freeData i32) i32
// State handling
fn C.fonsPushState(s &C.FONScontext)
fn C.fonsPopState(s &C.FONScontext)
fn C.fonsClearState(s &C.FONScontext)
// State setting
fn C.fonsSetSize(s &C.FONScontext, size f32)
fn C.fonsSetColor(s &C.FONScontext, color u32)
fn C.fonsSetSpacing(s &C.FONScontext, spacing f32)
fn C.fonsSetBlur(s &C.FONScontext, blur f32)
fn C.fonsSetAlign(s &C.FONScontext, align i32)
fn C.fonsSetFont(s &C.FONScontext, font i32)
// Draw text
fn C.fonsDrawText(s &C.FONScontext, x f32, y f32, str &char, end &char) f32
// Measure text
fn C.fonsTextBounds(s &C.FONScontext, x f32, y f32, str &char, end &char, bounds &f32) f32
fn C.fonsLineBounds(s &C.FONScontext, y f32, miny &f32, maxy &f32)
fn C.fonsVertMetrics(s &C.FONScontext, ascender &f32, descender &f32, lineh &f32)
// Text iterator
fn C.fonsTextIterInit(s &C.FONScontext, iter &C.FONStextIter, x f32, y f32, str &char, end &char) i32
fn C.fonsTextIterNext(s &C.FONScontext, iter &C.FONStextIter, quad &C.FONSquad) i32
// Pull texture changes
fn C.fonsGetTextureData(s &C.FONScontext, width &int, height &int) &char
fn C.fonsValidateTexture(s &C.FONScontext, dirty &int) i32
// Draws the stash texture for debugging
fn C.fonsDrawDebug(s &C.FONScontext, x f32, y f32)
@@ -0,0 +1,57 @@
module fontstash
pub struct C.FONSparams {
width int
height int
flags char
userPtr voidptr
// int (*renderCreate)(void* uptr, int width, int height)
renderCreate fn (uptr voidptr, width int, height int) int = unsafe { nil }
// int (*renderResize)(void* uptr, int width, int height)
renderResize fn (uptr voidptr, width int, height int) int = unsafe { nil }
// void (*renderUpdate)(void* uptr, int* rect, const unsigned char* data)
renderUpdate fn (uptr voidptr, rect &int, data &u8) = unsafe { nil }
// void (*renderDraw)(void* uptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts)
renderDraw fn (uptr voidptr, verts &f32, tcoords &f32, colors &u32, nverts int) = unsafe { nil }
// void (*renderDelete)(void* uptr)
renderDelete fn (uptr voidptr) = unsafe { nil }
}
pub struct C.FONSquad {
x0 f32
y0 f32
s0 f32
t0 f32
x1 f32
y1 f32
s1 f32
t1 f32
}
pub struct C.FONStextIter {
x f32
y f32
nextx f32
nexty f32
scale f32
spacing f32
codepoint u32
isize i16
iblur i16
font &C.FONSfont = unsafe { nil }
prevGlyphIndex int
str &u8
next &u8
end &u8
utf8state u32
}
pub struct C.FONSfont {}
pub struct C.FONScontext {
pub:
params C.FONSparams
itw f32
ith f32
texData &u8 = unsafe { nil }
}