MCPcopy Create free account
hub / github.com/esengine/esengine / constructor

Method constructor

packages/fairygui/src/text/DynamicFont.ts:129–162  ·  view source on GitHub ↗
(name: string, config: IDynamicFontConfig)

Source from the content-addressed store, hash-verified

127 public version: number = 0;
128
129 constructor(name: string, config: IDynamicFontConfig) {
130 this.name = name;
131 this._fontFamily = config.fontFamily;
132 this._fontSize = config.fontSize ?? 32;
133 this._atlasWidth = config.atlasWidth ?? 1024;
134 this._atlasHeight = config.atlasHeight ?? 1024;
135 this._padding = config.padding ?? 2;
136
137 // Create canvas
138 if (typeof OffscreenCanvas !== 'undefined') {
139 this._canvas = new OffscreenCanvas(this._atlasWidth, this._atlasHeight);
140 } else {
141 this._canvas = document.createElement('canvas');
142 this._canvas.width = this._atlasWidth;
143 this._canvas.height = this._atlasHeight;
144 }
145
146 const ctx = this._canvas.getContext('2d');
147 if (!ctx) {
148 throw new Error('Failed to create canvas context');
149 }
150 this._ctx = ctx;
151
152 // Initialize canvas
153 this.initCanvas();
154
155 // Measure font metrics
156 this.measureMetrics();
157
158 // Preload common characters
159 if (config.preloadChars) {
160 this.requestCharacters(config.preloadChars);
161 }
162 }
163
164 /**
165 * Set texture upload callback

Callers

nothing calls this directly

Calls 4

initCanvasMethod · 0.95
measureMetricsMethod · 0.95
requestCharactersMethod · 0.95
getContextMethod · 0.65

Tested by

no test coverage detected