-#include <config.h>
-
#include "math_bigopinset.h"
-#include "LColor.h"
#include "Painter.h"
#include "mathed/support.h"
#include "support/LOstream.h"
+
using std::ostream;
-MathBigopInset::MathBigopInset(string const & nam, int id, short st)
- : MathedInset(nam, LM_OT_BIGOP, st), lims_(-1), sym_(id)
-{}
+MathBigopInset::MathBigopInset(string const & name, int id)
+ : MathUpDownInset(false, false), sym_(id), limits_(0)
+{
+ SetName(name);
+}
-MathedInset * MathBigopInset::Clone()
+MathInset * MathBigopInset::clone() const
{
- return new MathBigopInset(name, sym_, GetStyle());
+ return new MathBigopInset(*this);
}
-void MathBigopInset::draw(Painter & pain, int x, int y)
+int MathBigopInset::limits() const
{
- string s;
- short t;
-
- if (sym_ < 256 || sym_ == LM_oint) {
- s += (sym_ == LM_oint) ? LM_int : sym_;
- t = LM_TC_BSYM;
- } else {
- s = name;
- t = LM_TC_TEXTRM;
- }
- if (sym_ == LM_oint) {
- pain.arc(x, y - 5 * width / 4, width, width, 0, 360 * 64,
- LColor::mathline);
- ++x;
- }
- pain.text(x, y, s, mathed_get_font(t, size()));
+ return limits_;
+}
+
+
+void MathBigopInset::limits(int limits)
+{
+ limits_ = limits;
}
-void MathBigopInset::Write(ostream & os, bool /* fragile */)
+bool MathBigopInset::hasLimits() const
{
- bool const limp = GetLimits();
-
- os << '\\' << name;
-
- if (limp && !(sym_ != LM_int && sym_ != LM_oint
- && (GetStyle() == LM_ST_DISPLAY)))
- os << "\\limits ";
- else
- if (!limp && (sym_ != LM_int && sym_ != LM_oint
- && (GetStyle() == LM_ST_DISPLAY)))
- os << "\\nolimits ";
- else
- os << ' ';
+ return limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY);
}
-void MathBigopInset::WriteNormal(ostream & os)
+void MathBigopInset::Write(ostream & os, bool fragile) const
{
- bool const limp = GetLimits();
-
- os << "[bigop " << name;
-
- if (limp && !(sym_ != LM_int && sym_ != LM_oint
- && (GetStyle() == LM_ST_DISPLAY)))
- os << " limits";
- else
- if (!limp && (sym_ != LM_int && sym_ != LM_oint
- && (GetStyle() == LM_ST_DISPLAY)))
- os << " nolimits";
-
- os << "] ";
+ //bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY;
+ os << '\\' << name();
+ MathUpDownInset::Write(os, fragile);
+}
+
+
+void MathBigopInset::WriteNormal(ostream & os) const
+{
+ os << "[bigop " << name() << "] ";
}
-void MathBigopInset::Metrics()
+
+void MathBigopInset::Metrics(MathStyles st, int, int)
{
- //char c;
- string s;
- short t;
+ //cerr << "\nBigopDraw\n";
+ size(st);
if (sym_ < 256 || sym_ == LM_oint) {
- char const c = (sym_ == LM_oint) ? LM_int: sym_;
- s += c;
- t = LM_TC_BSYM;
+ ssym_ = string();
+ ssym_ += (sym_ == LM_oint) ? LM_int : sym_;
+ code_ = LM_TC_BSYM;
+ } else {
+ ssym_ = name();
+ code_ = LM_TC_TEXTRM;
+ }
+
+ int wid;
+ mathed_string_dim(code_, size(), ssym_, ascent_, descent_, wid);
+ 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 {
- s = name;
- t = LM_TC_TEXTRM;
+ MathUpDownInset::Metrics(st, ascent_, descent_);
+ width_ += wid;
+ dx0_ = wid;
+ dx1_ = wid;
+ dxx_ = 0;
}
- mathed_string_height(t, size(), s, ascent, descent);
- width = mathed_string_width(t, size(), s);
- if (sym_ == LM_oint) width += 2;
}
-bool MathBigopInset::GetLimits() const
+void MathBigopInset::draw(Painter & pain, int x, int y)
{
- // Default case
- if (lims_ < 0) {
- return sym_ != LM_int &&
- sym_ != LM_oint &&
- GetStyle() == LM_ST_DISPLAY;
- }
-
- // Custom
- return lims_ > 0;
-}
+ xo(x);
+ yo(y);
+ drawStr(pain, code_, size_, x + dxx_, y, ssym_);
-void MathBigopInset::SetLimits(bool ls)
-{
- lims_ = ls ? 1 : 0;
+ if (up())
+ xcell(0).draw(pain, x + dx0_, y + dy0_);
+ if (down())
+ xcell(1).draw(pain, x + dx1_, y + dy1_);
+
+ if (sym_ == LM_oint) {
+ int xx = x - 1;
+ int yy = y - (ascent_ - descent_) / 2;
+ pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline);
+ }
}
+
+