Bo Peng wrote:
Dear all,

When some encoding error happens, it is extremely difficult to locate
the offending character. LyX gives an error message "Some characters
of your document are probably not representable in the chosen
encoding." with no hint of which and where the character is. This is,
IMHO, a major issue with 1.5.3.

In the attached patch, I try to

1. define encoding_exception
+class encoding_exception : public std::exception {
+public:
+       virtual ~encoding_exception() throw() {}
+       virtual const char * what() const throw();
+};

2.  Throw this exception in Encoding::Encoding. It is strange to me
that we do nothing here when we know ".\nLaTeX export will fail.".

Encoding::Encoding(string const & n, string const & l, string const & i,
                   bool f, Encoding::Package p)
        : Name_(n), LatexName_(l), iconvName_(i), fixedwidth_(f), package_(p)
@@ -325,10 +331,7 @@
                // c cannot be encoded in this encoding
                CharInfoMap::const_iterator const it = unicodesymbols.find(c);
                if (it == unicodesymbols.end())
-                       lyxerr << "Could not find LaTeX command for character 
0x"
-                              << std::hex << c << std::dec
-                              << ".\nLaTeX export will fail."
-                              << endl;
+                       throw encoding_exception();

3. catch this exception in TeXOnePar

-       bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
+       bool need_par = false;
+       try {
+               need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
                                             os, texrow, runparams);
+       } catch (encoding_exception & e) {
+               //      
+               errorList.push_back(ErrorItem(_("Encoding error"),
+                       _(" "), -1, 0, 0));
+       }

HOWEVER, passing errorList to this function means interface change to
a lot of functions, which makes this patch somewhat large.

With this proof-of-concept patch, when encoding error happens, a
errorlist dialog will display. Clicking on the error item will (not
yet) move the cursor to the offending character. I would like to ask

1. Is this in general welcome?

I guess so.

3. Any better idea?

Couldn't you use Buffer::errorList() instead of passing it around?

Abdel.


Reply via email to