* src/Buffer.cpp:

- better translatable error message for uncodable chars, now also
	  displaying the code point value.
* src/Paragraph.cpp:
	- do not throw in View Source mode, but mark up uncodable chars (fix bug 4437).
* src/frontends/qt4/LaTeXHighlighter.{cpp,h}:
	- highlight LyX warnings.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22294 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2007-12-24 13:55:01 +00:00
parent 04537d8664
commit 09f09e2121
4 changed files with 32 additions and 7 deletions

View File

@ -1024,8 +1024,13 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
runparams, output_preamble, output_body);
}
catch (EncodingException & e) {
docstring msg = _("Could not find LaTeX command for character '%'");
msg[msg.size() - 2] = e.failed_char;
odocstringstream ods;
ods.put(e.failed_char);
ostringstream oss;
oss << "0x" << hex << e.failed_char << dec;
docstring msg = bformat(_("Could not find LaTeX command for character '%1$s'"
" (code point %2$s)"),
ods.str(), from_utf8(oss.str()));
errorList.push_back(ErrorItem(msg, _("Some characters of your document are probably not "
"representable in the chosen encoding.\n"
"Changing the document encoding to utf8 could help."),

View File

@ -2024,10 +2024,16 @@ bool Paragraph::latex(Buffer const & buf,
d->latexSpecialChar(os, rp, running_font, runningChange,
*style, i, column);
} catch (EncodingException & e) {
// add location information and throw again.
e.par_id = id();
e.pos = i;
throw(e);
if (runparams.dryrun) {
os << _("<LyX Warning: uncodable character>");
os.put(c);
os << _("</LyX Warning>");
} else {
// add location information and throw again.
e.par_id = id();
e.pos = i;
throw(e);
}
}
}

View File

@ -11,6 +11,7 @@
#include <config.h>
#include "LaTeXHighlighter.h"
#include "qt_helpers.h"
#include <QString>
#include <QTextDocument>
@ -25,6 +26,8 @@ LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent)
keywordFormat.setFontWeight(QFont::Bold);
commentFormat.setForeground(Qt::darkGray);
mathFormat.setForeground(Qt::red);
warningFormat.setForeground(Qt::red);
warningFormat.setFontWeight(QFont::Bold);
}
@ -90,7 +93,7 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
// * that is the first character in a line
// * that is preceded by
// ** an even number of backslashes
// ** any character other than a backslash
// ** any character other than a backslash
QRegExp exprComment("(?:^|[^\\\\])(?:\\\\\\\\)*(%).*$");
text.indexOf(exprComment);
index = exprComment.pos(1);
@ -101,6 +104,16 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
text.indexOf(exprComment, index + length);
index = exprComment.pos(1);
}
// <LyX Warning: ...> ... </LyX Warning>
QString opening = QRegExp::escape(qt_("<LyX Warning:"));
QString closing = QRegExp::escape(qt_("</LyX Warning>"));
QRegExp exprWarning(opening + "[^<]*" + closing);
index = text.indexOf(exprWarning);
while (index >= 0) {
int length = exprWarning.matchedLength();
setFormat(index, length, warningFormat);
index = text.indexOf(exprWarning, index + length);
}
}
} // namespace frontend

View File

@ -34,6 +34,7 @@ private:
QTextCharFormat commentFormat;
QTextCharFormat keywordFormat;
QTextCharFormat mathFormat;
QTextCharFormat warningFormat;
};
} // namespace frontend