Skip to content

Commit

Permalink
Add --lyric-height option
Browse files Browse the repository at this point in the history
  • Loading branch information
lpugin committed Dec 27, 2024
1 parent aae3bb5 commit b4d0d07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/vrv/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions src/adjustfloatingpositionerfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 13 additions & 4 deletions src/view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b4d0d07

Please sign in to comment.