This is "InsetUnificiation" for draw()  

[And incidentally the second phase of the two-phase drawing,
and 80 lines of removed code....]

There should be no user visible change, but I am not 100% sure because
of the 'float x' -> 'int x' change.

Known drawback: For Insets that do not properly implement the first phase
(i.e. almost everything in src/insets) part of the metrics computation (the
width) is done twice per redraw.  But that's purely transitional and only
there to keep the patch small.

If there is nothing fundamentally wrong with it I'd like to apply that
as-is and fix code cosmetics if there are any later.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.93
diff -u -p -r1.93 inset.h
--- insets/inset.h      28 May 2003 06:47:15 -0000      1.93
+++ insets/inset.h      28 May 2003 15:41:16 -0000
@@ -169,8 +169,6 @@ public:
        int descent(BufferView *, LyXFont const &) const;
        ///
        int width(BufferView *, LyXFont const &) const;
-       ///
-       virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) 
const = 0;
        /// update the inset representation
        virtual void update(BufferView *, bool = false)
                {}
Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.3
diff -u -p -r1.3 insetbase.h
--- insets/insetbase.h  10 Mar 2003 13:33:39 -0000      1.3
+++ insets/insetbase.h  28 May 2003 15:41:16 -0000
@@ -16,6 +16,8 @@
 
 class BufferView;
 class FuncRequest;
