mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
Interpolate the book's body and heading families into the Typst preamble, title page, cover, and contents. Embed the needed bundled fonts and load any chosen system fonts (via fontdb) into the Typst engine so PDF preview and export match the on-screen fonts.
39 lines
851 B
TypeScript
39 lines
851 B
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
export const isDesktop = typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
|
|
|
|
export interface ImageInput {
|
|
path: string;
|
|
data: string;
|
|
}
|
|
|
|
export interface PdfFonts {
|
|
bundled: string[];
|
|
system: string[];
|
|
}
|
|
|
|
export async function compilePdf(
|
|
source: string,
|
|
images: ImageInput[] = [],
|
|
emitWarnings = false,
|
|
fonts: PdfFonts = { bundled: [], system: [] },
|
|
): Promise<Uint8Array> {
|
|
const buffer = await invoke<ArrayBuffer>("compile_pdf", {
|
|
source,
|
|
images,
|
|
emitWarnings,
|
|
bundledFonts: fonts.bundled,
|
|
systemFonts: fonts.system,
|
|
});
|
|
return new Uint8Array(buffer);
|
|
}
|
|
|
|
export async function listSystemFonts(): Promise<string[]> {
|
|
if (!isDesktop) return [];
|
|
try {
|
|
return await invoke<string[]>("list_system_fonts");
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|