replicad
replicad copied to clipboard
Allow fonts to be loaded from blobs / buffers, especially as font blobs become a supported browser feature
opentype.js exports a parse() function which accepts an ArrayBuffer and returns a Font object. It'd be great if Replicad exported a loadFont() variant which could call this, so that something like the following would work:
async function getBrowserFont(name) {
const fontDatas = await window.queryLocalFonts({ postscriptNames: [name] }));
const fontData = fontDatas[0];
return await fontData.blob();
}
async function main(replicad) {
const font = await replicad.loadFont(getBrowserFont('Helvetica'));
...
}
window.queryLocalFonts() is an existing experimental browser API (but, yeah, window isn't currently exposed to the Replicad main()): https://developer.mozilla.org/en-US/docs/Web/API/Window/queryLocalFonts
And even if that's not available, it'd be nice to be able to get my font buffer from wherever and not just from a URL (even though maybe a data URL would theoretically work? Still seems less than ideal compared to just using a straight buffer).