+class MetricsInfo;
+class PainterInfo;
 
 /** Dispatch result codes
                DISPATCHED          = the inset catched the action
@@ -62,6 +64,8 @@ public:
 
        /// small wrapper for the time being
        virtual dispatch_result localDispatch(FuncRequest const & cmd);
+       ///
+       virtual void draw(PainterInfo & pi, int x, int y) const = 0;
 
        ///
        virtual ~InsetBase() {}
Index: insets/insetbutton.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbutton.C,v
retrieving revision 1.29
diff -u -p -r1.29 insetbutton.C
--- insets/insetbutton.C        27 May 2003 13:54:58 -0000      1.29
+++ insets/insetbutton.C        28 May 2003 15:41:16 -0000
@@ -21,6 +21,7 @@
 #include "frontends/Painter.h"
 #include "support/LAssert.h"
 #include "lyxfont.h"
+#include "metricsinfo.h"
 #include "frontends/font_metrics.h"
 
 using std::ostream;
@@ -46,27 +47,23 @@ void InsetButton::dimension(BufferView *
 }
 
 
-void InsetButton::draw(BufferView * bv, LyXFont const &,
-                       int baseline, float & x) const
+void InsetButton::draw(PainterInfo & pi, int x, int y) const
 {
-       lyx::Assert(bv);
-       cache(bv);
+       lyx::Assert(pi.base.bv);
+       cache(pi.base.bv);
 
-       Painter & pain = bv->painter();
        // Draw it as a box with the LaTeX text
        LyXFont font(LyXFont::ALL_SANE);
        font.setColor(LColor::command).decSize();
 
-       string const s = getScreenLabel(bv->buffer());
+       string const s = getScreenLabel(pi.base.bv->buffer());
 
        if (editable()) {
-               pain.buttonText(int(x) + 2, baseline, s, font);
+               pi.pain.buttonText(x + 2, y, s, font);
        } else {
-               pain.rectText(int(x) + 2, baseline, s, font,
+               pi.pain.rectText(x + 2, y, s, font,
                              LColor::commandbg, LColor::commandframe);
        }
-
-       x += width(bv, font);
 }
 
 
Index: insets/insetbutton.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbutton.h,v
retrieving revision 1.18
diff -u -p -r1.18 insetbutton.h
--- insets/insetbutton.h        23 May 2003 15:30:47 -0000      1.18
+++ insets/insetbutton.h        28 May 2003 15:41:16 -0000
@@ -25,7 +25,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        dispatch_result localDispatch(FuncRequest const & cmd);
 
Index: insets/insetcaption.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcaption.C,v
retrieving revision 1.30
diff -u -p -r1.30 insetcaption.C
--- insets/insetcaption.C       23 May 2003 08:59:43 -0000      1.30
+++ insets/insetcaption.C       28 May 2003 15:41:16 -0000
@@ -21,6 +21,7 @@
 #include "debug.h"
 #include "gettext.h"
 #include "Lsstream.h"
+#include "metricsinfo.h"
 #include "support/lstrings.h"
 #include "support/LAssert.h"
 #include "support/BoostFormat.h"
@@ -66,8 +67,7 @@ string const InsetCaption::editMessage()
 }
 
 
-void InsetCaption::draw(BufferView * bv, LyXFont const & f,
-                       int baseline, float & x) const
+void InsetCaption::draw(PainterInfo & pi, int x, int y) const
 {
        // We must draw the label, we should get the label string
        // from the enclosing float inset.
@@ -88,7 +88,7 @@ void InsetCaption::draw(BufferView * bv,
                lyx::Assert(0);
 
        FloatList const & floats =
-               bv->buffer()->params.getLyXTextClass().floats();
+               pi.base.bv->buffer()->params.getLyXTextClass().floats();
        string const fl = i2 ? floats.getType(type).name() : N_("Float");
 
        // Discover the number...
@@ -96,12 +96,9 @@ void InsetCaption::draw(BufferView * bv,
 
        // Generate the label
        string const label = bformat("%1$s %2$s:", _(fl), num);
-       Painter & pain = bv->painter();
-       int const w = font_metrics::width(label, f);
-       pain.text(int(x), baseline, label, f);
-       x += w;
-
-       InsetText::draw(bv, f, baseline, x);
+       int const w = font_metrics::width(label, pi.base.font);
+       pi.pain.text(x, y, label, pi.base.font);
+       InsetText::draw(pi, x + w, y);
 }
 
 
Index: insets/insetcaption.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcaption.h,v
retrieving revision 1.15
diff -u -p -r1.15 insetcaption.h
--- insets/insetcaption.h       23 May 2003 08:59:43 -0000      1.15
+++ insets/insetcaption.h       28 May 2003 15:41:16 -0000
@@ -34,8 +34,7 @@ public:
        ///
        virtual string const editMessage() const;
        ///
-       virtual void draw(BufferView * bv, LyXFont const & f,
-                         int baseline, float & x) const;
+       virtual void draw(PainterInfo & pi, int x, int y) const;
        ///
        virtual int latex(Buffer const * buf, std::ostream & os,
                          LatexRunParams const &) const;
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.144
diff -u -p -r1.144 insetcollapsable.C
--- insets/insetcollapsable.C   27 May 2003 13:54:58 -0000      1.144
+++ insets/insetcollapsable.C   28 May 2003 15:41:16 -0000
@@ -25,6 +25,7 @@
 #include "WordLangTuple.h"
 #include "funcrequest.h"
 #include "buffer.h"
+#include "metricsinfo.h"
 
 #include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
@@ -151,22 +152,16 @@ void InsetCollapsable::dimension(BufferV
 }
 
 
-void InsetCollapsable::draw_collapsed(Painter & pain,
-                                     int baseline, float & x) const
+void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const
 {
-       pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
-                       baseline, label, labelfont);
-       Dimension dim;
-       dimension_collapsed(dim);
-       x += dim.wid;
+       pi.pain.buttonText(x + TEXT_TO_INSET_OFFSET, y, label, labelfont);
 }
 
 
-void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
-                            int baseline, float & x, bool inlined) const
+void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const
 {
-       lyx::Assert(bv);
-       cache(bv);
+       lyx::Assert(pi.base.bv);
+       cache(pi.base.bv);
 
        if (nodraw())
                return;
@@ -174,45 +169,41 @@ void InsetCollapsable::draw(BufferView *
        Dimension dim_collapsed;
        dimension_collapsed(dim_collapsed);
 
-       Painter & pain = bv->painter();
-
+       int const aa    = ascent(pi.base.bv, pi.base.font);
        button_length   = dim_collapsed.width();
-       button_top_y    = -ascent(bv, f);
-       button_bottom_y = -ascent(bv, f) + dim_collapsed.height();
+       button_top_y    = -aa;
+       button_bottom_y = -aa + dim_collapsed.height();
 
        if (!isOpen()) {
-               draw_collapsed(pain, baseline, x);
+               draw_collapsed(pi, x, y);
                return;
        }
 
-       float old_x = x;
+       int old_x = x;
 
        if (!owner())
                x += scroll();
 
-       top_x = int(x);
-       top_baseline = baseline;
+       top_x = x;
+       top_baseline = y;
 
-       int const bl = baseline - ascent(bv, f) + dim_collapsed.ascent();
+       int const bl = y - aa + dim_collapsed.ascent();
 
        if (inlined) {
-               inset.draw(bv, f, baseline, x);
+               inset.draw(pi, x, y);
        } else {
-               draw_collapsed(pain, bl, old_x);
-               int const yy = bl + dim_collapsed.descent() + inset.ascent(bv, f);
-               inset.draw(bv, f, yy, x);
-               // contained inset may be shorter than the button
-               if (x < top_x + button_length + TEXT_TO_INSET_OFFSET)
-                       x = top_x + button_length + TEXT_TO_INSET_OFFSET;
+               draw_collapsed(pi, old_x, bl);
+               int const yy = bl + dim_collapsed.descent()
+                       + inset.ascent(pi.base.bv, pi.base.font);
+               inset.draw(pi, x, yy);
        }
 }
 
 
-void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
-                           int baseline, float & x) const
+void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
        // by default, we are not inlined-drawing
-       draw(bv, f, baseline, x, false);
+       draw(pi, x, y, false);
 }
 
 
Index: insets/insetcollapsable.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.106
diff -u -p -r1.106 insetcollapsable.h
--- insets/insetcollapsable.h   26 May 2003 09:13:53 -0000      1.106
+++ insets/insetcollapsable.h   28 May 2003 15:41:17 -0000
@@ -49,10 +49,9 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, const LyXFont &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        /// draw, either inlined (no button) or collapsed/open
-       void draw(BufferView * bv, LyXFont const & f,
-                 int baseline, float & x, bool inlined) const;
+       void draw(PainterInfo & pi, int x, int y, bool inlined) const;
        ///
        void update(BufferView *, bool = false);
        ///
@@ -183,7 +182,7 @@ protected:
        ///
        int height_collapsed() const;
        ///
-       void draw_collapsed(Painter & pain, int, float &) const;
+       void draw_collapsed(PainterInfo & pi, int x, int y) const;
        ///
        int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
 
Index: insets/inseterror.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inseterror.C,v
retrieving revision 1.57
diff -u -p -r1.57 inseterror.C
--- insets/inseterror.C 27 May 2003 13:54:58 -0000      1.57
+++ insets/inseterror.C 28 May 2003 15:41:17 -0000
@@ -17,6 +17,7 @@
 #include "funcrequest.h"
 #include "gettext.h"
 #include "lyxfont.h"
+#include "metricsinfo.h"
 
 #include "frontends/Dialogs.h"
 #include "frontends/font_metrics.h"
@@ -71,30 +72,24 @@ void InsetError::dimension(BufferView *,
 }
 
 
-void InsetError::draw(BufferView * bv, LyXFont const & font,
-                     int baseline, float & x) const
+void InsetError::draw(PainterInfo & pi, int x, int y) const
 {
-       lyx::Assert(bv);
-       cache(bv);
+       lyx::Assert(pi.base.bv);
+       cache(pi.base.bv);
 
-       Painter & pain = bv->painter();
        LyXFont efont;
-       efont.setSize(font.size()).decSize();
+       efont.setSize(pi.base.font.size()).decSize();
        efont.setColor(LColor::error);
 
        // Draw as "Error" in a framed box
        x += 1;
-       pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
-                         width(bv, font) - 2,
-                         ascent(bv, font) + descent(bv, font) - 2,
-                          LColor::insetbg);
-       pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
-                      width(bv, font) - 2,
-                      ascent(bv, font) + descent(bv, font) - 2,
-                      LColor::error);
-       pain.text(int(x + 2), baseline, _("Error"), efont);
-
-       x +=  width(bv, font) - 1;
+       Dimension dim;
+       dimension(pi.base.bv, pi.base.font, dim);
+       pi.pain.fillRectangle(x, y - dim.asc + 1,
+             dim.wid - 2, dim.asc + dim.des - 2, LColor::insetbg);
+       pi.pain.rectangle(x, y - dim.asc + 1,
+             dim.wid - 2, dim.asc + dim.des - 2, LColor::error);
+       pi.pain.text(x + 2, y, _("Error"), efont);
 }
 
 
Index: insets/inseterror.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inseterror.h,v
retrieving revision 1.57
diff -u -p -r1.57 inseterror.h
--- insets/inseterror.h 26 May 2003 09:13:53 -0000      1.57
+++ insets/inseterror.h 28 May 2003 15:41:17 -0000
@@ -35,7 +35,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        void write(Buffer const *, std::ostream &) const {}
        ///
Index: insets/insetert.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v
retrieving revision 1.125
diff -u -p -r1.125 insetert.C
--- insets/insetert.C   26 May 2003 09:13:53 -0000      1.125
+++ insets/insetert.C   28 May 2003 15:41:17 -0000
@@ -575,10 +575,9 @@ void InsetERT::dimension(BufferView * bv
 }
 
 
-void InsetERT::draw(BufferView * bv, LyXFont const & f,
-                   int baseline, float & x) const
+void InsetERT::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCollapsable::draw(bv, f, baseline, x, inlined());
+       InsetCollapsable::draw(pi, x, y, inlined());
 }
 
 
Index: insets/insetert.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.h,v
retrieving revision 1.71
diff -u -p -r1.71 insetert.h
--- insets/insetert.h   26 May 2003 09:13:53 -0000      1.71
+++ insets/insetert.h   28 May 2003 15:41:17 -0000
@@ -105,7 +105,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, const LyXFont &, int , float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        /// set the status of the inset
        void status(BufferView *, ERTStatus const st) const;
        ///
Index: insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.175
diff -u -p -r1.175 insetgraphics.C
--- insets/insetgraphics.C      27 May 2003 13:54:58 -0000      1.175
+++ insets/insetgraphics.C      28 May 2003 15:41:17 -0000
@@ -73,7 +73,7 @@ TODO
 #include "Lsstream.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
-#include "Lsstream.h"
+#include "metricsinfo.h"
 
 #include "frontends/lyx_gui.h"
 #include "frontends/Alert.h"
@@ -341,9 +341,9 @@ BufferView * InsetGraphics::view() const
 }
 
 
-void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
-                        int baseline, float & x) const
+void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
+       BufferView * bv = pi.base.bv;
        // MakeAbsPath returns params().filename unchanged if it absolute
        // already.
        string const file_with_path =
@@ -359,22 +359,18 @@ void InsetGraphics::draw(BufferView * bv
        cache_->view = bv->owner()->view();
        int oasc = cache_->old_ascent;
 
-       int ldescent = descent(bv, font);
-       int lascent  = ascent(bv, font);
-       int lwidth   = width(bv, font);
+       Dimension dim;
+       dimension(bv, pi.base.font, dim);
 
        // we may have changed while someone other was drawing us so better
        // to not draw anything as we surely call to redraw ourself soon.
        // This is not a nice thing to do and should be fixed properly somehow.
        // But I still don't know the best way to go. So let's do this like this
        // for now (Jug 20020311)
-       if (lascent != oasc)
+       if (dim.asc != oasc)
                return;
 
        // Make sure now that x is updated upon exit from this routine
-       int old_x = int(x);
-       x += lwidth;
-
        grfx::Params const & gparams = params().as_grfxParams();
 
        if (gparams.display != grfx::NoDisplay &&
@@ -386,26 +382,25 @@ void InsetGraphics::draw(BufferView * bv
 
        // This will draw the graphics. If the graphics has not been loaded yet,
        // we draw just a rectangle.
-       Painter & paint = bv->painter();
 
        if (imageIsDrawable()) {
-               paint.image(old_x + TEXT_TO_INSET_OFFSET, baseline - lascent,
-                           lwidth - 2 * TEXT_TO_INSET_OFFSET, lascent + ldescent,
+               pi.pain.image(x + TEXT_TO_INSET_OFFSET, y - dim.asc,
+                           dim.wid - 2 * TEXT_TO_INSET_OFFSET, dim.asc + dim.des,
                            *cache_->loader.image());
 
        } else {
 
-               paint.rectangle(old_x + TEXT_TO_INSET_OFFSET, baseline - lascent,
-                               lwidth - 2 * TEXT_TO_INSET_OFFSET, lascent + ldescent);
+               pi.pain.rectangle(x + TEXT_TO_INSET_OFFSET, y - dim.asc,
+                               dim.wid - 2 * TEXT_TO_INSET_OFFSET, dim.asc + dim.des);
 
                // Print the file name.
-               LyXFont msgFont(font);
+               LyXFont msgFont = pi.base.font;
                msgFont.setFamily(LyXFont::SANS_FAMILY);
                string const justname = OnlyFilename (params().filename);
                if (!justname.empty()) {
                        msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-                       paint.text(old_x + TEXT_TO_INSET_OFFSET + 6,
-                                  baseline - font_metrics::maxAscent(msgFont) - 4,
+                       pi.pain.text(x + TEXT_TO_INSET_OFFSET + 6,
+                                  y - font_metrics::maxAscent(msgFont) - 4,
                                   justname, msgFont);
                }
 
@@ -413,7 +408,7 @@ void InsetGraphics::draw(BufferView * bv
                string const msg = statusMessage();
                if (!msg.empty()) {
                        msgFont.setSize(LyXFont::SIZE_TINY);
-                       paint.text(old_x + TEXT_TO_INSET_OFFSET + 6, baseline - 4, 
msg, msgFont);
+                       pi.pain.text(x + TEXT_TO_INSET_OFFSET + 6, y - 4, msg, 
msgFont);
                }
        }
 }
Index: insets/insetgraphics.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.h,v
retrieving revision 1.67
diff -u -p -r1.67 insetgraphics.h
--- insets/insetgraphics.h      26 May 2003 09:13:53 -0000      1.67
+++ insets/insetgraphics.h      28 May 2003 15:41:17 -0000
@@ -39,7 +39,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        EDITABLE editable() const;
        ///
Index: insets/insetinclude.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.C,v
retrieving revision 1.117
diff -u -p -r1.117 insetinclude.C
--- insets/insetinclude.C       26 May 2003 09:13:53 -0000      1.117
+++ insets/insetinclude.C       28 May 2003 15:41:17 -0000
@@ -22,7 +22,8 @@
 #include "Lsstream.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
-#include "Lsstream.h"
+#include "metricsinfo.h"
+#include "dimension.h"
 
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
@@ -532,28 +533,22 @@ int InsetInclude::width(BufferView * bv,
 }
 
 
-void InsetInclude::draw(BufferView * bv, LyXFont const & font, int y,
-                       float & xx) const
+void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
-       cache(bv);
+       cache(pi.base.bv);
        if (!preview_->previewReady()) {
-               InsetButton::draw(bv, font, y, xx);
+               InsetButton::draw(pi, x, y);
                return;
        }
 
        if (!preview_->monitoring())
                preview_->startMonitoring();
 
-       int const x = int(xx);
-       int const w = width(bv, font);
-       int const d = descent(bv, font);
-       int const a = ascent(bv, font);
-       int const h = a + d;
+       Dimension dim;
+       dimension(pi.base.bv, pi.base.font, dim);
 
-       bv->painter().image(x, y - a, w, h,
+       pi.pain.image(x, y - dim.asc, dim.wid, dim.height(),
                            *(preview_->pimage()->image()));
-
-       xx += w;
 }
 
 
Index: insets/insetinclude.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.h,v
retrieving revision 1.65
diff -u -p -r1.65 insetinclude.h
--- insets/insetinclude.h       26 May 2003 09:13:53 -0000      1.65
+++ insets/insetinclude.h       28 May 2003 15:41:17 -0000
@@ -66,7 +66,7 @@ public:
        ///
        int width(BufferView *, LyXFont const &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
 
        /// get the parameters
        Params const & params(void) const;
Index: insets/insetlatexaccent.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetlatexaccent.C,v
retrieving revision 1.68
diff -u -p -r1.68 insetlatexaccent.C
--- insets/insetlatexaccent.C   27 May 2003 13:54:59 -0000      1.68
+++ insets/insetlatexaccent.C   28 May 2003 15:41:17 -0000
@@ -21,6 +21,7 @@
 #include "frontends/font_metrics.h"
 #include "language.h"
 #include "lyxlex.h"
+#include "metricsinfo.h"
 
 using std::ostream;
 using std::endl;
@@ -306,9 +307,7 @@ int InsetLatexAccent::rbearing(LyXFont c
 }
 
 
-bool InsetLatexAccent::displayISO8859_9(BufferView * bv, LyXFont const & font,
-                                       int baseline,
-                                       float & x) const
+bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const
 {
        unsigned char tmpic = ic;
 
@@ -339,9 +338,7 @@ bool InsetLatexAccent::displayISO8859_9(
        default:         return false;
        }
        if (tmpic != ic) {
-               char ch = char(tmpic);
-               bv->painter().text(int(x), baseline, ch, font);
-               x += width(bv, font);
+               pi.pain.text(x, y, char(tmpic), pi.base.font);
                return true;
        }
        else
@@ -349,13 +346,10 @@ bool InsetLatexAccent::displayISO8859_9(
 }
 
 
-void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0,
-                           int baseline, float & x) const
+void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const
 {
-       Painter & pain = bv->painter();
-
        if (lyxrc.font_norm_type == LyXRC::ISO_8859_9)
-               if (displayISO8859_9(bv, font0, baseline, x))
+               if (displayISO8859_9(pi, x, baseline))
                        return;
 
        /* draw it! */
