preliminary work for \parbox support

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4543 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-08 11:29:51 +00:00
parent f3059f5772
commit 4dd411c611
15 changed files with 220 additions and 108 deletions

View File

@ -97,6 +97,10 @@ libmathed_la_SOURCES = \
math_notinset.h \
math_numberinset.C \
math_numberinset.h \
math_parboxinset.C \
math_parboxinset.h \
math_parinset.C \
math_parinset.h \
math_parser.C \
math_parser.h \
math_pos.C \

View File

@ -1384,6 +1384,8 @@ bool MathCursor::inMathMode() const
return false;
if (par()->asFboxInset())
return false;
if (par()->asParboxInset())
return false;
if (par()->asParInset())
return false;
return true;

View File

@ -17,6 +17,7 @@
#include "math_macrotable.h"
#include "math_macroarg.h"
#include "math_notinset.h"
#include "math_parboxinset.h"
#include "math_rootinset.h"
#include "math_sizeinset.h"
#include "math_spaceinset.h"
@ -99,7 +100,6 @@ key_type wordlist_array[] =
{"ldots", "dots", ""},
{"left", "left", ""},
{"limits", "limit", ""},
{"lyxbox", "box", ""},
{"lyxnegspace", "space", ""},
{"lyxposspace", "space", ""},
{"mathbb", "font", ""},
@ -113,7 +113,7 @@ key_type wordlist_array[] =
{"mathsf", "font", ""},
{"mathtt", "font", ""},
{"matrix", "matrix", ""},
{"mbox", "box", ""},
{"mbox", "mbox", ""},
{"newcommand", "newcommand", ""},
{"nolimits", "limit", ""},
{"nonumber", "nonum", ""},
@ -123,6 +123,7 @@ key_type wordlist_array[] =
{"overrightarrow", "decoration", ""},
{"overleftrightarrow", "decoration", ""},
{"pageref", "ref", ""},
{"parbox", "parbox", ""},
{"pmatrix", "matrix", ""},
{"prettyref", "ref", ""},
{"protect", "protect", ""},
@ -135,6 +136,7 @@ key_type wordlist_array[] =
{"scriptstyle", "style", ""},
{"text", "font", "mathtext"},
{"textbf", "font", "mathtext"},
{"textipa", "font", "mathtext"},
{"textit", "font", "mathtext"},
{"textmd", "font", "mathtext"},
{"textrm", "font", "mathtext"},
@ -328,8 +330,10 @@ MathAtom createMathInset(string const & s)
return MathAtom(new MathSpaceInset(l->name));
if (inset == "dots")
return MathAtom(new MathDotsInset(l->name));
if (inset == "box")
if (inset == "mbox")
return MathAtom(new MathBoxInset(l->name));
if (inset == "parbox")
return MathAtom(new MathParboxInset);
if (inset == "fbox")
return MathAtom(new MathFboxInset);
if (inset == "style")

View File

@ -34,7 +34,7 @@ void MathFontInset::metrics(MathMetricsInfo & mi) const
MathFontSetChanger dummy(mi.base, name_.c_str());
xcell(0).metrics(mi);
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent() + 2;
descent_ = xcell(0).descent() + 1;
width_ = xcell(0).width() + 2;
}

View File

@ -657,44 +657,3 @@ void MathHullInset::check() const
lyx::Assert(nonum_.size() == nrows());
lyx::Assert(label_.size() == nrows());
}
//
// MathParInset
//
MathParInset::MathParInset()
{
lyxerr << "constructing MathParInset\n";
}
void MathParInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, "textnormal");
MathGridInset::metrics(mi);
}
void MathParInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, "textnormal");
MathGridInset::draw(pi, x, y);
}
void MathParInset::write(WriteStream & os) const
{
for (idx_type i = 0; i < nargs(); ++i)
os << cell(i) << "\n";
}
void MathParInset::infoize(std::ostream & os) const
{
os << "Type: Paragraph ";
}

