]> git.lyx.org Git - features.git/commitdiff
Handle properly unicode paragraph/line break
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 7 Nov 2016 09:14:39 +0000 (10:14 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 6 Feb 2017 09:28:22 +0000 (10:28 +0100)
They are shown on screen by arrow or pilcrow symbol and cause a line break.

They are still not handled in LaTeX output, though.
(cherry picked from commit 6dfbab31245df074df4d1664321e2ff434f3ca6a)

src/Paragraph.cpp
src/TextMetrics.cpp
status.22x

index 7ac0a666cfb6a91cd373db8058ca06434eca6e47..4b07afa8a948f2f83560749e797f24fe10333b1e 100644 (file)
@@ -3153,6 +3153,11 @@ bool Paragraph::isHfill(pos_type pos) const
 
 bool Paragraph::isNewline(pos_type pos) const
 {
+       // U+2028 LINE SEPARATOR
+       // U+2029 PARAGRAPH SEPARATOR
+       char_type const c = d->text_[pos];
+       if (c == 0x2028 || c == 0x2029)
+               return true;
        Inset const * inset = getInset(pos);
        return inset && inset->lyxCode() == NEWLINE_CODE;
 }
index a26b88dc726b0d6a32f9cb5f90fdec712e4783b5..c537e4536b0715e74c4902180da2118acf268a88 100644 (file)
@@ -851,7 +851,23 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
                } else if (c == '\t')
                        row.addSpace(i, theFontMetrics(*fi).width(from_ascii("    ")),
                                     *fi, par.lookupChange(i));
-               else {
+               else if (c == 0x2028 || c == 0x2029) {
+                       /**
+                        * U+2028 LINE SEPARATOR
+                        * U+2029 PARAGRAPH SEPARATOR
+
+                        * These are special unicode characters that break
+                        * lines/pragraphs. Not handling them lead to trouble wrt
+                        * Qt QTextLayout formatting. We add a visible character
+                        * on screen so that the user can see that something is
+                        * happening.
+                       */
+                       row.finalizeLast();
+                       // ⤶ U+2936 ARROW POINTING DOWNWARDS THEN CURVING LEFTWARDS
+                       // ¶ U+00B6 PILCROW SIGN
+                       char_type const screen_char = (c == 0x2028) ? 0x2936 : 0x00B6;
+                       row.add(i, screen_char, *fi, par.lookupChange(i));
+               } else {
                        // FIXME: please someone fix the Hebrew/Arabic parenthesis mess!
                        // see also Paragraph::getUChar.
                        if (fi->language()->lang() == "hebrew") {
@@ -911,6 +927,7 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
                BufferParams const & bparams
                        = text_->inset().buffer().params();
                f.setLanguage(par.getParLanguage(bparams));
+               // ¶ U+00B6 PILCROW SIGN
                row.addVirtual(end, docstring(1, char_type(0x00B6)), f, Change());
        }
 
index 34afd0d0a253c31135a8a4298697e3885c5df502..5c969b2bf6e398cd0fcd54cf70820fca9ec18b3b 100644 (file)
@@ -161,6 +161,8 @@ What's new
 - Fix cursor movement when the document contains high-plane Unicode
   characters (bug 10443).
 
+- Fix crash when the document contains Unicode line-breaking characters.
+
 - Allow using colors supported by xcolor inside mathed (bug 10417).
 
 - Change description of "frame of button" color to "button frame" (bug