fix: Comic Shanns issues, new fonts structure (#8641)

This commit is contained in:
Marcel Mraz 2024-10-21 01:11:53 +03:00 committed by GitHub
parent 15ca182333
commit 61623bbeba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
279 changed files with 13267 additions and 488 deletions

View file

@ -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",
},