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_notinset.h \
math_numberinset.C \ math_numberinset.C \
math_numberinset.h \ math_numberinset.h \
math_parboxinset.C \
math_parboxinset.h \
math_parinset.C \
math_parinset.h \
math_parser.C \ math_parser.C \
math_parser.h \ math_parser.h \
math_pos.C \ math_pos.C \

View File

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

View File

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

View File

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

View File

@ -657,44 +657,3 @@ void MathHullInset::check() const
lyx::Assert(nonum_.size() == nrows()); lyx::Assert(nonum_.size() == nrows());
lyx::Assert(label_.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_; 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 #endif

View File

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

View File

@ -34,15 +34,9 @@ MathInset * MathKernInset::clone() const
void MathKernInset::metrics(MathMetricsInfo & /*mi*/) const void MathKernInset::metrics(MathMetricsInfo & /*mi*/) const
{ {
#ifdef WITH_WARNINGS width_ = wid_.inBP();
#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;
ascent_ = 0; ascent_ = 0;
descent_ = 0; descent_ = 0;
//cerr << "handling kern of width " << wid_.value() << "\n";
} }

View File

@ -3,12 +3,14 @@
#include "math_metricsinfo.h" #include "math_metricsinfo.h"
#include "math_support.h" #include "math_support.h"
#include "debug.h"
#include "frontends/Painter.h" #include "frontends/Painter.h"
MathMetricsBase::MathMetricsBase() 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_; 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; MathStyles style;
/// ///
string fontname; 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 #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_macrotable.h"
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
#include "math_hullinset.h" #include "math_hullinset.h"
#include "math_parboxinset.h"
#include "math_parinset.h"
#include "math_rootinset.h" #include "math_rootinset.h"
#include "math_sizeinset.h" #include "math_sizeinset.h"
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
@ -125,13 +127,14 @@ enum {
FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
FLAG_END = 1 << 3, // next \\end 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_TEXTMODE = 1 << 5, // we are in a box
FLAG_ITEM = 1 << 6, // read a (possibly braced token) FLAG_ITEM = 1 << 6, // read a (possibly braced token)
FLAG_LEAVE = 1 << 7, // leave the loop at the end FLAG_LEAVE = 1 << 7, // leave the loop at the end
FLAG_SIMPLE = 1 << 8, // next $ leaves the loop FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
FLAG_EQUATION = 1 << 9, // 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; 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 // cat codes
// //
@ -734,7 +750,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
limits = 0; limits = 0;
} }
else if (t.character() == ']' && (flags & FLAG_BRACK_END)) else if (t.character() == ']' && (flags & FLAG_BRACK_LAST))
return; return;
else if (t.cat() == catOther) else if (t.cat() == catOther)
@ -846,13 +862,13 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
} }
else if (t.cs() == "sqrt") { else if (t.cs() == "sqrt") {
char c = getChar(); MathArray ar;
if (c == '[') { parse_into(ar, FLAG_OPTION, mathmode);
if (ar.size()) {
cell->push_back(MathAtom(new MathRootInset)); 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); parse_into(cell->back()->cell(1), FLAG_ITEM, mathmode);
} else { } else {
putback();
cell->push_back(MathAtom(new MathSqrtInset)); cell->push_back(MathAtom(new MathSqrtInset));
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode); 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") { else if (t.cs() == "ref") {
cell->push_back(MathAtom(new RefInset)); cell->push_back(MathAtom(new RefInset));
char c = getChar(); parse_into(cell->back()->cell(1), FLAG_OPTION, mathmode);
if (c == '[')
parse_into(cell->back()->cell(1), FLAG_BRACK_END, mathmode);
else
putback();
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode); parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
} }
@ -1009,16 +1021,8 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
// Disabled // Disabled
else if (1 && t.cs() == "ar") { else if (1 && t.cs() == "ar") {
MathXYArrowInset * p = new MathXYArrowInset; MathXYArrowInset * p = new MathXYArrowInset;
// try to read target // try to read target
char c = getChar(); parse_into(p->cell(0), FLAG_OTPTION, mathmode);
if (c == '[') {
parse_into(p->cell(0), FLAG_BRACK_END, mathmode);
//lyxerr << "read target: " << p->cell(0) << "\n";
} else {
putback();
}
// try to read label // try to read label
if (nextToken().cat() == catSuper || nextToken().cat() == catSub) { if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
p->up_ = nextToken().cat() == catSuper; p->up_ = nextToken().cat() == catSuper;
@ -1050,7 +1054,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
return; return;
} }
else if (l->inset == "box") { else if (l->inset == "mbox") {
// switch to text mode // switch to text mode
cell->push_back(createMathInset(t.cs())); cell->push_back(createMathInset(t.cs()));
parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode); parse_into(cell->back()->cell(0), FLAG_ITEM, mathmode);
@ -1062,6 +1066,17 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
return; 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 { else {
MathAtom p = createMathInset(t.cs()); MathAtom p = createMathInset(t.cs());
for (MathInset::idx_type i = 0; i < p->nargs(); ++i) 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) bool mathed_parse_macro(string & name, string const & str)
{ {
istringstream is(str.c_str()); istringstream is(str.c_str());
Parser parser(is); return Parser(is).parse_macro(name);
return parser.parse_macro(name);
} }
bool mathed_parse_macro(string & name, istream & is) bool mathed_parse_macro(string & name, istream & is)
{ {
Parser parser(is); return Parser(is).parse_macro(name);
return parser.parse_macro(name);
} }
bool mathed_parse_macro(string & name, LyXLex & lex) bool mathed_parse_macro(string & name, LyXLex & lex)
{ {
Parser parser(lex); return Parser(lex).parse_macro(name);
return parser.parse_macro(name);
} }
@ -1129,18 +1143,17 @@ bool mathed_parse_macro(string & name, LyXLex & lex)
bool mathed_parse_normal(MathAtom & t, string const & str) bool mathed_parse_normal(MathAtom & t, string const & str)
{ {
istringstream is(str.c_str()); istringstream is(str.c_str());
Parser parser(is); return Parser(is).parse_normal(t);
return parser.parse_normal(t);
} }
bool mathed_parse_normal(MathAtom & t, istream & is) bool mathed_parse_normal(MathAtom & t, istream & is)
{ {
Parser parser(is); return Parser(is).parse_normal(t);
return parser.parse_normal(t);
} }
bool mathed_parse_normal(MathAtom & t, LyXLex & lex) bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
{ {
Parser parser(lex); return Parser(lex).parse_normal(t);
return parser.parse_normal(t);
} }

View File

@ -566,6 +566,9 @@ fontinfo fontinfos[] = {
{"texttt", LyXFont::TYPEWRITER_FAMILY, inh_series, inh_shape, LColor::black}, {"texttt", LyXFont::TYPEWRITER_FAMILY, inh_series, inh_shape, LColor::black},
{"textup", inh_family, inh_series, LyXFont::UP_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}, {"lyxtex", inh_family, inh_series, inh_shape, LColor::latex},
{"lyxsymbol", LyXFont::SYMBOL_FAMILY, inh_series, inh_shape, LColor::math}, {"lyxsymbol", LyXFont::SYMBOL_FAMILY, inh_series, inh_shape, LColor::math},
{"lyxboldsymbol", {"lyxboldsymbol",

View File

@ -68,6 +68,15 @@ void MathXArray::metrics(MathMetricsInfo & mi) const
} }
//lyxerr << "MathXArray::metrics(): '" << ascent_ << " " //lyxerr << "MathXArray::metrics(): '" << ascent_ << " "
// << descent_ << " " << width_ << "'\n"; // << 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(); x += p->width();
} }
} }
//
// re-break paragraph
//
if (pi.base.restrictwidth) {
}
} }