Skip to content

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

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

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions