resolveTextLineHeight function

double resolveTextLineHeight(
  1. TextStyle style
)

文本样式的单行行高(logical px),等价 Android EmojiSpan 中的 fontHeight。

返回值按未缩放的逻辑像素计算,渲染期的 textScaler 会同时作用于文本与 emoji,两者的相对大小关系保持不变。

Implementation

double resolveTextLineHeight(TextStyle style) {
  final cached = _lineHeightCache[style];
  if (cached != null) return cached;

  final fontSize = style.fontSize ?? _kFallbackFontSize;
  final painter = TextPainter(
    text: TextSpan(
      text: _kMeasurementSample,
      style: style.copyWith(fontSize: fontSize),
    ),
    textDirection: TextDirection.ltr,
    maxLines: 1,
  )..layout();
  final height = painter.height;
  painter.dispose();

  if (_lineHeightCache.length >= _kLineHeightCacheLimit) {
    _lineHeightCache.clear();
  }
  _lineHeightCache[style] = height;
  return height;
}