2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-10-25 21:53:06 +00:00
|
|
|
|
* \file InsetMathFracBase.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathFrac.h"
|
2007-10-25 21:53:06 +00:00
|
|
|
|
|
|
|
|
|
#include "Cursor.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2007-10-25 21:53:06 +00:00
|
|
|
|
#include "MathSupport.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "TextPainter.h"
|
2007-10-25 21:53:06 +00:00
|
|
|
|
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-10-25 21:53:06 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathFracBase
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMathFracBase::InsetMathFracBase(idx_type ncells)
|
|
|
|
|
: InsetMathNest(ncells)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathFracBase::idxUpDown(Cursor & cur, bool up) const
|
|
|
|
|
{
|
|
|
|
|
InsetMath::idx_type target = !up; // up ? 0 : 1, since upper cell has idx 0
|
|
|
|
|
if (cur.idx() == target)
|
|
|
|
|
return false;
|
|
|
|
|
cur.idx() = target;
|
|
|
|
|
cur.pos() = cell(target).x2pos(cur.x_target());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathFrac
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2007-09-15 16:39:51 +00:00
|
|
|
|
InsetMathFrac::InsetMathFrac(Kind kind, InsetMath::idx_type ncells)
|
|
|
|
|
: InsetMathFracBase(ncells), kind_(kind)
|
2001-07-09 10:19:50 +00:00
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathFrac::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetMathFrac(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathFrac * InsetMathFrac::asFracInset()
|
2001-11-13 18:33:48 +00:00
|
|
|
|
{
|
2006-04-06 09:46:01 +00:00
|
|
|
|
return kind_ == ATOP ? 0 : this;
|
2001-11-13 18:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathFrac const * InsetMathFrac::asFracInset() const
|
2002-08-08 16:08:11 +00:00
|
|
|
|
{
|
2006-04-06 09:46:01 +00:00
|
|
|
|
return kind_ == ATOP ? 0 : this;
|
2002-08-08 16:08:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
|
bool InsetMathFrac::idxForward(Cursor & cur) const
|
2007-09-15 16:39:51 +00:00
|
|
|
|
{
|
2007-09-30 17:56:49 +00:00
|
|
|
|
InsetMath::idx_type target = 0;
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
|
|
|
|
|
if (nargs() == 3)
|
|
|
|
|
target = 0;
|
|
|
|
|
else if (nargs() == 2)
|
|
|
|
|
target = 1;
|
|
|
|
|
} else
|
2007-09-30 17:56:49 +00:00
|
|
|
|
return false;
|
2007-09-15 16:39:51 +00:00
|
|
|
|
if (cur.idx() == target)
|
|
|
|
|
return false;
|
|
|
|
|
cur.idx() = target;
|
|
|
|
|
cur.pos() = cell(target).x2pos(cur.x_target());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
|
bool InsetMathFrac::idxBackward(Cursor & cur) const
|
2007-09-15 16:39:51 +00:00
|
|
|
|
{
|
2007-09-30 17:56:49 +00:00
|
|
|
|
InsetMath::idx_type target = 0;
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
|
|
|
|
|
if (nargs() == 3)
|
|
|
|
|
target = 2;
|
|
|
|
|
else if (nargs() == 2)
|
|
|
|
|
target = 0;
|
|
|
|
|
} else
|
2007-09-30 17:56:49 +00:00
|
|
|
|
return false;
|
2007-09-15 16:39:51 +00:00
|
|
|
|
if (cur.idx() == target)
|
|
|
|
|
return false;
|
|
|
|
|
cur.idx() = target;
|
|
|
|
|
cur.pos() = cell(target).x2pos(cur.x_target());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension dim0, dim1, dim2;
|
|
|
|
|
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
|
|
|
|
|
if (nargs() == 1) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(mi.base.font, UP_SHAPE);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
dim.wid = dim0.width()+ 3;
|
|
|
|
|
dim.asc = dim0.asc;
|
|
|
|
|
dim.des = dim0.des;
|
2007-09-18 15:04:58 +00:00
|
|
|
|
} else if (nargs() == 2) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(0).metrics(mi, dim0);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(mi.base.font, UP_SHAPE);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.wid = dim0.width() + dim1.wid + 5;
|
|
|
|
|
dim.asc = std::max(dim0.asc, dim1.asc);
|
|
|
|
|
dim.des = std::max(dim0.des, dim1.des);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
} else {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(2).metrics(mi, dim2);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(mi.base.font, UP_SHAPE);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
FracChanger dummy(mi.base);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.wid = dim0.width() + dim1.wid + dim2.wid + 10;
|
|
|
|
|
dim.asc = std::max(dim2.asc, dim0.height() + 5);
|
|
|
|
|
dim.des = std::max(dim2.des, dim1.height() - 5);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
}
|
2006-04-06 09:46:01 +00:00
|
|
|
|
} else {
|
2007-09-15 16:39:51 +00:00
|
|
|
|
FracChanger dummy(mi.base);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
2007-10-01 10:23:56 +00:00
|
|
|
|
if (nargs() == 3)
|
|
|
|
|
cell(2).metrics(mi, dim2);
|
|
|
|
|
|
2007-09-15 16:39:51 +00:00
|
|
|
|
if (kind_ == NICEFRAC) {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = dim0.width() + dim1.wid + 5;
|
|
|
|
|
dim.asc = dim0.height() + 5;
|
|
|
|
|
dim.des = dim1.height() - 5;
|
2007-09-15 16:39:51 +00:00
|
|
|
|
} else if (kind_ == UNITFRAC) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(mi.base.font, UP_SHAPE);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = dim0.width() + dim1.wid + 5;
|
|
|
|
|
dim.asc = dim0.height() + 5;
|
|
|
|
|
dim.des = dim1.height() - 5;
|
2007-09-15 16:39:51 +00:00
|
|
|
|
} else {
|
2007-09-24 13:52:04 +00:00
|
|
|
|
dim.wid = std::max(dim0.width(), dim1.wid) + 2;
|
|
|
|
|
dim.asc = dim0.height() + 2 + 5;
|
|
|
|
|
dim.des = dim1.height() + 2 - 5;
|
2007-09-15 16:39:51 +00:00
|
|
|
|
}
|
2006-04-06 09:46:01 +00:00
|
|
|
|
}
|
2004-04-07 16:54:15 +00:00
|
|
|
|
metricsMarkers(dim);
|
2007-09-23 22:39:49 +00:00
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension const dim0 = cell(0).dimension(*pi.base.bv);
|
2007-09-23 22:39:49 +00:00
|
|
|
|
int m = x + dim.wid / 2;
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
|
|
|
|
|
if (nargs() == 1) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(pi.base.font, UP_SHAPE);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
cell(0).draw(pi, x + 1, y);
|
|
|
|
|
} else if (nargs() == 2) {
|
|
|
|
|
cell(0).draw(pi, x + 1, y);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(pi.base.font, UP_SHAPE);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(1).draw(pi, x + dim0.width() + 5, y);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
} else {
|
|
|
|
|
cell(2).draw(pi, x + 1, y);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(pi.base.font, UP_SHAPE);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
FracChanger dummy(pi.base);
|
2007-10-01 09:54:41 +00:00
|
|
|
|
Dimension const dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
|
Dimension const dim2 = cell(2).dimension(*pi.base.bv);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int xx = x + dim2.wid + 5;
|
2007-09-18 15:04:58 +00:00
|
|
|
|
cell(0).draw(pi, xx + 2,
|
2007-09-24 13:52:04 +00:00
|
|
|
|
y - dim0.des - 5);
|
|
|
|
|
cell(1).draw(pi, xx + dim0.width() + 5,
|
|
|
|
|
y + dim1.asc / 2);
|
2007-09-18 15:04:58 +00:00
|
|
|
|
}
|
2006-04-06 09:46:01 +00:00
|
|
|
|
} else {
|
2007-09-15 16:39:51 +00:00
|
|
|
|
FracChanger dummy(pi.base);
|
2007-10-01 09:54:41 +00:00
|
|
|
|
Dimension const dim1 = cell(1).dimension(*pi.base.bv);
|
2007-09-15 16:39:51 +00:00
|
|
|
|
if (kind_ == NICEFRAC) {
|
|
|
|
|
cell(0).draw(pi, x + 2,
|
2007-09-24 13:52:04 +00:00
|
|
|
|
y - dim0.des - 5);
|
|
|
|
|
cell(1).draw(pi, x + dim0.width() + 5,
|
|
|
|
|
y + dim1.asc / 2);
|
2007-09-15 16:39:51 +00:00
|
|
|
|
} else if (kind_ == UNITFRAC) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
ShapeChanger dummy2(pi.base.font, UP_SHAPE);
|
2007-09-15 16:39:51 +00:00
|
|
|
|
cell(0).draw(pi, x + 2,
|
2007-09-24 13:52:04 +00:00
|
|
|
|
y - dim0.des - 5);
|
|
|
|
|
cell(1).draw(pi, x + dim0.width() + 5,
|
|
|
|
|
y + dim1.asc / 2);
|
2007-09-15 16:39:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Classical fraction
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(0).draw(pi, m - dim0.width() / 2,
|
|
|
|
|
y - dim0.des - 2 - 5);
|
|
|
|
|
cell(1).draw(pi, m - dim1.wid / 2,
|
|
|
|
|
y + dim1.asc + 2 - 5);
|
2007-09-15 16:39:51 +00:00
|
|
|
|
}
|
2006-04-06 09:46:01 +00:00
|
|
|
|
}
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (kind_ == NICEFRAC || kind_ == UNITFRAC) {
|
2007-09-15 16:39:51 +00:00
|
|
|
|
// Diag line:
|
|
|
|
|
int xx = x;
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (nargs() == 3)
|
2007-10-01 10:23:56 +00:00
|
|
|
|
xx += cell(2).dimension(*pi.base.bv).wid + 5;
|
|
|
|
|
|
2007-09-24 13:52:04 +00:00
|
|
|
|
pi.pain.line(xx + dim0.wid,
|
2007-09-23 22:39:49 +00:00
|
|
|
|
y + dim.des - 2,
|
2007-09-24 13:52:04 +00:00
|
|
|
|
xx + dim0.wid + 5,
|
2007-10-25 12:41:02 +00:00
|
|
|
|
y - dim.asc + 2, Color_math);
|
2007-09-12 08:15:33 +00:00
|
|
|
|
}
|
2006-07-19 10:50:18 +00:00
|
|
|
|
if (kind_ == FRAC || kind_ == OVER)
|
2007-05-28 22:27:45 +00:00
|
|
|
|
pi.pain.line(x + 1, y - 5,
|
2007-10-25 12:41:02 +00:00
|
|
|
|
x + dim.wid - 2, y - 5, Color_math);
|
2004-04-07 16:54:15 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-19 16:55:58 +00:00
|
|
|
|
{
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Dimension dim0, dim1;
|
|
|
|
|
cell(0).metricsT(mi, dim0);
|
|
|
|
|
cell(1).metricsT(mi, dim1);
|
|
|
|
|
dim.wid = std::max(dim0.width(), dim1.wid);
|
|
|
|
|
dim.asc = dim0.height() + 1;
|
|
|
|
|
dim.des = dim1.height();
|
2002-03-19 16:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
|
2002-03-19 16:55:58 +00:00
|
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
|
// FIXME: BROKEN!
|
2007-09-24 13:52:04 +00:00
|
|
|
|
/*
|
2007-09-23 22:39:49 +00:00
|
|
|
|
Dimension dim;
|
|
|
|
|
int m = x + dim.width() / 2;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
cell(0).drawT(pain, m - dim0.width() / 2, y - dim0.des - 1);
|
|
|
|
|
cell(1).drawT(pain, m - dim1.wid / 2, y + dim1.asc);
|
2006-04-06 09:46:01 +00:00
|
|
|
|
// ASCII art: ignore niceties
|
2007-09-12 08:15:33 +00:00
|
|
|
|
if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC || kind_ == UNITFRAC)
|
2007-09-23 22:39:49 +00:00
|
|
|
|
pain.horizontalLine(x, y, dim.width());
|
2007-09-24 13:52:04 +00:00
|
|
|
|
*/
|
2002-03-19 16:55:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::write(WriteStream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2006-07-19 10:50:18 +00:00
|
|
|
|
switch (kind_) {
|
|
|
|
|
case ATOP:
|
2001-10-19 11:25:48 +00:00
|
|
|
|
os << '{' << cell(0) << "\\atop " << cell(1) << '}';
|
2006-07-19 10:50:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case OVER:
|
|
|
|
|
// \\over is only for compatibility, normalize this to \\frac
|
|
|
|
|
os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
|
|
|
|
|
break;
|
|
|
|
|
case FRAC:
|
|
|
|
|
case NICEFRAC:
|
2007-09-12 08:15:33 +00:00
|
|
|
|
case UNITFRAC:
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (nargs() == 2)
|
|
|
|
|
InsetMathNest::write(os);
|
|
|
|
|
else
|
|
|
|
|
os << "\\unitfrac[" << cell(2) << "]{" << cell(0) << "}{" << cell(1) << '}';
|
2006-07-19 10:50:18 +00:00
|
|
|
|
break;
|
2007-09-15 16:39:51 +00:00
|
|
|
|
case UNIT:
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (nargs() == 2)
|
|
|
|
|
os << "\\unit[" << cell(0) << "]{" << cell(1) << '}';
|
|
|
|
|
else
|
|
|
|
|
os << "\\unit{" << cell(0) << '}';
|
2007-09-15 16:39:51 +00:00
|
|
|
|
break;
|
2006-07-19 10:50:18 +00:00
|
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring InsetMathFrac::name() const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2006-04-06 09:46:01 +00:00
|
|
|
|
switch (kind_) {
|
|
|
|
|
case FRAC:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return from_ascii("frac");
|
2006-07-19 10:50:18 +00:00
|
|
|
|
case OVER:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return from_ascii("over");
|
2006-04-06 09:46:01 +00:00
|
|
|
|
case NICEFRAC:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return from_ascii("nicefrac");
|
2007-09-12 08:15:33 +00:00
|
|
|
|
case UNITFRAC:
|
|
|
|
|
return from_ascii("unitfrac");
|
2007-09-15 16:39:51 +00:00
|
|
|
|
case UNIT:
|
|
|
|
|
return from_ascii("unit");
|
2006-04-06 09:46:01 +00:00
|
|
|
|
case ATOP:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return from_ascii("atop");
|
2006-04-06 09:46:01 +00:00
|
|
|
|
}
|
2006-07-31 17:44:50 +00:00
|
|
|
|
// shut up stupid compiler
|
2006-10-22 10:15:23 +00:00
|
|
|
|
return docstring();
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathFrac::extraBraces() const
|
2006-07-16 17:19:05 +00:00
|
|
|
|
{
|
2006-07-19 10:50:18 +00:00
|
|
|
|
return kind_ == ATOP || kind_ == OVER;
|
2006-07-16 17:19:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2001-11-13 16:27:06 +00:00
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
2001-11-07 17:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::octave(OctaveStream & os) const
|
2002-04-25 15:37:10 +00:00
|
|
|
|
{
|
|
|
|
|
os << '(' << cell(0) << ")/(" << cell(1) << ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathFrac::mathmlize(MathStream & os) const
|
2001-11-07 17:30:26 +00:00
|
|
|
|
{
|
2001-11-08 12:06:56 +00:00
|
|
|
|
os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2006-04-06 09:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathFrac::validate(LaTeXFeatures & features) const
|
2006-04-06 09:46:01 +00:00
|
|
|
|
{
|
2007-09-18 15:04:58 +00:00
|
|
|
|
if (kind_ == NICEFRAC || kind_ == UNITFRAC || kind_ == UNIT)
|
2007-09-12 08:15:33 +00:00
|
|
|
|
features.require("units");
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::validate(features);
|
2006-04-06 09:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-10-25 21:53:06 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathDFrac
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetMathDFrac::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new InsetMathDFrac(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathDFrac::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
Dimension dim0, dim1;
|
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.wid = std::max(dim0.wid, dim1.wid) + 2;
|
|
|
|
|
dim.asc = dim0.height() + 2 + 5;
|
|
|
|
|
dim.des = dim1.height() + 2 - 5;
|
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathDFrac::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
|
int m = x + dim.wid / 2;
|
|
|
|
|
cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
|
|
|
|
|
cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
|
|
|
|
|
pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color_math);
|
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetMathDFrac::name() const
|
|
|
|
|
{
|
|
|
|
|
return from_ascii("dfrac");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathDFrac::mathmlize(MathStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << MTag("mdfrac") << cell(0) << cell(1) << ETag("mdfrac");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathDFrac::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require("amsmath");
|
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathTFrac
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetMathTFrac::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new InsetMathTFrac(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathTFrac::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
StyleChanger dummy(mi.base, LM_ST_SCRIPT);
|
|
|
|
|
Dimension dim0;
|
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
Dimension dim1;
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.wid = std::max(dim0.width(), dim1.width()) + 2;
|
|
|
|
|
dim.asc = dim0.height() + 2 + 5;
|
|
|
|
|
dim.des = dim1.height() + 2 - 5;
|
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathTFrac::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
StyleChanger dummy(pi.base, LM_ST_SCRIPT);
|
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
|
int m = x + dim.wid / 2;
|
|
|
|
|
cell(0).draw(pi, m - dim0.width() / 2, y - dim0.descent() - 2 - 5);
|
|
|
|
|
cell(1).draw(pi, m - dim1.width() / 2, y + dim1.ascent() + 2 - 5);
|
|
|
|
|
pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color_math);
|
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetMathTFrac::name() const
|
|
|
|
|
{
|
|
|
|
|
return from_ascii("tfrac");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathTFrac::mathmlize(MathStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << MTag("mtfrac") << cell(0) << cell(1) << ETag("mtfrac");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathTFrac::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require("amsmath");
|
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathBinom
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMathBinom::InsetMathBinom(bool choose)
|
|
|
|
|
: choose_(choose)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetMathBinom::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new InsetMathBinom(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMathBinom::dw(int height) const
|
|
|
|
|
{
|
|
|
|
|
int w = height / 5;
|
|
|
|
|
if (w > 15)
|
|
|
|
|
w = 15;
|
|
|
|
|
if (w < 6)
|
|
|
|
|
w = 6;
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
2007-10-28 13:15:35 +00:00
|
|
|
|
FracChanger dummy(mi.base);
|
2007-10-25 21:53:06 +00:00
|
|
|
|
Dimension dim0, dim1;
|
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.asc = dim0.height() + 4 + 5;
|
|
|
|
|
dim.des = dim1.height() + 4 - 5;
|
|
|
|
|
dim.wid = std::max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
|
|
|
|
|
metricsMarkers2(dim);
|
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
|
int m = x + dim.width() / 2;
|
2007-10-28 13:15:35 +00:00
|
|
|
|
FracChanger dummy(pi.base);
|
2007-10-25 21:53:06 +00:00
|
|
|
|
cell(0).draw(pi, m - dim0.width() / 2, y - dim0.des - 3 - 5);
|
|
|
|
|
cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5);
|
|
|
|
|
mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
|
|
|
|
|
mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
|
|
|
|
|
dw(dim.height()), dim.height(), from_ascii(")"));
|
|
|
|
|
drawMarkers2(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathBinom::extraBraces() const
|
|
|
|
|
{
|
|
|
|
|
return choose_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBinom::write(WriteStream & os) const
|
|
|
|
|
{
|
|
|
|
|
if (choose_)
|
|
|
|
|
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
|
|
|
|
|
else
|
|
|
|
|
os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBinom::normalize(NormalStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "[binom " << cell(0) << ' ' << cell(1) << ']';
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-10-28 21:48:51 +00:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathDBinom
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
Inset * InsetMathDBinom::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new InsetMathDBinom(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMathDBinom::dw(int height) const
|
|
|
|
|
{
|
|
|
|
|
int w = height / 5;
|
|
|
|
|
if (w > 15)
|
|
|
|
|
w = 15;
|
|
|
|
|
if (w < 6)
|
|
|
|
|
w = 6;
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathDBinom::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
Dimension dim0, dim1;
|
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.asc = dim0.height() + 4 + 5;
|
|
|
|
|
dim.des = dim1.height() + 4 - 5;
|
|
|
|
|
dim.wid = std::max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
|
|
|
|
|
metricsMarkers2(dim);
|
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathDBinom::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
|
int m = x + dim.width() / 2;
|
|
|
|
|
cell(0).draw(pi, m - dim0.width() / 2, y - dim0.des - 3 - 5);
|
|
|
|
|
cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5);
|
|
|
|
|
mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
|
|
|
|
|
mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
|
|
|
|
|
dw(dim.height()), dim.height(), from_ascii(")"));
|
|
|
|
|
drawMarkers2(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetMathDBinom::name() const
|
|
|
|
|
{
|
|
|
|
|
return from_ascii("dbinom");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InsetMathDBinom::mathmlize(MathStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << MTag("mdbinom") << cell(0) << cell(1) << ETag("mdbinom");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InsetMathDBinom::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require("amsmath");
|
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetMathTBinom
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
Inset * InsetMathTBinom::clone() const
|
|
|
|
|
{
|
|
|
|
|
return new InsetMathTBinom(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMathTBinom::dw(int height) const
|
|
|
|
|
{
|
|
|
|
|
int w = height / 5;
|
|
|
|
|
if (w > 15)
|
|
|
|
|
w = 15;
|
|
|
|
|
if (w < 6)
|
|
|
|
|
w = 6;
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathTBinom::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
StyleChanger dummy(mi.base, LM_ST_SCRIPT);
|
|
|
|
|
Dimension dim0, dim1;
|
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
|
dim.asc = dim0.height() + 4 + 5;
|
|
|
|
|
dim.des = dim1.height() + 4 - 5;
|
|
|
|
|
dim.wid = std::max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
|
|
|
|
|
metricsMarkers2(dim);
|
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathTBinom::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
StyleChanger dummy(pi.base, LM_ST_SCRIPT);
|
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
|
|
|
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
|
|
|
|
|
int m = x + dim.width() / 2;
|
|
|
|
|
cell(0).draw(pi, m - dim0.width() / 2, y - dim0.des - 3 - 5);
|
|
|
|
|
cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5);
|
|
|
|
|
mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
|
|
|
|
|
mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
|
|
|
|
|
dw(dim.height()), dim.height(), from_ascii(")"));
|
|
|
|
|
drawMarkers2(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetMathTBinom::name() const
|
|
|
|
|
{
|
|
|
|
|
return from_ascii("tbinom");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InsetMathTBinom::mathmlize(MathStream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << MTag("mtbinom") << cell(0) << cell(1) << ETag("mtbinom");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InsetMathTBinom::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require("amsmath");
|
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|