svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
269 stars 53 forks source link

Default Font Not Being Overridden #90

Closed calvinsomething closed 2 years ago

calvinsomething commented 2 years ago

I followed the Readme for setting the font like so:

const window = createSVGWindow()
registerWindow(window, window.document)

const canvas = SVG(window.document.documentElement) as Container

config
    .setFontDir(`${fontDir}`)
    .setFontFamilyMappings({"Jersey M54": "Jersey M54.ttf"})

canvas.text("TESTING").font("family", "Jersey M54")

The text works except for the font. I get this error:

Could not open font "sans-serif" in file "/fontDir/OpenSans-Regular.ttf". Error: ENOENT: no such file or directory, open '/fontDir/OpenSans-Regular.ttf'

I've tried using .preloadFonts() as well as .font({family: "Jersey M54"). I've also tried setting the config properties both before creating and right before registering the window. It's really hard to know what's going wrong because there's not really any documentation and the other Github issue that is similar to this is from an older version of the library.

Fuzzyma commented 2 years ago

Yoi create a text element and set the font afterwards. So it first tries to use the default font which it can't find in the font folder. That's why it throws

calvinsomething commented 2 years ago

Great, thank you.