1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* File: math_root.C
|
|
|
|
* Purpose: Implementation of the root object
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1999
|
|
|
|
* Description: Root math object
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1999 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-07-17 07:38:41 +00:00
|
|
|
#include "math_rootinset.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "Painter.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathRootInset::MathRootInset()
|
2001-08-03 17:10:22 +00:00
|
|
|
: MathNestInset(2)
|
2001-02-28 11:56:36 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathRootInset::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return new MathRootInset(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathRootInset::metrics(MathStyles st)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-03 17:10:22 +00:00
|
|
|
MathNestInset::metrics(st);
|
2001-06-25 00:06:33 +00:00
|
|
|
size_ = st;
|
2001-06-27 15:33:55 +00:00
|
|
|
ascent_ = std::max(xcell(0).ascent() + 5, xcell(1).ascent()) + 2;
|
|
|
|
descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
|
2001-06-25 00:06:33 +00:00
|
|
|
width_ = xcell(0).width() + xcell(1).width() + 10;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void MathRootInset::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
xo(x);
|
|
|
|
yo(y);
|
|
|
|
int const w = xcell(0).width();
|
|
|
|
xcell(0).draw(pain, x, y - 5 - xcell(0).descent()); // the "exponent"
|
|
|
|
xcell(1).draw(pain, x + w + 8, y); // the "base"
|
|
|
|
int const a = ascent();
|
|
|
|
int const d = descent();
|
|
|
|
int xp[5];
|
|
|
|
int yp[5];
|
|
|
|
xp[0] = x + width_; yp[0] = y - a + 1;
|
|
|
|
xp[1] = x + w + 4; yp[1] = y - a + 1;
|
|
|
|
xp[2] = x + w; yp[2] = y + d;
|
|
|
|
xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
|
|
|
|
xp[4] = x; yp[4] = y + (d - a)/2 + 2;
|
|
|
|
pain.lines(xp, yp, 5, LColor::mathline);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathRootInset::write(std::ostream & os, bool fragile) const
|
2000-03-07 01:14:37 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
os << "\\sqrt[";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(0).write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
os << "]{";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(1).write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
os << '}';
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-04-27 12:35:55 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathRootInset::writeNormal(std::ostream & os) const
|
2001-04-25 15:43:57 +00:00
|
|
|
{
|
2001-04-27 12:35:55 +00:00
|
|
|
os << "[root ";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(1).writeNormal(os);
|
2001-04-25 15:43:57 +00:00
|
|
|
os << " ";
|
2001-07-26 06:56:43 +00:00
|
|
|
cell(0).writeNormal(os);
|
2001-04-27 12:35:55 +00:00
|
|
|
os << "] ";
|
2001-04-25 15:43:57 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
bool MathRootInset::idxUp(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (idx == 0)
|
|
|
|
return false;
|
|
|
|
idx = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathRootInset::idxDown(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
if (idx == 1)
|
|
|
|
return false;
|
|
|
|
idx = 1;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|