Skip to content

Fix #204 — $1…$4 in-string font switches (%%setfont-n) - #214

Merged
sbeitzel merged 1 commit into
developfrom
feature/fix_204
Oct 3, 2026
Merged

sbeitzel merged 1 commit into
developfrom
feature/fix_204

Conversation

@sbeitzel

@sbeitzel sbeitzel commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Fix #204

$1…$4 set the rest of a string in the %%setfont-n face and size, $0 returns to the string's own font, and $$ prints $. This applies to every string CeolKit prints, and the text is measured as it is drawn. Behaviour was checked against abcm2ps 8.14 (-g/-v).

Decisions

  • Unset %%setfont-n: keeps the string's face at the documented default of 12 (scaled), with an unsetFontSwitch warning. abcm2ps itself reports a null size and draws 8 pt Helvetica.
  • Footers: not affected, matching abcm2ps 8.14, which drops the $ there and prints 1Left. $T gives the title without its switches.
  • Chord symbols: follow switches ("G$1m" → G, then a bold m). The parser reads the chord with the switches removed, so "G$1m" is a chord, not chord-line text. The public ChordSymbol.Segment enum is unchanged.
  • w: lyrics: a switch carries across syllables to $0 or the end of the line, as abcm2ps does. Each syllable's TextString is written with the switch in force at its start.
  • Only $0–$4 are switches (the §11.4.2 set); abcm2ps also reads $5–$9.

Not done: title-block row heights and band line heights still follow the role's size, not a larger switched run inside it.

Tests: 9 parser tests and 14 renderer tests are new. The full suite passes on macOS, and in Linux Docker (1,496 tests). No snapshot changed.

🤖 Generated with Claude Code

`$1`…`$4` now set the rest of a string, to the next switch, in the face
and size `%%setfont-1`…`4` name; `$0` returns to the string's own font and
`$$` prints `$`.  Any other `$` (`$5` included) prints as written.

- `FontSwitch` (CeolKitModel) splits a string into runs; the text itself
  keeps its switches, and `plainText` takes them out.
- `TextStyle` carries the `%%setfont-n` faces, so `width(of:)` and
  `builder.text(_:style:)` follow switches wherever text is measured or
  drawn: titles, composer, info fields, `Q:` text, annotations, chord-line
  text, chord symbols, `w:` and `W:`.  A string with no switch draws as
  before, byte for byte.
- A run set in a switched face is measured in it, so a title stays centred
  and the note spacing for annotations (#185) and lyrics widens to suit.
- Chord symbols are read with their switches removed (`"G$1m"` is G minor,
  not chord-line text), and the switches go back into the text segments.
- As in abcm2ps, a switch in a `w:` line holds from syllable to syllable;
  the aligner writes each syllable with the switch in force at its start.
- A switch in `Q:` text is closed before the metronome mark.
- An unset `%%setfont-n` keeps the string's face at abcm2ps's documented
  default of 12, with an `unsetFontSwitch` warning.
- Footers are unchanged: abcm2ps 8.14 does not switch font there either.
  `$T` gives the title without its switches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sbeitzel
sbeitzel merged commit 895e50b into develop Oct 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant