make on-screen appearance of nested delimiters closer to what LaTeX does

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2514 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-15 06:53:25 +00:00
parent f51395af68
commit 9f0fe8a2f6
3 changed files with 53 additions and 38 deletions

View File

@ -14,7 +14,6 @@ using std::ostream;
MathDecorationInset::MathDecorationInset(latexkeys const * key)
: MathNestInset(1), key_(key)
{
upper_ = key_->id != LM_underline && key_->id != LM_underbrace;
}
@ -24,6 +23,21 @@ MathInset * MathDecorationInset::clone() const
}
bool MathDecorationInset::upper() const
{
return key_->id != LM_underline && key_->id != LM_underbrace;
}
bool MathDecorationInset::protect() const
{
return
key_->name == "overbrace" ||
key_->name == "underbrace" ||
key_->name == "overleftarrow" ||
key_->name == "overrightarrow";
}
void MathDecorationInset::metrics(MathStyles st) const
{
@ -35,7 +49,7 @@ void MathDecorationInset::metrics(MathStyles st) const
dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);
if (upper_) {
if (upper()) {
dy_ = -ascent_ - dh_;
ascent_ += dh_ + 1;
} else {
@ -63,11 +77,7 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const
void MathDecorationInset::write(ostream & os, bool fragile) const
{
string name = key_->name;
if (fragile &&
(name == "overbrace" ||
name == "underbrace" ||
name == "overleftarrow" ||
name == "overrightarrow"))
if (fragile && protect())
os << "\\protect";
os << '\\' << name;
@ -82,6 +92,7 @@ void MathDecorationInset::write(ostream & os, bool fragile) const
os << '}';
}
void MathDecorationInset::writeNormal(ostream & os) const
{
os << "[" << key_->name << " ";

View File

@ -28,11 +28,15 @@ public:
void metrics(MathStyles st) const;
///
void writeNormal(std::ostream & os) const;
private:
///
latexkeys const * key_;
bool upper() const;
///
bool upper_;
bool protect() const;
///
latexkeys const * key_;
/// height cache of deco
mutable int dh_;
/// vertical offset cache of deco

View File

@ -50,37 +50,13 @@ void MathDelimInset::write(std::ostream & os, bool fragile) const
}
void MathDelimInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int w = dw();
xcell(0).draw(pain, x + w, y);
if (latexName(left_) == ".") {
pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
LColor::mathcursor, Painter::line_onoffdash);
} else
mathed_draw_deco(pain, x, y - ascent_, w, height(), left_);
x += width() - w - 2;
if (latexName(right_) == ".") {
pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_,
LColor::mathcursor, Painter::line_onoffdash);
} else
mathed_draw_deco(pain, x, y - ascent_, w, height(), right_);
}
int MathDelimInset::dw() const
{
int w = height()/5;
int w = height() / 5;
if (w > 15)
w = 15;
if (w < 6)
w = 6;
if (w < 4)
w = 4;
return w;
}
@ -89,7 +65,31 @@ void MathDelimInset::metrics(MathStyles st) const
{
xcell(0).metrics(st);
size_ = st;
ascent_ = xcell(0).ascent() + 2;
descent_ = xcell(0).descent() + 2;
ascent_ = std::max(xcell(0).ascent(), mathed_char_ascent(LM_TC_VAR, st,'I'));
descent_ = xcell(0).descent();
width_ = xcell(0).width() + 2 * dw() + 4;
}
void MathDelimInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int w = dw();
xcell(0).draw(pain, x + w + 2, y);
if (latexName(left_) == ".") {
pain.line(x + 2, yo() - ascent_, x + 2, yo() + descent_,
LColor::mathcursor, Painter::line_onoffdash);
} else
mathed_draw_deco(pain, x, y - ascent_ - 2, w, height() + 4, left_);
x += width();
if (latexName(right_) == ".") {
pain.line(x + 2, yo() - ascent_, x + 2, yo() + descent_,
LColor::mathcursor, Painter::line_onoffdash);
} else
mathed_draw_deco(pain, x - dw(), y - ascent_ - 2, w, height() + 4, right_);
}