]> git.lyx.org Git - features.git/commitdiff
write sequences of chars with same code as unit
authorAndré Pönitz <poenitz@gmx.net>
Fri, 17 Aug 2001 13:18:10 +0000 (13:18 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 17 Aug 2001 13:18:10 +0000 (13:18 +0000)
(i.e. no more \mathrm{a}\mathrm{b})

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2533 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/array.C
src/mathed/math_charinset.C
src/mathed/math_charinset.h
src/mathed/math_inset.h

index a7108e3366aace7cfb35a1ba50dc41e17f6b7f20..7115697cc59e12ec512717aad56e8747d9ae7331 100644 (file)
@@ -2,6 +2,8 @@
 
        * math_parser.C: new "lexxer"
 
+       * array.C: write sequences of chars with same code as a unit
+
 2001-08-13  André Pönitz  <poenitz@gmx.net>
 
        * math_factory.[Ch]: new files for the creation of math insets
index 31de4bae0e7ec8af53f19e2e457768733eca0dd0..593b6fe8d4a87b058c709891c4f190fbd6757d8e 100644 (file)
@@ -3,6 +3,7 @@
 #endif
 
 #include "math_inset.h"
+#include "math_charinset.h"
 #include "debug.h"
 #include "array.h"
 #include "mathed/support.h"
@@ -173,11 +174,40 @@ std::ostream & operator<<(std::ostream & os, MathArray const & ar)
        return os;
 }
 
+// returns sequence of char with same code starting at it up to end
+// it might be less, though...
+string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
+{
+       string s;
+       MathCharInset const * p = (*it)->asCharInset();
+       if (!p)
+               return s;
+
+       MathTextCodes c = p->code();
+       while (it != end && (p = (*it)->asCharInset()) && p->code() == c) { 
+               s += p->getChar();
+               ++it;
+       }
+       return s;
+}
+
 
 void MathArray::write(ostream & os, bool fragile) const
 {
-       for (const_iterator it = begin(); it != end(); ++it)
-               (*it)->write(os, fragile);
+       for (const_iterator it = begin(); it != end(); ) {
+               MathCharInset const * p = (*it)->asCharInset();
+               if (p) {
+                       // special handling for character sequences with the same code
+                       string s = charSequence(it, end());
+                       p->writeHeader(os);
+                       os << s;
+                       p->writeTrailer(os);
+                       it += s.size();
+               } else {
+                       (*it)->write(os, fragile);
+                       ++it;
+               }
+       }
 }
 
 
index bee9ec01bd57d9dcffe17a6200205a6ca4424fed..94a7bf8b48c92c7b1093d174daad29a84bb8f8eb 100644 (file)
@@ -72,21 +72,34 @@ void MathCharInset::draw(Painter & pain, int x, int y) const
 }
 
 
-void MathCharInset::write(std::ostream & os, bool) const
+void MathCharInset::writeHeader(std::ostream & os) const
 {
        if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
                os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
+}
 
-       if (code_ == LM_TC_TEX || code_ == LM_TC_SPECIAL)
-               os << '\\';
-
-       os << char_;
 
+void MathCharInset::writeTrailer(std::ostream & os) const
+{
        if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
                os << '}';
 }
 
 
+void MathCharInset::writeRaw(std::ostream & os) const
+{
+       os << char_;
+}
+
+
+void MathCharInset::write(std::ostream & os, bool) const
+{
+       writeHeader(os);
+       writeRaw(os);
+       writeTrailer(os);
+}
+
+
 void MathCharInset::writeNormal(std::ostream & os) const
 {
        os << char_;
index 629e93e46332243e114421e1bbf37b75f3c46c57..9925d0e350689cc6cfae48a7098512795154729c 100644 (file)
@@ -29,6 +29,12 @@ public:
        ///
        void write(std::ostream &, bool fragile) const;
        ///
+       void writeHeader(std::ostream &) const;
+       ///
+       void writeTrailer(std::ostream &) const;
+       ///
+       void writeRaw(std::ostream &) const;
+       ///
        void writeNormal(std::ostream &) const;
        /// 
        int ascent() const;
@@ -37,7 +43,7 @@ public:
        ///
        int width() const;
        /// identifies Charinsets
-       bool isCharInset() const { return true; }
+       MathCharInset const * asCharInset() const { return this; }
        ///
        char getChar() const { return char_; }
        ///
index d5d5774254d5db0598504a9a1958a5783feeb316..ca8a5638c887554f8a30bee1fc074ea79e15aa2e 100644 (file)
@@ -39,6 +39,7 @@
 
 
 class LaTeXFeatures;
+class MathCharInset;
 
 class MathInset {
 public: 
@@ -175,7 +176,7 @@ public:
        /// identifies ArrayInsets
        virtual bool isArray() const { return false; }
        /// identifies Charinsets
-       virtual bool isCharInset() const { return false; }
+       virtual MathCharInset const * asCharInset() const { return 0; }
        ///
        virtual bool isActive() const { return nargs() > 0; }
        ///