v4.0.0-rc3: SVG text rendering not working

Open
#2,619 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript, node.js

Research direction

Start with the minimal reproduction using createCanvas, loadImage, and drawImage, then trace the lunasvg SVG text path and compare its callbacks with the existing fillText functions. Done means SVG text renders instead of producing a blank image, with coverage added for SVG plus text rendering.

Written by the indexing model from the issue text.

Description

Bug

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.

Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Automattic/node-canvas

All issues in Automattic/node-canvas

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.