]> git.lyx.org Git - features.git/commitdiff
Improve metrics of equations. More work remains to be done.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 19 Feb 2018 17:24:29 +0000 (18:24 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 19 Feb 2018 17:36:33 +0000 (18:36 +0100)
Use proper value for above/below skip (12pt) instead of the hardcoded
12 pixels.

Add forgotten skip before display math preview.

Make "too small preview" size dpi-dependent.
Make gap in front of equation (what is it good for, BTW?) dpi-dependent.

src/mathed/InsetMathHull.cpp
src/mathed/InsetMathHull.h

index 287c169f0cffa18d4b50bad1652640dc4ed218dc..8f40d2cff1fbb7e31cbb64d814b3fc5252e08226 100644 (file)
@@ -525,22 +525,37 @@ bool InsetMathHull::previewState(const BufferView *const bv) const
 
 
 namespace {
-static const int ERROR_FRAME_WIDTH = 2;
+const int ERROR_FRAME_WIDTH = 2;
+
+bool previewTooSmall(MetricsBase const & mb, Dimension const & dim)
+{
+       // Value was hardcoded to 10 pixels
+       int const minval = mb.bv->zoomedPixels(10);
+       return dim.width() <= minval && dim.height() <= minval;
+}
 }
 
+
 void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       // true value in LaTeX is 12pt plus 3pt minus 9pt
+       // FIXME: even better would be to handle the short skip case.
+       int const display_margin = display() ? mi.base.inPixels(Length(12, Length::PT)) : 0;
+
        if (previewState(mi.base.bv)) {
                preview_->metrics(mi, dim);
-               if (previewTooSmall(dim)) {
+               if (previewTooSmall(mi.base, dim)) {
                        // preview image is too small
                        dim.wid += 2 * ERROR_FRAME_WIDTH;
                        dim.asc += 2 * ERROR_FRAME_WIDTH;
                } else {
-                       // insert a one pixel gap in front of the formula
-                       dim.wid += 1;
-                       if (display())
-                               dim.des += displayMargin();
+                       // insert a gap in front of the formula
+                       // value was hardcoded to 1 pixel
+                       dim.wid += mi.base.bv->zoomedPixels(1) ;
+                       if (display()) {
+                               dim.asc += display_margin;
+                               dim.des += display_margin;
+                       }
                }
                return;
        }
@@ -553,8 +568,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
        InsetMathGrid::metrics(mi, dim);
 
        if (display()) {
-               dim.asc += displayMargin();
-               dim.des += displayMargin();
+               dim.asc += display_margin;
+               dim.des += display_margin;
        }
 
        if (numberedType()) {
@@ -580,18 +595,12 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
-bool InsetMathHull::previewTooSmall(Dimension const & dim) const
-{
-       return dim.width() <= 10 && dim.height() <= 10;
-}
-
-
 ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const
 {
        BufferView const * const bv = pi.base.bv;
        if (previewState(bv)) {
                Dimension const dim = dimension(*pi.base.bv);
-               if (previewTooSmall(dim))
+               if (previewTooSmall(pi.base, dim))
                        return Color_error;
                return graphics::PreviewLoader::backgroundColor();
        }
@@ -621,7 +630,7 @@ void InsetMathHull::drawMarkers(PainterInfo & pi, int x, int y) const
 void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
 {
        Dimension const dim = dimension(*pi.base.bv);
-       if (previewTooSmall(dim)) {
+       if (previewTooSmall(pi.base, dim)) {
                pi.pain.fillRectangle(x, y - 2 * ERROR_FRAME_WIDTH,
                    dim.wid, dim.asc + dim.des, backgroundColor(pi));
                return;
@@ -645,12 +654,14 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
                // already.
                Changer dummy = !canPaintChange(*bv) ? make_change(pi.change_, Change())
                        : Changer();
-               if (previewTooSmall(dim)) {
+               if (previewTooSmall(pi.base, dim)) {
                        // we have an extra frame
                        preview_->draw(pi, x + ERROR_FRAME_WIDTH, y);
                } else {
                        // one pixel gap in front
-                       preview_->draw(pi, x + 1, y);
+                       // value was hardcoded to 1 pixel
+                       int const gap = pi.base.bv->zoomedPixels(1) ;
+                       preview_->draw(pi, x + gap, y);
                }
                return;
        }
index 2863b727fb76f9adba47d7c129516bc10bdd9267..89c05043634c5d83373b421fa352cffaf2a2bab9 100644 (file)
@@ -175,9 +175,6 @@ public:
        ///
        void initUnicodeMath() const;
 
-       ///
-       static int displayMargin() { return 12; }
-
        /// Force inset into LTR environment if surroundings are RTL
        virtual bool forceLTR() const { return true; }
        ///
@@ -305,8 +302,6 @@ protected:
        void handleFont2(Cursor & cur, docstring const & arg);
        ///
        bool previewState(BufferView const * const bv) const;
-       ///
-       bool previewTooSmall(Dimension const & dim) const;
 };