sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Fonts are not rendered correctly when using an svg

Open isaacfink opened this issue 1 year ago • 7 comments

Question about an existing feature

What are you trying to achieve?

Render an svg with the fonts

The fonts are not on the host os (end user can upload fonts) but I am downloading all of ti to a temp folder and setting the env for font config

When you searched for similar issues, what did you find that might be related?

I saw that I need to provide the FONTCONFIG_PATH and the first line in my code is this process.env.FONTCONFIG_PATH = TEMP_FILES_FONTS The svgs are rendering correctly but the font is using the default font, I am using the fontname library to extract the name from the fonts

isaacfink avatar Jun 29 '23 11:06 isaacfink

Use the FC_DEBUG environment variable to help debug font discovery.

https://sharp.pixelplumbing.com/install#fonts https://www.freedesktop.org/software/fontconfig/fontconfig-user.html

lovell avatar Jun 29 '23 13:06 lovell

@lovell adding FC_DEBUG doesn't output anything, here is my script

process.env.FONTCONFIG_PATH = TEMP_FILES_FONTS;
process.env.FC_DEBUG = '1';

this is at the top of the file

isaacfink avatar Jun 29 '23 15:06 isaacfink

Make sure these are set before require('sharp') is called, and ideally before the process starts.

lovell avatar Jun 29 '23 16:06 lovell

I have set it before importing sharp and also did the following

  1. added FC_DEBUG = 1 to my .env file
  2. added this to the dev script, export FC_DEBUG=1 && vite dev

still no logs

isaacfink avatar Jun 29 '23 20:06 isaacfink

Is the FC_CONFIG supposed to be a directory with fonts or a fontconfig file with entries for each font? If the latter can I set whatever family names I want for fonts? That was another pain point

isaacfink avatar Jun 29 '23 20:06 isaacfink

FONTCONFIG_PATH is an absolute path, without the trailing slash, to a directory containing a custom fonts.conf file.

lovell avatar Jun 30 '23 08:06 lovell

@isaacfink Were you able to make any progress with this?

lovell avatar Sep 27 '23 08:09 lovell

Closing due to inactivity but please feel free to reopen with more details if further help is required.

lovell avatar May 16 '24 12:05 lovell