void CServerDoc::OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect) { // get first view of document POSITION pos = GetFirstViewPosition(); ASSERT(pos != NULL); CServerView* pView = (CServerView*)GetNextView(pos); ASSERT_KINDOF(CServerView, pView); ASSERT_VALID(pView); CSize sizeNum(lpPosRect->right - lpPosRect->left, lpPosRect->bottom - lpPosRect->top); // for denom -- get extent in device // create a view dc CServerDC dc(pView); // set zoom to 100% dc.SetViewportExt(CSize(1,1)); dc.SetWindowExt(CSize(1,1)); // get extents in device CSize sizeDenom = pView->CalcActualItemSize(m_pRoot, &dc); // notify first view of potential zoom factor change! pView->SetZoomFactor(sizeNum, sizeDenom); // resize the window COleServerDoc::OnSetItemRects(lpPosRect, lpClipRect); // set scrollbar state (if necessary) pView->SetScrollInfo(); }
nsresult nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, bool aPlaceOrigin, nsHTMLReflowMetrics& aDesiredSize, bool aWidthOnly) { //////////////////////////////////// // Get the children's desired sizes nsBoundingMetrics bmNum, bmDen; nsHTMLReflowMetrics sizeNum(aDesiredSize.GetWritingMode()); nsHTMLReflowMetrics sizeDen(aDesiredSize.GetWritingMode()); nsIFrame* frameDen = nullptr; nsIFrame* frameNum = mFrames.FirstChild(); if (frameNum) frameDen = frameNum->GetNextSibling(); if (!frameNum || !frameDen || frameDen->GetNextSibling()) { // report an error, encourage people to get their markups in order if (aPlaceOrigin) { ReportChildCountError(); } return ReflowError(aRenderingContext, aDesiredSize); } GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum); GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen); nsPresContext* presContext = PresContext(); nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); nsRefPtr<nsFontMetrics> fm; nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); aRenderingContext.SetFont(fm); nscoord defaultRuleThickness, axisHeight; GetRuleThickness(aRenderingContext, fm, defaultRuleThickness); GetAxisHeight(aRenderingContext, fm, axisHeight); bool outermostEmbellished = false; if (mEmbellishData.coreFrame) { nsEmbellishData parentData; GetEmbellishDataFrom(GetParent(), parentData); outermostEmbellished = parentData.coreFrame != mEmbellishData.coreFrame; } // see if the linethickness attribute is there nsAutoString value; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::linethickness_, value); mLineThickness = CalcLineThickness(presContext, mStyleContext, value, onePixel, defaultRuleThickness); // bevelled attribute mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::bevelled_, value); mIsBevelled = value.EqualsLiteral("true"); if (!mIsBevelled) { mLineRect.height = mLineThickness; // by default, leave at least one-pixel padding at either end, and add // lspace & rspace that may come from <mo> if we are an outermost // embellished container (we fetch values from the core since they may use // units that depend on style data, and style changes could have occurred // in the core since our last visit there) nscoord leftSpace = onePixel; nscoord rightSpace = onePixel; if (outermostEmbellished) { nsEmbellishData coreData; GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData); leftSpace += StyleVisibility()->mDirection ? coreData.trailingSpace : coreData.leadingSpace; rightSpace += StyleVisibility()->mDirection ? coreData.leadingSpace : coreData.trailingSpace; } ////////////////// // Get shifts nscoord numShift = 0; nscoord denShift = 0; // Rule 15b, App. G, TeXbook nscoord numShift1, numShift2, numShift3; nscoord denShift1, denShift2; GetNumeratorShifts(fm, numShift1, numShift2, numShift3); GetDenominatorShifts(fm, denShift1, denShift2); if (StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK) { // C > T numShift = numShift1; denShift = denShift1; } else { numShift = (0 < mLineRect.height) ? numShift2 : numShift3; denShift = denShift2; } nscoord minClearance = 0; nscoord actualClearance = 0; nscoord actualRuleThickness = mLineThickness; if (0 == actualRuleThickness) { // Rule 15c, App. G, TeXbook // min clearance between numerator and denominator minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK ? 7 * defaultRuleThickness : 3 * defaultRuleThickness; actualClearance = (numShift - bmNum.descent) - (bmDen.ascent - denShift); // actualClearance should be >= minClearance if (actualClearance < minClearance) { nscoord halfGap = (minClearance - actualClearance)/2; numShift += halfGap; denShift += halfGap; } } else { // Rule 15d, App. G, TeXbook // min clearance between numerator or denominator and middle of bar // TeX has a different interpretation of the thickness. // Try $a \above10pt b$ to see. Here is what TeX does: // minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK // ? 3 * actualRuleThickness : actualRuleThickness; // 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 = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK ? 3 * defaultRuleThickness : defaultRuleThickness + onePixel; // adjust numShift to maintain minClearance if needed actualClearance = (numShift - bmNum.descent) - (axisHeight + actualRuleThickness/2); if (actualClearance < minClearance) { numShift += (minClearance - actualClearance); } // adjust denShift to maintain minClearance if needed actualClearance = (axisHeight - actualRuleThickness/2) - (bmDen.ascent - denShift); if (actualClearance < minClearance) { denShift += (minClearance - actualClearance); } } ////////////////// // Place Children // XXX Need revisiting the width. TeX uses the exact width // e.g. in $$\huge\frac{\displaystyle\int}{i}$$ nscoord width = std::max(bmNum.width, bmDen.width); nscoord dxNum = leftSpace + (width - sizeNum.Width())/2; nscoord dxDen = leftSpace + (width - sizeDen.Width())/2; width += leftSpace + rightSpace; // see if the numalign attribute is there mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::numalign_, value); if (value.EqualsLiteral("left")) dxNum = leftSpace; else if (value.EqualsLiteral("right")) dxNum = width - rightSpace - sizeNum.Width(); // see if the denomalign attribute is there mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::denomalign_, value); if (value.EqualsLiteral("left")) dxDen = leftSpace; else if (value.EqualsLiteral("right")) dxDen = width - rightSpace - sizeDen.Width(); mBoundingMetrics.rightBearing = std::max(dxNum + bmNum.rightBearing, dxDen + bmDen.rightBearing); if (mBoundingMetrics.rightBearing < width - rightSpace) mBoundingMetrics.rightBearing = width - rightSpace; mBoundingMetrics.leftBearing = std::min(dxNum + bmNum.leftBearing, dxDen + bmDen.leftBearing); if (mBoundingMetrics.leftBearing > leftSpace) mBoundingMetrics.leftBearing = leftSpace; mBoundingMetrics.ascent = bmNum.ascent + numShift; mBoundingMetrics.descent = bmDen.descent + denShift; mBoundingMetrics.width = width; aDesiredSize.SetBlockStartAscent(sizeNum.BlockStartAscent() + numShift); aDesiredSize.Height() = aDesiredSize.BlockStartAscent() + sizeDen.Height() - sizeDen.BlockStartAscent() + denShift; aDesiredSize.Width() = mBoundingMetrics.width; aDesiredSize.mBoundingMetrics = mBoundingMetrics; mReference.x = 0; mReference.y = aDesiredSize.BlockStartAscent(); if (aPlaceOrigin) { nscoord dy; // place numerator dy = 0; FinishReflowChild(frameNum, presContext, sizeNum, nullptr, dxNum, dy, 0); // place denominator dy = aDesiredSize.Height() - sizeDen.Height(); FinishReflowChild(frameDen, presContext, sizeDen, nullptr, dxDen, dy, 0); // place the fraction bar - dy is top of bar dy = aDesiredSize.BlockStartAscent() - (axisHeight + actualRuleThickness/2); mLineRect.SetRect(leftSpace, dy, width - (leftSpace + rightSpace), actualRuleThickness); } } else { nscoord numShift = 0.0; nscoord denShift = 0.0; nscoord padding = 3 * defaultRuleThickness; nscoord slashRatio = 3; // Define the constant used in the expression of the maximum width nscoord em = fm->EmHeight(); nscoord slashMaxWidthConstant = 2 * em; // For large line thicknesses the minimum slash height is limited to the // largest expected height of a fraction nscoord slashMinHeight = slashRatio * std::min(2 * mLineThickness, slashMaxWidthConstant); nscoord leadingSpace = padding; nscoord trailingSpace = padding; if (outermostEmbellished) { nsEmbellishData coreData; GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData); leadingSpace += coreData.leadingSpace; trailingSpace += coreData.trailingSpace; } nscoord delta; // ___________ // | | / // {|-NUMERATOR-| / // {|___________| S // { L // numShift{ A // ------------------------------------------------------- baseline // S _____________ } denShift // H | |} // / |-DENOMINATOR-|} // / |_____________| // // first, ensure that the top of the numerator is at least as high as the // top of the denominator (and the reverse for the bottoms) delta = std::max(bmDen.ascent - bmNum.ascent, bmNum.descent - bmDen.descent) / 2; if (delta > 0) { numShift += delta; denShift += delta; } if (StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK) { delta = std::min(bmDen.ascent + bmDen.descent, bmNum.ascent + bmNum.descent) / 2; numShift += delta; denShift += delta; } else { nscoord xHeight = fm->XHeight(); numShift += xHeight / 2; denShift += xHeight / 4; } // Set the ascent/descent of our BoundingMetrics. mBoundingMetrics.ascent = bmNum.ascent + numShift; mBoundingMetrics.descent = bmDen.descent + denShift; // At this point the height of the slash is // mBoundingMetrics.ascent + mBoundingMetrics.descent // Ensure that it is greater than slashMinHeight delta = (slashMinHeight - (mBoundingMetrics.ascent + mBoundingMetrics.descent)) / 2; if (delta > 0) { mBoundingMetrics.ascent += delta; mBoundingMetrics.descent += delta; } // Set the width of the slash if (aWidthOnly) { mLineRect.width = mLineThickness + slashMaxWidthConstant; } else { mLineRect.width = mLineThickness + std::min(slashMaxWidthConstant, (mBoundingMetrics.ascent + mBoundingMetrics.descent) / slashRatio); } // Set horizontal bounding metrics if (StyleVisibility()->mDirection) { mBoundingMetrics.leftBearing = trailingSpace + bmDen.leftBearing; mBoundingMetrics.rightBearing = trailingSpace + bmDen.width + mLineRect.width + bmNum.rightBearing; } else { mBoundingMetrics.leftBearing = leadingSpace + bmNum.leftBearing; mBoundingMetrics.rightBearing = leadingSpace + bmNum.width + mLineRect.width + bmDen.rightBearing; } mBoundingMetrics.width = leadingSpace + bmNum.width + mLineRect.width + bmDen.width + trailingSpace; // Set aDesiredSize aDesiredSize.SetBlockStartAscent(mBoundingMetrics.ascent + padding); aDesiredSize.Height() = mBoundingMetrics.ascent + mBoundingMetrics.descent + 2 * padding; aDesiredSize.Width() = mBoundingMetrics.width; aDesiredSize.mBoundingMetrics = mBoundingMetrics; mReference.x = 0; mReference.y = aDesiredSize.BlockStartAscent(); if (aPlaceOrigin) { nscoord dx, dy; // place numerator dx = MirrorIfRTL(aDesiredSize.Width(), sizeNum.Width(), leadingSpace); dy = aDesiredSize.BlockStartAscent() - numShift - sizeNum.BlockStartAscent(); FinishReflowChild(frameNum, presContext, sizeNum, nullptr, dx, dy, 0); // place the fraction bar dx = MirrorIfRTL(aDesiredSize.Width(), mLineRect.width, leadingSpace + bmNum.width); dy = aDesiredSize.BlockStartAscent() - mBoundingMetrics.ascent; mLineRect.SetRect(dx, dy, mLineRect.width, aDesiredSize.Height() - 2 * padding); // place denominator dx = MirrorIfRTL(aDesiredSize.Width(), sizeDen.Width(), leadingSpace + bmNum.width + mLineRect.width); dy = aDesiredSize.BlockStartAscent() + denShift - sizeDen.BlockStartAscent(); FinishReflowChild(frameDen, presContext, sizeDen, nullptr, dx, dy, 0); } } return NS_OK; }