1999-09-21 02:12:01 +00:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla MathML Project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is The University Of
|
|
|
|
* Queensland. Portions created by The University Of Queensland are
|
|
|
|
* Copyright (C) 1999 The University Of Queensland. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
|
|
|
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
|
2000-01-07 14:49:46 +00:00
|
|
|
* Shyjan Mahamud <mahamud@cs.cmu.edu> (added TeX rendering rules)
|
1999-09-21 02:12:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsLineLayout.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
|
|
|
|
#include "nsMathMLmmultiscriptsFrame.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// <mmultiscripts> -- attach prescripts and tensor indices to a base - implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
1999-12-10 13:02:23 +00:00
|
|
|
NS_NewMathMLmmultiscriptsFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-09-21 02:12:01 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-10 13:02:23 +00:00
|
|
|
nsMathMLmmultiscriptsFrame* it = new (aPresShell) nsMathMLmmultiscriptsFrame;
|
1999-09-21 02:12:01 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmmultiscriptsFrame::nsMathMLmmultiscriptsFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMathMLmmultiscriptsFrame::~nsMathMLmmultiscriptsFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLmmultiscriptsFrame::Init(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsMathMLContainerFrame::Init
|
|
|
|
(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
|
|
|
mSubScriptShiftFactor = 0.0f;
|
|
|
|
mSupScriptShiftFactor = 0.0f;
|
|
|
|
mScriptSpace = NSFloatPointsToTwips(0.5f); // 0.5pt as in plain TeX
|
|
|
|
|
|
|
|
// check for subscriptshift and superscriptshift attribute in ex units
|
|
|
|
nsAutoString value;
|
|
|
|
mSubUserSetFlag = mSupUserSetFlag = PR_FALSE;
|
|
|
|
mSubScriptShiftFactor = mSubScriptShiftFactor = 0.0f;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute
|
|
|
|
(kNameSpaceID_None, nsMathMLAtoms::subscriptshift_, value)) {
|
|
|
|
PRInt32 aErrorCode;
|
|
|
|
float aUserValue = value.ToFloat(&aErrorCode);
|
|
|
|
if (NS_SUCCEEDED(aErrorCode)) {
|
|
|
|
mSubUserSetFlag = PR_TRUE;
|
|
|
|
mSubScriptShiftFactor = aUserValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute
|
|
|
|
(kNameSpaceID_None, nsMathMLAtoms::superscriptshift_, value)) {
|
|
|
|
PRInt32 aErrorCode;
|
|
|
|
float aUserValue = value.ToFloat(&aErrorCode);
|
|
|
|
if (NS_SUCCEEDED(aErrorCode)) {
|
|
|
|
mSupUserSetFlag = PR_TRUE;
|
|
|
|
mSupScriptShiftFactor = aUserValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-18 04:35:37 +00:00
|
|
|
mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS;
|
2000-01-07 14:49:46 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-10 13:02:23 +00:00
|
|
|
nsMathMLmmultiscriptsFrame::Place(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
PRBool aPlaceOrigin,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1999-09-21 02:12:01 +00:00
|
|
|
{
|
2000-01-07 14:49:46 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's desired sizes
|
|
|
|
|
|
|
|
nscoord minShiftFromXHeight, aSubDrop, aSupDrop;
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
// Initialize super/sub shifts that
|
|
|
|
// depend only on the current font
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
// get x-height (an ex)
|
|
|
|
nscoord xHeight = 0;
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
const nsStyleFont* aFont =
|
|
|
|
(const nsStyleFont*) mStyleContext->GetStyleData (eStyleStruct_Font);
|
|
|
|
aPresContext->GetMetricsFor (aFont->mFont, getter_AddRefs(fm));
|
|
|
|
fm->GetXHeight (xHeight);
|
|
|
|
|
2000-01-18 04:35:37 +00:00
|
|
|
nscoord aRuleSize = 0;
|
2000-01-07 14:49:46 +00:00
|
|
|
// XXX need to do update this ...
|
2000-01-18 04:35:37 +00:00
|
|
|
GetRuleThickness (fm, aRuleSize);
|
2000-01-07 14:49:46 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////
|
|
|
|
// first the shift for the subscript
|
|
|
|
|
|
|
|
// aSubScriptShift{1,2}
|
|
|
|
// = minimum amount to shift the subscript down
|
|
|
|
// = sub{1,2} in TeXbook
|
|
|
|
// aSubScriptShift1 = subscriptshift attribute * x-height
|
|
|
|
nscoord aSubScriptShift1, aSubScriptShift2;
|
|
|
|
|
|
|
|
// Get aSubScriptShift{1,2} default from font
|
|
|
|
GetSubScriptShifts (fm, aSubScriptShift1, aSubScriptShift2);
|
|
|
|
if (mSubUserSetFlag) {
|
|
|
|
// the user has set the subscriptshift attribute
|
|
|
|
float aFactor = ((float) aSubScriptShift2) / aSubScriptShift1;
|
|
|
|
aSubScriptShift1 = NSToCoordRound(mSubScriptShiftFactor * xHeight);
|
|
|
|
aSubScriptShift2 = NSToCoordRound(aFactor * aSubScriptShift1);
|
|
|
|
}
|
|
|
|
// the font dependent shift
|
|
|
|
nscoord aSubScriptShift = PR_MAX(aSubScriptShift1,aSubScriptShift2);
|
|
|
|
|
|
|
|
/////////////////////////////////////
|
|
|
|
// next the shift for the superscript
|
|
|
|
|
|
|
|
// aSupScriptShift{1,2,3}
|
|
|
|
// = minimum amount to shift the supscript up
|
|
|
|
// = sup{1,2,3} in TeX
|
|
|
|
// aSupScriptShift1 = superscriptshift attribute * x-height
|
|
|
|
// Note that there are THREE values for supscript shifts depending
|
|
|
|
// on the current style
|
|
|
|
nscoord aSupScriptShift1, aSupScriptShift2, aSupScriptShift3;
|
|
|
|
// Set aSupScriptShift{1,2,3} default from font
|
|
|
|
GetSupScriptShifts (fm, aSupScriptShift1, aSupScriptShift2, aSupScriptShift3);
|
|
|
|
if (mSupUserSetFlag) {
|
|
|
|
// the user has set the superscriptshift attribute
|
|
|
|
float aFactor2 = ((float) aSupScriptShift2) / aSupScriptShift1;
|
|
|
|
float aFactor3 = ((float) aSupScriptShift3) / aSupScriptShift1;
|
|
|
|
aSupScriptShift1 = NSToCoordRound(mSupScriptShiftFactor * xHeight);
|
|
|
|
aSupScriptShift2 = NSToCoordRound(aFactor2 * aSupScriptShift1);
|
|
|
|
aSupScriptShift3 = NSToCoordRound(aFactor3 * aSupScriptShift1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get sup script shift depending on current script level and display style
|
|
|
|
// Rule 18c, App. G, TeXbook
|
|
|
|
nscoord aSupScriptShift;
|
2000-01-14 08:38:25 +00:00
|
|
|
if ( mPresentationData.scriptLevel == 0 &&
|
|
|
|
NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags) &&
|
|
|
|
!NS_MATHML_IS_COMPRESSED(mPresentationData.flags)) {
|
2000-01-07 14:49:46 +00:00
|
|
|
// Style D in TeXbook
|
|
|
|
aSupScriptShift = aSupScriptShift1;
|
|
|
|
}
|
2000-01-14 08:38:25 +00:00
|
|
|
else if (NS_MATHML_IS_COMPRESSED(mPresentationData.flags)) {
|
2000-01-07 14:49:46 +00:00
|
|
|
// Style C' in TeXbook = D',T',S',SS'
|
|
|
|
aSupScriptShift = aSupScriptShift3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// everything else = T,S,SS
|
|
|
|
aSupScriptShift = aSupScriptShift2;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's sizes
|
|
|
|
////////////////////////////////////
|
|
|
|
|
2000-01-18 04:35:37 +00:00
|
|
|
nscoord width = 0, prescriptsWidth = 0, rightBearing = 0;
|
1999-09-21 02:12:01 +00:00
|
|
|
nsIFrame* mprescriptsFrame = nsnull; // frame of <mprescripts/>, if there.
|
2000-01-07 14:49:46 +00:00
|
|
|
PRBool isSubScript = PR_FALSE;
|
|
|
|
PRBool isSubScriptPresent = PR_TRUE;
|
|
|
|
PRBool isSupScriptPresent = PR_TRUE;
|
|
|
|
nscoord minSubScriptShift = 0, minSupScriptShift = 0;
|
|
|
|
nscoord trySubScriptShift = aSubScriptShift;
|
|
|
|
nscoord trySupScriptShift = aSupScriptShift;
|
|
|
|
nscoord maxSubScriptShift = aSubScriptShift;
|
|
|
|
nscoord maxSupScriptShift = aSupScriptShift;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
nsHTMLReflowMetrics baseSize (nsnull);
|
|
|
|
nsHTMLReflowMetrics subScriptSize (nsnull);
|
|
|
|
nsHTMLReflowMetrics supScriptSize (nsnull);
|
|
|
|
nsIFrame* baseFrame;
|
|
|
|
nsIFrame* subScriptFrame;
|
|
|
|
nsIFrame* supScriptFrame;
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2000-01-18 04:35:37 +00:00
|
|
|
PRBool firstPrescriptsPair = PR_FALSE;
|
|
|
|
nsBoundingMetrics bmBase, bmSubScript, bmSupScript;
|
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
// XXX is there an NSPR macro for int_max ???
|
2000-01-18 04:35:37 +00:00
|
|
|
mBoundingMetrics.ascent = mBoundingMetrics.descent = -10000000;
|
|
|
|
mBoundingMetrics.width = 0;
|
|
|
|
|
|
|
|
aDesiredSize.ascent = aDesiredSize.descent = -10000000;
|
2000-01-07 14:49:46 +00:00
|
|
|
aDesiredSize.width = aDesiredSize.height = 0;
|
1999-12-10 13:02:23 +00:00
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
nsIFrame* aChildFrame = mFrames.FirstChild();
|
|
|
|
while (nsnull != aChildFrame)
|
|
|
|
{
|
|
|
|
if (!IsOnlyWhitespace (aChildFrame)) {
|
1999-09-21 02:12:01 +00:00
|
|
|
nsCOMPtr<nsIContent> childContent;
|
|
|
|
nsCOMPtr<nsIAtom> childTag;
|
2000-01-07 14:49:46 +00:00
|
|
|
aChildFrame->GetContent(getter_AddRefs(childContent));
|
1999-09-21 02:12:01 +00:00
|
|
|
childContent->GetTag(*getter_AddRefs(childTag));
|
|
|
|
|
1999-12-10 13:02:23 +00:00
|
|
|
if (childTag.get() == nsMathMLAtoms::mprescripts_) {
|
2000-01-07 14:49:46 +00:00
|
|
|
mprescriptsFrame = aChildFrame;
|
2000-01-18 04:35:37 +00:00
|
|
|
firstPrescriptsPair = PR_TRUE;
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
2000-01-07 14:49:46 +00:00
|
|
|
else {
|
2000-01-18 04:35:37 +00:00
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
if (childTag.get() == nsMathMLAtoms::none_) {
|
|
|
|
// we need to record the presence of none tag explicitly
|
|
|
|
// for correct negotiation between sup/sub shifts later
|
|
|
|
if (isSubScript) {
|
|
|
|
isSubScriptPresent = PR_FALSE;
|
2000-01-18 04:35:37 +00:00
|
|
|
bmSubScript.Clear();
|
|
|
|
bmSubScript.leftBearing = 10000000;
|
2000-01-07 14:49:46 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
isSupScriptPresent = PR_FALSE;
|
2000-01-18 04:35:37 +00:00
|
|
|
bmSupScript.Clear();
|
|
|
|
bmSupScript.leftBearing = 10000000;
|
2000-01-07 14:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-18 04:35:37 +00:00
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
if (0 == count) {
|
2000-01-07 14:49:46 +00:00
|
|
|
// base
|
|
|
|
baseFrame = aChildFrame;
|
2000-01-18 04:35:37 +00:00
|
|
|
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
|
|
|
|
|
|
|
|
// we update mBoundingMetrics.{ascent,descent} with that
|
2000-01-07 14:49:46 +00:00
|
|
|
// of the baseFrame only after processing all the sup/sub pairs
|
2000-01-18 04:35:37 +00:00
|
|
|
// XXX need italic correction only *if* there are postscripts ?
|
|
|
|
mBoundingMetrics.width = bmBase.width + bmBase.supItalicCorrection;
|
|
|
|
mBoundingMetrics.rightBearing = bmBase.rightBearing;
|
|
|
|
mBoundingMetrics.leftBearing = bmBase.leftBearing; // until overwritten
|
2000-01-07 14:49:46 +00:00
|
|
|
}
|
1999-09-21 02:12:01 +00:00
|
|
|
else {
|
2000-01-07 14:49:46 +00:00
|
|
|
// super/subscript block
|
|
|
|
if (isSubScript) {
|
|
|
|
if (isSubScriptPresent) {
|
|
|
|
// subscript
|
|
|
|
subScriptFrame = aChildFrame;
|
2000-01-18 04:35:37 +00:00
|
|
|
GetReflowAndBoundingMetricsFor(subScriptFrame, subScriptSize, bmSubScript);
|
2000-01-07 14:49:46 +00:00
|
|
|
// get the subdrop from the subscript font
|
|
|
|
GetSubDropFromChild (aPresContext, subScriptFrame, aSubDrop);
|
|
|
|
// parameter v, Rule 18a, App. G, TeXbook
|
2000-01-18 04:35:37 +00:00
|
|
|
minSubScriptShift = bmBase.descent + aSubDrop;
|
2000-01-07 14:49:46 +00:00
|
|
|
trySubScriptShift = PR_MAX(minSubScriptShift,aSubScriptShift);
|
2000-01-18 04:35:37 +00:00
|
|
|
mBoundingMetrics.descent =
|
|
|
|
PR_MAX(mBoundingMetrics.descent,bmSubScript.descent);
|
2000-01-07 14:49:46 +00:00
|
|
|
aDesiredSize.descent =
|
2000-01-18 04:35:37 +00:00
|
|
|
PR_MAX(aDesiredSize.descent,subScriptSize.ascent);
|
|
|
|
width = bmSubScript.width + mScriptSpace;
|
|
|
|
rightBearing = bmSubScript.rightBearing + mScriptSpace;
|
2000-01-07 14:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (isSupScriptPresent) {
|
|
|
|
// supscript
|
|
|
|
supScriptFrame = aChildFrame;
|
2000-01-18 04:35:37 +00:00
|
|
|
GetReflowAndBoundingMetricsFor(supScriptFrame, supScriptSize, bmSupScript);
|
2000-01-07 14:49:46 +00:00
|
|
|
// get the supdrop from the supscript font
|
|
|
|
GetSupDropFromChild (aPresContext, supScriptFrame, aSupDrop);
|
|
|
|
// parameter u, Rule 18a, App. G, TeXbook
|
2000-01-18 04:35:37 +00:00
|
|
|
minSupScriptShift = bmBase.ascent - aSupDrop;
|
2000-01-07 14:49:46 +00:00
|
|
|
// get min supscript shift limit from x-height
|
|
|
|
// = d(x) + 1/4 * sigma_5, Rule 18c, App. G, TeXbook
|
|
|
|
minShiftFromXHeight = NSToCoordRound
|
2000-01-18 04:35:37 +00:00
|
|
|
((bmSupScript.descent + (1.0f/4.0f) * xHeight));
|
2000-01-07 14:49:46 +00:00
|
|
|
trySupScriptShift =
|
|
|
|
PR_MAX(minSupScriptShift,PR_MAX(minShiftFromXHeight,aSupScriptShift));
|
2000-01-18 04:35:37 +00:00
|
|
|
mBoundingMetrics.ascent =
|
|
|
|
PR_MAX(mBoundingMetrics.ascent,bmSupScript.ascent);
|
2000-01-07 14:49:46 +00:00
|
|
|
aDesiredSize.ascent =
|
|
|
|
PR_MAX(aDesiredSize.ascent,supScriptSize.ascent);
|
2000-01-18 04:35:37 +00:00
|
|
|
width = PR_MAX(width, bmSupScript.width + mScriptSpace);
|
|
|
|
rightBearing = PR_MAX(rightBearing, bmSupScript.rightBearing + mScriptSpace);
|
2000-01-07 14:49:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION((isSubScriptPresent || isSupScriptPresent),"mmultiscripts : both sup/subscripts are absent");
|
2000-01-18 04:35:37 +00:00
|
|
|
|
|
|
|
if (!mprescriptsFrame) { // we are still looping over base & postscripts
|
|
|
|
mBoundingMetrics.rightBearing = mBoundingMetrics.width + rightBearing;
|
|
|
|
mBoundingMetrics.width += width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prescriptsWidth += width;
|
|
|
|
if (firstPrescriptsPair) {
|
|
|
|
firstPrescriptsPair = PR_FALSE;
|
|
|
|
mBoundingMetrics.leftBearing =
|
|
|
|
PR_MIN(bmSubScript.leftBearing, bmSupScript.leftBearing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
width = rightBearing = 0;
|
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
if (isSubScriptPresent && isSupScriptPresent) {
|
|
|
|
// negotiate between the various shifts so that
|
|
|
|
// there is enough gap between the sup and subscripts
|
|
|
|
// Rule 18e, App. G, TeXbook
|
|
|
|
nscoord gap =
|
2000-01-18 04:35:37 +00:00
|
|
|
(trySupScriptShift - bmSupScript.descent) -
|
|
|
|
(bmSubScript.ascent - trySubScriptShift);
|
2000-01-07 14:49:46 +00:00
|
|
|
if (gap < 4.0f * aRuleSize) {
|
|
|
|
// adjust trySubScriptShift to get a gap of (4.0 * aRuleSize)
|
|
|
|
trySubScriptShift += NSToCoordRound ((4.0f * aRuleSize) - gap);
|
|
|
|
}
|
|
|
|
|
|
|
|
// next we want to ensure that the bottom of the superscript
|
|
|
|
// will be > (4/5) * x-height above baseline
|
|
|
|
gap = NSToCoordRound ((4.0f/5.0f) * xHeight -
|
2000-01-18 04:35:37 +00:00
|
|
|
(trySupScriptShift - bmSupScript.descent));
|
2000-01-07 14:49:46 +00:00
|
|
|
if (gap > 0.0f) {
|
|
|
|
trySupScriptShift += gap;
|
|
|
|
trySubScriptShift -= gap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
maxSubScriptShift = PR_MAX(maxSubScriptShift, trySubScriptShift);
|
|
|
|
maxSupScriptShift = PR_MAX(maxSupScriptShift, trySupScriptShift);
|
|
|
|
|
|
|
|
trySubScriptShift = aSubScriptShift;
|
|
|
|
trySupScriptShift = aSupScriptShift;
|
|
|
|
isSubScriptPresent = PR_TRUE;
|
|
|
|
isSupScriptPresent = PR_TRUE;
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
isSubScript = !isSubScript;
|
1999-09-21 02:12:01 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2000-01-07 14:49:46 +00:00
|
|
|
|
|
|
|
rv = aChildFrame->GetNextSibling(&aChildFrame);
|
1999-09-21 02:12:01 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"failed to get next child");
|
|
|
|
}
|
2000-01-18 04:35:37 +00:00
|
|
|
|
|
|
|
// we left out the width of prescripts, so ...
|
|
|
|
mBoundingMetrics.rightBearing += prescriptsWidth;
|
|
|
|
mBoundingMetrics.width += prescriptsWidth;
|
|
|
|
|
|
|
|
// we left out the base during our bounding box updates, so ...
|
|
|
|
mBoundingMetrics.ascent =
|
|
|
|
PR_MAX(mBoundingMetrics.ascent+maxSupScriptShift,bmBase.ascent);
|
|
|
|
mBoundingMetrics.descent =
|
|
|
|
PR_MAX(mBoundingMetrics.descent+maxSubScriptShift,bmBase.descent);
|
|
|
|
|
|
|
|
// get the reflow metrics ...
|
2000-01-07 14:49:46 +00:00
|
|
|
aDesiredSize.ascent =
|
|
|
|
PR_MAX(aDesiredSize.ascent+maxSupScriptShift,baseSize.ascent);
|
|
|
|
aDesiredSize.descent =
|
|
|
|
PR_MAX(aDesiredSize.descent+maxSubScriptShift,baseSize.descent);
|
|
|
|
aDesiredSize.height = aDesiredSize.ascent + aDesiredSize.descent;
|
2000-01-18 04:35:37 +00:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
|
|
|
|
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent - mBoundingMetrics.ascent;
|
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
//////////////////
|
|
|
|
// Place Children
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
// Place prescripts, followed by base, and then postscripts.
|
|
|
|
// The list of frames is in the order: {base} {postscripts} {prescripts}
|
|
|
|
// We go over the list in a circular manner, starting at <prescripts/>
|
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dx = 0, dy = 0;
|
2000-01-18 04:35:37 +00:00
|
|
|
nsRect aRect;
|
2000-01-07 14:49:46 +00:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
aChildFrame = mprescriptsFrame;
|
|
|
|
do {
|
|
|
|
if (nsnull == aChildFrame) { // end of prescripts,
|
|
|
|
// place the base ...
|
|
|
|
aChildFrame = baseFrame;
|
2000-01-18 04:35:37 +00:00
|
|
|
// dy = mBoundingMetrics.ascent - bmBase.ascent;
|
|
|
|
dy = aDesiredSize.ascent - baseSize.ascent;
|
|
|
|
FinishReflowChild (baseFrame, aPresContext, baseSize, dx, dy, 0);
|
|
|
|
dx += baseSize.width + bmBase.supItalicCorrection;
|
1999-09-21 02:12:01 +00:00
|
|
|
}
|
2000-01-07 14:49:46 +00:00
|
|
|
else if (mprescriptsFrame != aChildFrame) {
|
|
|
|
// process each sup/sub pair
|
|
|
|
if (!IsOnlyWhitespace (aChildFrame)) {
|
|
|
|
if (0 == count) {
|
|
|
|
subScriptFrame = aChildFrame;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
else if (1 == count) {
|
|
|
|
supScriptFrame = aChildFrame;
|
|
|
|
count = 0;
|
|
|
|
|
2000-01-18 04:35:37 +00:00
|
|
|
// get the ascent/descent of sup/subscripts stored in their rects
|
2000-01-07 14:49:46 +00:00
|
|
|
// rect.x = descent, rect.y = ascent
|
|
|
|
subScriptFrame->GetRect (aRect);
|
|
|
|
subScriptSize.ascent = aRect.y;
|
|
|
|
subScriptSize.width = aRect.width;
|
|
|
|
subScriptSize.height = aRect.height;
|
|
|
|
|
|
|
|
supScriptFrame->GetRect (aRect);
|
|
|
|
supScriptSize.ascent = aRect.y;
|
|
|
|
supScriptSize.width = aRect.width;
|
|
|
|
supScriptSize.height = aRect.height;
|
1999-09-21 02:12:01 +00:00
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
// XXX should we really center the boxes
|
|
|
|
// XXX i'm leaving it as left-justified
|
|
|
|
// XXX which is consistent with what's done for <msubsup>
|
2000-01-18 04:35:37 +00:00
|
|
|
|
|
|
|
// reverting to center. It looks much nicer and adds a bit
|
|
|
|
// of variety to the engine. At least we have two functions
|
|
|
|
// doing two different things.
|
|
|
|
|
|
|
|
width = PR_MAX(subScriptSize.width, supScriptSize.width);
|
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
dy = aDesiredSize.ascent -
|
|
|
|
subScriptSize.ascent +
|
|
|
|
maxSubScriptShift;
|
2000-01-18 04:35:37 +00:00
|
|
|
FinishReflowChild (subScriptFrame, aPresContext, subScriptSize,
|
|
|
|
dx + (width-subScriptSize.width)/2, dy, 0);
|
2000-01-07 14:49:46 +00:00
|
|
|
|
|
|
|
dy = aDesiredSize.ascent -
|
|
|
|
supScriptSize.ascent -
|
|
|
|
maxSupScriptShift;
|
2000-01-18 04:35:37 +00:00
|
|
|
FinishReflowChild (supScriptFrame, aPresContext, supScriptSize,
|
|
|
|
dx + (width-supScriptSize.width)/2, dy, 0);
|
2000-01-07 14:49:46 +00:00
|
|
|
|
2000-01-18 04:35:37 +00:00
|
|
|
dx += mScriptSpace + width;
|
|
|
|
}
|
2000-01-07 14:49:46 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-18 04:35:37 +00:00
|
|
|
|
2000-01-07 14:49:46 +00:00
|
|
|
rv = aChildFrame->GetNextSibling(&aChildFrame);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"failed to get next child");
|
|
|
|
} while (mprescriptsFrame != aChildFrame);
|
|
|
|
}
|
|
|
|
|
1999-09-21 02:12:01 +00:00
|
|
|
return rv;
|
|
|
|
}
|