]> git.lyx.org Git - features.git/commitdiff
*** empty log message ***
authorAndré Pönitz <poenitz@gmx.net>
Thu, 30 Aug 2001 08:55:13 +0000 (08:55 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 30 Aug 2001 08:55:13 +0000 (08:55 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2626 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/math_charinset.C
src/mathed/math_charinset.h
src/mathed/math_cursor.C
src/mathed/math_defs.h
src/mathed/math_factory.C
src/mathed/math_parser.C
src/mathed/math_specialcharinset.C [new file with mode: 0644]
src/mathed/math_specialcharinset.h [new file with mode: 0644]
src/mathed/support.C

index ca542e96686652cf7a96e9fab2c83a7abd1eef81..aa18fccd2b2c811f41051122737728c65961487f 100644 (file)
@@ -82,6 +82,8 @@ libmathed_la_SOURCES = \
        math_sizeinset.h \
        math_spaceinset.C \
        math_spaceinset.h \
+       math_specialcharinset.C \
+       math_specialcharinset.h \
        math_sqrtinset.C \
        math_sqrtinset.h \
        math_stackrelinset.C \
index bfb6a7c3ab05996af66c92de8a65658abc59bb4e..353f60e9e51929d6611e321ecfeccd7bc673b1ab 100644 (file)
 
 
 MathCharInset::MathCharInset(char c)
-       : char_(c), code_(nativeCode(c)), needbs_(false)
+       : char_(c), code_(nativeCode(c))
 {
 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
 }
 
 
 MathCharInset::MathCharInset(char c, MathTextCodes t)
-       : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t), needbs_(false)
-{
-//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
-}
-
-
-MathCharInset::MathCharInset(char c, MathTextCodes t, bool needbs)
-       : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t), needbs_(needbs)
+       : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
 {
 //lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
 }
@@ -38,8 +31,6 @@ MathTextCodes MathCharInset::nativeCode(char c) const
 {
        if (isalpha(c))
                return LM_TC_VAR;
-       if (strchr("#$%{|}", c))
-               return LM_TC_SPECIAL;
        //if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
        return LM_TC_CONST;
 }
@@ -100,8 +91,6 @@ void MathCharInset::writeTrailer(std::ostream & os) const
 
 void MathCharInset::writeRaw(std::ostream & os) const
 {
-       if (needbs_)
-               os << "\\";
        os << char_;
 }
 
@@ -116,8 +105,6 @@ void MathCharInset::write(std::ostream & os, bool) const
 
 void MathCharInset::writeNormal(std::ostream & os) const
 {
-       if (needbs_)
-               os << "\\";
        os << char_;
 }
 
index 1822ed0e9e088ce06e9174b15589f4a77f02d017..37f6029e079a91ace6131b4587e2496d597ade1e 100644 (file)
@@ -19,8 +19,6 @@ public:
        ///
        MathCharInset(char c, MathTextCodes t);
        ///
-       MathCharInset(char c, MathTextCodes t, bool needbs);
-       ///
        MathInset * clone() const;
        ///
        MathTextCodes nativeCode(char c) const;
@@ -60,7 +58,5 @@ private:
        char char_;
        /// the font to be used on screen
        MathTextCodes code_;
-       /// do wee need a backslash when writing LaTeX?
-       bool needbs_;
 };
 #endif
index 5241a194a50b9c79210b8239f54f09e067ce653e..8b3acf61402ee62776121bf2b197d117ec1fd00c 100644 (file)
@@ -37,6 +37,7 @@
 #include "math_matrixinset.h"
 #include "math_scriptinset.h"
 #include "math_spaceinset.h"
+#include "math_specialcharinset.h"
 #include "math_parser.h"
 
 using std::endl;
@@ -1281,6 +1282,11 @@ void MathCursor::interpret(string const & s)
                return;
        }
 
