Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get ligatures addon working with latest version of Chrome #3936

Merged
merged 5 commits into from
Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion 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 https://bugs.chromium.org/p/chromium/issues/detail?id=1312603
else if (typeof process !== 'object' && 'queryLocalFonts' in window) {
const fonts: Record<string, IFontMetadata[]> = {};
try {
const fontsIterator = await (window as any).queryLocalFonts();
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 All @@ -90,7 +106,9 @@ export default async function load(fontFamily: string, cacheSize: number): Promi
if (fonts.hasOwnProperty(family) && fonts[family].length > 0) {
const font = fonts[family][0];
if ('blob' in font) {
return loadBuffer(await (await font.blob()).arrayBuffer(), { cacheSize });
const bytes = await font.blob();
const buffer = await bytes.arrayBuffer();
return loadBuffer(buffer, { cacheSize });
}
return await loadFile(font.path, { cacheSize });
}
Expand Down