From 71d514f39ef940ec9f847ee3e71403226536578d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 17 Aug 2001 13:18:10 +0000 Subject: [PATCH] write sequences of chars with same code as unit (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 | 2 ++ src/mathed/array.C | 34 ++++++++++++++++++++++++++++++++-- src/mathed/math_charinset.C | 23 ++++++++++++++++++----- src/mathed/math_charinset.h | 8 +++++++- src/mathed/math_inset.h | 3 ++- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index a7108e3366..7115697cc5 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -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 * math_factory.[Ch]: new files for the creation of math insets diff --git a/src/mathed/array.C b/src/mathed/array.C index 31de4bae0e..593b6fe8d4 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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; + } + } } diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index bee9ec01bd..94a7bf8b48 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -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_; diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 629e93e463..9925d0e350 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -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_; } /// diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index d5d5774254..ca8a5638c8 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -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; } /// -- 2.39.2