fontstash: isolate implementation from external stb_truetype (#31193)

* fontstash: guard stb_truetype implementation include (#30615)

* x.executor: inline JobFn as fn () ! to avoid alias collision with x.async (#31191)

When a program imports both x.executor and x.async, the transform stage resolved executor.ExecutorJob.f (typed JobFn) to async.JobFn (fn (mut context.Context) !), because both modules declare a type alias named JobFn and the transform's type cache reused the async entry. Inlining the concrete signature removes the indirection and the collision.

* compress.deflate: make const init dependencies explicit to fix crash (#31039) (#31184)

* math.decimal: support exponent notation in from_string (#31104) (#31190)

* math.decimal: support exponent notation in from_string (#31104)

* math.decimal: validate exponent grammar and exact supported range

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* toml: avoid replacement local that triggers autofree undeclared cleanup (#30804) (#31188)

* os: use underscore-prefixed stat macros on Windows for portability (#31060) (#31189)

* os: use underscore-prefixed stat macros on Windows for portability (#31060)

* os: use portable V constants for Windows stat mode bits

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* net.mbedtls: use the system CA bundle when validate is set without verify (fix #31098) (#31186)

* net.mbedtls: use the system CA bundle when validate is set without verify (fix #31098)

the client set VERIFY_REQUIRED with an empty CA chain, so every handshake failed with MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED. now it loads $SSL_CERT_FILE or the first common system bundle, like SSL_CTX_set_default_verify_paths does in the openssl backend, and errors out at init if there is none.

* net.mbedtls: document default trusted CA selection

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* compiler: avoid repeated self-compilation lookups and copies (#31197)

* compiler: reduce repeated self-compilation lookups and copies

Reuse immutable type and call metadata, avoid unnecessary name work and
node copies, and accelerate standard map, string and builder operations.
Add focused coverage for cache invalidation and borrowed storage lifetime.

* docs: record paired self-compilation results

* ci: fix macOS self-test failures and worker selection (#31196)

* ci: respect macOS self-test workers with fail-fast

* builtin: keep vgc thread-cache test allocation at runtime

* driver: align wasm array gate tests with string support

* tests: use selected C compiler for raw assembly fixture

* tests: isolate codegen fixtures between concurrent runs (#31206)

* tests: read canonical struct initializer operand in defaults regression (#31207)

* transform: avoid repeated full-AST result type refreshes during monomorphization (#31185)

* transform: speed up generic result type refresh

* transform: retain ordinary generic function alias refresh candidates

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* types: warn on unknown attribute names (custom attributes, rfcs#35) (#31183)

* types: warn on unknown attribute names (custom attributes, rfcs#35)

* types: distinguish source attribute names from flattened metadata

* types: preserve ownership of legacy and leading attributes

* types: keep attribute warnings on fields with inline access

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* net.mbedtls: avoid empty client credentials with system trust (#31202)

* ci: keep a v -N test vlib/ lane, plus one false-positive notice fix (#31194)

* types: treat a generic parameter used only in a comptime $if condition as used

* ci: add a v -N test vlib/ lane for the modules that are clean today

* types: preserve notices around quoted reflection metadata

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* gg: draw text with a font shader and triangle batches (#31208)

* gg: draw text with a font shader and triangle batches

fontstash emits two triangles per glyph, but the text batch was opened as quads,
so the render context inserted duplicate vertices every fourth input and shifted
the triangle stream out of alignment. Glyphs came out clipped and stray triangles
sampled empty atlas texels.

The r8 text atlas also went through the generic shader, which rendered white
glyphs red and empty texels black. Text now uses a font pipeline whose shader
reads the red channel as coverage.

The atlas is uploaded once per frame from FT.flush instead of once per draw
call, which sokol rejects with VALIDATE_UPDIMG_ONCE. Pipelines also take the
window's sample count, so they match the MSAA framebuffer.

* gg: upload new font glyphs before their first render pass

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* tools: keep the git pre-commit hook runnable by V releases (#31216)

Git runs `.git/hooks/pre-commit` with the `v` found on PATH, which can be
an older release than the V that installed the hook. The hook used array
spreading and `os.system_args`, which the V 0.5.2 release does not have,
so with that release on PATH every commit failed with
`invalid expression: unexpected token ...`.

Build the argument lists with `<<` and run them with `os.exec`. The
commands still run without a shell, so file names with spaces keep
working, and the script compiles with both master and 0.5.2. Add a note
asking to keep the script compatible with the latest release.

* math.decimal: add floored and Euclidean division (#31214)

Add `Decimal.floor_div` and `floor_mod`, whose remainder takes the
divisor's sign as with `math.floor_mod`, and `Decimal.div_euclid` and
`mod_euclid`, whose remainder is never negative as with
`big.Integer.mod_euclid`. Each pair satisfies `a == q * b + r` exactly
and returns an error on a zero divisor.

Document these, `rem`, `sign`, `min`, `max` and the minor-unit
conversions in the README.

Part of #31104.

* ci: fix macOS bootstrap and example builds (#31205)

* fastc: dereference pointer-returning calls with indexed arguments

* builtin: avoid FastC symbol collision in two-byte string search

* tools: build the macOS tray example as a project folder

* tests: align parser and Wasm audits with supported features

* transform: preserve caller types in generic specializations

* cgen: preserve source module identity in cached declarations

* cgen: resolve cached capture array fields in their source module

* test: assert the default SLH-DSA key description

* cgen: deduplicate owned closure drop helpers by symbol (#31213)

* gg, macos: fix default Metal shaders and Intel NSRect returns (#31217)

* macos: use objc_msgSend_stret for struct returns on x86_64

macos_objc_msg_rect dispatched every -[NSView bounds] style message
through plain objc_msgSend. On Apple Silicon the 32-byte NSRect comes
back in registers, so that worked; on Intel a structure this size is
answered through memory, which only objc_msgSend_stret does. Calling
plain objc_msgSend shifted every argument by the hidden return-slot
pointer and crashed at the first rect query, for example ui2's
native_bounds during applicationDidFinishLaunching on an Intel Mac.

macos_point and macos_range fit in registers on both architectures and
keep the direct call.

* gg: fail with a clear message when macOS has no Metal device

On macOS, sokol's Metal backend asserts when gfx.setup gets no device. That
happens in virtual machines without GPU access, where MTLCreateSystemDefaultDevice
returns nil. Check for the device first and panic with a message that names the
cause.

* gg: document the default macOS Metal device requirement

* gg: select Metal shaders for the default macOS backend

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* Merge commit from fork

* gg.render: add rewind, num_vertices and num_commands (#31218)

* gg.render: add rewind, num_vertices and num_commands

render.Context gains rewind(), num_vertices() and num_commands(), the
sokol_gl calls it replaces (sgl_rewind, sgl_num_vertices,
sgl_num_commands), so a client can discard a frame it abandons before
the pass starts without committing an empty frame, which would also
advance the frame index and rewind every other context.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbSAqfeVNTyrhAeRyWBpd1

* gg.render: reset recording state consistently after commit

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* cgen: avoid double-dropping runtime-owned map keys (#31223)

* parser: preserve keyword fields after match defaults (#31226)

* types: check quoted labels in raw inline assembly (#31221)

* transform: preserve nested array initializer clone decisions (#31222)

* transform: retain clone decisions in nested array initializers

* types: exercise clone-copy cache lifecycle in normal tests

* build(deps): bump docker/login-action from 4.6.0 to 4.7.0 (#31224)

Bumps [docker/login-action](https://github.com/docker/login-action) from 4.6.0 to 4.7.0.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/dbcb813823bdd20940b903addbd779551569679f...81c6f93d4bc991e510b342a00b419b3bb4efc5c6)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-version: 4.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* cgen: judge a cached module header's C includes by all of the module's sources (#31227)

A cached module header stands for all the sources of its module, but
core_native_header_is_redeclared judged its includes by the first one only
(cached_header_sources). A build that read a module from its header therefore
kept a shipped binding such as v.cmdexec's cmdexec_poll.h (cmdexec_pipe.c.v)
or os's <sys/mman.h> (mmap_nix.c.v) as an SDK include and switched the
program to the system libc preamble, while the build that parsed the module
from source did not. The two generated different C, so the object of the
builtin bundle that the build from source published was keyed
`system_libc_headers=false`, and the warm builds looked it up under
`system_libc_headers=true`.

Since #31069 the tests of the compiler's modules keep the cache, so each warm
build of such a test (vlib/v/gen/c, vlib/v/types, ...) missed builtin's
object, restarted from source and populated the cache again, every time.
#31154 made an exception for os's <sys/mman.h>; cmdexec_poll.h still misses.

FlatAst.cached_header_module_sources now maps each header to all the sources of
its module, and an include in a header is redeclared when it is for one of
them. This replaces the exception for os. A warm `v test` of
vlib/v/gen/c/main_argument_names_test.v now finds every object and takes
4.4 s, against 9.3 s.

* toml: parse repeated hexadecimal digits without stripping prefixes (#31225)

* fix: allow toml parsing of HEX value with repeating b characters

* fix: allow toml parsing of HEX value with repeating b characters

* toml: preserve invalid numeric rejection beside repeated hex digits

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* gg: restore the selected pipeline after drawing text (#31220)

* gg: re-fit the scale on Android resize instead of resetting it to 1

The .resized handler set ctx.scale = dpi_scale(), which is always 1 on
Android — sapp reports no DPI there — throwing away the fit of the
design size to the framebuffer that set_scale computes at startup. A
rotation left the layout on the old fit and the frame at scale 1.
set_scale handles both: the fit on Android, the DPI scale elsewhere.

* gg/render: restore the default pipeline after each recorded batch

A loaded pipeline stayed on the stack forever: text rendering loads the
font shader pipeline, which reads the texture's red channel as alpha,
and every batch recorded after any text draw — ui2's gl surface quad
among them — ran with it, painting the vertex colour where a texture
was asked and the texture's red channel where alpha was. Videos and
images drew as a static colour whose alpha cycled; an untextured quad
under it drew white. sokol-gl resets the pipeline at begin; this
renderer loads it per batch before begin (text and the translucent
draw helpers), so restoring after the batch is recorded keeps both
orders working.

* fix: math/floor.v type mismatch

* gg: re-fit the scale on Android resize instead of resetting it to 1

The .resized handler set ctx.scale = dpi_scale(), which is always 1 on
Android — sapp reports no DPI there — throwing away the fit of the
design size to the framebuffer that set_scale computes at startup. A
rotation left the layout on the old fit and the frame at scale 1.
set_scale handles both: the fit on Android, the DPI scale elsewhere.

* gg/render: restore the default pipeline after each recorded batch

A loaded pipeline stayed on the stack forever: text rendering loads the
font shader pipeline, which reads the texture's red channel as alpha,
and every batch recorded after any text draw — ui2's gl surface quad
among them — ran with it, painting the vertex colour where a texture
was asked and the texture's red channel where alpha was. Videos and
images drew as a static colour whose alpha cycled; an untextured quad
under it drew white. sokol-gl resets the pipeline at begin; this
renderer loads it per batch before begin (text and the translucent
draw helpers), so restoring after the batch is recorded keeps both
orders working.

* fix: math/floor.v type mismatch

* gg: scope the font pipeline and preserve batch selections

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* cleanup: remove remaining deprecated size aliases (#31203)

* cleanup: remove deprecated {i,u}size from vlib

* strconv: preserve legacy signed formatting and compatibility coverage

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>

* driver: remove implicit test binaries after execution (#31236)

* cache: reuse bootstrap builtin objects in test builds (#31219)

* cache: retain builtin objects across test compilations

* checker: recognize builtin lifecycle attributes

* cache: stabilize ignored local names across source reparsing

* transform: preserve generic struct map return types

* cache: preserve error dispatch IDs and portable make warmups

* net.openssl: honor TLS server upgrade verification and ALPN config (#31238)

* net.smtp: bound TLS test server accept and publish ready port atomically (#31239)

* fontstash: isolate implementation from generated translation units

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>
Co-authored-by: berce <75228263+bercedev@users.noreply.github.com>
Co-authored-by: Jengro <avey777@outlook.com>
Co-authored-by: diviocity <diviocity@disroot.org>
Co-authored-by: Albris W <admin@albrisllc.com>
Co-authored-by: eris <250676896+uaaw@users.noreply.github.com>
Co-authored-by: Tomas Zbk <85851175+tomaszbk@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Richard Wheeler <Richard_Wheeler@rjew.info>
This commit is contained in:
4 files changed
+70 -49

No files matched your search

+45 -40
View File
@@ -103,6 +103,50 @@ struct FONStextIter {
};
typedef struct FONStextIter FONStextIter;
// Shared context layout for the V and sokol bindings.
#ifndef FONS_VERTEX_COUNT
# define FONS_VERTEX_COUNT 1024
#endif
#ifndef FONS_MAX_STATES
# define FONS_MAX_STATES 20
#endif
typedef struct FONSfont FONSfont;
typedef struct FONSatlas FONSatlas;
struct FONSstate
{
int font;
int align;
float size;
unsigned int color;
float blur;
float spacing;
};
typedef struct FONSstate FONSstate;
struct FONScontext
{
FONSparams params;
float itw,ith;
unsigned char* texData;
int dirtyRect[4];
FONSfont** fonts;
FONSatlas* atlas;
int cfonts;
int nfonts;
float verts[FONS_VERTEX_COUNT*2];
float tcoords[FONS_VERTEX_COUNT*2];
unsigned int colors[FONS_VERTEX_COUNT];
int nverts;
unsigned char* scratch;
int nscratch;
FONSstate states[FONS_MAX_STATES];
int nstates;
void (*handleError)(void* uptr, int error, int val);
void* errorUptr;
};
typedef struct FONScontext FONScontext;
// Constructor and destructor.
@@ -118,6 +162,7 @@ FONS_DEF int fonsExpandAtlas(FONScontext* s, int width, int height);
FONS_DEF int fonsResetAtlas(FONScontext* stash, int width, int height);
// Add fonts
FONS_DEF int fonsAddFontMem(FONScontext* stash, const char* name, unsigned char* data, int dataSize, int freeData);
FONS_DEF int fonsGetFontByName(FONScontext* s, const char* name);
FONS_DEF int fonsAddFallbackFont(FONScontext* stash, int base, int fallback);
@@ -368,12 +413,6 @@ static int fons__tt_getGlyphKernAdvance(FONSttFontImpl *font, int glyph1, int gl
#ifndef FONS_INIT_ATLAS_NODES
# define FONS_INIT_ATLAS_NODES 256
#endif
#ifndef FONS_VERTEX_COUNT
# define FONS_VERTEX_COUNT 1024
#endif
#ifndef FONS_MAX_STATES
# define FONS_MAX_STATES 20
#endif
#ifndef FONS_MAX_FALLBACKS
# define FONS_MAX_FALLBACKS 20
#endif
@@ -427,18 +466,6 @@ struct FONSfont
int fallbacks[FONS_MAX_FALLBACKS];
int nfallbacks;
};
typedef struct FONSfont FONSfont;
struct FONSstate
{
int font;
int align;
float size;
unsigned int color;
float blur;
float spacing;
};
typedef struct FONSstate FONSstate;
struct FONSatlasNode {
short x, y, width;
@@ -452,29 +479,7 @@ struct FONSatlas
int nnodes;
int cnodes;
};
typedef struct FONSatlas FONSatlas;
struct FONScontext
{
FONSparams params;
float itw,ith;
unsigned char* texData;
int dirtyRect[4];
FONSfont** fonts;
FONSatlas* atlas;
int cfonts;
int nfonts;
float verts[FONS_VERTEX_COUNT*2];
float tcoords[FONS_VERTEX_COUNT*2];
unsigned int colors[FONS_VERTEX_COUNT];
int nverts;
unsigned char* scratch;
int nscratch;
FONSstate states[FONS_MAX_STATES];
int nstates;
void (*handleError)(void* uptr, int error, int val);
void* errorUptr;
};
#ifdef STB_TRUETYPE_IMPLEMENTATION
+1 -1
View File
@@ -1,6 +1,6 @@
module fontstash
#define FONS_USE_FREETYPE 1
#flag -DFONS_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
+2 -8
View File
@@ -1,21 +1,15 @@
module fontstash
#flag -I @VEXEROOT/thirdparty/fontstash
@[use_once]
#define FONTSTASH_IMPLEMENTATION
#flag @VEXEROOT/vlib/fontstash/fontstash_impl.c
$if gcboehm ? {
// The implementation header expands the collector's allocation macros.
#flag -DFONTSTASH_USE_GCBOEHM
$if tinyc && linux {
#include <gc/gc.h>
} $else {
#include <gc.h>
}
#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"
+22
View File
@@ -0,0 +1,22 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#if defined(FONTSTASH_USE_GCBOEHM)
// Darwin TinyCC defines __APPLE__ without __MACH__.
#if defined(__APPLE__) && !defined(GC_DARWIN_THREADS)
#define GC_DARWIN_THREADS 1
#endif
#if defined(__TINYC__) && defined(__linux__)
#include <gc/gc.h>
#else
#include <gc.h>
#endif
#define FONTSTASH_MALLOC GC_MALLOC
#define FONTSTASH_REALLOC GC_REALLOC
#define FONTSTASH_FREE GC_FREE
#define FONTSTASH_MALLOC_ATOMIC GC_MALLOC_ATOMIC
#endif
#define FONTSTASH_IMPLEMENTATION
#include "fontstash.h"