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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
#include <functional>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_root.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-07-09 10:19:50 +00:00
|
|
|
: MathInset(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-06-25 00:06:33 +00:00
|
|
|
void MathRootInset::Metrics(MathStyles st)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathInset::Metrics(st);
|
|
|
|
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-06-27 15:33:55 +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[";
|
|
|
|
cell(0).Write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
os << "]{";
|
2001-06-25 00:06:33 +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-06-27 15:33:55 +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-06-25 00:06:33 +00:00
|
|
|
cell(1).WriteNormal(os);
|
2001-04-25 15:43:57 +00:00
|
|
|
os << " ";
|
2001-06-25 00:06:33 +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;
|
|
|
|
}
|