]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetSpace.cpp
* src/insets/InsetSpace.cpp:
[lyx.git] / src / insets / InsetSpace.cpp
index 86e690a77744b4433b2e97cd60016c304273d6df..ff4091d2427d00f3059940206709001cf50610d2 100644 (file)
@@ -207,7 +207,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
                        break;
                case InsetSpaceParams::CUSTOM:
                case InsetSpaceParams::CUSTOM_PROTECTED:
-                       dim.wid = params_.length.inBP();
+                       dim.wid = max(4, abs(params_.length.inBP()));
                        break;
                case InsetSpaceParams::HFILL:
                case InsetSpaceParams::HFILL_PROTECTED:
@@ -232,7 +232,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
        if (isStretchableSpace()) {
                int const asc = theFontMetrics(pi.base.font).ascent('M');
                int const desc = theFontMetrics(pi.base.font).descent('M');
-               //Pixel height divisible by 2 for prettier fill graphics:
+               // Pixel height divisible by 2 for prettier fill graphics:
                int const oddheight = (asc ^ desc) & 1;
                int const x0 = x + 1;
                int const x1 = x + dim.wid - 2;
@@ -241,7 +241,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
                int const y2 = (y0 + y1) / 2;
                int xoffset = (y0 - y1) / 2;
 
-               //Two tests for very narrow insets
+               // Two tests for very narrow insets
                if (xoffset > x1 - x0
                     && (params_.kind == InsetSpaceParams::LEFTARROWFILL
                         || params_.kind == InsetSpaceParams::RIGHTARROWFILL))
@@ -319,6 +319,12 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
        xp[3] = x + w;
        yp[3] = y - max(h / 4, 1);
 
+       if (params_.length.inBP() < 0) {
+               // turn symbol upside down. A prettier solution would use
+               // inverted arrows (like in VSpace).
+               swap(yp[0], yp[1]);
+               swap(yp[2], yp[3]);
+       }
        if (params_.kind == InsetSpaceParams::PROTECTED ||
            params_.kind == InsetSpaceParams::ENSPACE ||
            params_.kind == InsetSpaceParams::NEGTHIN ||
@@ -441,13 +447,12 @@ void InsetSpaceParams::read(Lexer & lex)
 
        if (lex.checkFor("\\length"))
                lex >> length;
-       lex >> "\\end_inset";
 }
 
 
 void InsetSpace::write(ostream & os) const
 {
-       os << "Space ";
+       os << "space ";
        params_.write(os);
 }
 
@@ -455,6 +460,7 @@ void InsetSpace::write(ostream & os) const
 void InsetSpace::read(Lexer & lex)
 {
        params_.read(lex);
+       lex >> "\\end_inset";
 }
 
 
@@ -632,7 +638,11 @@ void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
        lex.setContext("InsetSpace::string2params");
        lex >> "space";
 
-       params.read(lex);
+       // There are cases, such as when we are called via getStatus() from
+       // Dialog::canApply(), where we are just called with "space" rather
+       // than a full "space \type{}\n\\end_inset".
+       if (lex.isOK())
+               params.read(lex);
 }