From f4bc9f1ecd72449dfdaf09ebbe6082833218504c Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 24 Jul 2022 19:47:18 -0700 Subject: [PATCH] Pull fonts using latest font access API in Chrome Part of #958 --- addons/xterm-addon-ligatures/src/font.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/xterm-addon-ligatures/src/font.ts b/addons/xterm-addon-ligatures/src/font.ts index 4075cc6c..3a3c799a 100644 --- a/addons/xterm-addon-ligatures/src/font.ts +++ b/addons/xterm-addon-ligatures/src/font.ts @@ -65,6 +65,22 @@ export default async function load(fontFamily: string, cacheSize: number): Promi console.error(err.name, err.message); } } + // Latest proposal + else if ('queryLocalFonts' in window) { + const fonts: Record = {}; + try { + const fontsIterator = await (window as any).queryLocalFonts(); // await (navigator as unknown as IFontAccessNavigator).fonts.query(); + for (const metadata of fontsIterator) { + if (!fonts.hasOwnProperty(metadata.family)) { + fonts[metadata.family] = []; + } + fonts[metadata.family].push(metadata); + } + fontsPromise = Promise.resolve(fonts); + } catch (err: any) { + console.error(err.name, err.message); + } + } // Node environment or no font access API else { try {