@@ -363,27 +357,28 @@ void InsetLatexAccent::draw(BufferView *
        // overhaul. Different ways of drawing (what metrics to use)
        // should also be considered.
 
-       LyXFont font(font0);
+       BufferView * bv = pi.base.bv;
+       LyXFont font = pi.base.font;
        if (lyxrc.font_norm_type == LyXRC::ISO_10646_1)
                font.setLanguage(english_language);
 
+       Dimension dim;
+       dimension(bv, font, dim);
+
        if (candisp) {
-               int asc = ascent(bv, font);
-               int desc = descent(bv, font);
-               int wid = width(bv, font);
                float x2 = x + (rbearing(font) - lbearing(font)) / 2.0;
                float hg;
                int y;
                if (plusasc) {
                        // mark at the top
                        hg = font_metrics::maxDescent(font);
-                       y = baseline - asc;
+                       y = baseline - dim.asc;
 
                        if (font.shape() == LyXFont::ITALIC_SHAPE)
                                x2 += (4.0 * hg) / 5.0; // italic
                } else {
                        // at the bottom
-                       hg = desc;
+                       hg = dim.des;
                        y = baseline;
                }
 
@@ -391,18 +386,18 @@ void InsetLatexAccent::draw(BufferView *
 
                // display with proper accent mark
                // first the letter
-               pain.text(int(x), baseline, ic, font);
+               pi.pain.text(x, baseline, ic, font);
 
                if (remdot) {
                        int tmpvar = baseline - font_metrics::ascent('i', font);
-                       float tmpx = 0;
+                       int tmpx = 0;
                        if (font.shape() == LyXFont::ITALIC_SHAPE)
-                               tmpx += (8.0 * hg) / 10.0; // italic
+                               tmpx += int(0.8 * hg); // italic
                        lyxerr[Debug::KEY] << "Removing dot." << endl;
                        // remove the dot first
-                       pain.fillRectangle(int(x + tmpx), tmpvar, wid,
-                                          font_metrics::ascent('i', font) -
-                                          font_metrics::ascent('x', font) - 1,
+                       pi.pain.fillRectangle(x + tmpx, tmpvar, dim.wid,
+                                          font_metrics::ascent('i', pi.base.font) -
+                                          font_metrics::ascent('x', pi.base.font) - 1,
                                           backgroundColor());
                        // the five lines below is a simple hack to
                        // make the display of accent 'i' and 'j'
@@ -410,7 +405,7 @@ void InsetLatexAccent::draw(BufferView *
                        // closer to the top of the dot-less 'i' or 'j'.
                        char tmpic = ic; // store the ic when we
                        ic = 'x';        // calculates the ascent of
-                       asc = ascent(bv, font); // the dot-less version (here: 'x')
+                       int asc = ascent(bv, font); // the dot-less version (here: 'x')
                        ic = tmpic;      // set the orig ic back
                        y = baseline - asc; // update to new y coord.
                }
@@ -418,48 +413,52 @@ void InsetLatexAccent::draw(BufferView *
                switch (modtype) {
                case ACUTE:     // acute 0xB4
                {
-                       pain.text(int(x2 - (font_metrics::rbearing(0xB4, font) - 
font_metrics::lbearing(0xB4, font)) / 2),
-                                 baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent(0xB4, font) - (font_metrics::ascent(0xB4, font) + 
font_metrics::descent(0xB4, font)) / 2,
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xB4, font)
+                                     - font_metrics::lbearing(0xB4, font)) / 2),
+                                 baseline - font_metrics::ascent(ic, font)
+                                                - font_metrics::descent(0xB4, font)
+                                                - (font_metrics::ascent(0xB4, font)
+                                                 + font_metrics::descent(0xB4, font)) 
/ 2,
                                  char(0xB4), font);
                        break;
                }
                case GRAVE:     // grave 0x60
                {
-                       pain.text(int(x2 - (font_metrics::rbearing(0x60, font) - 
font_metrics::lbearing(0x60, font)) / 2),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0x60, font) - 
font_metrics::lbearing(0x60, font)) / 2),
                                  int(baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent(0x60, font) - (font_metrics::ascent(0x60, font) + 
font_metrics::descent(0x60, font)) / 2.0),
                                  char(0x60), font);
                        break;
                }
                case MACRON:     // macron
                {
-                       pain.text(int(x2 - (font_metrics::rbearing(0xAF, font) - 
font_metrics::lbearing(0xAF, font)) / 2),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xAF, font) - 
font_metrics::lbearing(0xAF, font)) / 2),
                                  baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent(0xAF, font) - (font_metrics::ascent(0xAF, font) + 
font_metrics::descent(0xAF, font)),
                                  char(0xAF), font);
                        break;
                }
                case TILDE:     // tilde
                {
-                       pain.text(int(x2 - (font_metrics::rbearing('~', font) - 
font_metrics::lbearing('~', font)) / 2),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('~', font) - 
font_metrics::lbearing('~', font)) / 2),
                                  baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent('~', font) - (font_metrics::ascent('~', font) + 
font_metrics::descent('~', font)) / 2,
                                  '~', font);
                        break;
                }
                case UNDERBAR:     // underbar 0x5F
                {
-                       pain.text(int(x2 - (font_metrics::rbearing(0x5F, font) - 
font_metrics::lbearing(0x5F, font)) / 2), baseline,
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0x5F, font) - 
font_metrics::lbearing(0x5F, font)) / 2), baseline,
                                  char(0x5F), font);
                        break;
                }
                case CEDILLA:     // cedilla
                {
-                       pain.text(int(x2 - (font_metrics::rbearing(0xB8, font) - 
font_metrics::lbearing(0xB8, font)) / 2), baseline,
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xB8, font) - 
font_metrics::lbearing(0xB8, font)) / 2), baseline,
                                  char(0xB8), font);
 
                        break;
                }
                case UNDERDOT:     // underdot
                {
-                       pain.text(int(x2 - (font_metrics::rbearing('.', font) - 
font_metrics::lbearing('.', font)) / 2.0),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('.', font) - 
font_metrics::lbearing('.', font)) / 2.0),
                                  int(baseline + 3.0 / 2.0 * 
(font_metrics::ascent('.', font) + font_metrics::descent('.', font))),
                                  '.', font);
                        break;
