]> git.lyx.org Git - lyx.git/commitdiff
Some Asian langagues allow to wrap text at any position
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 14 May 2019 20:44:29 +0000 (22:44 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 15 May 2019 16:26:08 +0000 (18:26 +0200)
This is hardcoded for now for simplicity and to allow backporting to
2.3.

The behavior is unchanged for all languages but Chinese, Japanese or
Korean.

Fixes part of bug #10299.

(cherry picked from commit 26c2811cc474f7e3be953f73bf6e9d79f14022cd)

src/Row.cpp
status.23x

index 3fb87bd7e1f3b80504742a85654fa361aca2c4b0..b241194e6eb323f4b4a2f3eb0dfad0f70dc66dc6 100644 (file)
@@ -19,6 +19,7 @@
 #include "Row.h"
 
 #include "DocIterator.h"
+#include "Language.h"
 
 #include "frontends/FontMetrics.h"
 
@@ -473,7 +474,25 @@ bool Row::shortenIfNeeded(pos_type const keep, int const w, int const next_width
                // make a copy of the element to work on it.
                Element brk = *cit_brk;
                wid_brk -= brk.dim.wid;
-               if (brk.countSeparators() == 0 || brk.pos < keep)
+               /*
+                * Some Asian languages split lines anywhere (no notion of
+                * word). It seems that QTextLayout is not aware of this fact.
+                * See for reference:
+                *    https://en.wikipedia.org/wiki/Line_breaking_rules_in_East_Asian_languages
+                *
+                * FIXME: Something shall be done about characters which are
+                * not allowed at the beginning or end of line.
+                *
+                * FIXME: hardcoding languages is bad. Put this information in
+                * `languages' file.
+               */
+               string const lang = brk.font.language()->lang();
+               bool force = lang == "chinese-simplified"
+                            || lang == "chinese-traditional"
+                            || lang == "japanese"
+                            || lang == "korean";
+               // FIXME: is it important to check for separators?
+               if ((!force && brk.countSeparators() == 0) || brk.pos < keep)
                        continue;
                /* We have found a suitable separable element. This is the common case.
                 * Try to break it cleanly (at word boundary) at a length that is both
@@ -481,7 +500,7 @@ bool Row::shortenIfNeeded(pos_type const keep, int const w, int const next_width
                 * - shorter than the natural width of the element, in order to enforce
                 *   break-up.
                 */
-               if (brk.breakAt(min(w - wid_brk, brk.dim.wid - 2), false)) {
+               if (brk.breakAt(min(w - wid_brk, brk.dim.wid - 2), force)) {
                        /* if this element originally did not cause a row overflow
                         * in itself, and the remainder of the row would still be
                         * too large after breaking, then we will have issues in
index 56a4c843c476cda3fabaa0b4fa71b8a7ec95ec0e..be847581eab3dfc545b31b939f677e4c4ed7b222 100644 (file)
@@ -61,6 +61,9 @@ What's new
 
 - Improve some icons (bug 11476).
 
+- Improve line breaking of Chinese, Japanese and Korean text. There are still
+  issues, though (bug 10299).
+
 
 * DOCUMENTATION AND LOCALIZATION