I have a problem loading .otf fonts in the latest Safari 15.2. This same code used to work just fine in previous versions of the same browser and still does work fine in other browsers.
One of the problematic fonts I experience the issue with is Adobe Gilbert.
I've tried loading the font file in two different ways:
@font-face {
font-family: gcb;
src: url(/assets/fonts/Gilbert-Color-Bold-Preview5.otf);
}
and
var selectedFont = new FontFace('gcb', 'url(/assets/fonts/Gilbert-Color-Bold-Preview5.otf)');
selectedFont.load().then(function(font) {
document.fonts.add(font);
});
(async () => {
const fontURL = "https://cdn.jsdelivr.net/gh/Fontself/TypeWithPride@master/fonts/Gilbert-Color%20Bold%20Preview_1005.otf";
const selectedFont = new FontFace('gcb', 'url(' + fontURL + ')');
await selectedFont.load();
document.fonts.add(selectedFont);
const canvas = document.querySelector("canvas");
ctx = canvas.getContext("2d", { alpha: false });
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, 300, 30);
ctx.font = "15pt gcb";
ctx.fillStyle = '#000';
ctx.fillText("I'm a canvas", 0, 20);
ctx.font = "15pt sans-serif";
ctx.fillText(", right?", 105, 20);
})().catch(console.error)
span, text {
font: 15pt gcb;
}
<canvas height=30></canvas><br>
<span>I'm a span</span><br>
<svg height=30><text y="15">I'm an SVG</text></svg>
In Safari I get nothing drawn in the canvas:
While on Chrome I get the text rendered in black, and in Firefox the text rendered in color as expected.
How can I get Safari to at least render the text like Chrome?