1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2024-11-10 11:35:52 +01:00

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

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

@ -3,7 +3,6 @@ import { LOCAL_FONT_PROTOCOL } from "./metadata";
import loadWoff2 from "./wasm/woff2.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 {
urls: URL[];
fontFace: FontFace;
@ -55,7 +54,7 @@ export class ExcalidrawFont implements Font {
"base64",
).buffer;
const base64 = await ExcalidrawFont.trySubsetGlyphsByCodePoints(
const base64 = await ExcalidrawFont.subsetGlyphsByCodePoints(
arrayBuffer,
codePoints,
);
@ -72,7 +71,7 @@ export class ExcalidrawFont implements Font {
if (response.ok) {
const arrayBuffer = await response.arrayBuffer();
const base64 = await ExcalidrawFont.trySubsetGlyphsByCodePoints(
const base64 = await ExcalidrawFont.subsetGlyphsByCodePoints(
arrayBuffer,
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 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,
codePoints: ReadonlySet<number>,
): Promise<string> {

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

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

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

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

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