neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

commit 6873478b8367768430216c40b21c85fb27e30408
parent 36158a8eed8df59a32c11554a2c6fda2510adb54
Author: cowmonk <cowmonk@based.pt>
Date:   Sun, 22 Nov 2026 21:42:28 -0700

include actual patches used and new README

Diffstat:
AREADME | 18++++++++++++++++++
Apatches/glyphByName.patch | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/inkBoxInTextExtents.patch | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/pixmanClipFillsToTarget.patch | 39+++++++++++++++++++++++++++++++++++++++
Apatches/setClipRectangle.patch | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 353 insertions(+), 0 deletions(-)

diff --git a/README b/README @@ -0,0 +1,18 @@ +neuwld +====== + +NOTE: This is a fork with nice QOL patches from MICE. This will likely be archived once all the patches are upstreamed. +See ./patches for all the patches added. + +neuwld is a drawing library that targets Wayland. The [swc Wayland compositor +library](https://github.com/michaelforney/swc) uses wld. + +Installing +========== +To build and install neuwld, simply use: + +```Bash +muon setup build +ninja -C build +muon -C build install +``` diff --git a/patches/glyphByName.patch b/patches/glyphByName.patch @@ -0,0 +1,60 @@ +From 330cd44b2c2b785a41ec5022a47c911ed0b91491 Mon Sep 17 00:00:00 2001 +From: xplshn <anto@xplshn.com.ar> +Date: Mon, 16 Nov 2026 13:26:14 -0300 +Subject: [PATCH 3/4] font: find a glyph by name + +--- + font.c | 20 ++++++++++++++++++++ + wld.h | 5 +++++ + 2 files changed, 25 insertions(+) + +diff --git a/font.c b/font.c +index 5ff011a..0cf6ae3 100644 +--- a/font.c ++++ b/font.c +@@ -205,6 +205,26 @@ wld_font_ensure_char(struct wld_font *font_base, uint32_t character) + return font_ensure_glyph(font, glyph_index); + } + ++EXPORT ++uint32_t ++wld_font_char_by_name(struct wld_font *font_base, const char *name) ++{ ++ struct font *font = (void *)font_base; ++ FT_UInt glyph_index, index; ++ FT_ULong c; ++ ++ if (!FT_HAS_GLYPH_NAMES(font->face)) ++ return 0; ++ glyph_index = FT_Get_Name_Index(font->face, (FT_String *)name); ++ if (!glyph_index) ++ return 0; ++ for (c = FT_Get_First_Char(font->face, &index); index; c = FT_Get_Next_Char(font->face, c, &index)) { ++ if (index == glyph_index) ++ return c; ++ } ++ return 0; ++} ++ + EXPORT + void + wld_font_text_extents_n(struct wld_font *font_base, +diff --git a/wld.h b/wld.h +index 47ef77c..887e9b4 100644 +--- a/wld.h ++++ b/wld.h +@@ -140,6 +140,11 @@ void wld_font_close(struct wld_font *font); + */ + bool wld_font_ensure_char(struct wld_font *font, uint32_t character); + ++/** ++ * The character that draws the glyph called name, or 0. ++ */ ++uint32_t wld_font_char_by_name(struct wld_font *font, const char *name); ++ + /** + * Calculate the text extents of the given UTF-8 string. + * +-- +2.56.1 + diff --git a/patches/inkBoxInTextExtents.patch b/patches/inkBoxInTextExtents.patch @@ -0,0 +1,76 @@ +From abc6ef868423b46260a5c749ed34c51e679ab828 Mon Sep 17 00:00:00 2001 +From: xplshn <noreply@localhost> +Date: Mon, 16 Nov 2026 10:39:25 -0300 +Subject: [PATCH 2/4] font: ink box in text extents + +--- + font.c | 28 +++++++++++++++++++++++++++- + wld.h | 7 +++++++ + 2 files changed, 34 insertions(+), 1 deletion(-) + +diff --git a/font.c b/font.c +index cbb187c..5ff011a 100644 +--- a/font.c ++++ b/font.c +@@ -216,6 +216,9 @@ wld_font_text_extents_n(struct wld_font *font_base, + uint32_t c; + FT_UInt glyph_index; + ++ struct glyph *glyph; ++ int32_t x1 = INT32_MAX, y1 = INT32_MAX, x2 = INT32_MIN, y2 = INT32_MIN; ++ + extents->advance = 0; + + while ((ret = FcUtf8ToUcs4((FcChar8 *)text, &c, length)) > 0 && c != '\0') { +@@ -226,6 +229,29 @@ wld_font_text_extents_n(struct wld_font *font_base, + if (!font_ensure_glyph(font, glyph_index)) + continue; + +- extents->advance += font->glyphs[glyph_index]->advance; ++ glyph = font->glyphs[glyph_index]; ++ if (glyph->bitmap.width && glyph->bitmap.rows) { ++ int32_t gx = (int32_t)extents->advance + glyph->x; ++ ++ if (gx < x1) ++ x1 = gx; ++ if (glyph->y < y1) ++ y1 = glyph->y; ++ if (gx + (int32_t)glyph->bitmap.width > x2) ++ x2 = gx + glyph->bitmap.width; ++ if (glyph->y + (int32_t)glyph->bitmap.rows > y2) ++ y2 = glyph->y + glyph->bitmap.rows; ++ } ++ extents->advance += glyph->advance; ++ } ++ ++ if (x1 > x2) { ++ extents->ink_x = extents->ink_y = 0; ++ extents->ink_width = extents->ink_height = 0; ++ return; + } ++ extents->ink_x = x1; ++ extents->ink_y = y1; ++ extents->ink_width = x2 - x1; ++ extents->ink_height = y2 - y1; + } +diff --git a/wld.h b/wld.h +index 8191ae3..47ef77c 100644 +--- a/wld.h ++++ b/wld.h +@@ -90,6 +90,13 @@ void wld_destroy_context(struct wld_context *context); + + struct wld_extents { + uint32_t advance; ++ ++ /** ++ * The box the glyphs cover, from the pen origin on the baseline. ++ * Only wld_font_text_extents sets it. ++ */ ++ int32_t ink_x, ink_y; ++ uint32_t ink_width, ink_height; + }; + + struct wld_font { +-- +2.56.1 + diff --git a/patches/pixmanClipFillsToTarget.patch b/patches/pixmanClipFillsToTarget.patch @@ -0,0 +1,39 @@ +From 67dc537b00c583a71b64b86f3ca2fdbf2c233a0c Mon Sep 17 00:00:00 2001 +From: xplshn <anto@xplshn.com.ar> +Date: Sat, 21 Nov 2026 11:49:18 -0300 +Subject: [PATCH 1/4] pixman: clip fills to the target + +A fill past the buffer edge wrote out of bounds. +--- + pixman.c | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +diff --git a/pixman.c b/pixman.c +index ed7788f..afd8ae6 100644 +--- a/pixman.c ++++ b/pixman.c +@@ -258,8 +258,19 @@ renderer_set_target(struct wld_renderer *base, struct buffer *buffer) + if (renderer->target) + pixman_image_unref(renderer->target); + +- if (buffer) +- return (renderer->target = pixman_image(buffer)); ++ if (buffer) { ++ pixman_region32_t clip; ++ ++ if (!(renderer->target = pixman_image(buffer))) ++ return false; ++ ++ /* solid fills only clip against an explicit region */ ++ pixman_region32_init_rect(&clip, 0, 0, buffer->base.width, ++ buffer->base.height); ++ pixman_image_set_clip_region32(renderer->target, &clip); ++ pixman_region32_fini(&clip); ++ return true; ++ } + + renderer->target = NULL; + return true; +-- +2.56.1 + diff --git a/patches/setClipRectangle.patch b/patches/setClipRectangle.patch @@ -0,0 +1,160 @@ +From dc00445a35f3369faaea6dbaef67b1b4357665a5 Mon Sep 17 00:00:00 2001 +From: xplshn <noreply@localhost> +Date: Mon, 16 Nov 2026 12:46:16 -0300 +Subject: [PATCH 4/4] renderer: add wld_set_clip + +Returns false when the renderer cant clip. +--- + interface/renderer.h | 7 +++++++ + pixman.c | 29 +++++++++++++++++++++++------ + renderer.c | 11 +++++++++++ + wld-private.h | 2 ++ + wld.h | 7 +++++++ + 5 files changed, 50 insertions(+), 6 deletions(-) + +diff --git a/interface/renderer.h b/interface/renderer.h +index ed34b3d..1c5e693 100644 +--- a/interface/renderer.h ++++ b/interface/renderer.h +@@ -47,6 +47,10 @@ static void renderer_draw_text(struct wld_renderer *renderer, + int32_t x, int32_t y, + const char *text, uint32_t length, + struct wld_extents *extents); ++#ifdef RENDERER_IMPLEMENTS_CLIP ++static void renderer_set_clip(struct wld_renderer *renderer, int32_t x, int32_t y, ++ uint32_t width, uint32_t height); ++#endif + static void renderer_flush(struct wld_renderer *renderer); + static void renderer_destroy(struct wld_renderer *renderer); + +@@ -65,6 +69,9 @@ static const struct wld_renderer_impl wld_renderer_impl = { + .draw_circle = &wld_draw_circle, + .draw_line = &wld_draw_line, + .draw_text = &renderer_draw_text, ++#ifdef RENDERER_IMPLEMENTS_CLIP ++ .set_clip = &renderer_set_clip, ++#endif + .flush = &renderer_flush, + .destroy = &renderer_destroy + }; +diff --git a/pixman.c b/pixman.c +index afd8ae6..2ebe613 100644 +--- a/pixman.c ++++ b/pixman.c +@@ -37,6 +37,7 @@ + struct pixman_renderer { + struct wld_renderer base; + pixman_image_t *target; ++ uint32_t target_width, target_height; + pixman_glyph_cache_t *glyph_cache; + }; + +@@ -53,6 +54,7 @@ struct pixman_map { + + #include "interface/context.h" + #define RENDERER_IMPLEMENTS_REGION ++#define RENDERER_IMPLEMENTS_CLIP + #include "interface/buffer.h" + #include "interface/renderer.h" + IMPL(pixman_renderer, wld_renderer) +@@ -259,16 +261,13 @@ renderer_set_target(struct wld_renderer *base, struct buffer *buffer) + pixman_image_unref(renderer->target); + + if (buffer) { +- pixman_region32_t clip; +- + if (!(renderer->target = pixman_image(buffer))) + return false; + + /* solid fills only clip against an explicit region */ +- pixman_region32_init_rect(&clip, 0, 0, buffer->base.width, +- buffer->base.height); +- pixman_image_set_clip_region32(renderer->target, &clip); +- pixman_region32_fini(&clip); ++ renderer->target_width = buffer->base.width; ++ renderer->target_height = buffer->base.height; ++ renderer_set_clip(base, 0, 0, buffer->base.width, buffer->base.height); + return true; + } + +@@ -276,6 +275,24 @@ renderer_set_target(struct wld_renderer *base, struct buffer *buffer) + return true; + } + ++void ++renderer_set_clip(struct wld_renderer *base, int32_t x, int32_t y, ++ uint32_t width, uint32_t height) ++{ ++ struct pixman_renderer *renderer = pixman_renderer(base); ++ pixman_region32_t clip, bounds; ++ ++ if (!renderer->target) ++ return; ++ pixman_region32_init_rect(&bounds, 0, 0, renderer->target_width, ++ renderer->target_height); ++ pixman_region32_init_rect(&clip, x, y, width, height); ++ pixman_region32_intersect(&clip, &clip, &bounds); ++ pixman_image_set_clip_region32(renderer->target, &clip); ++ pixman_region32_fini(&clip); ++ pixman_region32_fini(&bounds); ++} ++ + void + renderer_fill_rectangle(struct wld_renderer *base, uint32_t color, + int32_t x, int32_t y, +diff --git a/renderer.c b/renderer.c +index 2f49bc8..7315a82 100644 +--- a/renderer.c ++++ b/renderer.c +@@ -286,6 +286,17 @@ wld_draw_text(struct wld_renderer *renderer, + extents); + } + ++EXPORT ++bool ++wld_set_clip(struct wld_renderer *renderer, int32_t x, int32_t y, ++ uint32_t width, uint32_t height) ++{ ++ if (!renderer->impl->set_clip) ++ return false; ++ renderer->impl->set_clip(renderer, x, y, width, height); ++ return true; ++} ++ + EXPORT + void + wld_flush(struct wld_renderer *renderer) +diff --git a/wld-private.h b/wld-private.h +index 5a02630..9ab1115 100644 +--- a/wld-private.h ++++ b/wld-private.h +@@ -116,6 +116,8 @@ struct wld_renderer_impl { + struct font *font, uint32_t color, + int32_t x, int32_t y, const char *text, uint32_t length, + struct wld_extents *extents); ++ void (*set_clip)(struct wld_renderer *renderer, int32_t x, int32_t y, ++ uint32_t width, uint32_t height); + void (*flush)(struct wld_renderer *renderer); + void (*destroy)(struct wld_renderer *renderer); + }; +diff --git a/wld.h b/wld.h +index 887e9b4..0e4d29a 100644 +--- a/wld.h ++++ b/wld.h +@@ -284,6 +284,13 @@ void wld_draw_line(struct wld_renderer *renderer, uint32_t color, + * @param extents If not NULL, will be initialized to the extents of the + * drawn text + */ ++/** ++ * Limit drawing to a rectangle of the target. Setting a target resets it. ++ * Returns false when the renderer cannot clip. ++ */ ++bool wld_set_clip(struct wld_renderer *renderer, int32_t x, int32_t y, ++ uint32_t width, uint32_t height); ++ + void wld_draw_text(struct wld_renderer *renderer, + struct wld_font *font, uint32_t color, + int32_t x, int32_t y, const char *text, uint32_t length, +-- +2.56.1 +