]> git.lyx.org Git - features.git/commitdiff
write \mathrm{x}\mathrm{y} as \mathrm{xy} again
authorAndré Pönitz <poenitz@gmx.net>
Mon, 5 Nov 2001 17:08:45 +0000 (17:08 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 5 Nov 2001 17:08:45 +0000 (17:08 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2966 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/mathed/BUGS
src/mathed/Makefile.am
src/mathed/array.C
src/mathed/array.h
src/mathed/math_binaryopinset.C [new file with mode: 0644]
src/mathed/math_binaryopinset.h [new file with mode: 0644]
src/mathed/math_charinset.C
src/mathed/math_matrixinset.C
src/mathed/math_stringinset.C [new file with mode: 0644]
src/mathed/math_stringinset.h [new file with mode: 0644]
src/mathed/support.C
src/mathed/support.h

index 81bbe4122fec60f499887f1bdabffcbf61e9e1d1..b9c283822761b1d3ab2579f814eb14cbccc0be57 100644 (file)
@@ -224,9 +224,11 @@ From: 
 // there, because otherwise more math symbols would be ready by now..
 // just a thought.
  
-- Some math symbols aren't very well supported (to my knowledge). I'm 
-  thinking of underbraces with extra data in them,or [] options.
+//- Some math symbols aren't very well supported (to my knowledge). I'm 
+//  thinking of underbraces with extra data in them
 
+- Some math symbols aren't very well supported (to my knowledge). I'm 
+  thinking of [] options.
 
 Herbert Voss:
 
index 5ca7a92d22077f30a04ee387b379e3ec799153ff..17977d84b4f28548eb0417ea036c1fd4bdae6e8f 100644 (file)
@@ -28,6 +28,8 @@ libmathed_la_SOURCES = \
        math_braceinset.h \
        math_boxinset.C \
        math_boxinset.h \
+       math_binaryopinset.C \
+       math_binaryopinset.h \
        math_charinset.C \
        math_charinset.h \
        math_cursor.C \
@@ -94,6 +96,8 @@ libmathed_la_SOURCES = \
        math_sqrtinset.h \
        math_stackrelinset.C \
        math_stackrelinset.h \
+       math_stringinset.C \
+       math_stringinset.h \
        math_symbolinset.C \
        math_symbolinset.h \
        support.C \
index 3c029857907d2b32f8f9f65063dd9835c9845763..48deaf73ab7066e3b125c9b91b8cb0d7bb11a3bb 100644 (file)
@@ -5,6 +5,7 @@
 #include "math_inset.h"
 #include "math_charinset.h"
 #include "math_scriptinset.h"
+#include "math_stringinset.h"
 #include "debug.h"
 #include "array.h"
 #include "mathed/support.h"
@@ -171,24 +172,37 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
 }
 
 
+MathArray MathArray::glueChars() const
+{
+       MathArray ar;
+       const_iterator it = begin();
+       while (it != end()) {
+               if (it->nucleus() && it->nucleus()->asCharInset()) {
+                       string s = charSequence(it, end());
+                       MathTextCodes c = it->nucleus()->asCharInset()->code();
+                       ar.push_back(MathAtom(new MathStringInset(s, c)));
+                       it += s.size();
+               } else {
+                       ar.push_back(*it);
+                       ++it;
+               }
+       }
+       return ar;
+}
+
+
 void MathArray::write(MathWriteInfo & wi) const
+{
+       glueChars().write1(wi);
+}
+
+
+void MathArray::write1(MathWriteInfo & wi) const
 {
        for (const_iterator it = begin(); it != end(); ++it) {  
                MathInset * p = it->nucleus();
                if (!p)
                        continue;
-
-/*
-               if (p->asCharInset()) {
-                       MathCharInset const * c = p->asCharInset();
-                       // special handling for character sequences with the same code
-                       string s = charSequence(it, end());
-                       c->writeHeader(os);
-                       os << s;
-                       c->writeTrailer(os);
-                       it += s.size() - 1;
-               } else
-*/
                if (MathScriptInset const * q = asScript(it)) {
                        q->write(p, wi);
                        ++it;
index db0f1d4ea5840f37ad044815c19a5c024c81958b..7ce020c73ff42829045865defab406f5ce49e6ff 100644 (file)
@@ -97,8 +97,10 @@ public:
        MathAtom & at(size_type pos);
        ///
        MathAtom const & at(size_type pos) const;
-       ///
+       /// glue chars if necessary
        void write(MathWriteInfo & os) const;
+       /// raw write 
+       void write1(MathWriteInfo & os) const;
        ///
        void writeNormal(std::ostream &) const;
        ///
@@ -113,6 +115,8 @@ public:
        iterator end();
        ///
        MathScriptInset const * asScript(const_iterator it) const;
+       /// glues chars with the same attributes into MathStringInsets
+       MathArray glueChars() const;
 private:
        /// Buffer
        buffer_type bf_;
diff --git a/src/mathed/math_binaryopinset.C b/src/mathed/math_binaryopinset.C
new file mode 100644 (file)
index 0000000..4ceb067
--- /dev/null
@@ -0,0 +1,60 @@
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_binaryopinset.h"
+#include "Painter.h"
+#include "support/LOstream.h"
+#include "support.h"
+
+
+MathBinaryOpInset::MathBinaryOpInset(char op)
+       : MathNestInset(2), op_(op)
+{}
+
+
+MathInset * MathBinaryOpInset::clone() const
+{   
+       return new MathBinaryOpInset(*this);
+}
+
+
+int MathBinaryOpInset::opwidth() const
+{
+       return mathed_char_width(LM_TC_CONST, mi_, op_);
+}
+
+
+void MathBinaryOpInset::metrics(MathMetricsInfo const & mi) const
+{
+       mi_ = mi;
+       xcell(0).metrics(mi);
+       xcell(1).metrics(mi);
+       width_   = xcell(0).width() + xcell(1).width() + opwidth();
+       ascent_  = std::max(xcell(0).ascent(),  xcell(1).ascent());
+       descent_ = std::max(xcell(0).descent(), xcell(1).descent());
+}
+
+
+void MathBinaryOpInset::draw(Painter & pain, int x, int y) const
+{ 
+       xcell(0).draw(pain, x, y); 
+       drawChar(pain, LM_TC_CONST, mi_, x + xcell(0).width() , y, op_);
+       xcell(1).draw(pain, x + width() - xcell(1).width(), y); 
+}
+
+
+void MathBinaryOpInset::write(MathWriteInfo & os) const
+{
+       os << '{' << cell(0) << op_ << cell(1) << '}';
+}
+
+
+void MathBinaryOpInset::writeNormal(std::ostream & os) const
+{
+       os << "[binop " << op_ << ' ';
+       cell(0).writeNormal(os); 
+       os << " ";
+       cell(1).writeNormal(os); 
+       os << "]";
+}
diff --git a/src/mathed/math_binaryopinset.h b/src/mathed/math_binaryopinset.h
new file mode 100644 (file)
index 0000000..ccd5f08
--- /dev/null
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+#ifndef MATH_BINARYOPINSET_H
+#define MATH_BINARYOPINSET_H
+
+#include "math_nestinset.h"
+#include "math_nestinset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** An inset for multiplication
+    \author André Pönitz
+ */
+class MathBinaryOpInset : public MathNestInset {
+public:
+       ///
+       explicit MathBinaryOpInset(char op);
+       ///
+       MathInset * clone() const;
+       ///
+       void draw(Painter &, int x, int y) const;
+       ///
+       void write(MathWriteInfo & os) const;
+       ///
+       void writeNormal(std::ostream &) const;
+       ///
+       void metrics(MathMetricsInfo const & st) const;
+private:
+       ///
+       int opwidth() const;
+       ///
+       char op_;
+       ///
+       mutable MathMetricsInfo mi_;
+};
+#endif
index ff1852c162f67211bb9b97b3c57f004209ed875c..89c3378a783825e587fcec70345a392fb9037a62 100644 (file)
 #include "debug.h"
 
 
-namespace {
-
-char const * math_font_name[] = {
-       "mathrm",
-       "mathcal",
-       "mathbf",
-       "mathbb",
-       "mathsf",
-       "mathtt",
-       "mathit",
-       "textrm"
-};
-
-}
-
-
 MathCharInset::MathCharInset(char c)
        : char_(c), code_(nativeCode(c))
 {
@@ -91,14 +75,14 @@ void MathCharInset::draw(Painter & pain, int x, int y) 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 (math_font_name(code_))
+               os << '\\' << math_font_name(code_) << '{';
 }
 
 
 void MathCharInset::writeTrailer(std::ostream & os) const
 {
-       if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM)
+       if (math_font_name(code_))
                os << '}';
 }
 
index afa54f49816907d7e643cec26d31b864f0ad03cd..4fa1ebd1f10c906d02d9809b933d45848cc59df9 100644 (file)
@@ -243,6 +243,14 @@ bool MathMatrixInset::numbered(row_type row) const
 bool MathMatrixInset::ams() const
 {
        return true;
+
+       return 
+               objtype_ == LM_OT_ALIGN ||
+               objtype_ == LM_OT_MULTLINE ||
+               objtype_ == LM_OT_GATHER ||
+               objtype_ == LM_OT_ALIGNAT ||
+               objtype_ == LM_OT_XALIGNAT ||
+               objtype_ == LM_OT_XXALIGNAT;
 }
 
 
diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C
new file mode 100644 (file)
index 0000000..7a79dca
--- /dev/null
@@ -0,0 +1,70 @@
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <cctype>
+
+#include "math_stringinset.h"
+#include "LColor.h"
+#include "Painter.h"
+#include "support/LOstream.h"
+#include "support.h"
+#include "math_parser.h"
+#include "debug.h"
+
+
+MathStringInset::MathStringInset(string const & s, MathTextCodes t)
+       : str_(s), code_(t)
+{}
+
+
+MathInset * MathStringInset::clone() const
+{   
+       return new MathStringInset(*this);
+}
+
+
+int MathStringInset::ascent() const
+{
+       return mathed_string_ascent(code_, mi_, str_);
+}
+
+
+int MathStringInset::descent() const
+{
+       return mathed_string_descent(code_, mi_, str_);
+}
+
+
+int MathStringInset::width() const
+{
+       return mathed_string_width(code_, mi_, str_);
+}
+
+
+void MathStringInset::metrics(MathMetricsInfo const & mi) const
+{
+       mi_ = mi;
+}
+
+
+void MathStringInset::draw(Painter & pain, int x, int y) const
+{ 
+       //lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
+       drawStr(pain, code_, mi_, x, y, str_);
+}
+
+
+void MathStringInset::write(MathWriteInfo & os) const
+{
+       if (math_font_name(code_)) 
+               os << '\\' << math_font_name(code_) << '{' << str_ << '}';
+       else 
+               os << str_;
+}
+
+
+void MathStringInset::writeNormal(std::ostream & os) const
+{
+       os << "[string " << str_ << " " << "mathalpha" << "]";
+}
diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h
new file mode 100644 (file)
index 0000000..6dfc022
--- /dev/null
@@ -0,0 +1,46 @@
+// -*- C++ -*-
+#ifndef MATH_STRINGINSET_H
+#define MATH_STRINGINSET_H
+
+#include "math_inset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** Some cllection of chars with similar properties
+    \author André Pönitz
+ */
+
+class MathStringInset : public MathInset {
+public:
+       ///
+       MathStringInset(string const & s, MathTextCodes t);
+       ///
+       MathInset * clone() const;
+       ///
+       void metrics(MathMetricsInfo const & st) const;
+       ///
+       void draw(Painter &, int x, int y) const;
+       ///
+       void write(MathWriteInfo & os) const;
+       ///
+       void writeNormal(std::ostream &) const;
+       /// 
+       int ascent() const;
+       ///
+       int descent() const;
+       ///
+       int width() const;
+       ///
+       string & str();
+
+private:
+       /// the string
+       string str_;
+       /// the font to be used on screen
+       MathTextCodes code_;
+       ///
+       mutable MathMetricsInfo mi_;
+};
+#endif
index 59274e474e32ccca03fb3bdb6000d40c21e50ac7..bf19f55d65b854686ee2710f10b090ce4e2002e4 100644 (file)
@@ -591,6 +591,29 @@ int mathed_string_width(MathTextCodes type, MathMetricsInfo const & size,
 }
 
 
+int mathed_string_ascent(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s)
+{
+       LyXFont const font = whichFont(type, size);
+       int asc = 0;
+       for (string::const_iterator it = s.begin(); it != s.end(); ++it)
+               asc = max(asc, lyxfont::ascent(*it, font));
+       return asc;
+}
+
+
+int mathed_string_descent(MathTextCodes type, MathMetricsInfo const & size,
+       string const & s)
+{
+       LyXFont const font = whichFont(type, size);
+       int des = 0;
+       for (string::const_iterator it = s.begin(); it != s.end(); ++it)
+               des = max(des, lyxfont::descent(*it, font));
+       return des;
+}
+
+
+
 void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
        const string & name)
 {
@@ -714,3 +737,22 @@ void math_font_max_dim(MathTextCodes code, MathMetricsInfo const & siz,
 char const * latex_mathspace[] = {
        "!", ",", ":", ";", "quad", "qquad"
 };
+
+
+char const * math_font_name(MathTextCodes code)
+{
+       static char const * theFontNames[] = {
+               "mathrm",
+               "mathcal",
+               "mathbf",
+               "mathbb",
+               "mathsf",
+               "mathtt",
+               "mathit",
+               "textrm"
+       };
+
+       if (code >= LM_TC_RM && code <= LM_TC_TEXTRM) 
+               return theFontNames[code - LM_TC_RM];
+       return 0;
+}
index 44cbb93ddd614906c4e89fc8a41bdf476372ad7a..2b219a39a55eee2cda3612dd830deb3aab717a22 100644 (file)
@@ -54,6 +54,7 @@ void smallerStyleScript(MathMetricsInfo &);
 // decrease math size for fractions
 void smallerStyleFrac(MathMetricsInfo & st);
 
+char const * math_font_name(MathTextCodes type);
 
 
 #endif