From: Abdelrazak Younes Date: Sat, 7 Oct 2006 16:30:26 +0000 (+0000) Subject: * qt_helpers: X-Git-Tag: 1.6.10~12442 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a21259dd02954a6aa5707bb0bf4da0f826e44a4b;p=features.git * qt_helpers: - ucs4_to_qchar() and qchar_to_ucs4() have been inlined. - ucs4_to_qstring(): pass a QString to avoid a copy. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15266 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index b5a2b0a3d6..6fcc79930a 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -137,7 +137,8 @@ int GuiFontMetrics::width(char_type const * s, size_t ls) const if (!lyx_gui::use_gui) return ls; - QString ucs2 = ucs4_to_qstring(s, ls); + QString ucs2; + ucs4_to_qstring(s, ls, ucs2); if (smallcaps_shape_) return smallcapsWidth(ucs2); diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C index 3fcfba0ee1..92744f0d2a 100644 --- a/src/frontends/qt4/QLPainter.C +++ b/src/frontends/qt4/QLPainter.C @@ -231,14 +231,8 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls, encoding = encodings.symbol_encoding(); #endif -#if 0 QString str; - str.setLength(ls); - for (unsigned int i = 0; i < ls; ++i) - str[i] = QChar(encoding->ucs(s[i])); -#else - QString str = ucs4_to_qstring(s, ls); -#endif + ucs4_to_qstring(s, ls, str); #if 0 // HACK: QT3 refuses to show single compose characters diff --git a/src/frontends/qt4/qt_helpers.C b/src/frontends/qt4/qt_helpers.C index 394c13341d..37649e144e 100644 --- a/src/frontends/qt4/qt_helpers.C +++ b/src/frontends/qt4/qt_helpers.C @@ -120,15 +120,12 @@ QString const toqstr(string const & str) } -QString const ucs4_to_qstring(char_type const * str, size_t ls) +void ucs4_to_qstring(char_type const * str, size_t ls, QString & s) { - QString s; s.reserve(ls); for (size_t i = 0; i < ls; ++i) s.append(ucs4_to_qchar(str[i])); - - return s; } @@ -164,18 +161,6 @@ void qstring_to_ucs4(QString const & qstr, vector & ucs4) } -char_type const qchar_to_ucs4(QChar const & qchar) -{ - return static_cast(qchar.unicode()); -} - - -QChar const ucs4_to_qchar(char_type const & ucs4) -{ - return QChar(static_cast(ucs4)); -} - - QString const qt_(char const * str) { return toqstr(_(str)); diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 9574965f41..bdefc8bbe8 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -19,13 +19,14 @@ #include "support/docstring.h" +#include + #include class LengthCombo; class QComboBox; class QLineEdit; class QString; -class QChar; std::string makeFontName(std::string const & family, std::string const & foundry); @@ -68,16 +69,19 @@ QString const toqstr(std::string const & str); */ QString const toqstr(lyx::docstring const & ucs4); -QString const ucs4_to_qstring(lyx::char_type const * str, size_t ls); +void ucs4_to_qstring(lyx::char_type const * str, size_t ls, QString & s); lyx::docstring const qstring_to_ucs4(QString const & qstr); void qstring_to_ucs4(QString const & qstr, std::vector & ucs4); -lyx::char_type const qchar_to_ucs4(QChar const & qchar); - -QChar const ucs4_to_qchar(lyx::char_type const & ucs4); +inline lyx::char_type const qchar_to_ucs4(QChar const & qchar) { + return static_cast(qchar.unicode()); +} +inline QChar const ucs4_to_qchar(lyx::char_type const ucs4) { + return QChar(static_cast(ucs4)); +} /** * qt_ - i18nize string and convert to unicode