layoutAnnotation method

double? layoutAnnotation(
  1. ChantContext ctxt,
  2. double? dropCapBaseline
)

Places the annotation of the first line, above the drop cap whose baseline is at dropCapBaseline (line coordinates), if there is one.

Returns the top of the annotation, excluding its own origin offset, or null when the score has no annotation. Safe to call repeatedly.

Implementation

double? layoutAnnotation(ChantContext ctxt, double? dropCapBaseline) {
  final a = score.annotation;
  if (a == null) return null;

  a.bounds = a.bounds.copyWith(
    x: staffLeft / 2,
    y: -ctxt.staffInterval * (score.staffLineCount * 2 - 1),
  );
  if (score.dropCap case DropCap dc when dropCapBaseline != null) {
    final dcHeight = ctxt.textMeasurer.measureMHeight(dc, ctxt);
    final lOffset = ctxt.textMeasurer.align == .baseline
        ? 0
        : lyricLineHeight;
    final highestNonCollidingY =
        dropCapBaseline -
        a.bounds.height +
        a.origin.y +
        lOffset -
        a.padding -
        dcHeight;
    a.bounds = a.bounds.copyWith(
      y: highestNonCollidingY < a.bounds.y
          ? highestNonCollidingY
          : (a.bounds.y + highestNonCollidingY) / 2,
    );
  }
  final top = a.bounds.y;
  a.bounds = a.bounds.copyWith(y: top + a.origin.y);
  return top;
}