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
This commit is contained in:
Richard Heck 2011-04-01 22:34:40 +00:00
parent 844296cd47
commit 740e89de17
10 changed files with 103 additions and 149 deletions

View File

@ -54,15 +54,19 @@ 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");
}

View 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;
}
@ -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;
}

View 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

View 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;

View 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);
}

View 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);
}

View File

@ -69,9 +69,6 @@ void InsetMathNumber::octave(OctaveStream & os) const
void InsetMathNumber::mathmlize(MathStream & os) const
{
if (os.inText())
os << str_;
else
os << "<mn>" << str_ << "</mn>";
}

View File

@ -1419,17 +1419,14 @@ void mathmlize(MathData const & dat, MathStream & os)
{
MathData ar = dat;
extractStructure(ar, MATHML);
if (ar.size() == 0) {
if (!os.inText())
if (ar.size() == 0)
os << "<mrow/>";
} else if (ar.size() == 1)
else if (ar.size() == 1)
os << ar.front();
else {
if (!os.inText())
os << MTag("mrow");
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
(*it)->mathmlize(os);
if (!os.inText())
os << ETag("mrow");
}
}

View 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_);
}

View 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_;
};