本文整理汇总了C++中nsIRenderingContext::SetFont方法的典型用法代码示例。如果您正苦于以下问题:C++ nsIRenderingContext::SetFont方法的具体用法?C++ nsIRenderingContext::SetFont怎么用?C++ nsIRenderingContext::SetFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsIRenderingContext
的用法示例。
在下文中一共展示了nsIRenderingContext::SetFont方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
nsTextBoxFrame::GetTextSize(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext,
const nsString& aString, nsSize& aSize, nscoord& aAscent)
{
nsCOMPtr<nsIFontMetrics> fontMet;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
fontMet->GetHeight(aSize.height);
aRenderingContext.SetFont(fontMet);
aSize.width =
nsLayoutUtils::GetStringWidth(this, &aRenderingContext, aString.get(), aString.Length());
fontMet->GetMaxAscent(aAscent);
}
示例2: rect
void
nsPageFrame::PaintHeaderFooter(nsIRenderingContext& aRenderingContext,
nsPoint aPt)
{
nsPresContext* pc = PresContext();
if (!mPD->mPrintSettings) {
if (pc->Type() == nsPresContext::eContext_PrintPreview || pc->IsDynamic())
mPD->mPrintSettings = pc->GetPrintSettings();
if (!mPD->mPrintSettings)
return;
}
nsRect rect(aPt.x, aPt.y, mRect.width - mPD->mShadowSize.width,
mRect.height - mPD->mShadowSize.height);
aRenderingContext.SetColor(NS_RGB(0,0,0));
// Get the FontMetrics to determine width.height of strings
nsCOMPtr<nsIFontMetrics> fontMet;
pc->DeviceContext()->GetMetricsFor(*mPD->mHeadFootFont,
pc->GetUserFontSet(),
*getter_AddRefs(fontMet));
aRenderingContext.SetFont(fontMet);
nscoord ascent = 0;
nscoord visibleHeight = 0;
if (fontMet) {
fontMet->GetHeight(visibleHeight);
fontMet->GetMaxAscent(ascent);
}
// print document headers and footers
nsXPIDLString headerLeft, headerCenter, headerRight;
mPD->mPrintSettings->GetHeaderStrLeft(getter_Copies(headerLeft));
mPD->mPrintSettings->GetHeaderStrCenter(getter_Copies(headerCenter));
mPD->mPrintSettings->GetHeaderStrRight(getter_Copies(headerRight));
DrawHeaderFooter(aRenderingContext, eHeader,
headerLeft, headerCenter, headerRight,
rect, ascent, visibleHeight);
nsXPIDLString footerLeft, footerCenter, footerRight;
mPD->mPrintSettings->GetFooterStrLeft(getter_Copies(footerLeft));
mPD->mPrintSettings->GetFooterStrCenter(getter_Copies(footerCenter));
mPD->mPrintSettings->GetFooterStrRight(getter_Copies(footerRight));
DrawHeaderFooter(aRenderingContext, eFooter,
footerLeft, footerCenter, footerRight,
rect, ascent, visibleHeight);
}
示例3: PlaceSubSupScript
NS_IMETHODIMP
nsMathMLmunderoverFrame::Place(nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize)
{
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishData.flags) &&
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
// place like sub-superscript pair
return nsMathMLmsubsupFrame::PlaceSubSupScript(GetPresContext(),
aRenderingContext,
aPlaceOrigin,
aDesiredSize,
this);
}
////////////////////////////////////
// Get the children's desired sizes
nsBoundingMetrics bmBase, bmUnder, bmOver;
nsHTMLReflowMetrics baseSize (nsnull);
nsHTMLReflowMetrics underSize (nsnull);
nsHTMLReflowMetrics overSize (nsnull);
nsIFrame* overFrame = nsnull;
nsIFrame* underFrame = nsnull;
nsIFrame* baseFrame = mFrames.FirstChild();
if (baseFrame)
underFrame = baseFrame->GetNextSibling();
if (underFrame)
overFrame = underFrame->GetNextSibling();
if (!baseFrame || !underFrame || !overFrame || overFrame->GetNextSibling()) {
// report an error, encourage people to get their markups in order
NS_WARNING("invalid markup");
return ReflowError(aRenderingContext, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
GetReflowAndBoundingMetricsFor(underFrame, underSize, bmUnder);
GetReflowAndBoundingMetricsFor(overFrame, overSize, bmOver);
nscoord onePixel = GetPresContext()->IntScaledPixelsToTwips(1);
////////////////////
// Place Children
aRenderingContext.SetFont(GetStyleFont()->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
nscoord xHeight = 0;
fm->GetXHeight (xHeight);
nscoord ruleThickness;
GetRuleThickness (aRenderingContext, fm, ruleThickness);
nscoord correction = 0;
GetItalicCorrection (bmBase, correction);
// there are 2 different types of placement depending on
// whether we want an accented under or not
nscoord underDelta1 = 0; // gap between base and underscript
nscoord underDelta2 = 0; // extra space beneath underscript
if (!NS_MATHML_EMBELLISH_IS_ACCENTUNDER(mEmbellishData.flags)) {
// Rule 13a, App. G, TeXbook
nscoord bigOpSpacing2, bigOpSpacing4, bigOpSpacing5, dummy;
GetBigOpSpacings (fm,
dummy, bigOpSpacing2,
dummy, bigOpSpacing4,
bigOpSpacing5);
underDelta1 = PR_MAX(bigOpSpacing2, (bigOpSpacing4 - bmUnder.ascent));
underDelta2 = bigOpSpacing5;
}
else {
// No corresponding rule in TeXbook - we are on our own here
// XXX tune the gap delta between base and underscript
// Should we use Rule 10 like \underline does?
underDelta1 = ruleThickness + onePixel/2;
underDelta2 = ruleThickness;
}
// empty under?
if (!(bmUnder.ascent + bmUnder.descent)) underDelta1 = 0;
nscoord overDelta1 = 0; // gap between base and overscript
nscoord overDelta2 = 0; // extra space above overscript
if (!NS_MATHML_EMBELLISH_IS_ACCENTOVER(mEmbellishData.flags)) {
// Rule 13a, App. G, TeXbook
nscoord bigOpSpacing1, bigOpSpacing3, bigOpSpacing5, dummy;
GetBigOpSpacings (fm,
bigOpSpacing1, dummy,
bigOpSpacing3, dummy,
bigOpSpacing5);
overDelta1 = PR_MAX(bigOpSpacing1, (bigOpSpacing3 - bmOver.descent));
overDelta2 = bigOpSpacing5;
// XXX This is not a TeX rule...
// delta1 (as computed abvove) can become really big when bmOver.descent is
// negative, e.g., if the content is &OverBar. In such case, we use the height
if (bmOver.descent < 0)
//.........这里部分代码省略.........
示例4: PlaceSuperScript
/* virtual */ nsresult
nsMathMLmoverFrame::Place(nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize)
{
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishData.flags) &&
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
// place like superscript
return nsMathMLmsupFrame::PlaceSuperScript(PresContext(),
aRenderingContext,
aPlaceOrigin,
aDesiredSize,
this, 0, nsPresContext::CSSPointsToAppUnits(0.5f));
}
////////////////////////////////////
// Get the children's desired sizes
nsBoundingMetrics bmBase, bmOver;
nsHTMLReflowMetrics baseSize;
nsHTMLReflowMetrics overSize;
nsIFrame* overFrame = nsnull;
nsIFrame* baseFrame = mFrames.FirstChild();
if (baseFrame)
overFrame = baseFrame->GetNextSibling();
if (!baseFrame || !overFrame || overFrame->GetNextSibling()) {
// report an error, encourage people to get their markups in order
return ReflowError(aRenderingContext, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
GetReflowAndBoundingMetricsFor(overFrame, overSize, bmOver);
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
////////////////////
// Place Children
aRenderingContext.SetFont(GetStyleFont()->mFont,
PresContext()->GetUserFontSet());
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
nscoord xHeight = 0;
fm->GetXHeight (xHeight);
nscoord ruleThickness;
GetRuleThickness (aRenderingContext, fm, ruleThickness);
// there are 2 different types of placement depending on
// whether we want an accented overscript or not
nscoord correction = 0;
GetItalicCorrection (bmBase, correction);
nscoord delta1 = 0; // gap between base and overscript
nscoord delta2 = 0; // extra space above overscript
if (!NS_MATHML_EMBELLISH_IS_ACCENTOVER(mEmbellishData.flags)) {
// Rule 13a, App. G, TeXbook
nscoord bigOpSpacing1, bigOpSpacing3, bigOpSpacing5, dummy;
GetBigOpSpacings (fm,
bigOpSpacing1, dummy,
bigOpSpacing3, dummy,
bigOpSpacing5);
delta1 = NS_MAX(bigOpSpacing1, (bigOpSpacing3 - bmOver.descent));
delta2 = bigOpSpacing5;
// XXX This is not a TeX rule...
// delta1 (as computed above) can become really big when bmOver.descent is
// negative, e.g., if the content is &OverBar. In such case, we use the height
if (bmOver.descent < 0)
delta1 = NS_MAX(bigOpSpacing1, (bigOpSpacing3 - (bmOver.ascent + bmOver.descent)));
}
else {
// Rule 12, App. G, TeXbook
// We are going to modify this rule to make it more general.
// The idea behind Rule 12 in the TeXBook is to keep the accent
// as close to the base as possible, while ensuring that the
// distance between the *baseline* of the accent char and
// the *baseline* of the base is atleast x-height.
// The idea is that for normal use, we would like all the accents
// on a line to line up atleast x-height above the baseline
// if possible.
// When the ascent of the base is >= x-height,
// the baseline of the accent char is placed just above the base
// (specifically, the baseline of the accent char is placed
// above the baseline of the base by the ascent of the base).
// For ease of implementation,
// this assumes that the font-designer designs accents
// in such a way that the bottom of the accent is atleast x-height
// above its baseline, otherwise there will be collisions
// with the base. Also there should be proper padding between
// the bottom of the accent char and its baseline.
// The above rule may not be obvious from a first
// reading of rule 12 in the TeXBook !!!
// The mathml <mover> tag can use accent chars that
// do not follow this convention. So we modify TeX's rule
// so that TeX's rule gets subsumed for accents that follow
// TeX's convention,
// while also allowing accents that do not follow the convention :
// we try to keep the *bottom* of the accent char atleast x-height
//.........这里部分代码省略.........
示例5: if
// exported routine that both munderover and msubsup share.
// munderover uses this when movablelimits is set.
nsresult
nsMathMLmsubsupFrame::PlaceSubSupScript(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize,
nsMathMLContainerFrame* aFrame,
nscoord aUserSubScriptShift,
nscoord aUserSupScriptShift,
nscoord aScriptSpace)
{
// force the scriptSpace to be atleast 1 pixel
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
aScriptSpace = PR_MAX(onePixel, aScriptSpace);
////////////////////////////////////
// Get the children's desired sizes
nsHTMLReflowMetrics baseSize;
nsHTMLReflowMetrics subScriptSize;
nsHTMLReflowMetrics supScriptSize;
nsBoundingMetrics bmBase, bmSubScript, bmSupScript;
nsIFrame* subScriptFrame = nsnull;
nsIFrame* supScriptFrame = nsnull;
nsIFrame* baseFrame = aFrame->GetFirstChild(nsnull);
if (baseFrame)
subScriptFrame = baseFrame->GetNextSibling();
if (subScriptFrame)
supScriptFrame = subScriptFrame->GetNextSibling();
if (!baseFrame || !subScriptFrame || !supScriptFrame ||
supScriptFrame->GetNextSibling()) {
// report an error, encourage people to get their markups in order
return aFrame->ReflowError(aRenderingContext, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
GetReflowAndBoundingMetricsFor(subScriptFrame, subScriptSize, bmSubScript);
GetReflowAndBoundingMetricsFor(supScriptFrame, supScriptSize, bmSupScript);
// get the subdrop from the subscript font
nscoord subDrop;
GetSubDropFromChild(subScriptFrame, subDrop);
// parameter v, Rule 18a, App. G, TeXbook
nscoord minSubScriptShift = bmBase.descent + subDrop;
// get the supdrop from the supscript font
nscoord supDrop;
GetSupDropFromChild(supScriptFrame, supDrop);
// parameter u, Rule 18a, App. G, TeXbook
nscoord minSupScriptShift = bmBase.ascent - supDrop;
//////////////////
// Place Children
//////////////////
//////////////////////////////////////////////////
// Get subscript shift
// slightly different from nsMathMLmsubFrame.cpp
//////////////////////////////////////////////////
// subScriptShift{1,2}
// = minimum amount to shift the subscript down
// = sub{1,2} in TeXbook
// subScriptShift1 = subscriptshift attribute * x-height
nscoord subScriptShift1, subScriptShift2;
aRenderingContext.SetFont(baseFrame->GetStyleFont()->mFont, nsnull,
aPresContext->GetUserFontSet());
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
// get x-height (an ex)
nscoord xHeight;
fm->GetXHeight (xHeight);
nscoord ruleSize;
GetRuleThickness (aRenderingContext, fm, ruleSize);
// Get subScriptShift{1,2} default from font
GetSubScriptShifts (fm, subScriptShift1, subScriptShift2);
if (0 < aUserSubScriptShift) {
// the user has set the subscriptshift attribute
float scaler = ((float) subScriptShift2) / subScriptShift1;
subScriptShift1 = PR_MAX(subScriptShift1, aUserSubScriptShift);
subScriptShift2 = NSToCoordRound(scaler * subScriptShift1);
}
// get a tentative value for subscriptshift
// Rule 18d, App. G, TeXbook
nscoord subScriptShift =
PR_MAX(minSubScriptShift,PR_MAX(subScriptShift1,subScriptShift2));
//////////////////////////////////////////////////
// Get supscript shift
// same code from nsMathMLmsupFrame.cpp
//////////////////////////////////////////////////
// get min supscript shift limit from x-height
// = d(x) + 1/4 * sigma_5, Rule 18c, App. G, TeXbook
//.........这里部分代码省略.........
示例6: ReflowError
nsresult
nsMathMLmfracFrame::PlaceInternal(nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize,
PRBool aWidthOnly)
{
////////////////////////////////////
// Get the children's desired sizes
nsBoundingMetrics bmNum, bmDen;
nsHTMLReflowMetrics sizeNum;
nsHTMLReflowMetrics sizeDen;
nsIFrame* frameDen = nsnull;
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
return ReflowError(aRenderingContext, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);
nsPresContext* presContext = PresContext();
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
aRenderingContext.SetFont(GetStyleFont()->mFont,
presContext->GetUserFontSet());
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
nscoord defaultRuleThickness, axisHeight;
GetRuleThickness(aRenderingContext, fm, defaultRuleThickness);
GetAxisHeight(aRenderingContext, fm, axisHeight);
nsEmbellishData coreData;
GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
// see if the linethickness attribute is there
nsAutoString value;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::linethickness_,
value);
mLineThickness = CalcLineThickness(presContext, mStyleContext, value,
onePixel, defaultRuleThickness);
if (!mIsBevelled) {
mLineRect.height = mLineThickness;
// by default, leave at least one-pixel padding at either end, or use
// lspace & rspace that may come from <mo> if we are an 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 = NS_MAX(onePixel, coreData.leftSpace);
nscoord rightSpace = NS_MAX(onePixel, coreData.rightSpace);
//////////////////
// 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 (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
// 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 = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
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
//.........这里部分代码省略.........
示例7: pt
void
nsTextBoxFrame::DrawText(nsIRenderingContext& aRenderingContext,
const nsRect& aTextRect,
const nscolor* aOverrideColor)
{
nsPresContext* presContext = PresContext();
// paint the title
nscolor overColor;
nscolor underColor;
nscolor strikeColor;
nsStyleContext* context = mStyleContext;
PRUint8 decorations = NS_STYLE_TEXT_DECORATION_NONE; // Begin with no decorations
PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_UNDERLINE | NS_STYLE_TEXT_DECORATION_OVERLINE |
NS_STYLE_TEXT_DECORATION_LINE_THROUGH; // A mask of all possible decorations.
PRBool hasDecorations = context->HasTextDecorations();
do { // find decoration colors
const nsStyleTextReset* styleText = context->GetStyleTextReset();
if (decorMask & styleText->mTextDecoration) { // a decoration defined here
nscolor color = aOverrideColor ? *aOverrideColor : context->GetStyleColor()->mColor;
if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decorMask & styleText->mTextDecoration) {
underColor = color;
decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE;
decorations |= NS_STYLE_TEXT_DECORATION_UNDERLINE;
}
if (NS_STYLE_TEXT_DECORATION_OVERLINE & decorMask & styleText->mTextDecoration) {
overColor = color;
decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE;
decorations |= NS_STYLE_TEXT_DECORATION_OVERLINE;
}
if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decorMask & styleText->mTextDecoration) {
strikeColor = color;
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
decorations |= NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
}
}
if (0 != decorMask) {
context = context->GetParent();
if (context) {
hasDecorations = context->HasTextDecorations();
}
}
} while (context && hasDecorations && (0 != decorMask));
nsCOMPtr<nsIFontMetrics> fontMet;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
nscoord offset;
nscoord size;
nscoord ascent;
fontMet->GetMaxAscent(ascent);
nscoord baseline =
presContext->RoundAppUnitsToNearestDevPixels(aTextRect.y + ascent);
nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
gfxPoint pt(presContext->AppUnitsToGfxUnits(aTextRect.x),
presContext->AppUnitsToGfxUnits(aTextRect.y));
gfxFloat width = presContext->AppUnitsToGfxUnits(aTextRect.width);
gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent);
// Underlines are drawn before overlines, and both before the text
// itself, per http://www.w3.org/TR/CSS21/zindex.html point 7.2.1.4.1.1.
// (We don't apply this rule to the access-key underline because we only
// find out where that is as a side effect of drawing the text, in the
// general case -- see below.)
if (decorations & (NS_FONT_DECORATION_OVERLINE |
NS_FONT_DECORATION_UNDERLINE)) {
fontMet->GetUnderline(offset, size);
gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset);
gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size);
if (decorations & NS_FONT_DECORATION_UNDERLINE) {
nsCSSRendering::PaintDecorationLine(ctx, underColor,
pt, gfxSize(width, sizePixel),
ascentPixel, offsetPixel,
NS_STYLE_TEXT_DECORATION_UNDERLINE,
nsCSSRendering::DECORATION_STYLE_SOLID);
}
if (decorations & NS_FONT_DECORATION_OVERLINE) {
nsCSSRendering::PaintDecorationLine(ctx, overColor,
pt, gfxSize(width, sizePixel),
ascentPixel, ascentPixel,
NS_STYLE_TEXT_DECORATION_OVERLINE,
nsCSSRendering::DECORATION_STYLE_SOLID);
}
}
aRenderingContext.SetFont(fontMet);
CalculateUnderline(aRenderingContext);
aRenderingContext.SetColor(aOverrideColor ? *aOverrideColor : GetStyleColor()->mColor);
#ifdef IBMBIDI
nsresult rv = NS_ERROR_FAILURE;
if (mState & NS_FRAME_IS_BIDI) {
//.........这里部分代码省略.........
示例8: DidReflowChildren
/* virtual */ nsresult
nsMathMLmencloseFrame::PlaceInternal(nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize,
PRBool aWidthOnly)
{
///////////////
// Measure the size of our content using the base class to format like an
// inferred mrow.
nsHTMLReflowMetrics baseSize;
nsresult rv =
nsMathMLContainerFrame::Place(aRenderingContext, PR_FALSE, baseSize);
if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) {
DidReflowChildren(GetFirstChild(nsnull));
return rv;
}
nsBoundingMetrics bmBase = baseSize.mBoundingMetrics;
nscoord dx_left = 0, dx_right = 0;
nsBoundingMetrics bmLongdivChar, bmRadicalChar;
nscoord radicalAscent = 0, radicalDescent = 0;
nscoord longdivAscent = 0, longdivDescent = 0;
nscoord psi = 0;
///////////////
// Thickness of bars and font metrics
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
nsCOMPtr<nsIFontMetrics> fm;
nscoord mEmHeight;
aRenderingContext.SetFont(GetStyleFont()->mFont,
PresContext()->GetUserFontSet());
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
GetRuleThickness(aRenderingContext, fm, mRuleThickness);
GetEmHeight(fm, mEmHeight);
nsBoundingMetrics bmOne;
aRenderingContext.GetBoundingMetrics(NS_LITERAL_STRING("1").get(), 1, bmOne);
///////////////
// General rules: the menclose element takes the size of the enclosed content.
// We add a padding when needed.
// determine padding & psi
nscoord padding = 3 * mRuleThickness;
nscoord delta = padding % onePixel;
if (delta)
padding += onePixel - delta; // round up
if (IsToDraw(NOTATION_LONGDIV) || IsToDraw(NOTATION_RADICAL)) {
nscoord phi;
// Rule 11, App. G, TeXbook
// psi = clearance between rule and content
if (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags))
fm->GetXHeight(phi);
else
phi = mRuleThickness;
psi = mRuleThickness + phi / 4;
delta = psi % onePixel;
if (delta)
psi += onePixel - delta; // round up
}
if (mRuleThickness < onePixel)
mRuleThickness = onePixel;
// Set horizontal parameters
if (IsToDraw(NOTATION_ROUNDEDBOX) ||
IsToDraw(NOTATION_TOP) ||
IsToDraw(NOTATION_LEFT) ||
IsToDraw(NOTATION_BOTTOM) ||
IsToDraw(NOTATION_CIRCLE))
dx_left = padding;
if (IsToDraw(NOTATION_ROUNDEDBOX) ||
IsToDraw(NOTATION_TOP) ||
IsToDraw(NOTATION_RIGHT) ||
IsToDraw(NOTATION_BOTTOM) ||
IsToDraw(NOTATION_CIRCLE))
dx_right = padding;
// Set vertical parameters
if (IsToDraw(NOTATION_RIGHT) ||
IsToDraw(NOTATION_LEFT) ||
IsToDraw(NOTATION_UPDIAGONALSTRIKE) ||
IsToDraw(NOTATION_DOWNDIAGONALSTRIKE) ||
IsToDraw(NOTATION_VERTICALSTRIKE) ||
IsToDraw(NOTATION_CIRCLE) ||
IsToDraw(NOTATION_ROUNDEDBOX) ||
IsToDraw(NOTATION_RADICAL) ||
IsToDraw(NOTATION_LONGDIV)) {
// set a minimal value for the base height
bmBase.ascent = NS_MAX(bmOne.ascent, bmBase.ascent);
bmBase.descent = NS_MAX(0, bmBase.descent);
}
mBoundingMetrics.ascent = bmBase.ascent;
mBoundingMetrics.descent = bmBase.descent;
//.........这里部分代码省略.........
示例9: ReflowError
/* virtual */ nsresult
nsMathMLmfracFrame::Place(nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize)
{
////////////////////////////////////
// Get the children's desired sizes
nsBoundingMetrics bmNum, bmDen;
nsHTMLReflowMetrics sizeNum;
nsHTMLReflowMetrics sizeDen;
nsIFrame* frameDen = nsnull;
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
NS_WARNING("invalid markup");
return ReflowError(aRenderingContext, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);
//////////////////
// Get shifts
nsPresContext* presContext = PresContext();
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
aRenderingContext.SetFont(GetStyleFont()->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
nscoord defaultRuleThickness, axisHeight;
GetRuleThickness(aRenderingContext, fm, defaultRuleThickness);
GetAxisHeight(aRenderingContext, fm, axisHeight);
// by default, leave at least one-pixel padding at either end, or use
// lspace & rspace that may come from <mo> if we are an 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)
nsEmbellishData coreData;
GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
nscoord leftSpace = PR_MAX(onePixel, coreData.leftSpace);
nscoord rightSpace = PR_MAX(onePixel, coreData.rightSpace);
// see if the linethickness attribute is there
nsAutoString value;
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::linethickness_, value);
mLineRect.height = CalcLineThickness(presContext, mStyleContext, value,
onePixel, defaultRuleThickness);
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 (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
// C > T
numShift = numShift1;
denShift = denShift1;
}
else {
numShift = (0 < mLineRect.height) ? numShift2 : numShift3;
denShift = denShift2;
}
nscoord minClearance = 0;
nscoord actualClearance = 0;
nscoord actualRuleThickness = mLineRect.height;
if (0 == actualRuleThickness) {
// Rule 15c, App. G, TeXbook
// min clearance between numerator and denominator
minClearance = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
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 = (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) ?
// 3 * actualRuleThickness : actualRuleThickness;
//.........这里部分代码省略.........
示例10: PlaceSubScript
/* virtual */ nsresult
nsMathMLmunderFrame::Place(nsIRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize)
{
if ( NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(mEmbellishData.flags) &&
!NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) {
// place like subscript
return nsMathMLmsubFrame::PlaceSubScript(PresContext(),
aRenderingContext,
aPlaceOrigin,
aDesiredSize,
this, 0, nsPresContext::CSSPointsToAppUnits(0.5f));
}
////////////////////////////////////
// Get the children's desired sizes
nsBoundingMetrics bmBase, bmUnder;
nsHTMLReflowMetrics baseSize;
nsHTMLReflowMetrics underSize;
nsIFrame* underFrame = nsnull;
nsIFrame* baseFrame = mFrames.FirstChild();
if (baseFrame)
underFrame = baseFrame->GetNextSibling();
if (!baseFrame || !underFrame || underFrame->GetNextSibling()) {
// report an error, encourage people to get their markups in order
return ReflowError(aRenderingContext, aDesiredSize);
}
GetReflowAndBoundingMetricsFor(baseFrame, baseSize, bmBase);
GetReflowAndBoundingMetricsFor(underFrame, underSize, bmUnder);
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
////////////////////
// Place Children
aRenderingContext.SetFont(GetStyleFont()->mFont,
PresContext()->GetUserFontSet());
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
nscoord xHeight = 0;
fm->GetXHeight (xHeight);
nscoord ruleThickness;
GetRuleThickness (aRenderingContext, fm, ruleThickness);
// there are 2 different types of placement depending on
// whether we want an accented under or not
nscoord correction = 0;
GetItalicCorrection (bmBase, correction);
nscoord delta1 = 0; // gap between base and underscript
nscoord delta2 = 0; // extra space beneath underscript
if (!NS_MATHML_EMBELLISH_IS_ACCENTUNDER(mEmbellishData.flags)) {
// Rule 13a, App. G, TeXbook
nscoord bigOpSpacing2, bigOpSpacing4, bigOpSpacing5, dummy;
GetBigOpSpacings (fm,
dummy, bigOpSpacing2,
dummy, bigOpSpacing4,
bigOpSpacing5);
delta1 = NS_MAX(bigOpSpacing2, (bigOpSpacing4 - bmUnder.ascent));
delta2 = bigOpSpacing5;
}
else {
// No corresponding rule in TeXbook - we are on our own here
// XXX tune the gap delta between base and underscript
// Should we use Rule 10 like \underline does?
delta1 = ruleThickness + onePixel/2;
delta2 = ruleThickness;
}
// empty under?
if (!(bmUnder.ascent + bmUnder.descent)) delta1 = 0;
nscoord dxBase, dxUnder = 0;
// Width of non-spacing marks is zero so use left and right bearing.
nscoord underWidth = bmUnder.width;
if (!underWidth) {
underWidth = bmUnder.rightBearing - bmUnder.leftBearing;
dxUnder = -bmUnder.leftBearing;
}
nscoord maxWidth = NS_MAX(bmBase.width, underWidth);
if (NS_MATHML_EMBELLISH_IS_ACCENTUNDER(mEmbellishData.flags)) {
dxUnder += (maxWidth - underWidth)/2;
}
else {
dxUnder += -correction/2 + (maxWidth - underWidth)/2;
}
dxBase = (maxWidth - bmBase.width)/2;
mBoundingMetrics.width =
NS_MAX(dxBase + bmBase.width, dxUnder + bmUnder.width);
mBoundingMetrics.ascent = bmBase.ascent;
mBoundingMetrics.descent =
bmBase.descent + delta1 + bmUnder.ascent + bmUnder.descent;
//.........这里部分代码省略.........