Bug 1027354 - Fix fontweight and fontstyle on single char <mi>. r=roc

This commit is contained in:
James Kitchener 2014-06-25 05:20:00 -04:00
parent f7cc46ac37
commit 522cf7fbea
5 changed files with 112 additions and 6 deletions

View File

@ -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 <mi> 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];

View File

@ -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 <mi> behaviour
MATH_FONT_STYLING_NORMAL = 0x1, // fontstyle="normal" has been set.
MATH_FONT_WEIGHT_BOLD = 0x2, // fontweight="bold" has been set.
};
protected:
nsAutoPtr<nsTransformingTextRunFactory> mInnerTransformingTextRunFactory;
uint32_t mFlags;
uint8_t mSSTYScriptLevel;
};

View File

@ -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 <mtext> 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<nsStyleContext*> styles;
if (transformingFactory) {

View File

@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Test math-variant overrides fontstyle and fontweight</title>
<title>Test math-variant interaction with fontstyle and fontweight</title>
</head>
<body>
<math>
@ -10,5 +10,35 @@
<mtext>A</mtext>
</mrow>
</math>
<p>
<math>
<mn>A</mn>
</math>
</p>
<p>
<math>
<mn fontweight="bold">A</mn>
</math>
</p>
<p>
<math>
<mn fontweight="bold" fontstyle="italic">A</mn>
</math>
</p>
<p>
<math>
<mn fontweight="bold" fontstyle="italic">A</mn>
</math>
</p>
<p>
<math>
<mn fontweight="bold" fontstyle="italic">A</mn>
</math>
</p>
<p>
<math>
<mn>A</mn>
</math>
</p>
</body>
</html>

View File

@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Test math-variant overrides fontstyle and fontweight</title>
<title>Test math-variant interaction with fontstyle and fontweight</title>
</head>
<body>
<math>
@ -10,6 +10,36 @@
<mtext mathvariant="normal" fontstyle="italic">A</mtext>
</mrow>
</math>
<p>
<math>
<mi fontstyle="normal">A</mi>
</math>
</p>
<p>
<math>
<mi fontstyle="normal" fontweight="bold">A</mi>
</math>
</p>
<p>
<math>
<mi fontweight="bold">A</mi>
</math>
</p>
<p>
<math>
<mi fontweight="bold" fontstyle="italic">A</mi>
</math>
</p>
<p>
<math>
<mi fontweight="bold" style="font-style:normal">A</mi>
</math>
</p>
<p>
<math>
<mi fontstyle="normal" style="font-weight:bold">A</mi>
</math>
</p>
</body>
</html>