]> git.lyx.org Git - lyx.git/commitdiff
Make the different Painter::text void methods
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 19 Mar 2016 16:52:07 +0000 (17:52 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 30 May 2016 12:55:41 +0000 (14:55 +0200)
The textwidth value that was returned is not used anymore. Now in some
cases we can avoid to compute it at all.

src/frontends/Painter.h
src/frontends/qt4/GuiPainter.cpp
src/frontends/qt4/GuiPainter.h

index c72d8133b972e05e9e070221efd3d3919a90eab8..21067682e601867f0ec52551ac017f606cbaac3b 100644 (file)
@@ -133,28 +133,29 @@ public:
        virtual void image(int x, int y, int w, int h,
                graphics::Image const & image) = 0;
 
        virtual void image(int x, int y, int w, int h,
                graphics::Image const & image) = 0;
 
+       /** draw a character at position x, y (y is the baseline)
+        */
+       virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
+
        /** draw a string at position x, y (y is the baseline). The
         * text direction is given by \c rtl.
        /** draw a string at position x, y (y is the baseline). The
         * text direction is given by \c rtl.
-        * \return the width of the drawn text.
         */
         */
-       virtual int text(int x, int y, docstring const & str, FontInfo const & f,
-                     bool rtl = false, double wordspacing = 0.0) = 0;
+       virtual void text(int x, int y, docstring const & str, FontInfo const & f,
+                      bool rtl = false, double wordspacing = 0.0) = 0;
 
        /** draw a string at position x, y (y is the baseline). The
         * text direction is enforced by the \c Font.
 
        /** draw a string at position x, y (y is the baseline). The
         * text direction is enforced by the \c Font.
-        * \return the width of the drawn text.
         */
         */
-       virtual int text(int x, int y, docstring const & str, Font const & f,
-                     double wordspacing = 0.0) = 0;
+       virtual void text(int x, int y, docstring const & str, Font const & f,
+                      double wordspacing = 0.0) = 0;
 
        /** draw a string at position x, y (y is the baseline), but
         * make sure that the part between \c from and \c to is in
         * \c other color. The text direction is enforced by the \c Font.
 
        /** draw a string at position x, y (y is the baseline), but
         * make sure that the part between \c from and \c to is in
         * \c other color. The text direction is enforced by the \c Font.
-        * \return the width of the drawn text.
         */
         */
-       virtual int text(int x, int y, docstring const & str, Font const & f,
-                     Color other, size_type from, size_type to,
-                     double const wordspacing) = 0;
+       virtual void text(int x, int y, docstring const & str, Font const & f,
+                         Color other, size_type from, size_type to,
+                         double const wordspacing) = 0;
 
        void setDrawingEnabled(bool drawing_enabled)
        { drawing_enabled_ = drawing_enabled; }
 
        void setDrawingEnabled(bool drawing_enabled)
        { drawing_enabled_ = drawing_enabled; }
@@ -164,12 +165,6 @@ public:
 
        double pixelRatio() const { return pixel_ratio_; }
 
 
        double pixelRatio() const { return pixel_ratio_; }
 
-       /// draw a char at position x, y (y is the baseline)
-       /**
-       * \return the width of the drawn text.
-       */
-       virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
-
        /// draw the underbar, strikeout, uuline and uwave font attributes
        virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
 
        /// draw the underbar, strikeout, uuline and uwave font attributes
        virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
 
index 5329624a6a1b6f2605f0713fa1c6bbcf10e6cb1e..12d4f72eb98e04b0b040ff8381bbff1502a0403b 100644 (file)
@@ -327,9 +327,9 @@ void GuiPainter::image(int x, int y, int w, int h, graphics::Image const & i)
 }
 
 
 }
 
 
-int GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
+void GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
 {
 {
-       return text(x, y, docstring(1, c), f);
+       text(x, y, docstring(1, c), f);
 }
 
 
 }
 
 
@@ -368,13 +368,13 @@ void GuiPainter::do_drawText(int x, int y, QString str, bool rtl, FontInfo const
 }
 
 
 }
 
 
