2020-01-16 22:45:47 +03:00
|
|
|
module fontstash
|
|
|
|
|
|
|
|
#flag -I @VROOT/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-01-23 12:25:40 +03:00
|
|
|
#flag -I /usr/local/Cellar/freetype/2.10.2/include/freetype2
|
|
|
|
//#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]
|
|
|
|
pub fn create_internal(params &C.FONSparams) &C.FONScontext {
|
|
|
|
return C.fonsCreateInternal(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn delete_internal(s &C.FONScontext) {
|
|
|
|
C.fonsDeleteInternal(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-01-23 12:25:40 +03:00
|
|
|
pub fn (s &C.FONScontext) 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]
|
|
|
|
pub fn (s &C.FONScontext) get_atlas_size(width &int, height &int) {
|
|
|
|
C.fonsGetAtlasSize(s, width, height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expands the atlas size.
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) expand_atlas(width int, height int) int {
|
|
|
|
return C.fonsExpandAtlas(s, width, height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the whole stash.
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) reset_atlas(width int, height int) int {
|
|
|
|
return C.fonsResetAtlas(s, width, height)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add fonts
|
|
|
|
[inline]
|
2021-04-14 12:47:24 +03:00
|
|
|
pub fn (s &C.FONScontext) get_font_by_name(name &char) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsGetFontByName(s, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) add_fallback_font(base int, fallback int) int {
|
|
|
|
return C.fonsAddFallbackFont(s, base, fallback)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2021-04-14 12:47:24 +03:00
|
|
|
pub fn (s &C.FONScontext) add_font_mem(name &char, data &byte, data_size int, free_data int) int {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsAddFontMem(s, name, data, data_size, free_data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// State handling
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) push_state() {
|
|
|
|
C.fonsPushState(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) pop_state() {
|
|
|
|
C.fonsPopState(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) clear_state() {
|
|
|
|
C.fonsClearState(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// State setting
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) set_size(size f32) {
|
|
|
|
C.fonsSetSize(s, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) set_color(color u32) {
|
|
|
|
C.fonsSetColor(s, color)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) set_spacing(spacing f32) {
|
|
|
|
C.fonsSetSpacing(s, spacing)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) set_blur(blur f32) {
|
|
|
|
C.fonsSetBlur(s, blur)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) set_align(align int) {
|
|
|
|
C.fonsSetAlign(s, align)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) set_font(font int) {
|
|
|
|
C.fonsSetFont(s, font)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw text
|
|
|
|
[inline]
|
2021-04-14 12:47:24 +03:00
|
|
|
pub fn (s &C.FONScontext) draw_text(x f32, y f32, str &char, end &char) f32 {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsDrawText(s, x, y, str, end)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measure text
|
|
|
|
[inline]
|
2021-04-14 12:47:24 +03:00
|
|
|
pub fn (s &C.FONScontext) text_bounds(x f32, y f32, str &char, end &char, bounds &f32) f32 {
|
2020-01-16 22:45:47 +03:00
|
|
|
return C.fonsTextBounds(s, x, y, str, end, bounds)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) line_bounds(y f32, miny &f32, maxy &f32) {
|
|
|
|
C.fonsLineBounds(s, y, miny, maxy)
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) vert_metrics(ascender &f32, descender &f32, lineh &f32) {
|
|
|
|
C.fonsVertMetrics(s, ascender, descender, lineh)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Text iterator
|
|
|
|
[inline]
|
2021-04-14 12:47:24 +03:00
|
|
|
pub fn (s &C.FONScontext) 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]
|
|
|
|
pub fn (s &C.FONScontext) text_iter_next(iter &C.FONStextIter, quad &C.FONSquad) int {
|
|
|
|
return C.fonsTextIterNext(s, iter, quad)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pull texture changes
|
|
|
|
[inline]
|
2021-04-14 12:47:24 +03:00
|
|
|
pub fn (s &C.FONScontext) get_texture_data(width &int, height &int) &byte {
|
|
|
|
return &byte(C.fonsGetTextureData(s, width, height))
|
2020-01-16 22:45:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) validate_texture(dirty &int) int {
|
|
|
|
return C.fonsValidateTexture(s, dirty)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draws the stash texture for debugging
|
|
|
|
[inline]
|
|
|
|
pub fn (s &C.FONScontext) draw_debug(x f32, y f32) {
|
|
|
|
C.fonsDrawDebug(s, x, y)
|
|
|
|
}
|