]> git.lyx.org Git - lyx.git/commitdiff
The mode setting stuff wasn't working properly for XHTML, so this patch
authorRichard Heck <rgheck@comcast.net>
Fri, 1 Apr 2011 22:34:40 +0000 (22:34 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 1 Apr 2011 22:34:40 +0000 (22:34 +0000)
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
src/mathed/InsetMathChar.cpp
src/mathed/InsetMathEnsureMath.cpp
src/mathed/InsetMathEnsureMath.h
src/mathed/InsetMathFont.cpp
src/mathed/InsetMathMBox.cpp
src/mathed/InsetMathNumber.cpp
src/mathed/MathExtern.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index fa3f5653241eb6fd876fac3a456bf4ed20c6a950..c6f98ca98718dbb7077e496529544eeab3f0dc9e 100644 (file)
@@ -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("<style type=\"text/css\">\n"
+                       "mstyle.mathbox { font-style: normal; }\n"
+                       "</style>");
+       else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+               features.addPreambleSnippet("<style type=\"text/css\">\n"
+                       "span.mathbox { font-style: normal; }\n"
+                       "</style>");
+
        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("<style type=\"text/css\">\n"
-                       "mtext.fbox { border: 1px solid black; }\n"
+                       "mstyle.fbox { border: 1px solid black; font-style: normal; padding: 0.5ex; }\n"
                        "</style>");
        else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
                features.addPreambleSnippet("<style type=\"text/css\">\n"
-                       "span.fbox { border: 1px solid black; }\n"
+                       "span.fbox { border: 1px solid black; font-style: normal; padding: 0.5ex; }\n"
                        "</style>");
+
+       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("<style type=\"text/css\">\n"
-                       "span.framebox { border: 1px solid black; }\n"
+                       "mstyle.framebox { border: 1px solid black; }\n"
                        "</style>");
        else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
                features.addPreambleSnippet("<style type=\"text/css\">\n"
@@ -370,15 +396,17 @@ void InsetMathBoxed::infoize(odocstream & os) const
 
 void InsetMathBoxed::mathmlize(MathStream & ms) const
 {
-       SetMode mathmode(ms, false, "class='boxed'");
-       ms << cell(0);
+       ms << MTag("mstyle", "class='boxed'")
+          << cell(0)
+          << ETag("mstyle");
 }
 
 
 void InsetMathBoxed::htmlize(HtmlStream & ms) const
 {
-       SetHTMLMode mathmode(ms, false, "class='boxed'");
-       ms << cell(0);
+       ms << MTag("span", "class='boxed'")
+          << cell(0)
+                << ETag("span");
 }
 
 
index 532d8496fa39bde2cfeb420a2f0f69ae69b3aca4..2c87824282775cfec55a7f0a27929a194fc971cd 100644 (file)
@@ -172,11 +172,10 @@ void InsetMathChar::mathmlize(MathStream & ms) const
                case '<': entity = "&lt;"; break;
                case '>': entity = "&gt;"; break;
                case '&': entity = "&amp;"; break;
-               case ' ': 
-                       if (!ms.inText())
-                               break;
-                       entity = "&ThinSpace;";
-                       break;
+               case ' ': {
+                       ms << from_ascii("&nsbp;");
+                       return;
+               }
                default: break;
        }
        
@@ -187,7 +186,7 @@ void InsetMathChar::mathmlize(MathStream & ms) const
                        ms << from_ascii(entity);
                return;
        }
-       
+
        if (!entity.empty()) {
                ms << "<mo>" << from_ascii(entity) << "</mo>";
                return;
@@ -208,6 +207,7 @@ void InsetMathChar::htmlize(HtmlStream & ms) const
                case '<': entity = "&lt;"; break;
                case '>': entity = "&gt;"; break;
                case '&': entity = "&amp;"; break;
+               case ' ': entity = "&nbsp;"; break;
                default: break;
        }
        
@@ -222,6 +222,7 @@ void InsetMathChar::htmlize(HtmlStream & ms) const
        }
        
        if (have_entity) {
+               // an operator, so give some space
                ms << ' ' << from_ascii(entity) << ' ';
                return;
        }               
