* formulabase.C: re-enable 'space enlargement' feature
+ * math_scriptinset.C:
+ math_bigopinset.C: rework of script insets
+
2001-07-22 André Pönitz <poenitz@gmx.net>
* math_cursor.C: fix "pullArg" behaviour
math_spaceinset.h \
math_sqrtinset.C \
math_sqrtinset.h \
- math_updowninset.C \
- math_updowninset.h \
math_utils.C \
math_utils.h \
support.C \
nextInset(pos)->Validate(features);
}
+
+void MathArray::pop_back()
+{
+ int pos = size();
+ prev(pos);
+ erase(pos);
+}
+
///
void push_back(MathArray const &);
///
+ void pop_back();
+ ///
MathInset * back_inset() const;
///
updateLocal(bv, true);
break;
}
+
+ case LFUN_PASTESELECTION:
+ {
+ string const clip = bv->getClipboard();
+ if (!clip.empty())
+ par(mathed_parse(clip));
+ break;
+ }
default:
result = InsetFormulaBase::localDispatch(bv, action, arg);
}
break;
- // cursor selection ----------------------------
case LFUN_PASTE:
if (was_macro)
using std::ostream;
MathBigopInset::MathBigopInset(string const & name, int id)
- : MathUpDownInset(false, false), sym_(id), limits_(0)
+ : sym_(id)
{
SetName(name);
}
}
-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;
os << '\\' << name();
- MathUpDownInset::Write(os, fragile);
}
}
-void MathBigopInset::Metrics(MathStyles st, int, int)
+void MathBigopInset::Metrics(MathStyles st)
{
//cerr << "\nBigopDraw\n";
size(st);
code_ = LM_TC_TEXTRM;
}
- int wid;
- mathed_string_dim(code_, size(), ssym_, ascent_, descent_, wid);
+ mathed_string_dim(code_, size(), ssym_, ascent_, descent_, width_);
if (sym_ == LM_oint)
- wid += 2;
- //cerr << " asc: " << ascent_ << " des: " << descent_
- // << " wid: " << wid << "\n";
- //cerr << " hasLimits: " << hasLimits() << " up: "
- // << up() << " down: " << down() << "\n";
-
- width_ = wid;
-
- if (hasLimits()) {
- xcell(0).Metrics(st);
- xcell(1).Metrics(st);
- //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 {
- MathUpDownInset::Metrics(st, ascent_, descent_);
- width_ += wid;
- dx0_ = wid;
- dx1_ = wid;
- dxx_ = 0;
- }
+ width_ += 2;
}
xo(x);
yo(y);
- drawStr(pain, code_, size_, x + dxx_, y, ssym_);
-
- if (up())
- xcell(0).draw(pain, x + dx0_, y + dy0_);
- if (down())
- xcell(1).draw(pain, x + dx1_, y + dy1_);
+ drawStr(pain, code_, size_, x, y, ssym_);
if (sym_ == LM_oint) {
int xx = x - 1;
pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline);
}
}
-
-
#ifndef MATH_BIGOPINSET_H
#define MATH_BIGOPINSET_H
-#include "math_updowninset.h"
+#include "math_inset.h"
/// big operators
-class MathBigopInset : public MathUpDownInset {
+class MathBigopInset : public MathInset {
public:
///
MathBigopInset(string const &, int);
///
void WriteNormal(std::ostream &) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void draw(Painter &, int, int);
///
- void limits(int);
- ///
- int limits() const;
- /// Identifies BigopInsets
- bool isBigopInset() const { return true; }
+ bool isScriptable() const { return true; }
private:
- ///
- bool hasLimits() const;
///
int sym_;
///
string ssym_;
///
MathTextCodes 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
data_.clear();
}
-
-
std::vector<MathArray> data_;
};
Selection theSelection;
-bool IsMacro(short tok, int id)
-{
- return tok != LM_TK_STACK &&
- tok != LM_TK_FRAC &&
- tok != LM_TK_SQRT &&
- tok != LM_TK_DECORATION &&
- tok != LM_TK_SPACE &&
- tok != LM_TK_DOTS &&
- tok != LM_TK_FUNCLIM &&
- tok != LM_TK_BIGSYM &&
- !(tok == LM_TK_SYM && id < 255);
-}
-
-
std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
{
os << "(par: " << p.par_ << " idx: " << p.idx_
{
if (!p)
return false;
- if (!(p->isActive() || (useupdown && p->isUpDownInset())))
+ if (!(p->isActive() || (useupdown && p->isScriptInset())))
return false;
if (sel) {
void MathCursor::Home()
{
dump("Home 1");
- if (macro_mode)
- MacroModeClose();
+ MacroModeClose();
clearLastCode();
if (!cursor().par_->idxHome(cursor().idx_, cursor().pos_))
pop();
void MathCursor::End()
{
dump("End 1");
- if (macro_mode)
- MacroModeClose();
+ MacroModeClose();
clearLastCode();
if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
pop();
}
+void MathCursor::erase()
+{
+ array().erase(cursor().pos_);
+}
+
+
void MathCursor::insert(char c, MathTextCodes t)
{
//lyxerr << "inserting '" << c << "'\n";
void MathCursor::Interpret(string const & s)
{
- lyxerr << "Interpret: '" << s << "' ('" << s.substr(0, 7) << "' " <<
-in_word_set(s) << " \n";
+ //lyxerr << "Interpret: '" << s << "'\n";
+ //lyxerr << "in: " << in_word_set(s) << " \n";
- if (s[0] == '^' || s[0] == '_') {
+ if (s.size() && (s[0] == '^' || s[0] == '_')) {
bool const up = (s[0] == '^');
SelCut();
- MathUpDownInset * p = prevUpDownInset();
+ MathScriptInset * p = prevScriptInset();
if (!p) {
- p = new MathScriptInset(up, !up);
+ MathInset * b = prevInset();
+ if (b && b->isScriptable()) {
+ p = new MathScriptInset(up, !up, b->clone());
+ plainLeft();
+ erase();
+ } else {
+ p = new MathScriptInset(up, !up);
+ }
insert(p);
plainLeft();
}
} else {
switch (l->token) {
case LM_TK_BIGSYM:
- p = new MathBigopInset(l->name, l->id);
- break;
+ p = new MathBigopInset(s, l->id);
+ break;
case LM_TK_SYM: {
MathTextCodes code = static_cast<MathTextCodes>(l->id);
void MathCursor::MacroModeClose()
{
- if (macro_mode) {
+ if (macro_mode) {
+ string name = imacro->name();
+ plainLeft();
+ erase();
+ delete imacro;
macro_mode = false;
- latexkeys const * l = in_word_set(imacro->name());
- if (!imacro->name().empty()
- && (!l || (l && IsMacro(l->token, l->id)))
- && !MathMacroTable::hasTemplate(imacro->name()))
- {
- if (!l) {
- //imacro->SetName(macrobf);
- // This guarantees that the string will be removed by destructor
- imacro->SetType(LM_OT_UNDEF);
- } else
- imacro->SetName(l->name);
- } else {
- Left();
- array().erase(cursor().pos_);
- if (l || MathMacroTable::hasTemplate(imacro->name()))
- Interpret(imacro->name());
- imacro->SetName(string());
- }
imacro = 0;
+ Interpret(name);
}
}
}
-MathUpDownInset * MathCursor::prevUpDownInset() const
+MathScriptInset * MathCursor::prevScriptInset() const
{
normalize();
MathInset * p = array().prevInset(cursor().pos_);
- return (p && p->isUpDownInset()) ? static_cast<MathUpDownInset *>(p) : 0;
+ return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
}
class MathInset;
class MathFuncInset;
-class MathUpDownInset;
+class MathScriptInset;
class MathSpaceInset;
class InsetFormulaBase;
class MathArray;
///
void insert(MathArray const &);
///
+ void erase();
+ ///
void Home();
///
void End();
///
MathInset * prevInset() const;
///
- MathUpDownInset * prevUpDownInset() const;
+ MathScriptInset * prevScriptInset() const;
///
MathSpaceInset * prevSpaceInset() const;
-void MathDecorationInset::Metrics(MathStyles st, int, int)
+void MathDecorationInset::Metrics(MathStyles st)
{
xcell(0).Metrics(st);
size_ = st;
///
void Write(std::ostream &, bool fragile) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void WriteNormal(std::ostream & os) const;
private:
}
-void MathDelimInset::Metrics(MathStyles st, int, int)
+void MathDelimInset::Metrics(MathStyles st)
{
xcell(0).Metrics(st);
size_ = st;
///
void Write(std::ostream &, bool fragile) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
private:
int dw() const;
///
}
-void MathDotsInset::Metrics(MathStyles st, int, int)
+void MathDotsInset::Metrics(MathStyles st)
{
size(st);
mathed_char_dim(LM_TC_VAR, size(), 'M', ascent_, descent_, width_);
///
void WriteNormal(std::ostream &) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
protected:
///
int dh_;
}
-void MathFracInset::Metrics(MathStyles st, int, int)
+void MathFracInset::Metrics(MathStyles st)
{
size_ = smallerStyleFrac(st);
xcell(0).Metrics(size_);
///
virtual void WriteNormal(std::ostream &) const;
///
- virtual void Metrics(MathStyles st, int asc = 0, int des = 0);
+ virtual void Metrics(MathStyles st);
///
virtual void draw(Painter &, int x, int baseline);
///
}
-void MathFuncInset::Metrics(MathStyles st, int, int)
+void MathFuncInset::Metrics(MathStyles st)
{
size_ = st;
if (name_.empty())
///
void WriteNormal(std::ostream &) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
private:
///
bool lims_;
return v_align_;
}
-void MathGridInset::Metrics(MathStyles st, int, int)
+void MathGridInset::Metrics(MathStyles st)
{
// let the cells adjust themselves
MathInset::Metrics(st);
///
void Write(std::ostream &, bool fragile) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void draw(Painter &, int, int);
///
{"widehat", LM_TK_DECORATION, LM_widehat},
{"sin", LM_TK_FUNC, 0},
{"asymp", LM_TK_SYM, LM_asymp},
- {"nolimits", LM_TK_LIMIT, 0 },
+ {"nolimits", LM_TK_LIMIT, -1},
{"perp", LM_TK_MACRO, LM_perp},
{"wedge", LM_TK_SYM, LM_wedge},
{"ln", LM_TK_FUNC, 0},
array.push_back(p);
}
-void MathInset::Metrics(MathStyles st, int, int)
+void MathInset::Metrics(MathStyles st)
{
size_ = st;
for (int i = 0; i < nargs(); ++i)
/// Appends itself with macro arguments substituted
virtual void substitute(MathArray & array, MathMacro const & macro) const;
/// Compute the size of the object
- virtual void Metrics(MathStyles st, int = 0, int = 0) = 0;
+ virtual void Metrics(MathStyles st) = 0;
///
virtual int ascent() const;
///
void GetXY(int & x, int & y) const;
///
bool covers(int x, int y) const;
+ /// Identifies things that can get scripts
+ virtual bool isScriptable() const { return false; }
/// Identifies ScriptInsets
- virtual bool isUpDownInset() const { return false; }
- /// Identifies BigopInsets
- virtual bool isBigopInset() const { return false; }
+ virtual bool isScriptInset() const { return false; }
/// Identifies SpaceInsets
virtual bool isSpaceInset() const { return false; }
///
}
-void MathMacro::Metrics(MathStyles st, int, int)
+void MathMacro::Metrics(MathStyles st)
{
if (mathcursor && mathcursor->isInside(this)) {
expanded_ = tmplate_->xcell(0);
///
void draw(Painter &, int, int);
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
MathInset * clone() const;
///
}
-void MathMacroArgument::Metrics(MathStyles st, int, int)
+void MathMacroArgument::Metrics(MathStyles st)
{
char str[] = "#0";
str[1] += number_;
///
MathInset * clone() const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void draw(Painter &, int x, int baseline);
///
}
-void MathMacroTemplate::Metrics(MathStyles st, int, int)
+void MathMacroTemplate::Metrics(MathStyles st)
{
xcell(0).Metrics(st);
size_ = st;
///
void draw(Painter &, int, int);
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
private:
///
int numargs_;
}
-void MathMatrixInset::Metrics(MathStyles /* st */, int, int)
+void MathMatrixInset::Metrics(MathStyles /* st */)
{
size_ = (GetType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
///
void Write(std::ostream &, bool fragile) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void draw(Painter &, int, int);
///
}
-MathInset * lastUpDownInset(MathArray & array, bool up, bool down)
+
+MathScriptInset * prevScriptInset(MathArray const & array)
{
MathInset * p = array.back_inset();
- if (!p || !p->isUpDownInset()) {
- p = new MathScriptInset(up, down);
+ return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
+}
+
+
+MathInset * lastScriptInset(MathArray & array, bool up, bool down, int limits)
+{
+ MathScriptInset * p = prevScriptInset(array);
+ if (!p) {
+ MathInset * b = array.back_inset();
+ if (b && b->isScriptable()) {
+ p = new MathScriptInset(up, down, b->clone());
+ array.pop_back();
+ } else {
+ p = new MathScriptInset(up, down);
+ }
array.push_back(p);
}
- MathUpDownInset * q = static_cast<MathScriptInset *>(p);
if (up)
- q->up(true);
+ p->up(true);
if (down)
- q->down(down);
+ p->down(down);
+ if (limits)
+ p->limits(limits);
return p;
}
-MathBigopInset * lastBigopInset(MathArray & array)
-{
- MathInset * p = array.back_inset();
- return (p && p->isBigopInset()) ? static_cast<MathBigopInset *>(p) : 0;
-}
-
-
static bool curr_num;
static string curr_label;
static int plevel = -1;
yyvarcode = LM_TC_VAR;
- int brace = 0;
+ int brace = 0;
+ int limits = 0;
++plevel;
while (t) {
- //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i << " "
+ //lyxerr << "t: " << t << " flags: " << flags << " i: " << yylval.i
+ // << " TK_LIMIT " << LM_TK_LIMIT << "\n";
+
// << " plevel: " << plevel << " ";
//array.dump(lyxerr);
//lyxerr << "\n";
break;
case '^':
- mathed_parse(lastUpDownInset(array, true, false)->cell(0), FLAG_ITEM);
+ mathed_parse(
+ lastScriptInset(array, true, false, limits)->cell(0), FLAG_ITEM);
break;
case '_':
- mathed_parse(lastUpDownInset(array, false, true)->cell(1), FLAG_ITEM);
+ mathed_parse(
+ lastScriptInset(array, false, true, limits)->cell(1), FLAG_ITEM);
break;
case LM_TK_LIMIT:
- {
- MathBigopInset * p = lastBigopInset(array);
- if (p)
- p->limits(yylval.l->id ? 1 : -1);
+ limits = yylval.l->id;
+ //lyxerr << "setting limit to " << limits << "\n";
break;
- }
case '&':
- {
if (flags & FLAG_AMPERSAND) {
flags &= ~FLAG_AMPERSAND;
--plevel;
return;
}
- lyxerr[Debug::MATHED] << "found tab unexpectedly, array: '" << array << "'\n";
+ lyxerr[Debug::MATHED]
+ << "found tab unexpectedly, array: '" << array << "'\n";
break;
- }
case LM_TK_NEWLINE:
- {
if (flags & FLAG_NEWLINE) {
flags &= ~FLAG_NEWLINE;
--plevel;
return;
}
- lyxerr[Debug::MATHED] << "found newline unexpectedly, array: '" << array << "'\n";
+ lyxerr[Debug::MATHED]
+ << "found newline unexpectedly, array: '" << array << "'\n";
break;
- }
case LM_TK_BIGSYM:
- {
+ //lyxerr << "clearing limits " << limits << "\n";
+ limits = 0;
+ //lyxerr << "found bigop '" << yylval.l->name << "'\n";
array.push_back(new MathBigopInset(yylval.l->name, yylval.l->id));
break;
- }
case LM_TK_SYM:
if (yylval.l->id < 256) {
}
-void MathRootInset::Metrics(MathStyles st, int, int)
+void MathRootInset::Metrics(MathStyles st)
{
MathInset::Metrics(st);
size_ = st;
///
void WriteNormal(std::ostream &) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
bool idxUp(int & idx, int & pos) const;
///
#include "support/LOstream.h"
-MathScriptInset::MathScriptInset(bool up, bool down)
- : MathUpDownInset(up, down)
+MathScriptInset::MathScriptInset()
+ : MathInset(2), up_(false), down_(false), limits_(0), symbol_(0)
{}
+MathScriptInset::MathScriptInset(bool up, bool down, MathInset * symbol)
+ : MathInset(2), up_(up), down_(down), limits_(0), symbol_(symbol)
+{}
+
+
+MathScriptInset::MathScriptInset(MathScriptInset const & p)
+ : MathInset(p), up_(p.up_), down_(p.down_),
+ limits_(p.limits_), symbol_(p.symbol_ ? p.symbol_->clone() : 0)
+{}
+
+
+MathScriptInset::~MathScriptInset()
+{
+ delete symbol_;
+}
+
+
MathInset * MathScriptInset::clone() const
{
return new MathScriptInset(*this);
}
-void MathScriptInset::WriteNormal(std::ostream & os) const
+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;
+}
+
+
+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::Write(std::ostream & os, bool fragile) const
+{
+ if (symbol_) {
+ symbol_->Write(os, fragile);
+ if (limits())
+ os << (limits() == 1 ? "\\limits" : "\\nolimits");
+ }
if (up()) {
- os << "[superscript ";
- cell(0).WriteNormal(os);
- os << "] ";
+ os << "^{";
+ cell(0).Write(os, fragile);
+ os << "}";
}
if (down()) {
- os << "[subscript ";
- cell(1).WriteNormal(os);
- os << "] ";
+ os << "_{";
+ cell(1).Write(os, fragile);
+ os << "}";
}
+ os << " ";
}
popit = true;
deleteit = !(up() || down());
}
+
+
+int MathScriptInset::limits() const
+{
+ return limits_;
+}
+
+
+void MathScriptInset::limits(int limits)
+{
+ limits_ = limits;
+}
+
+
+bool MathScriptInset::hasLimits() const
+{
+ return
+ symbol_ && (limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY));
+}
+
+
+void MathScriptInset::WriteNormal(std::ostream & os) const
+{
+ if (limits() && symbol_)
+ os << "[" << (limits() ? "limits" : "nolimits") << "]";
+ if (up()) {
+ os << "[superscript ";
+ cell(0).WriteNormal(os);
+ os << "] ";
+ }
+ if (down()) {
+ os << "[subscript ";
+ cell(1).WriteNormal(os);
+ os << "] ";
+ }
+}
+
+
+void MathScriptInset::Metrics(MathStyles st)
+{
+ size_ = st;
+ MathStyles tt = smallerStyleScript(st);
+
+ xcell(0).Metrics(tt);
+ xcell(1).Metrics(tt);
+
+ width_ = std::max(xcell(0).width(), xcell(1).width());
+
+ if (hasLimits()) {
+ symbol_->Metrics(st);
+ int wid = symbol_->width();
+ ascent_ = symbol_->ascent();
+ descent_ = symbol_->descent();
+ width_ = std::max(width_, wid);
+ if (up()) {
+ ascent_ += xcell(0).height() + 2;
+ dy0_ = - (ascent_ - xcell(0).ascent());
+ }
+ if (down()) {
+ descent_ += xcell(1).height() + 2;
+ dy1_ = descent_ - xcell(1).descent();
+ }
+ dxx_ = (width_ - wid) / 2;
+ dx0_ = (width_ - xcell(0).width()) / 2;
+ dx1_ = (width_ - xcell(1).width()) / 2;
+ } else {
+ int asc;
+ int des;
+ int wid = 0;
+ mathed_char_height(LM_TC_VAR, st, 'I', asc, des);
+ if (symbol_) {
+ symbol_->Metrics(st);
+ wid = symbol_->width();
+ asc = symbol_->ascent();
+ des = symbol_->descent();
+ }
+ ascent_ = up() ? xcell(0).height() + asc : 0;
+ descent_ = down() ? xcell(1).height() + des : 0;
+ width_ += wid;
+ dy0_ = - asc - xcell(0).descent();
+ dy1_ = des + xcell(1).ascent();
+ dx0_ = wid;
+ dx1_ = wid;
+ dxx_ = 0;
+ }
+}
+
+
+void MathScriptInset::draw(Painter & pain, int x, int y)
+{
+ xo(x);
+ yo(y);
+
+ if (symbol_)
+ symbol_->draw(pain, x + dxx_, y);
+ if (up())
+ xcell(0).draw(pain, x + dx0_, y + dy0_);
+ if (down())
+ xcell(1).draw(pain, x + dx1_, y + dy1_);
+}
#ifndef MATH_SCRIPTINSET_H
#define MATH_SCRIPTINSET_H
-#include "math_updowninset.h"
+#include "math_inset.h"
#ifdef __GNUG__
#pragma interface
\author André Pönitz
*/
-class MathScriptInset : public MathUpDownInset {
+
+class MathScriptInset : public MathInset {
public:
///
- MathScriptInset(bool up, bool down);
+ MathScriptInset();
+ ///
+ MathScriptInset(bool up, bool down, MathInset * = 0);
+ ///
+ MathScriptInset(MathScriptInset const &);
+ ///
+ ~MathScriptInset();
///
MathInset * clone() const;
///
+ void Write(std::ostream &, bool fragile) const;
+ ///
void WriteNormal(std::ostream &) const;
- /// Identifies ScriptInsets
- bool isUpDownInset() const { return true; }
+ ///
+ 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;
///
void idxDelete(int & idx, bool & popit, bool & deleteit);
+
+ ///
+ bool up() const;
+ ///
+ bool down() const;
+ ///
+ void up(bool);
+ ///
+ void down(bool);
+ ///
+ void limits(int);
+ ///
+ int limits() const;
+ ///
+ bool isActive() const { return false; }
+ /// Identifies ScriptInsets
+ bool isScriptInset() const { return true; }
+ ///
+ int xoffset() const { return dxx_; }
+private:
+ ///
+ bool hasLimits() const;
+ ///
+ bool up_;
+ ///
+ bool down_;
+ ///
+ string ssym_;
+ /// 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_;
+ ///
+ int dy0_;
+ ///
+ int dy1_;
+ ///
+ MathInset * symbol_;
};
#endif
}
-void MathSizeInset::Metrics(MathStyles /* st */, int, int)
+void MathSizeInset::Metrics(MathStyles /* st */)
{
xcell(0).Metrics(style_);
ascent_ = xcell(0).ascent_;
///
virtual MathInset * clone() const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void draw(Painter &, int x, int baseline);
///
}
-void MathSpaceInset::Metrics(MathStyles st, int, int)
+void MathSpaceInset::Metrics(MathStyles st)
{
size_ = st;
width_ = space_ ? space_ * 2 : 2;
///
void WriteNormal(std::ostream &) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
bool isSpaceInset() const { return true; }
///
}
-void MathSqrtInset::Metrics(MathStyles st, int, int)
+void MathSqrtInset::Metrics(MathStyles st)
{
xcell(0).Metrics(st);
size_ = st;
///
void WriteNormal(std::ostream &) const;
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
};
#endif
+++ /dev/null
-#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)
-{
- size_ = st;
- MathStyles tt = smallerStyleScript(st);
-
- if (up())
- xcell(0).Metrics(tt);
- if (down())
- xcell(1).Metrics(tt);
-
- // 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() + asc : 0;
- descent_ = down() ? xcell(1).height() + des : 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_);
-}
-
+++ /dev/null
-// -*- 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
{}
-void MathXArray::Metrics(MathStyles st, int, int)
+void MathXArray::Metrics(MathStyles st)
{
if (data_.empty()) {
mathed_char_dim(LM_TC_VAR, st, 'I', ascent_, descent_, width_);
width_ = 0;
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)) {
+ int asc;
+ int des;
+ int wid;
MathInset * p = data_.nextInset(pos);
if (p) {
- // only MathUpDownInsets will use the asc/des information...
- p->Metrics(st, asc, des);
+ p->Metrics(st);
asc = p->ascent();
des = p->descent();
wid = p->width();
///
MathXArray();
///
- void Metrics(MathStyles st, int asc = 0, int des = 0);
+ void Metrics(MathStyles st);
///
void draw(Painter & pain, int x, int y);