@@ -467,7 +466,7 @@ void InsetLatexAccent::draw(BufferView *
 
                case DOT:    // dot
                {
-                       pain.text(int(x2 - (font_metrics::rbearing('.', font) - 
font_metrics::lbearing('.', font)) / 2.0),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('.', font) - 
font_metrics::lbearing('.', font)) / 2.0),
                                  baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent('.', font) - (font_metrics::ascent('.', font) + 
font_metrics::descent('.', font)) / 2,
                                  '.', font);
                        break;
@@ -477,20 +476,20 @@ void InsetLatexAccent::draw(BufferView *
                {
                        LyXFont tmpf(font);
                        tmpf.decSize().decSize();
-                       pain.text(int(x2 - (font_metrics::rbearing(0xB0, tmpf) - 
font_metrics::lbearing(0xB0, tmpf)) / 2.0),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0xB0, tmpf) - 
font_metrics::lbearing(0xB0, tmpf)) / 2.0),
                                  int(baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent(0xB0, tmpf) - (font_metrics::ascent(0xB0, tmpf) + 
font_metrics::descent(0xB0, tmpf)) / 3.0),
                                  char(0xB0), tmpf);
                        break;
                }
                case TIE:     // tie
                {
-                       pain.arc(int(x2 + hg35), int(y + hg / 2.0),
+                       pi.pain.arc(int(x2 + hg35), int(y + hg / 2.0),
                                 int(2 * hg), int(hg), 0, 360 * 32);
                        break;
                }
                case BREVE:     // breve
                {
-                       pain.arc(int(x2 - (hg / 2.0)), y,
+                       pi.pain.arc(int(x2 - (hg / 2.0)), y,
                                 int(hg), int(hg), 0, -360*32);
                        break;
                }
@@ -501,41 +500,41 @@ void InsetLatexAccent::draw(BufferView *
                        xp[0] = int(x2 - hg35); yp[0] = int(y + hg35);
                        xp[1] = int(x2);        yp[1] = int(y + hg);
                        xp[2] = int(x2 + hg35); yp[2] = int(y + hg35);
-                       pain.lines(xp, yp, 3);
+                       pi.pain.lines(xp, yp, 3);
                        break;
                }
                case SPECIAL_CARON:    // special caron
                {
                        switch (ic) {
-                       case 'L': wid = int(4.0 * wid / 5.0); break;
+                       case 'L': dim.wid = int(4.0 * dim.wid / 5.0); break;
                        case 't': y -= int(hg35 / 2.0); break;
                        }
                        int xp[3], yp[3];
-                       xp[0] = int(x + wid);
+                       xp[0] = int(x + dim.wid);
                        yp[0] = int(y + hg35 + hg);
 
-                       xp[1] = int(x + wid + (hg35 / 2.0));
+                       xp[1] = int(x + dim.wid + (hg35 / 2.0));
                        yp[1] = int(y + hg + (hg35 / 2.0));
 
-                       xp[2] = int(x + wid + (hg35 / 2.0));
+                       xp[2] = int(x + dim.wid + (hg35 / 2.0));
                        yp[2] = y + int(hg);
 
-                       pain.lines(xp, yp, 3);
+                       pi.pain.lines(xp, yp, 3);
                        break;
                }
                case HUNGARIAN_UMLAUT:    // hung. umlaut
                {
-                       pain.text(int(x2 - (font_metrics::rbearing('´', font) - 
font_metrics::lbearing('´', font))),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('´', font) - 
font_metrics::lbearing('´', font))),
                                  baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + 
font_metrics::descent('´', font)) / 2,
                                  '´', font);
