On Tue, Jan 19, 2016 at 05:27:47PM -0500, Guillaume Munch wrote:
> Le 19/01/2016 16:44, Enrico Forestieri a écrit :
> >On Mon, Jan 18, 2016 at 10:37:23PM -0500, Guillaume Munch wrote:
> >>
> >>Enrico: the width of the line of the plain separator changed, as you can
> >>see, which I guess was not intended.
> >
> >For the new symbol I used the width of 'n' instead of 'm'. As both kind
> >share the same base width, I tried to compensate choosing the width of
> >the plain separator as 8 times the width of 'n', while it previously
> >was 5 times the width of 'm'. I didn't care to measure the widths as I
> >deemed it not so important. Note also that this is font dependent.
> >You are welcome to suggest something different than 8 if you find it
> >is too large or too narrow with respect to the previous width.
> >
> 
> I do not mind so much about the width itself. However what my screenshot
> showed is that the line is shorter than the actual width of the spearator.
> As you can see the paragraph mark is further on the right, which maybe is
> confusing, and I thought was not intended.
> 
> If this is really intended, tell me and I will review your patch. Otherwise
> I will be waiting for a corrected patch.

Sorry, I misunderstood. I had updated the width in metrics() but forgot to
do it in draw(). Updated patch attached.

-- 
Enrico
diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h
index d077a1f..c72d813 100644
--- a/src/frontends/Painter.h
+++ b/src/frontends/Painter.h
@@ -95,6 +95,23 @@ public:
                fill_style = fill_none, line_style = line_solid,
                int line_width = thin_line) = 0;
 
+       /**
+        * path -  draw a path with bezier curves
+        * @param xp array of points' x co-ords
+        * @param yp array of points' y co-ords
+        * @param c1x array of first control points' x co-ords
+        * @param c1y array of first control points' y co-ords
+        * @param c2x array of second control points' x co-ords
+        * @param c2y array of second control points' y co-ords
+        * @param np size of the points array
+        */
+       virtual void path(int const * xp, int const * yp,
+               int const * c1x, int const * c1y,
+               int const * c2x, int const * c2y,
+               int np, Color,
+               fill_style = fill_none, line_style = line_solid,
+               int line_width = thin_line) = 0;
+
        /// draw a rectangle
        virtual void rectangle(int x, int y, int w, int h, Color,
                line_style = line_solid, int line_width = thin_line) = 0;
diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp
index 2b024d8..9407825 100644
--- a/src/frontends/qt4/GuiPainter.cpp
+++ b/src/frontends/qt4/GuiPainter.cpp
@@ -229,6 +229,40 @@ void GuiPainter::lines(int const * xp, int const * yp, int 
np,
 }
 
 
+void GuiPainter::path(int const * xp, int const * yp,
+       int const * c1x, int const * c1y,
+       int const * c2x, int const * c2y,
+       int np,
+       Color col,
+       fill_style fs,
+       line_style ls,
+       int lw)
+{
+       if (!isDrawingEnabled())
+               return;
+
+       QPainterPath bpath;
+       bpath.moveTo(xp[0], yp[0]);
+
+       for (int i = 1; i < np; ++i) {
+               bool line = c1x[i] == xp[i - 1] && c1y[i] == yp[i - 1] &&
+                           c2x[i] == xp[i] && c2y[i] == yp[i];
+               if (line)
+                       bpath.lineTo(xp[i], yp[i]);
+               else
+                       bpath.cubicTo(c1x[i], c1y[i],  c2x[i], c2y[i], xp[i], 
yp[i]);
+       }
+       QColor const color = computeColor(col);
+       setQPainterPen(color, ls, lw);
+       bool const text_is_antialiased = renderHints() & TextAntialiasing;
+       setRenderHint(Antialiasing, text_is_antialiased);
+       drawPath(bpath);
+       if (fs != fill_none)
+               fillPath(bpath, QBrush(color));
+       setRenderHint(Antialiasing, false);
+}
+
+
 void GuiPainter::rectangle(int x, int y, int w, int h,
        Color col,
        line_style ls,
diff --git a/src/frontends/qt4/GuiPainter.h b/src/frontends/qt4/GuiPainter.h
index eadf985..3819ff3 100644
--- a/src/frontends/qt4/GuiPainter.h
+++ b/src/frontends/qt4/GuiPainter.h
@@ -18,6 +18,7 @@
 #include "frontends/Painter.h"
 
 #include <QPainter>
+#include <QPainterPath>
 #include <stack>
 
 class QString;
@@ -59,6 +60,23 @@ public:
                line_style ls = line_solid,
                int lw = thin_line);
 
