[LyX/2.3.x] Check class options for uncodable glyphs

Juergen Spitzmueller spitz at lyx.org
Sat May 16 06:43:39 UTC 2020


commit af4e5aefe0db1bfd65482d2cae995a81f49e7a7c
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Fri May 15 09:50:25 2020 +0200

    Check class options for uncodable glyphs
    
    Fixes #11865
    
    (cherry picked from commit 11dc817e9d13ab065908d99ba6dd5f0b9b4f6e64)
---
 src/BufferParams.cpp |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 status.23x           |    2 ++
 2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 9a15849..11a7842 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -1722,12 +1722,52 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
 	if (!options.empty()) {
 		clsoptions << options << ',';
 	}
-
-	string strOptions(clsoptions.str());
+	
+	docstring const strOptions = from_utf8(clsoptions.str());
 	if (!strOptions.empty()) {
-		strOptions = rtrim(strOptions, ",");
-		// FIXME UNICODE
-		os << '[' << from_utf8(strOptions) << ']';
+		// Check if class options contain uncodable glyphs
+		docstring uncodable_glyphs;
+		docstring options_encodable;
+		Encoding const * const enc = features.runparams().encoding;
+		if (enc) {
+			for (size_t n = 0; n < strOptions.size(); ++n) {
+				char_type c = strOptions[n];
+				if (!enc->encodable(c)) {
+					docstring const glyph(1, c);
+					LYXERR0("Uncodable character '"
+						<< glyph
+						<< "' in class options!");
+					uncodable_glyphs += glyph;
+					if (features.runparams().dryrun) {
+						options_encodable += "<" + _("LyX Warning: ")
+						   + _("uncodable character") + " '";
+						options_encodable += c;
+						options_encodable += "'>";
+					}
+				} else
+					options_encodable += c;
+			}
+		} else
+			options_encodable = strOptions;
+	
+		// On BUFFER_VIEW|UPDATE, warn user if we found uncodable glyphs
+		if (!features.runparams().dryrun && !uncodable_glyphs.empty()) {
+			frontend::Alert::warning(
+				_("Uncodable character in class options"),
+				support::bformat(
+				  _("The class options of your document contain glyphs "
+				    "that are unknown in the current document encoding "
+				    "(namely %1$s).\nThese glyphs are omitted "
+				    " from the output, which may result in "
+				    "incomplete output."
+				    "\n\nPlease select an appropriate "
+				    "document encoding\n"
+				    "(such as utf8) or change the "
+				    "class options accordingly."),
+				  uncodable_glyphs));
+		}
+		options_encodable = rtrim(options_encodable, ",");
+		os << '[' << options_encodable << ']';
 	}
 
 	os << '{' << from_ascii(tclass.latexname()) << "}\n";
diff --git a/status.23x b/status.23x
index a34e52e..4b05d28 100644
--- a/status.23x
+++ b/status.23x
@@ -47,6 +47,8 @@ What's new
 
 - Fix crash with non-encodable glyph in nomcenlature inset (bug 11584).
 
+- Fix crash with non-encodable glyph in class options (bug 11865).
+
 - Fix problems with non-ASCII characters in file path with recent LaTeX
   (bug 11146).
 


More information about the lyx-cvs mailing list