-                       pain.text(int(x2),
+                       pi.pain.text(int(x2),
                                  baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + 
font_metrics::descent('´', font)) / 2,
                                  '´', font);
                        break;
                }
                case UMLAUT:    // umlaut
                {
-                       pain.text(int(x2 - (font_metrics::rbearing('¨', font) - 
font_metrics::lbearing('¨', font)) / 2),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing('¨', font) - 
font_metrics::lbearing('¨', font)) / 2),
                                  baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent('¨', font) - (font_metrics::ascent('¨', font) + 
font_metrics::descent('¨', font)) / 2,
                                  '¨', font);
                        break;
@@ -544,7 +543,7 @@ void InsetLatexAccent::draw(BufferView *
                {
                        LyXFont tmpf(font);
                        tmpf.decSize().decSize().decSize();
-                       pain.text(int(x2 - (font_metrics::rbearing(0x5E, tmpf) - 
font_metrics::lbearing(0x5E, tmpf)) / 2),
+                       pi.pain.text(int(x2 - (font_metrics::rbearing(0x5E, tmpf) - 
font_metrics::lbearing(0x5E, tmpf)) / 2),
                                  int(baseline - font_metrics::ascent(ic, font) - 
font_metrics::descent(0x5E, tmpf) - (font_metrics::ascent(0x5E, tmpf) + 
font_metrics::descent(0x5E, tmpf)) / 3.0),
                                  char(0x5E), tmpf);
                        break;
@@ -567,7 +566,7 @@ void InsetLatexAccent::draw(BufferView *
                        xp[3] = int(x2 + hg / 4.0);
                        yp[3] = y + int(hg);
 
-                       pain.lines(xp, yp, 4);
+                       pi.pain.lines(xp, yp, 4);
                        break;
                }
                case lSLASH:
@@ -578,10 +577,10 @@ void InsetLatexAccent::draw(BufferView *
                        xp[0] = int(x);
                        yp[0] = y + int(3.0 * hg);
 
-                       xp[1] = int(x + float(wid) * 0.75);
+                       xp[1] = int(x + float(dim.wid) * 0.75);
                        yp[1] = y + int(hg);
 
-                       pain.lines(xp, yp, 2);
+                       pi.pain.lines(xp, yp, 2);
                        break;
                }
                case DOT_LESS_I: // dotless-i
@@ -592,18 +591,13 @@ void InsetLatexAccent::draw(BufferView *
                }
                }
        } else {
-               pain.fillRectangle(int(x + 1),
-                                  baseline - ascent(bv, font) + 1,
-                                  width(bv, font) - 2,
-                                  ascent(bv, font)
-                                  + descent(bv, font) - 2,
-                                  backgroundColor());
-               pain.rectangle(int(x + 1), baseline - ascent(bv, font) + 1,
-                              width(bv, font) - 2,
-                              ascent(bv, font) + descent(bv, font) - 2);
-               pain.text(int(x + 2), baseline, contents, font);
+               pi.pain.fillRectangle(x + 1,
+                                  baseline - dim.asc + 1, dim.wid - 2,
+                                  dim.asc + dim.des - 2, backgroundColor());
+               pi.pain.rectangle(x + 1, baseline - dim.asc + 1,
+                              dim.wid - 2, dim.asc + dim.des - 2);
+               pi.pain.text(x + 2, baseline, contents, font);
        }
-       x +=  width(bv, font);
 }
 
 
Index: insets/insetlatexaccent.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetlatexaccent.h,v
retrieving revision 1.48
diff -u -p -r1.48 insetlatexaccent.h
--- insets/insetlatexaccent.h   26 May 2003 09:13:53 -0000      1.48
+++ insets/insetlatexaccent.h   28 May 2003 15:41:17 -0000
@@ -36,14 +36,13 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        int lbearing(LyXFont const & font) const;
        ///
        int rbearing(LyXFont const & font) const;
        ///
-       bool displayISO8859_9(BufferView *, LyXFont const & font,
-                             int baseline, float & x) const;
+       bool displayISO8859_9(PainterInfo & pi, int x, int y) const;
        ///
        void write(Buffer const *, std::ostream &) const;
        ///
Index: insets/insetnewline.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetnewline.C,v
retrieving revision 1.7
diff -u -p -r1.7 insetnewline.C
--- insets/insetnewline.C       27 May 2003 13:54:59 -0000      1.7
+++ insets/insetnewline.C       28 May 2003 15:41:17 -0000
@@ -17,6 +17,7 @@
 #include "dimension.h"
 #include "paragraph.h"
 #include "lyxtext.h"
+#include "metricsinfo.h"
 #include "support/LOstream.h"
 #include "frontends/Painter.h"
 #include "frontends/font_metrics.h"
@@ -75,18 +76,14 @@ int InsetNewline::docbook(Buffer const *
 }
 
 
-void InsetNewline::draw(BufferView * bv, LyXFont const & font,
-                       int baseline, float & x) const
+void InsetNewline::draw(PainterInfo & pi, int x, int y) const
 {
-       Painter & pain(bv->painter());
-
-       int const wid = font_metrics::width('n', font);
-       int const asc = font_metrics::maxAscent(font);
-       int const y = baseline;
+       int const wid = font_metrics::width('n', pi.base.font);
+       int const asc = font_metrics::maxAscent(pi.base.font);
 
        // hack, and highly dubious
        lyx::pos_type pos = parOwner()->getPositionOfInset(this);
-       bool const ltr_pos = (bv->text->bidi_level(pos) % 2 == 0);
+       bool const ltr_pos = (pi.base.bv->text->bidi_level(pos) % 2 == 0);
 
        int xp[3];
        int yp[3];
@@ -105,7 +102,7 @@ void InsetNewline::draw(BufferView * bv,
                xp[2] = int(x + wid * 0.625);
        }
 
-       pain.lines(xp, yp, 3, LColor::eolmarker);
+       pi.pain.lines(xp, yp, 3, LColor::eolmarker);
 
        yp[0] = int(y - 0.500 * asc * 0.75);
        yp[1] = int(y - 0.500 * asc * 0.75);
@@ -121,7 +118,5 @@ void InsetNewline::draw(BufferView * bv,
                xp[2] = int(x);
        }
 
-       pain.lines(xp, yp, 3, LColor::eolmarker);
-
-       x += wid;
+       pi.pain.lines(xp, yp, 3, LColor::eolmarker);
 }
Index: insets/insetnewline.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetnewline.h,v
retrieving revision 1.7
diff -u -p -r1.7 insetnewline.h
--- insets/insetnewline.h       26 May 2003 09:13:53 -0000      1.7
+++ insets/insetnewline.h       28 May 2003 15:41:17 -0000
@@ -33,8 +33,7 @@ public:
 
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
 
-       virtual void draw(BufferView *, LyXFont const &,
-                         int baseline, float & x) const;
+       virtual void draw(PainterInfo & pi, int x, int y) const;
 
        virtual int latex(Buffer const *, std::ostream &,
                          LatexRunParams const &) const;
Index: insets/insetquotes.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetquotes.C,v
retrieving revision 1.90
diff -u -p -r1.90 insetquotes.C
--- insets/insetquotes.C        27 May 2003 13:54:59 -0000      1.90
+++ insets/insetquotes.C        28 May 2003 15:41:17 -0000
@@ -23,6 +23,7 @@
 #include "lyxlex.h"
 #include "lyxrc.h"
 #include "paragraph.h"
