]> git.lyx.org Git - features.git/commitdiff
* support/qstring_helpers.h: erase ucs4_to_qstring() method.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 26 Feb 2007 15:13:08 +0000 (15:13 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 26 Feb 2007 15:13:08 +0000 (15:13 +0000)
* FontMetrics.h: only one string width() method.

* Painter.h: only one text() method.

* all other files: adapt to above API change.

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

src/frontends/FontMetrics.h
src/frontends/NoGuiFontMetrics.h
src/frontends/Painter.h
src/frontends/qt4/GuiFontMetrics.C
src/frontends/qt4/GuiFontMetrics.h
src/frontends/qt4/QLPainter.C
src/frontends/qt4/QLPainter.h
src/rowpainter.C
src/support/qstring_helpers.h

index 89890c1ba005ff9e7c3b6dab00cb7c41158752ce..cdad1946da1a67ad72db898a3e1afae4a4cc293c 100644 (file)
@@ -74,7 +74,7 @@ public:
        /// return the right bearing of the char in the font
        virtual int rbearing(char_type c) const = 0;
        /// return the width of the string in the font
-       virtual int width(char_type const * s, size_t n) const = 0;
+       virtual int width(docstring const & s) const = 0;
        /// FIXME ??
        virtual int signedWidth(docstring const & s) const = 0;
        /// return char dimension for the font.
@@ -111,12 +111,6 @@ public:
        inline int center(char_type c) const {
                return (rbearing(c) - lbearing(c)) / 2;
        }
-
-       /// return the width of the string in the font
-       inline int width(docstring const & s) const
-       {
-           return s.empty() ? 0 : width(s.data(), s.length());
-       }
 };
 
 
index bf0ea1bf3f8a60ff4ef6522e6bf7ef180364fa52..28ab4f40a908bd0ea285a63d1f2e33471d7a5bb6 100644 (file)
@@ -45,13 +45,13 @@ public:
        
        virtual int rbearing(char_type) const { return 1; }
        
-       virtual int width(char_type const *, size_t n) const { return n; }
+       virtual int width(docstring const & s) const { return s.size(); }
        
        virtual int signedWidth(docstring const & s) const
        {
                if (s.size() && s[0] == '-')
-                       return -FontMetrics::width(s.substr(1, s.length() - 1));
-               return FontMetrics::width(s);
+                       return -width(s.substr(1, s.length() - 1));
+               return width(s);
        }
        
        virtual Dimension const dimension(char_type) const { return Dimension(1, 1, 1); }
index 40f624b420f73edda88fa512b0b1e6ec22f24a5b..2b3de17435f5b050708a212dee00e297ecce3e72 100644 (file)
@@ -135,14 +135,6 @@ public:
        void setDrawingEnabled(bool drawing_enabled = true)
        { drawing_enabled_ = drawing_enabled; }
 