-int GuiPainter::text(int x, int y, docstring const & s,
-                     FontInfo const & f, bool const rtl,
-                     double const wordspacing)
+void GuiPainter::text(int x, int y, docstring const & s,
+                      FontInfo const & f, bool const rtl,
+                      double const wordspacing)
 {
        //LYXERR0("text: x=" << x << ", s=" << s);
 {
        //LYXERR0("text: x=" << x << ", s=" << s);
-       if (s.empty())
-               return 0;
+       if (s.empty() || !isDrawingEnabled())
+               return;
 
        /* Caution: The following ucs4 to QString conversions work for symbol fonts
        only because they are no real conversions but simple casts in reality.
 
        /* Caution: The following ucs4 to QString conversions work for symbol fonts
        only because they are no real conversions but simple casts in reality.
@@ -406,9 +406,6 @@ int GuiPainter::text(int x, int y, docstring const & s,
        // Note that we have to take in account space stretching (word spacing)
        int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') * wordspacing;
 
        // Note that we have to take in account space stretching (word spacing)
        int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') * wordspacing;
 
-       if (!isDrawingEnabled())
-               return textwidth;
-
        textDecoration(f, x, y, textwidth);
 
        if (use_pixmap_cache_) {
        textDecoration(f, x, y, textwidth);
 
        if (use_pixmap_cache_) {
@@ -428,7 +425,7 @@ int GuiPainter::text(int x, int y, docstring const & s,
                if (QPixmapCache::find(key, pm)) {
                        // Draw the cached pixmap.
                        drawPixmap(x + lb, y - mA, pm);
                if (QPixmapCache::find(key, pm)) {
                        // Draw the cached pixmap.
                        drawPixmap(x + lb, y - mA, pm);
-                       return textwidth;
+                       return;
                }
 
                // Only the right bearing of the last character is
                }
 
                // Only the right bearing of the last character is
@@ -456,27 +453,26 @@ int GuiPainter::text(int x, int y, docstring const & s,
                        drawPixmap(x + lb, y - mA, pm);
                        //rectangle(x-lb, y-mA, w, h, Color_green);
                }
                        drawPixmap(x + lb, y - mA, pm);
                        //rectangle(x-lb, y-mA, w, h, Color_green);
                }
-               return textwidth;
+               return;
        }
 
        // don't use the pixmap cache,
        do_drawText(x, y, str, rtl, f, ff);
        //LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
        //      << " at " << x << "," << y);
        }
 
        // don't use the pixmap cache,
        do_drawText(x, y, str, rtl, f, ff);
        //LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
        //      << " at " << x << "," << y);
-       return textwidth;
 }
 
 
 }
 
 
-int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
-                     double const wordspacing)
+void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
+                      double const wordspacing)
 {
 {
-       return text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing);
+       text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing);
 }
 
 
 }
 
 
-int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
-                     Color other, size_type const from, size_type const to,
-                     double const wordspacing)
+void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
+                      Color other, size_type const from, size_type const to,
+                      double const wordspacing)
 {
        GuiFontMetrics const & fm = getFontMetrics(f.fontInfo());
        FontInfo fi = f.fontInfo();
 {
        GuiFontMetrics const & fm = getFontMetrics(f.fontInfo());
        FontInfo fi = f.fontInfo();
@@ -495,7 +491,7 @@ int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
        fi.setPaintColor(other);
        QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
        setClipRegion(clip);
        fi.setPaintColor(other);
        QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
        setClipRegion(clip);
-       int const textwidth = text(x, y, str, fi, rtl, wordspacing);
+       text(x, y, str, fi, rtl, wordspacing);
 
        // Then the part in normal color
        // Note that in Qt5, it is not possible to use Qt::UniteClip,
 
        // Then the part in normal color
        // Note that in Qt5, it is not possible to use Qt::UniteClip,
@@ -505,8 +501,6 @@ int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
        setClipRegion(region - clip);
        text(x, y, str, fi, rtl, wordspacing);
        setClipping(false);
        setClipRegion(region - clip);
        text(x, y, str, fi, rtl, wordspacing);
        setClipping(false);
-
-       return textwidth;
 }
 
 
 }
 
 
index 5aec66ac4c453edb0bf65331e21612c188e99cae..f92b606096521ddf44f2d41ac2781c1dd0e4a718 100644 (file)
@@ -107,29 +107,26 @@ public:
 
        /** draw a string at position x, y (y is the baseline). The
         * text direction is given by \c rtl.
 
        /** draw a string at position x, y (y is the baseline). The
         * text direction is given by \c rtl.
-        * \return the width of the drawn text.
         */
         */
-       virtual int text(int x, int y, docstring const & str, FontInfo const & f,
-                     bool rtl = false, double wordspacing = 0.0);
+       virtual void text(int x, int y, docstring const & str, FontInfo const & f,
+                      bool rtl = false, double wordspacing = 0.0);
 
        /** draw a string at position x, y (y is the baseline). The
         * text direction is enforced by the \c Font.
 
        /** draw a string at position x, y (y is the baseline). The
         * text direction is enforced by the \c Font.
-        * \return the width of the drawn text.
         */
         */
-       virtual int text(int x, int y, docstring const & str, Font const & f,
-                     double wordspacing = 0.0);
+       virtual void text(int x, int y, docstring const & str, Font const & f,
+                      double wordspacing = 0.0);
 
        /** draw a string at position x, y (y is the baseline), but
         * make sure that the part between \c from and \c to is in
         * \c other color. The text direction is enforced by the \c Font.
 
        /** draw a string at position x, y (y is the baseline), but
         * make sure that the part between \c from and \c to is in
         * \c other color. The text direction is enforced by the \c Font.
-        * \return the width of the drawn text.
         */
         */
-       virtual int text(int x, int y, docstring const & str, Font const & f,
-                     Color other, size_type from, size_type to,
-                     double const wordspacing);
+       virtual void text(int x, int y, docstring const & str, Font const & f,
+                         Color other, size_type from, size_type to,
+                      double const wordspacing);
 
        /// draw a char at position x, y (y is the baseline)
 
        /// draw a char at position x, y (y is the baseline)
-       virtual int text(int x, int y, char_type c, FontInfo const & f);
+       virtual void text(int x, int y, char_type c, FontInfo const & f);
 
        ///
        virtual void textDecoration(FontInfo const & f, int x, int y, int width);
 
        ///
        virtual void textDecoration(FontInfo const & f, int x, int y, int width);