getApproxTextHeight method

double getApproxTextHeight()

The exact font height is retrieved from TextMetrics.fontBoundingBoxAscent. However, not all browsers support this property, and if this property returns null, the height can be approximated by getting the width of character 'M'. This is no magic, see also: https://stackoverflow.com/a/13318387/9113939.

Implementation

double getApproxTextHeight() {
  ctx.font = labelFontStyle;
  var metric = ctx.measureText('100'); // 100 is a test text. It does not matter what is put here.
  return metric.fontBoundingBoxAscent.toDouble();
}