mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-13 17:20:55 +00:00
Catch encoding exception when performing instant preview on an uncodable char (bug 6116).
* MathStream{.cpp, h}: - replace bool dryrun() by enum output that also knows whether the stream is for instant preview * InsetMathHull.cpp: - tell the stream whether we use it for instant preview. * MathString.cpp (write): - gracefully catch encoding exception for instant preview. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@30894 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2ae59edd73
commit
c35cfda727
@ -1607,7 +1607,7 @@ void Cursor::normalize()
|
||||
<< pos() << ' ' << lastpos() << " in idx: " << idx()
|
||||
<< " in atom: '";
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true, false);
|
||||
WriteStream wi(os, false, true, WriteStream::wsDefault);
|
||||
inset().asInsetMath()->write(wi);
|
||||
lyxerr << to_utf8(os.str()) << endl;
|
||||
pos() = lastpos();
|
||||
|
@ -65,7 +65,7 @@ Inset * InsetFormulaMacro::clone() const
|
||||
void InsetFormulaMacro::write(ostream & os) const
|
||||
{
|
||||
os << "FormulaMacro\n";
|
||||
WriteStream wi(os, false, false, false);
|
||||
WriteStream wi(os, false, false, WriteStream::wsDefault);
|
||||
tmpl()->write(wi);
|
||||
}
|
||||
|
||||
@ -74,7 +74,8 @@ int InsetFormulaMacro::latex(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
{
|
||||
//lyxerr << "InsetFormulaMacro::latex" << endl;
|
||||
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun,
|
||||
WriteStream wi(os, runparams.moving_arg, true,
|
||||
runparams.dryrun ? WriteStream::wsDryrun: WriteStream::wsDefault,
|
||||
runparams.encoding);
|
||||
tmpl()->write(wi);
|
||||
return 2;
|
||||
@ -84,7 +85,7 @@ int InsetFormulaMacro::latex(odocstream & os,
|
||||
int InsetFormulaMacro::plaintext(odocstream & os, OutputParams const & runparams) const
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, true, false, runparams.encoding);
|
||||
WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding);
|
||||
tmpl()->write(wi);
|
||||
|
||||
docstring const str = oss.str();
|
||||
|
@ -47,7 +47,7 @@ void InsetMath::dump() const
|
||||
{
|
||||
lyxerr << "---------------------------------------------" << endl;
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true, false);
|
||||
WriteStream wi(os, false, true, WriteStream::wsDefault);
|
||||
write(wi);
|
||||
lyxerr << to_utf8(os.str());
|
||||
lyxerr << "\n---------------------------------------------" << endl;
|
||||
@ -136,7 +136,7 @@ HullType InsetMath::getType() const
|
||||
ostream & operator<<(ostream & os, MathAtom const & at)
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, false, false);
|
||||
WriteStream wi(oss, false, false, WriteStream::wsDefault);
|
||||
at->write(wi);
|
||||
return os << to_utf8(oss.str());
|
||||
}
|
||||
@ -144,7 +144,7 @@ ostream & operator<<(ostream & os, MathAtom const & at)
|
||||
|
||||
odocstream & operator<<(odocstream & os, MathAtom const & at)
|
||||
{
|
||||
WriteStream wi(os, false, false, false);
|
||||
WriteStream wi(os, false, false, WriteStream::wsDefault);
|
||||
at->write(wi);
|
||||
return os;
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
||||
InsetMathGrid::metricsT(mi, dim);
|
||||
} else {
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true, false);
|
||||
WriteStream wi(os, false, true, WriteStream::wsDefault);
|
||||
write(wi);
|
||||
dim.wid = os.str().size();
|
||||
dim.asc = 1;
|
||||
@ -438,7 +438,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
|
||||
InsetMathGrid::drawT(pain, x, y);
|
||||
} else {
|
||||
odocstringstream os;
|
||||
WriteStream wi(os, false, true, false);
|
||||
WriteStream wi(os, false, true, WriteStream::wsDefault);
|
||||
write(wi);
|
||||
pain.draw(x, y, os.str().c_str());
|
||||
}
|
||||
@ -456,7 +456,7 @@ static docstring latexString(InsetMathHull const & inset)
|
||||
static Encoding const * encoding = 0;
|
||||
if (inset.isBufferValid())
|
||||
encoding = &(inset.buffer().params().encoding());
|
||||
WriteStream wi(ls, false, true, false, encoding);
|
||||
WriteStream wi(ls, false, true, WriteStream::wsPreview, encoding);
|
||||
inset.write(wi);
|
||||
return ls.str();
|
||||
}
|
||||
@ -1596,7 +1596,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
|
||||
void InsetMathHull::write(ostream & os) const
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, false, false);
|
||||
WriteStream wi(oss, false, false, WriteStream::wsDefault);
|
||||
oss << "Formula ";
|
||||
write(wi);
|
||||
os << to_utf8(oss.str());
|
||||
@ -1634,7 +1634,7 @@ int InsetMathHull::plaintext(odocstream & os, OutputParams const & runparams) co
|
||||
return tpain.textheight();
|
||||
} else {
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, true, false, runparams.encoding);
|
||||
WriteStream wi(oss, false, true, WriteStream::wsDefault, runparams.encoding);
|
||||
wi << cell(0);
|
||||
|
||||
docstring const str = oss.str();
|
||||
@ -1666,7 +1666,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
|
||||
// Workaround for db2latex: db2latex always includes equations with
|
||||
// \ensuremath{} or \begin{display}\end{display}
|
||||
// so we strip LyX' math environment
|
||||
WriteStream wi(ls, false, false, false, runparams.encoding);
|
||||
WriteStream wi(ls, false, false, WriteStream::wsDefault, runparams.encoding);
|
||||
InsetMathGrid::write(wi);
|
||||
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
||||
ms << ETag("alt");
|
||||
|
@ -364,7 +364,8 @@ void InsetMathNest::normalize(NormalStream & os) const
|
||||
|
||||
int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const
|
||||
{
|
||||
WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun,
|
||||
WriteStream wi(os, runparams.moving_arg, true,
|
||||
runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault,
|
||||
runparams.encoding);
|
||||
write(wi);
|
||||
return wi.line();
|
||||
|
@ -11,11 +11,13 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "InsetMathString.h"
|
||||
#include "MathFactory.h"
|
||||
#include "MathStream.h"
|
||||
#include "MathSupport.h"
|
||||
|
||||
#include "Encoding.h"
|
||||
|
||||
#include "support/debug.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/textutils.h"
|
||||
@ -159,14 +161,24 @@ void InsetMathString::write(WriteStream & os) const
|
||||
&& isAlphaASCII(command[command.size() - 1]))
|
||||
os.pendingSpace(true);
|
||||
} catch (EncodingException & e) {
|
||||
if (os.dryrun()) {
|
||||
// FIXME: this is OK for View->Source
|
||||
// but math preview will likely fail.
|
||||
switch (os.output()) {
|
||||
case WriteStream::wsDryrun: {
|
||||
os << "<" << _("LyX Warning: ")
|
||||
<< _("uncodable character") << " '";
|
||||
os << docstring(1, e.failed_char);
|
||||
os << "'>";
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
case WriteStream::wsPreview: {
|
||||
// indicate the encoding error by a boxed '?'
|
||||
os << "{\\fboxsep=1pt\\fbox{?}}";;
|
||||
LYXERR0("Uncodable character" << " '"
|
||||
<< docstring(1, e.failed_char)
|
||||
<< "'");
|
||||
break;
|
||||
}
|
||||
case WriteStream::wsDefault:
|
||||
default:
|
||||
// throw again
|
||||
throw(e);
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ void MacroData::write(odocstream & os, bool overwriteRedefinition) const
|
||||
// output template
|
||||
MathMacroTemplate const & tmpl =
|
||||
static_cast<MathMacroTemplate const &>(*inset);
|
||||
WriteStream wi(os, false, true, false);
|
||||
WriteStream wi(os, false, true, WriteStream::wsDefault);
|
||||
tmpl.write(wi, overwriteRedefinition);
|
||||
}
|
||||
|
||||
|
@ -1118,7 +1118,7 @@ void MathMacroTemplate::read(Lexer & lex)
|
||||
void MathMacroTemplate::write(ostream & os) const
|
||||
{
|
||||
odocstringstream oss;
|
||||
WriteStream wi(oss, false, false, false);
|
||||
WriteStream wi(oss, false, false, WriteStream::wsDefault);
|
||||
oss << "FormulaMacro\n";
|
||||
write(wi);
|
||||
os << to_utf8(oss.str());
|
||||
|
@ -107,17 +107,17 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
|
||||
}
|
||||
|
||||
|
||||
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun,
|
||||
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType output,
|
||||
Encoding const * encoding)
|
||||
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
|
||||
dryrun_(dryrun), pendingspace_(false), pendingbrace_(false),
|
||||
output_(output), pendingspace_(false), pendingbrace_(false),
|
||||
textmode_(false), locked_(0), line_(0), encoding_(encoding)
|
||||
{}
|
||||
|
||||
|
||||
WriteStream::WriteStream(odocstream & os)
|
||||
: os_(os), fragile_(false), firstitem_(false), latex_(false),
|
||||
dryrun_(false), pendingspace_(false), pendingbrace_(false),
|
||||
output_(wsDefault), pendingspace_(false), pendingbrace_(false),
|
||||
textmode_(false), locked_(0), line_(0), encoding_(0)
|
||||
{}
|
||||
|
||||
|
@ -33,7 +33,13 @@ class MathData;
|
||||
class WriteStream {
|
||||
public:
|
||||
///
|
||||
WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun,
|
||||
enum OutputType {
|
||||
wsDefault,
|
||||
wsDryrun,
|
||||
wsPreview
|
||||
};
|
||||
///
|
||||
WriteStream(odocstream & os, bool fragile, bool latex, OutputType output,
|
||||
Encoding const * encoding = 0);
|
||||
///
|
||||
explicit WriteStream(odocstream & os);
|
||||
@ -46,7 +52,7 @@ public:
|
||||
///
|
||||
bool latex() const { return latex_; }
|
||||
///
|
||||
bool dryrun() const { return dryrun_; }
|
||||
OutputType output() const { return output_; }
|
||||
///
|
||||
odocstream & os() { return os_; }
|
||||
///
|
||||
@ -80,8 +86,8 @@ private:
|
||||
bool firstitem_;
|
||||
/// are we writing to .tex?
|
||||
int latex_;
|
||||
/// is it for preview?
|
||||
bool dryrun_;
|
||||
/// output type (default, source preview, instant preview)?
|
||||
OutputType output_;
|
||||
/// do we have a space pending?
|
||||
bool pendingspace_;
|
||||
/// do we have a brace pending?
|
||||
|
@ -183,6 +183,9 @@ What's new
|
||||
- Fix a crash when accessing the Navigate menu after an empty inset has
|
||||
been dissolved (bug 6003).
|
||||
|
||||
- Fix a crash when performing instant preview on an uncodable character
|
||||
(bug 6116).
|
||||
|
||||
- Fix communication between lyxclient and server, which leads to a
|
||||
crash once CTRL+D is used on the client side (bug 6106).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user