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

Method measureMetrics

packages/fairygui/src/text/DynamicFont.ts:224–241  ·  view source on GitHub ↗

* Measure font metrics * 测量字体度量

()

Source from the content-addressed store, hash-verified

222 * 测量字体度量
223 */
224 private measureMetrics(): void {
225 const ctx = this._ctx;
226 ctx.font = `${this._fontSize}px "${this._fontFamily}"`;
227
228 // Measure using a reference character
229 const metrics = ctx.measureText('Mgy');
230
231 // Estimate ascent and descent
232 this._ascent = this._fontSize * 0.8;
233 this._lineHeight = this._fontSize * 1.2;
234
235 // Try to use actual metrics if available
236 if ('actualBoundingBoxAscent' in metrics) {
237 this._ascent = metrics.actualBoundingBoxAscent;
238 const descent = metrics.actualBoundingBoxDescent;
239 this._lineHeight = this._ascent + descent + this._padding * 2;
240 }
241 }
242
243 /**
244 * Request characters to be available in the atlas

Callers 1

constructorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected