X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathRoot.cpp;h=8c4d1fa5ac784b94403c964b20bb729ee0014d74;hb=02e82157ec583c3900e359de86be79fac6512387;hp=0d812391155a67bfa6ad2c20e852edc5c515096d;hpb=f497296c30e6da2f97b16da8ad1c9e96feffb16b;p=lyx.git diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index 0d81239115..8c4d1fa5ac 100644 --- a/src/mathed/InsetMathRoot.cpp +++ b/src/mathed/InsetMathRoot.cpp @@ -4,7 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ @@ -12,69 +12,74 @@ #include #include "InsetMathRoot.h" + #include "MathData.h" #include "MathStream.h" -#include "cursor.h" -#include "LColor.h" -#include "frontends/Painter.h" +#include "Cursor.h" +#include "LaTeXFeatures.h" +#include "MetricsInfo.h" +#include "frontends/Painter.h" -namespace lyx { -using std::max; -using std::auto_ptr; +using namespace std; +namespace lyx { -InsetMathRoot::InsetMathRoot() - : InsetMathNest(2) +InsetMathRoot::InsetMathRoot(Buffer * buf) + : InsetMathNest(buf, 2) {} -auto_ptr InsetMathRoot::doClone() const +Inset * InsetMathRoot::clone() const { - return auto_ptr(new InsetMathRoot(*this)); + return new InsetMathRoot(*this); } -bool InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const +void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const { + Changer dummy = mi.base.changeEnsureMath(); InsetMathNest::metrics(mi); - dim.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2; - dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2; - dim.wid = cell(0).width() + cell(1).width() + 10; - metricsMarkers(dim); - if (dim_ == dim) - return false; - dim_ = dim; - return true; + Dimension const & dim0 = cell(0).dimension(*mi.base.bv); + Dimension const & dim1 = cell(1).dimension(*mi.base.bv); + dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2; + dim.des = max(dim0.descent() - 5, dim1.descent()) + 2; + dim.wid = dim0.width() + dim1.width() + 10; + metricsMarkers(mi, dim); } void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const { - int const w = cell(0).width(); + Changer dummy = pi.base.changeEnsureMath(); + Dimension const & dim0 = cell(0).dimension(*pi.base.bv); + int const w = dim0.width(); // the "exponent" - cell(0).draw(pi, x, y - 5 - cell(0).descent()); + cell(0).draw(pi, x, y - 5 - dim0.descent()); // the "base" cell(1).draw(pi, x + w + 8, y); - int const a = dim_.ascent(); - int const d = dim_.descent(); - int xp[5]; - int yp[5]; - xp[0] = x + dim_.width(); yp[0] = y - a + 1; - xp[1] = x + w + 4; yp[1] = y - a + 1; - xp[2] = x + w; yp[2] = y + d; - xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2; - xp[4] = x + w - 5; yp[4] = y + (d - a)/2 + 4; - pi.pain.lines(xp, yp, 5, LColor::math); + Dimension const dim = dimension(*pi.base.bv); + int const a = dim.ascent(); + int const d = dim.descent(); + int xp[4]; + int yp[4]; + pi.pain.line(x + dim.width(), y - a + 1, + x + w + 4, y - a + 1, pi.base.font.color()); + xp[0] = x + w + 4; yp[0] = y - a + 1; + xp[1] = x + w; yp[1] = y + d; + xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2; + xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4; + pi.pain.lines(xp, yp, 4, pi.base.font.color()); drawMarkers(pi, x, y); } void InsetMathRoot::write(WriteStream & os) const { + MathEnsurer ensurer(os); os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}'; } @@ -85,9 +90,9 @@ void InsetMathRoot::normalize(NormalStream & os) const } -bool InsetMathRoot::idxUpDown(LCursor & cur, bool up) const +bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const { - LCursor::idx_type const target = up ? 0 : 1; + Cursor::idx_type const target = up ? 0 : 1; if (cur.idx() == target) return false; cur.idx() = target; @@ -120,4 +125,23 @@ void InsetMathRoot::mathmlize(MathStream & os) const } +void InsetMathRoot::htmlize(HtmlStream & os) const +{ + os << MTag("span", "class='root'") + << MTag("sup") << cell(0) << ETag("sup") + << from_ascii("√") + << MTag("span", "class='rootof'") << cell(1) << ETag("span") + << ETag("span"); +} + + +void InsetMathRoot::validate(LaTeXFeatures & features) const +{ + if (features.runparams().math_flavor == OutputParams::MathAsHTML) + features.addCSSSnippet( + "span.rootof{border-top: thin solid black;}\n" + "span.root sup{font-size: 75%;}"); + InsetMathNest::validate(features); +} + } // namespace lyx