2007-06-12 10:10:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-09-21 06:12:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
1999-09-21 06:12:01 +04:00
|
|
|
|
|
|
|
#include "nsMathMLmmultiscriptsFrame.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// <mmultiscripts> -- attach prescripts and tensor indices to a base - implementation
|
|
|
|
//
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLmmultiscriptsFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLmmultiscriptsFrame(aContext);
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmmultiscriptsFrame)
|
|
|
|
|
1999-09-21 06:12:01 +04:00
|
|
|
nsMathMLmmultiscriptsFrame::~nsMathMLmmultiscriptsFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmmultiscriptsFrame::TransmitAutomaticData()
|
2000-01-07 17:49:46 +03:00
|
|
|
{
|
2002-02-07 07:38:08 +03:00
|
|
|
// if our base is an embellished operator, let its state bubble to us
|
2005-09-07 03:47:01 +04:00
|
|
|
mPresentationData.baseFrame = mFrames.FirstChild();
|
|
|
|
GetEmbellishDataFrom(mPresentationData.baseFrame, mEmbellishData);
|
2002-02-07 07:38:08 +03:00
|
|
|
|
|
|
|
// The REC says:
|
|
|
|
// The <mmultiscripts> element increments scriptlevel by 1, and sets
|
|
|
|
// displaystyle to "false", within each of its arguments except base
|
2008-01-09 12:38:28 +03:00
|
|
|
UpdatePresentationDataFromChildAt(1, -1,
|
2002-02-07 07:38:08 +03:00
|
|
|
~NS_MATHML_DISPLAYSTYLE, NS_MATHML_DISPLAYSTYLE);
|
|
|
|
|
|
|
|
// The TeXbook (Ch 17. p.141) says the superscript inherits the compression
|
|
|
|
// while the subscript is compressed. So here we collect subscripts and set
|
|
|
|
// the compression flag in them.
|
|
|
|
PRInt32 count = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isSubScript = false;
|
2009-02-03 17:42:18 +03:00
|
|
|
nsAutoTArray<nsIFrame*, 8> subScriptFrames;
|
2002-02-07 07:38:08 +03:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (childFrame->GetContent()->Tag() == nsGkAtoms::mprescripts_) {
|
2002-02-07 07:38:08 +03:00
|
|
|
// mprescripts frame
|
|
|
|
}
|
|
|
|
else if (0 == count) {
|
|
|
|
// base frame
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// super/subscript block
|
|
|
|
if (isSubScript) {
|
|
|
|
// subscript
|
|
|
|
subScriptFrames.AppendElement(childFrame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// superscript
|
|
|
|
}
|
|
|
|
isSubScript = !isSubScript;
|
|
|
|
}
|
|
|
|
count++;
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-02-07 07:38:08 +03:00
|
|
|
}
|
2009-02-03 17:42:18 +03:00
|
|
|
for (PRInt32 i = subScriptFrames.Length() - 1; i >= 0; i--) {
|
|
|
|
childFrame = subScriptFrames[i];
|
2008-01-09 12:38:28 +03:00
|
|
|
PropagatePresentationDataFor(childFrame,
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_MATHML_COMPRESSED, NS_MATHML_COMPRESSED);
|
|
|
|
}
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLmmultiscriptsFrame::ProcessAttributes()
|
2002-02-07 07:38:08 +03:00
|
|
|
{
|
2000-01-26 09:49:38 +03:00
|
|
|
mSubScriptShift = 0;
|
|
|
|
mSupScriptShift = 0;
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2012-05-16 02:30:14 +04:00
|
|
|
// subscriptshift
|
|
|
|
//
|
|
|
|
// "Specifies the minimum amount to shift the baseline of subscript down; the
|
|
|
|
// default is for the rendering agent to use its own positioning rules."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: automatic
|
|
|
|
//
|
|
|
|
// We use 0 as the default value so unitless values can be ignored.
|
|
|
|
// XXXfredw Should we forbid negative values? (bug 411227)
|
|
|
|
//
|
2000-01-07 17:49:46 +03:00
|
|
|
nsAutoString value;
|
2005-10-28 15:25:24 +04:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::subscriptshift_, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2012-05-16 02:30:14 +04:00
|
|
|
ParseNumericValue(value, &mSubScriptShift,
|
|
|
|
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
|
|
|
|
PresContext(), mStyleContext);
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
2012-05-16 02:30:14 +04:00
|
|
|
// superscriptshift
|
|
|
|
//
|
|
|
|
// "Specifies the minimum amount to shift the baseline of superscript up; the
|
|
|
|
// default is for the rendering agent to use its own positioning rules."
|
|
|
|
//
|
|
|
|
// values: length
|
|
|
|
// default: automatic
|
|
|
|
//
|
|
|
|
// We use 0 as the default value so unitless values can be ignored.
|
|
|
|
// XXXfredw Should we forbid negative values? (bug 411227)
|
|
|
|
//
|
2005-10-28 15:25:24 +04:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::superscriptshift_, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2012-05-16 02:30:14 +04:00
|
|
|
ParseNumericValue(value, &mSupScriptShift,
|
|
|
|
nsMathMLElement::PARSE_ALLOW_NEGATIVE,
|
|
|
|
PresContext(), mStyleContext);
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-18 07:52:48 +03:00
|
|
|
/* virtual */ nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLmmultiscriptsFrame::Place(nsRenderingContext& aRenderingContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPlaceOrigin,
|
2006-08-04 03:27:55 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1999-09-21 06:12:01 +04:00
|
|
|
{
|
2000-01-07 17:49:46 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's desired sizes
|
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord minShiftFromXHeight, subDrop, supDrop;
|
2000-01-07 17:49:46 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////
|
2001-02-23 19:10:51 +03:00
|
|
|
// Initialize super/sub shifts that
|
2000-01-07 17:49:46 +03:00
|
|
|
// depend only on the current font
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
2005-02-07 04:57:50 +03:00
|
|
|
ProcessAttributes();
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
// get x-height (an ex)
|
2008-01-09 12:38:28 +03:00
|
|
|
const nsStyleFont* font = GetStyleFont();
|
2011-08-14 21:08:04 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
|
|
|
aRenderingContext.SetFont(fm);
|
2000-03-28 13:38:24 +04:00
|
|
|
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord xHeight = fm->XHeight();
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord ruleSize;
|
|
|
|
GetRuleThickness (aRenderingContext, fm, ruleSize);
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2005-09-07 03:47:01 +04:00
|
|
|
// scriptspace from TeX for extra spacing after sup/subscript (0.5pt in plain TeX)
|
|
|
|
// forced to be at least 1 pixel here
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
|
2010-08-13 13:58:04 +04:00
|
|
|
nscoord scriptSpace = NS_MAX(nsPresContext::CSSPointsToAppUnits(0.5f), onePixel);
|
2005-09-07 03:47:01 +04:00
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
/////////////////////////////////////
|
|
|
|
// first the shift for the subscript
|
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// subScriptShift{1,2}
|
|
|
|
// = minimum amount to shift the subscript down
|
2000-01-07 17:49:46 +03:00
|
|
|
// = sub{1,2} in TeXbook
|
2001-02-23 19:10:51 +03:00
|
|
|
// subScriptShift1 = subscriptshift attribute * x-height
|
|
|
|
nscoord subScriptShift1, subScriptShift2;
|
2000-01-07 17:49:46 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// Get subScriptShift{1,2} default from font
|
|
|
|
GetSubScriptShifts (fm, subScriptShift1, subScriptShift2);
|
2000-01-26 09:49:38 +03:00
|
|
|
if (0 < mSubScriptShift) {
|
2000-01-07 17:49:46 +03:00
|
|
|
// the user has set the subscriptshift attribute
|
2001-02-23 19:10:51 +03:00
|
|
|
float scaler = ((float) subScriptShift2) / subScriptShift1;
|
2009-09-16 19:01:36 +04:00
|
|
|
subScriptShift1 = NS_MAX(subScriptShift1, mSubScriptShift);
|
2001-02-23 19:10:51 +03:00
|
|
|
subScriptShift2 = NSToCoordRound(scaler * subScriptShift1);
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
|
|
|
// the font dependent shift
|
2009-09-16 19:01:36 +04:00
|
|
|
nscoord subScriptShift = NS_MAX(subScriptShift1,subScriptShift2);
|
2000-01-07 17:49:46 +03:00
|
|
|
|
|
|
|
/////////////////////////////////////
|
|
|
|
// next the shift for the superscript
|
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// supScriptShift{1,2,3}
|
2000-01-07 17:49:46 +03:00
|
|
|
// = minimum amount to shift the supscript up
|
|
|
|
// = sup{1,2,3} in TeX
|
2001-02-23 19:10:51 +03:00
|
|
|
// supScriptShift1 = superscriptshift attribute * x-height
|
2000-01-07 17:49:46 +03:00
|
|
|
// Note that there are THREE values for supscript shifts depending
|
|
|
|
// on the current style
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord supScriptShift1, supScriptShift2, supScriptShift3;
|
|
|
|
// Set supScriptShift{1,2,3} default from font
|
|
|
|
GetSupScriptShifts (fm, supScriptShift1, supScriptShift2, supScriptShift3);
|
2000-01-26 09:49:38 +03:00
|
|
|
if (0 < mSupScriptShift) {
|
2000-01-07 17:49:46 +03:00
|
|
|
// the user has set the superscriptshift attribute
|
2001-02-23 19:10:51 +03:00
|
|
|
float scaler2 = ((float) supScriptShift2) / supScriptShift1;
|
|
|
|
float scaler3 = ((float) supScriptShift3) / supScriptShift1;
|
2009-09-16 19:01:36 +04:00
|
|
|
supScriptShift1 = NS_MAX(supScriptShift1, mSupScriptShift);
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift2 = NSToCoordRound(scaler2 * supScriptShift1);
|
|
|
|
supScriptShift3 = NSToCoordRound(scaler3 * supScriptShift1);
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// get sup script shift depending on current script level and display style
|
|
|
|
// Rule 18c, App. G, TeXbook
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord supScriptShift;
|
2008-01-09 12:38:28 +03:00
|
|
|
if ( font->mScriptLevel == 0 &&
|
2000-01-14 11:38:25 +03:00
|
|
|
NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags) &&
|
|
|
|
!NS_MATHML_IS_COMPRESSED(mPresentationData.flags)) {
|
2000-01-07 17:49:46 +03:00
|
|
|
// Style D in TeXbook
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift = supScriptShift1;
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
2000-01-14 11:38:25 +03:00
|
|
|
else if (NS_MATHML_IS_COMPRESSED(mPresentationData.flags)) {
|
2000-01-07 17:49:46 +03:00
|
|
|
// Style C' in TeXbook = D',T',S',SS'
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift = supScriptShift3;
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// everything else = T,S,SS
|
2001-02-23 19:10:51 +03:00
|
|
|
supScriptShift = supScriptShift2;
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// Get the children's sizes
|
|
|
|
////////////////////////////////////
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2000-01-18 07:35:37 +03:00
|
|
|
nscoord width = 0, prescriptsWidth = 0, rightBearing = 0;
|
2001-02-23 19:10:51 +03:00
|
|
|
nsIFrame* mprescriptsFrame = nsnull; // frame of <mprescripts/>, if there.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isSubScript = false;
|
2001-02-23 19:10:51 +03:00
|
|
|
nscoord minSubScriptShift = 0, minSupScriptShift = 0;
|
|
|
|
nscoord trySubScriptShift = subScriptShift;
|
|
|
|
nscoord trySupScriptShift = supScriptShift;
|
|
|
|
nscoord maxSubScriptShift = subScriptShift;
|
|
|
|
nscoord maxSupScriptShift = supScriptShift;
|
2000-01-07 17:49:46 +03:00
|
|
|
PRInt32 count = 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLReflowMetrics baseSize;
|
|
|
|
nsHTMLReflowMetrics subScriptSize;
|
|
|
|
nsHTMLReflowMetrics supScriptSize;
|
2000-03-28 13:38:24 +04:00
|
|
|
nsIFrame* baseFrame = nsnull;
|
|
|
|
nsIFrame* subScriptFrame = nsnull;
|
|
|
|
nsIFrame* supScriptFrame = nsnull;
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool firstPrescriptsPair = false;
|
2000-01-18 07:35:37 +03:00
|
|
|
nsBoundingMetrics bmBase, bmSubScript, bmSupScript;
|
2001-02-02 12:37:14 +03:00
|
|
|
nscoord italicCorrection = 0;
|
2000-01-18 07:35:37 +03:00
|
|
|
|
|
|
|
mBoundingMetrics.width = 0;
|
2002-02-07 07:38:08 +03:00
|
|
|
mBoundingMetrics.ascent = mBoundingMetrics.descent = -0x7FFFFFFF;
|
2007-01-23 07:06:56 +03:00
|
|
|
nscoord ascent = -0x7FFFFFFF, descent = -0x7FFFFFFF;
|
2000-01-07 17:49:46 +03:00
|
|
|
aDesiredSize.width = aDesiredSize.height = 0;
|
1999-12-10 16:02:23 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (childFrame->GetContent()->Tag() == nsGkAtoms::mprescripts_) {
|
2002-02-07 07:38:08 +03:00
|
|
|
if (mprescriptsFrame) {
|
|
|
|
// duplicate <mprescripts/> found
|
|
|
|
// report an error, encourage people to get their markups in order
|
2006-08-04 03:27:55 +04:00
|
|
|
return ReflowError(aRenderingContext, aDesiredSize);
|
2002-02-07 07:38:08 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
mprescriptsFrame = childFrame;
|
2011-10-17 18:59:28 +04:00
|
|
|
firstPrescriptsPair = true;
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (0 == count) {
|
|
|
|
// base
|
|
|
|
baseFrame = childFrame;
|
|
|
|
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
|
|
|
|
GetItalicCorrection(bmBase, italicCorrection);
|
2005-09-07 03:47:01 +04:00
|
|
|
// for the superscript, we always add "a little to spare"
|
|
|
|
italicCorrection += onePixel;
|
2001-02-23 19:10:51 +03:00
|
|
|
|
|
|
|
// we update mBoundingMetrics.{ascent,descent} with that
|
|
|
|
// of the baseFrame only after processing all the sup/sub pairs
|
|
|
|
// XXX need italic correction only *if* there are postscripts ?
|
|
|
|
mBoundingMetrics.width = bmBase.width + italicCorrection;
|
|
|
|
mBoundingMetrics.rightBearing = bmBase.rightBearing;
|
|
|
|
mBoundingMetrics.leftBearing = bmBase.leftBearing; // until overwritten
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2000-01-07 17:49:46 +03:00
|
|
|
else {
|
2001-02-23 19:10:51 +03:00
|
|
|
// super/subscript block
|
|
|
|
if (isSubScript) {
|
|
|
|
// subscript
|
|
|
|
subScriptFrame = childFrame;
|
|
|
|
GetReflowAndBoundingMetricsFor(subScriptFrame, subScriptSize, bmSubScript);
|
|
|
|
// get the subdrop from the subscript font
|
2005-02-07 04:57:50 +03:00
|
|
|
GetSubDropFromChild (subScriptFrame, subDrop);
|
2001-02-23 19:10:51 +03:00
|
|
|
// parameter v, Rule 18a, App. G, TeXbook
|
|
|
|
minSubScriptShift = bmBase.descent + subDrop;
|
2009-09-16 19:01:36 +04:00
|
|
|
trySubScriptShift = NS_MAX(minSubScriptShift,subScriptShift);
|
2001-02-23 19:10:51 +03:00
|
|
|
mBoundingMetrics.descent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.descent,bmSubScript.descent);
|
|
|
|
descent = NS_MAX(descent,subScriptSize.height - subScriptSize.ascent);
|
2005-09-07 03:47:01 +04:00
|
|
|
width = bmSubScript.width + scriptSpace;
|
|
|
|
rightBearing = bmSubScript.rightBearing;
|
2001-02-02 12:37:14 +03:00
|
|
|
}
|
1999-09-21 06:12:01 +04:00
|
|
|
else {
|
2001-02-23 19:10:51 +03:00
|
|
|
// supscript
|
|
|
|
supScriptFrame = childFrame;
|
|
|
|
GetReflowAndBoundingMetricsFor(supScriptFrame, supScriptSize, bmSupScript);
|
|
|
|
// get the supdrop from the supscript font
|
2005-02-07 04:57:50 +03:00
|
|
|
GetSupDropFromChild (supScriptFrame, supDrop);
|
2001-02-23 19:10:51 +03:00
|
|
|
// parameter u, Rule 18a, App. G, TeXbook
|
|
|
|
minSupScriptShift = bmBase.ascent - supDrop;
|
|
|
|
// get min supscript shift limit from x-height
|
|
|
|
// = d(x) + 1/4 * sigma_5, Rule 18c, App. G, TeXbook
|
|
|
|
minShiftFromXHeight = NSToCoordRound
|
|
|
|
((bmSupScript.descent + (1.0f/4.0f) * xHeight));
|
|
|
|
trySupScriptShift =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(minSupScriptShift,NS_MAX(minShiftFromXHeight,supScriptShift));
|
2001-02-23 19:10:51 +03:00
|
|
|
mBoundingMetrics.ascent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.ascent,bmSupScript.ascent);
|
|
|
|
ascent = NS_MAX(ascent,supScriptSize.ascent);
|
|
|
|
width = NS_MAX(width, bmSupScript.width + scriptSpace);
|
|
|
|
rightBearing = NS_MAX(rightBearing, bmSupScript.rightBearing);
|
2001-02-23 19:10:51 +03:00
|
|
|
|
|
|
|
if (!mprescriptsFrame) { // we are still looping over base & postscripts
|
|
|
|
mBoundingMetrics.rightBearing = mBoundingMetrics.width + rightBearing;
|
|
|
|
mBoundingMetrics.width += width;
|
2001-02-02 12:37:14 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-02-23 19:10:51 +03:00
|
|
|
prescriptsWidth += width;
|
|
|
|
if (firstPrescriptsPair) {
|
2011-10-17 18:59:28 +04:00
|
|
|
firstPrescriptsPair = false;
|
2001-02-23 19:10:51 +03:00
|
|
|
mBoundingMetrics.leftBearing =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MIN(bmSubScript.leftBearing, bmSupScript.leftBearing);
|
2000-01-18 07:35:37 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
|
|
|
width = rightBearing = 0;
|
|
|
|
|
|
|
|
// negotiate between the various shifts so that
|
|
|
|
// there is enough gap between the sup and subscripts
|
|
|
|
// Rule 18e, App. G, TeXbook
|
|
|
|
nscoord gap =
|
|
|
|
(trySupScriptShift - bmSupScript.descent) -
|
|
|
|
(bmSubScript.ascent - trySubScriptShift);
|
|
|
|
if (gap < 4.0f * ruleSize) {
|
|
|
|
// adjust trySubScriptShift to get a gap of (4.0 * ruleSize)
|
|
|
|
trySubScriptShift += NSToCoordRound ((4.0f * ruleSize) - gap);
|
|
|
|
}
|
2001-02-02 12:37:14 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// 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 -
|
|
|
|
(trySupScriptShift - bmSupScript.descent));
|
|
|
|
if (gap > 0.0f) {
|
|
|
|
trySupScriptShift += gap;
|
|
|
|
trySubScriptShift -= gap;
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2009-09-16 19:01:36 +04:00
|
|
|
maxSubScriptShift = NS_MAX(maxSubScriptShift, trySubScriptShift);
|
|
|
|
maxSupScriptShift = NS_MAX(maxSupScriptShift, trySupScriptShift);
|
2001-02-23 19:10:51 +03:00
|
|
|
|
|
|
|
trySubScriptShift = subScriptShift;
|
|
|
|
trySupScriptShift = supScriptShift;
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
|
|
|
isSubScript = !isSubScript;
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
count++;
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2000-03-28 13:38:24 +04:00
|
|
|
// note: width=0 if all sup-sub pairs match correctly
|
|
|
|
if ((0 != width) || !baseFrame || !subScriptFrame || !supScriptFrame) {
|
|
|
|
// report an error, encourage people to get their markups in order
|
2006-08-04 03:27:55 +04:00
|
|
|
return ReflowError(aRenderingContext, aDesiredSize);
|
2000-03-28 13:38:24 +04:00
|
|
|
}
|
2000-01-18 07:35:37 +03: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 ...
|
2001-02-23 19:10:51 +03:00
|
|
|
mBoundingMetrics.ascent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.ascent+maxSupScriptShift,bmBase.ascent);
|
2001-02-23 19:10:51 +03:00
|
|
|
mBoundingMetrics.descent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.descent+maxSubScriptShift,bmBase.descent);
|
2000-01-18 07:35:37 +03:00
|
|
|
|
|
|
|
// get the reflow metrics ...
|
2001-02-23 19:10:51 +03:00
|
|
|
aDesiredSize.ascent =
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(ascent+maxSupScriptShift,baseSize.ascent);
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent +
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(descent+maxSubScriptShift,baseSize.height - baseSize.ascent);
|
2000-01-18 07:35:37 +03:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
2001-02-03 00:29:21 +03:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2000-01-18 07:35:37 +03:00
|
|
|
|
|
|
|
mReference.x = 0;
|
2000-03-28 13:38:24 +04:00
|
|
|
mReference.y = aDesiredSize.ascent;
|
2000-01-18 07:35:37 +03:00
|
|
|
|
2000-01-07 17:49:46 +03:00
|
|
|
//////////////////
|
2001-02-23 19:10:51 +03:00
|
|
|
// Place Children
|
1999-09-21 06:12:01 +04:00
|
|
|
|
2000-01-07 17:49:46 +03: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;
|
|
|
|
|
|
|
|
count = 0;
|
2001-02-23 19:10:51 +03:00
|
|
|
childFrame = mprescriptsFrame;
|
2000-01-07 17:49:46 +03:00
|
|
|
do {
|
2001-02-23 19:10:51 +03:00
|
|
|
if (!childFrame) { // end of prescripts,
|
2001-02-02 12:37:14 +03:00
|
|
|
// place the base ...
|
2001-02-23 19:10:51 +03:00
|
|
|
childFrame = baseFrame;
|
2000-01-18 07:35:37 +03:00
|
|
|
dy = aDesiredSize.ascent - baseSize.ascent;
|
2010-01-05 13:22:31 +03:00
|
|
|
FinishReflowChild (baseFrame, PresContext(), nsnull, baseSize,
|
|
|
|
MirrorIfRTL(aDesiredSize.width,
|
|
|
|
baseSize.width,
|
|
|
|
dx),
|
|
|
|
dy, 0);
|
2005-09-07 03:47:01 +04:00
|
|
|
dx += bmBase.width + italicCorrection;
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
else if (mprescriptsFrame != childFrame) {
|
2001-02-02 12:37:14 +03:00
|
|
|
// process each sup/sub pair
|
2001-02-23 19:10:51 +03:00
|
|
|
if (0 == count) {
|
|
|
|
subScriptFrame = childFrame;
|
|
|
|
count = 1;
|
2001-02-02 12:37:14 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
else if (1 == count) {
|
|
|
|
supScriptFrame = childFrame;
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
// get the ascent/descent of sup/subscripts stored in their rects
|
|
|
|
// rect.x = descent, rect.y = ascent
|
|
|
|
GetReflowAndBoundingMetricsFor(subScriptFrame, subScriptSize, bmSubScript);
|
|
|
|
GetReflowAndBoundingMetricsFor(supScriptFrame, supScriptSize, bmSupScript);
|
|
|
|
|
|
|
|
// center w.r.t. largest width
|
2009-09-16 19:01:36 +04:00
|
|
|
width = NS_MAX(subScriptSize.width, supScriptSize.width);
|
2001-02-23 19:10:51 +03:00
|
|
|
|
|
|
|
dy = aDesiredSize.ascent - subScriptSize.ascent +
|
|
|
|
maxSubScriptShift;
|
2010-01-05 13:22:31 +03:00
|
|
|
FinishReflowChild (subScriptFrame, PresContext(), nsnull,
|
|
|
|
subScriptSize,
|
|
|
|
MirrorIfRTL(aDesiredSize.width,
|
|
|
|
subScriptSize.width,
|
|
|
|
dx + (width-subScriptSize.width)/2),
|
|
|
|
dy, 0);
|
2000-01-18 07:35:37 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
dy = aDesiredSize.ascent - supScriptSize.ascent -
|
|
|
|
maxSupScriptShift;
|
2010-01-05 13:22:31 +03:00
|
|
|
FinishReflowChild (supScriptFrame, PresContext(), nsnull,
|
|
|
|
supScriptSize,
|
|
|
|
MirrorIfRTL(aDesiredSize.width,
|
|
|
|
supScriptSize.width,
|
|
|
|
dx + (width-supScriptSize.width)/2),
|
|
|
|
dy, 0);
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2005-09-07 03:47:01 +04:00
|
|
|
dx += width + scriptSpace;
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
|
|
|
}
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2001-02-23 19:10:51 +03:00
|
|
|
} while (mprescriptsFrame != childFrame);
|
2000-01-07 17:49:46 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
return NS_OK;
|
1999-09-21 06:12:01 +04:00
|
|
|
}
|