]> git.lyx.org Git - features.git/commitdiff
Make Word Wrap property confiurable by language
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 5 Jun 2019 13:45:10 +0000 (15:45 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 5 Jun 2019 13:50:53 +0000 (15:50 +0200)
It is now possible to specify in the lib/language file whether screen
rows can be broken anywhere (CJK languages) or only at work boundary.

Set WordWrap to false for the CJK languages (notice that japanese-cjk
had been forgotten before).

Moreover, remove a test for separators in row element that was not
really helpful.

Fixes part of ticket #10299.

lib/languages
src/Language.cpp
src/Language.h
src/Row.cpp

index f32514f73d0b0e8573aeac119de487c430faeaf7..b53b7c466318b0617d5e16e124e4a4cda62398d0 100644 (file)
@@ -17,6 +17,7 @@
 #      FontEncoding       <font encoding|font encoding|...>
 #      InternalEncoding   <true|false>
 #      RTL                <true|false>
+#      WordWrap           <true|false>
 #      LangCode           <language_code>
 #      LangVariety        <language_variety>
 #      PreBabelPreamble
 #   If True, LyX takes care for characters/macros that do not exist in
 #   some font encodings ("<", ">", "|" and straight quote).
 #   It is not required for standard encodings like T2A. See bug #5091.
+# * WordWrap is only used for on-screen display: when is is true (the default), rows are broken
+#   at word boundary; otherwise, they can be ended at arbitrary position. This
+#   setting is useful for CJK languages.
 # * LangCode is also used for spellchecking and thesaurus, where the
 #   dictionaries are named accordingly. Thus, check this when introducing/
 #   changing language codes (especially aspell, thesaurus).
@@ -501,6 +505,7 @@ Language chinese-simplified
        HasGuiSupport    true
        Encoding         euc-cn
        QuoteStyle       english
+       WordWrap         false
        LangCode         zh_CN
        DateFormats      "yyyy年M月d日|yyyy-M-d|yy-M-d"
        Requires         CJK
@@ -512,6 +517,7 @@ Language chinese-traditional
        HasGuiSupport    true
        QuoteStyle       cjk
        Encoding         utf8-cjk
+       WordWrap         false
        LangCode         zh_TW
        DateFormats      "yyyy年M月d日|yyyy年M月d日|yy年M月d日"
        Requires         CJK
@@ -909,6 +915,7 @@ Language japanese
        HasGuiSupport    true
        BabelName        japanese
        Encoding         jis-platex
+       WordWrap         false
        LangCode         ja_JP
        Requires         japanese
        FontEncoding     ASCII
@@ -920,7 +927,8 @@ End
 Language japanese-cjk
        GuiName         "Japanese (CJK)"
        Encoding        euc-jp
-       DateFormats      "yyyy年M月d日|yyyy/MM/dd|yy/MM/dd"
+       DateFormats     "yyyy年M月d日|yyyy/MM/dd|yy/MM/dd"
+       WordWrap        false
        LangCode        ja_JP
        Requires        CJK
        QuoteStyle      cjk
@@ -960,6 +968,7 @@ Language korean
        Encoding        euc-kr
        QuoteStyle      cjkangle
        DateFormats     "yyyy년 M월 d일|yyyy. M. d.|yy. M. d."
+       WordWrap        false
        LangCode        ko_KR
        Requires        CJK
 End
index 24e5cd7482a5cdb3f6caab524067f49d4b30251b..c96928adc06db12a25695279f4a5aab729049aa4 100644 (file)
@@ -131,7 +131,8 @@ bool Language::readLanguage(Lexer & lex)
                LA_PROVIDES,
                LA_REQUIRES,
                LA_QUOTESTYLE,
-               LA_RTL
+               LA_RTL,
+               LA_WORDWRAP
        };
 
        // Keep these sorted alphabetically!
@@ -153,7 +154,8 @@ bool Language::readLanguage(Lexer & lex)
                { "provides",             LA_PROVIDES },
                { "quotestyle",           LA_QUOTESTYLE },
                { "requires",             LA_REQUIRES },
-               { "rtl",                  LA_RTL }
+               { "rtl",                  LA_RTL },
+               {"wordwrap",              LA_WORDWRAP }
        };
 
        bool error = false;
@@ -240,6 +242,9 @@ bool Language::readLanguage(Lexer & lex)
                case LA_RTL:
                        lex >> rightToLeft_;
                        break;
+               case LA_WORDWRAP:
+                       lex >> word_wrap_;
+                       break;
                }
        }
        lex.popTable();
index 1dabbacaec4c011e44093c1d09f37ea54b9fcf03..ee3828cc6032d17834c48b65a4fed711153ef7af 100644 (file)
@@ -36,7 +36,7 @@ class Language {
 public:
        ///
        Language() : rightToLeft_(false), encoding_(0), internal_enc_(false),
-                                has_gui_support_(false) {}
+                                has_gui_support_(false), word_wrap_(true) {}
        /// LyX language name
        std::string const lang() const { return lang_; }
        /// Babel language name
@@ -59,6 +59,8 @@ public:
        std::string const display() const { return display_; }
        /// is this a RTL language?
        bool rightToLeft() const { return rightToLeft_; }
+       /// shall text be wrapped at word boundary ?
+       bool wordWrap() const { return word_wrap_; }
        /**
         * Translate a string from the layout files that appears in the output.
         * It takes the translations from lib/layouttranslations instead of
@@ -142,6 +144,8 @@ private:
        ///
        bool has_gui_support_;
        ///
+       bool word_wrap_;
+       ///
        TranslationMap layoutTranslations_;
 };
 
index 63b7195af450fbed83cc55f5987070ff8979f88f..117b2ac9faea9945452fb4bf44187026d48e99a3 100644 (file)
@@ -492,13 +492,10 @@ bool Row::shortenIfNeeded(pos_type const keep, int const w, int const next_width
                 * 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)
+               bool const word_wrap = brk.font.language()->wordWrap();
+               // When there is text before the body part (think description
+               // environment), do not try to break.
+               if (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
@@ -506,7 +503,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), force)) {
+               if (brk.breakAt(min(w - wid_brk, brk.dim.wid - 2), !word_wrap)) {
                        /* 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