]> git.lyx.org Git - features.git/commitdiff
* src/InsetIndex.cpp:
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 15 Sep 2008 14:19:00 +0000 (14:19 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 15 Sep 2008 14:19:00 +0000 (14:19 +0000)
- fix LaTeX output with unrepresentable characters in current encoding (bug 5022).

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

src/insets/InsetIndex.cpp

index 00da6df8be4b1103639d29f3b837612c8f62fd46..fa13bdc0f532353fb77944a2b72c0069cb3e9f60 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "Buffer.h"
 #include "DispatchResult.h"
+#include "Encoding.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
@@ -25,6 +26,8 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
+#include "frontends/alert.h"
+
 #include <ostream>
 
 using namespace std;
@@ -106,10 +109,31 @@ int InsetIndex::latex(odocstream & os,
                if (contains(*it, '\\') && !contains(*it, '@')) {
                        // Plaintext might return nothing (e.g. for ERTs)
                        docstring const spart = 
-                               (it2 < levels_plain.end() && !(*it2).empty()) ? *it2 : *it;
+                               (it2 < levels_plain.end() && !(*it2).empty())
+                               ? *it2 : *it;
+                       // Now we need to validate that all characters in
+                       // the sorting part are representable in the current
+                       // encoding. If not try the LaTeX macro which might
+                       // or might not be a good choice, and issue a warning.
+                       docstring spart2;
+                       for (int n = 0; n < spart.size(); ++n) {
+                               try {
+                                       spart2 += runparams.encoding->latexChar(spart[n]);
+                               } catch (EncodingException & /* e */) {
+                                       LYXERR0("Uncodable character in index entry. Sorting might be wrong!");
+                               }
+                       }
+                       if (spart != spart2 && !runparams.dryrun) {
+                               // FIXME: warning should be passed to the error dialog
+                               frontend::Alert::warning(_("Index sorting failed"),
+                               bformat(_("LyX's automatic index sorting algorithm faced\n"
+                                 "problems with the entry '%1$s'.\n"
+                                 "Please specify the sorting of this entry manually, as\n"
+                                 "explained in the User Guide."), spart));
+                       }
                        // remove remaining \'s for the sorting part
                        docstring const ppart =
-                               subst(spart, from_ascii("\\"), docstring());
+                               subst(spart2, from_ascii("\\"), docstring());
                        os << ppart;
                        os << '@';
                        i += ppart.size() + 1;