Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/fonts.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { mainWindow } from './window.js';
7
import type { IJSONSchemaSnippet } from '../common/jsonSchema.js';
8
import { isElectron, isMacintosh, isWindows } from '../common/platform.js';
9
10
/**
11
* The best font-family to be used in CSS based on the platform:
12
* - Windows: Segoe preferred, fallback to sans-serif
13
* - macOS: standard system font, fallback to sans-serif
14
* - Linux: standard system font preferred, fallback to Ubuntu fonts
15
*
16
* Note: this currently does not adjust for different locales.
17
*/
18
export const DEFAULT_FONT_FAMILY = isWindows ? '"Segoe WPC", "Segoe UI", sans-serif' : isMacintosh ? '-apple-system, BlinkMacSystemFont, sans-serif' : 'system-ui, "Ubuntu", "Droid Sans", sans-serif';
19
20
interface FontData {
21
readonly family: string;
22
}
23
24
export const getFonts = async (): Promise<string[]> => {
25
try {
26
// @ts-ignore
27
const fonts = await mainWindow.queryLocalFonts() as FontData[];
28
const fontsArray = [...fonts];
29
const families = fontsArray.map(font => font.family);
30
return families;
31
} catch (error) {
32
console.error(`Failed to query fonts: ${error}`);
33
return [];
34
}
35
};
36
37
38
export const getFontSnippets = async (): Promise<IJSONSchemaSnippet[]> => {
39
if (!isElectron) {
40
return [];
41
}
42
const fonts = await getFonts();
43
const snippets: IJSONSchemaSnippet[] = fonts.map(font => {
44
return {
45
body: `${font}`
46
};
47
});
48
return snippets;
49
};
50
51