mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: add first-class support for CJK (#8530)
This commit is contained in:
parent
21815fb930
commit
b479f3bd65
288 changed files with 3559 additions and 918 deletions
|
@ -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;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue