From: André Pönitz Date: Mon, 5 Nov 2001 17:08:45 +0000 (+0000) Subject: write \mathrm{x}\mathrm{y} as \mathrm{xy} again X-Git-Tag: 1.6.10~20399 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=dff2911bda426ad439e6475f62183cedd7044801;p=features.git write \mathrm{x}\mathrm{y} as \mathrm{xy} again git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2966 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/BUGS b/src/mathed/BUGS index 81bbe4122f..b9c2838227 100644 --- a/src/mathed/BUGS +++ b/src/mathed/BUGS @@ -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: diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 5ca7a92d22..17977d84b4 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 \ diff --git a/src/mathed/array.C b/src/mathed/array.C index 3c02985790..48deaf73ab 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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; diff --git a/src/mathed/array.h b/src/mathed/array.h index db0f1d4ea5..7ce020c73f 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -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 index 0000000000..4ceb067faa --- /dev/null +++ b/src/mathed/math_binaryopinset.C @@ -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 index 0000000000..ccd5f085f4 --- /dev/null +++ b/src/mathed/math_binaryopinset.h @@ -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 diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index ff1852c162..89c3378a78 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -13,22 +13,6 @@ #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 << '}'; } diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index afa54f4981..4fa1ebd1f1 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -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 index 0000000000..7a79dca1cb --- /dev/null +++ b/src/mathed/math_stringinset.C @@ -0,0 +1,70 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +#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 index 0000000000..6dfc022145 --- /dev/null +++ b/src/mathed/math_stringinset.h @@ -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 diff --git a/src/mathed/support.C b/src/mathed/support.C index 59274e474e..bf19f55d65 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -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; +} diff --git a/src/mathed/support.h b/src/mathed/support.h index 44cbb93ddd..2b219a39a5 100644 --- a/src/mathed/support.h +++ b/src/mathed/support.h @@ -54,6 +54,7 @@ void smallerStyleScript(MathMetricsInfo &); // decrease math size for fractions void smallerStyleFrac(MathMetricsInfo & st); +char const * math_font_name(MathTextCodes type); #endif