Le 22/07/2015 12:05, Jean-Marc Lasgouttes a écrit :
Now for something different... I have been annoyed by the looks of
InsetNewLine for some time now. The following patch replaces the
horrible hand-made arrow with a nice Unicode character.

Not only that, but you have 3 different characters to play with! Can you
imagine a funnier activity that trying out this patch and giving feedback?

JMarc

PS: I know that I broke the weird 'break but keep justified' symbol. In
any case, if we keep this patch, it is better to actually keep the row
justified rather to indicate this with a cryptic sign.

Here is a new version of the patch. Is that OK for master? Note that I have not changed anything related to on-screen justification (yet!).

JMarc




>From 2d78129b5b8991e15a281d47f32f018ddf85385c Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Wed, 22 Jul 2015 10:52:33 +0200
Subject: [PATCH] Replace hand-drawn newline by a proper unicode character.

At the same time, the LINEBREAK type of newline is rendered with an
inverted newline character. The color coding is thus suppressed. It
seems better to me to use color coding for different classes of
elements rather than different versions of the same element.

There are several possible possibile characters in the source, so that
we can experiment.
---
 src/insets/InsetNewline.cpp |  143 ++++++++++++-------------------------------
 src/insets/InsetNewline.h   |    4 +-
 2 files changed, 41 insertions(+), 106 deletions(-)

diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
index 0927c7e..cd19595 100644
--- a/src/insets/InsetNewline.cpp
+++ b/src/insets/InsetNewline.cpp
@@ -34,8 +34,24 @@ using namespace std;
 
 namespace lyx {
 
-InsetNewline::InsetNewline() : Inset(0)
-{}
+char_type InsetNewlineParams::newline_char(bool left_to_right) const
+{
+	// Different possibilities for character. Note that the RtL version is
+	// obtained by adding 1 to the code point.
+
+	// U+2936  ARROW POINTING DOWNWARDS THEN CURVING LEFTWARDS
+	char_type const newline_base_char = 0x2936;
+	// U+21B2  DOWNWARDS ARROW WITH TIP LEFTWARDS
+	//char_type const newline_base_char = 0x21B2;
+	// U+21A9 LEFTWARDS ARROW WITH HOOK
+	//char_type const newline_base_char = 0x21A9;
+
+	// The character is reversed in RtL text. It is additionally reversed for
+	// LINEBREAK kind of inset.
+	bool const ltr_char = (kind == NEWLINE) == left_to_right;
+
+	return newline_base_char + (ltr_char ? 0 : 1);
+}
 
 
 void InsetNewlineParams::write(ostream & os) const
@@ -56,7 +72,7 @@ void InsetNewlineParams::read(Lexer & lex)
 {
 	string token;
 	lex.setContext("InsetNewlineParams::read");
-	lex >> token;	
+	lex >> token;
 	if (token == "newline")
 		kind = InsetNewlineParams::NEWLINE;
 	else if (token == "linebreak")
@@ -66,6 +82,26 @@ void InsetNewlineParams::read(Lexer & lex)
 }
 
 
+
+InsetNewline::InsetNewline() : Inset(0)
+{}
+
+
+void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+	frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
+	dim = fm.dimension(params_.newline_char(true));
+}
+
+
+void InsetNewline::draw(PainterInfo & pi, int x, int y) const
+{
+	FontInfo font = pi.base.font;
+	font.setColor(Color_eolmarker);
+	pi.pain.text(x, y, params_.newline_char(pi.ltr_pos), font);
+}
+
+
 void InsetNewline::write(ostream & os) const
 {
 	os << "Newline ";
@@ -80,15 +116,6 @@ void InsetNewline::read(Lexer & lex)
 }
 
 
