2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathBox.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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2007-11-06 20:57:29 +00:00
|
|
|
* \author Ling Li (InsetMathMakebox)
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathBox.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
#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-11-06 20:57:29 +00:00
|
|
|
#include "MathSupport.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetMathBox
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
InsetMathBox::InsetMathBox(docstring const & name)
|
2006-09-16 18:11:38 +00:00
|
|
|
: InsetMathNest(1), name_(name)
|
2001-10-19 16:07:10 +00:00
|
|
|
{}
|
2001-10-19 11:25:48 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathBox::write(WriteStream & os) const
|
2001-10-19 11:25:48 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
ModeSpecifier specifier(os, TEXT_MODE);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '\\' << name_ << '{' << cell(0) << '}';
|
2001-10-19 11:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathBox::normalize(NormalStream & os) const
|
2001-10-19 11:25:48 +00:00
|
|
|
{
|
2001-12-18 12:21:33 +00:00
|
|
|
os << '[' << name_ << ' ';
|
2001-10-19 11:25:48 +00:00
|
|
|
//text_->write(buffer(), os);
|
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-10-19 11:25:48 +00:00
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
FontSetChanger dummy(mi.base, "textnormal");
|
2004-01-30 11:41:12 +00:00
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
metricsMarkers(dim);
|
2002-06-04 09:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
|
2002-06-04 09:06:04 +00:00
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
FontSetChanger dummy(pi.base, "textnormal");
|
2002-08-02 14:29:42 +00:00
|
|
|
cell(0).draw(pi, x, y);
|
2003-05-28 13:22:36 +00:00
|
|
|
drawMarkers(pi, x, y);
|
2001-10-24 19:09:31 +00:00
|
|
|
}
|
2002-07-10 07:15:36 +00:00
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathBox::infoize(odocstream & os) const
|
2002-07-10 07:15:36 +00:00
|
|
|
{
|
|
|
|
os << "Box: " << name_;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2008-03-05 18:57:08 +00:00
|
|
|
void InsetMathBox::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
if (name_ == "tag" || name_ == "tag*")
|
|
|
|
features.require("amsmath");
|
|
|
|
cell(0).validate(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetMathFBox
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
InsetMathFBox::InsetMathFBox()
|
|
|
|
: InsetMathNest(1)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
{
|
|
|
|
FontSetChanger dummy(mi.base, "textnormal");
|
|
|
|
cell(0).metrics(mi, dim);
|
2008-08-24 21:16:09 +00:00
|
|
|
metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
|
2007-11-06 20:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
|
|
|
|
dim.width() - 2, dim.height() - 2, Color_foreground);
|
|
|
|
FontSetChanger dummy(pi.base, "textnormal");
|
|
|
|
cell(0).draw(pi, x + 3, y);
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathFBox::write(WriteStream & os) const
|
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
ModeSpecifier specifier(os, TEXT_MODE);
|
2007-11-06 20:57:29 +00:00
|
|
|
os << "\\fbox{" << cell(0) << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathFBox::normalize(NormalStream & os) const
|
|
|
|
{
|
|
|
|
os << "[fbox " << cell(0) << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathFBox::infoize(odocstream & os) const
|
|
|
|
{
|
|
|
|
os << "FBox: ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2008-02-28 12:46:32 +00:00
|
|
|
// InsetMathMakebox
|
2007-11-06 20:57:29 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
InsetMathMakebox::InsetMathMakebox(bool framebox)
|
|
|
|
: InsetMathNest(3), framebox_(framebox)
|
2007-11-06 20:57:29 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
|
2007-11-06 20:57:29 +00:00
|
|
|
{
|
|
|
|
FontSetChanger dummy(mi.base, "textnormal");
|
2008-02-28 12:45:36 +00:00
|
|
|
|
|
|
|
Dimension wdim;
|
|
|
|
static docstring bracket = from_ascii("[");
|
|
|
|
mathed_string_dim(mi.base.font, bracket, wdim);
|
|
|
|
int w = wdim.wid;
|
|
|
|
|
|
|
|
Dimension dim0;
|
|
|
|
Dimension dim1;
|
|
|
|
Dimension dim2;
|
|
|
|
cell(0).metrics(mi, dim0);
|
|
|
|
cell(1).metrics(mi, dim1);
|
|
|
|
cell(2).metrics(mi, dim2);
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
|
2008-02-28 12:45:36 +00:00
|
|
|
dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc));
|
|
|
|
dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
|
2008-02-28 12:46:32 +00:00
|
|
|
|
|
|
|
if (framebox_) {
|
|
|
|
dim.wid += 4;
|
|
|
|
dim.asc += 3;
|
|
|
|
dim.des += 2;
|
|
|
|
} else {
|
|
|
|
dim.asc += 1;
|
|
|
|
dim.des += 1;
|
|
|
|
}
|
2008-02-28 12:45:36 +00:00
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
metricsMarkers(dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
|
2007-11-06 20:57:29 +00:00
|
|
|
{
|
2008-02-28 12:45:36 +00:00
|
|
|
drawMarkers(pi, x, y);
|
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
FontSetChanger dummy(pi.base, "textnormal");
|
2008-02-28 12:46:32 +00:00
|
|
|
BufferView const & bv = *pi.base.bv;
|
2008-02-28 12:45:36 +00:00
|
|
|
int w = mathed_char_width(pi.base.font, '[');
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
if (framebox_) {
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
|
|
|
|
dim.width() - 2, dim.height() - 2, Color_foreground);
|
|
|
|
x += 2;
|
|
|
|
}
|
2008-02-28 12:45:36 +00:00
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
drawStrBlack(pi, x, y, from_ascii("["));
|
2008-02-28 12:45:36 +00:00
|
|
|
x += w;
|
2007-11-06 20:57:29 +00:00
|
|
|
cell(0).draw(pi, x, y);
|
|
|
|
x += cell(0).dimension(bv).wid;
|
|
|
|
drawStrBlack(pi, x, y, from_ascii("]"));
|
2008-02-28 12:46:32 +00:00
|
|
|
x += w;
|
2007-11-06 20:57:29 +00:00
|
|
|
|
|
|
|
drawStrBlack(pi, x, y, from_ascii("["));
|
2008-02-28 12:45:36 +00:00
|
|
|
x += w;
|
2007-11-06 20:57:29 +00:00
|
|
|
cell(1).draw(pi, x, y);
|
|
|
|
x += cell(1).dimension(bv).wid;
|
|
|
|
drawStrBlack(pi, x, y, from_ascii("]"));
|
2008-02-28 12:46:32 +00:00
|
|
|
x += w + 2;
|
2007-11-06 20:57:29 +00:00
|
|
|
|
|
|
|
cell(2).draw(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
void InsetMathMakebox::write(WriteStream & os) const
|
2007-11-06 20:57:29 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
ModeSpecifier specifier(os, TEXT_MODE);
|
2008-02-28 12:46:32 +00:00
|
|
|
os << (framebox_ ? "\\framebox" : "\\makebox");
|
|
|
|
if (cell(0).size() || !os.latex()) {
|
|
|
|
os << '[' << cell(0) << ']';
|
|
|
|
if (cell(1).size() || !os.latex())
|
|
|
|
os << '[' << cell(1) << ']';
|
|
|
|
}
|
2007-11-06 20:57:29 +00:00
|
|
|
os << '{' << cell(2) << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
void InsetMathMakebox::normalize(NormalStream & os) const
|
2007-11-06 20:57:29 +00:00
|
|
|
{
|
2008-02-28 12:46:32 +00:00
|
|
|
os << (framebox_ ? "[framebox " : "[makebox ")
|
|
|
|
<< cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
|
2007-11-06 20:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 12:46:32 +00:00
|
|
|
void InsetMathMakebox::infoize(odocstream & os) const
|
|
|
|
{
|
|
|
|
os << (framebox_ ? "Framebox" : "Makebox")
|
|
|
|
<< " (width: " << cell(0)
|
|
|
|
<< " pos: " << cell(1) << ")";
|
|
|
|
}
|
|
|
|
|
2007-11-06 20:57:29 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetMathBoxed
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
InsetMathBoxed::InsetMathBoxed()
|
|
|
|
: InsetMathNest(1)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
{
|
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
|
|
|
|
dim.width() - 2, dim.height() - 2, Color_foreground);
|
|
|
|
cell(0).draw(pi, x + 3, y);
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBoxed::write(WriteStream & os) const
|
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
ModeSpecifier specifier(os, MATH_MODE);
|
2007-11-06 20:57:29 +00:00
|
|
|
os << "\\boxed{" << cell(0) << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBoxed::normalize(NormalStream & os) const
|
|
|
|
{
|
|
|
|
os << "[boxed " << cell(0) << ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBoxed::infoize(odocstream & os) const
|
|
|
|
{
|
|
|
|
os << "Boxed: ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathBoxed::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
features.require("amsmath");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|