X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathFont.cpp;h=a017dd810c4ac3e08af92ff71325f05f4511ebb9;hb=4c724a6072013247ac178f0acec06825585c6c55;hp=5909c14c9bd630e8d153b8814fcc3ec8b4f1198c;hpb=0b8c6246ff39501afac5a68a6751605bd581313e;p=lyx.git diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 5909c14c9b..a017dd810c 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -18,8 +18,12 @@ #include "MathParser.h" #include "MetricsInfo.h" +#include "support/gettext.h" +#include "support/lstrings.h" + #include +using namespace lyx::support; namespace lyx { @@ -62,7 +66,7 @@ void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathFont::draw(PainterInfo & pi, int x, int y) const { - FontSetChanger dummy(pi.base, key_->name.c_str()); + FontSetChanger dummy(pi.base, key_->name); cell(0).draw(pi, x + 1, y); drawMarkers(pi, x, y); setPosCache(pi, x, y); @@ -92,17 +96,71 @@ docstring InsetMathFont::name() const void InsetMathFont::validate(LaTeXFeatures & features) const { InsetMathNest::validate(features); - // Make sure amssymb is put in preamble if Blackboard Bold or - // Fraktur used: - if (key_->name == "mathfrak" || key_->name == "mathbb") - features.require("amssymb"); - if (key_->name == "text" || key_->name == "textnormal" - || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text")) - features.require("amstext"); - if (key_->name == "textipa") - features.require("tipa"); - if (key_->name == "ce" || key_->name == "cf") - features.require("mhchem"); + if (features.runparams().isLaTeX()) { + // Make sure amssymb is put in preamble if Blackboard Bold or + // Fraktur used: + if (key_->name == "mathfrak" || key_->name == "mathbb") + features.require("amssymb"); + if (key_->name == "text" || key_->name == "textnormal" + || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text")) + features.require("amstext"); + if (key_->name == "mathscr") + features.require("mathrsfs"); + if (key_->name == "textipa") + features.require("tipa"); + if (key_->name == "ce" || key_->name == "cf") + features.require("mhchem"); + } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) { + features.addCSSSnippet( + "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.script{font: normal normal normal inherit cursive;}\n" + "span.italic{font: italic normal normal inherit serif;}\n" + "span.sans{font: normal normal normal inherit sans-serif;}\n" + "span.monospace{font: normal normal normal inherit monospace;}\n" + "span.noun{font: normal small-caps normal inherit normal;}"); + } +} + + +// The fonts we want to support are listed in lib/symbols +void InsetMathFont::htmlize(HtmlStream & os) const +{ + // FIXME These are not quite right, because they do not nest + // correctly. A proper fix would presumably involve tracking + // the fonts already in effect. + std::string variant; + docstring const & tag = key_->name; + 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 == "mathbb" || tag == "mathbf" + || tag == "textbf") + variant = "bold"; + 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 (!variant.empty()) { + os << MTag("span", "class='" + variant + "'") + << cell(0) + << ETag("span"); + } else + os << cell(0); } @@ -125,33 +183,34 @@ void InsetMathFont::mathmlize(MathStream & os) const || tag == "textbf") variant = "bold"; else if (tag == "mathcal") - variant == "script"; + variant = "script"; else if (tag == "mathit" || tag == "textsl" - || tag == "emph") + || tag == "emph" || tag == "textit") variant = "italic"; - else if (tag == "mathsf" || tag == "textit" - || tag == "textsf") + 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 - - // FIXME We need some kind of "mode tracker", so we can - // just output verbatim text in some cases. - docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); - bool const textmode = (beg == "text"); + if (!variant.empty()) { - os << ""; - SetMode sm(os, textmode); + if (tag == "mathbb") { + os << MTag("mstyle", "class='mathbb' mathvariant='" + variant + "'") + << cell(0) + << ETag("mstyle"); + } else { + os << MTag("mstyle", "mathvariant='" + variant + "'") + << cell(0) + << ETag("mstyle"); + } + } else os << cell(0); - os << ""; - } } void InsetMathFont::infoize(odocstream & os) const { - os << "Font: " << key_->name; + os << bformat(_("Font: %1$s"), key_->name); }