-void InsetNewline::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('n');
-}
-
-
 void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
 	switch (cmd.action()) {
@@ -127,21 +154,6 @@ bool InsetNewline::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-ColorCode InsetNewline::ColorName() const
-{
-	switch (params_.kind) {
-		case InsetNewlineParams::NEWLINE:
-			return Color_eolmarker;
-			break;
-		case InsetNewlineParams::LINEBREAK:
-			return Color_pagebreak;
-			break;
-	}
-	// not really useful, but to avoids gcc complaints
-	return Color_eolmarker;
-}
-
-
 void InsetNewline::latex(otexstream & os, OutputParams const & rp) const
 {
 	switch (params_.kind) {
@@ -183,83 +195,6 @@ docstring InsetNewline::xhtml(XHTMLStream & xs, OutputParams const &) const
 }
 
 
-void InsetNewline::draw(PainterInfo & pi, int x, int y) const
-{
-	FontInfo font;
-	font.setColor(ColorName());
-
-	frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
-	int const wid = fm.width('n');
-	int const asc = fm.maxAscent();
-
-	int xp[3];
-	int yp[3];
-
-	yp[0] = int(y - 0.875 * asc * 0.75);
-	yp[1] = int(y - 0.500 * asc * 0.75);
-	yp[2] = int(y - 0.125 * asc * 0.75);
-
-	if (pi.ltr_pos) {
-		xp[0] = int(x + wid * 0.375);
-		xp[1] = int(x);
-		xp[2] = int(x + wid * 0.375);
-	} else {
-		xp[0] = int(x + wid * 0.625);
-		xp[1] = int(x + wid);
-		xp[2] = int(x + wid * 0.625);
-	}
-
-	pi.pain.lines(xp, yp, 3, ColorName());
-
-	yp[0] = int(y - 0.500 * asc * 0.75);
-	yp[1] = int(y - 0.500 * asc * 0.75);
-	yp[2] = int(y - asc * 0.75);
-
-	if (pi.ltr_pos) {
-		xp[0] = int(x);
-		xp[1] = int(x + wid);
-		xp[2] = int(x + wid);
-	} else {
-		xp[0] = int(x + wid);
-		xp[1] = int(x);
-		xp[2] = int(x);
-	}
-
-	pi.pain.lines(xp, yp, 3, ColorName());
-
-	if (params_.kind == InsetNewlineParams::LINEBREAK) {
-
-		yp[2] = int(y - 0.500 * asc * 0.75);
-
-		if (pi.ltr_pos) {
-			xp[0] = int(x + 1.3 * wid);
-			xp[1] = int(x + 2 * wid);
-			xp[2] = int(x + 2 * wid);
-		} else {
-			xp[0] = int(x - 0.3 * wid);
-			xp[1] = int(x - wid);
-			xp[2] = int(x - wid);
-		}
-		pi.pain.lines(xp, yp, 3, ColorName());
-
-		yp[0] = int(y - 0.875 * asc * 0.75);
-		yp[1] = int(y - 0.500 * asc * 0.75);
-		yp[2] = int(y - 0.125 * asc * 0.75);
-	
-		if (pi.ltr_pos) {
-			xp[0] = int(x + 2 * wid * 0.813);
-			xp[1] = int(x + 2 * wid);
-			xp[2] = int(x + 2 * wid * 0.813);
-		} else {
-			xp[0] = int(x - wid * 0.625);
-			xp[1] = int(x - wid);
-			xp[2] = int(x - wid * 0.625);
-		}
-		pi.pain.lines(xp, yp, 3, ColorName());
-	}
-}
-
-
 string InsetNewline::contextMenuName() const
 {
 	return "context-newline";
diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h
index 2dc9c55..5a4cdb0 100644
--- a/src/insets/InsetNewline.h
+++ b/src/insets/InsetNewline.h
@@ -30,6 +30,8 @@ public:
 	///
 	InsetNewlineParams() : kind(NEWLINE) {}
 	///
+	char_type newline_char(bool left_to_right) const;
+	///
 	void write(std::ostream & os) const;
 	///
 	void read(Lexer & lex);
@@ -76,8 +78,6 @@ private:
 	/// a line separator)?
 	bool isSpace() const { return true; }
 	///
-	ColorCode ColorName() const;
-	///
 	std::string contextMenuName() const;
 	///
 	Inset * clone() const { return new InsetNewline(*this); }
-- 
1.7.9.5

Reply via email to