feat: add first-class support for CJK (#8530)

This commit is contained in:
Marcel Mraz 2024-10-17 21:14:17 +03:00 committed by GitHub
parent 21815fb930
commit b479f3bd65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
288 changed files with 3559 additions and 918 deletions

View file

@ -34,12 +34,14 @@ Object.defineProperty(window, "FontFace", {
private source: string;
private descriptors: any;
private status: string;
private unicodeRange: string;
constructor(family, source, descriptors) {
this.family = family;
this.source = source;
this.descriptors = descriptors;
this.status = "unloaded";
this.unicodeRange = "U+0000-00FF";
}
load() {
@ -61,27 +63,26 @@ Object.defineProperty(window, "EXCALIDRAW_ASSET_PATH", {
value: `file://${__dirname}/`,
});
// mock the font fetch only, so that everything else, as font subsetting, can run inside of the (snapshot) tests
vi.mock(
"./packages/excalidraw/fonts/ExcalidrawFont",
"./packages/excalidraw/fonts/ExcalidrawFontFace",
async (importOriginal) => {
const mod = await importOriginal<
typeof import("./packages/excalidraw/fonts/ExcalidrawFont")
typeof import("./packages/excalidraw/fonts/ExcalidrawFontFace")
>();
const ExcalidrawFontImpl = mod.ExcalidrawFont;
const ExcalidrawFontFaceImpl = mod.ExcalidrawFontFace;
return {
...mod,
ExcalidrawFont: class extends ExcalidrawFontImpl {
public async getContent(): Promise<string> {
const url = this.urls[0];
if (url.protocol !== "file:") {
return super.getContent(new Set());
ExcalidrawFontFace: class extends ExcalidrawFontFaceImpl {
public async fetchFont(url: URL): Promise<ArrayBuffer> {
if (!url.toString().startsWith("file://")) {
return super.fetchFont(url);
}
// read local assets directly, without running a server
const content = await fs.promises.readFile(url);
return `data:font/woff2;base64,${content.toString("base64")}`;
return content.buffer;
}
},
};