Skip to content

v4.0.0-rc3: SVG text rendering not working #2619

In review

Description

@iamlemec

Minimal reproduction:

import { createCanvas, loadImage } from 'canvas'

const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100">
  <text x="10" y="60" font-family="sans-serif" font-size="40" fill="red">Hello</text>
</svg>`

const img = await loadImage(Buffer.from(svg))
const canvas = createCanvas(200, 100)
const ctx = canvas.getContext('2d')
ctx.drawImage(img, 0, 0)

Resulting in a blank output image.

The issue is that the retriever/measurer/painter callbacks are not set when using lunasvg. So it gets no font data, and even if it did, the text would not be measured or painted. There are also no SVG + text tests.

I have a fix ready as well, two PRs: one here and one in the lunasvg fork. Basically it hooks these callbacks up and pipes them to the existing functions used in fillText. Just want to make sure this is a real issue before proceeding.

See forks here: node-canvas and lunasvg.

Activity

  1. chearon commented on Oct 11, 2026

    @chearon
    Collaborator

    Ah thanks for making this issue. I'm not sure why the retriever function isn't being set, because I know I got the feature working, but I think it's because I picked an old commit while rebasing or something. I'll have to look.

    As for the measurer and painter, that can be done in node-canvas before returning the font. The way I changed LunaSVG makes FontFace a public API.

    I'll post back when I know more...

  2. added this to the 4.0.0 milestone on Oct 20, 2026
  3. added 2 commits that reference this issue on Nov 29, 2026
    a500892
    f78e71a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions