feat: display reference book page numbers in song page footer (Closes #3)
Render a two-row footer at the bottom of each song page showing reference book abbreviations as column headers with corresponding page numbers below. A thin separator line is drawn above the footer. MeasurementEngine now reserves vertical space for the reference footer when reference books are configured and the song has references. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,13 @@ class MeasurementEngine(
|
||||
}
|
||||
}
|
||||
|
||||
// Reference book footer: reserve space for abbreviation row + page number row + separator line
|
||||
if (config.referenceBooks.isNotEmpty() && song.references.isNotEmpty()) {
|
||||
val metaLineHeight = fontMetrics.measureLineHeight(config.fonts.metadata, config.fonts.metadata.size)
|
||||
heightMm += metaLineHeight * 1.4f * 2 // two rows (headers + numbers)
|
||||
heightMm += metaLineHeight * 0.5f // separator line gap
|
||||
}
|
||||
|
||||
val pageCount = if (heightMm <= contentHeightMm) 1 else 2
|
||||
return MeasuredSong(song, heightMm, pageCount)
|
||||
}
|
||||
|
||||
@@ -258,4 +258,70 @@ class MeasurementEngineTest {
|
||||
|
||||
labeledHeight shouldBeGreaterThan unlabeledHeight
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `references add footer height when reference books configured`() {
|
||||
val configWithRefs = BookConfig(
|
||||
referenceBooks = listOf(
|
||||
ReferenceBook(id = "mo", name = "Mundorgel", abbreviation = "MO"),
|
||||
ReferenceBook(id = "pl", name = "Pfadfinderlied", abbreviation = "PL")
|
||||
)
|
||||
)
|
||||
val engineWithRefs = MeasurementEngine(fontMetrics, configWithRefs)
|
||||
|
||||
val songWithRefs = Song(
|
||||
title = "With Refs",
|
||||
references = mapOf("mo" to 42, "pl" to 17),
|
||||
sections = listOf(
|
||||
SongSection(
|
||||
type = SectionType.VERSE,
|
||||
lines = listOf(SongLine(listOf(LineSegment(text = "Line"))))
|
||||
)
|
||||
)
|
||||
)
|
||||
val songWithoutRefs = Song(
|
||||
title = "No Refs",
|
||||
sections = listOf(
|
||||
SongSection(
|
||||
type = SectionType.VERSE,
|
||||
lines = listOf(SongLine(listOf(LineSegment(text = "Line"))))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val heightWith = engineWithRefs.measure(songWithRefs).totalHeightMm
|
||||
val heightWithout = engineWithRefs.measure(songWithoutRefs).totalHeightMm
|
||||
|
||||
heightWith shouldBeGreaterThan heightWithout
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `references do not add height when no reference books configured`() {
|
||||
val songWithRefs = Song(
|
||||
title = "With Refs",
|
||||
references = mapOf("mo" to 42),
|
||||
sections = listOf(
|
||||
SongSection(
|
||||
type = SectionType.VERSE,
|
||||
lines = listOf(SongLine(listOf(LineSegment(text = "Line"))))
|
||||
)
|
||||
)
|
||||
)
|
||||
val songWithoutRefs = Song(
|
||||
title = "No Refs",
|
||||
sections = listOf(
|
||||
SongSection(
|
||||
type = SectionType.VERSE,
|
||||
lines = listOf(SongLine(listOf(LineSegment(text = "Line"))))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
// Default config has no reference books
|
||||
val heightWith = engine.measure(songWithRefs).totalHeightMm
|
||||
val heightWithout = engine.measure(songWithoutRefs).totalHeightMm
|
||||
|
||||
// Should be the same since no reference books are configured
|
||||
heightWith shouldBe heightWithout
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user