Math: support all font combinations in HTML.

This code cannot yet be triggered, we need nesting first.
This commit is contained in:
Thibaut Cuvelier 2024-10-29 04:21:05 +01:00
parent 78ce5ebc45
commit 5c17e07bd1

View File

@ -104,28 +104,41 @@ public:
std::string toHTMLSpanClass() const std::string toHTMLSpanClass() const
{ {
// See the existing classes in InsetMathFont::validate. In particular, std::string span_class;
// there is no double-struck style!
switch (family_) { switch (family_) {
case MATH_MONOSPACE_FAMILY: case MATH_NORMAL_FAMILY:
return "monospace"; break;
case MATH_FRAKTUR_FAMILY: case MATH_FRAKTUR_FAMILY:
return "fraktur"; span_class = "fraktur";
case MATH_SCRIPT_FAMILY: break;
return "script"; case MATH_SANS_FAMILY:
case MATH_SMALL_CAPS: span_class = "sans";
return "noun"; break;
case MATH_SANS_FAMILY: case MATH_MONOSPACE_FAMILY:
return "sans"; span_class = "monospace";
case MATH_NORMAL_FAMILY: break;
if (series_ == MATH_MEDIUM_SERIES) { case MATH_DOUBLE_STRUCK_FAMILY:
return shape_ == MATH_UP_SHAPE ? "normal" : "italic"; // This style does not exist in HTML and cannot be implemented in CSS.
} break;
return "bold"; case MATH_SCRIPT_FAMILY:
case MATH_DOUBLE_STRUCK_FAMILY: span_class = "script";
// No support for double-struck font in CSS. break;
return ""; case MATH_SMALL_CAPS:
span_class = "noun";
break;
} }
if (series_ == MATH_BOLD_SERIES) {
if (!span_class.empty()) span_class += "-";
span_class += "bold";
}
if (shape_ == MATH_ITALIC_SHAPE) {
if (!span_class.empty()) span_class += "-";
span_class += "italic";
}
return span_class;
} }
private: private:
@ -282,13 +295,29 @@ void InsetMathFont::validate(LaTeXFeatures & features) const
} else if (features.runparams().math_flavor == OutputParams::MathAsHTML) { } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
features.addCSSSnippet( features.addCSSSnippet(
"span.normal{font: normal normal normal inherit serif;}\n" "span.normal{font: normal normal normal inherit serif;}\n"
"span.fraktur{font: normal normal normal inherit cursive;}\n"
"span.bold{font: normal normal bold inherit serif;}\n" "span.bold{font: normal normal bold inherit serif;}\n"
"span.script{font: normal normal normal inherit cursive;}\n"
"span.italic{font: italic normal normal inherit serif;}\n" "span.italic{font: italic normal normal inherit serif;}\n"
"span.bold-italic{font: italic normal bold inherit serif;}\n"
"span.fraktur{font: normal normal normal inherit cursive;}\n"
"span.fraktur-bold{font: normal normal bold inherit cursive;}\n"
"span.fraktur-italic{font: italic normal normal inherit cursive;}\n"
"span.fraktur-bold-italic{font: italic normal bold inherit cursive;}\n"
"span.script{font: normal normal normal inherit cursive;}\n"
"span.script-bold{font: normal normal bold inherit cursive;}\n"
"span.script-italic{font: italic normal normal inherit cursive;}\n"
"span.script-bold-italic{font: italic normal bold inherit cursive;}\n"
"span.sans{font: normal normal normal inherit sans-serif;}\n" "span.sans{font: normal normal normal inherit sans-serif;}\n"
"span.sans-bold{font: normal normal normal inherit bold-serif;}\n"
"span.sans-italic{font: italic normal normal inherit sans-serif;}\n"
"span.sans-bold-italic{font: italic normal normal inherit bold-serif;}\n"
"span.monospace{font: normal normal normal inherit monospace;}\n" "span.monospace{font: normal normal normal inherit monospace;}\n"
"span.noun{font: normal small-caps normal inherit normal;}"); "span.monospace-bold{font: normal normal bold inherit monospace;}\n"
"span.monospace-italic{font: italic normal normal inherit monospace;}\n"
"span.monospace-bold-italic{font: italic normal bold inherit monospace;}\n"
"span.noun{font: normal small-caps normal inherit normal;}\n"
"span.noun-bold{font: normal small-caps bold inherit normal;}\n"
"span.noun-italic{font: italic small-caps normal inherit normal;}\n"
"span.noun-bold-italic{font: italic small-caps bold inherit normal;}");
} }
} }