On Sun, Oct 19, 2003 at 06:32:15PM +0100, John Levon spake thusly:
 
> On Sun, Oct 19, 2003 at 08:40:26PM +0300, Martin Vermeer wrote:
> 
> > Would it be possible at this point to force the *row* that a displayed
> > math inset is on, to be aligned centre? Then (1) the offset_ hack in
> > formula.C will no longer be needed, and (2) also the cursor will be
> > positioned correctly before of after the mathinset (a bug I haven't
> > yet mentioned).
> > 
> > Does this sound like a plan?
> 
> Sounds like exactly what we need to be doing.

Implemented this, and it works exactly as I expected. Even the empty
line problem has gone now, at least for display math. The cursor
behaves, and the sensitive area coincides with the visible inset.
Note also the alternative (and IMHO proper) fix for the
row-stretches-above-displayed-inset problem. This *should* work in 
Hebrew/Arabic also.

Attached; I propose to put this in now as it fixes bugs and makes
everything a little bit cleaner. Makes it easier to work on the
remaining problems.

- Martin

--
Martin Vermeer  [EMAIL PROTECTED]
Helsinki University of Technology 
Dept. of Surveying, Inst. of Geodesy
P.O. Box 1200, FIN-02015 HUT, Finland
:wq
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.463
diff -u -p -r1.463 text.C
--- text.C      17 Oct 2003 18:01:09 -0000      1.463
+++ text.C      20 Oct 2003 05:56:22 -0000
@@ -691,6 +691,25 @@ pos_type LyXText::rowBreakPoint(Paragrap
                        point = i;
                        break;
                }
+               InsetOld * in;
+               // Break before...      
+               if (i + 1 < last) {
+                       in = pit->isInset(i + 1) ? pit->getInset(i + 1) : 0;
+                       if (in) {
+                               if (in->display()) {
+                                       point = i;
+                                       break;
+                               }
+                       }
+                       // ...and after.
+                       in = pit->isInset(i) ? pit->getInset(i) : 0;
+                       if (in) {
+                               if (in->display()) {
+                                       point = i;
+                                       break;
+                               }
+                       }
+               }
 
                char const c = pit->getChar(i);
                if (i > endPosOfFontSpan) {
@@ -716,7 +735,7 @@ pos_type LyXText::rowBreakPoint(Paragrap
                x += thiswidth;
                chunkwidth += thiswidth;
 
-               InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0;
+               in = pit->isInset(i) ? pit->getInset(i) : 0;
 
                // break before a character that will fall off
                // the right of the row
@@ -1445,15 +1464,35 @@ void LyXText::prepareToPrint(ParagraphLi
                        align = LYX_ALIGN_LEFT;
                }
 
+               // Display-style insets should always be on a centred row
+               inset = pit->isInset(rit->pos()) ? pit->getInset(rit->pos()) : 0;
+               if (inset) {
+                       if (inset->display()) {
+                               align = LYX_ALIGN_CENTER;
+lyxerr << "centering display inset..." << endl;
+                       }
+               }
+               
                switch (align) {
            case LYX_ALIGN_BLOCK:
                {
                        int const ns = numberOfSeparators(*pit, *rit);
                        RowList::iterator next_row = boost::next(rit);
+                       bool disp_inset(false);
+                       if (next_row != pit->rows.end()) {
+                               inset = pit->isInset(next_row->pos()) ? 
+                                       pit->getInset(next_row->pos()) : 0;
+                               if (inset)
+                                       disp_inset = inset->display();
+                       }
+                       // If we have separators, this is not the last row of a
+                       // par, does not end in newline, and is not row above a
+                       // display inset... then stretch it
                        if (ns
                                && next_row != pit->rows.end()
                                && !pit->isNewline(next_row->pos() - 1)
-                               ) {
+                               && !disp_inset
+                          ) {
                                        fill_separator = w / ns;
                        } else if (is_rtl) {
                                x += w;
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.127
diff -u -p -r1.127 inset.h
--- insets/inset.h      15 Oct 2003 08:49:43 -0000      1.127
+++ insets/inset.h      20 Oct 2003 05:56:23 -0000
@@ -274,6 +274,8 @@ public:
        // is this equivalent to a space (which is BTW different from
        // a line separator)?
        virtual bool isSpace() const { return false; }
+       // should we have a non-filled line before this inset?
+       virtual bool display() const { return false; }
        // should we break lines after this inset?
        virtual bool isLineSeparator() const { return false; }
        // if this inset has paragraphs should they be output all as default
Index: insets/insetfloat.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloat.h,v
retrieving revision 1.54
diff -u -p -r1.54 insetfloat.h
--- insets/insetfloat.h 17 Oct 2003 18:01:12 -0000      1.54
+++ insets/insetfloat.h 20 Oct 2003 05:56:23 -0000
@@ -45,6 +45,8 @@ public:
        ///
        ~InsetFloat();
        ///
+       virtual bool display() const { return true; }
+       ///
        void write(Buffer const & buf, std::ostream & os) const;
        ///
        void read(Buffer const & buf, LyXLex & lex);
Index: insets/insetfootlike.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfootlike.h,v
retrieving revision 1.20
diff -u -p -r1.20 insetfootlike.h
--- insets/insetfootlike.h      28 Aug 2003 07:41:29 -0000      1.20
+++ insets/insetfootlike.h      20 Oct 2003 05:56:23 -0000
@@ -28,6 +28,8 @@ public:
        ///
        void write(Buffer const & buf, std::ostream & os) const;
        ///
+       bool display() const { return true; }
+       ///
        bool insetAllowed(InsetOld::Code) const;
        /** returns true if, when outputing LaTeX, font changes should
            be closed before generating this inset. This is needed for
Index: mathed/formula.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v
retrieving revision 1.302
diff -u -p -r1.302 formula.C
--- mathed/formula.C    14 Oct 2003 21:30:22 -0000      1.302
+++ mathed/formula.C    20 Oct 2003 05:56:23 -0000
@@ -277,8 +277,9 @@ void InsetFormula::metrics(MetricsInfo &
        }
 
        if (display()) {
-               offset_ = (m.base.textwidth - dim.wid) / 2;
-               dim.wid = m.base.textwidth;
+               //offset_ = (m.base.textwidth - dim.wid) / 2;
+               //dim.wid = m.base.textwidth;
+               offset_ = 0;
        } else {
                offset_ = 0;
        }

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to