]> git.lyx.org Git - features.git/commitdiff
Consider EuropeanNumberTerminator property when determining text direction
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 22 Jul 2018 10:36:38 +0000 (12:36 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 9 Sep 2018 09:30:43 +0000 (11:30 +0200)
Also, use EuropeanNumberSeparator information rather than relying on an
own (incomplete) list of number separators.

Fixes: #4057
(cherry picked from commit 611df441b6e44ad641d6d9424fe68fe72d641706)

src/Text.cpp
src/support/lstrings.cpp
src/support/textutils.h
status.23x

index b38620545d4754dab88ec681be892e2137b8ea65..ca2d06eabba30265abe53588670a65600a0d5862 100644 (file)
@@ -968,14 +968,19 @@ void Text::insertChar(Cursor & cur, char_type c)
        if (lyxrc.auto_number) {
                static docstring const number_operators = from_ascii("+-/*");
                static docstring const number_unary_operators = from_ascii("+-");
-               static docstring const number_separators = from_ascii(".,:");
 
+               // European Number Separators: comma, dot etc.
+               // European Number Terminators: percent, permille, degree, euro etc.
                if (cur.current_font.fontInfo().number() == FONT_ON) {
                        if (!isDigitASCII(c) && !contains(number_operators, c) &&
-                           !(contains(number_separators, c) &&
+                           !(isEuropeanNumberSeparator(c) &&
                              cur.pos() != 0 &&
                              cur.pos() != cur.lastpos() &&
                              tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
+                             tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON) &&
+                           !(isEuropeanNumberTerminator(c) &&
+                             cur.pos() != 0 &&
+                             tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
                              tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
                           )
                                number(cur); // Set current_font.number to OFF
@@ -993,7 +998,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                  ) {
                                        setCharFont(pit, cur.pos() - 1, cur.current_font,
                                                tm.font_);
-                               } else if (contains(number_separators, c)
+                               } else if (isEuropeanNumberSeparator(c)
                                     && cur.pos() >= 2
                                     && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) {
                                        setCharFont(pit, cur.pos() - 1, cur.current_font,
index 4a12c34b4daec5fb2767ccec63a4ae4626859305..21fe05aa09389fb1e04b7518529d64793fe395ab 100644 (file)
@@ -164,6 +164,26 @@ bool isNumber(char_type c)
 }
 
 
+bool isEuropeanNumberSeparator(char_type c)
+{
+       if (!is_utf16(c))
+               // assume that no non-utf16 character is a numeral
+               // c outside the UCS4 range is catched as well
+               return false;
+       return ucs4_to_qchar(c).direction() == QChar::DirES;
+}
+
+
+bool isEuropeanNumberTerminator(char_type c)
+{
+       if (!is_utf16(c))
+               // assume that no non-utf16 character is a numeral
+               // c outside the UCS4 range is catched as well
+               return false;
+       return ucs4_to_qchar(c).direction() == QChar::DirET;
+}
+
+
 bool isDigitASCII(char_type c)
 {
        return '0' <= c && c <= '9';
index f5965882ec3b3d31c8f1ae68900667a286cac3ab..314ea7588d26943b281f177b9c2d532f9d0e37ae 100644 (file)
@@ -44,6 +44,14 @@ bool isSpace(char_type c);
 /// return true if a unicode char is a numeral.
 bool isNumber(char_type c);
 
+/// return true if a unicode char has the direction attribute
+/// European Number Separator [ES]
+bool isEuropeanNumberSeparator(char_type c);
+
+/// return true if a unicode char has the direction attribute
+/// European Number Terminator [ET]
+bool isEuropeanNumberTerminator(char_type c);
+
 /// return whether \p c is a digit in the ASCII range
 bool isDigitASCII(char_type c);
 
index 9474b7e7ffe82f62d2140dd079422183cb3e43bc..9d44843e0088266ba912b9bf4b93795ab0aa66c0 100644 (file)
@@ -64,6 +64,9 @@ What's new
 
 - Fix document-wide language setting with minted (bug 11203).
 
+- Fix display of percent sign with numbers in RTL (bug 4057).
+
+
 
 * INTERNALS