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
This commit is contained in:
André Pönitz 2001-08-17 13:18:10 +00:00
parent 3c93fa9279
commit 71d514f39e
5 changed files with 61 additions and 9 deletions

View 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

View 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;
}
}
}

View 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_;

View 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_; }
///

View 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; }
///