From fb086f0fbf90a659e64832aaff4d93d3dd8fbcfd Mon Sep 17 00:00:00 2001 From: Mikey Gower Date: Tue, 6 Feb 2024 13:25:48 -0500 Subject: [PATCH] remove loaders from FontBook --- src/renderers/webgl/textures/font.ts | 65 +--------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/src/renderers/webgl/textures/font.ts b/src/renderers/webgl/textures/font.ts index 44cb8f5..ea57989 100644 --- a/src/renderers/webgl/textures/font.ts +++ b/src/renderers/webgl/textures/font.ts @@ -1,24 +1,5 @@ import { BitmapFont, TextStyle } from 'pixi.js' import { MIN_ZOOM } from '../utils' -import { throttle } from '../../../utils' -import FontFaceObserver from 'fontfaceobserver' - -const warn = throttle((err) => console.warn(err), 0) - -const GENERIC_FONT_FAMILIES = new Set([ - 'serif', - 'sans-serif', - 'monospace', - 'cursive', - 'fantasy', - 'system-ui', - 'emoji', - 'math', - 'fangsong', - 'ui-serif', - 'ui-sans-serif', - 'ui-monospace' -]) export class FontBook { static defaultResolution = 2 @@ -31,9 +12,6 @@ export class FontBook { scaleFactor: number chars: string | (string | string[])[] - private cache: { [family: string]: boolean } = {} - private loading: { [family: string]: Promise } = {} - constructor( resolution = FontBook.defaultResolution, maxFontSize = FontBook.defaultMaxFontSize, @@ -50,40 +28,6 @@ export class FontBook { return BitmapFont.available[fontName] } - available(fontFamily: string | undefined, fontWeight: string | number | undefined = 'normal') { - const family = fontFamily?.split(', ')[0] - return ( - family === undefined || - this.cache[family] === true || - GENERIC_FONT_FAMILIES.has(family) || - document.fonts.check(`${fontWeight} 1em ${family}`) - ) - } - - async load(fontFamily: string | undefined, fontWeight: string | number | undefined = 'normal', timeout?: number) { - if (fontFamily === undefined || this.available(fontFamily, fontWeight)) { - return true - } - - const family = fontFamily.split(', ')[0] - - try { - if (!this.loading[family]) { - const weight = typeof fontWeight === 'string' && !isNaN(+fontWeight) ? +fontWeight : fontWeight - const font = new FontFaceObserver(family, { weight }) - this.loading[family] = font.load(null, timeout) - } - - await this.loading[family] - this.cache[family] = true - } catch (error) { - warn(error) - return false - } - - return this.cache[family] - } - create(fontName: string, style: TextStyle) { const font = FontBook.find(fontName) @@ -95,12 +39,7 @@ export class FontBook { return font } - delete(fontName?: string) { - if (fontName === undefined) { - this.cache = {} - this.loading = {} - } else { - FontBook.find(fontName)?.destroy() - } + delete(fontName: string) { + FontBook.find(fontName)?.destroy() } }