measureCellSize method

CellSize measureCellSize(
  1. double fontSize
)

Implementation

CellSize measureCellSize(double fontSize) {
  final testString = 'xxxxxxxxxx' * 1000;

  final text = Text(
    testString,
    maxLines: 1,
    style: (style.textStyleProvider != null)
        ? style.textStyleProvider!(
            fontSize: fontSize,
          )
        : TextStyle(
            fontFamily: 'monospace',
            fontFamilyFallback: style.fontFamily,
            fontSize: fontSize,
          ),
  );

  final size = textSize(text);

  final charWidth = (size.width / testString.length);
  final charHeight = size.height;

  final cellWidth = charWidth * style.fontWidthScaleFactor;
  final cellHeight = size.height * style.fontHeightScaleFactor;

  return CellSize(
    charWidth: charWidth,
    charHeight: charHeight,
    cellWidth: cellWidth,
    cellHeight: cellHeight,
    letterSpacing: cellWidth - charWidth,
    lineSpacing: cellHeight - charHeight,
  );
}