* Measure font metrics * 测量字体度量
()
| 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 |