mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: multiple fonts fallbacks (#8286)
This commit is contained in:
parent
d0a380758e
commit
230d0edc44
11 changed files with 293 additions and 127 deletions
|
@ -43,7 +43,6 @@ import type { RenderableElementsMap } from "./types";
|
|||
import { syncInvalidIndices } from "../fractionalIndex";
|
||||
import { renderStaticScene } from "../renderer/staticScene";
|
||||
import { Fonts } from "../fonts";
|
||||
import { LOCAL_FONT_PROTOCOL } from "../fonts/metadata";
|
||||
|
||||
const SVG_EXPORT_TAG = `<!-- svg-source:excalidraw -->`;
|
||||
|
||||
|
@ -375,35 +374,28 @@ export const exportToSvg = async (
|
|||
? []
|
||||
: await Promise.all(
|
||||
Array.from(fontFamilies).map(async (x) => {
|
||||
const { fontFaces } = Fonts.registered.get(x) ?? {};
|
||||
const { fonts, metadata } = Fonts.registered.get(x) ?? {};
|
||||
|
||||
if (!Array.isArray(fontFaces)) {
|
||||
if (!Array.isArray(fonts)) {
|
||||
console.error(
|
||||
`Couldn't find registered font-faces for font-family "${x}"`,
|
||||
`Couldn't find registered fonts for font-family "${x}"`,
|
||||
Fonts.registered,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return Promise.all(
|
||||
fontFaces
|
||||
.filter((font) => font.url.protocol !== LOCAL_FONT_PROTOCOL)
|
||||
.map(async (font) => {
|
||||
try {
|
||||
const content = await font.getContent();
|
||||
if (metadata?.local) {
|
||||
// don't inline local fonts
|
||||
return;
|
||||
}
|
||||
|
||||
return `@font-face {
|
||||
return Promise.all(
|
||||
fonts.map(
|
||||
async (font) => `@font-face {
|
||||
font-family: ${font.fontFace.family};
|
||||
src: url(${content});
|
||||
}`;
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`Skipped inlining font with URL "${font.url.toString()}"`,
|
||||
e,
|
||||
);
|
||||
return "";
|
||||
}
|
||||
}),
|
||||
src: url(${await font.getContent()});
|
||||
}`,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue