samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.67k stars 63 forks source link

`context.font` doesn't update on alpine #134

Open 2fd opened 1 year ago

2fd commented 1 year ago

I'm trying to create an image inside a node container on alpine, but the prop front doesn't update if I assign a new value.

As a Proof of Concept I setup this repo https://github.com/2fd/poc-skia-canvas-context to show the error.

It runs the following test:

    // Create canvas  and context
    const canvas = new Canvas(100, 100)
    const context = canvas.getContext('2d')

    // Check default value
    expect(context.font).toBe('10px sans-serif')

    // Check update
    context.font = 'normal 600 20px/24px Times'
    expect(context.font).toBe('normal 600 20px/24px Times')

and run it on node 14, 16, 18, and 20 using slim and alpine and it fails on every version of alpine

Screenshot 2024-04-07 at 11 20 41 PM

the value of font never was updated

Screenshot 2023-01-23 at 01 15 49
arthurbdev commented 5 months ago

Did you find a workaround?

2fd commented 5 months ago

~no, I didn't~

2fd commented 5 months ago

Hi @arthurbdev, after digging a little bit a found the root cause here. If you try to update the context with a font that is not present on your distro it will ignore any other change. In which case the solution will be to install the font you will use.

I have tested it and it worked just fine: Screenshot 2024-04-07 at 11 50 11 PM