Skip fonts inlining for library items

This commit is contained in:
Marcel Mraz 2024-08-19 17:40:50 +02:00
parent 25c3256908
commit 8ee20225cf
7 changed files with 15 additions and 8 deletions

View File

@ -133,6 +133,7 @@ const SingleLibraryItem = ({
exportBackground: true, exportBackground: true,
}, },
files: null, files: null,
skipInliningFonts: true,
}); });
node.innerHTML = svg.outerHTML; node.innerHTML = svg.outerHTML;
})(); })();

View File

@ -3,7 +3,6 @@ import { LOCAL_FONT_PROTOCOL } from "./metadata";
import loadWoff2 from "./wasm/woff2.loader"; import loadWoff2 from "./wasm/woff2.loader";
import loadHbSubset from "./wasm/hb-subset.loader"; import loadHbSubset from "./wasm/hb-subset.loader";
// import init, * as brotli from "../../../node_modules/brotli-wasm/pkg.web/brotli_wasm.js";
export interface Font { export interface Font {
urls: URL[]; urls: URL[];
fontFace: FontFace; fontFace: FontFace;
@ -55,7 +54,7 @@ export class ExcalidrawFont implements Font {
"base64", "base64",
).buffer; ).buffer;
const base64 = await ExcalidrawFont.trySubsetGlyphsByCodePoints( const base64 = await ExcalidrawFont.subsetGlyphsByCodePoints(
arrayBuffer, arrayBuffer,
codePoints, codePoints,
); );
@ -72,7 +71,7 @@ export class ExcalidrawFont implements Font {
if (response.ok) { if (response.ok) {
const arrayBuffer = await response.arrayBuffer(); const arrayBuffer = await response.arrayBuffer();
const base64 = await ExcalidrawFont.trySubsetGlyphsByCodePoints( const base64 = await ExcalidrawFont.subsetGlyphsByCodePoints(
arrayBuffer, arrayBuffer,
codePoints, codePoints,
); );
@ -104,14 +103,14 @@ export class ExcalidrawFont implements Font {
} }
/** /**
* Tries to convert a font data as arraybuffer into a dataurl (base64) with subsetted glyphs based on the specified `codePoints`. * Tries to subset glyphs in a font based on the used codepoints, returning the font as daturl.
* *
* @param arrayBuffer font data buffer, preferrably in the woff2 format, though others should work as well * @param arrayBuffer font data buffer, preferrably in the woff2 format, though others should work as well
* @param codePoints codepoints used to subset the glyphs * @param codePoints codepoints used to subset the glyphs
* *
* @returns font with subsetted glyphs converted into a dataurl * @returns font with subsetted glyphs (all glyphs in case of errors) converted into a dataurl
*/ */
private static async trySubsetGlyphsByCodePoints( private static async subsetGlyphsByCodePoints(
arrayBuffer: ArrayBuffer, arrayBuffer: ArrayBuffer,
codePoints: ReadonlySet<number>, codePoints: ReadonlySet<number>,
): Promise<string> { ): Promise<string> {

View File

@ -1,3 +1,6 @@
/**
* Lazy loads wasm and respective bindings for font subsetting based on the harfbuzzjs.
*/
let loadedWasm: ReturnType<typeof load> | null = null; let loadedWasm: ReturnType<typeof load> | null = null;
// TODO: add support for fetching the wasm from an URL (external CDN, data URL, etc.) // TODO: add support for fetching the wasm from an URL (external CDN, data URL, etc.)

View File

@ -1,5 +1,5 @@
// GENERATED CODE -- DO NOT EDIT! // GENERATED CODE -- DO NOT EDIT!
/* eslint-disable prettier/prettier */ /* eslint-disable */
// @ts-nocheck // @ts-nocheck
/** /**

View File

@ -1,3 +1,6 @@
/**
* Lazy loads wasm and respective bindings for woff2 compression and decompression.
*/
type Vector = any; type Vector = any;
let loadedWasm: ReturnType<typeof load> | null = null; let loadedWasm: ReturnType<typeof load> | null = null;

View File

@ -1,5 +1,5 @@
// GENERATED CODE -- DO NOT EDIT! // GENERATED CODE -- DO NOT EDIT!
/* eslint-disable prettier/prettier */ /* eslint-disable */
// @ts-nocheck // @ts-nocheck
/** /**

View File

@ -18,6 +18,7 @@ const exportLibraryItemToSvg = async (elements: LibraryItem["elements"]) => {
}, },
files: null, files: null,
renderEmbeddables: false, renderEmbeddables: false,
skipInliningFonts: true,
}); });
}; };