2020-01-16 22:45:47 +03:00
|
|
|
module fontstash
|
|
|
|
|
2021-04-19 19:01:47 +03:00
|
|
|
#flag -I @VEXEROOT/thirdparty/fontstash
|
2020-01-17 22:05:45 +03:00
|
|
|
#define FONTSTASH_IMPLEMENTATION
|
2021-03-29 12:27:34 +03:00
|
|
|
$if gcboehm ? {
|
|
|
|
#define FONTSTASH_MALLOC GC_MALLOC
|
|
|
|
#define FONTSTASH_REALLOC GC_REALLOC
|
|
|
|
#define FONTSTASH_FREE GC_FREE
|
|
|
|
}
|
2020-01-17 22:05:45 +03:00
|
|
|
#include "fontstash.h"
|
2021-12-06 20:08:50 +03:00
|
|
|
#flag darwin -I/usr/local/Cellar/freetype/2.10.2/include/freetype2
|
2021-05-14 14:28:53 +03:00
|
|
|
|
|
|
|
$if windows {
|
|
|
|
$if tinyc {
|
|
|
|
#flag @VEXEROOT/thirdparty/tcc/lib/openlibm.o
|
|
|
|
}
|
|
|
|
} $else {
|
|
|
|
#flag -lm
|
|
|
|
}
|
|
|
|
|
2021-12-06 23:39:43 +03:00
|
|
|
pub type Context = C.FONScontext
|
|
|
|
|
2021-01-23 12:25:40 +03:00
|
|
|
//#flag -lfreetype
|
2020-01-17 22:05:45 +03:00
|
|
|
pub const (
|
|
|
|
// TODO: fontstash.used_import is used to keep v from warning about unused imports
|
|
|
|
used_import = 1
|
|
|
|
)
|
2020-01-16 22:45:47 +03:00
|
|
|
|
|
|
|
// Contructor and destructor.
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn create_internal(params &C.FONSparams) &Context {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsCreateInternal(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn delete_internal(s &Context) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsDeleteInternal(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_error_callback(callback fn (voidptr, int, int), uptr voidptr) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetErrorCallback(s, callback, uptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns current atlas size.
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) get_atlas_size() (int, int) {
|
|
|
|
mut width := 0
|
|
|
|
mut height := 0
|
|
|
|
C.fonsGetAtlasSize(s, &width, &height)
|
|
|
|
return width, height
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Expands the atlas size.
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) expand_atlas(width int, height int) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsExpandAtlas(s, width, height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the whole stash.
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) reset_atlas(width int, height int) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsResetAtlas(s, width, height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add fonts
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) get_font_by_name(name string) int {
|
|
|
|
return C.fonsGetFontByName(s, &char(name.str))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) add_fallback_font(base int, fallback int) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsAddFallbackFont(s, base, fallback)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) add_font_mem(name string, data []byte, free_data bool) int {
|
|
|
|
return C.fonsAddFontMem(s, &char(name.str), data.data, data.len, int(free_data))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// State handling
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) push_state() {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsPushState(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) pop_state() {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsPopState(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) clear_state() {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsClearState(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// State setting
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_size(size f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetSize(s, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_color(color u32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetColor(s, color)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_spacing(spacing f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetSpacing(s, spacing)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_blur(blur f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetBlur(s, blur)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_align(align int) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetAlign(s, align)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) set_font(font int) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsSetFont(s, font)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw text
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) draw_text(x f32, y f32, text string) f32 {
|
|
|
|
return C.fonsDrawText(s, x, y, &char(text.str), &char(0))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Measure text
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
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(0), bounds)
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) line_bounds(y f32, miny &f32, maxy &f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsLineBounds(s, y, miny, maxy)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) vert_metrics(ascender &f32, descender &f32, lineh &f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsVertMetrics(s, ascender, descender, lineh)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Text iterator
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) text_iter_init(iter &C.FONStextIter, x f32, y f32, str &char, end &char) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsTextIterInit(s, iter, x, y, str, end)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) text_iter_next(iter &C.FONStextIter, quad &C.FONSquad) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsTextIterNext(s, iter, quad)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pull texture changes
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) get_texture_data(width &int, height &int) &byte {
|
2021-04-14 12:47:24 +03:00
|
|
|
return &byte(C.fonsGetTextureData(s, width, height))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) validate_texture(dirty &int) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsValidateTexture(s, dirty)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draws the stash texture for debugging
|
|
|
|
[inline]
|
2021-12-06 23:39:43 +03:00
|
|
|
pub fn (s &Context) draw_debug(x f32, y f32) {
|
2020-01-16 22:45:47 +03:00
|
|
|
C.fonsDrawDebug(s, x, y)
|
|
|
|
}
|