Skip to content

Commit

Permalink
Pull fonts using latest font access API in Chrome
Browse files Browse the repository at this point in the history
Part of xtermjs#958
  • Loading branch information
Tyriar committed Jul 25, 2022
1 parent b11217a commit f4bc9f1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions addons/xterm-addon-ligatures/src/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, IFontMetadata[]> = {};
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 {
Expand Down

0 comments on commit f4bc9f1

Please sign in to comment.