I have this problem with variable fonts and was wondering if someone has an idea for a solution. I have built this poster-generator, using variable fonts, where you can manipulate the font-variation-settings on two axes. Here is a live example http://automat.markjulienhahn.de
Now I am trying to download the result via html2canvas. Unfortunately it seems like canvas-objects do not support variable fonts, so the canvas-object can only show one state of the font and the fontVariationSettings don't have any effect.
This is how I pull the canvas element:
<script src="html2canvas.min.js"></script>
<script>
var app = new Vue({
el: '#app',
methods: {
saveCanvas(){
html2canvas(document.querySelector("#capture")).then(
canvas => {
document.body.appendChild(canvas);
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
console.log(image);
window.location.href=image;
});
}
}
})
</script>
And this is how I manipulate the Variable Font.
function randomizeState() {
randomWeight = Math.floor(Math.random(1,100) * 100);
randomWidth = Math.floor(Math.random(1,100) * 100);
document.getElementById("element").style.fontVariationSettings = "\"frst\" " + randomWeight + ", \"scnd\" " + randomWidth;
document.getElementById("state1").innerHTML = randomWeight + " " + randomWidth;
}
I would appreciate any help!