mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: Comic Shanns issues, new fonts structure (#8641)
This commit is contained in:
parent
15ca182333
commit
61623bbeba
279 changed files with 13267 additions and 488 deletions
|
@ -1,19 +1,10 @@
|
|||
import { promiseTry } from "../utils";
|
||||
import { LOCAL_FONT_PROTOCOL } from "./metadata";
|
||||
import { subsetWoff2GlyphsByCodepoints } from "./subset/subset-main";
|
||||
import { LOCAL_FONT_PROTOCOL } from "./FontMetadata";
|
||||
import { subsetWoff2GlyphsByCodepoints } from "../subset/subset-main";
|
||||
|
||||
type DataURL = string;
|
||||
|
||||
export interface IExcalidrawFontFace {
|
||||
urls: URL[] | DataURL[];
|
||||
fontFace: FontFace;
|
||||
toCSS(
|
||||
characters: string,
|
||||
codePoints: Array<number>,
|
||||
): Promise<string> | undefined;
|
||||
}
|
||||
|
||||
export class ExcalidrawFontFace implements IExcalidrawFontFace {
|
||||
export class ExcalidrawFontFace {
|
||||
public readonly urls: URL[] | DataURL[];
|
||||
public readonly fontFace: FontFace;
|
||||
|
||||
|
@ -43,16 +34,17 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {
|
|||
*
|
||||
* Retrieves `undefined` otherwise.
|
||||
*/
|
||||
public toCSS(
|
||||
characters: string,
|
||||
codePoints: Array<number>,
|
||||
): Promise<string> | undefined {
|
||||
public toCSS(characters: string): Promise<string> | undefined {
|
||||
// quick exit in case the characters are not within this font face's unicode range
|
||||
if (!this.getUnicodeRangeRegex().test(characters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.getContent(codePoints).then(
|
||||
const codepoints = Array.from(characters).map(
|
||||
(char) => char.codePointAt(0)!,
|
||||
);
|
||||
|
||||
return this.getContent(codepoints).then(
|
||||
(content) =>
|
||||
`@font-face { font-family: ${this.fontFace.family}; src: url(${content}); }`,
|
||||
);
|
||||
|
@ -98,6 +90,10 @@ export class ExcalidrawFontFace implements IExcalidrawFontFace {
|
|||
public fetchFont(url: URL | DataURL): Promise<ArrayBuffer> {
|
||||
return promiseTry(async () => {
|
||||
const response = await fetch(url, {
|
||||
// always prefer cache (even stale), otherwise it always triggers an unnecessary validation request
|
||||
// which we don't need as we are controlling freshness of the fonts with the stable hash suffix in the url
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
|
||||
cache: "force-cache",
|
||||
headers: {
|
||||
Accept: "font/woff2",
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue