From 0895b76f1ed8d984d766b185b425346b3f020cd4 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Sat, 27 Feb 2021 13:27:03 -0500 Subject: [PATCH] Fix bug #12169 Patch from Daniel. --- src/frontends/NullPainter.h | 2 +- src/frontends/Painter.h | 2 +- src/frontends/qt/GuiPainter.cpp | 21 ++++++++++++++------- src/frontends/qt/GuiPainter.h | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/frontends/NullPainter.h b/src/frontends/NullPainter.h index c8e2145884..3af85aa6b2 100644 --- a/src/frontends/NullPainter.h +++ b/src/frontends/NullPainter.h @@ -105,7 +105,7 @@ public: /// leave monochrome painting mode void leaveMonochromeMode() override {} /// draws a wavy line that can be used for underlining. - void wavyHorizontalLine(int, int, int, ColorCode) override {} + void wavyHorizontalLine(FontInfo const &, int, int, int, ColorCode) override {} }; } // namespace frontend diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h index 94ee4606c0..41427ab3e0 100644 --- a/src/frontends/Painter.h +++ b/src/frontends/Painter.h @@ -186,7 +186,7 @@ public: /// leave monochrome painting mode virtual void leaveMonochromeMode() = 0; /// draws a wavy line that can be used for underlining. - virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0; + virtual void wavyHorizontalLine(FontInfo const & f, int x, int y, int width, ColorCode col) = 0; private: /// Ratio between physical pixels and device-independent pixels double pixel_ratio_; diff --git a/src/frontends/qt/GuiPainter.cpp b/src/frontends/qt/GuiPainter.cpp index 30d7fe3925..75e9ace9e2 100644 --- a/src/frontends/qt/GuiPainter.cpp +++ b/src/frontends/qt/GuiPainter.cpp @@ -406,7 +406,7 @@ void GuiPainter::textDecoration(FontInfo const & f, int x, int y, int width) doubleUnderline(f, x, y, width); if (f.uwave() == FONT_ON) // f.color() doesn't work on some circumstances - wavyHorizontalLine(x, y, width, f.realColor().baseColor); + wavyHorizontalLine(f, x, y, width, f.realColor().baseColor); } @@ -546,21 +546,28 @@ void GuiPainter::dashedUnderline(FontInfo const & f, int x, int y, int width) } -void GuiPainter::wavyHorizontalLine(int x, int y, int width, ColorCode col) +void GuiPainter::wavyHorizontalLine(FontInfo const & f, int x, int y, int width, ColorCode col) { - setQPainterPen(computeColor(col)); - int const step = 2; + FontMetrics const & fm = theFontMetrics(f); + int const pos = fm.underlinePos(); + + setQPainterPen(computeColor(col), line_solid, fm.lineWidth()); + int const step = 2 * fm.lineWidth(); int const xend = x + width; - int height = 1; + int height = 1 * fm.lineWidth(); //FIXME: I am not sure if Antialiasing gives the best effect. //setRenderHint(Antialiasing, true); + QVector points; while (x < xend) { height = - height; - drawLine(x, y - height, x + step, y + height); + points.append(QPoint(x, y + pos - height)); + points.append(QPoint(x + step, y + pos + height)); x += step; - drawLine(x, y + height, x + step/2, y + height); + points.append(QPoint(x, (qreal)y + pos + height)); + points.append(QPoint(x + step/2, y + pos + height)); x += step/2; } + drawPolyline(points); //setRenderHint(Antialiasing, false); } diff --git a/src/frontends/qt/GuiPainter.h b/src/frontends/qt/GuiPainter.h index b5f61c1dcc..f3b521bcc0 100644 --- a/src/frontends/qt/GuiPainter.h +++ b/src/frontends/qt/GuiPainter.h @@ -160,7 +160,7 @@ public: int preeditText(int x, int y, char_type c, FontInfo const & f, preedit_style style) override; - void wavyHorizontalLine(int x, int y, int width, ColorCode col) override; + void wavyHorizontalLine(FontInfo const & f, int x, int y, int width, ColorCode col) override; private: /// check the font, and if set, draw an underline -- 2.39.5