+#include "metricsinfo.h"
 #include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
 #include "support/LAssert.h"
@@ -202,18 +203,17 @@ LyXFont const InsetQuotes::convertFont(L
 #endif
 
 
-void InsetQuotes::draw(BufferView * bv, LyXFont const & font,
-                      int baseline, float & x) const
+void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
 {
-       string const text = dispString(font.language());
+       string const text = dispString(pi.base.font.language());
 
        if (text.length() == 2 && text[0] == text[1]) {
-               bv->painter().text(int(x), baseline, text[0], font);
-               int x2 = int(x + font_metrics::width(',', font));
-               bv->painter().text(x2, baseline, text[0], font);
-       } else
-               bv->painter().text(int(x), baseline, text, font);
-       x += width(bv, font);
+               pi.pain.text(x, y, text[0], pi.base.font);
+               int const t = font_metrics::width(',', pi.base.font);
+               pi.pain.text(x + t, y, text[0], pi.base.font);
+       } else {
+               pi.pain.text(x, y, text, pi.base.font);
+       }
 }
 
 
Index: insets/insetquotes.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetquotes.h,v
retrieving revision 1.47
diff -u -p -r1.47 insetquotes.h
--- insets/insetquotes.h        26 May 2003 09:13:53 -0000      1.47
+++ insets/insetquotes.h        28 May 2003 15:41:17 -0000
@@ -75,7 +75,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
 #if 0
        ///
        LyXFont const convertFont(LyXFont const & font) const;
Index: insets/insetspace.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspace.C,v
retrieving revision 1.7
diff -u -p -r1.7 insetspace.C
--- insets/insetspace.C 28 May 2003 06:47:15 -0000      1.7
+++ insets/insetspace.C 28 May 2003 15:41:17 -0000
@@ -24,6 +24,7 @@
 #include "frontends/font_metrics.h"
 #include "lyxlex.h"
 #include "lyxfont.h"
+#include "metricsinfo.h"
 
 using std::ostream;
 using std::max;
@@ -73,31 +74,28 @@ void InsetSpace::dimension(BufferView *,
 }
 
 
-void InsetSpace::draw(BufferView * bv, LyXFont const & f,
-                           int baseline, float & x) const
+void InsetSpace::draw(PainterInfo & pi, int x, int y) const
 {
-       Painter & pain = bv->painter();
-       LyXFont font(f);
-
-       float w = width(bv, font);
-       int h = font_metrics::ascent('x', font);
+       int const w = width(pi.base.bv, pi.base.font);
+       int const h = font_metrics::ascent('x', pi.base.font);
        int xp[4], yp[4];
 
-       xp[0] = int(x); yp[0] = baseline - max(h / 4, 1);
+       xp[0] = x;
+       yp[0] = y - max(h / 4, 1);
        if (kind_ == NORMAL) {
-               xp[1] = int(x); yp[1] = baseline;
-               xp[2] = int(x + w); yp[2] = baseline;
+               xp[1] = x;     yp[1] = y;
+               xp[2] = x + w; yp[2] = y;
        } else {
-               xp[1] = int(x); yp[1] = baseline + max(h / 4, 1);
-               xp[2] = int(x + w); yp[2] = baseline + max(h / 4, 1);
+               xp[1] = x;     yp[1] = y + max(h / 4, 1);
+               xp[2] = x + w; yp[2] = y + max(h / 4, 1);
        }
-       xp[3] = int(x + w); yp[3] = baseline - max(h / 4, 1);
+       xp[3] = x + w;
+       yp[3] = y - max(h / 4, 1);
 
        if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN)
-               pain.lines(xp, yp, 4, LColor::latex);
+               pi.pain.lines(xp, yp, 4, LColor::latex);
        else
-               pain.lines(xp, yp, 4, LColor::special);
-       x += w;
+               pi.pain.lines(xp, yp, 4, LColor::special);
 }
 
 
Index: insets/insetspace.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspace.h,v
retrieving revision 1.6
diff -u -p -r1.6 insetspace.h
--- insets/insetspace.h 28 May 2003 06:47:15 -0000      1.6
+++ insets/insetspace.h 28 May 2003 15:41:17 -0000
@@ -56,7 +56,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        void write(Buffer const *, std::ostream &) const;
        /// Will not be used when lyxf3
Index: insets/insetspecialchar.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspecialchar.C,v
retrieving revision 1.67
diff -u -p -r1.67 insetspecialchar.C
--- insets/insetspecialchar.C   27 May 2003 13:54:59 -0000      1.67
+++ insets/insetspecialchar.C   28 May 2003 15:41:17 -0000
@@ -22,6 +22,7 @@
 #include "frontends/font_metrics.h"
 #include "lyxlex.h"
 #include "lyxfont.h"
+#include "metricsinfo.h"
 
 using std::ostream;
 using std::max;
@@ -58,56 +59,49 @@ void InsetSpecialChar::dimension(BufferV
 }
 
 
-void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f,
-                           int baseline, float & x) const
+void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
 {
-       Painter & pain = bv->painter();
-       LyXFont font(f);
+       LyXFont font = pi.base.font;
 
        switch (kind_) {
        case HYPHENATION:
        {
                font.setColor(LColor::special);
-               pain.text(int(x), baseline, '-', font);
-               x += width(bv, font);
+               pi.pain.text(x, y, '-', font);
                break;
        }
        case LIGATURE_BREAK:
        {
                font.setColor(LColor::special);
-               pain.text(int(x), baseline, '|', font);
-               x += width(bv, font);
+               pi.pain.text(x, y, '|', font);
                break;
        }
        case END_OF_SENTENCE:
        {
                font.setColor(LColor::special);
-               pain.text(int(x), baseline, '.', font);
-               x += width(bv, font);
+               pi.pain.text(x, y, '.', font);
                break;
        }
        case LDOTS:
        {
                font.setColor(LColor::special);
-               pain.text(int(x), baseline, ". . .", font);
-               x += width(bv, font);
+               pi.pain.text(x, y, ". . .", font);
                break;
        }
        case MENU_SEPARATOR:
        {
                // A triangle the width and height of an 'x'
                int w = font_metrics::width('x', font);
-               int ox = font_metrics::width(' ', font) + int(x);
+               int ox = font_metrics::width(' ', font) + x;
                int h = font_metrics::ascent('x', font);
                int xp[4], yp[4];
 
-               xp[0] = ox;     yp[0] = baseline;
-               xp[1] = ox;     yp[1] = baseline - h;
-               xp[2] = ox + w; yp[2] = baseline - h/2;
-               xp[3] = ox;     yp[3] = baseline;
+               xp[0] = ox;     yp[0] = y;
+               xp[1] = ox;     yp[1] = y - h;
+               xp[2] = ox + w; yp[2] = y - h/2;
+               xp[3] = ox;     yp[3] = y;
 
-               pain.lines(xp, yp, 4, LColor::special);
-               x += width(bv, font);
+               pi.pain.lines(xp, yp, 4, LColor::special);
                break;
        }
        }
Index: insets/insetspecialchar.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetspecialchar.h,v
retrieving revision 1.50
diff -u -p -r1.50 insetspecialchar.h
--- insets/insetspecialchar.h   26 May 2003 09:13:53 -0000      1.50
+++ insets/insetspecialchar.h   28 May 2003 15:41:17 -0000
@@ -48,7 +48,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        void write(Buffer const *, std::ostream &) const;
        /// Will not be used when lyxf3
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.280
diff -u -p -r1.280 insettabular.C
--- insets/insettabular.C       27 May 2003 17:29:02 -0000      1.280
+++ insets/insettabular.C       28 May 2003 15:41:17 -0000
@@ -31,7 +31,7 @@
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
 #include "WordLangTuple.h"
-#include "Lsstream.h"
+#include "metricsinfo.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -278,40 +278,39 @@ void InsetTabular::dimension(BufferView 
 }
 
 
