[LyX/master] Fix bug #12169 Patch from Daniel.

Richard Kimberly Heck rikiheck at lyx.org
Sat Feb 27 18:22:36 UTC 2021


commit 0895b76f1ed8d984d766b185b425346b3f020cd4
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Sat Feb 27 13:27:03 2021 -0500

    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 c8e2145..3af85aa 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 94ee460..41427ab 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 30d7fe3..75e9ace 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<QPoint> 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 b5f61c1..f3b521b 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


More information about the lyx-cvs mailing list