split super/subscript handling in new base class MathUpDownInset and

MathScriptInset/MathBigOpInset


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2220 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-12 07:18:29 +00:00
parent b33a63e177
commit 0024f42724
49 changed files with 526 additions and 485 deletions

View File

@ -1,4 +1,11 @@
2001-07-12 André Pönitz <poenitz@htwm.de>
* math_updowninset.[hC]: new base class for script and bigop insets
*.[hC]: subsequnet changes to all Metric() functions
* math_parser.C: small changes (\sqrt0 is read properly now)
2001-07-10 André Pönitz <poenitz@htwm.de> 2001-07-10 André Pönitz <poenitz@htwm.de>
* math_accentinset.[hC]: rewrite * math_accentinset.[hC]: rewrite

View File

@ -66,6 +66,8 @@ libmathed_la_SOURCES = \
math_spaceinset.h \ math_spaceinset.h \
math_sqrtinset.C \ math_sqrtinset.C \
math_sqrtinset.h \ math_sqrtinset.h \
math_updowninset.C \
math_updowninset.h \
math_utils.C \ math_utils.C \
math_utils.h \ math_utils.h \
matriz.C \ matriz.C \

View File

@ -23,7 +23,7 @@ MathArray::~MathArray()
{ {
for (int pos = 0; pos < size(); next(pos)) for (int pos = 0; pos < size(); next(pos))
if (MathIsInset(pos)) if (MathIsInset(pos))
delete GetInset(pos); delete nextInset(pos);
} }
@ -32,7 +32,7 @@ MathArray::MathArray(MathArray const & array)
{ {
for (int pos = 0; pos < size(); next(pos)) for (int pos = 0; pos < size(); next(pos))
if (isInset(pos)) if (isInset(pos))
replace(pos, GetInset(pos)->clone()); replace(pos, nextInset(pos)->clone());
} }
@ -75,7 +75,7 @@ void MathArray::substitute(MathMacro const & m)
MathArray tmp; MathArray tmp;
for (int pos = 0; pos < size(); next(pos)) { for (int pos = 0; pos < size(); next(pos)) {
if (isInset(pos)) if (isInset(pos))
GetInset(pos)->substitute(tmp, m); nextInset(pos)->substitute(tmp, m);
else else
tmp.push_back(GetChar(pos), GetCode(pos)); tmp.push_back(GetChar(pos), GetCode(pos));
} }
@ -91,7 +91,7 @@ MathArray & MathArray::operator=(MathArray const & array)
} }
MathInset * MathArray::GetInset(int pos) const MathInset * MathArray::nextInset(int pos) const
{ {
if (!isInset(pos)) if (!isInset(pos))
return 0; return 0;
@ -100,6 +100,14 @@ MathInset * MathArray::GetInset(int pos) const
return p; return p;
} }
MathInset * MathArray::prevInset(int pos) const
{
if (!pos)
return 0;
prev(pos);
return nextInset(pos);
}
byte MathArray::GetChar(int pos) const byte MathArray::GetChar(int pos) const
{ {
return pos < size() ? bf_[pos + 1] : '\0'; return pos < size() ? bf_[pos + 1] : '\0';
@ -157,7 +165,7 @@ void MathArray::insert(int pos, MathArray const & array)
bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end()); bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end());
for (int p = pos; p < pos + array.size(); next(p)) for (int p = pos; p < pos + array.size(); next(p))
if (isInset(p)) if (isInset(p))
replace(p, GetInset(p)->clone()); replace(p, nextInset(p)->clone());
} }
@ -230,35 +238,12 @@ MathInset * MathArray::back_inset() const
int pos = size(); int pos = size();
prev(pos); prev(pos);
if (isInset(pos)) if (isInset(pos))
return GetInset(pos); return nextInset(pos);
} }
return 0; return 0;
} }
MathScriptInset * MathArray::prevScriptInset(int pos) const
{
if (!pos)
return 0;
prev(pos);
MathInset * inset = GetInset(pos);
if (inset && inset->isScriptInset())
return static_cast<MathScriptInset *>(inset);
return 0;
}
MathScriptInset * MathArray::nextScriptInset(int pos) const
{
MathInset * inset = GetInset(pos);
if (inset && inset->isScriptInset())
return static_cast<MathScriptInset *>(inset);
return 0;
}
void MathArray::dump2(ostream & os) const void MathArray::dump2(ostream & os) const
{ {
for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it) for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it)
@ -272,7 +257,7 @@ void MathArray::dump(ostream & os) const
{ {
for (int pos = 0; pos < size(); next(pos)) { for (int pos = 0; pos < size(); next(pos)) {
if (isInset(pos)) if (isInset(pos))
os << "<inset: " << GetInset(pos) << ">"; os << "<inset: " << nextInset(pos) << ">";
else else
os << "<" << int(bf_[pos]) << " " << int(bf_[pos+1]) << ">"; os << "<" << int(bf_[pos]) << " " << int(bf_[pos+1]) << ">";
} }
@ -296,7 +281,7 @@ void MathArray::Write(ostream & os, bool fragile) const
for (int pos = 0; pos < size(); next(pos)) { for (int pos = 0; pos < size(); next(pos)) {
if (isInset(pos)) { if (isInset(pos)) {
GetInset(pos)->Write(os, fragile); nextInset(pos)->Write(os, fragile);
} else { } else {

View File

@ -24,7 +24,6 @@
#include "LString.h" #include "LString.h"
class MathInset; class MathInset;
class MathScriptInset;
class MathMacro; class MathMacro;
class Painter; class Painter;
@ -33,9 +32,7 @@ class Painter;
#endif #endif
/** \class MathArray /** \class MathArray
\brief A resizable array. \brief Low level container for math insets
A general purpose resizable array.
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
\author André Pönitz \author André Pönitz
@ -101,11 +98,9 @@ public:
/// ///
/// ///
MathInset * GetInset(int pos) const; MathInset * nextInset(int pos) const;
/// ///
MathScriptInset * prevScriptInset(int pos) const; MathInset * prevInset(int pos) const;
///
MathScriptInset * nextScriptInset(int pos) const;
/// ///
byte GetChar(int pos) const; byte GetChar(int pos) const;
/// read subsequent chars of the same kind. /// read subsequent chars of the same kind.

View File

@ -147,6 +147,7 @@ LyXFont WhichFont(short type, int size)
case LM_TC_SPECIAL: //f = Math_Fonts[0]; break; case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
case LM_TC_TEXTRM: case LM_TC_TEXTRM:
case LM_TC_TEX:
case LM_TC_RM: case LM_TC_RM:
f = Math_Fonts[6]; f = Math_Fonts[6];
break; break;
@ -184,6 +185,9 @@ LyXFont WhichFont(short type, int size)
if (type != LM_TC_TEXTRM) if (type != LM_TC_TEXTRM)
f.setColor(LColor::math); f.setColor(LColor::math);
if (type == LM_TC_TEX)
f.setColor(LColor::latex);
return f; return f;
} }

View File

@ -17,7 +17,7 @@ MathInset * MathAccentInset::clone() const
return new MathAccentInset(*this); return new MathAccentInset(*this);
} }
void MathAccentInset::Metrics(MathStyles st) void MathAccentInset::Metrics(MathStyles st, int, int)
{ {
xcell(0).Metrics(st); xcell(0).Metrics(st);
ascent_ = xcell(0).ascent(); ascent_ = xcell(0).ascent();

View File

@ -20,7 +20,7 @@ public:
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
int getAccentCode() const; int getAccentCode() const;
/// ///

View File

@ -1,17 +1,15 @@
#include <config.h> #include <config.h>
#include <functional>
#include "math_bigopinset.h" #include "math_bigopinset.h"
#include "LColor.h"
#include "Painter.h" #include "Painter.h"
#include "mathed/support.h" #include "mathed/support.h"
#include "support/LOstream.h" #include "support/LOstream.h"
using std::ostream; using std::ostream;
MathBigopInset::MathBigopInset(string const & name, int id) MathBigopInset::MathBigopInset(string const & name, int id)
: MathScriptInset(false, true), lims_(0), sym_(id) : MathUpDownInset(false, false), sym_(id), limits_(0)
{ {
SetName(name); SetName(name);
} }
@ -23,132 +21,116 @@ MathInset * MathBigopInset::clone() const
} }
int MathBigopInset::limits() const
{
return limits_;
}
void MathBigopInset::limits(int limits)
{
limits_ = limits;
}
bool MathBigopInset::hasLimits() const
{
return limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY);
}
void MathBigopInset::Write(ostream & os, bool fragile) const void MathBigopInset::Write(ostream & os, bool fragile) const
{ {
//bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY; //bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY;
os << '\\' << name(); os << '\\' << name();
if (limits() == 1) MathUpDownInset::Write(os, fragile);
os << "\\limits ";
else if (limits() == -1)
os << "\\nolimits ";
else
os << ' ';
MathScriptInset::Write(os, fragile);
} }
void MathBigopInset::WriteNormal(ostream & os) const void MathBigopInset::WriteNormal(ostream & os) const
{ {
os << "[bigop " << name(); os << "[bigop " << name() << "] ";
if (limits() == 1)
os << "\\limits ";
else if (limits() == -1)
os << "\\nolimits ";
else
os << ' ';
MathScriptInset::WriteNormal(os);
os << "] ";
} }
void MathBigopInset::Metrics(MathStyles st)
void MathBigopInset::Metrics(MathStyles st, int, int)
{ {
MathScriptInset::Metrics(st); //cerr << "\nBigopDraw\n";
size(st); size(st);
string s;
short t;
if (sym_ < 256 || sym_ == LM_oint) { if (sym_ < 256 || sym_ == LM_oint) {
char const c = (sym_ == LM_oint) ? LM_int : sym_; ssym_ = string();
s += c; ssym_ += (sym_ == LM_oint) ? LM_int : sym_;
t = LM_TC_BSYM; code_ = LM_TC_BSYM;
} else { } else {
s = name(); ssym_ = name();
t = LM_TC_TEXTRM; code_ = LM_TC_TEXTRM;
} }
int asc, des, wid; int wid;
mathed_string_dim(t, size(), s, asc, des, wid); mathed_string_dim(code_, size(), ssym_, ascent_, descent_, wid);
if (sym_ == LM_oint) if (sym_ == LM_oint)
wid += 2; wid += 2;
//cerr << " asc: " << ascent_ << " des: " << descent_
// << " wid: " << wid << "\n";
//cerr << " hasLimits: " << hasLimits() << " up: "
// << up() << " down: " << down() << "\n";
width_ = wid;
if (hasLimits()) { if (hasLimits()) {
ascent_ = asc + xcell(0).height() + 2; xcell(0).Metrics(st);
descent_ = des + xcell(1).height() + 2; xcell(1).Metrics(st);
width_ = std::max(width_, wid); //cerr << " 0: ascent_: " << xcell(0).ascent() << " descent_: " <<
// xcell(0).descent() << " width_: " << xcell(0).width() << "\n";
//cerr << " 1: ascent_: " << xcell(1).ascent() << " descent_: " <<
// xcell(1).descent() << " width_: " << xcell(1).width() << "\n";
if (up()) {
ascent_ += xcell(0).height() + 1;
width_ = std::max(width_, xcell(0).width());
dy0_ = - (ascent_ - xcell(0).ascent());
}
if (down()) {
descent_ += xcell(1).height() + 1;
width_ = std::max(width_, xcell(1).width());
dy1_ = descent_ - xcell(1).descent();
}
dxx_ = (width_ - wid) / 2;
dx0_ = (width_ - xcell(0).width()) / 2;
dx1_ = (width_ - xcell(1).width()) / 2;
//cerr << " ascent_: " << ascent_ << " descent_: "
// << descent_ << " width_: " << width_ << "\n";
//cerr << " dx0_: " << dx0_ << " dx1_: " << dx1_
// << " dxx_: " << dxx_ << "\n";
//cerr << " dy0_: " << dy0_ << " dy1_: " << dy1_
// << "\n";
} else { } else {
ascent_ = std::max(ascent_, asc); MathUpDownInset::Metrics(st, ascent_, descent_);
descent_ = std::max(descent_, des); width_ += wid;
width_ += wid; dx0_ = wid;
dx1_ = wid;
dxx_ = 0;
} }
} }
void MathBigopInset::draw(Painter & pain, int x, int y) void MathBigopInset::draw(Painter & pain, int x, int y)
{ {
xo(x); xo(x);
yo(y); yo(y);
string s; pain.text(x + dxx_, y, ssym_, mathed_get_font(code_, size()));
short t;
if (up())
if (sym_ < 256 || sym_ == LM_oint) { xcell(0).draw(pain, x + dx0_, y + dy0_);
s += (sym_ == LM_oint) ? LM_int : sym_; if (down())
t = LM_TC_BSYM; xcell(1).draw(pain, x + dx1_, y + dy1_);
} else {
s = name();
t = LM_TC_TEXTRM;
}
if (sym_ == LM_oint) { if (sym_ == LM_oint) {
int wid; int xx = x - 1;
int asc; int yy = y - (ascent_ - descent_) / 2;
int des; pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline);
mathed_char_dim(t, size(), LM_int, asc, des, wid);
wid += 2;
pain.arc(x - 1, y - (asc - des) / 2, wid, wid, 0, 360 * 64, LColor::mathline);
}
int asc, des, wid;
mathed_string_dim(t, size(), s, asc, des, wid);
if (hasLimits()) {
int w = width();
pain.text(x + (w - wid)/2, y, s, mathed_get_font(t, size()));
xcell(0).draw
(pain, x + (w - xcell(0).width())/2, y - asc - xcell(0).descent() - 1);
xcell(1).draw
(pain, x + (w - xcell(1).width())/2, y + des + xcell(1).ascent() + 1);
} else {
pain.text(x, y, s, mathed_get_font(t, size()));
MathScriptInset::draw(pain, x + wid, y);
} }
} }
int MathBigopInset::limits() const
{
return lims_;
}
void MathBigopInset::limits(int limit)
{
lims_ = limit;
}
bool MathBigopInset::hasLimits() const
{
return limits() == 1 || (limits() == 0 && size() == LM_ST_DISPLAY);
}
void MathBigopInset::idxDelete(int & idx, bool & popit, bool & deleteit)
{
if (idx == 0)
up(false);
else
down(false);
popit = true;
deleteit = true;
}

View File

@ -2,35 +2,45 @@
#ifndef MATH_BIGOPINSET_H #ifndef MATH_BIGOPINSET_H
#define MATH_BIGOPINSET_H #define MATH_BIGOPINSET_H
#include "math_scriptinset.h" #include "math_updowninset.h"
/// big operators /// big operators
class MathBigopInset : public MathScriptInset { class MathBigopInset : public MathUpDownInset {
public: public:
/// ///
MathBigopInset(string const &, int); MathBigopInset(string const &, int);
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///
void draw(Painter &, int, int);
///
void Write(std::ostream &, bool fragile) const; void Write(std::ostream &, bool fragile) const;
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
int limits() const; void draw(Painter &, int, int);
///
bool hasLimits() const;
/// ///
void limits(int); void limits(int);
/// ///
void idxDelete(int & idx, bool & popit, bool & deleteit); int limits() const;
/// Identifies BigopInsets
bool isBigopInset() const { return true; }
private: private:
/// 1: \limits, -1: \nolimits, 0: use default ///
int lims_; bool hasLimits() const;
/// ///
int sym_; int sym_;
///
string ssym_;
///
short code_;
/// 1: \limits, -1: \nolimits, 0: use default
int limits_;
/// x offset for drawing the superscript
int dx0_;
/// x offset for drawing the subscript
int dx1_;
/// x offset for drawing the inner symbol
int dxx_;
}; };
#endif #endif

View File

@ -306,9 +306,9 @@ void MathCursor::SetPos(int x, int y)
lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n"; lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n";
MathInset * n = nextInset(); MathInset * n = nextInset();
MathInset * p = prevInset(); MathInset * p = prevInset();
if (n && (n->isActive() || n->isScriptInset()) && n->covers(x, y)) if (n && (n->isActive() || n->isUpDownInset()) && n->covers(x, y))
push(n, true); push(n, true);
else if (p && (p->isActive() || p->isScriptInset()) && p->covers(x, y)) { else if (p && (p->isActive() || p->isUpDownInset()) && p->covers(x, y)) {
array().prev(cursor_); array().prev(cursor_);
push(p, false); push(p, false);
} else } else
@ -536,7 +536,7 @@ bool MathCursor::toggleLimits()
return false; return false;
MathInset * p = prevInset(); MathInset * p = prevInset();
int old = p->limits(); int old = p->limits();
p->limits(old == -1 ? 1 : -1); p->limits(old < 0 ? 1 : -1);
return old != p->limits(); return old != p->limits();
} }
@ -554,29 +554,27 @@ void MathCursor::Interpret(string const & s)
in_word_set(s) << " \n"; in_word_set(s) << " \n";
if (s[0] == '^') { if (s[0] == '^') {
MathScriptInset * p = nearbyScriptInset(); MathUpDownInset * p = nearbyUpDownInset();
if (!p) { if (!p) {
p = new MathScriptInset; p = new MathScriptInset(true, false);
insert(p); insert(p);
array().prev(cursor_); array().prev(cursor_);
} }
push(p, true); push(p, true);
if (!p->up()) p->up(true);
p->up(true);
idx_ = 0; idx_ = 0;
return; return;
} }
if (s[0] == '_') { if (s[0] == '_') {
MathScriptInset * p = nearbyScriptInset(); MathUpDownInset * p = nearbyUpDownInset();
if (!p) { if (!p) {
p = new MathScriptInset; p = new MathScriptInset(false, true);
insert(p); insert(p);
array().prev(cursor_); array().prev(cursor_);
} }
push(p, true); push(p, true);
if (!p->down()) p->down(true);
p->down(true);
idx_ = 1; idx_ = 1;
return; return;
} }
@ -1064,28 +1062,30 @@ MathInset * MathCursor::prevInset() const
int c = cursor_; int c = cursor_;
if (!array().prev(c)) if (!array().prev(c))
return 0; return 0;
return array().GetInset(c); return array().nextInset(c);
} }
MathInset * MathCursor::nextInset() const MathInset * MathCursor::nextInset() const
{ {
normalize(); normalize();
return array().GetInset(cursor_); return array().nextInset(cursor_);
} }
MathScriptInset * MathCursor::nearbyScriptInset() const MathUpDownInset * MathCursor::nearbyUpDownInset() const
{ {
normalize(); normalize();
MathScriptInset * p = array().prevScriptInset(cursor_); MathInset * p = array().prevInset(cursor_);
if (p) if (p && p->isUpDownInset())
return p; return static_cast<MathUpDownInset *>(p);
return array().nextScriptInset(cursor_); p = array().nextInset(cursor_);
if (p && p->isUpDownInset())
return static_cast<MathUpDownInset *>(p);
return 0;
} }
MathArray & MathCursor::array() const MathArray & MathCursor::array() const
{ {
static MathArray dummy; static MathArray dummy;

View File

@ -25,7 +25,7 @@
class MathInset; class MathInset;
class MathFuncInset; class MathFuncInset;
class MathScriptInset; class MathUpDownInset;
class InsetFormulaBase; class InsetFormulaBase;
class MathArray; class MathArray;
class MathXArray; class MathXArray;
@ -217,7 +217,7 @@ private:
/// ///
MathInset * prevInset() const; MathInset * prevInset() const;
/// ///
MathScriptInset * nearbyScriptInset() const; MathUpDownInset * nearbyUpDownInset() const;
/// ///
MathFuncInset * imacro; MathFuncInset * imacro;

View File

@ -28,7 +28,7 @@ MathInset * MathDecorationInset::clone() const
void MathDecorationInset::Metrics(MathStyles st) void MathDecorationInset::Metrics(MathStyles st, int, int)
{ {
xcell(0).Metrics(st); xcell(0).Metrics(st);
size_ = st; size_ = st;

View File

@ -22,7 +22,7 @@ public:
/// ///
void Write(std::ostream &, bool fragile) const; void Write(std::ostream &, bool fragile) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
private: private:
/// ///
int deco_; int deco_;

View File

@ -89,7 +89,7 @@ int MathDelimInset::dw() const
} }
void MathDelimInset::Metrics(MathStyles st) void MathDelimInset::Metrics(MathStyles st, int, int)
{ {
xcell(0).Metrics(st); xcell(0).Metrics(st);
size_ = st; size_ = st;

View File

@ -22,7 +22,7 @@ public:
/// ///
void Write(std::ostream &, bool fragile) const; void Write(std::ostream &, bool fragile) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
private: private:
int dw() const; int dw() const;
/// ///

View File

@ -33,7 +33,7 @@ void MathDotsInset::draw(Painter & pain, int x, int y)
} }
void MathDotsInset::Metrics(MathStyles st) void MathDotsInset::Metrics(MathStyles st, int, int)
{ {
size(st); size(st);
mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_); mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);

View File

@ -23,7 +23,7 @@ public:
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
protected: protected:
/// ///
int dh_; int dh_;

View File

@ -24,7 +24,7 @@ MathInset * MathFracInset::clone() const
} }
void MathFracInset::Metrics(MathStyles st) void MathFracInset::Metrics(MathStyles st, int, int)
{ {
size_ = smallerStyleFrac(st); size_ = smallerStyleFrac(st);
xcell(0).Metrics(size_); xcell(0).Metrics(size_);

View File

@ -22,7 +22,7 @@ public:
/// ///
virtual void WriteNormal(std::ostream &) const; virtual void WriteNormal(std::ostream &) const;
/// ///
virtual void Metrics(MathStyles st); virtual void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
virtual void draw(Painter &, int x, int baseline); virtual void draw(Painter &, int x, int baseline);
/// ///

View File

@ -55,7 +55,7 @@ void MathFuncInset::WriteNormal(std::ostream & os) const
} }
void MathFuncInset::Metrics(MathStyles st) void MathFuncInset::Metrics(MathStyles st, int, int)
{ {
LyXFont font = WhichFont(LM_TC_TEXTRM, size()); LyXFont font = WhichFont(LM_TC_TEXTRM, size());
#ifndef NO_LATEX #ifndef NO_LATEX

View File

@ -25,7 +25,7 @@ public:
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
private: private:
/// ///
bool lims_; bool lims_;

View File

@ -7,7 +7,6 @@
#include "math_grid.h" #include "math_grid.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "debug.h" #include "debug.h"
#include "Painter.h"
namespace { namespace {
@ -77,7 +76,7 @@ char MathGridInset::valign() const
return v_align_; return v_align_;
} }
void MathGridInset::Metrics(MathStyles st) void MathGridInset::Metrics(MathStyles st, int, int)
{ {
// let the cells adjust themselves // let the cells adjust themselves
MathInset::Metrics(st); MathInset::Metrics(st);

View File

@ -58,7 +58,7 @@ public:
/// ///
void Write(std::ostream &, bool fragile) const; void Write(std::ostream &, bool fragile) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///

View File

@ -70,12 +70,6 @@ void MathInset::limits(int)
{ {
} }
bool MathInset::hasLimits() const
{
return false;
}
string const & MathInset::name() const string const & MathInset::name() const
{ {
return name_; return name_;
@ -172,12 +166,6 @@ MathArray const & MathInset::cell(int i) const
} }
void MathInset::setData(MathArray const & a, int idx)
{
cells_[idx].data_ = a;
}
void MathInset::substitute(MathArray & array, MathMacro const & m) const void MathInset::substitute(MathArray & array, MathMacro const & m) const
{ {
MathInset * p = clone(); MathInset * p = clone();
@ -186,7 +174,7 @@ void MathInset::substitute(MathArray & array, MathMacro const & m) const
array.push_back(p); array.push_back(p);
} }
void MathInset::Metrics(MathStyles st) void MathInset::Metrics(MathStyles st, int, int)
{ {
size_ = st; size_ = st;
for (int i = 0; i < nargs(); ++i) for (int i = 0; i < nargs(); ++i)
@ -373,4 +361,3 @@ bool MathInset::covers(int x, int y) const
y >= yo_ - ascent_ && y >= yo_ - ascent_ &&
y <= yo_ + descent_; y <= yo_ + descent_;
} }

View File

@ -60,7 +60,7 @@ public:
/// Appends itself with macro arguments substituted /// Appends itself with macro arguments substituted
virtual void substitute(MathArray & array, MathMacro const & macro) const; virtual void substitute(MathArray & array, MathMacro const & macro) const;
/// Compute the size of the object /// Compute the size of the object
virtual void Metrics(MathStyles st) = 0; virtual void Metrics(MathStyles st, int = 0, int = 0) = 0;
/// ///
virtual int ascent() const; virtual int ascent() const;
/// ///
@ -70,8 +70,6 @@ public:
/// ///
virtual int height() const; virtual int height() const;
/// ///
virtual bool hasLimits() const;
///
virtual int limits() const; virtual int limits() const;
/// ///
virtual void limits(int); virtual void limits(int);
@ -136,8 +134,6 @@ public:
MathXArray & xcell(int); MathXArray & xcell(int);
/// ///
MathXArray const & xcell(int) const; MathXArray const & xcell(int) const;
///
void setData(MathArray const &, int);
/// ///
int xo() const; int xo() const;
@ -174,9 +170,11 @@ public:
/// ///
bool covers(int x, int y) const; bool covers(int x, int y) const;
/// Identifies ScriptInsets /// Identifies ScriptInsets
virtual bool isScriptInset() const { return false; } virtual bool isUpDownInset() const { return false; }
/// Identifies AccentInsets /// Identifies AccentInsets
virtual bool isAccentInset() const { return false; } virtual bool isAccentInset() const { return false; }
/// Identifies BigopInsets
virtual bool isBigopInset() const { return false; }
/// ///
virtual bool isActive() const { return nargs() > 0; } virtual bool isActive() const { return nargs() > 0; }

View File

@ -44,7 +44,7 @@ MathInset * MathMacro::clone() const
} }
void MathMacro::Metrics(MathStyles st) void MathMacro::Metrics(MathStyles st, int, int)
{ {
if (mathcursor && mathcursor->isInside(this)) { if (mathcursor && mathcursor->isInside(this)) {
expanded_ = tmplate_->xcell(0); expanded_ = tmplate_->xcell(0);

View File

@ -41,7 +41,7 @@ public:
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///

View File

@ -38,7 +38,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y)
} }
void MathMacroArgument::Metrics(MathStyles st) void MathMacroArgument::Metrics(MathStyles st, int, int)
{ {
char str[] = "#0"; char str[] = "#0";
str[1] += number_; str[1] += number_;

View File

@ -18,7 +18,7 @@ public:
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
void draw(Painter &, int x, int baseline); void draw(Painter &, int x, int baseline);
/// ///

View File

@ -114,7 +114,7 @@ void MathMacroTable::builtinMacros()
{ {
MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0); MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
MathAccentInset * p = new MathAccentInset(LM_not); MathAccentInset * p = new MathAccentInset(LM_not);
p->cell(0).push_back('0', LM_TC_VAR); p->cell(0).push_back('O', LM_TC_VAR);
t->push_back(p); t->push_back(p);
insertTemplate(t); insertTemplate(t);
} }

View File

@ -51,7 +51,7 @@ void MathMacroTemplate::Write(std::ostream & os, bool fragile) const
} }
void MathMacroTemplate::Metrics(MathStyles st) void MathMacroTemplate::Metrics(MathStyles st, int, int)
{ {
xcell(0).Metrics(st); xcell(0).Metrics(st);
size_ = st; size_ = st;

View File

@ -34,7 +34,7 @@ public:
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
private: private:
/// ///
int numargs_; int numargs_;

View File

@ -97,7 +97,7 @@ MathInset * MathMatrixInset::clone() const
} }
void MathMatrixInset::Metrics(MathStyles /* st */) void MathMatrixInset::Metrics(MathStyles /* st */, int, int)
{ {
size_ = (GetType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; size_ = (GetType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
@ -245,7 +245,7 @@ void MathMatrixInset::Validate1(LaTeXFeatures & features)
MathIter it(cell()); MathIter it(cell());
while (it.OK() && !(features.binom && features.boldsymbol)) { while (it.OK() && !(features.binom && features.boldsymbol)) {
MathInset * p = it.GetInset(); MathInset * p = it.nextInset();
if (p) { if (p) {
p = it.GetActiveInset(); p = it.GetActiveInset();
if (p) { if (p) {

View File

@ -29,7 +29,7 @@ public:
/// ///
void Write(std::ostream &, bool fragile) const; void Write(std::ostream &, bool fragile) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///

View File

@ -15,6 +15,8 @@
* the GNU General Public Licence version 2 or later. * the GNU General Public Licence version 2 or later.
*/ */
// {[(
#include <config.h> #include <config.h>
#include <cctype> #include <cctype>
@ -38,6 +40,7 @@
#include "math_funcinset.h" #include "math_funcinset.h"
#include "math_spaceinset.h" #include "math_spaceinset.h"
#include "math_sizeinset.h" #include "math_sizeinset.h"
#include "math_scriptinset.h"
#include "math_dotsinset.h" #include "math_dotsinset.h"
#include "math_fracinset.h" #include "math_fracinset.h"
#include "math_deliminset.h" #include "math_deliminset.h"
@ -75,12 +78,10 @@ lexcode_enum lexcode[256];
char const * latex_special_chars = "#$%&_{}"; char const * latex_special_chars = "#$%&_{}";
/// Read TeX into data, flags give stop conditions
void mathed_parse(MathArray & data, unsigned flags);
namespace { namespace {
void mathed_parse(MathArray & array, unsigned flags);
unsigned char getuchar(std::istream * is) unsigned char getuchar(std::istream * is)
{ {
char c; char c;
@ -93,17 +94,22 @@ const unsigned char LM_TK_CLOSE = '}';
enum { enum {
FLAG_BRACE = 1 << 0, // A { needed //} FLAG_BRACE = 1 << 0, // A { needed //}
FLAG_BRACE_OPT = 1 << 2, // Optional { FLAG_BRACE_OPT = 1 << 2, // Optional { //}
FLAG_BRACE_LAST = 1 << 3, // Last } ends the parsing process FLAG_BRACE_LAST = 1 << 3, // // { Last } ends the parsing process
FLAG_BRACK_ARG = 1 << 4, // Optional [ FLAG_BRACK_ARG = 1 << 4, // Optional [ //]
FLAG_RIGHT = 1 << 5, // Next right ends the parsing process FLAG_RIGHT = 1 << 5, // Next right ends the parsing process
FLAG_END = 1 << 6, // Next end ends the parsing process FLAG_END = 1 << 6, // Next end ends the parsing process
FLAG_BRACE_FONT = 1 << 7, // Next } closes a font FLAG_BRACE_FONT = 1 << 7, // // { Next } closes a font
FLAG_BRACK_END = 1 << 9, // Next ] ends the parsing process FLAG_BRACK_END = 1 << 9, // // [ Next ] ends the parsing process
FLAG_AMPERSAND = 1 << 10, // Next & ends the parsing process FLAG_AMPERSAND = 1 << 10, // Next & ends the parsing process
FLAG_NEWLINE = 1 << 11 // Next \\ ends the parsing process FLAG_NEWLINE = 1 << 11, // Next \\ ends the parsing process
// Read a (possibly braced token)
FLAG_ITEM = FLAG_BRACE_OPT | FLAG_BRACE_LAST
}; };
}
/// ///
union { union {
@ -114,6 +120,7 @@ union {
} yylval; } yylval;
string yytext; string yytext;
int yylineno; int yylineno;
istream * yyis; istream * yyis;
@ -302,9 +309,9 @@ int yylex()
yylval.i = (i < 4) ? i : 0; yylval.i = (i < 4) ? i : 0;
return LM_TK_SPACE; return LM_TK_SPACE;
} }
if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) { if (lexcode[c] == LexAlpha) {
yytext.erase(); yytext.erase();
while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) { while (lexcode[c] == LexAlpha) {
yytext += c; yytext += c;
c = getuchar(yyis); c = getuchar(yyis);
} }
@ -333,25 +340,26 @@ int yylex()
} }
void handle_frac(MathArray & dat, string const & name) MathInset * lastUpDownInset(MathArray & array, bool up, bool down)
{
MathFracInset * p = new MathFracInset(name);
mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
mathed_parse(p->cell(1), FLAG_BRACE | FLAG_BRACE_LAST);
dat.push_back(p);
}
MathScriptInset * lastScriptInset(MathArray & array)
{ {
MathInset * p = array.back_inset(); MathInset * p = array.back_inset();
if (!p || !p->isScriptInset()) { if (!p || !p->isUpDownInset()) {
p = new MathScriptInset; p = new MathScriptInset(up, down);
array.push_back(p); array.push_back(p);
} }
return static_cast<MathScriptInset *>(p); MathUpDownInset * q = static_cast<MathScriptInset *>(p);
if (up)
q->up(true);
if (down)
q->down(down);
return p;
} }
MathBigopInset * lastBigopInset(MathArray & array)
{
MathInset * p = array.back_inset();
return (p && p->isBigopInset()) ? static_cast<MathBigopInset *>(p) : 0;
} }
@ -480,10 +488,21 @@ MathInset * mathed_parse()
} }
namespace {
void handle_frac(MathArray & array, string const & name)
{
MathFracInset * p = new MathFracInset(name);
mathed_parse(p->cell(0), FLAG_ITEM);
mathed_parse(p->cell(1), FLAG_ITEM);
array.push_back(p);
}
void mathed_parse(MathArray & array, unsigned flags) void mathed_parse(MathArray & array, unsigned flags)
{ {
int t = yylex(); int t = yylex();
int tprev = 0;
bool panic = false; bool panic = false;
static int plevel = -1; static int plevel = -1;
yyvarcode = LM_TC_VAR; yyvarcode = LM_TC_VAR;
@ -577,28 +596,16 @@ void mathed_parse(MathArray & array, unsigned flags)
break; break;
case '^': case '^':
{ mathed_parse(lastUpDownInset(array, true, false)->cell(0), FLAG_ITEM);
MathArray ar;
mathed_parse(ar, FLAG_BRACE_OPT | FLAG_BRACE_LAST);
MathScriptInset * p = lastScriptInset(array);
p->setData(ar, 0);
p->up(true);
break; break;
}
case '_': case '_':
{ mathed_parse(lastUpDownInset(array, false, true)->cell(1), FLAG_ITEM);
MathArray ar;
mathed_parse(ar, FLAG_BRACE_OPT | FLAG_BRACE_LAST);
MathScriptInset * p = lastScriptInset(array);
p->setData(ar, 1);
p->down(true);
break; break;
}
case LM_TK_LIMIT: case LM_TK_LIMIT:
{ {
MathScriptInset * p = lastScriptInset(array); MathBigopInset * p = lastBigopInset(array);
if (p) if (p)
p->limits(yylval.l->id ? 1 : -1); p->limits(yylval.l->id ? 1 : -1);
break; break;
@ -669,15 +676,13 @@ void mathed_parse(MathArray & array, unsigned flags)
{ {
unsigned char c = getuchar(yyis); unsigned char c = getuchar(yyis);
if (c == '[') { if (c == '[') {
MathRootInset * rt = new MathRootInset; array.push_back(new MathRootInset);
mathed_parse(rt->cell(0), FLAG_BRACK_END); mathed_parse(array.back_inset()->cell(0), FLAG_BRACK_END);
mathed_parse(rt->cell(1), FLAG_BRACE | FLAG_BRACE_LAST); mathed_parse(array.back_inset()->cell(1), FLAG_ITEM);
array.push_back(rt);
} else { } else {
yyis->putback(c); yyis->putback(c);
MathSqrtInset * sq = new MathSqrtInset; array.push_back(new MathSqrtInset);
mathed_parse(sq->cell(0), FLAG_BRACE | FLAG_BRACE_LAST); mathed_parse(array.back_inset()->cell(0), FLAG_ITEM);
array.push_back(sq);
} }
break; break;
} }
@ -700,7 +705,7 @@ void mathed_parse(MathArray & array, unsigned flags)
rd = yylval.i; rd = yylval.i;
MathDelimInset * dl = new MathDelimInset(ld, rd); MathDelimInset * dl = new MathDelimInset(ld, rd);
dl->setData(ar, 0); dl->cell(0) = ar;
array.push_back(dl); array.push_back(dl);
break; break;
} }
@ -766,7 +771,7 @@ void mathed_parse(MathArray & array, unsigned flags)
if (MathMacroTable::hasTemplate(yytext)) { if (MathMacroTable::hasTemplate(yytext)) {
MathMacro * m = MathMacroTable::cloneTemplate(yytext); MathMacro * m = MathMacroTable::cloneTemplate(yytext);
for (int i = 0; i < m->nargs(); ++i) for (int i = 0; i < m->nargs(); ++i)
mathed_parse(m->cell(i), FLAG_BRACE_OPT | FLAG_BRACE_LAST); mathed_parse(m->cell(i), FLAG_ITEM);
array.push_back(m); array.push_back(m);
m->Metrics(LM_ST_TEXT); m->Metrics(LM_ST_TEXT);
} else } else
@ -831,7 +836,6 @@ void mathed_parse(MathArray & array, unsigned flags)
} // end of big switch } // end of big switch
tprev = t;
if (panic) { if (panic) {
lyxerr << " Math Panic, expect problems!" << endl; lyxerr << " Math Panic, expect problems!" << endl;
// Search for the end command. // Search for the end command.
@ -849,6 +853,8 @@ void mathed_parse(MathArray & array, unsigned flags)
--plevel; --plevel;
} }
}
MathInset * mathed_parse(istream & is) MathInset * mathed_parse(istream & is)
{ {
@ -879,3 +885,5 @@ MathInset * mathed_parse(LyXLex & lex)
return p; return p;
} }
//]})

View File

@ -34,7 +34,7 @@ MathInset * MathRootInset::clone() const
} }
void MathRootInset::Metrics(MathStyles st) void MathRootInset::Metrics(MathStyles st, int, int)
{ {
MathInset::Metrics(st); MathInset::Metrics(st);
size_ = st; size_ = st;

View File

@ -39,7 +39,7 @@ public:
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
bool idxUp(int & idx, int & pos) const; bool idxUp(int & idx, int & pos) const;
/// ///

View File

@ -4,22 +4,12 @@
#pragma implementation #pragma implementation
#endif #endif
#include <functional>
#include "math_scriptinset.h" #include "math_scriptinset.h"
#include "LColor.h"
#include "Painter.h"
#include "debug.h"
#include "mathed/support.h"
#include "support/LOstream.h" #include "support/LOstream.h"
MathScriptInset::MathScriptInset()
: MathInset(2), up_(false), down_(false)
{}
MathScriptInset::MathScriptInset(bool up, bool down) MathScriptInset::MathScriptInset(bool up, bool down)
: MathInset(2), up_(up), down_(down) : MathUpDownInset(up, down)
{} {}
@ -29,67 +19,6 @@ MathInset * MathScriptInset::clone() const
} }
void MathScriptInset::Metrics(MathStyles st)
{
size_ = smallerStyleScript(st);
xcell(0).Metrics(size_);
xcell(1).Metrics(size_);
width_ = std::max(xcell(0).width(), xcell(1).width()) + 2;
if (up())
ascent_ = std::max(ascent_, xcell(0).height() + 9);
if (down())
descent_ = std::max(descent_, xcell(1).height());
}
bool MathScriptInset::up() const
{
return up_;
}
bool MathScriptInset::down() const
{
return down_;
}
void MathScriptInset::up(bool b)
{
up_ = b;
}
void MathScriptInset::down(bool b)
{
down_ = b;
}
void MathScriptInset::draw(Painter & pain, int x, int y)
{
xo(x);
yo(y);
if (up())
xcell(0).draw(pain, x, y - xcell(0).descent() - 9);
if (down())
xcell(1).draw(pain, x, y + xcell(1).ascent());
}
void MathScriptInset::Write(std::ostream & os, bool fragile) const
{
if (up()) {
os << "^{";
cell(0).Write(os, fragile);
os << "}";
}
if (down()) {
os << "_{";
cell(1).Write(os, fragile);
os << "}";
}
}
void MathScriptInset::WriteNormal(std::ostream & os) const void MathScriptInset::WriteNormal(std::ostream & os) const
{ {
if (up()) { if (up()) {
@ -104,86 +33,6 @@ void MathScriptInset::WriteNormal(std::ostream & os) const
} }
} }
bool MathScriptInset::idxRight(int &, int &) const
{
return false;
}
bool MathScriptInset::idxLeft(int &, int &) const
{
return false;
}
bool MathScriptInset::idxUp(int & idx, int & pos) const
{
if (idx == 0 || !up())
return false;
idx = 0;
pos = 0;
return true;
}
bool MathScriptInset::idxDown(int & idx, int & pos) const
{
if (idx == 1 || !down())
return false;
idx = 1;
pos = 0;
return true;
}
bool MathScriptInset::idxFirst(int & idx, int & pos) const
{
idx = up() ? 0 : 1;
pos = 0;
return true;
}
bool MathScriptInset::idxLast(int & idx, int & pos) const
{
idx = down() ? 1 : 0;
pos = cell(idx).size();
return true;
}
bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
{
if (!up())
return false;
idx = 0;
pos = 0;
return true;
}
bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
{
if (!down())
return false;
idx = 1;
pos = 0;
return true;
}
bool MathScriptInset::idxLastUp(int & idx, int & pos) const
{
if (!up())
return false;
idx = 0;
pos = cell(idx).size();
return true;
}
bool MathScriptInset::idxLastDown(int & idx, int & pos) const
{
if (!down())
return false;
idx = 1;
pos = cell(idx).size();
return true;
}
void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit) void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
{ {

View File

@ -2,7 +2,7 @@
#ifndef MATH_SCRIPTINSET_H #ifndef MATH_SCRIPTINSET_H
#define MATH_SCRIPTINSET_H #define MATH_SCRIPTINSET_H
#include "math_inset.h" #include "math_updowninset.h"
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
@ -12,61 +12,18 @@
\author André Pönitz \author André Pönitz
*/ */
class MathScriptInset : public MathInset { class MathScriptInset : public MathUpDownInset {
public: public:
///
MathScriptInset();
/// ///
MathScriptInset(bool up, bool down); MathScriptInset(bool up, bool down);
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///
void Write(std::ostream &, bool fragile) const;
///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
///
void Metrics(MathStyles st);
///
void draw(Painter &, int x, int baseline);
///
bool idxUp(int & idx, int & pos) const;
///
bool idxDown(int & idx, int & pos) const;
///
bool idxLeft(int & idx, int & pos) const;
///
bool idxRight(int & idx, int & pos) const;
///
bool idxFirst(int & idx, int & pos) const;
///
bool idxFirstUp(int & idx, int & pos) const;
///
bool idxFirstDown(int & idx, int & pos) const;
///
bool idxLast(int & idx, int & pos) const;
///
bool idxLastUp(int & idx, int & pos) const;
///
bool idxLastDown(int & idx, int & pos) const;
///
bool up() const;
///
bool down() const;
///
void up(bool);
///
void down(bool);
///
bool isActive() const { return false; }
/// Identifies ScriptInsets /// Identifies ScriptInsets
bool isScriptInset() const { return true; } bool isUpDownInset() const { return true; }
/// ///
void idxDelete(int & idx, bool & popit, bool & deleteit); void idxDelete(int & idx, bool & popit, bool & deleteit);
private:
///
bool up_;
///
bool down_;
}; };
#endif #endif

View File

@ -45,7 +45,7 @@ void MathSizeInset::draw(Painter & pain, int x, int y)
} }
void MathSizeInset::Metrics(MathStyles /* st */) void MathSizeInset::Metrics(MathStyles /* st */, int, int)
{ {
xcell(0).Metrics(style_); xcell(0).Metrics(style_);
ascent_ = xcell(0).ascent_; ascent_ = xcell(0).ascent_;

View File

@ -20,7 +20,7 @@ public:
/// ///
virtual MathInset * clone() const; virtual MathInset * clone() const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
void draw(Painter &, int x, int baseline); void draw(Painter &, int x, int baseline);
/// ///

View File

@ -55,7 +55,7 @@ void MathSpaceInset::WriteNormal(std::ostream & os) const
} }
void MathSpaceInset::Metrics(MathStyles st) void MathSpaceInset::Metrics(MathStyles st, int, int)
{ {
size_ = st; size_ = st;
width_ = space_ ? space_ * 2 : 2; width_ = space_ ? space_ * 2 : 2;

View File

@ -23,7 +23,7 @@ public:
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
void SetSpace(int sp); void SetSpace(int sp);
/// ///

View File

@ -22,7 +22,7 @@ MathInset * MathSqrtInset::clone() const
} }
void MathSqrtInset::Metrics(MathStyles st) void MathSqrtInset::Metrics(MathStyles st, int, int)
{ {
xcell(0).Metrics(st); xcell(0).Metrics(st);
size_ = st; size_ = st;
@ -51,7 +51,7 @@ void MathSqrtInset::draw(Painter & pain, int x, int y)
void MathSqrtInset::Write(std::ostream & os, bool fragile) const void MathSqrtInset::Write(std::ostream & os, bool fragile) const
{ {
os << '\\' << name_ << '{'; os << "\\sqrt{";
cell(0).Write(os, fragile); cell(0).Write(os, fragile);
os << '}'; os << '}';
} }

View File

@ -24,6 +24,6 @@ public:
/// ///
void WriteNormal(std::ostream &) const; void WriteNormal(std::ostream &) const;
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
}; };
#endif #endif

View File

@ -0,0 +1,178 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_updowninset.h"
#include "support/LOstream.h"
MathUpDownInset::MathUpDownInset()
: MathInset(2), up_(false), down_(false)
{}
MathUpDownInset::MathUpDownInset(bool up, bool down)
: MathInset(2), up_(up), down_(down)
{}
MathInset * MathUpDownInset::clone() const
{
return new MathUpDownInset(*this);
}
bool MathUpDownInset::up() const
{
return up_;
}
bool MathUpDownInset::down() const
{
return down_;
}
void MathUpDownInset::up(bool b)
{
up_ = b;
}
void MathUpDownInset::down(bool b)
{
down_ = b;
}
bool MathUpDownInset::idxRight(int &, int &) const
{
return false;
}
bool MathUpDownInset::idxLeft(int &, int &) const
{
return false;
}
bool MathUpDownInset::idxUp(int & idx, int & pos) const
{
if (idx == 0 || !up())
return false;
idx = 0;
pos = 0;
return true;
}
bool MathUpDownInset::idxDown(int & idx, int & pos) const
{
if (idx == 1 || !down())
return false;
idx = 1;
pos = 0;
return true;
}
bool MathUpDownInset::idxFirst(int & idx, int & pos) const
{
idx = up() ? 0 : 1;
pos = 0;
return true;
}
bool MathUpDownInset::idxLast(int & idx, int & pos) const
{
idx = down() ? 1 : 0;
pos = cell(idx).size();
return true;
}
bool MathUpDownInset::idxFirstUp(int & idx, int & pos) const
{
if (!up())
return false;
idx = 0;
pos = 0;
return true;
}
bool MathUpDownInset::idxFirstDown(int & idx, int & pos) const
{
if (!down())
return false;
idx = 1;
pos = 0;
return true;
}
bool MathUpDownInset::idxLastUp(int & idx, int & pos) const
{
if (!up())
return false;
idx = 0;
pos = cell(idx).size();
return true;
}
bool MathUpDownInset::idxLastDown(int & idx, int & pos) const
{
if (!down())
return false;
idx = 1;
pos = cell(idx).size();
return true;
}
void MathUpDownInset::idxDelete(int & idx, bool & popit, bool & deleteit)
{
if (idx == 0)
up(false);
else
down(false);
popit = true;
deleteit = !(up() || down());
}
void MathUpDownInset::Write(std::ostream & os, bool fragile) const
{
if (up()) {
os << "^{";
cell(0).Write(os, fragile);
os << "}";
}
if (down()) {
os << "_{";
cell(1).Write(os, fragile);
os << "}";
}
}
void MathUpDownInset::Metrics(MathStyles st, int asc, int des)
{
if (up())
xcell(0).Metrics(st);
if (down())
xcell(1).Metrics(st);
// we assume that asc, des, wid are the metrics of the item in front
// of this MathScriptInset
width_ = std::max(xcell(0).width(), xcell(1).width());
ascent_ = up() ? xcell(0).height() + 9 : 0;
descent_ = down() ? xcell(1).height() : 0;
dy0_ = - asc - xcell(0).descent();
dy1_ = des + xcell(1).ascent();
}
void MathUpDownInset::draw(Painter & pain, int x, int y)
{
xo(x);
yo(y);
if (up())
xcell(0).draw(pain, x, y + dy0_);
if (down())
xcell(1).draw(pain, x, y + dy1_);
}

View File

@ -0,0 +1,75 @@
// -*- C++ -*-
#ifndef MATH_UPDOWNINSET_H
#define MATH_UPDOWNINSET_H
#include "math_inset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Abstract base class for super- and subscripts and mathop inset
\author André Pönitz
*/
class MathUpDownInset : public MathInset {
public:
///
MathUpDownInset();
///
MathUpDownInset(bool up, bool down);
///
MathInset * clone() const;
///
void Write(std::ostream &, bool fragile) const;
///
void Metrics(MathStyles st, int asc = 0, int des = 0);
///
void draw(Painter &, int x, int baseline);
///
bool idxUp(int & idx, int & pos) const;
///
bool idxDown(int & idx, int & pos) const;
///
bool idxLeft(int & idx, int & pos) const;
///
bool idxRight(int & idx, int & pos) const;
///
bool idxFirst(int & idx, int & pos) const;
///
bool idxFirstUp(int & idx, int & pos) const;
///
bool idxFirstDown(int & idx, int & pos) const;
///
bool idxLast(int & idx, int & pos) const;
///
bool idxLastUp(int & idx, int & pos) const;
///
bool idxLastDown(int & idx, int & pos) const;
///
bool up() const;
///
bool down() const;
///
void up(bool);
///
void down(bool);
///
bool isActive() const { return false; }
/// Identifies ScriptInsets
bool isUpDownInset() const { return true; }
///
void idxDelete(int & idx, bool & popit, bool & deleteit);
private:
///
bool up_;
///
bool down_;
protected:
///
int dy0_;
///
int dy1_;
};
#endif

View File

@ -14,12 +14,13 @@
using std::max; using std::max;
using std::min; using std::min;
MathXArray::MathXArray() MathXArray::MathXArray()
: width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT) : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), style_(LM_ST_TEXT)
{} {}
void MathXArray::Metrics(MathStyles st) void MathXArray::Metrics(MathStyles st, int, int)
{ {
if (data_.empty()) { if (data_.empty()) {
mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_); mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
@ -31,24 +32,28 @@ void MathXArray::Metrics(MathStyles st)
width_ = 0; width_ = 0;
style_ = st; style_ = st;
// keep last values for scriptInset's need to look back
int asc = 0;
int des = 0;
int wid = 0;
mathed_char_height(LM_TC_VAR, st, 'I', asc, des);
for (int pos = 0; pos < data_.size(); data_.next(pos)) { for (int pos = 0; pos < data_.size(); data_.next(pos)) {
MathInset * p = data_.GetInset(pos); MathInset * p = data_.nextInset(pos);
if (p) { if (p) {
p->Metrics(st); // only MathUpDownInsets will use the asc/des information...
ascent_ = max(ascent_, p->ascent()); p->Metrics(st, asc, des);
descent_ = max(descent_, p->descent()); asc = p->ascent();
width_ += p->width(); des = p->descent();
wid = p->width();
} else { } else {
char cx = data_.GetChar(pos); char cx = data_.GetChar(pos);
MathTextCodes fc = data_.GetCode(pos); MathTextCodes fc = data_.GetCode(pos);
int asc;
int des;
int wid;
mathed_char_dim(fc, style_, cx, asc, des, wid); mathed_char_dim(fc, style_, cx, asc, des, wid);
ascent_ = max(ascent_, asc);
descent_ = max(descent_, des);
width_ += wid;
} }
ascent_ = max(ascent_, asc);
descent_ = max(descent_, des);
width_ += wid;
} }
} }
@ -64,7 +69,7 @@ void MathXArray::draw(Painter & pain, int x, int y)
} }
for (int pos = 0; pos < data_.size(); data_.next(pos)) { for (int pos = 0; pos < data_.size(); data_.next(pos)) {
MathInset * p = data_.GetInset(pos); MathInset * p = data_.nextInset(pos);
if (p) { if (p) {
p->draw(pain, x, y); p->draw(pain, x, y);
x += p->width(); x += p->width();
@ -104,7 +109,7 @@ int MathXArray::width(int pos) const
return 0; return 0;
if (data_.isInset(pos)) if (data_.isInset(pos))
return data_.GetInset(pos)->width(); return data_.nextInset(pos)->width();
else else
return mathed_char_width(data_.GetCode(pos), style_, data_.GetChar(pos)); return mathed_char_width(data_.GetCode(pos), style_, data_.GetChar(pos));
} }

View File

@ -18,7 +18,7 @@ public:
/// ///
MathXArray(); MathXArray();
/// ///
void Metrics(MathStyles st); void Metrics(MathStyles st, int asc = 0, int des = 0);
/// ///
void draw(Painter & pain, int x, int y); void draw(Painter & pain, int x, int y);