Bug 1002526 - Part 2 - Pass the font inflation parameter to nsMathMLChar. b=1002526. r=karl

This commit is contained in:
Frédéric Wang 2014-10-25 08:30:00 +02:00
parent ce3221837c
commit 7bd964a4d4
7 changed files with 68 additions and 33 deletions

View File

@ -51,12 +51,13 @@ static const float kLargeOpFactor = float(M_SQRT2);
static const float kIntegralFactor = 2.0;
static void
NormalizeDefaultFont(nsFont& aFont)
NormalizeDefaultFont(nsFont& aFont, float aFontSizeInflation)
{
if (aFont.fontlist.GetDefaultFontType() != eFamily_none) {
aFont.fontlist.Append(FontFamilyName(aFont.fontlist.GetDefaultFontType()));
aFont.fontlist.SetDefaultFontType(eFamily_none);
}
aFont.size = NSToCoordRound(aFont.size * aFontSizeInflation);
}
// -----------------------------------------------------------------------------
@ -1041,6 +1042,7 @@ public:
StretchEnumContext(nsMathMLChar* aChar,
nsPresContext* aPresContext,
gfxContext* aThebesContext,
float aFontSizeInflation,
nsStretchDirection aStretchDirection,
nscoord aTargetSize,
uint32_t aStretchHint,
@ -1050,6 +1052,7 @@ public:
: mChar(aChar),
mPresContext(aPresContext),
mThebesContext(aThebesContext),
mFontSizeInflation(aFontSizeInflation),
mDirection(aStretchDirection),
mTargetSize(aTargetSize),
mStretchHint(aStretchHint),
@ -1073,6 +1076,7 @@ private:
nsMathMLChar* mChar;
nsPresContext* mPresContext;
gfxContext* mThebesContext;
float mFontSizeInflation;
const nsStretchDirection mDirection;
const nscoord mTargetSize;
const uint32_t mStretchHint;
@ -1102,7 +1106,7 @@ StretchEnumContext::TryVariants(nsGlyphTable* aGlyphTable,
// Use our stretchy style context now that stretching is in progress
nsStyleContext *sc = mChar->mStyleContext;
nsFont font = sc->StyleFont()->mFont;
NormalizeDefaultFont(font);
NormalizeDefaultFont(font, mFontSizeInflation);
bool isVertical = (mDirection == NS_STRETCH_DIRECTION_VERTICAL);
nscoord oneDevPixel = mPresContext->AppUnitsPerDevPixel();
@ -1252,7 +1256,7 @@ nsMathMLChar::StretchEnumContext::TryParts(nsGlyphTable* aGlyphTable,
{
// Use our stretchy style context now that stretching is in progress
nsFont font = mChar->mStyleContext->StyleFont()->mFont;
NormalizeDefaultFont(font);
NormalizeDefaultFont(font, mFontSizeInflation);
// Compute the bounding metrics of all partial glyphs
nsAutoPtr<gfxTextRun> textRun[4];
@ -1430,7 +1434,7 @@ nsMathMLChar::StretchEnumContext::EnumCallback(const FontFamilyName& aFamily,
// We test with the kNullGlyph
nsStyleContext *sc = context->mChar->mStyleContext;
nsFont font = sc->StyleFont()->mFont;
NormalizeDefaultFont(font);
NormalizeDefaultFont(font, context->mFontSizeInflation);
nsRefPtr<gfxFontGroup> fontGroup;
FontFamilyList family;
family.Append(unquotedFamilyName);
@ -1512,6 +1516,7 @@ InsertMathFallbacks(FontFamilyList& aFamilyList,
nsresult
nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
gfxContext* aThebesContext,
float aFontSizeInflation,
nsStretchDirection& aStretchDirection,
const nsBoundingMetrics& aContainerSize,
nsBoundingMetrics& aDesiredStretchSize,
@ -1530,7 +1535,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
// mStyleContext is a leaf context used only when stretching happens.
// For the base size, the default font should come from the parent context
nsFont font = mStyleContext->GetParent()->StyleFont()->mFont;
NormalizeDefaultFont(font);
NormalizeDefaultFont(font, aFontSizeInflation);
nsRefPtr<nsFontMetrics> fm;
aPresContext->DeviceContext()->
@ -1644,7 +1649,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
if (!done) { // normal case
// Use the css font-family but add preferred fallback fonts.
font = mStyleContext->StyleFont()->mFont;
NormalizeDefaultFont(font);
NormalizeDefaultFont(font, aFontSizeInflation);
// really shouldn't be doing things this way but for now
// insert fallbacks into the list
@ -1660,6 +1665,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
NS_ConvertUTF16toUTF8(fontlistStr).get(), mData[0], mData[0]&0x00FF);
#endif
StretchEnumContext enumData(this, aPresContext, aThebesContext,
aFontSizeInflation,
aStretchDirection, targetSize, aStretchHint,
aDesiredStretchSize, font.fontlist, glyphFound);
enumData.mTryParts = !largeopOnly;
@ -1759,6 +1765,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
nsresult
nsMathMLChar::Stretch(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
float aFontSizeInflation,
nsStretchDirection aStretchDirection,
const nsBoundingMetrics& aContainerSize,
nsBoundingMetrics& aDesiredStretchSize,
@ -1775,7 +1782,8 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext,
mScaleY = mScaleX = 1.0;
mDirection = aStretchDirection;
nsresult rv =
StretchInternal(aPresContext, aRenderingContext.ThebesContext(), mDirection,
StretchInternal(aPresContext, aRenderingContext.ThebesContext(),
aFontSizeInflation, mDirection,
aContainerSize, aDesiredStretchSize, aStretchHint);
// Record the metrics
@ -1799,6 +1807,7 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext,
nscoord
nsMathMLChar::GetMaxWidth(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
float aFontSizeInflation,
uint32_t aStretchHint,
float aMaxSize, bool aMaxSizeIsAbsolute)
{
@ -1806,7 +1815,8 @@ nsMathMLChar::GetMaxWidth(nsPresContext* aPresContext,
nsStretchDirection direction = NS_STRETCH_DIRECTION_VERTICAL;
const nsBoundingMetrics container; // zero target size
StretchInternal(aPresContext, aRenderingContext.ThebesContext(), direction,
StretchInternal(aPresContext, aRenderingContext.ThebesContext(),
aFontSizeInflation, direction,
container, bm, aStretchHint | NS_STRETCH_MAXWIDTH);
return std::max(bm.width, bm.rightBearing) - std::min(0, bm.leftBearing);

View File

@ -114,6 +114,7 @@ public:
nsresult
Stretch(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
float aFontSizeInflation,
nsStretchDirection aStretchDirection,
const nsBoundingMetrics& aContainerSize,
nsBoundingMetrics& aDesiredStretchSize,
@ -167,6 +168,7 @@ public:
nscoord
GetMaxWidth(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
float aFontSizeInflation,
uint32_t aStretchHint = NS_STRETCH_NORMAL,
float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY,
// Perhaps just nsOperatorFlags aFlags.
@ -245,6 +247,7 @@ private:
nsresult
StretchInternal(nsPresContext* aPresContext,
gfxContext* aThebesContext,
float aFontSizeInflation,
nsStretchDirection& aStretchDirection,
const nsBoundingMetrics& aContainerSize,
nsBoundingMetrics& aDesiredStretchSize,

View File

@ -343,10 +343,10 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext,
// Thickness of bars and font metrics
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
nsLayoutUtils::
FontSizeInflationFor(this));
fontSizeInflation);
GetRuleThickness(aRenderingContext, fm, mRuleThickness);
if (mRuleThickness < onePixel) {
mRuleThickness = onePixel;
@ -484,7 +484,7 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext,
if (IsToDraw(NOTATION_LONGDIV)) {
if (aWidthOnly) {
nscoord longdiv_width = mMathMLChar[mLongDivCharIndex].
GetMaxWidth(PresContext(), aRenderingContext);
GetMaxWidth(PresContext(), aRenderingContext, fontSizeInflation);
// Update horizontal parameters
dx_left = std::max(dx_left, longdiv_width);
@ -497,6 +497,7 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext,
// height(longdiv) should be >= height(base) + psi + mRuleThickness
mMathMLChar[mLongDivCharIndex].Stretch(PresContext(), aRenderingContext,
fontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
contSize, bmLongdivChar,
NS_STRETCH_LARGER, false);
@ -525,7 +526,7 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext,
if (aWidthOnly) {
nscoord radical_width = mMathMLChar[mRadicalCharIndex].
GetMaxWidth(PresContext(), aRenderingContext);
GetMaxWidth(PresContext(), aRenderingContext, fontSizeInflation);
// Update horizontal parameters
*dx_leading = std::max(*dx_leading, radical_width);
@ -538,6 +539,7 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext,
// height(radical) should be >= height(base) + psi + mRadicalRuleThickness
mMathMLChar[mRadicalCharIndex].Stretch(PresContext(), aRenderingContext,
fontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
contSize, bmRadicalChar,
NS_STRETCH_LARGER,

View File

@ -193,6 +193,7 @@ direction, this has no impact on overall appearance.
static void
ApplyUnstretchedMetrics(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
nsBoundingMetrics& aMetrics,
bool aIsRTL)
@ -200,6 +201,7 @@ ApplyUnstretchedMetrics(nsPresContext* aPresContext,
if (aMathMLChar && 0 < aMathMLChar->Length()) {
nsBoundingMetrics charSize;
aMathMLChar->Stretch(aPresContext, aRenderingContext,
aFontSizeInflation,
NS_STRETCH_DIRECTION_DEFAULT,
aMetrics, // size is unimportant as we aren't stretching
charSize, NS_STRETCH_NONE, aIsRTL);
@ -219,10 +221,10 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext,
int32_t i;
const nsStyleFont* font = StyleFont();
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
nsLayoutUtils::
FontSizeInflationFor(this));
fontSizeInflation);
nscoord axisHeight, em;
GetAxisHeight(*aReflowState.rendContext, fm, axisHeight);
GetEmHeight(fm, em);
@ -320,13 +322,16 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext,
// To achieve a minimum size of "1", the container should be enlarged by the
// unstretched metrics of the fences and separators.
ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext, mOpenChar,
ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext,
fontSizeInflation, mOpenChar,
containerSize, isRTL);
for (i = 0; i < mSeparatorsCount; i++) {
ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext,
&mSeparatorsChar[i], containerSize, isRTL);
fontSizeInflation, &mSeparatorsChar[i],
containerSize, isRTL);
}
ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext, mCloseChar,
ApplyUnstretchedMetrics(aPresContext, *aReflowState.rendContext,
fontSizeInflation, mCloseChar,
containerSize, isRTL);
//////////////////////////////////////////
@ -341,19 +346,22 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext,
/////////////////
// opening fence ...
ReflowChar(aPresContext, *aReflowState.rendContext, *fm, mOpenChar,
ReflowChar(aPresContext, *aReflowState.rendContext, *fm,
fontSizeInflation, mOpenChar,
NS_MATHML_OPERATOR_FORM_PREFIX, font->mScriptLevel,
axisHeight, leading, em, containerSize, ascent, descent, isRTL);
/////////////////
// separators ...
for (i = 0; i < mSeparatorsCount; i++) {
ReflowChar(aPresContext, *aReflowState.rendContext, *fm, &mSeparatorsChar[i],
ReflowChar(aPresContext, *aReflowState.rendContext, *fm,
fontSizeInflation, &mSeparatorsChar[i],
NS_MATHML_OPERATOR_FORM_INFIX, font->mScriptLevel,
axisHeight, leading, em, containerSize, ascent, descent, isRTL);
}
/////////////////
// closing fence ...
ReflowChar(aPresContext, *aReflowState.rendContext, *fm, mCloseChar,
ReflowChar(aPresContext, *aReflowState.rendContext, *fm,
fontSizeInflation, mCloseChar,
NS_MATHML_OPERATOR_FORM_POSTFIX, font->mScriptLevel,
axisHeight, leading, em, containerSize, ascent, descent, isRTL);
@ -472,6 +480,7 @@ GetCharSpacing(nsMathMLChar* aMathMLChar,
nsMathMLmfencedFrame::ReflowChar(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsFontMetrics& aFontMetrics,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
nsOperatorFlags aForm,
int32_t aScriptLevel,
@ -491,6 +500,7 @@ nsMathMLmfencedFrame::ReflowChar(nsPresContext* aPresContext,
// stretch the char to the appropriate height if it is not big enough.
nsBoundingMetrics charSize;
nsresult res = aMathMLChar->Stretch(aPresContext, aRenderingContext,
aFontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
aContainerSize, charSize,
NS_STRETCH_NORMAL, aRTL);
@ -572,12 +582,14 @@ nsMathMLmfencedFrame::PlaceChar(nsMathMLChar* aMathMLChar,
static nscoord
GetMaxCharWidth(nsPresContext* aPresContext,
nsRenderingContext* aRenderingContext,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
nsOperatorFlags aForm,
int32_t aScriptLevel,
nscoord em)
{
nscoord width = aMathMLChar->GetMaxWidth(aPresContext, *aRenderingContext);
nscoord width = aMathMLChar->GetMaxWidth(aPresContext, *aRenderingContext,
aFontSizeInflation);
if (0 < aMathMLChar->Length()) {
nscoord leftSpace;
@ -597,16 +609,17 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(nsRenderingContext* aRenderingCon
nsPresContext* presContext = PresContext();
const nsStyleFont* font = StyleFont();
float fontSizeInflation = nsLayoutUtils:: FontSizeInflationFor(this);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
nsLayoutUtils::
FontSizeInflationFor(this));
fontSizeInflation);
nscoord em;
GetEmHeight(fm, em);
if (mOpenChar) {
width +=
GetMaxCharWidth(presContext, aRenderingContext, mOpenChar,
GetMaxCharWidth(presContext, aRenderingContext,
fontSizeInflation, mOpenChar,
NS_MATHML_OPERATOR_FORM_PREFIX, font->mScriptLevel, em);
}
@ -621,7 +634,8 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(nsRenderingContext* aRenderingCon
if (i < mSeparatorsCount) {
width +=
GetMaxCharWidth(presContext, aRenderingContext, &mSeparatorsChar[i],
GetMaxCharWidth(presContext, aRenderingContext,
fontSizeInflation, &mSeparatorsChar[i],
NS_MATHML_OPERATOR_FORM_INFIX, font->mScriptLevel, em);
}
i++;
@ -631,7 +645,8 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(nsRenderingContext* aRenderingCon
if (mCloseChar) {
width +=
GetMaxCharWidth(presContext, aRenderingContext, mCloseChar,
GetMaxCharWidth(presContext, aRenderingContext,
fontSizeInflation, mCloseChar,
NS_MATHML_OPERATOR_FORM_POSTFIX, font->mScriptLevel, em);
}

View File

@ -66,6 +66,7 @@ public:
ReflowChar(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsFontMetrics& aFontMetrics,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
nsOperatorFlags aForm,
int32_t aScriptLevel,

View File

@ -615,10 +615,10 @@ nsMathMLmoFrame::Stretch(nsRenderingContext& aRenderingContext,
nsIFrame* firstChild = mFrames.FirstChild();
// get the axis height;
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
nsLayoutUtils::
FontSizeInflationFor(this));
fontSizeInflation);
nscoord axisHeight, height;
GetAxisHeight(aRenderingContext, fm, axisHeight);
@ -746,6 +746,7 @@ nsMathMLmoFrame::Stretch(nsRenderingContext& aRenderingContext,
// let the MathMLChar stretch itself...
nsresult res = mMathMLChar.Stretch(PresContext(), aRenderingContext,
fontSizeInflation,
aStretchDirection, container, charSize,
stretchHint,
StyleVisibility()->mDirection);
@ -988,6 +989,7 @@ nsMathMLmoFrame::GetIntrinsicISizeMetrics(nsRenderingContext *aRenderingContext,
StyleFont());
aDesiredSize.Width() = mMathMLChar.
GetMaxWidth(PresContext(), *aRenderingContext,
nsLayoutUtils::FontSizeInflationFor(this),
stretchHint, mMaxSize,
NS_MATHML_OPERATOR_MAXSIZE_IS_ABSOLUTE(mFlags));
}

View File

@ -224,9 +224,9 @@ nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
// Prepare the radical symbol and the overline bar
nsRefPtr<nsFontMetrics> fm;
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
nsLayoutUtils::
FontSizeInflationFor(this));
fontSizeInflation);
nscoord ruleThickness, leading, psi;
GetRadicalParameters(fm, StyleFont()->mMathDisplay ==
@ -260,6 +260,7 @@ nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
// height(radical) should be >= height(base) + psi + ruleThickness
nsBoundingMetrics radicalSize;
mSqrChar.Stretch(aPresContext, renderingContext,
fontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
contSize, radicalSize,
NS_STRETCH_LARGER,
@ -367,19 +368,20 @@ nsMathMLmrootFrame::GetIntrinsicISizeMetrics(nsRenderingContext* aRenderingConte
return;
}
float fontSizeInflation = nsLayoutUtils::FontSizeInflationFor(this);
nscoord baseWidth =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, baseFrame,
nsLayoutUtils::PREF_ISIZE);
nscoord indexWidth =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, indexFrame,
nsLayoutUtils::PREF_ISIZE);
nscoord sqrWidth = mSqrChar.GetMaxWidth(PresContext(), *aRenderingContext);
nscoord sqrWidth = mSqrChar.GetMaxWidth(PresContext(), *aRenderingContext,
fontSizeInflation);
nscoord dxSqr;
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
nsLayoutUtils::
FontSizeInflationFor(this));
fontSizeInflation);
GetRadicalXOffsets(indexWidth, sqrWidth, fm, nullptr, &dxSqr);
nscoord width = dxSqr + sqrWidth + baseWidth;