#3796·ebiten

text/v2/internal/oksvg: replace oksvg with an internal OpenType SVG renderer

Author: hajimehoshiCreated Sep 27, 2026Updated Sep 27, 2026
Labelsfeatureos:linuxos:windowsos:macosos:androidos:iosos:freebsdos:js

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

This is a platform-independent feature request. The exploratory GPU rendering comparisons described below were run on macOS only.

What feature would you like to be added?

Replace text/v2/internal/oksvg with an Ebitengine-owned implementation of OpenType SVG glyph parsing and rendering. Keep the implementation internal to text/v2, rather than introducing a public general-purpose SVG package.

Reuse encoding/xml and the existing vector package where appropriate. This does not initially require writing a new low-level rasterizer. Add general-purpose capabilities to vector when the rendering model needs them, particularly sample-aware path clipping.

Prerequisite: #3797 (vector path clipping). The clipping API and its interaction with group composition should be validated before the renderer depends on them.

Implementation plan

  1. Define the supported profile and acceptance corpus. Target the required capabilities of the OpenType SVG specification, and record which optional capabilities are supported. Select real SVG emoji fonts at fixed versions, with suitable test-data licenses, and inventory the constructs they use. The synthetic prototype is not sufficient evidence of font compatibility. Identify existing supported behavior that must not regress.
  2. Implement a retained document model. Parse XML into a tree, index IDs, and resolve references independently of document order. Preserve group boundaries, ancestor transforms and inherited properties, original curve commands, paint definitions, and clipping relationships. Select the requested glyph from a shared SVG document without losing ancestor context or shared definitions. Bound input size, nesting, reference expansion, decoded images, and rendering allocations.
  3. Implement OpenType SVG semantics. Cover paths and basic shapes, transforms and viewport mapping, fill rules, fills and strokes, linear/radial gradients and their references, clipping, opacity, embedded PNG/JPEG images, and currentColor. Define foreground/palette inputs and support for CPAL color variables and fallbacks. Handle inheritance separately from group opacity. Scope optional CSS, filters, masks, and other optional features explicitly instead of accidentally accumulating general browser-SVG support.
  4. Build the GPU renderer on vector. Generate geometry at an appropriate output-dependent accuracy, evaluate paint, and compose isolated opacity groups. Implement sample-aware clipping through the separate vector clipping feature. Validate nested clipping and groups together before finalizing the rendering interfaces: multiplying resolved alpha masks is insufficient for shared edges. Gradient painting can initially use coverage images and shaders; a dedicated path-paint API is an optional later optimization.
  5. Integrate lifecycle, caching, and fallback. Keep parsing CPU-only and GPU rendering within the Ebitengine graphics lifecycle. Cache parsed documents and rendered glyphs with the relevant size, subpixel-position, foreground, and palette inputs. Distinguish malformed data, unsupported features, valid empty glyphs, and successful rendering, and define when outline fallback is appropriate. Avoid silently rendering incomplete artwork.
  6. Evaluate a size-dependent quality policy. Start by evaluating 2x rendering for glyph bitmaps whose longest output dimension is at most 32 physical pixels, with native rendering above that. The threshold is provisional and internal, not a public API guarantee. Compare real glyphs at actual display size before selecting a default; retain 4x as an experimental comparison. Clipping correctness must hold at every quality level.
  7. Validate and replace the fork. Compare the real-font corpus and focused fixtures against an independent reference renderer. Exercise malformed input and reference expansion with fuzzing, and check multiple graphics backends. Measure uncached generation time, cache-hit behavior, and memory on representative workloads. Remove oksvg, and any dependencies no longer used elsewhere, only after the replacement passes these checks.

The replacement should not require applications to change their normal text/v2 drawing calls. Exact internal interfaces and any new vector APIs remain subject to the clipping/group-composition prototype.

Why is this needed?

The current fork has attracted many AI-assisted bug reports involving parsing, references, inherited state, colors, and rendering. The reviewed issue-tracking sheet contained 69 rows mentioning oksvg in the file-path column: 28 marked unresolved, 18 duplicate, 13 resolved, and 10 cancelled. These are tracker statuses, not 69 independently confirmed defects. Some reports concern capabilities outside the required OpenType SVG profile, so the raw report count alone is not a justification for a rewrite.

The stronger reason is the recurring mismatch between the representation and SVG semantics. Flattened paths and style-stack handling make reference expansion, group opacity, and clipping difficult to implement reliably. Missing features can also produce plausible but incorrect glyphs under IgnoreErrorMode.

An exploratory prototype at Ebitengine commit 3f273b3f52b9912926023938d38aec5ec9438f00 compared 12 synthetic fixtures at four sizes (16, 24, 64, and 256 pixels) and two offsets (0 and 0.375 pixels), giving 96 configurations. It compared oksvg/rasterx and five vector variants with librsvg 2.62.3/Cairo 1.18.4. The reference images were rendered at higher resolution and box-filtered down, with selected convergence checks.

Observed semantic differences:

  • A half-opacity group with overlapping opaque shapes produced overlap alpha 191 through oksvg, versus 128 through the reference and the prototype's isolated-group renderer.
  • The even-odd ring's center was filled through oksvg rather than remaining transparent.
  • A partial clip was ignored through oksvg.
  • Stroke widths did not follow the outer scaling in the tested oksvg fixtures.

These results mix SVG interpretation and rasterization behavior. They do not establish that rasterx's low-level coverage algorithm is intrinsically inferior.

The existing vector package was sufficient to produce gradients, transformed strokes, even-odd fills, and isolated opacity groups in the prototype. Supersampling improved small-detail coverage:

24px fixture Native vector AA 2x vector + box filter 4x vector + box filter
Synthetic emoji 2.39 0.85 0.31
Thin curved stroke 5.81 2.09 0.78
Radial gradient 2.09 0.66 0.29
Transformed stroke 6.88 2.32 0.79

Values are mean absolute premultiplied RGBA channel errors on a 0..255 scale, over pixels occupied by either image, averaged over both offsets. They are not perceptual quality scores. Native output can still look acceptable at actual size. A 2x intermediate has four times the pixels per surface; 4x has sixteen times. This experiment did not measure production rendering performance.

The prototype also identified requirements that a replacement must address:

  • Multiplying already-resolved shape and clip alpha thins shared edges. Supersampling reduces this error but does not eliminate it. Composing point samples before the final resolve preserved identical-shape clipping in all tested size/offset combinations.
  • Retaining original cubics matters at larger sizes. For the 256px thin curve, 4x rendering alone had error 1.55; subdividing the original cubics before constructing the vector path reduced it to 0.38. A filled-cubic control improved as well, independently of stroke expansion.

These results support a focused internal replacement using existing rendering primitives, with explicit semantics and quality requirements, rather than continuing an open-ended series of patches to the fork.

Rendering comparison at 24×24 pixels, enlarged 8× with nearest-neighbor scaling to make differences visible. Columns, left to right: supersampled librsvg reference, native vector AA, vector rendered at 2× and downsampled, vector rendered at 4× and downsampled, and the current oksvg/rasterx implementation. These synthetic fixtures illustrate differences in edge quality, clipping, group opacity, transformed strokes, and even-odd filling. The oksvg differences include unsupported or incorrect SVG semantics, not just rasterization quality. This is not a performance benchmark or a real-font compatibility test.

Image

Authored by Codex (OpenAI), on behalf of @hajimehoshi, following a rendering prototype and design discussion. The measurements above cover synthetic fixtures, not a complete emoji-font compatibility suite.