capHeightCentringShift function

double capHeightCentringShift({
  1. required double ascent,
  2. required double lineHeight,
  3. required double baseline,
  4. required double capHeight,
})

Distance to move a line down so its capitals are centred in the line.

lineHeight and baseline are measured from the top of the line. Negative moves the line up.

Returns zero when capHeight is not positive or exceeds ascent: that measurement is not a cap band, for example in fonts that draw guide lines.

Across the Google Fonts in the tables, the shift reaches 0.44 em (Linefont) and is over 0.1 em for 261 fonts. A widget that applies it must leave room for it.

Implementation

double capHeightCentringShift({
  required double ascent,
  required double lineHeight,
  required double baseline,
  required double capHeight,
}) {
  if (capHeight <= 0 || capHeight > ascent) return 0;
  return lineHeight / 2 - (baseline - capHeight / 2);
}