-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Rendering SVGs with custom fonts on macOS #2399
Comments
Have you tried setting the fontconfig-related environment variables before the call to The |
Yes, I've tried using FC_DEBUG=1024 and setting the environment variables manually before even starting the node process. When I manually invoke When invoking But when rendering the SVG with sharp, it nevertheless doesn't use the custom fonts. |
The prebuilt binaries for macOS configure fontconfig with a default location of https://github.com/lovell/sharp-libvips/blob/master/build/lin.sh#L310 If you already have fontconfig installed via homebrew then you might need to run |
I still haven't been able to get this to work, but I'll try with a new minimal example from scratch this weekend. |
Thanks for the update, once you work it all out this is probably something to add to the docs. |
I'm having the same problem. I'm on macOS Catalina 10.15.7. I checked and I have fonts.conf in the path specified above. Running |
I got it to work. I was using Here's a trimmed down example: <svg xmlns="http://www.w3.org/2000/svg">
<style>
.myClass {
font-family: 'Suprema';
font-weight: 600;
}
</style>
<text class="myClass">Font renders correctly</text>
</svg> I wish I knew why this works. @gfmio hopefully this will fix it for you, too. |
If available, the
|
Pango (the text renderer used by librsvg) defaults to the CoreText rendering and mapping backend on macOS. You could try to use the Fontconfig backend with the |
Great sleuthing Kleis, I did not know this. Perhaps sharp should automagically set this env variable when using the prebuilt binaries? |
That could work. Alternatively, we might be able to build Pango without CoreText support by removing this: (Note that I'm not sure what the advantages of CoreText are compared to Fontconfig and vice versa) |
The env variable approach would allow the proposed new default setting of |
Commit ef964b5 changes the default behaviour of If required, setting |
sharp v0.27.0 now available, thanks for reporting this. |
sharp v0.27.1 will revert this change as it is causing too many problems - see #2515 If you require consistent cross-platform font behaviour, please continue to set |
What are you trying to achieve?
Render SVGs with custom fonts on macOS
Have you searched for similar questions?
Yes, and I've found the ones covering the usage of fonts.conf on Linux / in AWS Lambda.
I followed the same method and when running the code in a linux container, fontconfig gets updated correctly, logs the debug output and renders the custom fonts.
On macOS, the custom fonts do not get picked up, fontconfig does not give any debug output and the default fonts get rendered.
Curioiusly, on both macOS and Linux, the command shelljs command does list the custom fonts, so it seems to me that fontconfig does pick up the correct settings, but then the rendering step doesn't make use of the updated config.
Does sharp / librsvg not use fontconfig on macOS? Or is there something else I need to configure? If so, what?
Are you able to provide a minimal, standalone code sample that demonstrates this question?
Are you able to provide a sample image that helps explain the question?
The test image I'm rendering is:
The output on Linux:
The output on macOS:
The text was updated successfully, but these errors were encountered: