mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-18 23:10:16 +02:00
feat: add first-class support for CJK (#8530)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user