From d652a84f4b10251af9e9d216e5642506047cdb29 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Thu, 4 Feb 2010 23:03:48 +0000 Subject: [PATCH] Automate the setting of the ascii only flag. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33328 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/CommandInset.cpp | 5 +---- src/mathed/MathFactory.cpp | 9 ++++++--- src/mathed/MathStream.h | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/mathed/CommandInset.cpp b/src/mathed/CommandInset.cpp index c5448a21fc..6ed32754d4 100644 --- a/src/mathed/CommandInset.cpp +++ b/src/mathed/CommandInset.cpp @@ -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); } diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index eae3777065..2a32e9397f 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -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; } diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 5eb2f8de2f..6fb8f8265f 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -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: /// -- 2.39.2