From 64635379a78bc9fcd7b9441a7b4965f41f87b8c7 Mon Sep 17 00:00:00 2001 From: "rbs%maths.uq.edu.au" Date: Wed, 17 Nov 2004 04:12:02 +0000 Subject: [PATCH] Beautify ::first-letter by using MathML's GetBoundingMetrics, b=21616, r+sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@165418 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsLineLayout.cpp | 8 ++++++++ mozilla/layout/generic/nsTextFrame.cpp | 18 ++++++++++++++++++ mozilla/layout/html/base/src/nsLineLayout.cpp | 8 ++++++++ mozilla/layout/html/base/src/nsTextFrame.cpp | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/mozilla/layout/generic/nsLineLayout.cpp b/mozilla/layout/generic/nsLineLayout.cpp index b87935aa44a..9572cab2645 100644 --- a/mozilla/layout/generic/nsLineLayout.cpp +++ b/mozilla/layout/generic/nsLineLayout.cpp @@ -2052,6 +2052,14 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) nsHTMLReflowState::CalcLineHeight(mPresContext, rc, spanFrame); nscoord contentHeight = spanFramePFD->mBounds.height - spanFramePFD->mBorderPadding.top - spanFramePFD->mBorderPadding.bottom; + + // Special-case for a ::first-letter frame, set the line height to + // the frame height if the user has left line-height == normal + if (spanFramePFD->GetFlag(PFD_ISLETTERFRAME) && !spanPrevInFlow && + spanFrame->GetStyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal) { + logicalHeight = spanFramePFD->mBounds.height; + } + nscoord leading = logicalHeight - contentHeight; psd->mTopLeading = leading / 2; psd->mBottomLeading = leading - psd->mTopLeading; diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index ac680897f23..cb99a2a8762 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -4789,6 +4789,24 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, } else { aReflowState.rendContext->GetTextDimensions(bp2, wordLen, dimensions); } +#ifdef MOZ_MATHML + // If GetBoundingMetrics is available, use the exact glyph metrics + // for ::first-letter + // XXX remove the #ifdef if GetBoundingMetrics becomes mainstream + if (justDidFirstLetter) { + nsresult res; + nsBoundingMetrics bm; + if (aTx.TransformedTextIsAscii()) { + res = aReflowState.rendContext->GetBoundingMetrics(bp1, wordLen, bm); + } else { + res = aReflowState.rendContext->GetBoundingMetrics(bp2, wordLen, bm); + } + if (NS_SUCCEEDED(res)) { + aTextData.mAscent = dimensions.ascent = bm.ascent; + aTextData.mDescent = dimensions.descent = bm.descent; + } + } +#endif if (aTs.mLetterSpacing) { dimensions.width += aTs.mLetterSpacing * wordLen; } diff --git a/mozilla/layout/html/base/src/nsLineLayout.cpp b/mozilla/layout/html/base/src/nsLineLayout.cpp index b87935aa44a..9572cab2645 100644 --- a/mozilla/layout/html/base/src/nsLineLayout.cpp +++ b/mozilla/layout/html/base/src/nsLineLayout.cpp @@ -2052,6 +2052,14 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) nsHTMLReflowState::CalcLineHeight(mPresContext, rc, spanFrame); nscoord contentHeight = spanFramePFD->mBounds.height - spanFramePFD->mBorderPadding.top - spanFramePFD->mBorderPadding.bottom; + + // Special-case for a ::first-letter frame, set the line height to + // the frame height if the user has left line-height == normal + if (spanFramePFD->GetFlag(PFD_ISLETTERFRAME) && !spanPrevInFlow && + spanFrame->GetStyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal) { + logicalHeight = spanFramePFD->mBounds.height; + } + nscoord leading = logicalHeight - contentHeight; psd->mTopLeading = leading / 2; psd->mBottomLeading = leading - psd->mTopLeading; diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index ac680897f23..cb99a2a8762 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -4789,6 +4789,24 @@ nsTextFrame::MeasureText(nsPresContext* aPresContext, } else { aReflowState.rendContext->GetTextDimensions(bp2, wordLen, dimensions); } +#ifdef MOZ_MATHML + // If GetBoundingMetrics is available, use the exact glyph metrics + // for ::first-letter + // XXX remove the #ifdef if GetBoundingMetrics becomes mainstream + if (justDidFirstLetter) { + nsresult res; + nsBoundingMetrics bm; + if (aTx.TransformedTextIsAscii()) { + res = aReflowState.rendContext->GetBoundingMetrics(bp1, wordLen, bm); + } else { + res = aReflowState.rendContext->GetBoundingMetrics(bp2, wordLen, bm); + } + if (NS_SUCCEEDED(res)) { + aTextData.mAscent = dimensions.ascent = bm.ascent; + aTextData.mDescent = dimensions.descent = bm.descent; + } + } +#endif if (aTs.mLetterSpacing) { dimensions.width += aTs.mLetterSpacing * wordLen; }