]> git.lyx.org Git - features.git/commitdiff
Catch encoding exception when performing instant preview on an uncodable char (bug...
authorJürgen Spitzmüller <spitz@lyx.org>
Fri, 7 Aug 2009 05:25:22 +0000 (05:25 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Fri, 7 Aug 2009 05:25:22 +0000 (05:25 +0000)
* 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/trunk@30895 a592a061-630c-0410-9148-cb99ea01b6c8

src/Cursor.cpp
src/mathed/InsetFormulaMacro.cpp
src/mathed/InsetMath.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathString.cpp
src/mathed/MacroTable.cpp
src/mathed/MathMacroTemplate.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index 4785ce32643df208e1bdaa22dc8cd9113faf7e68..f12f442fd89650ee314e9dda5585b60fbee2e6ce 100644 (file)
@@ -1590,7 +1590,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();
index 1d80cbedbc90382ac4c3b94f585001c816f30ed7..eaa89d70e3087715204e36eef74f1541b4686012 100644 (file)
@@ -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,8 +74,9 @@ int InsetFormulaMacro::latex(odocstream & os,
                             OutputParams const & runparams) const
 {
        //lyxerr << "InsetFormulaMacro::latex" << endl;
-       WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun,
-                       runparams.encoding);
+       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();
index 139defa9b55b5d015b7ddba53a46490128ddb2b5..d6c40d7e30343f3133c9d4abd830a871292099e8 100644 (file)
@@ -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;
 }
index f632b80288ba4be53398c52c8e6a692071fb6973..d22203816f4774bc9066a094473b5d7d2b1100cb 100644 (file)
@@ -420,7 +420,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;
@@ -435,7 +435,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());
        }
@@ -453,7 +453,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();
 }
@@ -1632,7 +1632,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());
@@ -1670,7 +1670,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();
@@ -1702,7 +1702,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()), "&", "&amp;"), "<", "&lt;"));
                ms << ETag("alt");
index 484418ea4a5eb5586a4d0c32b28022d9f49b47b6..a0962e972a021e1c81210f5c40c29a6062569820 100644 (file)
@@ -377,8 +377,9 @@ void InsetMathNest::normalize(NormalStream & os) const
 
 int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const
 {
-       WriteStream wi(os, runparams.moving_arg, true, runparams.dryrun,
-                       runparams.encoding);
+       WriteStream wi(os, runparams.moving_arg, true,
+                      runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault,
+                      runparams.encoding);
        write(wi);
        return wi.line();
 }
index b1648a505a809f90000947ce01a7961ca8863d27..8b9db39c818facae13cab001d4dce3b7f6e6d0c2 100644 (file)
 #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);
                        }
index df996215fe86e42f299192ec9b16e3798164b51e..1a7ba802959b80f17d8af6e86247c746b9429240 100644 (file)
@@ -165,7 +165,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);
 }
 
index 6cccd8fa6aa27150c2eae1b9f857ed3707882167..421ca8146395f6d0666c5f61d036b9b69deb20d7 100644 (file)
@@ -1121,7 +1121,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());
index b8a8019d3665dbe0ad51f802e68442f3f7849246..bfba25e463a7eac03ddd1c19c224f409ed67d990 100644 (file)
@@ -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)
 {}
 
index a973975107dd0be2efbe19f6ed59e249f16af269..e93cef123d410480a4caaefe9dfde48b1537532b 100644 (file)
@@ -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?