+       if (lastcode_ != LM_TC_TEX && strchr("#$%{|}", c)) {
+               insert(new MathSpecialCharInset(c));    
+               return;
+       }
+
        if (lastcode_ == LM_TC_TEX) {
                if (macroName().empty()) {
                        insert(c, LM_TC_TEX);
@@ -1299,11 +1305,6 @@ void MathCursor::interpret(string const & s)
                return;
        }
 
-       if (c == '{' || c == '}') {
-               niceInsert(new MathCharInset(c, LM_TC_SPECIAL));
-               return;
-       }
-
        if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
                static char const greek[26] =
                        {'A', 'B', 'X',  0 , 'E',  0 ,  0 , 'H', 'I',  0 ,
index b09fb2d06b95f98cc130c2e8c89fe8e8d8918231..3ed2b92ac6e045c211ed01b8562e637253278c30 100644 (file)
@@ -75,8 +75,6 @@ enum MathTextCodes  {
        LM_TC_TEXTRM,
        /// Math mode TeX characters ",;:{}"  
        LM_TC_TEX,
-       /// Special characters "{}&#_%"
-       LM_TC_SPECIAL,
        /// Internal code when typing greek
        LM_TC_GREEK,
        /// Internal code when typing a single greek character
index 342f1e50b7c0d92bdf90c20868dd95987d86b1bf..4078da8ed39ac79e22d4237bd7908fb9103fd359 100644 (file)
@@ -15,6 +15,7 @@
 #include "math_notinset.h"
 #include "math_rootinset.h"
 #include "math_spaceinset.h"
+#include "math_specialcharinset.h"
 #include "math_sqrtinset.h"
 #include "math_symbolinset.h"
 #include "math_stackrelinset.h"
@@ -30,6 +31,8 @@ MathInset * createMathInset(latexkeys const * l)
                        return new MathBigopInset(l);
                case LM_TK_FUNCLIM:
                        return new MathFuncLimInset(l);
+               case LM_TK_SPECIAL:
+                       return new MathSpecialCharInset(l->id);
                case LM_TK_SYM: 
                        return new MathSymbolInset(l);
                case LM_TK_STACK:
index 4eadb7bc9900b6814d0157855fa5d3765e702eb3..168a438bdfcb5286b3916a53d7ff108666939923 100644 (file)
@@ -39,6 +39,7 @@
 #include "math_rootinset.h"
 #include "math_sqrtinset.h"
 #include "math_scriptinset.h"
+#include "math_specialcharinset.h"
 #include "math_sqrtinset.h"
 #include "debug.h"
 #include "support.h"
@@ -682,18 +683,18 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                }
 
                else if (t.cat() == catBegin) {
-                       array.push_back(new MathCharInset('{', LM_TC_SPECIAL));
+                       array.push_back(new MathCharInset('{', LM_TC_TEX));
                }
 
                else if (t.cat() == catEnd) {
                        if (flags & FLAG_BRACE_LAST)
                                return;
-                       array.push_back(new MathCharInset('}', LM_TC_SPECIAL));
+                       array.push_back(new MathCharInset('}', LM_TC_TEX));
                }
                
                else if (t.cat() == catAlign) {
                        lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
-                       array.push_back(new MathCharInset('&', LM_TC_SPECIAL));
+                       array.push_back(new MathCharInset('&', LM_TC_TEX));
                }
                
                else if (t.cat() == catSuper)
@@ -796,7 +797,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                        break;
 
                else  LM_TK_SPECIAL:
-                       array.push_back(new MathCharInset(ival_, LM_TC_SPECIAL));
+                       array.push_back(new MathCharInset(ival_, LM_TC_TEX));
                        break;
 */
                
@@ -849,7 +850,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                        int pos;
                        for (pos = array.size() - 1; pos >= 0; --pos) {
                                MathInset * q = array.nextInset(pos);
-                               if (q->getChar() == '{' && q->code() == LM_TC_SPECIAL)
+                               if (q->getChar() == '{')
                                        break;
                        }
                        if (pos >= 0) {
diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C
new file mode 100644 (file)
index 0000000..4fe90e8
--- /dev/null
@@ -0,0 +1,62 @@
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_specialcharinset.h"
+#include "support/LOstream.h"
+#include "support.h"
+
+
+MathSpecialCharInset::MathSpecialCharInset(char c)
+       : char_(c)
+{}
+
+
+MathInset * MathSpecialCharInset::clone() const
+{   
+       return new MathSpecialCharInset(*this);
+}
+
+
+int MathSpecialCharInset::ascent() const
+{
+       return mathed_char_ascent(LM_TC_CONST, size(), char_);
+}
+
+
+int MathSpecialCharInset::descent() const
+{
+       return mathed_char_descent(LM_TC_CONST, size(), char_);
+}
+
+
+int MathSpecialCharInset::width() const
+{
+       return mathed_char_width(LM_TC_CONST, size(), char_);
+}
+
+
+void MathSpecialCharInset::metrics(MathStyles st) const
+{
+       size_ = st;
+}
+
+
+void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
+{ 
+       xo(x);
+       yo(y);
+       drawChar(pain, LM_TC_CONST, size_, x, y, char_);
+}
+
+
+void MathSpecialCharInset::write(std::ostream & os, bool) const
+{
+       os << "\\" << char_;
+}
+
+
+void MathSpecialCharInset::writeNormal(std::ostream & os) const
+{
+       os << "\\" << char_;
+}
diff --git a/src/mathed/math_specialcharinset.h b/src/mathed/math_specialcharinset.h
new file mode 100644 (file)
index 0000000..6582868
--- /dev/null
@@ -0,0 +1,41 @@
+// -*- C++ -*-
+#ifndef MATH_SPECIALCHARINSET_H
+#define MATH_SPECIALCHARINSET_H
+
+#include "math_inset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** An inset for characters like {, #, and $ that need to be escaped 
+    when written out, but can be inserted by a single keystroke
+    \author André Pönitz
+ */
+
+class MathSpecialCharInset : public MathInset {
+public:
+       ///
+       explicit MathSpecialCharInset(char c);
+       ///
+       MathInset * clone() const;
+       ///
+       void metrics(MathStyles st) const;
+       ///
+       void draw(Painter &, int x, int y) const;
+       ///
+       void write(std::ostream &, bool fragile) const;
+       ///
+       void writeNormal(std::ostream &) const;
+       /// 
+       int ascent() const;
+       ///
+       int descent() const;
+       ///
+       int width() const;
+
+private:
+       /// the character
+       char char_;
+};
+#endif
index 87d0af49baa55d9ca12fac1cf66c2814616ba070..91528084e2550f05a2061a0c47483f5b6009d9a5 100644 (file)
@@ -165,7 +165,6 @@ LyXFont WhichFont(MathTextCodes type, MathStyles size)
                f = Math_Fonts[5];
                break;
 
-       case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
        case LM_TC_TEXTRM:
        case LM_TC_CONST:
        case LM_TC_TEX: