From 38784472e4d88f7165bfb63f4a5a6dd45dac6288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Tue, 17 Jun 2014 02:41:00 -0400 Subject: [PATCH] Bug 961365 - Part 3: Use MATH constants for fractions and stacks. r=jfkthame --- layout/mathml/nsMathMLmfracFrame.cpp | 111 +++++++++++++++++++-------- 1 file changed, 81 insertions(+), 30 deletions(-) diff --git a/layout/mathml/nsMathMLmfracFrame.cpp b/layout/mathml/nsMathMLmfracFrame.cpp index 53b8ce51cee..34ade9929dc 100644 --- a/layout/mathml/nsMathMLmfracFrame.cpp +++ b/layout/mathml/nsMathMLmfracFrame.cpp @@ -219,7 +219,15 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, aRenderingContext.SetFont(fm); nscoord defaultRuleThickness, axisHeight; - GetRuleThickness(aRenderingContext, fm, defaultRuleThickness); + nscoord oneDevPixel = fm->AppUnitsPerDevPixel(); + gfxFont* mathFont = fm->GetThebesFontGroup()->GetFirstMathFont(); + if (mathFont) { + defaultRuleThickness = + mathFont->GetMathConstant(gfxFontEntry::FractionRuleThickness, + oneDevPixel); + } else { + GetRuleThickness(aRenderingContext, fm, defaultRuleThickness); + } GetAxisHeight(aRenderingContext, fm, axisHeight); bool outermostEmbellished = false; @@ -239,6 +247,8 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::bevelled_, value); mIsBevelled = value.EqualsLiteral("true"); + bool displayStyle = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK; + if (!mIsBevelled) { mLineRect.height = mLineThickness; @@ -258,6 +268,8 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, coreData.leadingSpace : coreData.trailingSpace; } + nscoord actualRuleThickness = mLineThickness; + ////////////////// // Get shifts nscoord numShift = 0; @@ -269,28 +281,54 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, GetNumeratorShifts(fm, numShift1, numShift2, numShift3); GetDenominatorShifts(fm, denShift1, denShift2); - if (StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK) { - // C > T - numShift = numShift1; - denShift = denShift1; - } - else { - numShift = (0 < mLineRect.height) ? numShift2 : numShift3; - denShift = denShift2; - } - nscoord minClearance = 0; - nscoord actualClearance = 0; - - nscoord actualRuleThickness = mLineThickness; + if (0 == actualRuleThickness) { + numShift = displayStyle ? numShift1 : numShift3; + denShift = displayStyle ? denShift1 : denShift2; + if (mathFont) { + numShift = mathFont-> + GetMathConstant(displayStyle ? + gfxFontEntry::StackTopDisplayStyleShiftUp : + gfxFontEntry::StackTopShiftUp, + oneDevPixel); + denShift = mathFont-> + GetMathConstant(displayStyle ? + gfxFontEntry::StackBottomDisplayStyleShiftDown : + gfxFontEntry::StackBottomShiftDown, + oneDevPixel); + } + } else { + numShift = displayStyle ? numShift1 : numShift2; + denShift = displayStyle ? denShift1 : denShift2; + if (mathFont) { + numShift = mathFont-> + GetMathConstant(displayStyle ? + gfxFontEntry::FractionNumeratorDisplayStyleShiftUp : + gfxFontEntry::FractionNumeratorShiftUp, + oneDevPixel); + denShift = mathFont-> + GetMathConstant( + displayStyle ? + gfxFontEntry::FractionDenominatorDisplayStyleShiftDown : + gfxFontEntry::FractionDenominatorShiftDown, + oneDevPixel); + } + } if (0 == actualRuleThickness) { // Rule 15c, App. G, TeXbook // min clearance between numerator and denominator - minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK ? + nscoord minClearance = displayStyle ? 7 * defaultRuleThickness : 3 * defaultRuleThickness; - actualClearance = + if (mathFont) { + minClearance = + mathFont->GetMathConstant(displayStyle ? + gfxFontEntry::StackDisplayStyleGapMin : + gfxFontEntry::StackGapMin, + oneDevPixel); + } + nscoord actualClearance = (numShift - bmNum.descent) - (bmDen.ascent - denShift); // actualClearance should be >= minClearance if (actualClearance < minClearance) { @@ -306,27 +344,40 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, // TeX has a different interpretation of the thickness. // Try $a \above10pt b$ to see. Here is what TeX does: - // minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK - // ? 3 * actualRuleThickness : actualRuleThickness; + // minClearance = displayStyle ? + // 3 * actualRuleThickness : actualRuleThickness; // we slightly depart from TeX here. We use the defaultRuleThickness instead // of the value coming from the linethickness attribute, i.e., we recover what // TeX does if the user hasn't set linethickness. But when the linethickness // is set, we avoid the wide gap problem. - minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK ? - 3 * defaultRuleThickness : defaultRuleThickness + onePixel; - - // adjust numShift to maintain minClearance if needed - actualClearance = - (numShift - bmNum.descent) - (axisHeight + actualRuleThickness/2); - if (actualClearance < minClearance) { - numShift += (minClearance - actualClearance); + nscoord minClearanceNum = displayStyle ? + 3 * defaultRuleThickness : defaultRuleThickness + onePixel; + nscoord minClearanceDen = minClearanceNum; + if (mathFont) { + minClearanceNum = mathFont-> + GetMathConstant(displayStyle ? + gfxFontEntry::FractionNumDisplayStyleGapMin : + gfxFontEntry::FractionNumeratorGapMin, + oneDevPixel); + minClearanceDen = mathFont-> + GetMathConstant(displayStyle ? + gfxFontEntry::FractionDenomDisplayStyleGapMin : + gfxFontEntry::FractionDenominatorGapMin, + oneDevPixel); } - // adjust denShift to maintain minClearance if needed - actualClearance = + + // adjust numShift to maintain minClearanceNum if needed + nscoord actualClearanceNum = + (numShift - bmNum.descent) - (axisHeight + actualRuleThickness/2); + if (actualClearanceNum < minClearanceNum) { + numShift += (minClearanceNum - actualClearanceNum); + } + // adjust denShift to maintain minClearanceDen if needed + nscoord actualClearanceDen = (axisHeight - actualRuleThickness/2) - (bmDen.ascent - denShift); - if (actualClearance < minClearance) { - denShift += (minClearance - actualClearance); + if (actualClearanceDen < minClearanceDen) { + denShift += (minClearanceDen - actualClearanceDen); } }