Math: use the new MathFontInfo class to determine HTML and MathML attributes.

This commit is contained in:
Thibaut Cuvelier 2024-10-29 04:12:29 +01:00
parent 9a81bb36f4
commit 78ce5ebc45

View File

@ -299,35 +299,11 @@ void InsetMathFont::htmlize(HtmlStream & os) const
// FIXME These are not quite right, because they do not nest // FIXME These are not quite right, because they do not nest
// correctly. A proper fix would presumably involve tracking // correctly. A proper fix would presumably involve tracking
// the fonts already in effect. // the fonts already in effect.
std::string variant; const MathFontInfo font = MathFontInfo::fromMacro(key_->name);
docstring const & tag = key_->name; const std::string span_class = font.toHTMLSpanClass();
if (tag == "mathnormal" || tag == "mathrm"
|| tag == "text" || tag == "textnormal"
|| tag == "textrm" || tag == "textup"
|| tag == "textmd")
variant = "normal";
else if (tag == "frak" || tag == "mathfrak")
variant = "fraktur";
else if (tag == "mathbf" || tag == "textbf")
variant = "bold";
else if (tag == "mathbb" || tag == "mathbbm"
|| tag == "mathds")
variant = "double-struck";
else if (tag == "mathcal")
variant = "script";
else if (tag == "mathit" || tag == "textsl"
|| tag == "emph" || tag == "textit")
variant = "italic";
else if (tag == "mathsf" || tag == "textsf")
variant = "sans";
else if (tag == "mathtt" || tag == "texttt")
variant = "monospace";
else if (tag == "textipa" || tag == "textsc" || tag == "noun")
variant = "noun";
docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); if (!span_class.empty()) {
if (!variant.empty()) { os << MTag("span", "class='" + span_class + "'")
os << MTag("span", "class='" + variant + "'")
<< cell(0) << cell(0)
<< ETag("span"); << ETag("span");
} else } else
@ -341,29 +317,10 @@ void InsetMathFont::mathmlize(MathMLStream & ms) const
// FIXME These are not quite right, because they do not nest // FIXME These are not quite right, because they do not nest
// correctly. A proper fix would presumably involve tracking // correctly. A proper fix would presumably involve tracking
// the fonts already in effect. // the fonts already in effect.
std::string variant; const MathFontInfo font = MathFontInfo::fromMacro(key_->name);
docstring const & tag = key_->name; const std::string variant = font.toMathMLMathVariant(ms.version());
if (tag == "mathnormal" || tag == "mathrm")
variant = "normal";
else if (tag == "frak" || tag == "mathfrak")
variant = "fraktur";
else if (tag == "mathbf" || tag == "textbf")
variant = "bold";
else if (tag == "mathbb" || tag == "mathbbm" || tag == "mathds")
variant = "double-struck";
else if (tag == "mathcal")
variant = "script";
else if (tag == "mathit" || tag == "textsl" || tag == "emph" ||
tag == "textit")
variant = "italic";
else if (tag == "mathsf" || tag == "textsf")
variant = "sans-serif";
else if (tag == "mathtt" || tag == "texttt")
variant = "monospace";
// no support at present for textipa, textsc, noun
if (tag == "text" || tag == "textnormal" || tag == "textrm" || if (font.shape() == MathFontInfo::MATH_UP_SHAPE) {
tag == "textup" || tag == "textmd") {
SetMode textmode(ms, true); SetMode textmode(ms, true);
ms << cell(0); ms << cell(0);
} else if (!variant.empty()) { } else if (!variant.empty()) {