@@ -14,14 +14,31 @@ static Float getTextRunLineHeight( const std::shared_ptr<Text>& text, Float line
1414 return lineHeight > 0 ? lineHeight : fontStyle.Font ->getLineSpacing ( fontStyle.CharacterSize );
1515}
1616
17- static Float getTextBaseline ( const std::shared_ptr<Text>& text, Float lineHeight ) {
17+ static Float getTextVisualLineHeight ( const std::shared_ptr<Text>& text, Float lineHeight ) {
18+ if ( !text || !text->getFontStyleConfig ().Font )
19+ return lineHeight;
20+ const auto & fontStyle = text->getFontStyleConfig ();
21+ return fontStyle.Font ->getLineSpacing ( fontStyle.CharacterSize );
22+ }
23+
24+ static Float getTextVisualBaseline ( const std::shared_ptr<Text>& text ) {
1825 if ( !text || !text->getFontStyleConfig ().Font )
1926 return 0 .f ;
2027 const auto & fontStyle = text->getFontStyleConfig ();
21- Float fontLineSpacing = fontStyle.Font ->getLineSpacing ( fontStyle.CharacterSize );
22- Float usedLineHeight = getTextRunLineHeight ( text, lineHeight );
28+ return fontStyle.Font ->getAscent ( fontStyle.CharacterSize );
29+ }
30+
31+ static Float getTextLineBoxBaselineForHeight ( const std::shared_ptr<Text>& text,
32+ Float usedLineHeight ) {
33+ if ( !text || !text->getFontStyleConfig ().Font )
34+ return 0 .f ;
35+ Float fontLineSpacing = getTextVisualLineHeight ( text, usedLineHeight );
2336 Float leading = eemax ( 0 .f , usedLineHeight - fontLineSpacing ) * 0 .5f ;
24- return leading + fontStyle.Font ->getAscent ( fontStyle.CharacterSize );
37+ return leading + getTextVisualBaseline ( text );
38+ }
39+
40+ static Float getTextLineBoxBaseline ( const std::shared_ptr<Text>& text, Float lineHeight ) {
41+ return getTextLineBoxBaselineForHeight ( text, getTextRunLineHeight ( text, lineHeight ) );
2542}
2643
2744static Float getFontXHeight ( const FontStyleConfig& fontStyle ) {
@@ -839,7 +856,7 @@ class RichTextInlineLayouter {
839856 bool isFloat = span.floatType != RichText::InlineFloat::None;
840857
841858 if ( span.type == RichText::RenderSpan::Type::Text ) {
842- Float baseline = getTextBaseline ( span.text , span. lineHeight );
859+ Float baseline = getTextVisualBaseline ( span.text );
843860 RichText::BaselineAlignValue baselineAlign = effectiveInlineBaselineAlign (
844861 inlineItems, span.inlinePath , span.baselineAlign );
845862 Float offsetY = getBaselineAlignedOffset (
@@ -1749,34 +1766,38 @@ class RichTextInlineLayouter {
17491766 const std::vector<RichText::InlineItem>& inlineItems ) {
17501767 Float maxAscent = 0 .f ;
17511768 Float maxDescent = 0 .f ;
1752- bool hasParticipatingAncestorLineHeight = false ;
1769+ bool hasParticipatingLineHeight = forcedLineHeight > 0 . f ;
17531770
17541771 for ( const auto & span : line.spans ) {
17551772 if ( span.type == RichText::RenderSpan::Type::Text ) {
17561773 InlineVerticalEdges edges = inlineAncestorLineHeightEdges (
17571774 inlineItems, span.inlinePath , span.size .getHeight () );
1758- hasParticipatingAncestorLineHeight =
1759- hasParticipatingAncestorLineHeight || edges.top > 0 || edges.bottom > 0 ;
1760- Float baseline = getTextBaseline ( span.text , span.lineHeight );
1775+ hasParticipatingLineHeight =
1776+ hasParticipatingLineHeight || edges.top > 0 || edges.bottom > 0 ;
1777+ Float lineHeight =
1778+ span.lineHeight > 0 .f
1779+ ? getTextRunLineHeight ( span.text , span.lineHeight )
1780+ : eemax ( forcedLineHeight,
1781+ getTextRunLineHeight ( span.text , span.lineHeight ) );
1782+ Float baseline = getTextLineBoxBaselineForHeight ( span.text , lineHeight );
17611783 maxAscent = std::max ( maxAscent, baseline + edges.top );
1762- maxDescent =
1763- std::max ( maxDescent, span.size .getHeight () - baseline + edges.bottom );
1784+ maxDescent = std::max ( maxDescent, lineHeight - baseline + edges.bottom );
17641785 } else {
17651786 bool isFloat = span.floatType != RichText::InlineFloat::None;
17661787 Float baseline = span.baseline ;
17671788 InlineVerticalEdges edges = inlineAncestorLineHeightEdges (
17681789 inlineItems, span.inlinePath , span.size .getHeight () );
17691790 if ( preserveFloatPositions && isFloat )
17701791 continue ;
1771- hasParticipatingAncestorLineHeight =
1772- hasParticipatingAncestorLineHeight || edges.top > 0 || edges.bottom > 0 ;
1792+ hasParticipatingLineHeight =
1793+ hasParticipatingLineHeight || edges.top > 0 || edges.bottom > 0 ;
17731794 maxAscent = std::max ( maxAscent, baseline + edges.top );
17741795 maxDescent =
17751796 std::max ( maxDescent, span.size .getHeight () - baseline + edges.bottom );
17761797 }
17771798 }
17781799
1779- if ( !hasParticipatingAncestorLineHeight )
1800+ if ( !hasParticipatingLineHeight )
17801801 return ;
17811802
17821803 line.maxAscent = maxAscent;
@@ -1796,8 +1817,9 @@ class RichTextInlineLayouter {
17961817 renderSpanText->setStyleConfig ( renderStyle );
17971818 renderSpanText->setTabWidth ( payload.text ->getTabWidth () );
17981819
1799- Float height = getTextRunLineHeight ( payload.text , payload.lineHeight );
1800- Float ascent = getTextBaseline ( payload.text , payload.lineHeight );
1820+ Float height = getTextVisualLineHeight ( payload.text , payload.lineHeight );
1821+ Float lineHeight = getTextRunLineHeight ( payload.text , payload.lineHeight );
1822+ Float ascent = getTextLineBoxBaseline ( payload.text , payload.lineHeight );
18011823 Float spanWidth = renderSpanText->getTextWidth ();
18021824
18031825 RichText::RenderSpan renderSpan;
@@ -1818,7 +1840,7 @@ class RichTextInlineLayouter {
18181840
18191841 line.spans .push_back ( std::move ( renderSpan ) );
18201842 line.maxAscent = std::max ( line.maxAscent , ascent );
1821- line.height = std::max ( line.height , height );
1843+ line.height = std::max ( line.height , lineHeight );
18221844
18231845 curX += spanWidth;
18241846 line.width += spanWidth;
0 commit comments