From 26bfdc2bebdd30b6855ab0ce9e392ba2eed1f926 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 23 Mar 2020 12:07:47 +0100 Subject: [PATCH] Paste some special chars as insets See #11790 --- src/Text.cpp | 18 ++++++++++++++++-- src/insets/InsetSpecialChar.cpp | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index 25ce684d22..4a447577f2 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -866,6 +866,13 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, pit_type pit = cur.pit(); pos_type pos = cur.pos(); + // The special chars we handle + map specialchars; + specialchars[0x200c] = InsetSpecialChar::LIGATURE_BREAK; + specialchars[0x200b] = InsetSpecialChar::ALLOWBREAK; + specialchars[0x2026] = InsetSpecialChar::LDOTS; + specialchars[0x2011] = InsetSpecialChar::NOBREAKDASH; + // insert the string, don't insert doublespace bool space_inserted = true; for (auto const & ch : str) { @@ -895,8 +902,15 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str, ++pos; space_inserted = true; } - } else if (!isPrintable(ch) && ch != 0x200c) { - // Ignore unprintables, except for ZWNJ (0x200c) + } else if (specialchars.find(ch) != specialchars.end()) { + par.insertInset(pos, new InsetSpecialChar(specialchars.find(ch)->second), + font, bparams.track_changes ? + Change(Change::INSERTED) + : Change(Change::UNCHANGED)); + ++pos; + space_inserted = false; + } else if (!isPrintable(ch)) { + // Ignore (other) unprintables continue; } else { // just insert the character diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 76da971ea0..740061e031 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -15,6 +15,7 @@ #include "InsetSpecialChar.h" #include "Dimension.h" +#include "Encoding.h" #include "Font.h" #include "Language.h" #include "LaTeXFeatures.h" @@ -384,6 +385,7 @@ void InsetSpecialChar::latex(otexstream & os, OutputParams const & rp) const { bool const rtl = rp.local_font->isRightToLeft(); + bool const utf8 = rp.encoding->iconvName() == "UTF-8"; string lswitch = ""; string lswitche = ""; if (rtl && !rp.use_polyglossia) { @@ -399,10 +401,15 @@ void InsetSpecialChar::latex(otexstream & os, os << "\\-"; break; case ALLOWBREAK: + // U+200B not yet supported by utf8 inputenc os << "\\LyXZeroWidthSpace" << termcmd; break; case LIGATURE_BREAK: - os << "\\textcompwordmark" << termcmd; + if (utf8) + // U+200C ZERO WIDTH NON-JOINER + os.put(0x200c); + else + os << "\\textcompwordmark" << termcmd; break; case END_OF_SENTENCE: os << "\\@."; -- 2.39.5