partial framebox support

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5169 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-29 09:57:57 +00:00
parent 9950158a94
commit 0355e7d391
7 changed files with 119 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2002-08-29 André Pönitz <poenitz@gmx.net>
* math_framboxinset.[Ch]: new (partial) support for \framebox
* math_parser.C: generalization for reading optional arguments
2002-08-26 Lars Gullik Bjønnes <larsbj@birdstep.com>
* math_parinset.C: add support/LOstream.h and config.h

View File

@ -65,6 +65,8 @@ libmathed_la_SOURCES = \
math_factory.h \
math_fboxinset.C \
math_fboxinset.h \
math_frameboxinset.C \
math_frameboxinset.h \
math_fontinset.C \
math_fontinset.h \
math_fontoldinset.C \

View File

@ -10,6 +10,7 @@
#include "math_dotsinset.h"
#include "math_ertinset.h"
#include "math_fboxinset.h"
#include "math_frameboxinset.h"
#include "math_fontinset.h"
#include "math_fontoldinset.h"
#include "math_fracinset.h"
@ -218,6 +219,8 @@ MathAtom createMathInset(string const & s)
if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
&& s[2] >= '1' && s[2] <= '9')
return MathAtom(new MathMacroArgument(s[2] - '0'));
if (s == "framebox")
return MathAtom(new MathFrameboxInset);
if (s == "kern")
return MathAtom(new MathKernInset);
if (s == "xymatrix")

View File

@ -26,7 +26,7 @@ public:
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo &, int x, int y) const;
void draw(MathPainterInfo & pi, int x, int y) const;
///
void write(WriteStream & os) const;
/// write normalized content

View File

@ -0,0 +1,64 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_frameboxinset.h"
#include "math_support.h"
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "frontends/Painter.h"
MathFrameboxInset::MathFrameboxInset()
: MathNestInset(2)
{}
MathInset * MathFrameboxInset::clone() const
{
return new MathFrameboxInset(*this);
}
void MathFrameboxInset::metrics(MathMetricsInfo & mi) const
{
w_ = mathed_char_width(mi.base.font, '[');
MathNestInset::metrics(mi);
dim_ = cell(0).dim();
dim_ += cell(1).dim();
dim_.w += 2 * w_ + 4;
metricsMarkers2(5); // 5 pixels margin
}
void MathFrameboxInset::draw(MathPainterInfo & pi, int x, int y) const
{
pi.pain.rectangle(x + 1, y - ascent() + 1, width() - 2, height() - 2,
LColor::black);
x += 5;
drawStrBlack(pi, x, y, "[");
x += w_;
cell(0).draw(pi, x, y);
x += cell(0).width();
drawStrBlack(pi, x, y, "]");
x += w_ + 4;
cell(1).draw(pi, x, y);
}
void MathFrameboxInset::write(WriteStream & os) const
{
os << "\\framebox";
if (cell(0).size())
os << '[' << cell(0) << ']';
os << '{' << cell(1) << '}';
}
void MathFrameboxInset::normalize(NormalStream & os) const
{
os << "[framebox " << cell(0) << ' ' << cell(1) << ']';
}

View File

@ -0,0 +1,34 @@
// -*- C++ -*-
#ifndef MATH_FRAMEBOXINSET_H
#define MATH_FRAMEBOXINSET_H
#include "math_nestinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Extra nesting
\author André Pönitz
*/
class MathFrameboxInset : public MathNestInset {
public:
///
MathFrameboxInset();
///
MathInset * clone() const;
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo & pi, int x, int y) const;
///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
private:
/// width of '[' in current font
mutable int w_;
};
#endif

View File

@ -1149,7 +1149,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
MathInset::mode_type m = mode;
if (m == MathInset::UNDECIDED_MODE)
m = at->currentMode();
for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
MathArray opt;
parse(opt, FLAG_OPTION, MathInset::VERBATIM_MODE);
MathInset::idx_type start = 0;
if (opt.size()) {
start = 1;
at.nucleus()->cell(0) = opt;
}
for (MathInset::idx_type i = start; i < at->nargs(); ++i)
parse(at.nucleus()->cell(i), FLAG_ITEM, m);
cell->push_back(at);
}