Hello,

As the title says. I've been testing this patch for some days and I didn't see any side effect. The contrary would be surprising as the changes are pretty simple.

Will commit tomorrow if there's no objection.

Abdel.
Index: frontends/gtk/GPainter.C
===================================================================
--- frontends/gtk/GPainter.C    (revision 15292)
+++ frontends/gtk/GPainter.C    (working copy)
@@ -196,7 +196,7 @@
 } // anon namespace
 
 
-void GPainter::text(int x, int y,
+int GPainter::text(int x, int y,
                    char_type const * s, size_t ls,
                    LyXFont const & f)
 {
@@ -204,6 +204,8 @@
        XftColor * xftClr = owner_.getColorHandler().
                getXftColor(f.realColor());
        XftDraw * draw = owner_.getXftDraw();
+       int textwidth = 0;
+
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
                XftDrawString32(draw,
                                xftClr,
@@ -211,11 +213,11 @@
                                x, y,
                                reinterpret_cast<FcChar32 const *>(s),
                                ls);
+               textwidth = font_metrics::width(s, ls, f);
        } else {
                LyXFont smallfont(f);
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
                XftFont * fontS = getXftFont(smallfont);
-               int tmpx = x;
                for (unsigned int i = 0; i < ls; ++i) {
                        // Ok, this looks quite ugly...
                        char_type c = 
gdk_keyval_to_unicode(gdk_keyval_to_upper(gdk_unicode_to_keyval(s[i])));
@@ -223,35 +225,37 @@
                                XftDrawString32(draw,
                                                xftClr,
                                                fontS,
-                                               tmpx, y,
+                                               x + textwidth, y,
                                                reinterpret_cast<FcChar32 
*>(&c),
                                                1);
-                               tmpx += font_metrics::width(c, smallfont);
+                               textwidth += font_metrics::width(c, smallfont);
                        } else {
                                XftDrawString32(draw,
                                                xftClr,
                                                font,
-                                               tmpx, y,
+                                               x + textwidth, y,
                                                reinterpret_cast<FcChar32 
*>(&c),
                                                1);
-                               tmpx += font_metrics::width(c, f);
+                               textwidth += font_metrics::width(c, f);
                        }
                }
        }
        if (f.underbar() == LyXFont::ON)
-               underline(f, x, y, font_metrics::width(s, ls, f));
+               underline(f, x, y, textwidth);
+
+       return textwidth;
 }
 
 
-void GPainter::text(int x, int y, docstring const & s, LyXFont const & f)
+int GPainter::text(int x, int y, docstring const & s, LyXFont const & f)
 {
-       text (x, y, reinterpret_cast<char_type const *>(s.data()), s.size(), f);
+       return text (x, y, reinterpret_cast<char_type const *>(s.data()), 
s.size(), f);
 }
 
 
-void GPainter::text(int x, int y, char_type c, LyXFont const & f)
+int GPainter::text(int x, int y, char_type c, LyXFont const & f)
 {
-       text (x, y, &c, 1, f);
+       return text (x, y, &c, 1, f);
 }
 
 
Index: frontends/gtk/GPainter.h
===================================================================
--- frontends/gtk/GPainter.h    (revision 15292)
+++ frontends/gtk/GPainter.h    (working copy)
@@ -97,16 +97,16 @@
                graphics::Image const & image);
 
        /// draw a string at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                lyx::docstring const & str, LyXFont const & f);
 
        /// draw a string at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                 lyx::char_type const * str, size_t l,
                LyXFont const & f);
 
        /// draw a char at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                 lyx::char_type c, LyXFont const & f);
 
        void start();
Index: frontends/nullpainter.h
===================================================================
--- frontends/nullpainter.h     (revision 15292)
+++ frontends/nullpainter.h     (working copy)
@@ -57,13 +57,13 @@
        ///
        void image(int, int, int, int, lyx::graphics::Image const &) {}
        ///
