On Tue, Nov 01, 2005 at 06:58:08PM +0100, Jean-Marc Lasgouttes wrote:
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> Martin> OK. Should we set all these values to 1000? Might unearth some
> Martin> problems we didn't even know about.
> 
> Why not an abstract virtual function or an assert?
> 
> JMarc

Here is the patch using abstract virtual functions. Seems to work, and
is undoubtedly more robust, in spite of being a lot more code.

- Martin

Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.59
diff -u -p -r1.59 insetbase.h
--- insets/insetbase.h  10 Sep 2005 06:51:54 -0000      1.59
+++ insets/insetbase.h  1 Nov 2005 19:44:36 -0000
@@ -380,12 +380,11 @@ public:
        /// mark the inset as erased or not
        virtual void markErased(bool erased);
                
-       /// pretty arbitrary
-       virtual int width() const { return 10; }
-       /// pretty arbitrary
-       virtual int ascent() const { return 10; }
-       /// pretty arbitrary
-       virtual int descent() const { return 10; }
+       virtual int width() const = 0;
+       ///
+       virtual int ascent() const = 0;
+       ///
+       virtual int descent() const = 0;
        ///
        int scroll() const { return 0; }
        ///
Index: mathed/./math_charinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_charinset.C,v
retrieving revision 1.71
diff -u -p -r1.71 math_charinset.C
--- mathed/./math_charinset.C   15 Jul 2005 08:51:34 -0000      1.71
+++ mathed/./math_charinset.C   1 Nov 2005 19:44:36 -0000
@@ -76,10 +76,10 @@ void MathCharInset::metrics(MetricsInfo 
        whichFont(font_, code_, mi);
        mathed_char_dim(font_, char_, dim_);
        if (isBinaryOp(char_, code_))
-               width_ += 2 * font_metrics::width(' ', font_);
+               dim_.wid += 2 * font_metrics::width(' ', font_);
        lyxerr << "MathCharInset::metrics: " << dim << endl;
 #endif
-       width_ = dim.wid;
+       dim_ = dim;
 }
 
 
Index: mathed/./math_charinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_charinset.h,v
retrieving revision 1.38
diff -u -p -r1.38 math_charinset.h
--- mathed/./math_charinset.h   14 Jul 2005 22:41:59 -0000      1.38
+++ mathed/./math_charinset.h   1 Nov 2005 19:44:36 -0000
@@ -29,8 +29,12 @@ public:
        ///
        void drawT(TextPainter &, int x, int y) const;
        ///
-       int width() const { return width_; }
-
+       int width() const { return dim_.wid; }
+       ///
+       int ascent() const { return dim_.asc; }
+       ///
+       int descent() const { return dim_.des; }
+       
        ///
        void write(WriteStream & os) const;
        ///
@@ -51,6 +55,6 @@ private:
        /// the character
        char char_;
        /// cached width
-       mutable int width_;
+       mutable Dimension dim_;
 };
 #endif
Index: mathed/./math_kerninset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_kerninset.C,v
retrieving revision 1.32
diff -u -p -r1.32 math_kerninset.C
--- mathed/./math_kerninset.C   3 Oct 2005 12:16:34 -0000       1.32
+++ mathed/./math_kerninset.C   1 Nov 2005 19:44:38 -0000
@@ -42,7 +42,8 @@ auto_ptr<InsetBase> MathKernInset::doClo
 
 void MathKernInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       dim.wid = wid_.inPixels(0, mathed_char_width(mi.base.font, 'M'));
+       dim_.wid = wid_.inPixels(0, mathed_char_width(mi.base.font, 'M'));
+       dim.wid = dim_.wid;
        dim.asc = 0;
        dim.des = 0;
 }
Index: mathed/./math_kerninset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_kerninset.h,v
retrieving revision 1.20
diff -u -p -r1.20 math_kerninset.h
--- mathed/./math_kerninset.h   23 Nov 2004 23:04:50 -0000      1.20
+++ mathed/./math_kerninset.h   1 Nov 2005 19:44:38 -0000
@@ -35,9 +35,18 @@ public:
        void write(WriteStream & os) const;
        ///
        void normalize(NormalStream & ns) const;
+       ///
+       int width() const { return dim_.wid; }
+       ///
+       int ascent() const { return 0; }
+       ///
+       int descent() const { return 0; }
 private:
        virtual std::auto_ptr<InsetBase> doClone() const;
        /// width in em
        LyXLength wid_;
+       /// Dimension cache
+       mutable Dimension dim_;
+       
 };
 #endif
