Fix #204 — $1…$4 in-string font switches (%%setfont-n) - #214
Merged
Merged
Conversation
`$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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #204
$1…$4set the rest of a string in the%%setfont-nface and size,$0returns 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
%%setfont-n: keeps the string's face at the documented default of 12 (scaled), with anunsetFontSwitchwarning. abcm2ps itself reports a null size and draws 8 pt Helvetica.$there and prints1Left.$Tgives the title without its 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 publicChordSymbol.Segmentenum is unchanged.w:lyrics: a switch carries across syllables to$0or the end of the line, as abcm2ps does. Each syllable'sTextStringis written with the switch in force at its start.$0–$4are 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