From b4d0d07732ec9c7636c6d7a4d0223301e025a07a Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Fri, 27 Dec 2024 17:43:39 +0100 Subject: [PATCH] Add --lyric-height option --- include/vrv/options.h | 1 + src/adjustfloatingpositionerfunctor.cpp | 15 +++++++++------ src/options.cpp | 4 ++++ src/view_element.cpp | 17 +++++++++++++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/vrv/options.h b/include/vrv/options.h index c81516b128..fd3569203e 100644 --- a/include/vrv/options.h +++ b/include/vrv/options.h @@ -714,6 +714,7 @@ class Options { OptionDbl m_ledgerLineThickness; OptionDbl m_ledgerLineExtension; OptionIntMap m_lyricElision; + OptionDbl m_lyricHeight; OptionDbl m_lyricLineThickness; OptionBool m_lyricNoStartHyphen; OptionDbl m_lyricSize; diff --git a/src/adjustfloatingpositionerfunctor.cpp b/src/adjustfloatingpositionerfunctor.cpp index 94fd8c7d94..e6b5ac655e 100644 --- a/src/adjustfloatingpositionerfunctor.cpp +++ b/src/adjustfloatingpositionerfunctor.cpp @@ -34,18 +34,21 @@ FunctorCode AdjustFloatingPositionersFunctor::VisitStaffAlignment(StaffAlignment staffAlignment->SortPositioners(); - const bool verseCollapse = m_doc->GetOptions()->m_lyricVerseCollapse.GetValue(); if (m_classId == SYL) { + const bool verseCollapse = m_doc->GetOptions()->m_lyricVerseCollapse.GetValue(); if (staffAlignment->GetVerseCount(verseCollapse) > 0) { - FontInfo *lyricFont = m_doc->GetDrawingLyricFont(staffAlignment->GetStaff()->m_drawingStaffSize); - int descender = m_doc->GetTextGlyphDescender(L'q', lyricFont, false); - int height = m_doc->GetTextGlyphHeight(L'I', lyricFont, false); + int verseHeight = (int)m_doc->GetOptions()->m_lyricHeight.GetValue() * drawingUnit; + if (verseHeight == 0) { + FontInfo *lyricFont = m_doc->GetDrawingLyricFont(staffAlignment->GetStaff()->m_drawingStaffSize); + verseHeight -= m_doc->GetTextGlyphDescender(L'q', lyricFont, false); + verseHeight += m_doc->GetTextGlyphHeight(L'I', lyricFont, false); + } if (staffAlignment->GetVerseCountAbove(verseCollapse)) { int margin = m_doc->GetTopMargin(SYL) * drawingUnit; int minMargin = std::max((int)(m_doc->GetOptions()->m_lyricTopMinMargin.GetValue() * drawingUnit), staffAlignment->GetOverflowAbove()); staffAlignment->SetOverflowAbove( - minMargin + staffAlignment->GetVerseCountAbove(verseCollapse) * (height - descender + margin)); + minMargin + staffAlignment->GetVerseCountAbove(verseCollapse) * (verseHeight + margin)); // For now just clear the overflowBelow, which avoids the overlap to be calculated. We could also keep // them and check if they are some lyrics in order to know if the overlap needs to be calculated or not. staffAlignment->ClearBBoxesAbove(); @@ -55,7 +58,7 @@ FunctorCode AdjustFloatingPositionersFunctor::VisitStaffAlignment(StaffAlignment int minMargin = std::max((int)(m_doc->GetOptions()->m_lyricTopMinMargin.GetValue() * drawingUnit), staffAlignment->GetOverflowBelow()); staffAlignment->SetOverflowBelow( - minMargin + staffAlignment->GetVerseCountBelow(verseCollapse) * (height - descender + margin)); + minMargin + staffAlignment->GetVerseCountBelow(verseCollapse) * (verseHeight + margin)); // For now just clear the overflowBelow, which avoids the overlap to be calculated. We could also keep // them and check if they are some lyrics in order to know if the overlap needs to be calculated or not. staffAlignment->ClearBBoxesBelow(); diff --git a/src/options.cpp b/src/options.cpp index 1fcbb2c101..3300e5885d 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1371,6 +1371,10 @@ Options::Options() m_lyricElision.Init(ELISION_regular, &Option::s_elision); this->Register(&m_lyricElision, "lyricElision", &m_generalLayout); + m_lyricHeight.SetInfo("Lyric height", "The lyric verse line height in MEI units (0.0 for the default text height)"); + m_lyricHeight.Init(0.0, 0.0, 20.0); + this->Register(&m_lyricHeight, "lyricHeight", &m_generalLayout); + m_lyricLineThickness.SetInfo("Lyric line thickness", "The lyric extender line thickness"); m_lyricLineThickness.Init(0.25, 0.10, 0.50); this->Register(&m_lyricLineThickness, "lyricLineThickness", &m_generalLayout); diff --git a/src/view_element.cpp b/src/view_element.cpp index 84455a7985..4323be6c03 100644 --- a/src/view_element.cpp +++ b/src/view_element.cpp @@ -2105,22 +2105,31 @@ int View::GetSylYRel(int verseN, Staff *staff, data_STAFFREL place) StaffAlignment *alignment = staff->GetAlignment(); if (!alignment) return 0; + const int drawingUnit = m_doc->GetDrawingUnit(staff->m_drawingStaffSize); + const bool verseCollapse = m_options->m_lyricVerseCollapse.GetValue(); int y = 0; FontInfo *lyricFont = m_doc->GetDrawingLyricFont(staff->m_drawingStaffSize); - int descender = -m_doc->GetTextGlyphDescender(L'q', lyricFont, false); - int height = m_doc->GetTextGlyphHeight(L'I', lyricFont, false); + const int descender = m_doc->GetTextGlyphDescender(L'q', lyricFont, false); + const int height = m_doc->GetTextGlyphHeight(L'I', lyricFont, false); + + int verseHeight = (int)m_doc->GetOptions()->m_lyricHeight.GetValue() * drawingUnit; + if (verseHeight == 0) { + verseHeight -= descender; + verseHeight += height; + } + int margin = m_doc->GetBottomMargin(SYL) * m_doc->GetDrawingUnit(staff->m_drawingStaffSize); // above the staff if (place == STAFFREL_above) { y = alignment->GetOverflowAbove() - - (alignment->GetVersePositionAbove(verseN, verseCollapse)) * (height + descender + margin) - (height); + - (alignment->GetVersePositionAbove(verseN, verseCollapse)) * (verseHeight + margin) - (height); } else { y = -alignment->GetStaffHeight() - alignment->GetOverflowBelow() - + alignment->GetVersePositionBelow(verseN, verseCollapse) * (height + descender + margin) + (descender); + + alignment->GetVersePositionBelow(verseN, verseCollapse) * (verseHeight + margin) + verseHeight - height; } return y;