From 27add8d945ba8e1395dd643f5b5f5cfc985a816e Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Tue, 30 Mar 2010 02:37:05 +0000 Subject: [PATCH] HTML for math boxes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33948 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathBox.cpp | 34 ++++++++++++++++++++++++++++++++++ src/mathed/InsetMathBox.h | 8 ++++++++ src/mathed/MathStream.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/mathed/MathStream.h | 20 +++++++++++++++++++- 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index 17d2b13346..b3cc30abcb 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -59,6 +59,13 @@ void InsetMathBox::mathmlize(MathStream & ms) const } +void InsetMathBox::htmlize(HtmlStream & ms) const +{ + SetHTMLMode textmode(ms, true); + ms << cell(0); +} + + void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); @@ -85,6 +92,7 @@ void InsetMathBox::validate(LaTeXFeatures & features) const { if (name_ == "tag" || name_ == "tag*") features.require("amsmath"); + cell(0).validate(features); } @@ -141,6 +149,13 @@ void InsetMathFBox::mathmlize(MathStream & ms) const } +void InsetMathFBox::htmlize(HtmlStream & ms) const +{ + SetHTMLMode textmode(ms, true, "class='fbox'"); + ms << cell(0); +} + + void InsetMathFBox::infoize(odocstream & os) const { os << "FBox: "; @@ -155,6 +170,7 @@ void InsetMathFBox::validate(LaTeXFeatures & features) const if (features.runparams().flavor == OutputParams::HTML) features.addPreambleSnippet(""); } @@ -275,6 +291,15 @@ void InsetMathMakebox::mathmlize(MathStream & ms) const } +void InsetMathMakebox::htmlize(HtmlStream & ms) const +{ + // FIXME We could do something with the other arguments. + std::string const cssclass = framebox_ ? "framebox" : "makebox"; + SetHTMLMode textmode(ms, true, "class='" + cssclass + "'"); + ms << cell(2); +} + + void InsetMathMakebox::validate(LaTeXFeatures & features) const { // FIXME XHTML @@ -283,6 +308,7 @@ void InsetMathMakebox::validate(LaTeXFeatures & features) const if (features.runparams().flavor == OutputParams::HTML) features.addPreambleSnippet(""); } @@ -342,6 +368,13 @@ void InsetMathBoxed::mathmlize(MathStream & ms) const } +void InsetMathBoxed::htmlize(HtmlStream & ms) const +{ + SetHTMLMode mathmode(ms, false, "class='boxed'"); + ms << cell(0); +} + + void InsetMathBoxed::validate(LaTeXFeatures & features) const { features.require("amsmath"); @@ -351,6 +384,7 @@ void InsetMathBoxed::validate(LaTeXFeatures & features) const if (features.runparams().flavor == OutputParams::HTML) features.addPreambleSnippet(""); InsetMathNest::validate(features); } diff --git a/src/mathed/InsetMathBox.h b/src/mathed/InsetMathBox.h index 5a958f4b78..3dfe2286c3 100644 --- a/src/mathed/InsetMathBox.h +++ b/src/mathed/InsetMathBox.h @@ -37,6 +37,8 @@ public: /// void mathmlize(MathStream & ms) const; /// + void htmlize(HtmlStream & ms) const; + /// void infoize(odocstream & os) const; /// void validate(LaTeXFeatures & features) const; @@ -68,6 +70,8 @@ public: /// void mathmlize(MathStream & ms) const; /// + void htmlize(HtmlStream & ms) const; + /// void infoize(odocstream & os) const; /// void validate(LaTeXFeatures & features) const; @@ -93,6 +97,8 @@ public: /// void mathmlize(MathStream & ms) const; /// + void htmlize(HtmlStream & ms) const; + /// mode_type currentMode() const { return TEXT_MODE; } /// void infoize(odocstream & os) const; @@ -121,6 +127,8 @@ public: void write(WriteStream & os) const; /// void mathmlize(MathStream & ms) const; + /// + void htmlize(HtmlStream & ms) const; /// write normalized content void normalize(NormalStream & ns) const; /// diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index 25bb288a50..8f2534bbb1 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -490,6 +490,43 @@ SetMode::~SetMode() ////////////////////////////////////////////////////////////////////// +SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text) + : os_(os), opened_(false) +{ + was_text_ = os_.inText(); + if (text) + os_.setTextMode(); + else + os_.setMathMode(); +} + + +SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text, string attrs) + : os_(os), opened_(true) +{ + was_text_ = os_.inText(); + if (text) { + os_.setTextMode(); + os_ << MTag("span", attrs); + } else + os_.setMathMode(); +} + + +SetHTMLMode::~SetHTMLMode() +{ + if (opened_) + os_ << ETag("span"); + if (was_text_) + os_.setTextMode(); + else + os_.setMathMode(); +} + + +////////////////////////////////////////////////////////////////////// + + MapleStream & operator<<(MapleStream & ms, MathAtom const & at) { at->maple(ms); diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index cf08afe23c..502848d234 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -392,7 +392,7 @@ private: /// odocstringstream deferred_; /// - friend class SetMode; + friend class SetHTMLMode; }; /// @@ -413,6 +413,24 @@ HtmlStream & operator<<(HtmlStream &, MTag const &); 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: + /// + HtmlStream & os_; + /// + bool opened_; + /// + bool was_text_; +}; + + // // Debugging // -- 2.39.2