@@ -1005,6 +1005,7 @@ void TextBlock::layout(const TextBase* t)
10051005
10061006 double layoutWidth = 0 ;
10071007 EngravingItem* e = t->parentItem ();
1008+ // TODO - remove when position is implemented for all text items
10081009 if (e && t->layoutToParentWidth ()) {
10091010 layoutWidth = e->width ();
10101011 switch (e->type ()) {
@@ -1085,18 +1086,24 @@ void TextBlock::layout(const TextBase* t)
10851086 x += w;
10861087 }
10871088
1088- const bool adjustCodaSymbol = fragmentFont.type () == Font::Type::MusicSymbolText && t->isMarker () && fi != m_fragments. begin () ;
1089-
1089+ const bool adjustCodaSymbol = fragmentFont.type () == Font::Type::MusicSymbolText && t->isMarker ();
1090+ double yOffset = 0.0 ;
10901091 if (adjustCodaSymbol) {
1091- // Align the x-height of the coda symbol to half the x-height of the previous text
1092- TextFragment& prevFragment = *(std::prev (fi));
1093- FontMetrics prevFm (prevFragment.font (t));
1092+ // Align the x-height of the coda symbol to half the x-height of the surrounding text
1093+ Font refFont;
1094+ if (m_fragments.size () == 1 ) {
1095+ refFont = t->font ();
1096+ } else {
1097+ TextFragment& refFragment = fi != m_fragments.begin () ? *(std::prev (fi)) : *(std::next (fi));
1098+ refFont = refFragment.font (t);
1099+ }
1100+ FontMetrics refFm (refFont);
10941101
1095- double middle = (fm.tightBoundingRect (f.text ).height () / 2 ) - fm.tightBoundingRect (f.text ).bottom ();
1096- double prevXHeight = prevFm .capHeight () / 2 ;
1097- double diff = prevXHeight - middle;
1102+ const double middle = (fm.tightBoundingRect (f.text ).height () / 2 ) - fm.tightBoundingRect (f.text ).bottom ();
1103+ const double refXHeight = refFm .capHeight () / 2 ;
1104+ yOffset = refXHeight - middle;
10981105
1099- f.pos .ry () -= diff ;
1106+ f.pos .ry () -= yOffset ;
11001107 }
11011108
11021109 RectF textBRect = fm.tightBoundingRect (f.text ).translated (f.pos );
@@ -1112,12 +1119,12 @@ void TextBlock::layout(const TextBase* t)
11121119 } else {
11131120 m_shape.add (textBRect, t);
11141121 }
1115-
11161122 if (fragmentFont.type () == Font::Type::MusicSymbol || fragmentFont.type () == Font::Type::MusicSymbolText) {
11171123 // SEMI-HACK: Music fonts can have huge linespacing because of tall symbols, so instead of using the
11181124 // font linespacing value we just use the height of the individual fragment with some added margin
11191125
1120- m_lineSpacing = std::max (m_lineSpacing, 1.25 * m_shape.bbox ().height ());
1126+ m_lineSpacing = std::max (m_lineSpacing, 1.25 * (m_shape.bbox ().height () - m_shape.bbox ().bottom ()) + yOffset);
1127+ // m_lineSpacing = std::max(m_lineSpacing, 1.25 * m_shape.bbox().height());
11211128 } else {
11221129 m_lineSpacing = std::max (m_lineSpacing, fm.lineSpacing ());
11231130 }
0 commit comments