diff --git a/layout/generic/MathMLTextRunFactory.cpp b/layout/generic/MathMLTextRunFactory.cpp index 8b512a7aa19..30853ca1149 100644 --- a/layout/generic/MathMLTextRunFactory.cpp +++ b/layout/generic/MathMLTextRunFactory.cpp @@ -596,7 +596,23 @@ MathMLTextRunFactory::RebuildTextRun(nsTransformedTextRun* aTextRun, mathVar = styleContext->StyleFont()->mMathVariant; if (singleCharMI && mathVar == NS_MATHML_MATHVARIANT_NONE) { - mathVar = NS_MATHML_MATHVARIANT_ITALIC; + // If the user has explicitly set a non-default value for fontstyle or + // fontweight, the italic mathvariant behaviour of is disabled + // This overrides the initial values specified in fontStyle, to avoid + // inconsistencies in which attributes allow CSS changes and which do not. + if (mFlags & MATH_FONT_WEIGHT_BOLD) { + fontStyle.weight = NS_FONT_WEIGHT_BOLD; + if (mFlags & MATH_FONT_STYLING_NORMAL) { + fontStyle.style = NS_FONT_STYLE_NORMAL; + } else { + fontStyle.style = NS_FONT_STYLE_ITALIC; + } + } else if (mFlags & MATH_FONT_STYLING_NORMAL) { + fontStyle.style = NS_FONT_STYLE_NORMAL; + fontStyle.weight = NS_FONT_WEIGHT_NORMAL; + } else { + mathVar = NS_MATHML_MATHVARIANT_ITALIC; + } } uint32_t ch = str[i]; diff --git a/layout/generic/MathMLTextRunFactory.h b/layout/generic/MathMLTextRunFactory.h index addd242d4fd..91cc262591e 100644 --- a/layout/generic/MathMLTextRunFactory.h +++ b/layout/generic/MathMLTextRunFactory.h @@ -14,14 +14,22 @@ class MathMLTextRunFactory : public nsTransformingTextRunFactory { public: MathMLTextRunFactory(nsTransformingTextRunFactory* aInnerTransformingTextRunFactory, - uint8_t aSSTYScriptLevel) + uint32_t aFlags, uint8_t aSSTYScriptLevel) : mInnerTransformingTextRunFactory(aInnerTransformingTextRunFactory), + mFlags(aFlags), mSSTYScriptLevel(aSSTYScriptLevel) {} virtual void RebuildTextRun(nsTransformedTextRun* aTextRun, gfxContext* aRefContext) MOZ_OVERRIDE; + enum { + // Style effects which may override single character behaviour + MATH_FONT_STYLING_NORMAL = 0x1, // fontstyle="normal" has been set. + MATH_FONT_WEIGHT_BOLD = 0x2, // fontweight="bold" has been set. + }; + protected: nsAutoPtr mInnerTransformingTextRunFactory; + uint32_t mFlags; uint8_t mSSTYScriptLevel; }; diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 3635111d8c2..7458d028bb1 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -1821,6 +1821,7 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer) bool anyTextTransformStyle = false; bool anyMathMLStyling = false; uint8_t sstyScriptLevel = 0; + uint32_t mathFlags = 0; uint32_t textFlags = nsTextFrameUtils::TEXT_NO_BREAKS; if (mCurrentRunContextInfo & nsTextFrameUtils::INCOMING_WHITESPACE) { @@ -1895,13 +1896,33 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer) textFlags |= gfxTextRunFactory::TEXT_ENABLE_SPACING; } fontStyle = f->StyleFont(); + nsIFrame* parent = mLineContainer->GetParent(); if (NS_MATHML_MATHVARIANT_NONE != fontStyle->mMathVariant) { anyMathMLStyling = true; } else if (mLineContainer->GetStateBits() & NS_FRAME_IS_IN_SINGLE_CHAR_MI) { textFlags |= nsTextFrameUtils::TEXT_IS_SINGLE_CHAR_MI; anyMathMLStyling = true; + // Test for fontstyle attribute as StyleFont() may not be accurate + // To be consistent in terms of ignoring CSS style changes, fontweight + // gets checked too. + if (parent) { + nsIContent* content = parent->GetContent(); + if (content) { + if (content->AttrValueIs(kNameSpaceID_None, + nsGkAtoms::fontstyle_, + NS_LITERAL_STRING("normal"), + eCaseMatters)) { + mathFlags |= MathMLTextRunFactory::MATH_FONT_STYLING_NORMAL; + } + if (content->AttrValueIs(kNameSpaceID_None, + nsGkAtoms::fontweight_, + NS_LITERAL_STRING("bold"), + eCaseMatters)) { + mathFlags |= MathMLTextRunFactory::MATH_FONT_WEIGHT_BOLD; + } + } + } } - nsIFrame* parent = mLineContainer->GetParent(); if (mLineContainer->HasAnyStateBits(TEXT_IS_IN_TOKEN_MATHML)) { // All MathML tokens except use 'math' script. if (!(parent && parent->GetContent() && @@ -2065,7 +2086,8 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer) } if (anyMathMLStyling) { transformingFactory = - new MathMLTextRunFactory(transformingFactory.forget(), sstyScriptLevel); + new MathMLTextRunFactory(transformingFactory.forget(), mathFlags, + sstyScriptLevel); } nsTArray styles; if (transformingFactory) { diff --git a/layout/reftests/mathml/mathvariant-3-ref.html b/layout/reftests/mathml/mathvariant-3-ref.html index ed7d05d55e4..7a7de4b82ad 100644 --- a/layout/reftests/mathml/mathvariant-3-ref.html +++ b/layout/reftests/mathml/mathvariant-3-ref.html @@ -1,7 +1,7 @@ - Test math-variant overrides fontstyle and fontweight + Test math-variant interaction with fontstyle and fontweight @@ -10,5 +10,35 @@ A +

+ + A + +

+

+ + A + +

+

+ + A + +

+

+ + A + +

+

+ + A + +

+

+ + A + +

diff --git a/layout/reftests/mathml/mathvariant-3.html b/layout/reftests/mathml/mathvariant-3.html index 7139c7df03b..b7c7a872561 100644 --- a/layout/reftests/mathml/mathvariant-3.html +++ b/layout/reftests/mathml/mathvariant-3.html @@ -1,7 +1,7 @@ - Test math-variant overrides fontstyle and fontweight + Test math-variant interaction with fontstyle and fontweight @@ -10,6 +10,36 @@ A +

+ + A + +

+

+ + A + +

+

+ + A + +

+

+ + A + +

+

+ + A + +

+

+ + A + +