Skip canvas being used during Control.serialize()?

So this is a strange one and I understand that this is not really a common use case.

For my Figma to BabylonJS Figma plug-in. I have decided to rewrite it to use actual BabylonJS controls from NPM rather than just using my own custom-made psedo-controls. This is worked very well for things like containers, lines, rectangle etc… however when I am on font I have noticed that my plug-in is crashing, showing the error message if I try to give it a new font size, style or weight.

Invalid engine. Unable to create a canvas.

Again, other controls will Serialize fine, however, when I try to serialise a text block that I have tried to change its font size or its weight or its style. I get that error.

The error message suggests that Babylon.js is trying to create a canvas to measure the text metrics (fontWeight/Stlye/Size, in this case). I think this is likely happening during the serialization process, as i assume Babylon.js needs to calculate these metrics to accurately serialize the TextBlock control?

My question is, is there a way that I could simply skip this?
I think it’s quite strange behaviour since this isn’t required for other elements. I understand that a lot of the text stuff reflects real world CSS. Just wanted to ask if it’s possible that I skip the creating a fake canvas.

The real question is: why does it fail to create it?

Figma plugins don’t have a canvas to access.

ooh I see! Please create an issue for me on the repo: I will add an option for you :slight_smile:

1 Like