Index: mathed/./math_numberinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_numberinset.C,v
retrieving revision 1.15
diff -u -p -r1.15 math_numberinset.C
--- mathed/./math_numberinset.C 17 Jul 2005 10:31:44 -0000      1.15
+++ mathed/./math_numberinset.C 1 Nov 2005 19:44:38 -0000
@@ -33,6 +33,7 @@ auto_ptr<InsetBase> MathNumberInset::doC
 void MathNumberInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        mathed_string_dim(mi.base.font, str_, dim);
+       dim_ = dim;
 }
 
 
Index: mathed/./math_numberinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_numberinset.h,v
retrieving revision 1.12
diff -u -p -r1.12 math_numberinset.h
--- mathed/./math_numberinset.h 23 Nov 2004 23:04:52 -0000      1.12
+++ mathed/./math_numberinset.h 1 Nov 2005 19:44:38 -0000
@@ -30,7 +30,13 @@ public:
        std::string str() const { return str_; }
        ///
        MathNumberInset * asNumberInset() { return this; }
-
+       ///
+       int width() const { return dim_.wid; }
+       ///
+       int ascent() const { return dim_.asc; }
+       ///
+       int descent() const { return dim_.des; }
+       
        ///
        void normalize(NormalStream &) const;
        ///
@@ -46,5 +52,8 @@ private:
        virtual std::auto_ptr<InsetBase> doClone() const;
        /// the number as string
        std::string str_;
+       /// dimensions:
+       mutable Dimension dim_;
+
 };
 #endif
Index: mathed/./math_stringinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_stringinset.C,v
retrieving revision 1.33
diff -u -p -r1.33 math_stringinset.C
--- mathed/./math_stringinset.C 17 Jul 2005 10:31:44 -0000      1.33
+++ mathed/./math_stringinset.C 1 Nov 2005 19:44:38 -0000
@@ -34,6 +34,7 @@ auto_ptr<InsetBase> MathStringInset::doC
 void MathStringInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        mathed_string_dim(mi.base.font, str_, dim);
+       dim_ = dim;
 }
 
 
Index: mathed/./math_stringinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_stringinset.h,v
retrieving revision 1.26
diff -u -p -r1.26 math_stringinset.h
--- mathed/./math_stringinset.h 23 Nov 2004 23:04:52 -0000      1.26
+++ mathed/./math_stringinset.h 1 Nov 2005 19:44:38 -0000
@@ -31,7 +31,13 @@ public:
        std::string str() const { return str_; }
        ///
        MathStringInset * asStringInset() { return this; }
-
+       /// 
+       int width() const { return dim_.wid; }
+       ///
+       int ascent() const { return dim_.asc; }
+       ///
+       int descent() const { return dim_.des; }
+       
        ///
        void normalize(NormalStream &) const;
        ///
@@ -49,5 +55,8 @@ private:
        virtual std::auto_ptr<InsetBase> doClone() const;
        /// the string
        std::string str_;
+       ///
+       mutable Dimension dim_;
+
 };
 #endif
Index: mathed/./math_symbolinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_symbolinset.C,v
retrieving revision 1.72
diff -u -p -r1.72 math_symbolinset.C
--- mathed/./math_symbolinset.C 17 Jul 2005 10:31:44 -0000      1.72
+++ mathed/./math_symbolinset.C 1 Nov 2005 19:44:39 -0000
@@ -92,7 +92,7 @@ void MathSymbolInset::metrics(MetricsInf
                if (sym_->inset == "cmex" || sym_->extra == "funclim")
                        scriptable_ = true;
 
-       width_ = dim.wid;
+       dim_ = dim;
 }
 
 
Index: mathed/./math_symbolinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_symbolinset.h,v
retrieving revision 1.44
diff -u -p -r1.44 math_symbolinset.h
--- mathed/./math_symbolinset.h 19 Jan 2005 15:03:31 -0000      1.44
+++ mathed/./math_symbolinset.h 1 Nov 2005 19:44:39 -0000
@@ -33,8 +33,12 @@ public:
        ///
        void draw(PainterInfo &, int x, int y) const;
        ///
-       int width() const { return width_; }
-
+       int width() const { return dim_.wid; }
+       ///
+       int ascent() const { return dim_.asc; }
+       ///
+       int descent() const { return dim_.des; }
+       
        ///
        bool isRelOp() const;
        /// do we take scripts?
@@ -71,8 +75,8 @@ private:
        latexkeys const * sym_;
        ///
        mutable int h_;
-       /// cached width
-       mutable int width_;
+       /// cached dim
+       mutable Dimension dim_;
        ///
        mutable bool scriptable_;
 };

Attachment: pgp11IAurMJCa.pgp
Description: PGP signature

Reply via email to