[LyX/master] When drawing macro names, enforce LtR direction

Jean-Marc Lasgouttes lasgouttes at lyx.org
Fri Sep 22 09:38:42 UTC 2023


commit 94c6d45b74f815c8c924ed88b30f246201733f05
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Fri Sep 22 12:41:44 2023 +0200

    When drawing macro names, enforce LtR direction
    
    Add a Direction parameter to the Painter::text methods that take a
    FontInfo parameter.
    
    In drawStrRed and drawStrBlack, force the direction to LtR.
    
    Fixes bug #12905.
---
 src/frontends/NullPainter.h     |    4 ++--
 src/frontends/Painter.h         |    9 +++++++--
 src/frontends/qt/GuiPainter.cpp |    8 ++++----
 src/frontends/qt/GuiPainter.h   |    9 ++++-----
 src/mathed/MathSupport.cpp      |    4 ++--
 5 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/frontends/NullPainter.h b/src/frontends/NullPainter.h
index 3af85aa..bec16fa 100644
--- a/src/frontends/NullPainter.h
+++ b/src/frontends/NullPainter.h
@@ -65,10 +65,10 @@ public:
 	void image(int, int, int, int, graphics::Image const &, bool) override {}
 
 	/// draw a string
-	void text(int, int, docstring const &, FontInfo const &) override {}
+	void text(int, int, docstring const &, FontInfo const &, Direction const = Auto) override {}
 
 	/// draw a char
-	void text(int, int, char_type, FontInfo const &) override {}
+	void text(int, int, char_type, FontInfo const &, Direction const = Auto) override {}
 
 	/// draw a string
 	void text(int, int, docstring const &, Font const &, double, double) override {}
diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h
index 41427ab..6095334 100644
--- a/src/frontends/Painter.h
+++ b/src/frontends/Painter.h
@@ -134,11 +134,16 @@ public:
 	virtual void image(int x, int y, int w, int h,
 		graphics::Image const & image, bool const revert_in_darkmode = false) = 0;
 
+	// Direction for painting text
+	enum Direction { LtR, RtL, Auto };
+
 	/// draw a string at position x, y (y is the baseline).
-	virtual void text(int x, int y, docstring const & str, FontInfo const & f) = 0;
+	virtual void text(int x, int y, docstring const & str, FontInfo const & f,
+	                  Direction const dir = Auto) = 0;
 
 	/// draw a char at position x, y (y is the baseline)
-	virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
+	virtual void text(int x, int y, char_type c, FontInfo const & f,
+	                  Direction const dir = Auto) = 0;
 
 	/** draw a string at position x, y (y is the baseline). The
 	 * text direction is enforced by the \c Font.
diff --git a/src/frontends/qt/GuiPainter.cpp b/src/frontends/qt/GuiPainter.cpp
index 62e48c4..7110910 100644
--- a/src/frontends/qt/GuiPainter.cpp
+++ b/src/frontends/qt/GuiPainter.cpp
@@ -282,15 +282,15 @@ void GuiPainter::image(int x, int y, int w, int h, graphics::Image const & i,
 }
 
 
-void GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
+void GuiPainter::text(int x, int y, char_type c, FontInfo const & f, Direction const dir)
 {
-	text(x, y, docstring(1, c), f);
+	text(x, y, docstring(1, c), f, dir);
 }
 
 
-void GuiPainter::text(int x, int y, docstring const & s, FontInfo const & f)
+void GuiPainter::text(int x, int y, docstring const & s, FontInfo const & f, Direction const dir)
 {
-	text(x, y, s, f, Auto, 0.0, 0.0);
+	text(x, y, s, f, dir, 0.0, 0.0);
 }
 
 
diff --git a/src/frontends/qt/GuiPainter.h b/src/frontends/qt/GuiPainter.h
index 522b83c..932072e 100644
--- a/src/frontends/qt/GuiPainter.h
+++ b/src/frontends/qt/GuiPainter.h
@@ -116,10 +116,12 @@ public:
 		lyx::graphics::Image const & image, bool const darkmode = false) override;
 
 	/// draw a string at position x, y (y is the baseline).
-	void text(int x, int y, docstring const & str, FontInfo const & f) override;
+	void text(int x, int y, docstring const & str, FontInfo const & f,
+	          Direction const dir = Auto) override;
 
 	/// draw a char at position x, y (y is the baseline)
-	void text(int x, int y, char_type c, FontInfo const & f) override;
+	void text(int x, int y, char_type c, FontInfo const & f,
+	          Direction const dir = Auto) override;
 
 	/** draw a string at position x, y (y is the baseline). The
 	 * text direction is enforced by the \c Font.
@@ -188,9 +190,6 @@ private:
 		line_style ls = line_solid, int lw = thin_line,
 		Qt::PenJoinStyle js = Qt::BevelJoin);
 
-	// Direction for painting text
-	enum Direction { LtR, RtL, Auto };
-
 	// Real text() method
 	void text(int x, int y, docstring const & s,
               FontInfo const & f, Direction const dir,
diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp
index 1601920..b71c46e 100644
--- a/src/mathed/MathSupport.cpp
+++ b/src/mathed/MathSupport.cpp
@@ -805,7 +805,7 @@ void drawStrRed(PainterInfo & pi, int x, int y, docstring const & str)
 	FontInfo f = pi.base.font;
 	augmentFont(f, "mathnormal");
 	f.setColor(Color_latex);
-	pi.pain.text(x, y, str, f);
+	pi.pain.text(x, y, str, f, Painter::LtR);
 }
 
 
@@ -814,7 +814,7 @@ void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & str)
 	FontInfo f = pi.base.font;
 	augmentFont(f, "mathnormal");
 	f.setColor(Color_foreground);
-	pi.pain.text(x, y, str, f);
+	pi.pain.text(x, y, str, f, Painter::LtR);
 }
 
 


More information about the lyx-cvs mailing list