View File

@ -115,25 +115,4 @@ private:
std::vector<string> label_;
};
class MathParInset : public MathHullInset {
public:
///
MathParInset();
///
MathParInset * asParInset() { return this; }
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo &, int x, int y) const;
///
void infoize(std::ostream & os) const;
///
void write(WriteStream & os) const;
private:
///
void rebreak();
};
#endif

View File

@ -61,6 +61,7 @@ class MathHullInset;
class MathMatrixInset;
class MathNestInset;
class MathParInset;
class MathParboxInset;
class MathScriptInset;
class MathStringInset;
class MathSpaceInset;
@ -208,6 +209,7 @@ public:
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
virtual MathNestInset * asNestInset() { return 0; }
virtual MathParInset * asParInset() { return 0; }
virtual MathParboxInset * asParboxInset() { return 0; }
virtual MathScriptInset * asScriptInset() { return 0; }
virtual MathScriptInset const * asScriptInset() const { return 0; }
virtual MathSpaceInset * asSpaceInset() { return 0; }

View File

@ -34,15 +34,9 @@ MathInset * MathKernInset::clone() const
void MathKernInset::metrics(MathMetricsInfo & /*mi*/) const
{
#ifdef WITH_WARNINGS
#warning fix this once the interface to LyXLength has improved
#endif
// this uses the numerical valu in pixels, even if the unit is cm or ex!
width_ = static_cast<int>(wid_.value());
width_ = (width_*static_cast<int>(lyxrc.zoom))/150;
width_ = wid_.inBP();
ascent_ = 0;
descent_ = 0;
//cerr << "handling kern of width " << wid_.value() << "\n";
}

View File

@ -3,12 +3,14 @@
#include "math_metricsinfo.h"
#include "math_support.h"
#include "debug.h"
#include "frontends/Painter.h"
MathMetricsBase::MathMetricsBase()
: font(), style(LM_ST_TEXT), fontname("mathnormal")
: font(), style(LM_ST_TEXT), fontname("mathnormal"),
restrictwidth(false), textwidth(0)
{}
@ -147,3 +149,18 @@ MathFontSetChanger::~MathFontSetChanger()
orig_ = save_;
}
MathWidthChanger::MathWidthChanger(MathMetricsBase & mb, int w)
: MathChanger<MathMetricsBase>(mb)
{
save_ = mb;
mb.restrictwidth = true;
mb.textwidth = w;
}
MathWidthChanger::~MathWidthChanger()
{
orig_ = save_;
}

View File

@ -32,6 +32,10 @@ struct MathMetricsBase {
MathStyles style;
///
string fontname;
/// if this is set...
bool restrictwidth;
/// ... this is valid
int textwidth;
};
@ -132,4 +136,13 @@ struct MathShapeChanger : public MathChanger<LyXFont, LyXFont::FONT_SHAPE> {
};
struct MathWidthChanger : public MathChanger<MathMetricsBase>
{
///
MathWidthChanger(MathMetricsBase & mb, int width);
///
~MathWidthChanger();
};
#endif

View File

