sharp icon indicating copy to clipboard operation
sharp copied to clipboard

SVG font loading, Linux

Open warfrogsdf opened this issue 7 years ago • 5 comments

warfrogsdf avatar Feb 04 '19 15:02 warfrogsdf

os: linux node: v10+ i use : const buffer = <svg> <rect x="0" y="0" height="${textBgH}px" fill="none" width="100%"/> <text font-family="'Algerian'" font-size="${textH}px" font-weight="bolder" x="0" y="${textH}" fill="red" >${text}</text> </svg>;

sharp(Buffer.from(buffer)) .png() .toFile('text.png'); console.log(sharp.versions)

but cant use my custom font Algerian

warfrogsdf avatar Feb 04 '19 15:02 warfrogsdf

Hello, the numeric FC_DEBUG environment variable can be used to help debug font loading problems. Try a value of 1 to start with.

https://www.freedesktop.org/software/fontconfig/fontconfig-user.html#DEBUG

lovell avatar Feb 04 '19 15:02 lovell

i solve this problem by import font to os font lib。but this method s Maintainability is so poor,i hope sharp have api to load font from project one sub directory txs。

warfrogsdf avatar Feb 04 '19 17:02 warfrogsdf

SVG rendering depends on librsvg, which depends on the cross-platform fontconfig to locate fonts.

At the bottom of the fontconfig-user page I linked to are listed various environment variables that can be used to control it e.g. to specify custom, non-OS fontconfig directories.

lovell avatar Feb 04 '19 17:02 lovell

I am setting FC_DEBUG=1 node myscript.js but I don't see any new logging. Just to be sure, I also tried setting export FC_DEBUG=8191 in the cli and process.env.FC_DEBUG = '1' inside my script, but none of these are giving me any debugging info. I am feeling stupid right now... Is there any other way to set FC_DEBUG?

zvictor avatar Aug 28 '21 09:08 zvictor