-void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
-                       float & x) const
+void InsetTabular::draw(PainterInfo & pi, int x, int y) const
 {
        if (nodraw()) {
                need_update = FULL;
                return;
        }
 
-       Painter & pain = bv->painter();
+       BufferView * bv = pi.base.bv;
        int i;
        int j;
        int nx;
 
 #if 0
-       UpdatableInset::draw(bv, font, baseline, x);
+       UpdatableInset::draw(pi, x, y);
 #else
        if (!owner())
-               x += static_cast<float>(scroll());
+               x += scroll();
 #endif
 
-       top_x = int(x);
-       top_baseline = baseline;
+       top_x = x;
+       top_baseline = y;
        x += ADD_TO_TABULAR_WIDTH;
 
        int cell = 0;
-       float cx;
+       int cx;
        first_visible_cell = -1;
        for (i = 0; i < tabular->rows(); ++i) {
-               nx = int(x);
+               nx = x;
                cell = tabular->GetCellNumber(i, 0);
-               if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
-                       (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
+               if (!((y + tabular->GetDescentOfRow(i)) > 0) &&
+                       (y - tabular->GetAscentOfRow(i)) < pi.pain.paperHeight())
                {
-               baseline += tabular->GetDescentOfRow(i) +
+               y += tabular->GetDescentOfRow(i) +
                                tabular->GetAscentOfRow(i + 1) +
                                tabular->GetAdditionalHeight(i + 1);
                        continue;
@@ -325,32 +324,30 @@ void InsetTabular::draw(BufferView * bv,
                        if (first_visible_cell < 0)
                                first_visible_cell = cell;
                        if (hasSelection()) {
-                               drawCellSelection(pain, nx, baseline, i, j, cell);
+                               drawCellSelection(pi.pain, nx, y, i, j, cell);
                        }
 
-                       tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
-                       drawCellLines(pain, nx, baseline, i, cell);
+                       tabular->GetCellInset(cell)->draw(pi, cx, y);
+                       drawCellLines(pi.pain, nx, y, i, cell);
                        nx += tabular->GetWidthOfColumn(cell);
                        ++cell;
                }
 
                // avoiding drawing the rest of a long table is
                // a pretty big speedup
-               if (baseline > bv->workHeight())
+               if (y > bv->workHeight())
                        break;
 
-               baseline += tabular->GetDescentOfRow(i) +
+               y += tabular->GetDescentOfRow(i) +
                        tabular->GetAscentOfRow(i + 1) +
                        tabular->GetAdditionalHeight(i + 1);
        }
 
-       x -= ADD_TO_TABULAR_WIDTH;
-       x += width(bv, font);
        need_update = NONE;
 }
 
 
-void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
+void InsetTabular::drawCellLines(Painter & pain, int x, int y,
                                 int row, int cell) const
 {
        int x2 = x + tabular->GetWidthOfColumn(cell);
@@ -358,34 +355,34 @@ void InsetTabular::drawCellLines(Painter
 
        if (!tabular->topAlreadyDrawn(cell)) {
                on_off = !tabular->TopLine(cell);
-               pain.line(x, baseline - tabular->GetAscentOfRow(row),
-                         x2, baseline -  tabular->GetAscentOfRow(row),
+               pain.line(x, y - tabular->GetAscentOfRow(row),
+                         x2, y -  tabular->GetAscentOfRow(row),
                          on_off ? LColor::tabularonoffline : LColor::tabularline,
                          on_off ? Painter::line_onoffdash : Painter::line_solid);
        }
        on_off = !tabular->BottomLine(cell);
-       pain.line(x, baseline + tabular->GetDescentOfRow(row),
-                 x2, baseline + tabular->GetDescentOfRow(row),
+       pain.line(x, y + tabular->GetDescentOfRow(row),
+                 x2, y + tabular->GetDescentOfRow(row),
                  on_off ? LColor::tabularonoffline : LColor::tabularline,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
        if (!tabular->leftAlreadyDrawn(cell)) {
                on_off = !tabular->LeftLine(cell);
-               pain.line(x, baseline -  tabular->GetAscentOfRow(row),
-                         x, baseline +  tabular->GetDescentOfRow(row),
+               pain.line(x, y -  tabular->GetAscentOfRow(row),
+                         x, y +  tabular->GetDescentOfRow(row),
                          on_off ? LColor::tabularonoffline : LColor::tabularline,
                          on_off ? Painter::line_onoffdash : Painter::line_solid);
        }
        on_off = !tabular->RightLine(cell);
        pain.line(x2 - tabular->GetAdditionalWidth(cell),
-                 baseline -  tabular->GetAscentOfRow(row),
+                 y -  tabular->GetAscentOfRow(row),
                  x2 - tabular->GetAdditionalWidth(cell),
-                 baseline +  tabular->GetDescentOfRow(row),
+                 y +  tabular->GetDescentOfRow(row),
                  on_off ? LColor::tabularonoffline : LColor::tabularline,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
 }
 
 
-void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
+void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
                                     int row, int column, int cell) const
 {
        lyx::Assert(hasSelection());
@@ -406,7 +403,7 @@ void InsetTabular::drawCellSelection(Pai
        if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
                int w = tabular->GetWidthOfColumn(cell);
                int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
-               pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
+               pain.fillRectangle(x, y - tabular->GetAscentOfRow(row) + 1,
                                   w, h, LColor::selection);
        }
 }
Index: insets/insettabular.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v
retrieving revision 1.118
diff -u -p -r1.118 insettabular.h
--- insets/insettabular.h       26 May 2003 09:13:54 -0000      1.118
+++ insets/insettabular.h       28 May 2003 15:41:17 -0000
@@ -92,7 +92,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, const LyXFont &, int , float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        void update(BufferView *, bool = false);
        ///
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.399
diff -u -p -r1.399 insettext.C
--- insets/insettext.C  27 May 2003 22:41:04 -0000      1.399
+++ insets/insettext.C  28 May 2003 15:41:18 -0000
@@ -39,7 +39,7 @@
 #include "sgml.h"
 #include "rowpainter.h"
 #include "insetnewline.h"
-#include "Lsstream.h"
+#include "metricsinfo.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -368,38 +368,37 @@ int InsetText::textWidth(BufferView * bv
 }
 
 
-void InsetText::draw(BufferView * bv, LyXFont const & f,
-                    int baseline, float & x) const
+void InsetText::draw(PainterInfo & pi, int x, int baseline) const
 {
        if (nodraw())
                return;
 
        // update our idea of where we are. Clearly, we should
        // not have to know this information.
-       if (top_x != int(x))
-               top_x = int(x);
+       if (top_x != x)
+               top_x = x;
 
-       int const start_x = int(x);
+       int const start_x = x;
 
-       Painter & pain = bv->painter();
+       BufferView * bv = pi.base.bv;
+       Painter & pain = pi.pain;
 
        // call this method so that dim_ has the right value
-       dimension(bv, f, dim_);
+       dimension(bv, pi.base.font, dim_);
 
        // repaint the background if needed
        if (backgroundColor() != LColor::background)
                clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
 
        // no draw is necessary !!!
-       if ((drawFrame_ == LOCKED) && !locked && paragraphs.begin()->empty()) {
+       if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
                top_baseline = baseline;
-               x += width(bv, f);
                need_update = NONE;
                return;
        }
 
        if (!owner())
-               x += static_cast<float>(scroll());
+               x += scroll();
 
        top_baseline = baseline;
        top_y = baseline - dim_.asc;
Index: insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.163
diff -u -p -r1.163 insettext.h
--- insets/insettext.h  27 May 2003 17:29:03 -0000      1.163
+++ insets/insettext.h  28 May 2003 15:41:18 -0000
@@ -96,7 +96,7 @@ public:
        ///
        int textWidth(BufferView *, bool fordraw = false) const;
        ///
-       void draw(BufferView *, LyXFont const &, int , float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        void update(BufferView *, bool = false);
        ///
Index: insets/updatableinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.C,v
retrieving revision 1.11
diff -u -p -r1.11 updatableinset.C
--- insets/updatableinset.C     26 May 2003 09:13:55 -0000      1.11
+++ insets/updatableinset.C     28 May 2003 15:41:18 -0000
@@ -57,13 +57,11 @@ void UpdatableInset::fitInsetCursor(Buff
 {}
 
 
-void UpdatableInset::draw(BufferView *, LyXFont const &,
-                         int /* baseline */, float & x) const
+void UpdatableInset::draw(PainterInfo &, int, int) const
 {
-       x += float(scx);
        // ATTENTION: don't do the following here!!!
-       //    top_x = int(x);
-       //    top_baseline = baseline;
+       //    top_x = x;
+       //    top_baseline = y;
 }
 
 
Index: insets/updatableinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.h,v
retrieving revision 1.7
diff -u -p -r1.7 updatableinset.h
--- insets/updatableinset.h     26 May 2003 09:13:55 -0000      1.7
+++ insets/updatableinset.h     28 May 2003 15:41:18 -0000
@@ -68,8 +68,7 @@ public:
        ///
        virtual void insetUnlock(BufferView *);
        ///
-       virtual void draw(BufferView *, LyXFont const &,
-                         int baseline, float & x) const;
+       virtual void draw(PainterInfo & pi, int x, int y) const;
        ///
        virtual bool insertInset(BufferView *, Inset *) { return false; }
        ///
Index: mathed/formula.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v
retrieving revision 1.265
diff -u -p -r1.265 formula.C
--- mathed/formula.C    28 May 2003 13:22:33 -0000      1.265
+++ mathed/formula.C    28 May 2003 15:41:18 -0000
@@ -212,44 +212,42 @@ void InsetFormula::read(Buffer const *, 
 //}
 
 
-void InsetFormula::draw(BufferView * bv, LyXFont const & font,
-                       int y, float & xx) const
+void InsetFormula::draw(PainterInfo & pi, int x, int y) const
 {
-       cache(bv);
+       cache(pi.base.bv);
        // This initiates the loading of the preview, so should come
        // before the metrics are computed.
        bool const use_preview = preview_->previewReady();
 
-       int const x = int(xx);
-       int const w = width(bv, font);
-       int const d = descent(bv, font);
-       int const a = ascent(bv, font);
+       Dimension dim;
+       dimension(pi.base.bv, pi.base.font, dim);
+       int const w = dim.wid;
+       int const d = dim.des;
+       int const a = dim.asc;
        int const h = a + d;
 
-       PainterInfo pi(bv);
-
        if (use_preview) {
                pi.pain.image(x + 1, y - a, w, h,   // one pixel gap in front
                              *(preview_->pimage()->image()));
        } else {
-               pi.base.style = LM_ST_TEXT;
-               pi.base.font  = font;
-               pi.base.font.setColor(LColor::math);
+               PainterInfo p(pi.base.bv);
+               p.base.style = LM_ST_TEXT;
+               p.base.font  = pi.base.font;
+               p.base.font.setColor(LColor::math);
                if (lcolor.getX11Name(LColor::mathbg)
                            != lcolor.getX11Name(LColor::background))
-                       pi.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
+                       p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
 
                if (mathcursor &&
                                const_cast<InsetFormulaBase const 
*>(mathcursor->formula()) == this)
                {
                        mathcursor->drawSelection(pi);
-                       //pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
+                       //p.pain.rectangle(x, y - a, w, h, LColor::mathframe);
                }
 
-               par_->draw(pi, x, y);
+               par_->draw(p, x, y);
        }
 
-       xx += w;
        xo_ = x;
        yo_ = y;
 }
Index: mathed/formula.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.h,v
retrieving revision 1.85
diff -u -p -r1.85 formula.h
--- mathed/formula.h    26 May 2003 09:13:55 -0000      1.85
+++ mathed/formula.h    28 May 2003 15:41:18 -0000
@@ -37,7 +37,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
 
        ///
        void write(Buffer const *, std::ostream &) const;
Index: mathed/formulabase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.h,v
retrieving revision 1.67
diff -u -p -r1.67 formulabase.h
--- mathed/formulabase.h        28 May 2003 13:22:33 -0000      1.67
+++ mathed/formulabase.h        28 May 2003 15:41:18 -0000
@@ -31,10 +31,6 @@ public:
        InsetFormulaBase();
        ///
        Inset * clone(Buffer const &) const = 0;
-       ///
-       //Inset * clone(Buffer const &, bool same_id) const = 0;
-       ///
-       virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0;
        /// lowest x coordinate
        virtual int xlow() const;
        /// highest x coordinate
Index: mathed/formulamacro.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulamacro.C,v
retrieving revision 1.124
diff -u -p -r1.124 formulamacro.C
--- mathed/formulamacro.C       28 May 2003 13:22:33 -0000      1.124
+++ mathed/formulamacro.C       28 May 2003 15:41:18 -0000
@@ -171,20 +171,18 @@ Inset::Code InsetFormulaMacro::lyxCode()
 }
 
 
-void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
-                            int y, float & xx) const
+void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
 {
        // label
-       LyXFont font(f);
+       LyXFont font = p.base.font;
        font.setColor(LColor::math);
 
-       PainterInfo pi(bv);
+       PainterInfo pi(p.base.bv);
        pi.base.style = LM_ST_TEXT;
        pi.base.font  = font;
 
        Dimension dim;
-       dimension(bv, font, dim);
-       int const x = int(xx);
+       dimension(pi.base.bv, font, dim);
        int const a = y - dim.asc + 1;
        int const w = dim.wid - 2;
        int const h = dim.height() - 2;
@@ -200,8 +198,7 @@ void InsetFormulaMacro::draw(BufferView 
        pi.pain.text(x + 2, y, prefix(), font);
 
        // formula
-       par()->draw(pi, x + font_metrics::width(prefix(), f) + 5, y);
-       xx += w + 2;
+       par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
        xo_ = x;
        yo_ = y;
 }
Index: mathed/formulamacro.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulamacro.h,v
retrieving revision 1.63
diff -u -p -r1.63 formulamacro.h
--- mathed/formulamacro.h       26 May 2003 09:13:55 -0000      1.63
+++ mathed/formulamacro.h       28 May 2003 15:41:18 -0000
@@ -35,7 +35,7 @@ public:
        ///
        void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       void draw(BufferView *, LyXFont const &, int, float &) const;
+       void draw(PainterInfo & pi, int x, int y) const;
 
        ///
        void read(Buffer const *, LyXLex & lex);
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.17
diff -u -p -r1.17 rowpainter.C
--- rowpainter.C        22 May 2003 10:47:30 -0000      1.17
+++ rowpainter.C        28 May 2003 15:41:16 -0000
@@ -33,6 +33,7 @@
 #include "rowpainter.h"
 #include "lyxrc.h"
 #include "lyxrow_funcs.h"
+#include "metricsinfo.h"
 
 using std::max;
 using lyx::pos_type;
@@ -103,12 +104,14 @@ void RowPainter::paintInset(pos_type con
 
        lyx::Assert(inset);
 
-       LyXFont const & font = getFont(pos);
-
 #warning inset->update FIXME
        inset->update(perv(bv_), false);
 
-       inset->draw(perv(bv_), font, yo_ + row_->baseline(), x_);
+       PainterInfo pi(perv(bv_));
+       pi.base.font = getFont(pos);
+       int const w = inset->width(perv(bv_), pi.base.font);
+       inset->draw(pi, int(x_), yo_ + row_->baseline());
+       x_ += w;
 }
 
 

Reply via email to