mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
mathed108.diff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2352 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a853f5850b
commit
9ccefe810b
@ -2,6 +2,9 @@
|
||||
|
||||
* 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
|
||||
|
@ -62,8 +62,6 @@ libmathed_la_SOURCES = \
|
||||
math_spaceinset.h \
|
||||
math_sqrtinset.C \
|
||||
math_sqrtinset.h \
|
||||
math_updowninset.C \
|
||||
math_updowninset.h \
|
||||
math_utils.C \
|
||||
math_utils.h \
|
||||
support.C \
|
||||
|
@ -369,3 +369,11 @@ void MathArray::Validate(LaTeXFeatures & features) const
|
||||
nextInset(pos)->Validate(features);
|
||||
}
|
||||
|
||||
|
||||
void MathArray::pop_back()
|
||||
{
|
||||
int pos = size();
|
||||
prev(pos);
|
||||
erase(pos);
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,8 @@ public:
|
||||
///
|
||||
void push_back(MathArray const &);
|
||||
///
|
||||
void pop_back();
|
||||
///
|
||||
MathInset * back_inset() const;
|
||||
|
||||
///
|
||||
|
@ -271,6 +271,14 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
|
||||
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);
|
||||
|
@ -507,7 +507,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
||||
}
|
||||
break;
|
||||
|
||||
// cursor selection ----------------------------
|
||||
|
||||
case LFUN_PASTE:
|
||||
if (was_macro)
|
||||
|
@ -7,7 +7,7 @@
|
||||
using std::ostream;
|
||||
|
||||
MathBigopInset::MathBigopInset(string const & name, int id)
|
||||
: MathUpDownInset(false, false), sym_(id), limits_(0)
|
||||
: sym_(id)
|
||||
{
|
||||
SetName(name);
|
||||
}
|
||||
@ -19,29 +19,10 @@ 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;
|
||||
os << '\\' << name();
|
||||
MathUpDownInset::Write(os, fragile);
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +32,7 @@ void MathBigopInset::WriteNormal(ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
void MathBigopInset::Metrics(MathStyles st, int, int)
|
||||
void MathBigopInset::Metrics(MathStyles st)
|
||||
{
|
||||
//cerr << "\nBigopDraw\n";
|
||||
size(st);
|
||||
@ -65,50 +46,9 @@ void MathBigopInset::Metrics(MathStyles st, int, int)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -117,12 +57,7 @@ void MathBigopInset::draw(Painter & pain, int x, int y)
|
||||
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;
|
||||
@ -130,5 +65,3 @@ void MathBigopInset::draw(Painter & pain, int x, int y)
|
||||
pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
#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);
|
||||
@ -16,31 +16,17 @@ public:
|
||||
///
|
||||
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
|
||||
|
@ -115,8 +115,6 @@ struct Selection
|
||||
data_.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<MathArray> data_;
|
||||
};
|
||||
|
||||
@ -124,20 +122,6 @@ struct Selection
|
||||
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_
|
||||
@ -229,7 +213,7 @@ bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const
|
||||
{
|
||||
if (!p)
|
||||
return false;
|
||||
if (!(p->isActive() || (useupdown && p->isUpDownInset())))
|
||||
if (!(p->isActive() || (useupdown && p->isScriptInset())))
|
||||
return false;
|
||||
|
||||
if (sel) {
|
||||
@ -376,8 +360,7 @@ void MathCursor::SetPos(int x, int y)
|
||||
void MathCursor::Home()
|
||||
{
|
||||
dump("Home 1");
|
||||
if (macro_mode)
|
||||
MacroModeClose();
|
||||
MacroModeClose();
|
||||
clearLastCode();
|
||||
if (!cursor().par_->idxHome(cursor().idx_, cursor().pos_))
|
||||
pop();
|
||||
@ -388,8 +371,7 @@ void MathCursor::Home()
|
||||
void MathCursor::End()
|
||||
{
|
||||
dump("End 1");
|
||||
if (macro_mode)
|
||||
MacroModeClose();
|
||||
MacroModeClose();
|
||||
clearLastCode();
|
||||
if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
|
||||
pop();
|
||||
@ -399,6 +381,12 @@ void MathCursor::End()
|
||||
}
|
||||
|
||||
|
||||
void MathCursor::erase()
|
||||
{
|
||||
array().erase(cursor().pos_);
|
||||
}
|
||||
|
||||
|
||||
void MathCursor::insert(char c, MathTextCodes t)
|
||||
{
|
||||
//lyxerr << "inserting '" << c << "'\n";
|
||||
@ -623,15 +611,22 @@ void MathCursor::SetSize(MathStyles size)
|
||||
|
||||
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();
|
||||
}
|
||||
@ -680,8 +675,8 @@ in_word_set(s) << " \n";
|
||||
} 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);
|
||||
@ -760,27 +755,14 @@ void MathCursor::MacroModeOpen()
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1095,11 +1077,11 @@ MathInset * MathCursor::nextInset() const
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
class MathInset;
|
||||
class MathFuncInset;
|
||||
class MathUpDownInset;
|
||||
class MathScriptInset;
|
||||
class MathSpaceInset;
|
||||
class InsetFormulaBase;
|
||||
class MathArray;
|
||||
@ -76,6 +76,8 @@ public:
|
||||
///
|
||||
void insert(MathArray const &);
|
||||
///
|
||||
void erase();
|
||||
///
|
||||
void Home();
|
||||
///
|
||||
void End();
|
||||
@ -259,7 +261,7 @@ public:
|
||||
///
|
||||
MathInset * prevInset() const;
|
||||
///
|
||||
MathUpDownInset * prevUpDownInset() const;
|
||||
MathScriptInset * prevScriptInset() const;
|
||||
///
|
||||
MathSpaceInset * prevSpaceInset() const;
|
||||
|
||||
|
@ -25,7 +25,7 @@ MathInset * MathDecorationInset::clone() const
|
||||
|
||||
|
||||
|
||||
void MathDecorationInset::Metrics(MathStyles st, int, int)
|
||||
void MathDecorationInset::Metrics(MathStyles st)
|
||||
{
|
||||
xcell(0).Metrics(st);
|
||||
size_ = st;
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
///
|
||||
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:
|
||||
|
@ -86,7 +86,7 @@ int MathDelimInset::dw() const
|
||||
}
|
||||
|
||||
|
||||
void MathDelimInset::Metrics(MathStyles st, int, int)
|
||||
void MathDelimInset::Metrics(MathStyles st)
|
||||
{
|
||||
xcell(0).Metrics(st);
|
||||
size_ = st;
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -31,7 +31,7 @@ void MathDotsInset::draw(Painter & pain, int x, int y)
|
||||
}
|
||||
|
||||
|
||||
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_);
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
///
|
||||
void WriteNormal(std::ostream &) const;
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
protected:
|
||||
///
|
||||
int dh_;
|
||||
|
@ -19,7 +19,7 @@ MathInset * MathFracInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
void MathFracInset::Metrics(MathStyles st, int, int)
|
||||
void MathFracInset::Metrics(MathStyles st)
|
||||
{
|
||||
size_ = smallerStyleFrac(st);
|
||||
xcell(0).Metrics(size_);
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
///
|
||||
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);
|
||||
///
|
||||
|
@ -39,7 +39,7 @@ void MathFuncInset::WriteNormal(std::ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
void MathFuncInset::Metrics(MathStyles st, int, int)
|
||||
void MathFuncInset::Metrics(MathStyles st)
|
||||
{
|
||||
size_ = st;
|
||||
if (name_.empty())
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
///
|
||||
void WriteNormal(std::ostream &) const;
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
private:
|
||||
///
|
||||
bool lims_;
|
||||
|
@ -74,7 +74,7 @@ char MathGridInset::valign() const
|
||||
return v_align_;
|
||||
}
|
||||
|
||||
void MathGridInset::Metrics(MathStyles st, int, int)
|
||||
void MathGridInset::Metrics(MathStyles st)
|
||||
{
|
||||
// let the cells adjust themselves
|
||||
MathInset::Metrics(st);
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
///
|
||||
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);
|
||||
///
|
||||
|
@ -82,7 +82,7 @@ latexkeys const wordlist[] =
|
||||
{"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},
|
||||
|
@ -170,7 +170,7 @@ void MathInset::substitute(MathArray & array, MathMacro const & m) const
|
||||
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)
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
/// 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;
|
||||
///
|
||||
@ -178,10 +178,10 @@ public:
|
||||
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; }
|
||||
///
|
||||
|
@ -49,7 +49,7 @@ MathInset * MathMacro::clone() const
|
||||
}
|
||||
|
||||
|
||||
void MathMacro::Metrics(MathStyles st, int, int)
|
||||
void MathMacro::Metrics(MathStyles st)
|
||||
{
|
||||
if (mathcursor && mathcursor->isInside(this)) {
|
||||
expanded_ = tmplate_->xcell(0);
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
///
|
||||
void draw(Painter &, int, int);
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
|
@ -34,7 +34,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y)
|
||||
}
|
||||
|
||||
|
||||
void MathMacroArgument::Metrics(MathStyles st, int, int)
|
||||
void MathMacroArgument::Metrics(MathStyles st)
|
||||
{
|
||||
char str[] = "#0";
|
||||
str[1] += number_;
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
///
|
||||
void draw(Painter &, int x, int baseline);
|
||||
///
|
||||
|
@ -49,7 +49,7 @@ void MathMacroTemplate::Write(std::ostream & os, bool fragile) const
|
||||
}
|
||||
|
||||
|
||||
void MathMacroTemplate::Metrics(MathStyles st, int, int)
|
||||
void MathMacroTemplate::Metrics(MathStyles st)
|
||||
{
|
||||
xcell(0).Metrics(st);
|
||||
size_ = st;
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
///
|
||||
void draw(Painter &, int, int);
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
private:
|
||||
///
|
||||
int numargs_;
|
||||
|
@ -92,7 +92,7 @@ MathInset * MathMatrixInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
void MathMatrixInset::Metrics(MathStyles /* st */, int, int)
|
||||
void MathMatrixInset::Metrics(MathStyles /* st */)
|
||||
{
|
||||
size_ = (GetType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
///
|
||||
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);
|
||||
///
|
||||
|
@ -339,26 +339,34 @@ int yylex()
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
array.push_back(p);
|
||||
}
|
||||
MathUpDownInset * q = static_cast<MathScriptInset *>(p);
|
||||
if (up)
|
||||
q->up(true);
|
||||
if (down)
|
||||
q->down(down);
|
||||
return p;
|
||||
return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
|
||||
}
|
||||
|
||||
|
||||
MathBigopInset * lastBigopInset(MathArray & array)
|
||||
MathInset * lastScriptInset(MathArray & array, bool up, bool down, int limits)
|
||||
{
|
||||
MathInset * p = array.back_inset();
|
||||
return (p && p->isBigopInset()) ? static_cast<MathBigopInset *>(p) : 0;
|
||||
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);
|
||||
}
|
||||
if (up)
|
||||
p->up(true);
|
||||
if (down)
|
||||
p->down(down);
|
||||
if (limits)
|
||||
p->limits(limits);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
@ -499,11 +507,14 @@ void mathed_parse(MathArray & array, unsigned flags)
|
||||
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";
|
||||
@ -585,48 +596,46 @@ void mathed_parse(MathArray & array, unsigned flags)
|
||||
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) {
|
||||
|
@ -30,7 +30,7 @@ MathInset * MathRootInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
void MathRootInset::Metrics(MathStyles st, int, int)
|
||||
void MathRootInset::Metrics(MathStyles st)
|
||||
{
|
||||
MathInset::Metrics(st);
|
||||
size_ = st;
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
///
|
||||
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;
|
||||
///
|
||||
|
@ -6,19 +6,198 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
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 << "^{";
|
||||
cell(0).Write(os, fragile);
|
||||
os << "}";
|
||||
}
|
||||
if (down()) {
|
||||
os << "_{";
|
||||
cell(1).Write(os, fragile);
|
||||
os << "}";
|
||||
}
|
||||
os << " ";
|
||||
}
|
||||
|
||||
|
||||
void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
|
||||
{
|
||||
if (idx == 0)
|
||||
up(false);
|
||||
else
|
||||
down(false);
|
||||
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);
|
||||
@ -32,12 +211,65 @@ void MathScriptInset::WriteNormal(std::ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
|
||||
void MathScriptInset::Metrics(MathStyles st)
|
||||
{
|
||||
if (idx == 0)
|
||||
up(false);
|
||||
else
|
||||
down(false);
|
||||
popit = true;
|
||||
deleteit = !(up() || down());
|
||||
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_);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#ifndef MATH_SCRIPTINSET_H
|
||||
#define MATH_SCRIPTINSET_H
|
||||
|
||||
#include "math_updowninset.h"
|
||||
#include "math_inset.h"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
@ -12,18 +12,92 @@
|
||||
\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
|
||||
|
@ -43,7 +43,7 @@ void MathSizeInset::draw(Painter & pain, int x, int y)
|
||||
}
|
||||
|
||||
|
||||
void MathSizeInset::Metrics(MathStyles /* st */, int, int)
|
||||
void MathSizeInset::Metrics(MathStyles /* st */)
|
||||
{
|
||||
xcell(0).Metrics(style_);
|
||||
ascent_ = xcell(0).ascent_;
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
///
|
||||
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);
|
||||
///
|
||||
|
@ -51,7 +51,7 @@ void MathSpaceInset::WriteNormal(std::ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
void MathSpaceInset::Metrics(MathStyles st, int, int)
|
||||
void MathSpaceInset::Metrics(MathStyles st)
|
||||
{
|
||||
size_ = st;
|
||||
width_ = space_ ? space_ * 2 : 2;
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
///
|
||||
void WriteNormal(std::ostream &) const;
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
///
|
||||
bool isSpaceInset() const { return true; }
|
||||
///
|
||||
|
@ -19,7 +19,7 @@ MathInset * MathSqrtInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
void MathSqrtInset::Metrics(MathStyles st, int, int)
|
||||
void MathSqrtInset::Metrics(MathStyles st)
|
||||
{
|
||||
xcell(0).Metrics(st);
|
||||
size_ = st;
|
||||
|
@ -24,6 +24,6 @@ public:
|
||||
///
|
||||
void WriteNormal(std::ostream &) const;
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
};
|
||||
#endif
|
||||
|
@ -1,179 +0,0 @@
|
||||
#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_);
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
// -*- 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
|
@ -19,7 +19,7 @@ MathXArray::MathXArray()
|
||||
{}
|
||||
|
||||
|
||||
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_);
|
||||
@ -31,17 +31,13 @@ void MathXArray::Metrics(MathStyles st, int, int)
|
||||
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();
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
///
|
||||
MathXArray();
|
||||
///
|
||||
void Metrics(MathStyles st, int asc = 0, int des = 0);
|
||||
void Metrics(MathStyles st);
|
||||
///
|
||||
void draw(Painter & pain, int x, int y);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user