]> git.lyx.org Git - features.git/commitdiff
Normalize everything that comes from 'outside' (plain text import,
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 3 Apr 2007 08:15:39 +0000 (08:15 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 3 Apr 2007 08:15:39 +0000 (08:15 +0000)
keyboard input via kmap, clipboard and selection) to normalized form KC
(precomposed characters) since we don't support the decomposed form very
well.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17702 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiClipboard.C
src/frontends/qt4/GuiSelection.C
src/insets/insettabular.C
src/lyx_cb.C
src/lyx_cb.h
src/support/docstring.C
src/support/docstring.h
src/tex-accent.C

index c133f35604b682ad02a6da0affd32d53f13c0264..3359e8b46963679943d65d7c60933c1d41c8781f 100644 (file)
@@ -66,7 +66,8 @@ string const GuiClipboard::getAsLyX() const
 docstring const GuiClipboard::getAsText() const
 {
        // text data from other applications
-       QString const str = qApp->clipboard()->text(QClipboard::Clipboard);
+       QString const str = qApp->clipboard()->text(QClipboard::Clipboard)
+                               .normalized(QString::NormalizationForm_KC);
        LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
                              << fromqstr(str) << "'" << endl;
        if (str.isNull())
index 9c8454f118806a469c6fbbfe1ad085ed810b5930..2b7b941a89a220f7f3add177d4f9aac495f323e6 100644 (file)
@@ -58,7 +58,8 @@ void GuiSelection::haveSelection(bool own)
 
 docstring const GuiSelection::get() const
 {
-       QString const str = qApp->clipboard()->text(QClipboard::Selection);
+       QString const str = qApp->clipboard()->text(QClipboard::Selection)
+                               .normalized(QString::NormalizationForm_KC);
        LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
                              << endl;
        if (str.isNull())
index ab43c81d2d1a218582eac43bdd07cb2a4f22bdf0..89a307d9e5af3d1c2ad3bcd67ee455055838c0ab 100644 (file)
@@ -701,9 +701,8 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_FILE_INSERT_PLAINTEXT_PARA:
        case LFUN_FILE_INSERT_PLAINTEXT: {
                // FIXME UNICODE
-               string const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
-               // FIXME: We don't know the encoding of the file
-               if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), from_utf8(tmpstr), false))
+               docstring const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
+               if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), tmpstr, false))
                        cur.undispatched();
                break;
        }
index 03a13320b0677d0b8fdb4ead6689b1cbe2785997..533ef99e92e036e73ffbfbc69d1a965e76865ba2 100644 (file)
@@ -326,8 +326,7 @@ void insertPlaintextFile(BufferView * bv, string const & f, bool asParagraph)
        if (!bv->buffer())
                return;
 
-       // FIXME: We don't know the encoding of the file
-       docstring const tmpstr = from_utf8(getContentsOfPlaintextFile(bv, f, asParagraph));
+       docstring const tmpstr = getContentsOfPlaintextFile(bv, f, asParagraph);
        if (tmpstr.empty())
                return;
 
@@ -341,8 +340,8 @@ void insertPlaintextFile(BufferView * bv, string const & f, bool asParagraph)
 }
 
 
-// Read plain text file (if filename is empty, prompt for one)
-string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asParagraph)
+docstring const getContentsOfPlaintextFile(BufferView * bv, string const & f,
+               bool asParagraph)
 {
        FileName fname(f);
 
@@ -355,12 +354,12 @@ string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asPara
                                     FileFilterList(), docstring());
 
                if (result.first == FileDialog::Later)
-                       return string();
+                       return docstring();
 
                fname = makeAbsPath(to_utf8(result.second));
 
                if (fname.empty())
-                       return string();
+                       return docstring();
        }
 
        if (!fs::is_readable(fname.toFilesystemEncoding())) {
@@ -369,7 +368,7 @@ string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asPara
                docstring const text = bformat(_("Could not read the specified document\n"
                                                           "%1$s\ndue to the error: %2$s"), file, error);
                Alert::error(_("Could not read file"), text);
-               return string();
+               return docstring();
        }
 
        ifstream ifs(fname.toFilesystemEncoding().c_str());
@@ -379,7 +378,7 @@ string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asPara
                docstring const text = bformat(_("Could not open the specified document\n"
                                                           "%1$s\ndue to the error: %2$s"), file, error);
                Alert::error(_("Could not open file"), text);
-               return string();
+               return docstring();
        }
 
        ifs.unsetf(ios::skipws);
@@ -399,7 +398,8 @@ string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asPara
        copy(ii, end, back_inserter(tmpstr));
 #endif
 
-       return tmpstr;
+       // FIXME UNICODE: We don't know the encoding of the file
+       return normalize_kc(from_utf8(tmpstr));
 }
 
 
index 03cecc4a7058b103faa96d56d1a68dcbeb23c09b..f320a1ffe0de7e5a851072d1326923fe36c5b58a 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef LYX_CB_H
 #define LYX_CB_H
 
-#include <string>
+#include "support/docstring.h"
 
 namespace lyx {
 
@@ -33,8 +33,9 @@ void autoSave(BufferView * bv);
 void newFile(BufferView * bv, std::string const & filename);
 ///
 void insertPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph);
-///
-std::string getContentsOfPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph);
+/// read plain text file (if \p f is empty, prompt for a filename)
+docstring const getContentsOfPlaintextFile(BufferView * bv,
+               std::string const & f, bool asParagraph);
 ///
 void reconfigure(LyXView & lv);
 
index 89abf212991ebf5fec66865e629fb5b95f05f688..57dbc19768bacfa95b32617674f1c239ff9a624d 100644 (file)
@@ -140,6 +140,12 @@ std::string const to_filesystem8bit(docstring const & s)
 }
 
 
+docstring const normalize_kc(docstring const & s)
+{
+       return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_KC));
+}
+
+
 bool operator==(lyx::docstring const & l, char const * r)
 {
        int const len = l.length();
index 0f466312b8056751c9e3d936c446c46339f71855..6ee612bb3cbf6913b8bd8aabec51733626b16e3b 100644 (file)
@@ -62,6 +62,9 @@ docstring const from_filesystem8bit(std::string const & s);
 /// convert \p s from ucs4 to the encoding of the file system.
 std::string const to_filesystem8bit(docstring const & s);
 
+/// normalize \p s to precomposed form kc
+docstring const normalize_kc(docstring const & s);
+
 /// Compare a docstring with a C string of ASCII characters
 bool operator==(lyx::docstring const &, char const *);
 
index 1ddc4b741c47f79878ebbf03d9b704d38bd0f595..adb9b1b365e4949282b9715fc7a4ccfc08c2e041 100644 (file)
@@ -103,8 +103,7 @@ docstring const DoAccent(docstring const & s, tex_accent accent)
                               << lyx_accent_table[accent].name << '.' << std::endl;
                os << s.substr(1);
        }
-       // FIXME: We should normalize the result to precomposed form
-       return os.str();
+       return normalize_kc(os.str());
 }