Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG with dominant-baseline does not align percentage-based y coordinates properly #1996

Open
Pasukaru opened this issue Dec 4, 2019 · 1 comment

Comments

@Pasukaru
Copy link

Pasukaru commented Dec 4, 2019

What is the output of running npx envinfo --binaries --languages --system --utilities?

npx: installed 1 in 1.188s

  System:
    OS: macOS 10.15.1
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Memory: 450.53 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - /var/folders/l9/m0pyz89d1yj3566s_f86mb4c0000gn/T/fnm-shell-1301444/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.9.0 - /var/folders/l9/m0pyz89d1yj3566s_f86mb4c0000gn/T/fnm-shell-1301444/bin/npm
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.20.1 - /usr/local/bin/git
    Clang: 1100.0.33.12 - /usr/bin/clang
    Subversion: 1.10.4 - /usr/bin/svn
  Languages:
    Bash: 3.2.57 - /bin/bash
    Java: 11.0.1 - /usr/bin/javac
    Perl: 5.18.4 - /usr/bin/perl
    PHP: 7.3.9 - /usr/bin/php
    Python: 2.7.16 - /usr/bin/python
    Python3: 3.7.5 - /usr/local/bin/python3
    Ruby: 2.6.3 - /usr/bin/ruby

What are the steps to reproduce?
Using sharp ^0.23.3, run the code snippets in the examples below.

What is the expected behaviour?

The picture should contain a circle with the letters AB centered inside of it.
However, the text is centered horizontally, and offset vertically.

Are you able to provide a standalone code sample, without other dependencies, that demonstrates this problem?
Are you able to provide a sample image that helps explain the problem?

Current behaviour:

sharp(Buffer.from(`
<svg width="128" height="128">
  <g>
    <circle cx="64" cy="64" r="64" fill="#808080"></circle>
    <text x="50%" y="50%" font-family="Arial" font-weight="bold" font-size="48px" dominant-baseline="middle" text-anchor="middle" fill="white">AB</text>
  </g>
</svg>
`)).png().toFile('AB.png');

image

Expected behaviour (created by setting the offset manually, might be off by a few pixels):

sharp(Buffer.from(`
<svg width="128" height="128">
  <g>
    <circle cx="64" cy="64" r="64" fill="#808080"></circle>
    <text x="50%" y="80" font-family="Arial" font-weight="bold" font-size="48px" dominant-baseline="middle" text-anchor="middle" fill="white">AB</text>
  </g>
</svg>
`)).png().toFile('AB.png')

image

@Pasukaru Pasukaru added the triage label Dec 4, 2019
@kleisauke
Copy link
Contributor

librsvg currently does not support dominant-baseline (or alignment-baseline), see:
https://gitlab.gnome.org/GNOME/librsvg/issues/414

As a workaround, use dy=".25em" to shift the text along the y-axis or try to specify the offset manually (as you did).

@lovell lovell changed the title SVG renderer does not align percentage-based y coordinates properly SVG with dominant-baseline does not align percentage-based y coordinates properly Dec 4, 2019
@lovell lovell added enhancement and removed bug labels Jan 13, 2020
marcelgerber added a commit to owid/owid-grapher that referenced this issue Jun 7, 2021
Sharp, which we use to export svg -> png, doesn't support
`dominant-baseline` (lovell/sharp#1996).
Instead, we can just include a rough estimate of the offset ourselves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants