From 740e89de178ed13513c8ce4a048463140b9f02e4 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 1 Apr 2011 22:34:40 +0000 Subject: [PATCH] The mode setting stuff wasn't working properly for XHTML, so this patch simplifies it and hopefully does get it working. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38195 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathBox.cpp | 68 ++++++++++++++++++-------- src/mathed/InsetMathChar.cpp | 13 ++--- src/mathed/InsetMathEnsureMath.cpp | 28 +++++++++-- src/mathed/InsetMathEnsureMath.h | 2 + src/mathed/InsetMathFont.cpp | 14 +++--- src/mathed/InsetMathMBox.cpp | 4 +- src/mathed/InsetMathNumber.cpp | 5 +- src/mathed/MathExtern.cpp | 13 ++--- src/mathed/MathStream.cpp | 77 +++--------------------------- src/mathed/MathStream.h | 28 +---------- 10 files changed, 103 insertions(+), 149 deletions(-) diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index fa3f565324..c6f98ca987 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -53,16 +53,20 @@ void InsetMathBox::normalize(NormalStream & os) const void InsetMathBox::mathmlize(MathStream & ms) const -{ - SetMode textmode(ms, true, "class='mathbox'"); - ms << cell(0); +{ + SetMode textmode(ms, true); + ms << MTag("mstyle", "class='mathbox'") + << cell(0) + << ETag("mstyle"); } void InsetMathBox::htmlize(HtmlStream & ms) const { SetHTMLMode textmode(ms, true); - ms << cell(0); + ms << MTag("span", "class='mathbox'") + << cell(0) + << ETag("span"); } @@ -90,10 +94,22 @@ void InsetMathBox::infoize(odocstream & os) const void InsetMathBox::validate(LaTeXFeatures & features) const { + // FIXME XHTML + // It'd be better to be able to get this from an InsetLayout, but at present + // InsetLayouts do not seem really to work for things that aren't InsetTexts. + if (features.runparams().math_flavor == OutputParams::MathAsMathML) + features.addPreambleSnippet(""); + else if (features.runparams().math_flavor == OutputParams::MathAsHTML) + features.addPreambleSnippet(""); + if (name_ == "tag" || name_ == "tag*") features.require("amsmath"); - cell(0).validate(features); + InsetMathNest::validate(features); } @@ -144,15 +160,19 @@ void InsetMathFBox::normalize(NormalStream & os) const void InsetMathFBox::mathmlize(MathStream & ms) const { - SetMode textmode(ms, true, "class='fbox'"); - ms << cell(0); + SetMode textmode(ms, true); + ms << MTag("mstyle", "class='fbox'") + << cell(0) + << ETag("mstyle"); } void InsetMathFBox::htmlize(HtmlStream & ms) const { - SetHTMLMode textmode(ms, true, "class='fbox'"); - ms << cell(0); + SetHTMLMode textmode(ms, true); + ms << MTag("span", "class='fbox'") + << cell(0) + << ETag("span"); } @@ -169,12 +189,14 @@ void InsetMathFBox::validate(LaTeXFeatures & features) const // InsetLayouts do not seem really to work for things that aren't InsetTexts. if (features.runparams().math_flavor == OutputParams::MathAsMathML) features.addPreambleSnippet(""); else if (features.runparams().math_flavor == OutputParams::MathAsHTML) features.addPreambleSnippet(""); + + cell(0).validate(features); InsetMathNest::validate(features); } @@ -290,17 +312,21 @@ void InsetMathMakebox::mathmlize(MathStream & ms) const { // FIXME We could do something with the other arguments. std::string const cssclass = framebox_ ? "framebox" : "makebox"; - SetMode textmode(ms, true, "class='" + cssclass + "'"); - ms << cell(2); + SetMode textmode(ms, true); + ms << MTag("mstyle", "class='" + cssclass + "'") + << cell(2) + << ETag("mstyle"); } void InsetMathMakebox::htmlize(HtmlStream & ms) const { // FIXME We could do something with the other arguments. + SetHTMLMode textmode(ms, true); std::string const cssclass = framebox_ ? "framebox" : "makebox"; - SetHTMLMode textmode(ms, true, "class='" + cssclass + "'"); - ms << cell(2); + ms << MTag("span", "class='" + cssclass + "'") + << cell(2) + << ETag("span"); } @@ -311,7 +337,7 @@ void InsetMathMakebox::validate(LaTeXFeatures & features) const // InsetLayouts do not seem really to work for things that aren't InsetTexts. if (features.runparams().math_flavor == OutputParams::MathAsMathML) features.addPreambleSnippet(""); else if (features.runparams().math_flavor == OutputParams::MathAsHTML) features.addPreambleSnippet(""); + else if (features.runparams().math_flavor == OutputParams::MathAsHTML) + features.addPreambleSnippet(""); + + InsetMathNest::validate(features); +} + } // namespace lyx diff --git a/src/mathed/InsetMathEnsureMath.h b/src/mathed/InsetMathEnsureMath.h index 83edf47482..41c3ad654a 100644 --- a/src/mathed/InsetMathEnsureMath.h +++ b/src/mathed/InsetMathEnsureMath.h @@ -42,6 +42,8 @@ public: /// void infoize(odocstream & os) const; /// + void validate(LaTeXFeatures & features) const; + /// InsetCode lyxCode() const { return MATH_ENSUREMATH_CODE; } private: virtual Inset * clone() const; diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 6b3f2e0f2f..efd43ced12 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -152,10 +152,10 @@ void InsetMathFont::htmlize(HtmlStream & os) const 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); + os << MTag("span", "class='" + variant + "'") + << cell(0) + << ETag("span"); } else os << cell(0); } @@ -190,12 +190,10 @@ void InsetMathFont::mathmlize(MathStream & os) const variant = "monospace"; // no support at present for textipa, textsc, noun - docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); - bool const textmode = (beg == "text"); if (!variant.empty()) { - std::string const attrs = "mathvariant='" + variant + "'"; - SetMode sm(os, textmode, attrs); - os << cell(0); + os << MTag("mstyle", "mathvariant='" + variant + "'") + << cell(0) + << ETag("mstyle"); } else os << cell(0); } diff --git a/src/mathed/InsetMathMBox.cpp b/src/mathed/InsetMathMBox.cpp index 527a080793..8b38755f04 100644 --- a/src/mathed/InsetMathMBox.cpp +++ b/src/mathed/InsetMathMBox.cpp @@ -119,13 +119,13 @@ void InsetMathMBox::cursorPos(BufferView const & bv, void InsetMathMBox::mathmlize(MathStream & ms) const { - SetMode textmode(ms, true, "class='mbox'"); + SetMode textmode(ms, true); ms << cell(0); } void InsetMathMBox::htmlize(HtmlStream & ms) const { - SetHTMLMode textmode(ms, true, "class='mbox'"); + SetHTMLMode textmode(ms, true); ms << cell(0); } diff --git a/src/mathed/InsetMathNumber.cpp b/src/mathed/InsetMathNumber.cpp index 45e73220fc..6a67ce18d7 100644 --- a/src/mathed/InsetMathNumber.cpp +++ b/src/mathed/InsetMathNumber.cpp @@ -69,10 +69,7 @@ void InsetMathNumber::octave(OctaveStream & os) const void InsetMathNumber::mathmlize(MathStream & os) const { - if (os.inText()) - os << str_; - else - os << "" << str_ << ""; + os << "" << str_ << ""; } diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index ce055ea336..8d1df06f77 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -1419,18 +1419,15 @@ void mathmlize(MathData const & dat, MathStream & os) { MathData ar = dat; extractStructure(ar, MATHML); - if (ar.size() == 0) { - if (!os.inText()) - os << ""; - } else if (ar.size() == 1) + if (ar.size() == 0) + os << ""; + else if (ar.size() == 1) os << ar.front(); else { - if (!os.inText()) - os << MTag("mrow"); + os << MTag("mrow"); for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it) (*it)->mathmlize(os); - if (!os.inText()) - os << ETag("mrow"); + os << ETag("mrow"); } } diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index 7a13955779..ed23eb4160 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -442,55 +442,16 @@ HtmlStream & operator<<(HtmlStream & ms, docstring const & s) SetMode::SetMode(MathStream & os, bool text) - : os_(os), opened_(false) -{ - init(text, ""); -} - - -SetMode::SetMode(MathStream & os, bool text, string const & attrs) - : os_(os), opened_(false) -{ - init(text, attrs); -} - - -void SetMode::init(bool text, string const & attrs) + : os_(os) { was_text_ = os_.inText(); - if (was_text_) - os_ << ""; - if (text) { - os_.setTextMode(); - os_ << ""; - opened_ = true; - } else { - if (!attrs.empty()) { - os_ << ""; - opened_ = true; - } - os_.setMathMode(); - } + os_.setTextMode(text); } SetMode::~SetMode() { - if (opened_) { - if (os_.inText()) - os_ << ""; - else - os_ << ""; - } - if (was_text_) { - os_.setTextMode(); - os_ << ""; - } else { - os_.setMathMode(); - } + os_.setTextMode(was_text_); } @@ -498,42 +459,16 @@ SetMode::~SetMode() SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text) - : os_(os), opened_(false) -{ - init(text, ""); -} - - -SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text, string attrs) - : os_(os), opened_(true) -{ - init(text, attrs); -} - - -void SetHTMLMode::init(bool text, string const & attrs) + : os_(os) { was_text_ = os_.inText(); - if (text) { - os_.setTextMode(); - if (attrs.empty()) - os_ << MTag("span"); - else - os_ << MTag("span", attrs); - opened_ = true; - } else - os_.setMathMode(); + os_.setTextMode(text); } SetHTMLMode::~SetHTMLMode() { - if (opened_) - os_ << ETag("span"); - if (was_text_) - os_.setTextMode(); - else - os_.setMathMode(); + os_.setTextMode(was_text_); } diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 7da9a9b9f9..ad1baada35 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -299,9 +299,7 @@ public: bool inText() const { return in_text_; } private: /// - void setTextMode() { in_text_ = true; } - /// - void setMathMode() { in_text_ = false; } + void setTextMode(bool t) { in_text_ = t; } /// odocstream & os_; /// @@ -335,30 +333,16 @@ MathStream & operator<<(MathStream &, ETag const &); /// A simpler version of ModeSpecifier, for MathML -// FIXME There are still problems here with nesting, at least -// potentially. The problem is that true nesting of text mode isn't -// actually possible. I.e., we can't have: -// -// So we have to have: -// -// instead, where the last is really a continuation of the first. -// We'll need some kind of stack to remember all that. class SetMode { public: - /// - explicit SetMode(MathStream & os, bool text, std::string const & attrs); /// explicit SetMode(MathStream & os, bool text); /// ~SetMode(); private: - /// - void init(bool, std::string const &); /// MathStream & os_; /// - bool opened_; - /// bool was_text_; }; @@ -387,9 +371,7 @@ public: bool inText() const { return in_text_; } private: /// - void setTextMode() { in_text_ = true; } - /// - void setMathMode() { in_text_ = false; } + void setTextMode(bool t) { in_text_ = t; } /// odocstream & os_; /// @@ -424,20 +406,14 @@ HtmlStream & operator<<(HtmlStream &, ETag const &); class SetHTMLMode { public: - /// - explicit SetHTMLMode(HtmlStream & os, bool text, std::string attrs); /// explicit SetHTMLMode(HtmlStream & os, bool text); /// ~SetHTMLMode(); private: - /// - void init(bool, std::string const &); /// HtmlStream & os_; /// - bool opened_; - /// bool was_text_; }; -- 2.39.2