@ -0,0 +1,70 @@
#include "math_parboxinset.h"
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "lyxlength.h"
#include "debug.h"
MathParboxInset::MathParboxInset()
: MathNestInset(1), lyx_width_(0), tex_width_("0mm"),
position_('c')
{
lyxerr << "constructing MathParboxInset\n";
}
MathInset * MathParboxInset::clone() const
{
return new MathParboxInset(*this);
}
void MathParboxInset::setPosition(string const & p)
{
position_ = p.size() > 0 ? p[0] : 'c';
}
void MathParboxInset::setWidth(string const & w)
{
tex_width_ = w;
lyx_width_ = LyXLength(w).inBP();
lyxerr << "setting " << w << " to " << lyx_width_ << " pixel\n";
}
void MathParboxInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy1(mi.base, "textnormal");
MathWidthChanger dummy2(mi.base, lyx_width_);
xcell(0).metrics(mi);
ascent_ = xcell(0).ascent();
descent_ = xcell(0).descent() + 1;
width_ = xcell(0).width() + 2;
}
void MathParboxInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy1(pi.base, "textnormal");
MathWidthChanger dummy2(pi.base, lyx_width_);
xcell(0).draw(pi, x + 1, y);
drawMarkers(pi, x, y);
}
void MathParboxInset::write(WriteStream & os) const
{
os << "\\parbox";
if (position_ != 'c')
os << '[' << position_ << ']';
os << '{' << tex_width_ << "}{" << cell(0) << '}';
}
void MathParboxInset::infoize(std::ostream & os) const
{
os << "Box: Parbox " << tex_width_ << ' ';
}

View File

@ -0,0 +1,37 @@
#ifndef MATH_PARBOXINSET_H
#define MATH_PARBOXINSET_H
#include "math_nestinset.h"
class MathParboxInset : public MathNestInset {
public:
///
MathParboxInset();
///
MathParboxInset * asParboxInset() { return this; }
///
MathInset * clone() const;
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo &, int x, int y) const;
///
void infoize(std::ostream & os) const;
///
void write(WriteStream & os) const;
///
void setWidth(string const & width);
///
void setPosition(string const & pos);
private:
///
void rebreak();
/// width on screen
int lyx_width_;
/// width for TeX
string tex_width_;
///
char position_;
};
#endif

View File

