commit d77c0707e0f06a3d6ce2ce1e3b69feb3a890df3e
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Apr 20 18:17:18 2018 +0200

    Handle combining characters in writeScriptChars
    
    They were output in the wrong order and thus produced wrong result.
---
 src/Paragraph.cpp |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 9f417e8..b623f05 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -330,7 +330,8 @@ public:
        /// Output consecutive unicode chars, belonging to the same script as
        /// specified by the latex macro \p ltx, to \p os starting from \p i.
        /// \return the number of characters written.
-       int writeScriptChars(otexstream & os, docstring const & ltx,
+       int writeScriptChars(OutputParams const &, otexstream & os,
+                            docstring const & ltx,
                             Change const &, Encoding const &,
                             std::string const, pos_type & i);
 
@@ -965,7 +966,8 @@ bool Paragraph::Private::simpleTeXBlanks(OutputParams const 
& runparams,
 }
 
 
-int Paragraph::Private::writeScriptChars(otexstream & os,
+int Paragraph::Private::writeScriptChars(OutputParams const & runparams,
+                                        otexstream & os,
                                         docstring const & ltx,
                                         Change const & runningChange,
                                         Encoding const & encoding,
@@ -1022,6 +1024,18 @@ int Paragraph::Private::writeScriptChars(otexstream & os,
                // Stop here if there is a font attribute or encoding change.
                if (found && cit != end && prev_font != cit->font())
                        break;
+
+               // Check whether we have a combining pair
+               char_type next_next = '\0';
+               if (i + 2 < size) {
+                       next_next = text_[i + 2];
+                       if (Encodings::isCombiningChar(next_next)) {
+                               length += latexSurrogatePair(os, next, 
next_next, runparams) - 1;
+                               i += 2;
+                               continue;
+                       }
+               }
+
                docstring const latex = encoding.latexChar(next).first;
                docstring::size_type const b1 =
                                        latex.find_first_of(from_ascii("{"));
@@ -1364,7 +1378,7 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
                        fontenc = running_font.language()->fontenc();
                if (Encodings::isKnownScriptChar(c, script)
                    && prefixIs(latex.first, from_ascii("\\" + script)))
-                       column += writeScriptChars(os, latex.first,
+                       column += writeScriptChars(runparams, os, latex.first,
                                                   running_change, encoding,
                                                   fontenc, i) - 1;
                else if (latex.second

Reply via email to