]> git.lyx.org Git - lyx.git/commitdiff
Partial support for units
authorMartin Vermeer <martin.vermeer@hut.fi>
Wed, 12 Sep 2007 08:15:33 +0000 (08:15 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Wed, 12 Sep 2007 08:15:33 +0000 (08:15 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20236 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ui/stdtoolbars.inc
src/LaTeXFeatures.cpp
src/mathed/InsetMathFrac.cpp
src/mathed/InsetMathFrac.h
src/mathed/MathFactory.cpp

index 1431a67e5c93a047ac3d6c8cee8cbaabde7e84a1..f1fb9c2bbddf7446dc980b1cf5be20f487259156 100644 (file)
@@ -273,7 +273,8 @@ ToolbarSet
        Toolbar "frac-square" "Fractions"
                Item "Standard  \\frac" "math-insert \frac"
                Item "No hor. line      \\atop" "math-insert \atop"
-               Item "Nice      \\nicefrac" "math-insert \nicefrac"
+               Item "Nice (3/4)        \\nicefrac" "math-insert \nicefrac"
+               Item "Units (km/h)      \\unitfrac" "math-insert \unitfrac"
                Item "Text frac (amsmath)       \\tfrac" "math-insert \tfrac"
                Item "Display frac (amsmath)    \\dfrac" "math-insert \dfrac"
                Item "Binomial  \\choose"  "math-insert \choose"
index a76cceda9ef9d5b9fe1128ef86d953f86b82368b..a9ff651aa879c832c97df02625573bc603e80253 100644 (file)
@@ -403,7 +403,7 @@ char const * simplefeatures[] = {
        "dvipost",
        "fancybox",
        "calc",
-       "nicefrac",
+       "units",
        "tipa",
        "framed",
        "pdfcolmk",
index b77dc0f5084ccdd03669cb4508cc91fc442dbe6f..867b04d96a8c36c71dfe45d1e45f83db7355818c 100644 (file)
@@ -54,6 +54,11 @@ bool InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.wid = cell(0).width() + cell(1).width() + 5;
                dim.asc = cell(0).height() + 5;
                dim.des = cell(1).height() - 5;
+       } else if (kind_ == UNITFRAC) {
+               ShapeChanger dummy2(mi.base.font, Font::UP_SHAPE);
+               dim.wid = cell(0).width() + cell(1).width() + 5;
+               dim.asc = cell(0).height() + 5;
+               dim.des = cell(1).height() - 5;
        } else {
                dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
                dim.asc = cell(0).height() + 2 + 5;
@@ -77,16 +82,24 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
                                y - cell(0).descent() - 5);
                cell(1).draw(pi, x + cell(0).width() + 5,
                                y + cell(1).ascent() / 2);
-               pi.pain.line(x + cell(0).width(),
-                               y + dim_.des - 2,
-                               x + cell(0).width() + 5,
-                               y - dim_.asc + 2, Color::math);
+       } else if (kind_ == UNITFRAC) {
+               ShapeChanger dummy2(pi.base.font, Font::UP_SHAPE);
+               cell(0).draw(pi, x + 2,
+                               y - cell(0).descent() - 5);
+               cell(1).draw(pi, x + cell(0).width() + 5,
+                               y + cell(1).ascent() / 2);
        } else {
                cell(0).draw(pi, m - cell(0).width() / 2,
                                y - cell(0).descent() - 2 - 5);
                cell(1).draw(pi, m - cell(1).width() / 2,
                                y + cell(1).ascent()  + 2 - 5);
        }
+       if (kind_ == NICEFRAC || kind_ == UNITFRAC) {
+               pi.pain.line(x + cell(0).width(),
+                               y + dim_.des - 2,
+                               x + cell(0).width() + 5,
+                               y - dim_.asc + 2, Color::math);
+       }
        if (kind_ == FRAC || kind_ == OVER)
                pi.pain.line(x + 1, y - 5,
                                x + dim_.wid - 2, y - 5, Color::math);
@@ -111,7 +124,7 @@ void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
        cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
        cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
        // ASCII art: ignore niceties
-       if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC)
+       if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC || kind_ == UNITFRAC)
                pain.horizontalLine(x, y, dim_.width());
 }
 
@@ -128,6 +141,7 @@ void InsetMathFrac::write(WriteStream & os) const
                break;
        case FRAC:
        case NICEFRAC:
+       case UNITFRAC:
                InsetMathNest::write(os);
                break;
        }
@@ -143,6 +157,8 @@ docstring InsetMathFrac::name() const
                return from_ascii("over");
        case NICEFRAC:
                return from_ascii("nicefrac");
+       case UNITFRAC:
+               return from_ascii("unitfrac");
        case ATOP:
                return from_ascii("atop");
        }
@@ -183,8 +199,8 @@ void InsetMathFrac::mathmlize(MathStream & os) const
 
 void InsetMathFrac::validate(LaTeXFeatures & features) const
 {
-       if (kind_ == NICEFRAC)
-               features.require("nicefrac");
+       if (kind_ == NICEFRAC || kind_ == UNITFRAC)
+               features.require("units");
        InsetMathNest::validate(features);
 }
 
index c03157bdaacbbee2cc674e7fee838d902a2bc428..9b7a0ad3be6f8b781b637a609a299502ac1df3ee 100644 (file)
@@ -27,7 +27,8 @@ public:
                FRAC,
                OVER,
                ATOP,
-               NICEFRAC
+               NICEFRAC,
+               UNITFRAC
        };
 
        ///
index 85d0b3f60b7aed36852229508541c0856afdb675..20af5fc592af4fe7327feeaccd70369ddc30cb4a 100644 (file)
@@ -370,6 +370,8 @@ MathAtom createInsetMath(docstring const & s)
                return MathAtom(new InsetMathFrac(InsetMathFrac::OVER));
        if (s == "nicefrac")
                return MathAtom(new InsetMathFrac(InsetMathFrac::NICEFRAC));
+       if (s == "unitfrac")
+               return MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC));
        //if (s == "infer")
        //      return MathAtom(new MathInferInset);
        if (s == "atop")