From 9f0fe8a2f6e8f6c313762abb372d8f652c30444c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 15 Aug 2001 06:53:25 +0000 Subject: [PATCH] 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 --- src/mathed/math_decorationinset.C | 25 ++++++++++---- src/mathed/math_decorationinset.h | 8 +++-- src/mathed/math_deliminset.C | 54 +++++++++++++++---------------- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 469a288837..f6c7333525 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -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 << " "; diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index 98cd9058c7..54024c14d8 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -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 diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index f5cbc7b2f4..1f46ecf5b5 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -50,46 +50,46 @@ void MathDelimInset::write(std::ostream & os, bool fragile) const } +int MathDelimInset::dw() const +{ + int w = height() / 5; + if (w > 15) + w = 15; + if (w < 4) + w = 4; + return w; +} + + +void MathDelimInset::metrics(MathStyles st) const +{ + xcell(0).metrics(st); + size_ = st; + 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, y); + xcell(0).draw(pain, x + w + 2, y); if (latexName(left_) == ".") { - pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_, + pain.line(x + 2, yo() - ascent_, x + 2, yo() + descent_, LColor::mathcursor, Painter::line_onoffdash); } else - mathed_draw_deco(pain, x, y - ascent_, w, height(), left_); + mathed_draw_deco(pain, x, y - ascent_ - 2, w, height() + 4, left_); - x += width() - w - 2; + x += width(); if (latexName(right_) == ".") { - pain.line(x + 4, yo() - ascent_, x + 4, yo() + descent_, + pain.line(x + 2, yo() - ascent_, x + 2, 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; - if (w > 15) - w = 15; - if (w < 6) - w = 6; - return w; -} - - -void MathDelimInset::metrics(MathStyles st) const -{ - xcell(0).metrics(st); - size_ = st; - ascent_ = xcell(0).ascent() + 2; - descent_ = xcell(0).descent() + 2; - width_ = xcell(0).width() + 2 * dw() + 4; + mathed_draw_deco(pain, x - dw(), y - ascent_ - 2, w, height() + 4, right_); } -- 2.39.2