-       void text(int, int, lyx::docstring const &, LyXFont const &) {}
+       int text(int, int, lyx::docstring const &, LyXFont const &) { return 0; 
}
 //     ///
-//     void text(int, int, char const *, size_t, LyXFont const &) {}
+//     int text(int, int, char const *, size_t, LyXFont const &) { return 0; }
        ///
-       void text(int, int, lyx::char_type const *, size_t, LyXFont const &) {}
+       int text(int, int, lyx::char_type const *, size_t, LyXFont const &) { 
return 0; }
        ///
-       void text(int, int, lyx::char_type, LyXFont const &) {}
+       int text(int, int, lyx::char_type, LyXFont const &) { return 0; }
        ///
        void rectText(int, int, lyx::docstring const &,
                LyXFont const &, LColor_color, LColor_color) {}
Index: frontends/Painter.h
===================================================================
--- frontends/Painter.h (revision 15292)
+++ frontends/Painter.h (working copy)
@@ -132,19 +132,26 @@
                lyx::graphics::Image const & image) = 0;
 
        /// draw a string at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       /**
+       * \return the width of the drawn text.
+       */
+       virtual int text(int x, int y,
                lyx::docstring const & str, LyXFont const & f) = 0;
 
        /**
         * Draw a string at position x, y (y is the baseline)
         * This is just for fast drawing
+        * \return the width of the drawn text.
         */
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                lyx::char_type const * str, size_t l,
                LyXFont const & f) = 0;
 
        /// draw a char at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       /**
+       * \return the width of the drawn text.
+       */
+       virtual int text(int x, int y,
                          lyx::char_type c, LyXFont const & f) = 0;
 
        /**
Index: frontends/qt3/QLPainter.C
===================================================================
--- frontends/qt3/QLPainter.C   (revision 15292)
+++ frontends/qt3/QLPainter.C   (working copy)
@@ -159,21 +159,21 @@
 }
 
 
-void QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
+int QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
 {
        lyxerr << "Drawing string" << endl;
        return text(x, y, reinterpret_cast<lyx::char_type const *>(s.data()), 
s.length(), f);
 }
 
 
-void QLPainter::text(int x, int y, lyx::char_type c, LyXFont const & f)
+int QLPainter::text(int x, int y, lyx::char_type c, LyXFont const & f)
 {
        char_type s[2] = { c, L'\0' };
        return text(x, y, s, 1, f);
 }
 
 
-void QLPainter::smallCapsText(int x, int y,
+int QLPainter::smallCapsText(int x, int y,
        QString const & s, LyXFont const & f)
 {
        LyXFont smallfont(f);
@@ -184,25 +184,27 @@
        QFontMetrics const & qfontm = QFontMetrics(qfont);
        QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
 
-       int tmpx = x;
        size_t ls = s.length();
+       int textwidth = 0;
        for (size_t i = 0; i < ls; ++i) {
                // Brain-dead MSVC wants at(i) rather than operator[]
                QChar const c = s.at(i).upper();
                if (c != s.at(i)) {
                        qp_->setFont(qsmallfont);
-                       qp_->drawText(tmpx, y, c);
-                       tmpx += qsmallfontm.width(c);
+                       qp_->drawText(x + textwidth, y, c);
+                       textwidth += qsmallfontm.width(c);
                } else {
                        qp_->setFont(qfont);
-                       qp_->drawText(tmpx, y, c);
-                       tmpx += qfontm.width(c);
+                       qp_->drawText(x + textwidth, y, c);
+                       textwidth += qfontm.width(c);
                }
        }
+
+       return textwidth;
 }
 
 
-void QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
+int QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
        LyXFont const & f)
 {
        lyxerr << "Drawing lyx::char_type const * s" << endl;
@@ -235,18 +237,23 @@
                str = ' ' + str;
 #endif
 
+       int textwidth;
+
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
                qp_->setFont(fontloader.get(f));
                // We need to draw the text as LTR as we use our own bidi
                // code.
                qp_->drawText(x, y, str, -1, QPainter::LTR);
+               textwidth = qp_->fontMetrics().width(str);
        } else {
-               smallCapsText(x, y, str, f);
+               textwidth = smallCapsText(x, y, str, f);
        }
 
        if (f.underbar() == LyXFont::ON) {
-               underline(f, x, y, qp_->fontMetrics().width(str));
+               underline(f, x, y, textwidth);
        }
+
+       return textwidth;
 }
 
 } // namespace frontend
Index: frontends/qt3/QLPainter.h
===================================================================
--- frontends/qt3/QLPainter.h   (revision 15292)
+++ frontends/qt3/QLPainter.h   (working copy)
@@ -98,22 +98,22 @@
                lyx::graphics::Image const & image);
 
        /// draw a string at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                          lyx::docstring const & str, LyXFont const & f);
 
        /** Draw a string at position x, y (y is the baseline)
         *  This is just for fast drawing
         */
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                          lyx::char_type const * str, size_t l,
                          LyXFont const & f);
 
        /// draw a char at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                          lyx::char_type c, LyXFont const & f);
 private:
        /// draw small caps text
