Skip to content

Commit

Permalink
0.17.6-1 ; 2.5.3-beta-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Oct 19, 2024
1 parent 587a58a commit 6ff3694
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
29 changes: 19 additions & 10 deletions packages/excalidraw/fonts/ExcalidrawFontFace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {

public fetchFont(url: URL | DataURL): Promise<ArrayBuffer> {
return promiseTry(async () => {
const ab = await fetchFontFromVault(url); //zsviczian
if (ab) {
return ab;
const result = await fetchFontFromVault(url); //zsviczian
if (result) {
if (typeof result === "string") {
url = result;
} else {
return result;
}
}
const response = await fetch(url, {
headers: {
Expand Down Expand Up @@ -231,20 +235,25 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {
const errorMessages = [];

while (i < this.urls.length) {
const url = this.urls[i];
let url = this.urls[i];

if (typeof url === "string" && url.startsWith("data:")) {
// it's dataurl, the font is inlined as base64, no need to fetch
return url as string;
}

try {
const arrayBuffer = await fetchFontFromVault(url); //zsviczian
if(arrayBuffer) {
return `data:font/woff2;base64,${await stringToBase64(
await toByteString(arrayBuffer),
true,
)}`;
const result = await fetchFontFromVault(url); //zsviczian
if(result) {
if(typeof result === "string") {
url = result;
} else {
return `data:font/woff2;base64,${await stringToBase64(
await toByteString(result),
true,
)}`;
}

}

const response = await fetch(url, {
Expand Down
8 changes: 4 additions & 4 deletions packages/excalidraw/fonts/css/fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

@font-face {
font-family: "Assistant";
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-Regular.woff2) format("woff2");
src: url(../woff2/Assistant/Assistant-Regular.woff2) format("woff2");
font-weight: 400;
style: normal;
display: swap;
}

@font-face {
font-family: "Assistant";
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-Medium.woff2) format("woff2");
src: url(../woff2/Assistant/Assistant-Medium.woff2) format("woff2");
font-weight: 500;
style: normal;
display: swap;
}

@font-face {
font-family: "Assistant";
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-SemiBold.woff2) format("woff2");
src: url(../woff2/Assistant/Assistant-SemiBold.woff2) format("woff2");
font-weight: 600;
style: normal;
display: swap;
}

@font-face {
font-family: "Assistant";
src: url(https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/Assistant-Bold.woff2) format("woff2");
src: url(../woff2/Assistant/Assistant-Bold.woff2) format("woff2");
font-weight: 700;
style: normal;
display: swap;
Expand Down
9 changes: 6 additions & 3 deletions packages/excalidraw/obsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@ export async function loadSceneFonts(elements: NonDeletedExcalidrawElement[]): P
await Fonts.loadFontFaces(fontFamilies);
}

export async function fetchFontFromVault(url: string | URL): Promise<ArrayBuffer|undefined> {
export async function fetchFontFromVault(url: string | URL): Promise<ArrayBuffer|undefined|string> {
if(typeof url === "string" && !url.startsWith("data") && url.endsWith(".woff2")) {
const arrayBuffer = hostPlugin.loadFontFromFile(decodeURIComponent(url.substring(url.lastIndexOf("/")+1)))
const filename = decodeURIComponent(url.substring(url.lastIndexOf("/")+1));
const arrayBuffer = hostPlugin.loadFontFromFile(filename)
if(arrayBuffer) {
return arrayBuffer;
}
if (["Assistant-Regular.woff2", "Assistant-Medium.woff2", "Assistant-SemiBold.woff2", "Assistant-Bold.woff2"].includes(filename)) {
return "https://unpkg.com/@zsviczian/[email protected]/dist/excalidraw-assets/" + filename;
}
}
return;

}
2 changes: 1 addition & 1 deletion packages/excalidraw/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zsviczian/excalidraw",
"version": "0.17.6",
"version": "0.17.6-1",
"main": "main.js",
"types": "types/excalidraw/index.d.ts",
"files": [
Expand Down

0 comments on commit 6ff3694

Please sign in to comment.