diff options
Diffstat (limited to 'v_windows/v/old/vlib/fontstash')
| -rw-r--r-- | v_windows/v/old/vlib/fontstash/a_d_use_freetype.v | 19 | ||||
| -rw-r--r-- | v_windows/v/old/vlib/fontstash/fontstash.v | 172 | ||||
| -rw-r--r-- | v_windows/v/old/vlib/fontstash/fontstash_funcs.v | 53 | ||||
| -rw-r--r-- | v_windows/v/old/vlib/fontstash/fontstash_structs.v | 80 | 
4 files changed, 324 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/fontstash/a_d_use_freetype.v b/v_windows/v/old/vlib/fontstash/a_d_use_freetype.v new file mode 100644 index 0000000..199fe31 --- /dev/null +++ b/v_windows/v/old/vlib/fontstash/a_d_use_freetype.v @@ -0,0 +1,19 @@ +module fontstash + +#define FONS_USE_FREETYPE 1 +#flag windows -I @VEXEROOT/thirdparty/freetype/include +#flag windows -L @VEXEROOT/thirdparty/freetype/win64 +#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 windows -lfreetype +#flag linux -lfreetype +#flag darwin -lfreetype +#flag darwin -lpng -lbz2 -lz diff --git a/v_windows/v/old/vlib/fontstash/fontstash.v b/v_windows/v/old/vlib/fontstash/fontstash.v new file mode 100644 index 0000000..6149a01 --- /dev/null +++ b/v_windows/v/old/vlib/fontstash/fontstash.v @@ -0,0 +1,172 @@ +module fontstash + +#flag -I @VEXEROOT/thirdparty/fontstash +#define FONTSTASH_IMPLEMENTATION +$if gcboehm ? { +	#define FONTSTASH_MALLOC GC_MALLOC +	#define FONTSTASH_REALLOC GC_REALLOC +	#define FONTSTASH_FREE GC_FREE +} +#include "fontstash.h" +#flag -I /usr/local/Cellar/freetype/2.10.2/include/freetype2 + +$if windows { +	$if tinyc { +		#flag @VEXEROOT/thirdparty/tcc/lib/openlibm.o +	} +} $else { +	#flag -lm +} + +//#flag -lfreetype +pub const ( +	// TODO: fontstash.used_import is used to keep v from warning about unused imports +	used_import = 1 +) + +// 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] +pub fn (s &C.FONScontext) set_error_callback(callback fn (voidptr, int, int), uptr voidptr) { +	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] +pub fn (s &C.FONScontext) get_font_by_name(name &char) int { +	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] +pub fn (s &C.FONScontext) add_font_mem(name &char, data &byte, data_size int, free_data int) int { +	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] +pub fn (s &C.FONScontext) draw_text(x f32, y f32, str &char, end &char) f32 { +	return C.fonsDrawText(s, x, y, str, end) +} + +// Measure text +[inline] +pub fn (s &C.FONScontext) text_bounds(x f32, y f32, str &char, end &char, bounds &f32) f32 { +	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] +pub fn (s &C.FONScontext) text_iter_init(iter &C.FONStextIter, x f32, y f32, str &char, end &char) int { +	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] +pub fn (s &C.FONScontext) get_texture_data(width &int, height &int) &byte { +	return &byte(C.fonsGetTextureData(s, width, height)) +} + +[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) +} diff --git a/v_windows/v/old/vlib/fontstash/fontstash_funcs.v b/v_windows/v/old/vlib/fontstash/fontstash_funcs.v new file mode 100644 index 0000000..8e260e7 --- /dev/null +++ b/v_windows/v/old/vlib/fontstash/fontstash_funcs.v @@ -0,0 +1,53 @@ +module fontstash + +// Contructor 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 int, height int) int + +// Resets the whole stash. +fn C.fonsResetAtlas(s &C.FONScontext, width int, height int) int + +// Add fonts +fn C.fonsGetFontByName(s &C.FONScontext, name &char) int +fn C.fonsAddFallbackFont(s &C.FONScontext, base int, fallback int) int +fn C.fonsAddFontMem(s &C.FONScontext, name &char, data &byte, dataSize int, freeData int) int + +// 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 int) +fn C.fonsSetFont(s &C.FONScontext, font int) + +// 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) int +fn C.fonsTextIterNext(s &C.FONScontext, iter &C.FONStextIter, quad &C.FONSquad) int + +// Pull texture changes +fn C.fonsGetTextureData(s &C.FONScontext, width &int, height &int) &char +fn C.fonsValidateTexture(s &C.FONScontext, dirty &int) int + +// Draws the stash texture for debugging +fn C.fonsDrawDebug(s &C.FONScontext, x f32, y f32) diff --git a/v_windows/v/old/vlib/fontstash/fontstash_structs.v b/v_windows/v/old/vlib/fontstash/fontstash_structs.v new file mode 100644 index 0000000..83daa52 --- /dev/null +++ b/v_windows/v/old/vlib/fontstash/fontstash_structs.v @@ -0,0 +1,80 @@ +module fontstash + +pub enum FonsFlags { +	top_left = 1 +	bottom_left = 2 +} + +pub enum FonsAlign { +	// Horizontal align +	left 		= 1	// Default +	center 		= 2 +	right 		= 4 +	// Vertical align +	top 		= 8 +	middle		= 16 +	bottom		= 32 +	baseline	= 64 // Default +} + +pub enum FonsErrorCode { +	// 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 +} + +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 +	// int (*renderResize)(void* uptr, int width, int height) +	renderResize fn(uptr voidptr, width int, height int) int +	// void (*renderUpdate)(void* uptr, int* rect, const unsigned char* data) +	renderUpdate fn(uptr voidptr, rect &int, data byteptr) +	// 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) +	// void (*renderDelete)(void* uptr) +	renderDelete fn(uptr voidptr) +} + +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 +	prevGlyphIndex int +	str byteptr +	next byteptr +	end byteptr +	utf8state u32 +} + +pub struct C.FONSfont {} + +pub struct C.FONScontext {}  | 
