feat: support rich multi-paragraph notes with formatting (Closes #7)

Add {start_of_notes}/{end_of_notes} (and short forms {son}/{eon}) block
directives to ChordProParser for multi-paragraph note content. Blank lines
within the block separate paragraphs. The renderer now word-wraps note
paragraphs to fit within the content width. MeasurementEngine estimates
wrapped line count for more accurate height calculations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit was merged in pull request #11.
This commit is contained in:
shahondin1624
2026-03-17 09:38:25 +01:00
parent 0139327034
commit 8c92c7d78b
4 changed files with 166 additions and 13 deletions

View File

@@ -226,19 +226,28 @@ class PdfBookRenderer : BookRenderer {
y -= config.layout.verseSpacing / 0.3528f
}
// Render notes at the bottom
// Render notes at the bottom (with word-wrap for multi-paragraph notes)
if (pageIndex == 0 && song.notes.isNotEmpty()) {
y -= 4f
val metaFont = fontMetrics.getBaseFont(config.fonts.metadata)
val metaSize = config.fonts.metadata.size
for (note in song.notes) {
cb.beginText()
cb.setFontAndSize(metaFont, metaSize)
cb.setColorFill(Color.GRAY)
cb.setTextMatrix(leftMargin, y - metaSize)
cb.showText(note)
cb.endText()
y -= metaSize * 1.5f
val noteLineHeight = metaSize * 1.5f
for ((idx, note) in song.notes.withIndex()) {
val wrappedLines = wrapText(note, metaFont, metaSize, contentWidth)
for (wrappedLine in wrappedLines) {
cb.beginText()
cb.setFontAndSize(metaFont, metaSize)
cb.setColorFill(Color.GRAY)
cb.setTextMatrix(leftMargin, y - metaSize)
cb.showText(wrappedLine)
cb.endText()
y -= noteLineHeight
}
// Add paragraph spacing between note paragraphs
if (idx < song.notes.size - 1) {
y -= noteLineHeight * 0.3f
}
}
}