Skip to content

Add configurable NABC horizontal alignment#1722

Open
lbssousa wants to merge 7 commits intogregorio-project:developfrom
lbssousa:feature/nabc-alignment
Open

Add configurable NABC horizontal alignment#1722
lbssousa wants to merge 7 commits intogregorio-project:developfrom
lbssousa:feature/nabc-alignment

Conversation

@lbssousa
Copy link
Copy Markdown
Contributor

@lbssousa lbssousa commented Mar 2, 2026

Only left and center alignment options were implemented. It's possible to add a right option as well, but I believe this is unlikely to be useful.

Fixes #1665.

lbssousa added 4 commits March 8, 2026 19:10
When \gresetnabcalignment{neume}{center} is active, NABC neumes were
centered over the width of the first glyph only.  For multi-glyph
elements (e.g. tristropha jjj) and multi-element neumes (e.g. scandicus
flexus fh/ji), this produced visually wrong centering.

The fix defers NABC placement when center alignment is active.  The
element advance (all glyph widths + inter-glyph/inter-element spacing)
is accumulated through GreEndOfGlyph and GreEndOfElement.  At end of
syllable (or next GreNABCNeumes), the deferred NABC is placed centered
over the full accumulated advance.

During the boxing pass and tight rendering, immediate placement is used
(no deferral) since the element advance is not meaningful there.
When center alignment is active and a voice's NABC is empty on the
next element, the centering now extends to span that element as well.
Previously, \GreNABCNeumes flushed ALL pending voices at once; now it
flushes only the voice being replaced, allowing other voices to keep
accumulating advance.

Changes:
- Add per-voice advance start registers (\gre@dimen@nabc@advance@start@i/ii)
  that record the element advance at the moment each voice enters
  pending state
- New \gre@nabc@flush@deferred@voice{<suffix>} macro flushes a single
  voice: kerns back by (advance - start), centers, kerns forward
- \gre@nabc@flush@deferred@halign now delegates to per-voice flush
- \GreNABCNeumes flushes only the voice matching #1 instead of all
- \gre@nabc@place@voice@i/ii record advance start when entering pending
The @now placement macros overwrite \gre@dimen@temp@five with the
vertical raise amount.  Using that same register for the horizontal
span caused the kern-forward after placement to use the wrong value,
breaking NABC line 2 (below-staff) positioning.

Switch to \gre@dimen@temp@one which is not touched by @now.
When center-aligning NABC glyphs over elements (neume mode), voices that
had no NABC on a subsequent element would remain pending across element
boundaries.  This caused their centering span to grow to include the
inter-element space and the next element's width, resulting in NABC
glyphs displaced far from their correct position.

Fix: call \gre@nabc@flush@deferred@halign at the very beginning of
\GreEndOfElement, before penalty/space insertion.  This ensures each
voice's centering span is bounded by its element's glyphs.

Note: the \ifgre@nabc@halign@pending block that accumulated inter-element
space into elementadvance is now dead code (since we flush before reaching
it), but is kept for forward compatibility with the nabcinterglyphmingap
branch, which replaces it with \gre@nabc@reduce@rightbalance.
@lbssousa lbssousa marked this pull request as ready for review March 9, 2026 09:50
When font resolution combines an LS (significative letter) with the
base neume into a single combined glyph (e.g. 'pulsnt3' in grelaon),
the post-resolution lwidths loop finds ls[i]='' and accumulates zero
width.  This caused lwidths[12] (right overflow) to be 0 even when
the neume has right-side LS, making the centering formula in neume
mode center the entire glyph (including LS) instead of just the
neume part.

Fix: compute LS widths from the original ls[] entries BEFORE font
resolution clears them for combined glyphs.  Use these pre-resolution
widths (overflow_left, overflow_right) for the alignment overflow
dimensions passed to TeX, while keeping the post-resolution lwidths
for add_ls positioning of separately-rendered LS parts.
When center-aligned NABC placement is deferred across element boundaries,
a line break at GreEndOfElement can move pending NABC rendering to the
next line, visually detaching neumes from their corresponding GABC notes
(e.g. ves(...hh|ds1|bv...)).

Force end-of-element to be unbreakable while NABC halign is pending so
the deferred flush stays on the same line as its glyph context.
@lbssousa lbssousa force-pushed the feature/nabc-alignment branch from eb30277 to 734fa4a Compare March 12, 2026 12:27
@rpspringuel rpspringuel added this to the 7.0.0 milestone Mar 18, 2026
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.

Control horizontal alignment of NABC neumes relative to GABC notes

2 participants