lovell / lovell/sharp

SVG text-decoration not inherited by nested tspan element

Open
#3,240 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

blocked-upstream-dependency
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

## Possible bug

### Is this a possible bug in a feature of sharp, unrelated to installation?

- [x] Running `npm install sharp` completes without error.
- [x] Running `node -e "require('sharp')"` completes without error.

If you cannot confirm both of these, please open an [installation issue](https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md) instead.

### Are you using the latest version of sharp?

- [x] I am using the latest version of `sharp` as reported by `npm view sharp dist-tags.latest`.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of `sharp` that is not the latest, please open an issue against that package instead.

### What is the output of running `npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp`?

System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 1.49 GB / 15.86 GB

Binaries:
Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
npm: 8.1.3 - C:\Program Files\nodejs\npm.CMD

npmPackages:
sharp: ^0.30.5 => 0.30.5

### What are the steps to reproduce?

Sharp is not adding text-decoration underline to the converted image.

### What is the expected behaviour?

The text is underlined.

### Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

This is a simple function to convert an SVG (encoded in base64) to png and return the converted image. Is part of an NodeJS/ExpressJS API. It receives the buffer, returns a bitmap.

```javascript
async convertSVG(svgData) {
let buffer = Buffer.from(svgData, "base64");

const sharp = require("sharp");
let tempFileName = path.join("temp.png");

await sharp(Buffer.from(buffer, "utf-8"), {
density: 300,
})
.png()
.toFile(tempFileName)
.then(() => {})
.catch((err) => {
// Logger.error(err);
return [400, "Could not convert SVG"];
});

buffer = fs.readFileSync(tempFileName);

const rimraf = require("rimraf");
rimraf(tempFileName, () => {}); // Remove temp file

return [200, buffer.toString("base64")];
}
```

This is the SVG, created with [FabricJS](https://github.com/fabricjs/fabric.js) and exported with `canvas.toSVG();`, but its not related to FabricJS

```svg

```

### Please provide sample image(s) that help explain this problem

This is the output of [www.svgviewer.dev](https://www.svgviewer.dev/), as you can see, the text is underlined.
![svgviewer-png-output](https://user-images.githubusercontent.com/92321864/170541885-0052f0ac-c3bd-49f2-97b8-432651e21ad1.png)

This is the output from sharp, the text is not underlined
![descarga](https://user-images.githubusercontent.com/92321864/170542614-19f7daa7-6e42-4112-bf51-de757d737ce2.png)

Looks like text-decoration="underline" is not being processed. Same issue if the `text-decoration` property is removed and is added inside `style="text-decoration:underline; etc etc`

Contributor guide

Open the 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.

Research direction

Reproduce the issue using the supplied SVG with a nested tspan and the sharp conversion entry point, comparing the rendered output with the expected underlined text. Trace how sharp handles SVG text-decoration inheritance during conversion and verify the result against the provided examples; done means the nested tspan renders underlined without regressing other SVG text handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.