/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
// // <menclose> -- enclose content with a stretching symbol such // as a long division sign. - implementation
// longdiv: // Unicode 5.1 assigns U+27CC to LONG DIVISION, but a right parenthesis // renders better with current font support. staticconst char16_t kLongDivChar = ')';
nsresult nsMathMLmencloseFrame::AllocateMathMLChar(nsMencloseNotation mask) { // Is the char already allocated? if (mask == NOTATION_LONGDIV && mLongDivCharIndex >= 0) { return NS_OK;
}
// No need to track the ComputedStyle given to our MathML chars. // The Style System will use Get/SetAdditionalComputedStyle() to keep it // up-to-date if dynamic changes arise.
uint32_t i = mMathMLChar.Length();
nsAutoString Char;
// XXX(Bug 1631371) Check if this should use a fallible operation as it // pretended earlier, or change the return type to void.
mMathMLChar.AppendElement();
if (mask == NOTATION_LONGDIV) { Char.Assign(kLongDivChar);
mLongDivCharIndex = i;
}
/* * Add a notation to draw, if the argument is the name of a known notation. * @param aNotation string name of a notation
*/
nsresult nsMathMLmencloseFrame::AddNotation(const nsAString& aNotation) {
nsresult rv;
/* * Initialize the list of notations to draw
*/ void nsMathMLmencloseFrame::InitNotations() {
MarkNeedsDisplayItemRebuild();
mNotationsToDraw.clear();
mLongDivCharIndex = -1;
mMathMLChar.Clear();
nsAutoString value;
if (mContent->AsElement()->GetAttr(nsGkAtoms::notation_, value)) { // parse the notation attribute
nsWhitespaceTokenizer tokenizer(value);
while (tokenizer.hasMoreTokens()) {
AddNotation(tokenizer.nextToken());
}
if (IsToDraw(NOTATION_UPDIAGONALARROW)) { // For <menclose notation="updiagonalstrike updiagonalarrow">, if // the two notations are drawn then the strike line may cause the point of // the arrow to be too wide. Hence we will only draw the updiagonalarrow // and the arrow shaft may be thought to be the updiagonalstrike.
mNotationsToDraw -= NOTATION_UPDIAGONALSTRIKE;
}
} else { // default: longdiv if (NS_FAILED(AllocateMathMLChar(NOTATION_LONGDIV))) { return;
}
mNotationsToDraw += NOTATION_LONGDIV;
}
}
NS_IMETHODIMP
nsMathMLmencloseFrame::InheritAutomaticData(nsIFrame* aParent) { // let the base class get the default from our parent
nsMathMLContainerFrame::InheritAutomaticData(aParent);
/* virtual */
nsresult nsMathMLmencloseFrame::Place(DrawTarget* aDrawTarget, const PlaceFlags& aFlags,
ReflowOutput& aDesiredSize) { /////////////// // Measure the size of our content using the base class to format like an // inferred mrow, without border/padding.
ReflowOutput baseSize(aDesiredSize.GetWritingMode());
PlaceFlags flags = aFlags + PlaceFlag::MeasureOnly +
PlaceFlag::IgnoreBorderPadding +
PlaceFlag::DoNotAdjustForWidthAndHeight;
nsresult rv = nsMathMLContainerFrame::Place(aDrawTarget, flags, baseSize);
if (NS_FAILED(rv)) {
DidReflowChildren(PrincipalChildList().FirstChild()); return rv;
}
if (IsToDraw(NOTATION_LONGDIV)) { // The MathML spec does not define precise layout rules for menclose. Here // we draw longdiv using the same parameter as for radicals. // See https://github.com/w3c/mathml-core/issues/245
nscoord dummy;
GetRadicalParameters(fm, StyleFont()->mMathStyle == StyleMathStyle::Normal,
dummy, leading, psi);
// adjust clearance psi to get an exact number of pixels -- this // gives a nicer & uniform look on stacked radicals (bug 130282)
delta = psi % onePixel; if (delta) {
psi += onePixel - delta; // round up
}
}
// Set horizontal parameters if (IsToDraw(NOTATION_ROUNDEDBOX) || IsToDraw(NOTATION_TOP) ||
IsToDraw(NOTATION_LEFT) || IsToDraw(NOTATION_BOTTOM) ||
IsToDraw(NOTATION_CIRCLE)) {
dx_left = padding;
}
/////////////// // updiagonal arrow notation. We need enough space at the top right corner to // draw the arrow head. if (IsToDraw(NOTATION_UPDIAGONALARROW)) { // This is an estimate, see nsDisplayNotation::Paint for the exact head size
nscoord arrowHeadSize = kArrowHeadSize * mRuleThickness;
// We want that the arrow shaft strikes the menclose content and that the // arrow head does not overlap with that content. Hence we add some space // on the right. We don't add space on the top but only ensure that the // ascent is large enough.
dx_right = std::max(dx_right, arrowHeadSize);
mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent, arrowHeadSize);
}
/////////////// // circle notation: we don't want the ellipse to overlap the enclosed // content. Hence, we need to increase the size of the bounding box by a // factor of at least sqrt(2). if (IsToDraw(NOTATION_CIRCLE)) { double ratio = (sqrt(2.0) - 1.0) / 2.0;
nscoord padding2;
// Update horizontal parameters
padding2 = ratio * bmBase.width;
/////////////// // longdiv notation: if (IsToDraw(NOTATION_LONGDIV)) { if (aFlags.contains(PlaceFlag::IntrinsicSize)) {
nscoord longdiv_width = mMathMLChar[mLongDivCharIndex].GetMaxWidth( this, aDrawTarget, fontSizeInflation);
// Update horizontal parameters
dx_left = std::max(dx_left, longdiv_width);
} else { // Stretch the parenthesis to the appropriate height if it is not // big enough.
nsBoundingMetrics contSize = bmBase;
contSize.ascent = mRuleThickness;
contSize.descent = bmBase.ascent + bmBase.descent + psi;
// height(longdiv) should be >= height(base) + psi + mRuleThickness
mMathMLChar[mLongDivCharIndex].Stretch( this, aDrawTarget, fontSizeInflation, NS_STRETCH_DIRECTION_VERTICAL,
contSize, bmLongdivChar, NS_STRETCH_LARGER, false);
mMathMLChar[mLongDivCharIndex].GetBoundingMetrics(bmLongdivChar);
if (IsToDraw(NOTATION_CIRCLE) || IsToDraw(NOTATION_ROUNDEDBOX) ||
(IsToDraw(NOTATION_TOP) && IsToDraw(NOTATION_BOTTOM))) { // center the menclose around the content (vertically)
nscoord dy = std::max(aDesiredSize.BlockStartAscent() - bmBase.ascent,
aDesiredSize.Height() -
aDesiredSize.BlockStartAscent() - bmBase.descent);
// phasorangle notation: // move up from the bottom by the angled line height if (IsToDraw(NOTATION_PHASORANGLE)) {
mBoundingMetrics.ascent = std::max(
mBoundingMetrics.ascent,
2 * kPhasorangleWidth * mRuleThickness - mBoundingMetrics.descent);
}
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
// Apply width/height to math content box. auto sizes = GetWidthAndHeightForPlaceAdjustment(aFlags);
dx_left += ApplyAdjustmentForWidthAndHeight(aFlags, sizes, aDesiredSize,
mBoundingMetrics);
// Add padding+border. auto borderPadding = GetBorderPaddingForPlace(aFlags);
InflateReflowAndBoundingMetrics(borderPadding, aDesiredSize,
mBoundingMetrics);
if (!aFlags.contains(PlaceFlag::MeasureOnly)) { ////////////////// // Set position and size of MathMLChars if (IsToDraw(NOTATION_LONGDIV)) {
mMathMLChar[mLongDivCharIndex].SetRect(nsRect(
dx_left - bmLongdivChar.width + borderPadding.left,
aDesiredSize.BlockStartAscent() - longdivAscent, bmLongdivChar.width,
bmLongdivChar.ascent + bmLongdivChar.descent));
}
// Draw the arrow head
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
builder->MoveTo(rect.TopRight());
builder->LineTo(
rect.TopRight() +
Point(-w - .4 * h, std::max(-strokeWidth / 2.0, h - .4 * w)));
builder->LineTo(rect.TopRight() + Point(-.7 * w, .7 * h));
builder->LineTo(
rect.TopRight() +
Point(std::min(strokeWidth / 2.0, -w + .4 * h), h + .4 * w));
builder->Close();
RefPtr<Path> path = builder->Finish();
aDrawTarget.Fill(path, color); return;
} case NOTATION_PHASORANGLE: { // Compute some parameters to draw the angled line, // that uses a slope of 2 (angle = tan^-1(2)). // H = w * tan(angle) = w * 2 Float w = Float(kPhasorangleWidth) * strokeWidth; Float H = 2 * w;
// Draw the angled line
aDrawTarget.StrokeLine(rect.BottomLeft(),
rect.BottomLeft() + Point(w, -H), color,
strokeOptions); return;
} default:
MOZ_ASSERT_UNREACHABLE( "This notation can not be drawn using " "nsDisplayNotation");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.