From 3915c2d01a534da1e275dc159c49971cbb170a68 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 31 Dec 2009 19:35:56 +0000 Subject: [PATCH] Fix some issues with textmode. We'll let SetMode() handle as much of this as possible for us. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32708 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathFont.cpp | 15 ++++++--------- src/mathed/MathExtern.cpp | 6 ++++-- src/mathed/MathStream.cpp | 33 +++++++++++++++++++++++++++++++++ src/mathed/MathStream.h | 20 ++++---------------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 5909c14c9b..35f58c00f3 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -127,25 +127,22 @@ void InsetMathFont::mathmlize(MathStream & os) const else if (tag == "mathcal") 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); + docstring const attrs = from_ascii("mathvariant='" + variant + "'"); + SetMode sm(os, textmode, attrs); + os << cell(0); + } else os << cell(0); - os << ""; - } } diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 2e43c11719..afeba3ebe2 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -1423,10 +1423,12 @@ void mathmlize(MathData const & dat, MathStream & os) } else if (ar.size() == 1) os << ar.front(); else { - os << (os.inText() ? MTag("mtext") : MTag("mrow")); + if (!os.inText()) + os << MTag("mrow"); for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it) (*it)->mathmlize(os); - os << (os.inText() ? ETag("mtext") : ETag("mrow")); + if (!os.inText()) + os << ETag("mrow"); } } diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index a638052a87..81a89dc6d3 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -337,6 +337,39 @@ MathStream & operator<<(MathStream & ms, docstring const & s) } +SetMode::SetMode(MathStream & os, bool text, docstring attrs) + : os_(os) +{ + was_text_ = os.inText(); + if (was_text_) + os << ""; + if (text) { + os.setTextMode(); + os << ""; + } else { + if (!attrs.empty()) + os << ""; + os.setMathMode(); + } +} + + +SetMode::~SetMode() +{ + if (os_.inText()) + os_ << ""; + if (was_text_) { + os_.setTextMode(); + os_ << ""; + } else { + os_.setMathMode(); + } +} + + ////////////////////////////////////////////////////////////////////// diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 8dc9c4628d..df97ce303a 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -306,23 +306,11 @@ MathStream & operator<<(MathStream &, ETag const &); class SetMode { public: /// - explicit SetMode(MathStream & os, bool text) - : os_(os) - { - was_text_ = os.inText(); - if (text) - os.setTextMode(); - else - os.setMathMode(); - } + explicit SetMode(MathStream & os, bool text, docstring attrs); + // not clear yet precisely what we need... + // explicit SetMode(MathStream & os, bool text); /// - ~SetMode() - { - if (was_text_) - os_.setTextMode(); - else - os_.setMathMode(); - } + ~SetMode(); private: /// MathStream & os_;