Normalize everything that comes from 'outside' (plain text import,

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
This commit is contained in:
Georg Baum 2007-04-03 08:15:39 +00:00
parent f3558df4c2
commit 0159c9d6c7
8 changed files with 29 additions and 19 deletions

View File

@ -66,7 +66,8 @@ string const GuiClipboard::getAsLyX() const
docstring const GuiClipboard::getAsText() const docstring const GuiClipboard::getAsText() const
{ {
// text data from other applications // 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(): `" LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
<< fromqstr(str) << "'" << endl; << fromqstr(str) << "'" << endl;
if (str.isNull()) if (str.isNull())

View File

@ -58,7 +58,8 @@ void GuiSelection::haveSelection(bool own)
docstring const GuiSelection::get() const 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) LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
<< endl; << endl;
if (str.isNull()) if (str.isNull())

View File

@ -701,9 +701,8 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_FILE_INSERT_PLAINTEXT_PARA: case LFUN_FILE_INSERT_PLAINTEXT_PARA:
case LFUN_FILE_INSERT_PLAINTEXT: { case LFUN_FILE_INSERT_PLAINTEXT: {
// FIXME UNICODE // FIXME UNICODE
string const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false); docstring 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(), tmpstr, false))
if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), from_utf8(tmpstr), false))
cur.undispatched(); cur.undispatched();
break; break;
} }

View File

@ -326,8 +326,7 @@ void insertPlaintextFile(BufferView * bv, string const & f, bool asParagraph)
if (!bv->buffer()) if (!bv->buffer())
return; return;
// FIXME: We don't know the encoding of the file docstring const tmpstr = getContentsOfPlaintextFile(bv, f, asParagraph);
docstring const tmpstr = from_utf8(getContentsOfPlaintextFile(bv, f, asParagraph));
if (tmpstr.empty()) if (tmpstr.empty())
return; 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) docstring const getContentsOfPlaintextFile(BufferView * bv, string const & f,
string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asParagraph) bool asParagraph)
{ {
FileName fname(f); FileName fname(f);
@ -355,12 +354,12 @@ string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asPara
FileFilterList(), docstring()); FileFilterList(), docstring());
if (result.first == FileDialog::Later) if (result.first == FileDialog::Later)
return string(); return docstring();
fname = makeAbsPath(to_utf8(result.second)); fname = makeAbsPath(to_utf8(result.second));
if (fname.empty()) if (fname.empty())
return string(); return docstring();
} }
if (!fs::is_readable(fname.toFilesystemEncoding())) { 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" docstring const text = bformat(_("Could not read the specified document\n"
"%1$s\ndue to the error: %2$s"), file, error); "%1$s\ndue to the error: %2$s"), file, error);
Alert::error(_("Could not read file"), text); Alert::error(_("Could not read file"), text);
return string(); return docstring();
} }
ifstream ifs(fname.toFilesystemEncoding().c_str()); 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" docstring const text = bformat(_("Could not open the specified document\n"
"%1$s\ndue to the error: %2$s"), file, error); "%1$s\ndue to the error: %2$s"), file, error);
Alert::error(_("Could not open file"), text); Alert::error(_("Could not open file"), text);
return string(); return docstring();
} }
ifs.unsetf(ios::skipws); ifs.unsetf(ios::skipws);
@ -399,7 +398,8 @@ string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asPara
copy(ii, end, back_inserter(tmpstr)); copy(ii, end, back_inserter(tmpstr));
#endif #endif
return tmpstr; // FIXME UNICODE: We don't know the encoding of the file
return normalize_kc(from_utf8(tmpstr));
} }

View File

@ -12,7 +12,7 @@
#ifndef LYX_CB_H #ifndef LYX_CB_H
#define LYX_CB_H #define LYX_CB_H
#include <string> #include "support/docstring.h"
namespace lyx { namespace lyx {
@ -33,8 +33,9 @@ void autoSave(BufferView * bv);
void newFile(BufferView * bv, std::string const & filename); void newFile(BufferView * bv, std::string const & filename);
/// ///
void insertPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph); void insertPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph);
/// /// read plain text file (if \p f is empty, prompt for a filename)
std::string getContentsOfPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph); docstring const getContentsOfPlaintextFile(BufferView * bv,
std::string const & f, bool asParagraph);
/// ///
void reconfigure(LyXView & lv); void reconfigure(LyXView & lv);

View 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) bool operator==(lyx::docstring const & l, char const * r)
{ {
int const len = l.length(); int const len = l.length();

View 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. /// convert \p s from ucs4 to the encoding of the file system.
std::string const to_filesystem8bit(docstring const & s); 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 /// Compare a docstring with a C string of ASCII characters
bool operator==(lyx::docstring const &, char const *); bool operator==(lyx::docstring const &, char const *);

View File

@ -103,8 +103,7 @@ docstring const DoAccent(docstring const & s, tex_accent accent)
<< lyx_accent_table[accent].name << '.' << std::endl; << lyx_accent_table[accent].name << '.' << std::endl;
os << s.substr(1); os << s.substr(1);
} }
// FIXME: We should normalize the result to precomposed form return normalize_kc(os.str());
return os.str();
} }