]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathStream.cpp
Whitespace.
[lyx.git] / src / mathed / MathStream.cpp
index a638052a87c7a3063c83f0a6ce064395f19449a3..c9f7ef54a50df772ff4164f936c548ed8a04d765 100644 (file)
@@ -337,6 +337,59 @@ MathStream & operator<<(MathStream & ms, docstring const & s)
 }
 
 
+SetMode::SetMode(MathStream & os, bool text)
+       : os_(os), opened_(false)
+{
+       init(text, from_ascii(""));
+}
+
+
+SetMode::SetMode(MathStream & os, bool text, docstring attrs)
+       : os_(os), opened_(false)
+{
+       init(text, attrs);
+}
+
+
+void SetMode::init(bool text, docstring attrs)
+{
+       was_text_ = os_.inText();
+       if (was_text_)
+               os_ << "</mtext>";
+       if (text) {
+               os_.setTextMode();
+               os_ << "<mtext";
+               if (!attrs.empty())
+                       os_ << " " << attrs;
+               os_ << ">";
+               opened_ = true;
+       } else {
+               if (!attrs.empty()) {
+                       os_ << "<mstyle " << attrs << ">";
+                       opened_ = true;
+               }
+               os_.setMathMode();
+       }
+}
+
+
+SetMode::~SetMode()
+{
+       if (opened_) {
+               if (os_.inText())
+                       os_ << "</mtext>";
+               else
+                       os_ << "</mstyle>";
+       }
+       if (was_text_) {
+               os_.setTextMode();
+               os_ << "<mtext>";
+       } else {
+               os_.setMathMode();
+       }
+}
+
+
 //////////////////////////////////////////////////////////////////////