]> git.lyx.org Git - features.git/commitdiff
* frontends/Painter:
authorAbdelrazak Younes <younes@lyx.org>
Tue, 10 Oct 2006 13:24:08 +0000 (13:24 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 10 Oct 2006 13:24:08 +0000 (13:24 +0000)
 - text(): now returns drawn text width()

* rowpainter:
 - paintChars(): use the returned width from Painter::text() instead of recalculating it.

All other files: implement the API change. qt3 and gtk not 100% guaranted to compile nor work.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15294 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/Painter.h
src/frontends/gtk/GPainter.C
src/frontends/gtk/GPainter.h
src/frontends/nullpainter.h
src/frontends/qt3/QLPainter.C
src/frontends/qt3/QLPainter.h
src/frontends/qt4/QLPainter.C
src/frontends/qt4/QLPainter.h
src/rowpainter.C

index 9dd8731c447ef612082c18dc3ab5425e45723835..783c899a5c23fa4feabce9927e34787451e627ff 100644 (file)
@@ -132,19 +132,26 @@ public:
                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 96d5c5734c04510ef93a86c9c5df50f05c6a9106..5da8aff2a95f10605d91e40512ad0bd8bad44e24 100644 (file)
@@ -196,7 +196,7 @@ inline XftFont * getXftFont(LyXFont const & f)
 } // 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 @@ void GPainter::text(int x, int y,
        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 @@ void GPainter::text(int x, int y,
                                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 @@ void GPainter::text(int x, int y,
                                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 6201db57c807f27c9a62c2d89c703dab7c802b86..16711569512640b2d6ea1ebe071bcbe1dcbe1f1e 100644 (file)
@@ -97,16 +97,16 @@ public:
                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 bb77976bcae84e75de4d9514b79baa4b055ece96..931e2bbc1e79a3d1b734f149e092a497a589c0eb 100644 (file)
@@ -57,13 +57,13 @@ public:
        ///
        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 7c788193b6a34cfba813a4f5b71e5830ea594dfb..8bf7c274bca1aae2e8eba4e857e6469ca5ec157e 100644 (file)
@@ -159,21 +159,21 @@ void QLPainter::image(int x, int y, int w, int h,
 }
 
 
-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 @@ void QLPainter::smallCapsText(int x, int y,
        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 @@ void QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
                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 ade005a79c42a6ba897e2452f5d85e75b0e01483..1c6a91f92be2e7df858b93fe3372b0c52402440f 100644 (file)
@@ -98,22 +98,22 @@ public:
                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 92744f0d2a75a9bb389bc5ea9d8409e39b860517..9bd17c44b426e3b4b1142a39e18b5f71afa27035 100644 (file)
@@ -183,13 +183,13 @@ void QLPainter::image(int x, int y, int w, int h,
 }
 
 
-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 @@ int QLPainter::smallCapsText(int x, int y,
 }
 
 
-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 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls,
                underline(f, x, y, textwidth);
        }
 
+       return textwidth;
 }
 
 
index f53b0e67c9323504fb59b21f1745b6b473079b5c..145e974c564f410d5aad3d812f3e16ae019a4f23 100644 (file)
@@ -103,18 +103,18 @@ public:
                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 bb223599289fb204896b00b4d49d38d84ad06b01..10ecef35b90247b96b5054aa0339a71a90ed1b7f 100644 (file)
@@ -316,12 +316,11 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font,
        // 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;
 }