I noticed that the corners of rectangles in LyX are drawn bevel instead
of a pointy since they are drawn with the Qt default, see
https://doc.qt.io/qt-5/qpen.html#QPen-3
https://doc.qt.io/qt-5/qt.html#PenJoinStyle-enum
I don't think the bevel corners are intentional in LyX and the attached
patch is intended to fix this. One effect is that the corners of insets
are pointy, see before and after pictures attached.
You might have wondered what the strange gap in the label is. This is
fixed at https://www.lyx.org/trac/ticket/10323.
--
Daniel
From e63300afcff62e0e4ebe413c5279cfe6b76e0a81 Mon Sep 17 00:00:00 2001
From: Daniel Ramoeller <d....@web.de>
Date: Thu, 6 Aug 2020 09:39:55 +0200
Subject: [PATCH] Fix for non-pointy rectangles
The default to join lines in Qt is bevel (Qt::BevelJoin) but for rectangles it
should be pointy (Qt::MiterJoin).
---
src/frontends/NullPainter.h | 2 +-
src/frontends/Painter.h | 11 ++++++++++-
src/frontends/qt/GuiPainter.cpp | 18 +++++++++++++++---
src/frontends/qt/GuiPainter.h | 5 +++--
4 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/src/frontends/NullPainter.h b/src/frontends/NullPainter.h
index 55a773e09c..d6f8b909de 100644
--- a/src/frontends/NullPainter.h
+++ b/src/frontends/NullPainter.h
@@ -45,7 +45,7 @@ public:
/// draw a rectangle
void rectangle(int, int, int, int, Color,
- line_style = line_solid, int = thin_line) {}
+ line_style = line_solid, int = thin_line, join_style =
join_miter) {}
/// draw a filled rectangle
void fillRectangle(int, int, int, int, Color) {}
diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h
index 718718f979..289ae693de 100644
--- a/src/frontends/Painter.h
+++ b/src/frontends/Painter.h
@@ -63,6 +63,14 @@ public:
line_onoffdash //< dashes with spaces
};
+ /// possible join styles
+ enum join_style {
+ join_bevel,
+ join_miter,
+ join_round,
+ join_svg_miter
+ };
+
/// possible fill styles
enum fill_style {
fill_none,
@@ -113,7 +121,8 @@ public:
/// 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;
+ line_style = line_solid, int line_width = thin_line,
+ join_style join = join_miter) = 0;
/// draw a filled rectangle
virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
diff --git a/src/frontends/qt/GuiPainter.cpp b/src/frontends/qt/GuiPainter.cpp
index d9074cb427..2709b1d003 100644
--- a/src/frontends/qt/GuiPainter.cpp
+++ b/src/frontends/qt/GuiPainter.cpp
@@ -57,7 +57,7 @@ GuiPainter::~GuiPainter()
void GuiPainter::setQPainterPen(QColor const & col,
- Painter::line_style ls, int lw)
+ Painter::line_style ls, int lw, join_style join)
{
if (col == current_color_ && ls == current_ls_ && lw == current_lw_)
return;
@@ -79,6 +79,17 @@ void GuiPainter::setQPainterPen(QColor const & col,
pen.setWidth(lw);
+ switch (join) {
+ case join_bevel:
+ pen.setJoinStyle(Qt::BevelJoin); break;
+ case join_miter:
+ pen.setJoinStyle(Qt::MiterJoin); break;
+ case join_round:
+ pen.setJoinStyle(Qt::RoundJoin); break;
+ case join_svg_miter:
+ pen.setJoinStyle(Qt::SvgMiterJoin); break;
+ }
+
setPen(pen);
}
@@ -208,9 +219,10 @@ void GuiPainter::path(int const * xp, int const * yp,
void GuiPainter::rectangle(int x, int y, int w, int h,
Color col,
line_style ls,
- int lw)
+ int lw,
+ join_style join)
{
- setQPainterPen(computeColor(col), ls, lw);
+ setQPainterPen(computeColor(col), ls, lw, join);
drawRect(x, y, w, h);
}
diff --git a/src/frontends/qt/GuiPainter.h b/src/frontends/qt/GuiPainter.h
index 22d69a7fe3..6d1f2dc3e5 100644
--- a/src/frontends/qt/GuiPainter.h
+++ b/src/frontends/qt/GuiPainter.h
@@ -86,7 +86,8 @@ public:
int w, int h,
Color,
line_style = line_solid,
- int lw = thin_line);
+ int lw = thin_line,
+ join_style = join_miter);
/// draw a filled rectangle
virtual void fillRectangle(
@@ -178,7 +179,7 @@ private:
/// set pen parameters
void setQPainterPen(QColor const & col,
- line_style ls = line_solid, int lw = thin_line);
+ line_style ls = line_solid, int lw = thin_line, join_style join
= join_bevel);
// Direction for painting text
enum Direction { LtR, RtL, Auto };
--
2.24.3 (Apple Git-128)
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel