[not part of default build] Recover from API changes and update the compression flag to match TeX

git-svn-id: svn://10.0.0.236/trunk@86068 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rbs%maths.uq.edu.au
2001-02-02 09:38:48 +00:00
parent 6e0b6f967b
commit 18baf8bf80
7 changed files with 127 additions and 107 deletions

View File

@@ -110,6 +110,7 @@ nsMathMLmactionFrame::Init(nsIPresContext* aPresContext,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv;
nsAutoString value, prefix;
// Init our local attributes
@@ -179,7 +180,13 @@ nsMathMLmactionFrame::Init(nsIPresContext* aPresContext,
}
// Let the base class do the rest
return nsMathMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
rv = nsMathMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
#if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS;
#endif
return rv;
}
// return the frame whose number is given by the attribute selection="number"
@@ -296,7 +303,7 @@ nsMathMLmactionFrame::Paint(nsIPresContext* aPresContext,
{
const nsStyleDisplay* disp =
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
if (0 && NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
if (disp->IsVisible() && mRect.width && mRect.height) {
// Paint our background and border
PRIntn skipSides = GetSkipSides();
@@ -319,6 +326,21 @@ nsMathMLmactionFrame::Paint(nsIPresContext* aPresContext,
if (childFrame)
PaintChild(aPresContext, aRenderingContext, aDirtyRect, childFrame, aWhichLayer);
#if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
// visual debug
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer &&
NS_MATHML_PAINT_BOUNDING_METRICS(mPresentationData.flags))
{
aRenderingContext.SetColor(NS_RGB(0,0,255));
nscoord x = mReference.x + mBoundingMetrics.leftBearing;
nscoord y = mReference.y - mBoundingMetrics.ascent;
nscoord w = mBoundingMetrics.rightBearing - mBoundingMetrics.leftBearing;
nscoord h = mBoundingMetrics.ascent + mBoundingMetrics.descent;
aRenderingContext.DrawRect(x,y,w,h);
}
#endif
return NS_OK;
}

View File

@@ -458,7 +458,7 @@ nsMathMLmfencedFrame::ReflowChar(nsIPresContext* aPresContext,
nsAutoString aData;
aMathMLChar->GetData(aData);
aMathMLChar->SetData(aPresContext, aData); // XXX hack to reset the enum, bug 45010
aMathMLChar->SetData(aPresContext, aData); // XXX hack to reset, bug 45010
PRBool found = nsMathMLOperators::LookupOperator(aData, aForm,
&aFlags, &aLeftSpace, &aRightSpace);
@@ -470,12 +470,11 @@ nsMathMLmfencedFrame::ReflowChar(nsIPresContext* aPresContext,
// stretch the char to the appropriate height if it is not big enough.
nsBoundingMetrics charSize;
charSize.Clear(); // this will tell stretch that we don't know the default size
nsresult res = aMathMLChar->Stretch(aPresContext, aRenderingContext,
NS_STRETCH_DIRECTION_VERTICAL,
aContainerSize, charSize);
if (eMathMLChar_DONT_STRETCH != aMathMLChar->GetEnum())
if (NS_STRETCH_DIRECTION_UNSUPPORTED != aMathMLChar->GetStretchDirection())
{
// has changed... so center the char around the axis
nscoord height = charSize.ascent + charSize.descent;
@@ -526,7 +525,7 @@ nsMathMLmfencedFrame::PlaceChar(nsMathMLChar* aMathMLChar,
aMathMLChar->GetRect(rect);
nscoord dy = aDesiredAscent - rect.y;
if (aMathMLChar->GetEnum() == eMathMLChar_DONT_STRETCH)
if (aMathMLChar->GetStretchDirection() == NS_STRETCH_DIRECTION_UNSUPPORTED)
{
// normal char, nsMathMLChar::Paint() will substract this later
dy += (aFontAscent - bm.ascent);

View File

@@ -195,44 +195,6 @@ nsMathMLmfracFrame::Paint(nsIPresContext* aPresContext,
aDirtyRect, aWhichLayer);
}
// over-ride the default method to update presentation parameters
// Rule 15a, App. G, TeXbook
NS_IMETHODIMP
nsMathMLmfracFrame::UpdatePresentationDataFromChildAt(PRInt32 aIndex,
PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed)
{
PRBool compressed;
nsIFrame* childFrame = mFrames.FirstChild();
while (nsnull != childFrame) {
if (!IsOnlyWhitespace(childFrame)) {
nsIMathMLFrame* aMathMLFrame = nsnull;
nsresult rv = childFrame->QueryInterface
(NS_GET_IID(nsIMathMLFrame), (void**)&aMathMLFrame);
if (NS_SUCCEEDED(rv) && nsnull != aMathMLFrame) {
if (0 == aIndex++) {
// numerator uses default compression
compressed = aCompressed;
}
else {
// denominator is 'compressed' (means 'prime' style in App. G, TeXbook)
compressed = PR_TRUE;
}
// update
aMathMLFrame->UpdatePresentationData
(aScriptLevelIncrement, aDisplayStyle, compressed);
// propagate down the subtrees
aMathMLFrame->UpdatePresentationDataFromChildAt
(0, aScriptLevelIncrement, aDisplayStyle, compressed);
}
}
childFrame->GetNextSibling(&childFrame);
}
return NS_OK;
}
NS_IMETHODIMP
nsMathMLmfracFrame::Place(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
@@ -269,7 +231,7 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext,
rv = childFrame->GetNextSibling(&childFrame);
}
#ifdef NS_DEBUG
if (2 != count) printf("mfrac: invalid markup");
if (2 != count) printf("mfrac: invalid markup\n");
#endif
if ((2 != count) || !frameNum || !frameDen) {
// report an error, encourage people to get their markups in order
@@ -320,7 +282,7 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext,
nscoord actualClearance = 0;
nscoord axisHeight = 0;
nscoord actualRuleThickness = (0 < mLineRect.height) ? mLineRect.height : 0;
nscoord actualRuleThickness = mLineRect.height;
if (0 == actualRuleThickness) {
// Rule 15c, App. G, TeXbook
@@ -345,14 +307,15 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext,
// TeX has a different interpretation of the thickeness.
// Try $a \above10pt b$ to see. Here is what TeX does:
// minClearance = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
// 3 * actualRuleThickness : actualRuleThickness;
// minClearance = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
// 3 * actualRuleThickness : actualRuleThickness;
// we don't follow TeX here, we use a modified version of Rule 15c in which
// one defaultRuleThickness is replaced by one actualRuleThickness
minClearance = actualRuleThickness +
(NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
6 * defaultRuleThickness : 2 * defaultRuleThickness;
// 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 = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
3 * defaultRuleThickness : defaultRuleThickness + onePixel;
// adjust numShift to maintain minClearance if needed
actualClearance =
@@ -372,6 +335,8 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext,
// Place Children
// there is 1 pixel padding at either end of the fraction
// XXX Need revisiting the width. TeX uses the exact width
// e.g. in $$\huge\frac{\displaystyle\int}{i}$$
nscoord width = 2*onePixel + PR_MAX(bmNum.width, bmDen.width);
nscoord dxNum = (width - sizeNum.width)/2;
nscoord dxDen = (width - sizeDen.width)/2;

View File

@@ -83,13 +83,6 @@ public:
nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize);
#if 0
NS_IMETHOD
Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
#endif
NS_IMETHOD
Paint(nsIPresContext* aPresContext,
@@ -97,12 +90,6 @@ public:
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD
UpdatePresentationDataFromChildAt(PRInt32 aIndex,
PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed);
NS_IMETHOD
SetInitialChildList(nsIPresContext* aPresContext,
nsIAtom* aListName,
@@ -110,8 +97,23 @@ public:
{
nsresult rv;
rv = nsMathMLContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList);
UpdatePresentationDataFromChildAt(0, 1, PR_FALSE, PR_FALSE);
// 1. The REC says:
// The <mfrac> element sets displaystyle to "false", or if it was already
// false increments scriptlevel by 1, within numerator and denominator.
// 2. The TeXbook (Ch 17. p.141) says the numerator inherits the compression
// while the denominator is compressed
PRInt32 increment =
NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags) ? 0 : 1;
UpdatePresentationDataFromChildAt(0, -1, increment,
~NS_MATHML_DISPLAYSTYLE,
NS_MATHML_DISPLAYSTYLE);
UpdatePresentationDataFromChildAt(1, 1, 0,
NS_MATHML_COMPRESSED,
NS_MATHML_COMPRESSED);
// switch the style of the numerator and denominator if necessary
InsertScriptLevelStyleContext(aPresContext);
// check whether or not this is an embellished operator
EmbellishOperator();
return rv;
}

View File

@@ -121,9 +121,9 @@ nsMathMLmstyleFrame::Init(nsIPresContext* aPresContext,
}
NS_IMETHODIMP
nsMathMLmstyleFrame::UpdatePresentationData(PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed)
nsMathMLmstyleFrame::UpdatePresentationData(PRInt32 aScriptLevelIncrement,
PRUint32 aFlagsValues,
PRUint32 aFlagsToUpdate)
{
// mstyle is special...
// Since UpdatePresentationData() can be called by a parent frame, the
@@ -131,46 +131,74 @@ nsMathMLmstyleFrame::UpdatePresentationData(PRInt32 aScriptLevelIncrement,
// Update only if attributes are not there
if (!NS_MATHML_IS_MSTYLE_WITH_DISPLAYSTYLE(mPresentationData.flags)) {
if (aDisplayStyle)
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
else
mPresentationData.flags &= ~NS_MATHML_DISPLAYSTYLE;
// update the flag if it is relevant to this call
if (NS_MATHML_IS_DISPLAYSTYLE(aFlagsToUpdate)) {
// updating the displaystyle flag is allowed
if (NS_MATHML_IS_DISPLAYSTYLE(aFlagsValues)) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
else {
mPresentationData.flags &= ~NS_MATHML_DISPLAYSTYLE;
}
}
}
if (!NS_MATHML_IS_MSTYLE_WITH_EXPLICIT_SCRIPTLEVEL(mPresentationData.flags)) {
mPresentationData.scriptLevel += aScriptLevelIncrement;
}
if (aCompressed)
mPresentationData.flags |= NS_MATHML_COMPRESSED;
else
mPresentationData.flags &= ~NS_MATHML_COMPRESSED;
if (NS_MATHML_IS_COMPRESSED(aFlagsToUpdate)) {
// updating the compression flag is allowed
if (NS_MATHML_IS_COMPRESSED(aFlagsValues)) {
// 'compressed' means 'prime' style in App. G, TeXbook
mPresentationData.flags |= NS_MATHML_COMPRESSED;
}
// no else. the flag is sticky. it retains its value once it is set
}
return NS_OK;
}
NS_IMETHODIMP
nsMathMLmstyleFrame::UpdatePresentationDataFromChildAt(PRInt32 aIndex,
PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed)
nsMathMLmstyleFrame::UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
PRInt32 aLastIndex,
PRInt32 aScriptLevelIncrement,
PRUint32 aFlagsValues,
PRUint32 aFlagsToUpdate)
{
// mstyle is special...
// Since UpdatePresentationDataFromChildAt() can be called by a parent frame,
// wee need to ensure that the attributes of mstyle take precedence
PRBool compressed = NS_MATHML_IS_COMPRESSED(mPresentationData.flags);
PRBool displayStyle = NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags);
if (NS_MATHML_IS_MSTYLE_WITH_DISPLAYSTYLE(mPresentationData.flags)) {
aDisplayStyle = displayStyle;
// see if the caller cares about the displaystyle flag
PRBool displaystyleChanged = PR_FALSE;
if (NS_MATHML_IS_DISPLAYSTYLE(aFlagsToUpdate)) {
if (!NS_MATHML_IS_MSTYLE_WITH_DISPLAYSTYLE(mPresentationData.flags)) {
// updating the displaystyle flag is allowed
displaystyleChanged = PR_TRUE;
}
else {
// our value takes precedence, updating is not allowed
aFlagsToUpdate &= ~NS_MATHML_DISPLAYSTYLE;
}
}
// see if the caller cares about the compression flag
PRBool compressionChanged = PR_FALSE;
if (NS_MATHML_IS_COMPRESSED(aFlagsToUpdate)) {
compressionChanged = PR_TRUE;
}
if (NS_MATHML_IS_MSTYLE_WITH_EXPLICIT_SCRIPTLEVEL(mPresentationData.flags)) {
aScriptLevelIncrement = 0;
}
if (0 == aScriptLevelIncrement &&
aDisplayStyle == displayStyle &&
aCompressed == compressed)
if (!aScriptLevelIncrement && !displaystyleChanged && !compressionChanged)
return NS_OK; // quick return, there is nothing to change
// let the base class worry about the update
return nsMathMLContainerFrame::UpdatePresentationDataFromChildAt(aIndex,
aScriptLevelIncrement, aDisplayStyle, aCompressed);
return
nsMathMLContainerFrame::UpdatePresentationDataFromChildAt(
aFirstIndex, aLastIndex, aScriptLevelIncrement,
aFlagsValues, aFlagsToUpdate);
}

View File

@@ -42,15 +42,16 @@ public:
nsIFrame* aPrevInFlow);
NS_IMETHOD
UpdatePresentationData(PRInt32 aScriptLevel,
PRBool aDisplayStyle,
PRBool aCompressed);
UpdatePresentationData(PRInt32 aScriptLevelIncrement,
PRUint32 aFlagsValues,
PRUint32 aFlagsToUpdate);
NS_IMETHOD
UpdatePresentationDataFromChildAt(PRInt32 aIndex,
PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed);
UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
PRInt32 aLastIndex,
PRInt32 aScriptLevelIncrement,
PRUint32 aFlagsValues,
PRUint32 aFlagsToUpdate);
NS_IMETHOD
SetInitialChildList(nsIPresContext* aPresContext,
@@ -59,8 +60,10 @@ public:
{
nsresult rv;
rv = nsMathMLContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList);
UpdatePresentationDataFromChildAt(0, mInnerScriptLevelIncrement,
NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags), PR_FALSE);
// This call is peculiar to <mstyle> and will quickly return if nothing to update
UpdatePresentationDataFromChildAt(0, -1, mInnerScriptLevelIncrement,
NS_MATHML_DISPLAYSTYLE & mPresentationData.flags,
NS_MATHML_DISPLAYSTYLE);
InsertScriptLevelStyleContext(aPresContext);
return rv;
}

View File

@@ -121,18 +121,19 @@ public:
}
NS_IMETHOD
UpdatePresentationData(PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed)
UpdatePresentationData(PRInt32 aScriptLevelIncrement,
PRUint32 aFlagsValues,
PRUint32 aFlagsToUpdate)
{
return NS_OK;
}
NS_IMETHOD
UpdatePresentationDataFromChildAt(PRInt32 aIndex,
PRInt32 aScriptLevelIncrement,
PRBool aDisplayStyle,
PRBool aCompressed)
UpdatePresentationDataFromChildAt(PRInt32 aFirstIndex,
PRInt32 aLastIndex,
PRInt32 aScriptLevelIncrement,
PRUint32 aFlagsValues,
PRUint32 aFlagsToUpdate)
{
return NS_OK;
}