Skip to content

Commit f4bc9f1

Browse files
committed
Pull fonts using latest font access API in Chrome
Part of xtermjs#958
1 parent b11217a commit f4bc9f1

File tree

1 file changed

+16
-0
lines changed
  • addons/xterm-addon-ligatures/src

1 file changed

+16
-0
lines changed

addons/xterm-addon-ligatures/src/font.ts

+16
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ export default async function load(fontFamily: string, cacheSize: number): Promi
6565
console.error(err.name, err.message);
6666
}
6767
}
68+
// Latest proposal
69+
else if ('queryLocalFonts' in window) {
70+
const fonts: Record<string, IFontMetadata[]> = {};
71+
try {
72+
const fontsIterator = await (window as any).queryLocalFonts(); // await (navigator as unknown as IFontAccessNavigator).fonts.query();
73+
for (const metadata of fontsIterator) {
74+
if (!fonts.hasOwnProperty(metadata.family)) {
75+
fonts[metadata.family] = [];
76+
}
77+
fonts[metadata.family].push(metadata);
78+
}
79+
fontsPromise = Promise.resolve(fonts);
80+
} catch (err: any) {
81+
console.error(err.name, err.message);
82+
}
83+
}
6884
// Node environment or no font access API
6985
else {
7086
try {

0 commit comments

Comments
 (0)