-       void smallCapsText(int x, int y,
+       int smallCapsText(int x, int y,
                QString const & str, LyXFont const & f);
 
        /// set pen parameters
Index: frontends/qt4/QLPainter.C
===================================================================
--- frontends/qt4/QLPainter.C   (revision 15292)
+++ frontends/qt4/QLPainter.C   (working copy)
@@ -183,13 +183,13 @@
 }
 
 
-void QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
+int QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
 {
     return text(x, y, reinterpret_cast<char_type const *>(s.data()), 
s.length(), f);
 }
 
 
-void QLPainter::text(int x, int y, char_type c, LyXFont const & f)
+int QLPainter::text(int x, int y, char_type c, LyXFont const & f)
 {
        char_type s[2] = { c, char_type('\0') };
        return text(x, y, s, 1, f);
@@ -222,7 +222,7 @@
 }
 
 
-void QLPainter::text(int x, int y, char_type const * s, size_t ls,
+int QLPainter::text(int x, int y, char_type const * s, size_t ls,
        LyXFont const & f)
 {
 #if 0
@@ -260,6 +260,7 @@
                underline(f, x, y, textwidth);
        }
 
+       return textwidth;
 }
 
 
Index: frontends/qt4/QLPainter.h
===================================================================
--- frontends/qt4/QLPainter.h   (revision 15292)
+++ frontends/qt4/QLPainter.h   (working copy)
@@ -103,18 +103,18 @@
                lyx::graphics::Image const & image);
 
        /// draw a string at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                lyx::docstring const & str, LyXFont const & f);
 
        /** Draw a string at position x, y (y is the baseline)
         *  This is just for fast drawing
         */
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                 lyx::char_type const * str, size_t l,
                LyXFont const & f);
 
        /// draw a char at position x, y (y is the baseline)
-       virtual void text(int x, int y,
+       virtual int text(int x, int y,
                 lyx::char_type c, LyXFont const & f);
 
        /// draw a pixmap from the image cache
Index: rowpainter.C
===================================================================
--- rowpainter.C        (revision 15292)
+++ rowpainter.C        (working copy)
@@ -316,12 +316,11 @@
        // Draw text and set the new x position
        //lyxerr << "paint row: yo_ " << yo_ << "\n";
 #if 0
-       pain_.text(int(x_), yo_, str, font);
-       x_ += theApp->fontLoader().metrics(font).width(str);
+       int width = pain_.text(int(x_), yo_, str, font);
 #else
-       pain_.text(int(x_), yo_, &str[0], str.size(), font);
-       x_ += theApp->fontLoader().metrics(font).width(&str[0], str.size());
+       int width = pain_.text(int(x_), yo_, &str[0], str.size(), font);
 #endif
+       x_ += width;
 }
 
 

Reply via email to