Bug 1747922 - Replace MathML font constants with enum r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D134802
This commit is contained in:
Neia Finch 2021-12-30 00:34:27 +00:00
Родитель d8a3bebe12
Коммит b205467245
10 изменённых файлов: 89 добавлений и 85 удалений

Просмотреть файл

@ -634,25 +634,25 @@ void MathMLElement::MapMathMLAttributesInto(
"tailed",
"looped",
"stretched"};
static const int32_t values[MOZ_ARRAY_LENGTH(sizes)] = {
NS_MATHML_MATHVARIANT_NORMAL,
NS_MATHML_MATHVARIANT_BOLD,
NS_MATHML_MATHVARIANT_ITALIC,
NS_MATHML_MATHVARIANT_BOLD_ITALIC,
NS_MATHML_MATHVARIANT_SCRIPT,
NS_MATHML_MATHVARIANT_BOLD_SCRIPT,
NS_MATHML_MATHVARIANT_FRAKTUR,
NS_MATHML_MATHVARIANT_DOUBLE_STRUCK,
NS_MATHML_MATHVARIANT_BOLD_FRAKTUR,
NS_MATHML_MATHVARIANT_SANS_SERIF,
NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF,
NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC,
NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC,
NS_MATHML_MATHVARIANT_MONOSPACE,
NS_MATHML_MATHVARIANT_INITIAL,
NS_MATHML_MATHVARIANT_TAILED,
NS_MATHML_MATHVARIANT_LOOPED,
NS_MATHML_MATHVARIANT_STRETCHED};
static const StyleMathMLMathVariant values[MOZ_ARRAY_LENGTH(sizes)] = {
StyleMathMLMathVariant::Normal,
StyleMathMLMathVariant::Bold,
StyleMathMLMathVariant::Italic,
StyleMathMLMathVariant::BoldItalic,
StyleMathMLMathVariant::Script,
StyleMathMLMathVariant::BoldScript,
StyleMathMLMathVariant::Fraktur,
StyleMathMLMathVariant::DoubleStruck,
StyleMathMLMathVariant::BoldFraktur,
StyleMathMLMathVariant::SansSerif,
StyleMathMLMathVariant::BoldSansSerif,
StyleMathMLMathVariant::SansSerifItalic,
StyleMathMLMathVariant::SansSerifBoldItalic,
StyleMathMLMathVariant::Monospace,
StyleMathMLMathVariant::Initial,
StyleMathMLMathVariant::Tailed,
StyleMathMLMathVariant::Looped,
StyleMathMLMathVariant::Stretched};
for (uint32_t i = 0; i < ArrayLength(sizes); ++i) {
if (str.LowerCaseEqualsASCII(sizes[i])) {
aDecls.SetKeywordValue(eCSSProperty__moz_math_variant, values[i]);

Просмотреть файл

@ -170,7 +170,7 @@ static uint32_t MathvarMappingSearch(uint32_t aKey,
http://lists.w3.org/Archives/Public/www-math/2013Sep/0012.html and
https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
*/
static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
static uint32_t MathVariant(uint32_t aCh, StyleMathMLMathVariant aMathVar) {
uint32_t baseChar;
enum CharacterType {
kIsLatin,
@ -182,11 +182,11 @@ static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
int8_t multiplier;
if (aMathVar <= NS_MATHML_MATHVARIANT_NORMAL) {
if (aMathVar <= StyleMathMLMathVariant::Normal) {
// nothing to do here
return aCh;
}
if (aMathVar > NS_MATHML_MATHVARIANT_STRETCHED) {
if (aMathVar > StyleMathMLMathVariant::Stretched) {
NS_ASSERTION(false, "Illegal mathvariant value");
return aCh;
}
@ -197,25 +197,25 @@ static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
return aCh;
}
if (aCh == GREEK_LETTER_DIGAMMA) {
if (aMathVar == NS_MATHML_MATHVARIANT_BOLD) {
if (aMathVar == StyleMathMLMathVariant::Bold) {
return MATH_BOLD_CAPITAL_DIGAMMA;
}
return aCh;
}
if (aCh == GREEK_SMALL_LETTER_DIGAMMA) {
if (aMathVar == NS_MATHML_MATHVARIANT_BOLD) {
if (aMathVar == StyleMathMLMathVariant::Bold) {
return MATH_BOLD_SMALL_DIGAMMA;
}
return aCh;
}
if (aCh == LATIN_SMALL_LETTER_DOTLESS_I) {
if (aMathVar == NS_MATHML_MATHVARIANT_ITALIC) {
if (aMathVar == StyleMathMLMathVariant::Italic) {
return MATH_ITALIC_SMALL_DOTLESS_I;
}
return aCh;
}
if (aCh == LATIN_SMALL_LETTER_DOTLESS_J) {
if (aMathVar == NS_MATHML_MATHVARIANT_ITALIC) {
if (aMathVar == StyleMathMLMathVariant::Italic) {
return MATH_ITALIC_SMALL_DOTLESS_J;
}
return aCh;
@ -297,19 +297,19 @@ static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
// follows immediately after the end of the bold number range.
// multiplier represents the order of the sequences relative to the first
// one.
case NS_MATHML_MATHVARIANT_BOLD:
case StyleMathMLMathVariant::Bold:
multiplier = 0;
break;
case NS_MATHML_MATHVARIANT_DOUBLE_STRUCK:
case StyleMathMLMathVariant::DoubleStruck:
multiplier = 1;
break;
case NS_MATHML_MATHVARIANT_SANS_SERIF:
case StyleMathMLMathVariant::SansSerif:
multiplier = 2;
break;
case NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF:
case StyleMathMLMathVariant::BoldSansSerif:
multiplier = 3;
break;
case NS_MATHML_MATHVARIANT_MONOSPACE:
case StyleMathMLMathVariant::Monospace:
multiplier = 4;
break;
default:
@ -328,19 +328,19 @@ static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
MATH_BOLD_DIGIT_ZERO;
} else if (varType == kIsGreekish) {
switch (aMathVar) {
case NS_MATHML_MATHVARIANT_BOLD:
case StyleMathMLMathVariant::Bold:
multiplier = 0;
break;
case NS_MATHML_MATHVARIANT_ITALIC:
case StyleMathMLMathVariant::Italic:
multiplier = 1;
break;
case NS_MATHML_MATHVARIANT_BOLD_ITALIC:
case StyleMathMLMathVariant::BoldItalic:
multiplier = 2;
break;
case NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF:
case StyleMathMLMathVariant::BoldSansSerif:
multiplier = 3;
break;
case NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC:
case StyleMathMLMathVariant::SansSerifBoldItalic:
multiplier = 4;
break;
default:
@ -362,23 +362,23 @@ static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
* monotonic mapping to the unencoded characters, requiring the use of a
* lookup table.
*/
case NS_MATHML_MATHVARIANT_INITIAL:
case StyleMathMLMathVariant::Initial:
mapTable = gArabicInitialMapTable;
tableLength = ArrayLength(gArabicInitialMapTable);
break;
case NS_MATHML_MATHVARIANT_TAILED:
case StyleMathMLMathVariant::Tailed:
mapTable = gArabicTailedMapTable;
tableLength = ArrayLength(gArabicTailedMapTable);
break;
case NS_MATHML_MATHVARIANT_STRETCHED:
case StyleMathMLMathVariant::Stretched:
mapTable = gArabicStretchedMapTable;
tableLength = ArrayLength(gArabicStretchedMapTable);
break;
case NS_MATHML_MATHVARIANT_LOOPED:
case StyleMathMLMathVariant::Looped:
mapTable = gArabicLoopedMapTable;
tableLength = ArrayLength(gArabicLoopedMapTable);
break;
case NS_MATHML_MATHVARIANT_DOUBLE_STRUCK:
case StyleMathMLMathVariant::DoubleStruck:
mapTable = gArabicDoubleMapTable;
tableLength = ArrayLength(gArabicDoubleMapTable);
break;
@ -389,12 +389,12 @@ static uint32_t MathVariant(uint32_t aCh, uint8_t aMathVar) {
newChar = MathvarMappingSearch(aCh, mapTable, tableLength);
} else {
// Must be Latin
if (aMathVar > NS_MATHML_MATHVARIANT_MONOSPACE) {
if (aMathVar > StyleMathMLMathVariant::Monospace) {
// Latin doesn't support the Arabic mathvariants
return aCh;
}
multiplier = aMathVar - 2;
// This is possible because the values for NS_MATHML_MATHVARIANT_* are
multiplier = (uint8_t)aMathVar - 2;
// This is possible because the values for StyleMathMLMathVariant::* are
// chosen to coincide with the order in which the encoded mathvariant
// characters are located within their unicode block (less an offset to
// avoid _NONE and _NORMAL variants)
@ -513,7 +513,7 @@ void MathMLTextRunFactory::RebuildTextRun(
}
}
uint8_t mathVar = NS_MATHML_MATHVARIANT_NONE;
StyleMathMLMathVariant mathVar = StyleMathMLMathVariant::None;
bool doMathvariantStyling = true;
// Ensure it will be safe to call FindFontForChar in the loop below.
@ -523,7 +523,7 @@ void MathMLTextRunFactory::RebuildTextRun(
int extraChars = 0;
mathVar = styles[i]->mMathVariant;
if (singleCharMI && mathVar == NS_MATHML_MATHVARIANT_NONE) {
if (singleCharMI && mathVar == StyleMathMLMathVariant::None) {
// 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
@ -539,7 +539,7 @@ void MathMLTextRunFactory::RebuildTextRun(
font.style = FontSlantStyle::Normal();
font.weight = FontWeight::Normal();
} else {
mathVar = NS_MATHML_MATHVARIANT_ITALIC;
mathVar = StyleMathMLMathVariant::Italic;
}
}
@ -549,9 +549,9 @@ void MathMLTextRunFactory::RebuildTextRun(
}
uint32_t ch2 = MathVariant(ch, mathVar);
if (mathVar == NS_MATHML_MATHVARIANT_BOLD ||
mathVar == NS_MATHML_MATHVARIANT_BOLD_ITALIC ||
mathVar == NS_MATHML_MATHVARIANT_ITALIC) {
if (mathVar == StyleMathMLMathVariant::Bold ||
mathVar == StyleMathMLMathVariant::BoldItalic ||
mathVar == StyleMathMLMathVariant::Italic) {
if (ch == ch2 && ch != 0x20 && ch != 0xA0) {
// Don't apply the CSS style if a character cannot be
// transformed. There is an exception for whitespace as it is both
@ -614,17 +614,18 @@ void MathMLTextRunFactory::RebuildTextRun(
RefPtr<gfxTextRun> cachedChild;
gfxTextRun* child;
if (mathVar == NS_MATHML_MATHVARIANT_BOLD && doMathvariantStyling) {
if (mathVar == StyleMathMLMathVariant::Bold && doMathvariantStyling) {
font.style = FontSlantStyle::Normal();
font.weight = FontWeight::Bold();
} else if (mathVar == NS_MATHML_MATHVARIANT_ITALIC && doMathvariantStyling) {
} else if (mathVar == StyleMathMLMathVariant::Italic &&
doMathvariantStyling) {
font.style = FontSlantStyle::Italic();
font.weight = FontWeight::Normal();
} else if (mathVar == NS_MATHML_MATHVARIANT_BOLD_ITALIC &&
} else if (mathVar == StyleMathMLMathVariant::BoldItalic &&
doMathvariantStyling) {
font.style = FontSlantStyle::Italic();
font.weight = FontWeight::Bold();
} else if (mathVar != NS_MATHML_MATHVARIANT_NONE) {
} else if (mathVar != StyleMathMLMathVariant::None) {
// Mathvariant overrides fontstyle and fontweight
// Need to check to see if mathvariant is actually applied as this function
// is used for other purposes.

Просмотреть файл

@ -2250,8 +2250,8 @@ already_AddRefed<gfxTextRun> BuildTextRunsScanner::BuildTextRunForFrames(
}
fontStyle = f->StyleFont();
nsIFrame* parent = mLineContainer->GetParent();
if (NS_MATHML_MATHVARIANT_NONE != fontStyle->mMathVariant) {
if (NS_MATHML_MATHVARIANT_NORMAL != fontStyle->mMathVariant) {
if (StyleMathMLMathVariant::None != fontStyle->mMathVariant) {
if (StyleMathMLMathVariant::Normal != fontStyle->mMathVariant) {
anyMathMLStyling = true;
}
} else if (mLineContainer->HasAnyStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI)) {

Просмотреть файл

@ -35,7 +35,7 @@ struct nsTransformedCharStyle final {
RefPtr<nsPresContext> mPresContext;
float mScriptSizeMultiplier;
mozilla::StyleTextTransform mTextTransform;
uint8_t mMathVariant;
mozilla::StyleMathMLMathVariant mMathVariant;
bool mExplicitLanguage;
bool mForceNonFullWidth = false;
bool mMaskPassword = false;

Просмотреть файл

@ -37,14 +37,14 @@ eMathMLFrameType nsMathMLTokenFrame::GetMathMLFrameType() {
return eMathMLFrameType_Ordinary;
}
uint8_t mathVariant = StyleFont()->mMathVariant;
if ((mathVariant == NS_MATHML_MATHVARIANT_NONE &&
StyleMathMLMathVariant mathVariant = StyleFont()->mMathVariant;
if ((mathVariant == StyleMathMLMathVariant::None &&
(StyleFont()->mFont.style == FontSlantStyle::Italic() ||
HasAnyStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI))) ||
mathVariant == NS_MATHML_MATHVARIANT_ITALIC ||
mathVariant == NS_MATHML_MATHVARIANT_BOLD_ITALIC ||
mathVariant == NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC ||
mathVariant == NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC) {
mathVariant == StyleMathMLMathVariant::Italic ||
mathVariant == StyleMathMLMathVariant::BoldItalic ||
mathVariant == StyleMathMLMathVariant::SansSerifItalic ||
mathVariant == StyleMathMLMathVariant::SansSerifBoldItalic) {
return eMathMLFrameType_ItalicIdentifier;
}
return eMathMLFrameType_UprightIdentifier;

Просмотреть файл

@ -135,6 +135,7 @@ rusty-enums = [
"mozilla::StyleStrokeLinecap",
"mozilla::StyleStrokeLinejoin",
"mozilla::StyleFlexWrap",
"mozilla::StyleMathMLMathVariant",
"mozilla::StyleTextDecorationSkipInk",
"mozilla::StyleTextDecorationLength",
"mozilla::StyleMaskType",

Просмотреть файл

@ -384,25 +384,27 @@ enum class StyleGridTrackBreadth : uint8_t {
#define NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT 8
// See nsStyleFont
#define NS_MATHML_MATHVARIANT_NONE 0
#define NS_MATHML_MATHVARIANT_NORMAL 1
#define NS_MATHML_MATHVARIANT_BOLD 2
#define NS_MATHML_MATHVARIANT_ITALIC 3
#define NS_MATHML_MATHVARIANT_BOLD_ITALIC 4
#define NS_MATHML_MATHVARIANT_SCRIPT 5
#define NS_MATHML_MATHVARIANT_BOLD_SCRIPT 6
#define NS_MATHML_MATHVARIANT_FRAKTUR 7
#define NS_MATHML_MATHVARIANT_DOUBLE_STRUCK 8
#define NS_MATHML_MATHVARIANT_BOLD_FRAKTUR 9
#define NS_MATHML_MATHVARIANT_SANS_SERIF 10
#define NS_MATHML_MATHVARIANT_BOLD_SANS_SERIF 11
#define NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC 12
#define NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC 13
#define NS_MATHML_MATHVARIANT_MONOSPACE 14
#define NS_MATHML_MATHVARIANT_INITIAL 15
#define NS_MATHML_MATHVARIANT_TAILED 16
#define NS_MATHML_MATHVARIANT_LOOPED 17
#define NS_MATHML_MATHVARIANT_STRETCHED 18
enum class StyleMathMLMathVariant : uint8_t {
None = 0,
Normal = 1,
Bold = 2,
Italic = 3,
BoldItalic = 4,
Script = 5,
BoldScript = 6,
Fraktur = 7,
DoubleStruck = 8,
BoldFraktur = 9,
SansSerif = 10,
BoldSansSerif = 11,
SansSerifItalic = 12,
SansSerifBoldItalic = 13,
Monospace = 14,
Initial = 15,
Tailed = 16,
Looped = 17,
Stretched = 18,
};
// See nsStyleFont::mMathStyle
#define NS_STYLE_MATH_STYLE_COMPACT 0

Просмотреть файл

@ -228,7 +228,7 @@ nsStyleFont::nsStyleFont(const Document& aDocument)
mFontSizeOffset{0},
mFontSizeKeyword(StyleFontSizeKeyword::Medium),
mMathDepth(0),
mMathVariant(NS_MATHML_MATHVARIANT_NONE),
mMathVariant(StyleMathMLMathVariant::None),
mMathStyle(NS_STYLE_MATH_STYLE_NORMAL),
mMinFontSizeRatio(100), // 100%
mExplicitLanguage(false),

Просмотреть файл

@ -103,7 +103,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
// math-depth support (used for MathML scriptlevel)
int8_t mMathDepth;
// MathML mathvariant support
uint8_t mMathVariant;
mozilla::StyleMathMLMathVariant mMathVariant;
// math-style support (used for MathML displaystyle)
uint8_t mMathStyle;

Просмотреть файл

@ -260,7 +260,7 @@ ${helpers.single_keyword(
bold-sans-serif sans-serif-italic sans-serif-bold-italic
monospace initial tailed looped stretched""",
engines="gecko",
gecko_constant_prefix="NS_MATHML_MATHVARIANT",
gecko_enum_prefix="StyleMathMLMathVariant",
gecko_ffi_name="mMathVariant",
spec="Internal (not web-exposed)",
animation_value_type="none",