-       /**
-        * 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 int text(int x, int y,
-               char_type const * str, size_t l, LyXFont const & f) = 0;
-
        /// draw a char at position x, y (y is the baseline)
        /**
        * \return the width of the drawn text.
index b90535690170ff640e129d2ea619ded6ee4153f2..ca696d3e391a4f1272603492cb883dbb073ed5b1 100644 (file)
@@ -82,21 +82,18 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const
 }
 
 
-int GuiFontMetrics::width(char_type const * s, size_t ls) const
+int GuiFontMetrics::width(docstring const & s) const
 {
-       // Caution: The following ucs4_to_something conversions work for
-       // symbol fonts only because they are no real conversions but simple
-       // casts in reality.
+       size_t ls = s.size();
+       if (ls == 0)
+               return 0;
 
        if (ls == 1 && !smallcaps_shape_) {
                return width(s[0]);
        }
 
-       if (smallcaps_shape_) {
-               QString ucs2;
-               ucs4_to_qstring(s, ls, ucs2);
-               return smallcapsWidth(ucs2);
-       }
+       if (smallcaps_shape_)
+               return smallcapsWidth(toqstr(s));
 
        int w = 0;
        for (unsigned int i = 0; i < ls; ++i)
@@ -130,9 +127,9 @@ int GuiFontMetrics::signedWidth(docstring const & s) const
                return 0;
 
        if (s[0] == '-')
-               return -width(&(s[1]), s.length() - 1);
+               return -width(s.substr(1, s.size() - 1));
        else
-               return FontMetrics::width(s);
+               return width(s);
 }
 
 
@@ -140,7 +137,7 @@ void GuiFontMetrics::rectText(docstring const & str,
        int & w, int & ascent, int & descent) const
 {
        static int const d = 2;
-       w = FontMetrics::width(str) + d * 2 + 2;
+       w = width(str) + d * 2 + 2;
        ascent = metrics_.ascent() + d;
        descent = metrics_.descent() + d;
 }
@@ -151,7 +148,7 @@ void GuiFontMetrics::buttonText(docstring const & str,
        int & w, int & ascent, int & descent) const
 {
        static int const d = 3;
-       w = FontMetrics::width(str) + d * 2 + 2;
+       w = width(str) + d * 2 + 2;
        ascent = metrics_.ascent() + d;
        descent = metrics_.descent() + d;
 }
index bb320dcce1a79871f4b30a7c05a6ed9120bfa4d2..59a03c3a471dfb9aec8bf5029e601cd2b12caa9d 100644 (file)
@@ -40,7 +40,7 @@ public:
        virtual int descent(char_type c) const;
        virtual int lbearing(char_type c) const;
        virtual int rbearing(char_type c) const;
-       virtual int width(char_type const * s, size_t n) const;
+       virtual int width(docstring const & s) const;
        virtual int signedWidth(docstring const & s) const;
        virtual Dimension const dimension(char_type c) const;
 
index c0090210b29e09fa9255f282a3dd4f6525f23b02..a7761ae892a21cb65c18c5f1432861f3b7149515 100644 (file)
@@ -170,16 +170,10 @@ void QLPainter::image(int x, int y, int w, int h, graphics::Image const & i)
 }
 
 
-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);
-}
-
-
 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);
+       docstring s(c, 1);
+       return text(x, y, s, f);
 }
 
 
@@ -210,15 +204,10 @@ int QLPainter::smallCapsText(int x, int y,
 }
 
 
-int QLPainter::text(int x, int y, char_type const * s, size_t ls,
-       LyXFont const & f)
+int QLPainter::text(int x, int y, docstring const & s,
+               LyXFont const & f)
 {
-       // Caution: The following ucs4_to_qstring conversion works for
-       // symbol fonts only because it is no real conversion but a simple
-       // cast in reality.
-
-       QString str;
-       ucs4_to_qstring(s, ls, str);
+       QString str = toqstr(s);
 
 #if 0
        // HACK: QT3 refuses to show single compose characters
@@ -246,7 +235,7 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
                        // same as that of a soft-hyphen (0x00ad), unless it
                        // occurs at a line-break. As a kludge, we force Qt to
                        // render this glyph using a one-column line.
-                       if (ls == 1 && str[0].unicode() == 0x00ad) {
+                       if (s.size() == 1 && str[0].unicode() == 0x00ad) {
                                QTextLayout adsymbol(str);
                                adsymbol.setFont(fi.font);
                                adsymbol.beginLayout();
index 20dcfe42a1eb9e839b3a2d307dd0538750991c83..3050ea4946fd187e2ab8d2b83e549bfc89509c6f 100644 (file)
@@ -92,13 +92,6 @@ public:
        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 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 int text(int x, int y,
                 lyx::char_type c, LyXFont const & f);
index 2cb5b6311abefe4f6583f6b4b3edc2924fd5e762..294f8e5e4bc81a27f866f6b2017375a5f5611bc7 100644 (file)
@@ -301,6 +301,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
        pain_.text(int(x_) + dx, yo_, str, font);
 }
 
+
 void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
                            bool hebrew, bool arabic)
 {
@@ -346,6 +347,8 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
                str.push_back(c);
        }
 
+       docstring s(&str[0], str.size());
+
        if (prev_change != Change::UNCHANGED) {
                LyXFont copy(font);
                if (prev_change == Change::DELETED) {
@@ -353,9 +356,9 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
                } else if (prev_change == Change::INSERTED) {
                        copy.setColor(LColor::newtext);
                }
-               x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy);
+               x_ += pain_.text(int(x_), yo_, s, copy);
        } else {
-               x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font);
+               x_ += pain_.text(int(x_), yo_, s, font);
        }
 }
 
index dfb22e6c1bf802ab86ef5163d74329287d0c945a..db98b4e1d6e1942ad1065d503c3e510e2800f66a 100644 (file)
@@ -103,21 +103,6 @@ QString const toqstr(docstring const & ucs4);
 #endif
 
 
-/**
- * ucs4_to_qstring - convert a UCS4 encoded char_type * into a QString
- *
- * This is a hack for the painter and font metrics and should not be used
- * elsewhere. Since it uses ucs4_to_qchar it has the same limitations.
- */
-inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
-{
-       int i = static_cast<int>(ls);
-       s.resize(i);
-       for (; --i >= 0;)
-               s[i] = ucs4_to_qchar(str[i]);
-}
-
-
 /**
  * qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
  *