measureText method

  1. @override
PTextMetric measureText(
  1. String text,
  2. PFont font
)
override

Measure the text dimension.

Implementation

@override
PTextMetric measureText(String text, PFont font) {
  var textStyle = font.toTextStyle();
  var textSpan = TextSpan(text: text, style: textStyle);

  final textPainterBlock =
      TextPainter(text: textSpan, textDirection: TextDirection.ltr)
        ..layout(minWidth: 0, maxWidth: double.infinity);

  var sizeBlock = textPainterBlock.size;

  return PTextMetric(sizeBlock.width, sizeBlock.height);
}