X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathRoot.cpp;h=8b86c5965ba3ab6ce02fe5737a4209671dce2f32;hb=64007533a76dd0634d39800dd11da9ef418871ed;hp=f9424ed4ed211be9519026b7de6a14b832d5bac3;hpb=7150b0caa381ed6872d0b6090a1057861cacfa50;p=lyx.git diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index f9424ed4ed..8b86c5965b 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,19 +12,25 @@ #include #include "InsetMathRoot.h" + #include "MathData.h" #include "MathStream.h" +#include "MathSupport.h" + #include "Cursor.h" +#include "LaTeXFeatures.h" +#include "MetricsInfo.h" #include "frontends/Painter.h" + using namespace std; namespace lyx { -InsetMathRoot::InsetMathRoot() - : InsetMathNest(2) +InsetMathRoot::InsetMathRoot(Buffer * buf) + : InsetMathNest(buf, 2) {} @@ -36,42 +42,60 @@ Inset * InsetMathRoot::clone() const void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const { - InsetMathNest::metrics(mi); - 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(dim); + Changer dummy = mi.base.changeEnsureMath(); + Dimension dim0; + { + Changer script = mi.base.font.changeStyle(LM_ST_SCRIPTSCRIPT); + cell(0).metrics(mi, dim0); + // make sure that the dim is high enough for any character + Dimension fontDim; + math_font_max_dim(mi.base.font, fontDim.asc, fontDim.des); + dim0 += fontDim; + } + + Dimension dim1; + cell(1).metrics(mi, dim1); + // make sure that the dim is high enough for any character + Dimension fontDim; + math_font_max_dim(mi.base.font, fontDim.asc, fontDim.des); + dim1 += fontDim; + + dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 1; + dim.des = max(dim0.descent() - 5, dim1.descent()); + dim.wid = dim0.width() + dim1.width() + 4; } void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const { + Changer dummy = pi.base.changeEnsureMath(); + Dimension const dim = dimension(*pi.base.bv); + int const a = dim.ascent(); + int const d = dim.descent(); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); int const w = dim0.width(); // the "exponent" - cell(0).draw(pi, x, y - 5 - dim0.descent()); + { + Changer script = pi.base.font.changeStyle(LM_ST_SCRIPTSCRIPT); + cell(0).draw(pi, x, y + (d - a)/2 - dim0.descent()); + } // the "base" - cell(1).draw(pi, x + w + 8, y); - Dimension const dim = dimension(*pi.base.bv); - int const a = dim.ascent(); - int const d = dim.descent(); + cell(1).draw(pi, x + w + 4, y); int xp[4]; int yp[4]; pi.pain.line(x + dim.width(), y - a + 1, - x + w + 4, y - a + 1, Color_math); + 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, Color_math); - drawMarkers(pi, x, y); + pi.pain.lines(xp, yp, 4, pi.base.font.color()); } void InsetMathRoot::write(WriteStream & os) const { + MathEnsurer ensurer(os); os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}'; } @@ -117,4 +141,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