[LyX/master] Allow row-breaking after some insets

Jean-Marc Lasgouttes lasgouttes at lyx.org
Tue Jun 23 21:11:57 UTC 2020


commit 3fea3b00968f9b02f487952c9a23614baed7d48c
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Tue Jun 23 23:34:49 2020 +0200

    Allow row-breaking after some insets
    
    Add new RowFlags value CanBreakAfter, which says that the row can be
    broken after the inset if needed. There is no CanBreakBefore yet,
    because I do not know of an inset that needs it.
    
    This makes screen closer to the actual behavior of insets.
    
    Currently, only unprotected spaces and some special characters are
    concerned. There may be more that need this handling.
    
    Fixes bug #11621.
---
 src/Row.cpp                     |   12 ++++++++++++
 src/insets/Inset.h              |    8 +++++---
 src/insets/InsetSpace.cpp       |   35 +++++++++++++++++++++++++++++++++++
 src/insets/InsetSpace.h         |    2 ++
 src/insets/InsetSpecialChar.cpp |   23 +++++++++++++++++++++++
 src/insets/InsetSpecialChar.h   |    2 ++
 6 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/src/Row.cpp b/src/Row.cpp
index 8ca6112..f59b6e4 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -480,6 +480,18 @@ bool Row::shortenIfNeeded(pos_type const keep, int const w, int const next_width
 		--cit_brk;
 		// make a copy of the element to work on it.
 		Element brk = *cit_brk;
+		/* If the current element is an inset that allows breaking row
+		 * after itself, and it the row is already short enough after
+		 * this inset, then cut right after this element.
+		 */
+		if (wid_brk <= w && brk.type == INSET
+		    && brk.inset->rowFlags() & Inset::CanBreakAfter) {
+			end_ = brk.endpos;
+			dim_.wid = wid_brk;
+			elements_.erase(cit_brk + 1, end);
+			return true;
+		}
+		// assume now that the current element is not there
 		wid_brk -= brk.dim.wid;
 		/*
 		 * Some Asian languages split lines anywhere (no notion of
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index e57a61b..f70b3c7 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -491,12 +491,14 @@ public:
 		BreakBefore = 1 << 0,
 		// break row after this inset
 		BreakAfter = 1 << 1,
+		// it is possible to break after this inset
+		CanBreakAfter = 1 << 2,
 		// force new (maybe empty) row after this inset
-		RowAfter = 1 << 2,
+		RowAfter = 1 << 3,
 		// specify an alignment (left, right) for a display inset
 		// (default is center)
-		AlignLeft = 1 << 3,
-		AlignRight = 1 << 4,
+		AlignLeft = 1 << 4,
+		AlignRight = 1 << 5,
 		// A display inset breaks row at both ends
 		Display = BreakBefore | BreakAfter
 	};
diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp
index 3317044..799568e 100644
--- a/src/insets/InsetSpace.cpp
+++ b/src/insets/InsetSpace.cpp
@@ -193,6 +193,41 @@ bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+Inset::RowFlags InsetSpace::rowFlags() const
+{
+	switch (params_.kind) {
+		case InsetSpaceParams::PROTECTED:
+		case InsetSpaceParams::CUSTOM_PROTECTED:
+		case InsetSpaceParams::HFILL_PROTECTED:
+		case InsetSpaceParams::THIN:
+		case InsetSpaceParams::NEGTHIN:
+		case InsetSpaceParams::MEDIUM:
+		case InsetSpaceParams::NEGMEDIUM:
+		case InsetSpaceParams::THICK:
+		case InsetSpaceParams::NEGTHICK:
+		case InsetSpaceParams::ENSPACE:
+		case InsetSpaceParams::VISIBLE:
+			// no break after these
+			return Inline;
+		case InsetSpaceParams::NORMAL:
+		case InsetSpaceParams::QUAD:
+		case InsetSpaceParams::QQUAD:
+		case InsetSpaceParams::ENSKIP:
+		case InsetSpaceParams::CUSTOM:
+		case InsetSpaceParams::HFILL:
+		case InsetSpaceParams::DOTFILL:
+		case InsetSpaceParams::HRULEFILL:
+		case InsetSpaceParams::LEFTARROWFILL:
+		case InsetSpaceParams::RIGHTARROWFILL:
+		case InsetSpaceParams::UPBRACEFILL:
+		case InsetSpaceParams::DOWNBRACEFILL:
+			// these allow line breaking
+			break;
+	}
+	return CanBreakAfter;
+}
+
+
 namespace {
 int const arrow_size = 8;
 }
diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h
index f8105da..65b1dc6 100644
--- a/src/insets/InsetSpace.h
+++ b/src/insets/InsetSpace.h
@@ -113,6 +113,8 @@ public:
 
 	///
 	docstring toolTip(BufferView const & bv, int x, int y) const;
+	/// unprotected spaces allow line breaking after them
+	RowFlags rowFlags() const;
 	///
 	void metrics(MetricsInfo &, Dimension &) const;
 	///
diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp
index 01007f6..2e51e95 100644
--- a/src/insets/InsetSpecialChar.cpp
+++ b/src/insets/InsetSpecialChar.cpp
@@ -82,6 +82,29 @@ docstring InsetSpecialChar::toolTip(BufferView const &, int, int) const
 }
 
 
+Inset::RowFlags InsetSpecialChar::rowFlags() const
+{
+	switch (kind_) {
+	case ALLOWBREAK:
+	case HYPHENATION:
+	case SLASH:
+		// these are the elements that allow line breaking
+		return CanBreakAfter;
+	case NOBREAKDASH:
+	case END_OF_SENTENCE:
+	case LIGATURE_BREAK:
+	case LDOTS:
+	case MENU_SEPARATOR:
+	case PHRASE_LYX:
+	case PHRASE_TEX:
+	case PHRASE_LATEX2E:
+	case PHRASE_LATEX:
+		break;
+	}
+	return Inline;
+}
+
+
 namespace {
 
 // helper function: draw text and update x.
diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h
index 6b33572..b7c6e79 100644
--- a/src/insets/InsetSpecialChar.h
+++ b/src/insets/InsetSpecialChar.h
@@ -62,6 +62,8 @@ public:
 	Kind kind() const;
 	///
 	docstring toolTip(BufferView const & bv, int x, int y) const;
+	/// some special chars allow line breaking after them
+	RowFlags rowFlags() const;
 	///
 	void metrics(MetricsInfo &, Dimension &) const;
 	///


More information about the lyx-cvs mailing list