From 2a1c6c354134350ceaba8d0ec025f85e7e481b77 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 31 Mar 2010 18:57:47 +0000 Subject: [PATCH] HTML for math fonts. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33970 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathFont.cpp | 77 ++++++++++++++++++++++++++++++------ src/mathed/InsetMathFont.h | 2 + 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 35f58c00f3..93a2665537 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -92,17 +92,70 @@ 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 == "textipa") + features.require("tipa"); + if (key_->name == "ce" || key_->name == "cf") + features.require("mhchem"); + } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) { + features.addPreambleSnippet(""); + } +} + + +// 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); + bool const textmode = (beg == "text"); + if (!variant.empty()) { + SetHTMLMode sm(os, textmode, "class='" + variant + "'"); + os << cell(0); + } else + os << cell(0); } @@ -138,7 +191,7 @@ void InsetMathFont::mathmlize(MathStream & os) const docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); bool const textmode = (beg == "text"); if (!variant.empty()) { - docstring const attrs = from_ascii("mathvariant='" + variant + "'"); + std::string const attrs = "mathvariant='" + variant + "'"; SetMode sm(os, textmode, attrs); os << cell(0); } else diff --git a/src/mathed/InsetMathFont.h b/src/mathed/InsetMathFont.h index 926732b3dc..88c83165e9 100644 --- a/src/mathed/InsetMathFont.h +++ b/src/mathed/InsetMathFont.h @@ -48,6 +48,8 @@ public: /// void mathmlize(MathStream &) const; /// + void htmlize(HtmlStream &) const; + /// void infoize(odocstream & os) const; /// int kerning(BufferView const * bv) const { return cell(0).kerning(bv); } -- 2.39.2