Skip to content
Draft
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
56 changes: 56 additions & 0 deletions frontend/src/state-providers/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,62 @@ export function createFontsState(editor: Editor) {
}
export type FontsState = ReturnType<typeof createFontsState>;

export type FontProvider = {
/**
* A display name for the font provider to show in the UI.
*/
displayName: string;

/**
* 32px icon for the font provider to show in the font management window.
*/
iconLarge: string;

needsBrowserPermissions: boolean;
needsNetwork: boolean;
web: boolean;
desktop: ("windows" | "macos" | "linux")[] | boolean;

/**
* Index all available typefaces.
*/
index(): Promise<void>;

/**
* Get a typeface by its name.
*/
getTypeface(name: string): Promise<Typeface | undefined>;

/**
* Load a font file for a given typeface and style.
*/
loadFont(typeface: string, styleName: string): Promise<Uint8Array>;

/**
* Get weight ranges for each font, for a given typeface.
*/
getWeights(typeface: string, styleName?: string): Promise<Record<string, [number, number]> | undefined>;
};

export type Typeface = {
postScriptName: string;
familyName: string;
fonts: FontStyle[];
isVariable: boolean;
isColorful: boolean;
hasMultipleWeights: boolean;
hasItalicVariants: boolean;
category: "serif" | "sans-serif" | "display" | "handwriting" | "monospace" | "other";
};

export type FontStyle = {
styleName: string;
group?: string;
weights: number | [number, number];
isItalic: boolean;
axes?: Record<string, [number, number]>;
};

const fontListAPI = "https://api.graphite.rs/font-list";

// From https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
Expand Down
Loading