Skip to content

Commit

Permalink
Temp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Jul 25, 2024
1 parent 888d979 commit f5f040a
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 32 deletions.
9 changes: 0 additions & 9 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ import { getTooltipDiv } from "./Tooltip";

const AppContext = React.createContext<AppClassProperties>(null!);
const AppPropsContext = React.createContext<AppProps>(null!);
export let showFourthFont: boolean = false; //zsviczian

const deviceContextInitialValue = {
viewport: {
Expand Down Expand Up @@ -713,7 +712,6 @@ class App extends React.Component<AppProps, AppState> {
setToast: this.setToast,
updateContainerSize: this.updateContainerSize, //zsviczian
id: this.id,
setLocalFont: this.setLocalFont, //zsviczian
selectElements: this.selectElements, //zsviczian
sendBackward: this.sendBackward, //zsviczian
bringForward: this.bringForward, //zsviczian
Expand Down Expand Up @@ -3947,13 +3945,6 @@ class App extends React.Component<AppProps, AppState> {
}
};

//zsviczian
public setLocalFont: ExcalidrawImperativeAPI["setLocalFont"] = (
showOnPanel: boolean,
) => {
showFourthFont = showOnPanel;
};

//zsviczian
public selectElements: ExcalidrawImperativeAPI["selectElements"] = (
elements: readonly ExcalidrawElement[],
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/entry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./publicPath";
import polyfill from "./polyfill";

import "../../public/fonts/fonts.css";
import "./fonts/assets/fonts.css";

polyfill();
export * from "./index";
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 8 additions & 8 deletions packages/excalidraw/fonts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import Cascadia from "./assets/CascadiaMono-Regular.woff2";
import ComicShanns from "./assets/ComicShanns-Regular.woff2";
import LiberationSans from "./assets/LiberationSans-Regular.woff2";

import LilitaLatin from "https://fonts.gstatic.com/s/lilitaone/v15/i7dPIFZ9Zz-WBtRtedDbYEF8RXi4EwQ.woff2";
import LilitaLatinExt from "https://fonts.gstatic.com/s/lilitaone/v15/i7dPIFZ9Zz-WBtRtedDbYE98RXi4EwSsbg.woff2";
import LilitaLatin from "./assets/LilitaLatin.woff2";
import LilitaLatinExt from "./assets/LilitaLatinExt.woff2";

import NunitoLatin from "https://fonts.gstatic.com/s/nunito/v26/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTQ3j6zbXWjgeg.woff2";
import NunitoLatinExt from "https://fonts.gstatic.com/s/nunito/v26/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTo3j6zbXWjgevT5.woff2";
import NunitoCyrilic from "https://fonts.gstatic.com/s/nunito/v26/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTA3j6zbXWjgevT5.woff2";
import NunitoCyrilicExt from "https://fonts.gstatic.com/s/nunito/v26/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTk3j6zbXWjgevT5.woff2";
import NunitoVietnamese from "https://fonts.gstatic.com/s/nunito/v26/XRXI3I6Li01BKofiOc5wtlZ2di8HDIkhdTs3j6zbXWjgevT5.woff2";
import NunitoLatin from "./assets/NunitoLatin.woff2";
import NunitoLatinExt from "./assets/NunitoLatinExt.woff2";
import NunitoCyrilic from "./assets/NunitoCyrilic.woff2";
import NunitoCyrilicExt from "./assets/NunitoCyrilicExt.woff2";
import NunitoVietnamese from "./assets/NunitoVietnamese.woff2";

export class Fonts {
// it's ok to track fonts across multiple instances only once, so let's use
Expand Down Expand Up @@ -247,7 +247,7 @@ export class Fonts {
* @param metadata font metadata
* @param params array of the rest of the FontFace parameters [uri: string, descriptors: FontFaceDescriptors?] ,
*/
function register(
export function register( //zsviczian
this:
| Fonts
| {
Expand Down
6 changes: 5 additions & 1 deletion packages/excalidraw/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,16 @@ export {
intersectElementWithLine, //zsviczian
determineFocusDistance, //zsviczian
measureText, //zsviczian
getDefaultLineHeight, //zsviczian
getLineHeight, //zsviczian
wrapText, //zsviczian
getFontString, //zsviczian
getBoundTextMaxWidth, //zsviczian
mermaidToExcalidraw, //zsviczian
destroyObsidianUtils, //zsviczian
registerLocalFont, //zsviczian
getFontFamilies, //zsviczian
getFontFamilyString, //zsviczian
registerFontsInCSS, //zsviczian
} from "../utils/export";

export {
Expand Down
57 changes: 57 additions & 0 deletions packages/excalidraw/obsidianUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { FreedrawIcon } from "./components/icons";
import { FONT_FAMILY } from "./constants";
import { Fonts, register } from "./fonts";
import { FONT_METADATA, FontMetadata, LOCAL_FONT_PROTOCOL } from "./fonts/metadata";

//zsviczian, my dirty little secrets. These are hacks I am not proud of...
export let hostPlugin: any = null;

Expand Down Expand Up @@ -32,3 +37,55 @@ export function getExcalidrawContentEl():HTMLElement {
export function hideFreedrawPenmodeCursor() {
return !hostPlugin.settings.penModeCrosshairVisible;
}

export function registerLocalFont(fontMetrics: FontMetadata & {name: string}, uri: string) {
const _register = register.bind({registered: Fonts.registered});
FONT_METADATA[FONT_FAMILY.LocalFont] = {metrics: fontMetrics.metrics, icon: FreedrawIcon};
_register("LocalFont", fontMetrics, {uri});
}

export function getFontFamilies(): string[] {
const fontFamilies:string[] = [];
for (const fontFaces of Fonts.registered.values()) {
for (const font of fontFaces.fontFaces.filter(font =>
//font.fontFace.weight === "400" &&
font.url.protocol !== LOCAL_FONT_PROTOCOL,
)) {
fontFamilies.push(font.fontFace.family);
}
}
return fontFamilies;
}

export async function registerFontsInCSS() {
const styleId = 'ExcalidrawFonts';
let styleElement = document.getElementById(styleId) as HTMLStyleElement;

if (!styleElement) {
styleElement = document.createElement('style');
styleElement.id = styleId;
document.head.appendChild(styleElement);
} else {
styleElement.textContent = '';
}

let cssContent = '';

for (const fontFaces of Fonts.registered.values()) {
for (const font of fontFaces.fontFaces.filter(font =>
//font.fontFace.weight === "400" &&
font.url.protocol !== LOCAL_FONT_PROTOCOL,
)) {
try {
const content = await font.getContent();
cssContent += `@font-face {font-family: ${font.fontFace.family}; src: url(${content});}\n`;
} catch (e) {
console.error(
`Skipped inlining font with URL "${font.url.toString()}"`,
e,
);
}
}
}
styleElement.textContent = cssContent;
}
1 change: 0 additions & 1 deletion packages/excalidraw/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ export interface ExcalidrawImperativeAPI {
addFiles: (data: BinaryFileData[]) => void;
updateContainerSize: InstanceType<typeof App>["updateContainerSize"]; //zsviczian
id: string;
setLocalFont: (showOnPanel: boolean) => void; //zsviczian
selectElements: (elements: readonly ExcalidrawElement[]) => void; //zsviczian
sendBackward: (elements: readonly ExcalidrawElement[]) => void; //zsviczian
bringForward: (elements: readonly ExcalidrawElement[]) => void; //zsviczian
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ export { determineFocusDistance } from "../excalidraw/element/binding"; //zsvicz
export {
measureText,
wrapText,
getDefaultLineHeight,
} from "../excalidraw/element/textElement"; //zsviczian
export { getFontString } from "../excalidraw/utils"; //zsviczian
export { getLineHeight } from "../excalidraw/fonts/index"; //zsviczian
export { getFontString, getFontFamilyString } from "../excalidraw/utils"; //zsviczian
export { getBoundTextMaxWidth } from "../excalidraw/element/textElement"; //zsviczian
export { mermaidToExcalidraw } from "../excalidraw/components/TTDDialog/MermaidToExcalidraw"; //zsviczian
export { destroyObsidianUtils } from "../excalidraw/obsidianUtils"; //zsviczian
export { destroyObsidianUtils } from "../excalidraw/obsidianUtils"; //zsviczian
export { registerLocalFont, getFontFamilies, registerFontsInCSS } from "../excalidraw/obsidianUtils"; //zsviczian
16 changes: 7 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7168,6 +7168,7 @@ formdata-polyfill@^4.0.10:
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
Expand Down Expand Up @@ -8938,6 +8939,7 @@ [email protected]:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"

node-forge@^1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
Expand Down Expand Up @@ -11628,22 +11630,18 @@ [email protected]:
dependencies:
argparse "^2.0.1"

web-streams-polyfill@^3.0.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b"
integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==

web-worker@^1.2.0:
version "1.3.0"
resolved "https://registry.npmjs.org/web-worker/-/web-worker-1.3.0.tgz#e5f2df5c7fe356755a5fb8f8410d4312627e6776"
integrity sha512-BSR9wyRsy/KOValMgd5kMyr3JzpdeoR9KVId8u5GVlTTAtNChlsE4yTxeY7zMdNSyOmoKBv8NH2qeRY9Tg+IaA==
wbuf@^1.1.0, wbuf@^1.7.3:
version "1.7.3"
resolved "https://registry.yarnpkg.com/wbuf/-/wbuf-1.7.3.tgz#c1d8d149316d3ea852848895cb6a0bfe887b87df"
integrity sha512-O84QOnr0icsbFGLS0O3bI5FswxzRr8/gHwWkDlQFskhSPryQXvrTMxjxGP4+iWYoauLoBvfDpkrOauZ+0iZpDA==
dependencies:
minimalistic-assert "^1.0.0"

web-streams-polyfill@^3.0.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b"
integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
Expand Down

0 comments on commit f5f040a

Please sign in to comment.