]> git.lyx.org Git - lyx.git/commitdiff
preliminary work for \parbox support
authorAndré Pönitz <poenitz@gmx.net>
Mon, 8 Jul 2002 11:29:51 +0000 (11:29 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 8 Jul 2002 11:29:51 +0000 (11:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4543 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/mathed/Makefile.am
src/mathed/math_cursor.C
src/mathed/math_factory.C
src/mathed/math_fontinset.C
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_inset.h
src/mathed/math_kerninset.C
src/mathed/math_metricsinfo.C
src/mathed/math_metricsinfo.h
src/mathed/math_parboxinset.C [new file with mode: 0644]
src/mathed/math_parboxinset.h [new file with mode: 0644]
src/mathed/math_parser.C
src/mathed/math_support.C
src/mathed/math_xdata.C

index e9e80b686ee4133c8880d7ad1afc41d62ec812ac..8b1e7eba8ae52fa087fde4790519c0cc45dfe239 100644 (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 \
index 74ad9e9214088e1be471819b77224a0b9defd84e..323e8bfe88660f245744bd5615f8477816278071 100644 (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;
index 2b4bdddca64309adfc8c4ca9fbff1292a6d3eeb4..adf2136607273063e102b61af9bf73fe6452f2d5 100644 (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")
index a1e3bea0025b0a4198876a2fb2a725ce554535b3..d3ea87547f80e0e2823b2e9006047defd6ed187e 100644 (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;
 }
 
index bf6afdaf1c203fcbf670ae455ceec1b8bffa8b5e..3c77873eed431207bf50ab930701f927cf98bb41 100644 (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 ";
-}
-
index fefebc6b532602c38ce07725b96b4c66c3424bbd..63b38f91e04911bcac48b2bf292acaec7fc96505 100644 (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
index 1e5eda10121eb0f1d031ce05ce570b51cdec7d39..42e925ae32e6de9b356da15c461dfa42aa2b0b8a 100644 (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; }
index b7fcd368554cca6c11111e794cd9c19775e626cf..3cf45812cac8d49b63bfc445b767e8c0c7980d58 100644 (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";
 }
 
 
index f0938619ff15993620301f04414a5f9f8a238772..118d5aaf486a8e27f0167fc3c1de0594ac1f32b5 100644 (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_;
+}
+
index 8df3260399e038b7ea911f4cc3d0477ed1d6d4a0..8cb8422fd51e2ffe1a575ebf8a17e0dd0ea60afa 100644 (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
diff --git a/src/mathed/math_parboxinset.C b/src/mathed/math_parboxinset.C
new file mode 100644 (file)
index 0000000..254a678
--- /dev/null
@@ -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_ << ' ';
+}
+
diff --git a/src/mathed/math_parboxinset.h b/src/mathed/math_parboxinset.h
new file mode 100644 (file)
index 0000000..4b03a91
--- /dev/null
@@ -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
index 913a66a309ad512d3931fdbb1bfbae9cdaf68eb1..c26e6b6d8c36859fcb507ba65c1e25843cb00928 100644 (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);
 }
index af18e35f39c7d7b306542092b6ffa7576b201f15..9ebc37d227c9783b60d62067b09a28d0e5338667 100644 (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",
index 854ddffc9dc307baf5562e69d84db1da84bb7a08..a36e326dc75a38cfbb732d0bdc9bfc04f8d06d09 100644 (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) {
+       }
 }