From: Abdelrazak Younes Date: Mon, 26 Feb 2007 15:13:08 +0000 (+0000) Subject: * support/qstring_helpers.h: erase ucs4_to_qstring() method. X-Git-Tag: 1.6.10~10667 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=ba62665f966508db5a4de6864f4aa7374c5a5356;p=features.git * support/qstring_helpers.h: erase ucs4_to_qstring() method. * 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 --- diff --git a/src/frontends/FontMetrics.h b/src/frontends/FontMetrics.h index 89890c1ba0..cdad1946da 100644 --- a/src/frontends/FontMetrics.h +++ b/src/frontends/FontMetrics.h @@ -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()); - } }; diff --git a/src/frontends/NoGuiFontMetrics.h b/src/frontends/NoGuiFontMetrics.h index bf0ea1bf3f..28ab4f40a9 100644 --- a/src/frontends/NoGuiFontMetrics.h +++ b/src/frontends/NoGuiFontMetrics.h @@ -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); } diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h index 40f624b420..2b3de17435 100644 --- a/src/frontends/Painter.h +++ b/src/frontends/Painter.h @@ -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. diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index b905356901..ca696d3e39 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -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; } diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index bb320dcce1..59a03c3a47 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -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; diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C index c0090210b2..a7761ae892 100644 --- a/src/frontends/qt4/QLPainter.C +++ b/src/frontends/qt4/QLPainter.C @@ -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(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(); diff --git a/src/frontends/qt4/QLPainter.h b/src/frontends/qt4/QLPainter.h index 20dcfe42a1..3050ea4946 100644 --- a/src/frontends/qt4/QLPainter.h +++ b/src/frontends/qt4/QLPainter.h @@ -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); diff --git a/src/rowpainter.C b/src/rowpainter.C index 2cb5b6311a..294f8e5e4b 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -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); } } diff --git a/src/support/qstring_helpers.h b/src/support/qstring_helpers.h index dfb22e6c1b..db98b4e1d6 100644 --- a/src/support/qstring_helpers.h +++ b/src/support/qstring_helpers.h @@ -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(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 *