index 70f3e9c188848146d00c36501908c43e190606d1..a4070265905f54b0574eaf837d6b81d96d3d1b00 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "InsetMathEnsureMath.h"
 
+#include "LaTeXFeatures.h"
 #include "MathData.h"
 #include "MathStream.h"
 #include "MathSupport.h"
@@ -73,16 +74,18 @@ void InsetMathEnsureMath::write(WriteStream & os) const
 void InsetMathEnsureMath::mathmlize(MathStream & os) const
 {
        SetMode mathmode(os, false);
-       os << cell(0);
+       os << MTag("mstyle", "class='math'")
+          << cell(0)
+          << ETag("mstyle");
 }
 
 
 void InsetMathEnsureMath::htmlize(HtmlStream & os) const
 {
-       os << "[EM]";
        SetHTMLMode mathmode(os, false);
-       os << cell(0);
-       os << "[/EM]";
+       os << MTag("span", "class='math'")
+          << cell(0)
+          << ETag("span");
 }
 
 
@@ -92,4 +95,21 @@ void InsetMathEnsureMath::infoize(odocstream & os) const
 }
 
 
+void InsetMathEnsureMath::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("<style type=\"text/css\">\n"
+                       "mstyle.math { font-style: italic; }\n"
+                       "</style>");
+       else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+               features.addPreambleSnippet("<style type=\"text/css\">\n"
+                       "span.mathbox { font-style: italic; }\n"
+                       "</style>");
+
+       InsetMathNest::validate(features);
+}
+
 } // namespace lyx
index 83edf47482022c6e122ceaf35337d30899956e6c..41c3ad654ab74f5f392abd167594eb779a5c16d7 100644 (file)
@@ -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;
index 6b3f2e0f2f51f0559e53fcd997a663d0a3ef04d5..efd43ced126e886b57636932ef7a7c769e97307a 100644 (file)
@@ -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);
 }
index 527a080793bfd2c5d4a2cad01d92d267eba479ab..8b38755f0485eb9d98ecc698596837d64fdd7019 100644 (file)
@@ -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);
 }
 
index 45e73220fc6d03f20eb6700b4d98866cbd6dd200..6a67ce18d75d92840db8f46c808a0834f6bf627d 100644 (file)
@@ -69,10 +69,7 @@ void InsetMathNumber::octave(OctaveStream & os) const
 
 void InsetMathNumber::mathmlize(MathStream & os) const
 {
-       if (os.inText())
-               os << str_;
-       else
-               os << "<mn>" << str_ << "</mn>";
+       os << "<mn>" << str_ << "</mn>";
 }
 
 
index ce055ea33670a96c97c5bc9b177ff1f63ffcb1fd..8d1df06f777ee1e78b3bfa8df57c035d5c939e6f 100644 (file)
@@ -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 << "<mrow/>";
-       } else if (ar.size() == 1)
+       if (ar.size() == 0)
+               os << "<mrow/>";
+       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");
        }
 }
 
index 7a13955779b6028438f3f6dbc15f2f405d2020d3..ed23eb416040a88a6303bb721d965d33cb5b68f9 100644 (file)
@@ -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_ << "</mtext>";
-       if (text) {
-               os_.setTextMode();
-               os_ << "<mtext";
-               if (!attrs.empty())
-                       os_ << " " << from_utf8(attrs);
-               os_ << ">";
-               opened_ = true;
-       } else {
-               if (!attrs.empty()) {
-                       os_ << "<mstyle " << from_utf8(attrs) << ">";
-                       opened_ = true;
-               }
-               os_.setMathMode();
-       }
+       os_.setTextMode(text);
 }
 
 
 SetMode::~SetMode()
 {
-       if (opened_) {
-               if (os_.inText())
-                       os_ << "</mtext>";
-               else
-                       os_ << "</mstyle>";
-       }
-       if (was_text_) {
-               os_.setTextMode();
-               os_ << "<mtext>";
-       } 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_);
 }
 
 
index 7da9a9b9f9177d0949a6a1c71f4ac8e0b3d750ba..ad1baada353dcd214b682442db7def4527a3a0d2 100644 (file)
@@ -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: 
-//             <mtext><mtext></mtext></mtext>
-// So we have to have:
-//             <mtext></mtext><mtext></mtext><mtext></mtext>
-// 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_;
 };