+       /**
+        * path -  draw a path with bezier curves
+        * @param xp array of points' x co-ords
+        * @param yp array of points' y co-ords
+        * @param c1x array of first control points' x co-ords
+        * @param c1y array of first control points' y co-ords
+        * @param c2x array of second control points' x co-ords
+        * @param c2y array of second control points' y co-ords
+        * @param np size of the points array
+        */
+       virtual void path(int const * xp, int const * yp,
+               int const * c1x, int const * c1y,
+               int const * c2x, int const * c2y,
+               int np, Color,
+               fill_style = fill_none, line_style = line_solid,
+               int line_width = thin_line);
+
        /// draw a rectangle
        virtual void rectangle(
                int x, int y,
diff --git a/src/insets/InsetSeparator.cpp b/src/insets/InsetSeparator.cpp
index 7fb7c64..b01a857 100644
--- a/src/insets/InsetSeparator.cpp
+++ b/src/insets/InsetSeparator.cpp
@@ -176,9 +176,9 @@ void InsetSeparator::metrics(MetricsInfo & mi, Dimension & 
dim) const
        frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
        dim.asc = fm.maxAscent();
        dim.des = fm.maxDescent();
-       dim.wid = fm.width('m');
+       dim.wid = fm.width('n');
        if (params_.kind == InsetSeparatorParams::PLAIN)
-               dim.wid *= 5;
+               dim.wid *= 8;
 }
 
 
@@ -188,52 +188,73 @@ void InsetSeparator::draw(PainterInfo & pi, int x, int y) 
const
        font.setColor(ColorName());
 
        frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
-       int const wid = fm.width('m');
+       int const wid = fm.width('n');
        int const asc = fm.maxAscent();
 
-       int xp[3];
-       int yp[3];
+       int xp[6];
+       int yp[6];
 
        if (params_.kind == InsetSeparatorParams::PLAIN) {
                yp[0] = int(y - 0.500 * asc * 0.75);
                yp[1] = int(y - 0.500 * asc * 0.75);
 
                xp[0] = int(x);
-               xp[1] = int(x + wid * 5);
+               xp[1] = int(x + wid * 8);
 
                pi.pain.lines(xp, yp, 2, ColorName());
        } else {
-               yp[0] = int(y - 0.875 * asc * 0.5);
-               yp[1] = int(y - 0.500 * asc * 0.5);
-               yp[2] = int(y - 0.125 * asc * 0.5);
+               yp[0] = int(y - 0.500 * asc * 0.5);
+               yp[1] = int(y - 0.250 * asc * 0.5);
+               yp[2] = int(y);
 
                if (pi.ltr_pos) {
-                       xp[0] = int(x + wid * 0.375);
-                       xp[1] = int(x);
-                       xp[2] = int(x + wid * 0.375);
+                       xp[0] = int(x + 1 + wid * 0.375);
+                       xp[1] = int(x + 1);
                } else {
-                       xp[0] = int(x + wid * 0.625);
-                       xp[1] = int(x + wid);
-                       xp[2] = int(x + wid * 0.625);
+                       xp[0] = int(x - 1 + wid * 0.625);
+                       xp[1] = int(x - 1 + wid);
                }
+               xp[2] = xp[0];
 
                pi.pain.lines(xp, yp, 3, ColorName(), Painter::fill_oddeven);
 
-               yp[0] = int(y - 0.500 * asc * 0.5);
-               yp[1] = int(y - 0.500 * asc * 0.5);
-               yp[2] = int(y - asc * 0.5);
+               yp[0] = yp[1];
+               yp[2] = int(y - 1.250 * asc * 0.5);
+               yp[3] = yp[2];
+               yp[4] = int(y - 0.750 * asc * 0.5);
+               yp[5] = yp[4];
 
+               xp[0] = xp[1];
                if (pi.ltr_pos) {
-                       xp[0] = int(x);
                        xp[1] = int(x + wid);
-                       xp[2] = int(x + wid);
+                       xp[2] = xp[1];
+                       xp[3] = int(x + wid * 0.75);
                } else {
-                       xp[0] = int(x + wid);
                        xp[1] = int(x);
-                       xp[2] = int(x);
+                       xp[2] = xp[1];
+                       xp[3] = int(x + wid * 0.25);
                }
+               xp[4] = xp[3];
+               xp[5] = xp[1];
+
+               int c1x[6];
+               int c1y[6];
+               int c2x[6];
+               int c2y[6];
+
+               for (int i = 1; i < 6; ++i) {
+                       c1x[i] = xp[i - 1];
+                       c1y[i] = yp[i - 1];
+                       c2x[i] = xp[i];
+                       c2y[i] = yp[i];
+               }
+
+               int d = pi.ltr_pos ? yp[3] - yp[4] : yp[4] - yp[3];
+
+               c1x[4] += d;
+               c2x[4] += d;
 
-               pi.pain.lines(xp, yp, 3, ColorName());
+               pi.pain.path(xp, yp, c1x, c1y, c2x, c2y, 6, ColorName());
        }
 }
 

Reply via email to