]> git.lyx.org Git - features.git/commitdiff
Automate the setting of the ascii only flag.
authorEnrico Forestieri <forenr@lyx.org>
Thu, 4 Feb 2010 23:03:48 +0000 (23:03 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 4 Feb 2010 23:03:48 +0000 (23:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33328 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/CommandInset.cpp
src/mathed/MathFactory.cpp
src/mathed/MathStream.h

index c5448a21fc688ab89ad915a30385f5521a1d938e..6ed32754d46f2515e71e537dcb3bfda65d8b9d30 100644 (file)
@@ -65,15 +65,12 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
 
 void CommandInset::write(WriteStream & os) const
 {
-       ModeSpecifier specifier(os, currentMode(), lockedMode());
+       ModeSpecifier specifier(os, currentMode(), lockedMode(), asciiOnly());
        MathEnsurer ensurer(os, needs_math_mode_);
-       bool const ascii = os.asciiOnly();
-       os.asciiOnly(asciiOnly());
        os << '\\' << name_;
        if (cell(1).size())
                os << '[' << cell(1) << ']';
        os << '{' << cell(0) << '}';
-       os.asciiOnly(ascii);
 }
 
 
index eae377706593f0de34e9b8efd21ddaff1c40e7d1..2a32e9397f861419fd303fc9d0351a6928241baa 100644 (file)
@@ -278,7 +278,8 @@ bool ensureMath(WriteStream & os, bool needs_math_mode, bool macro)
 }
 
 
-int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked)
+int ensureMode(WriteStream & os, InsetMath::mode_type mode,
+               bool locked, bool ascii)
 {
        bool textmode = mode == InsetMath::TEXT_MODE;
        if (os.latex() && textmode && os.pendingBrace()) {
@@ -287,10 +288,12 @@ int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked)
                os.pendingSpace(false);
                os.textMode(true);
        }
-       int oldmodes = os.textMode() ? 1 : 0;
+       int oldmodes = os.textMode() ? 0x01 : 0;
        os.textMode(textmode);
-       oldmodes |= os.lockedMode() ? 2 : 0;
+       oldmodes |= os.lockedMode() ? 0x02 : 0;
        os.lockedMode(locked);
+       oldmodes |= os.asciiOnly() ? 0x04 : 0;
+       os.asciiOnly(ascii);
        return oldmodes;
 }
 
index 5eb2f8de2fb1206b89794938a7572702142680bb..6fb8f8265fe18b3b45d8458edfa096876fa19871 100644 (file)
@@ -127,7 +127,7 @@ WriteStream & operator<<(WriteStream &, unsigned int);
 bool ensureMath(WriteStream & os, bool needs_math_mode = true, bool macro = false);
 
 /// ensure the requested mode, possibly by closing \ensuremath
-int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked);
+int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked, bool ascii);
 
 
 /**
@@ -191,6 +191,8 @@ private:
  * the mode needs being temporarily switched when a command would not work
  * in the current mode. As there are cases where this switching is to be
  * avoided, the optional third parameter can be used to lock the mode.
+ * When the mode is locked, the optional fourth parameter specifies whether
+ * strings are to be output by using a suitable ascii representation.
  *
  * Example 1:
  *
@@ -204,6 +206,13 @@ private:
  *
  * Sets the current mode to text mode and disallows mode switching.
  *
+ * Example 3:
+ *
+ *      ModeSpecifier specifier(os, TEXT_MODE, true, true);
+ *
+ * Sets the current mode to text mode, disallows mode switching, and outputs
+ * strings as ascii only.
+ *
  * At the end of specifier's scope the mode is reset to its previous value.
  */
 class ModeSpecifier
@@ -211,13 +220,14 @@ class ModeSpecifier
 public:
        ///
        explicit ModeSpecifier(WriteStream & os, InsetMath::mode_type mode,
-                               bool locked = false)
-               : os_(os), oldmodes_(ensureMode(os, mode, locked)) {}
+                               bool locked = false, bool ascii = false)
+               : os_(os), oldmodes_(ensureMode(os, mode, locked, ascii)) {}
        ///
        ~ModeSpecifier()
        {
-               os_.textMode(oldmodes_ & 1);
-               os_.lockedMode(oldmodes_ & 2);
+               os_.textMode(oldmodes_ & 0x01);
+               os_.lockedMode(oldmodes_ & 0x02);
+               os_.asciiOnly(oldmodes_ & 0x04);
        }
 private:
        ///