@ -50,6 +50,8 @@ following hack as starting point to write some macros:
#include "math_macrotable.h"
#include "math_macrotemplate.h"
#include "math_hullinset.h"
#include "math_parboxinset.h"
#include "math_parinset.h"
#include "math_rootinset.h"
#include "math_sizeinset.h"
#include "math_sqrtinset.h"
@ -125,13 +127,14 @@ enum {
FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
FLAG_END = 1 << 3, // next \\end ends the parsing process
FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing
FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
FLAG_TEXTMODE = 1 << 5, // we are in a box
FLAG_ITEM = 1 << 6, // read a (possibly braced token)
FLAG_LEAVE = 1 << 7, // leave the loop at the end
FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
FLAG_EQUATION = 1 << 9, // next \] leaves the loop
FLAG_SIMPLE2 = 1 << 10 // next \) leaves the loop
FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
FLAG_OPTION = 1 << 11 // read [...] style option
};
@ -648,6 +651,19 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
flags |= FLAG_LEAVE;
}
if (flags & FLAG_OPTION) {
if (t.cat() == catOther && t.character() == '[') {
// skip the bracket and collect everything to the clsing bracket
flags |= FLAG_BRACK_LAST;
continue;
}
// no option found, put back token and we are done
putback();
return;
}
//
// cat codes
//
@ -734,7 +750,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
limits = 0;
}
else if (t.character() == ']' && (flags & FLAG_BRACK_END))
else if (t.character() == ']' && (flags & FLAG_BRACK_LAST))
return;
else if (t.cat() == catOther)
@ -846,13 +862,13 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
}
else if (t.cs() == "sqrt") {
char c = getChar();
if (c == '[') {
MathArray ar;
parse_into(ar, FLAG_OPTION, mathmode);
if (ar.size()) {
cell->push_back(MathAtom(new MathRootInset));
parse_into(cell->back()->cell(0), FLAG_BRACK_END, mathmode);
cell->back()->cell(0) = ar;
parse_into(cell->back()->cell(1), FLAG_ITEM, mathmode);
} else {
putback();
cell->push_back(MathAtom(new MathSqrtInset));
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
}
@ -860,11 +876,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
else if (t.cs() == "ref") {
cell->push_back(MathAtom(new RefInset));
char c = getChar();
if (c == '[')
parse_into(cell->back()->cell(1), FLAG_BRACK_END, mathmode);
else
putback();
parse_into(cell->back()->cell(1), FLAG_OPTION, mathmode);
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
}
@ -1009,16 +1021,8 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
// Disabled
else if (1 && t.cs() == "ar") {
MathXYArrowInset * p = new MathXYArrowInset;
// try to read target
char c = getChar();
if (c == '[') {
parse_into(p->cell(0), FLAG_BRACK_END, mathmode);
//lyxerr << "read target: " << p->cell(0) << "\n";
} else {
putback();
}
parse_into(p->cell(0), FLAG_OTPTION, mathmode);
// try to read label
if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
p->up_ = nextToken().cat() == catSuper;
@ -1050,7 +1054,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
return;
}
else if (l->inset == "box") {
else if (l->inset == "mbox") {
// switch to text mode
cell->push_back(createMathInset(t.cs()));
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
@ -1062,6 +1066,17 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
return;
}
else if (l->inset == "parbox") {
// read optional positioning and width
MathArray pos, width;
parse_into(pos, FLAG_OPTION, false);
parse_into(width, FLAG_ITEM, false);
cell->push_back(createMathInset(t.cs()));
parse_into(cell->back()->cell(0), FLAG_ITEM, false);
cell->back()->asParboxInset()->setPosition(asString(pos));
cell->back()->asParboxInset()->setWidth(asString(width));
}
else {
MathAtom p = createMathInset(t.cs());
for (MathInset::idx_type i = 0; i < p->nargs(); ++i)
@ -1108,20 +1123,19 @@ void mathed_parse_cell(MathArray & ar, istream & is)
bool mathed_parse_macro(string & name, string const & str)
{
istringstream is(str.c_str());
Parser parser(is);
return parser.parse_macro(name);
return Parser(is).parse_macro(name);
}
bool mathed_parse_macro(string & name, istream & is)
{
Parser parser(is);
return parser.parse_macro(name);
return Parser(is).parse_macro(name);
}
bool mathed_parse_macro(string & name, LyXLex & lex)
{
Parser parser(lex);
return parser.parse_macro(name);
return Parser(lex).parse_macro(name);
}
@ -1129,18 +1143,17 @@ bool mathed_parse_macro(string & name, LyXLex & lex)
bool mathed_parse_normal(MathAtom & t, string const & str)
{
istringstream is(str.c_str());
Parser parser(is);
return parser.parse_normal(t);
return Parser(is).parse_normal(t);
}
bool mathed_parse_normal(MathAtom & t, istream & is)
{
Parser parser(is);
return parser.parse_normal(t);
return Parser(is).parse_normal(t);
}
bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
{
Parser parser(lex);
return parser.parse_normal(t);
return Parser(lex).parse_normal(t);
}

View File

@ -566,6 +566,9 @@ fontinfo fontinfos[] = {
{"texttt", LyXFont::TYPEWRITER_FAMILY, inh_series, inh_shape, LColor::black},
{"textup", inh_family, inh_series, LyXFont::UP_SHAPE, LColor::black},
// TIPA support
{"textipa", inh_family, inh_series, inh_shape, LColor::black},
{"lyxtex", inh_family, inh_series, inh_shape, LColor::latex},
{"lyxsymbol", LyXFont::SYMBOL_FAMILY, inh_series, inh_shape, LColor::math},
{"lyxboldsymbol",

View File

@ -68,6 +68,15 @@ void MathXArray::metrics(MathMetricsInfo & mi) const
}
//lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
// << descent_ << " " << width_ << "'\n";
//
// re-break paragraph
//
if (mi.base.restrictwidth) {
width_ = mi.base.textwidth;
lyxerr << "restricting width to " << width_ << " pixel\n";
}
}
@ -110,6 +119,12 @@ void MathXArray::draw(MathPainterInfo & pi, int x, int y) const
x += p->width();
}
}
//
// re-break paragraph
//
if (pi.base.restrictwidth) {
}
}