Skip to content

Feature Request: Add public API to remove font faces from the global cache #258

@Lpsd

Description

@Lpsd

Currently, LunaSVG provides APIs to add font faces to the global font cache:

lunasvg_add_font_face_from_file()
lunasvg_add_font_face_from_data()

However, there is no corresponding API to remove a font face from the cache. This makes it impossible to properly manage font lifecycle in applications that need to dynamically load and unload fonts.

In our application (Multi Theft Auto), we allow users to register custom fonts for SVG rendering at runtime via 'resources'. When a resource (similar to a plugin/module) is unloaded, we need to clean up all associated fonts. Without a removal API:

  1. Memory leak: The font data passed to lunasvg_add_font_face_from_data() with a destroy_func callback is never freed because the internal plutovg_font_face_cache holds a reference indefinitely.
  2. Font name conflicts: The cache uses the font family name as a lookup key. When lunasvg_add_font_face_from_data() is called with a family name that already exists in the cache, the behavior is undefined from the API consumer's perspective
  3. No cleanup path: Applications have no way to release font resources without terminating.

The proposal is to add a public API such as lunasvg_remove_font_face() to address this.

Using LunaSVG version: 3.5.0 (PlutoVG bundled)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions