diff --git a/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.cpp index 3454b664652..0b6231a1e74 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.cpp @@ -158,22 +158,20 @@ nsMathMLContainerFrame::GetRuleThickness(nsIRenderingContext& aRenderingContext, { // get the bounding metrics of the overbar char, the rendering context // is assumed to have been set with the font of the current style context - nsBoundingMetrics bm; + nscoord xHeight; + aFontMetrics->GetXHeight(xHeight); PRUnichar overBar = 0x00AF; + nsBoundingMetrics bm; nsresult rv = aRenderingContext.GetBoundingMetrics(&overBar, PRUint32(1), bm); if (NS_SUCCEEDED(rv)) { aRuleThickness = bm.ascent + bm.descent; } - else { - printf("GetBoundingMetrics() failed in GetRuleThickness()\n"); + if (NS_FAILED(rv) || aRuleThickness <= 0 || aRuleThickness >= xHeight) { // fall-back to the other version GetRuleThickness(aFontMetrics, aRuleThickness); } #if 0 - nscoord xHeight; - aRuleThickness->GetXHeight(xHeight); - nscoord oldRuleThickness; GetRuleThickness(aFontMetrics, oldRuleThickness); @@ -186,6 +184,39 @@ nsMathMLContainerFrame::GetRuleThickness(nsIRenderingContext& aRenderingContext, #endif } +void +nsMathMLContainerFrame::GetAxisHeight(nsIRenderingContext& aRenderingContext, + nsIFontMetrics* aFontMetrics, + nscoord& aAxisHeight) +{ + // get the bounding metrics of the minus sign, the rendering context + // is assumed to have been set with the font of the current style context + nscoord xHeight; + aFontMetrics->GetXHeight(xHeight); + PRUnichar minus = '-'; + nsBoundingMetrics bm; + nsresult rv = aRenderingContext.GetBoundingMetrics(&minus, PRUint32(1), bm); + if (NS_SUCCEEDED(rv)) { + aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2; + } + if (NS_FAILED(rv) || aAxisHeight <= 0 || aAxisHeight >= xHeight) { + // fall-back to the other version + GetAxisHeight(aFontMetrics, aAxisHeight); + } + +#if 0 + nscoord oldAxis; + GetAxisHeight(aFontMetrics, oldAxis); + + PRUnichar plus = '+'; + rv = aRenderingContext.GetBoundingMetrics(&plus, PRUint32(1), bm); + nscoord plusAxis = bm.ascent - (bm.ascent + bm.descent)/2;; + + printf("xheight:%4d Axis:%4d oldAxis:%4d plusAxis:%4d\n", + xHeight, aAxisHeight, oldAxis, plusAxis); +#endif +} + // ================ // Utilities for parsing and retrieving numeric values // All returned values are in twips. diff --git a/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.h b/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.h index 3d46415b195..0fad6495415 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.h +++ b/mozilla/layout/mathml/base/src/nsMathMLContainerFrame.h @@ -441,14 +441,19 @@ public: ruleThickness = NSToCoordRound (40.000f/430.556f * xHeight); } - // the rule thickness is not accurately obtained using the x-height. - // Here is a slow GetRuleThickness() which obtains the rule - // thickness by actually measuring the overbar char U+00AF + // Some parameters are not accurately obtained using the x-height. + // Here are some slower variants to obtain the desired metrics + // by actually measuring some characters static void GetRuleThickness(nsIRenderingContext& aRenderingContext, nsIFontMetrics* aFontMetrics, nscoord& aRuleThickness); + static void + GetAxisHeight(nsIRenderingContext& aRenderingContext, + nsIFontMetrics* aFontMetrics, + nscoord& aAxisHeight); + protected: // information about the presentation policy of the frame diff --git a/mozilla/layout/mathml/base/src/nsMathMLmfencedFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmfencedFrame.cpp index 521fce9cc91..2475b69c8c3 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmfencedFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmfencedFrame.cpp @@ -330,9 +330,10 @@ nsMathMLmfencedFrame::Reflow(nsIPresContext* aPresContext, nsStyleFont font; mStyleContext->GetStyle(eStyleStruct_Font, font); nsCOMPtr fm; - aPresContext->GetMetricsFor(font.mFont, getter_AddRefs(fm)); + aReflowState.rendContext->SetFont(font.mFont); + aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm)); nscoord axisHeight, em; - GetAxisHeight(fm, axisHeight); + GetAxisHeight(*aReflowState.rendContext, fm, axisHeight); em = NSToCoordRound(float(font.mFont.size)); nscoord fontAscent, fontDescent; diff --git a/mozilla/layout/mathml/base/src/nsMathMLmfracFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmfracFrame.cpp index 026e9926a02..e1025890606 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmfracFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmfracFrame.cpp @@ -355,7 +355,8 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext, } else { // Rule 15d, App. G, TeXbook - GetAxisHeight (fm, axisHeight); +// GetAxisHeight (fm, axisHeight); + GetAxisHeight(aRenderingContext, fm, axisHeight); // min clearance between numerator or denominator and middle of bar diff --git a/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp index 9c8a67ea1d9..c0712c517be 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp @@ -131,9 +131,6 @@ nsMathMLmoFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.SetColor(NS_RGB(0,255,255)); nscoord x = mReference.x + mBoundingMetrics.leftBearing; nscoord y = mReference.y - mBoundingMetrics.ascent; -//nsRect rect; -//mMathMLChar.GetRect(rect); -//y = rect.y; nscoord w = mBoundingMetrics.rightBearing - mBoundingMetrics.leftBearing; nscoord h = mBoundingMetrics.ascent + mBoundingMetrics.descent; aRenderingContext.DrawRect(x,y,w,h); @@ -558,9 +555,10 @@ nsMathMLmoFrame::Stretch(nsIPresContext* aPresContext, nsStyleFont font; mStyleContext->GetStyle(eStyleStruct_Font, font); nsCOMPtr fm; - aPresContext->GetMetricsFor(font.mFont, getter_AddRefs(fm)); + aRenderingContext.SetFont(font.mFont); + aRenderingContext.GetFontMetrics(*getter_AddRefs(fm)); nscoord fontAscent, fontDescent, axisHeight; - GetAxisHeight(fm, axisHeight); + GetAxisHeight(aRenderingContext, fm, axisHeight); fm->GetMaxAscent(fontAscent); fm->GetMaxDescent(fontDescent); diff --git a/mozilla/layout/mathml/base/src/nsMathMLmrootFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmrootFrame.cpp index 024e587b036..f1bc87d36de 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmrootFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmrootFrame.cpp @@ -45,11 +45,14 @@ // and -- form a radical - implementation // -//TODO: -// The code assumes that TeX fonts are picked! Another separate version of -// Reflow() is needed as a fall-back for cases where TeX fonts (CMSY/CMEX) -// are not installed on the system, e.g., the fall-back could explicitly -// draw the branches of the radical using th default rule thickness. +//NOTE: +// The code assumes that TeX fonts are picked. +// There is not fall-back to draw the branches of the sqrt explicitly +// in the case where TeX fonts are not there. In general, there is not +// fall-back(s) in MathML when some (freely-downloadable) fonts are missing. +// Otherwise, this will add much work and unnecessary complexity to the core +// MathML engine. Assuming that authors have the free fonts is part of the +// deal. We are not responsible for cases of misconfigurations out there. // additional style context to be used by our MathMLChar. #define NS_SQR_CHAR_STYLE_CONTEXT_INDEX 0 @@ -109,20 +112,26 @@ nsMathMLmrootFrame::Paint(nsIPresContext* aPresContext, { nsresult rv = NS_OK; - + ///////////// + // paint the content we are square-rooting + rv = nsMathMLContainerFrame::Paint(aPresContext, aRenderingContext, + aDirtyRect, aWhichLayer); ///////////// // paint the sqrt symbol - if ((NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) && - !NS_MATHML_HAS_ERROR(mPresentationData.flags)) + if (!NS_MATHML_HAS_ERROR(mPresentationData.flags)) { mSqrChar.Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, this); - // paint the overline bar - nsStyleColor color; - mStyleContext->GetStyle(eStyleStruct_Color, color); - aRenderingContext.SetColor(color.mColor); - aRenderingContext.FillRect(mBarRect.x, mBarRect.y, - mBarRect.width, mBarRect.height); + + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) + { + // paint the overline bar + nsStyleColor color; + mStyleContext->GetStyle(eStyleStruct_Color, color); + aRenderingContext.SetColor(color.mColor); + aRenderingContext.FillRect(mBarRect.x, mBarRect.y, + mBarRect.width, mBarRect.height); + } #if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX) // for visual debug @@ -144,10 +153,6 @@ nsMathMLmrootFrame::Paint(nsIPresContext* aPresContext, #endif } - ///////////// - // paint the content we are square-rooting - rv = nsMathMLContainerFrame::Paint(aPresContext, aRenderingContext, - aDirtyRect, aWhichLayer); return rv; } diff --git a/mozilla/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp index 1868c0d91f6..1acaff740f5 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmsqrtFrame.cpp @@ -45,11 +45,14 @@ // and -- form a radical - implementation // -//TODO: -// The code assumes that TeX fonts are picked! Another separate version of -// Reflow() is needed as a fall-back for cases where TeX fonts (CMSY/CMEX) -// are not installed on the system, e.g., the fall-back could explicitly -// draw the branches of the radical using th default rule thickness. +//NOTE: +// The code assumes that TeX fonts are picked. +// There is not fall-back to draw the branches of the sqrt explicitly +// in the case where TeX fonts are not there. In general, there is not +// fall-back(s) in MathML when some (freely-downloadable) fonts are missing. +// Otherwise, this will add much work and unnecessary complexity to the core +// MathML engine. Assuming that authors have the free fonts is part of the +// deal. We are not responsible for cases of misconfigurations out there. // additional style context to be used by our MathMLChar. #define NS_SQR_CHAR_STYLE_CONTEXT_INDEX 0 @@ -90,7 +93,7 @@ nsMathMLmsqrtFrame::Init(nsIPresContext* aPresContext, rv = nsMathMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - mEmbellishData.flags = NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY; + mEmbellishData.flags |= NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY; mSqrChar.SetEnum(aPresContext, eMathMLChar_Sqrt); ResolveMathMLCharStyle(aPresContext, mContent, mStyleContext, &mSqrChar); @@ -109,20 +112,26 @@ nsMathMLmsqrtFrame::Paint(nsIPresContext* aPresContext, { nsresult rv = NS_OK; - + ///////////// + // paint the content we are square-rooting + rv = nsMathMLContainerFrame::Paint(aPresContext, aRenderingContext, + aDirtyRect, aWhichLayer); ///////////// // paint the sqrt symbol - if ((NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) && - !NS_MATHML_HAS_ERROR(mPresentationData.flags)) + if (!NS_MATHML_HAS_ERROR(mPresentationData.flags)) { mSqrChar.Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, this); - // paint the overline bar - nsStyleColor color; - mStyleContext->GetStyle(eStyleStruct_Color, color); - aRenderingContext.SetColor(color.mColor); - aRenderingContext.FillRect(mBarRect.x, mBarRect.y, - mBarRect.width, mBarRect.height); + + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) + { + // paint the overline bar + nsStyleColor color; + mStyleContext->GetStyle(eStyleStruct_Color, color); + aRenderingContext.SetColor(color.mColor); + aRenderingContext.FillRect(mBarRect.x, mBarRect.y, + mBarRect.width, mBarRect.height); + } #if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX) // for visual debug @@ -144,10 +153,6 @@ nsMathMLmsqrtFrame::Paint(nsIPresContext* aPresContext, #endif } - ///////////// - // paint the content we are square-rooting - rv = nsMathMLContainerFrame::Paint(aPresContext, aRenderingContext, - aDirtyRect, aWhichLayer); return rv; } diff --git a/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.cpp index 03a4703f36e..18eb019eda2 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.cpp @@ -111,10 +111,11 @@ nsMathMLmtableOuterFrame::Reflow(nsIPresContext* aPresContext, nsStyleFont font; mStyleContext->GetStyle(eStyleStruct_Font, font); nsCOMPtr fm; - aPresContext->GetMetricsFor(font.mFont, getter_AddRefs(fm)); + aReflowState.rendContext->SetFont(font.mFont); + aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm)); nscoord axisHeight; - GetAxisHeight(fm, axisHeight); + GetAxisHeight(*aReflowState.rendContext, fm, axisHeight); // center about the axis aDesiredSize.ascent = aDesiredSize.height/2 + axisHeight; diff --git a/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.h b/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.h index ede966b1142..628d1f674ef 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.h +++ b/mozilla/layout/mathml/base/src/nsMathMLmtableFrame.h @@ -159,6 +159,26 @@ public: axisHeight = NSToCoordRound (250.000f/430.556f * axisHeight); } + + static void + GetAxisHeight(nsIRenderingContext& aRenderingContext, + nsIFontMetrics* aFontMetrics, + nscoord& aAxisHeight) + { + // get the bounding metrics of the minus sign, the rendering context + // is assumed to have been set with the font of the current style context + nsBoundingMetrics bm; + PRUnichar minus = '-'; + nsresult rv = aRenderingContext.GetBoundingMetrics(&minus, PRUint32(1), bm); + if (NS_SUCCEEDED(rv)) { + aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2; + } + if (NS_FAILED(rv) || aAxisHeight <= 0) { + // fall-back to the other version + GetAxisHeight(aFontMetrics, aAxisHeight); + } + } + protected: nsMathMLmtableOuterFrame(); virtual ~nsMathMLmtableOuterFrame();