#include "FontLoader.h"
#include "Application.h"
+#include "qt_helpers.h"
#include "debug.h"
#include "language.h"
for (unsigned int i = 0; i < ls; ++i)
str[i] = QChar(encoding->ucs(s[i]));
#else
- //std::vector<boost::uint32_t> in(s, s + ls);
- //std::vector<unsigned short> ucs2 = ucs4_to_ucs2(in);
- std::vector<unsigned short> ucs2 = ucs4_to_ucs2(s, ls);
- ucs2.push_back(0);
- QString str = QString::fromUtf16(&ucs2[0]);
+ QString str = ucs4_to_qstring(s, ls);
#endif
#if 0
size_t QLyXKeySym::getUCSEncoded() const
{
- unsigned short const * ptr = text_.utf16();
- std::vector<unsigned short> tmp(ptr, ptr + text_.length());
-
- //lyxerr << "Data is " << tmp << endl;
- lyxerr << "Length is " << text_.length() << endl;
-
- if (text_.isEmpty())
- return 0;
+ if (text_.isEmpty())
+ return 0;
- //size_t res = utf8_to_ucs4(tmp, tmp.length());
- //lyxerr << "Res is " << res << endl;
- return ucs2_to_ucs4(tmp)[0];
+ BOOST_ASSERT(text_.size() == 1);
+ return qchar_to_ucs4(text_[0]);
}
#include "Application.h"
#include "FontLoader.h"
+#include "qt_helpers.h"
#include "language.h"
namespace {
-int smallcapswidth(unsigned short const * s, size_t ls, LyXFont const & f)
+int smallcapswidth(QString const & s, LyXFont const & f)
{
if (!lyx_gui::use_gui)
return 1;
int w = 0;
+ size_t const ls = s.size();
+
for (size_t i = 0; i < ls; ++i) {
- QChar const c = s[i];
+ QChar const & c = s[i];
QChar const uc = c.toUpper();
if (c != uc)
w += qsmallm.width(uc);
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r = theApp->fontLoader().metrics(f).boundingRect(ucs4_to_ucs2(c));
+ QRect const & r = theApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, width, height)
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r = theApp->fontLoader().metrics(f).boundingRect(ucs4_to_ucs2(c));
+ QRect const & r = theApp->fontLoader().metrics(f).boundingRect(ucs4_to_qchar(c));
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, width, height)
{
if (!lyx_gui::use_gui)
return 1;
- return theApp->fontLoader().metrics(f).leftBearing(ucs4_to_ucs2(c));
+ return theApp->fontLoader().metrics(f).leftBearing(ucs4_to_qchar(c));
}
QFontMetrics const & m = theApp->fontLoader().metrics(f);
// Qt rbearing is from the right edge of the char's width().
- unsigned short sc = ucs4_to_ucs2(c);
+ QChar sc = ucs4_to_qchar(c);
return m.width(sc) - m.rightBearing(sc);
}
if (!lyx_gui::use_gui)
return ls;
- std::vector<unsigned short> ucs2 = ucs4_to_ucs2(s, ls);
- ucs2.push_back(0);
+ QString ucs2 = ucs4_to_qstring(s, ls);
if (f.realShape() == LyXFont::SMALLCAPS_SHAPE)
- return smallcapswidth(&ucs2[0], ls, f);
+ return smallcapswidth(ucs2, f);
QLFontInfo & fi = theApp->fontLoader().fontinfo(f);
if (ls == 1)
- return fi.width(ucs2[0]);
+ return fi.width(ucs2[0].unicode());
int w = 0;
for (size_t i = 0; i < ls; ++i)
- w += fi.width(ucs2[i]);
+ w += fi.width(ucs2[i].unicode());
return w;
}
#include "support/lstrings.h"
#include "support/convert.h"
+#include "debug.h"
+
#include <QComboBox>
#include <qlineedit.h>
#include <qtextcodec.h>
using lyx::support::isStrDbl;
+using lyx::char_type;
+using std::vector;
using std::make_pair;
using std::string;
using std::pair;
+using std::endl;
string makeFontName(string const & family, string const & foundry)
}
+QString const ucs4_to_qstring(char_type const * str, size_t ls)
+{
+ QString s;
+
+ for (size_t i = 0; i < ls; ++i)
+ s.append(ucs4_to_qchar(str[i]));
+
+ return s;
+}
+
+
+QString const ucs4_to_qstring(vector<char_type> const & ucs4)
+{
+ QString s;
+ size_t const ls = ucs4.size();
+
+ for (size_t i = 0; i < ls; ++i)
+ s.append(ucs4_to_qchar(ucs4[i]));
+
+ return s;
+}
+
+
+vector<char_type> qstring_to_ucs4(QString const & qstr)
+{
+ size_t ls = qstr.size();
+ vector<char_type> ucs4;
+ for (size_t i = 0; i < ls; ++i)
+ ucs4.push_back(static_cast<boost::uint32_t>(qstr[i].unicode()));
+
+ return ucs4;
+}
+
+
+void qstring_to_ucs4(QString const & qstr, vector<char_type> & ucs4)
+{
+ size_t ls = qstr.size();
+ ucs4.clear();
+ for (size_t i = 0; i < ls; ++i)
+ ucs4.push_back(static_cast<boost::uint32_t>(qstr[i].unicode()));
+}
+
+
+char_type const qchar_to_ucs4(QChar const & qchar)
+{
+ return static_cast<boost::uint32_t>(qchar.unicode());
+}
+
+
+QChar const ucs4_to_qchar(char_type const & ucs4)
+{
+ return QChar(static_cast<unsigned short>(ucs4));
+}
+
+
QString const qt_(char const * str)
{
return toqstr(_(str));
#include "lyxlength.h"
//#include "lengthcombo.h"
+#include "support/types.h"
+
+#include <vector>
+
class LengthCombo;
class QComboBox;
class QLineEdit;
class QString;
+class QChar;
std::string makeFontName(std::string const & family, std::string const & foundry);
QString const toqstr(std::string const & str);
+/**
+ * toqstr - convert ucs4 into QString
+ *
+ * QString uses ucs2 (a.k.a utf16) internally.
+ */
+QString const ucs4_to_qstring(lyx::char_type const * str, size_t ls);
+
+QString const ucs4_to_qstring(std::vector<lyx::char_type> const & ucs4);
+
+std::vector<lyx::char_type> qstring_to_ucs4(QString const & qstr);
+
+void qstring_to_ucs4(QString const & qstr, std::vector<lyx::char_type> & ucs4);
+
+lyx::char_type const qchar_to_ucs4(QChar const & qchar);
+
+QChar const ucs4_to_qchar(lyx::char_type const & ucs4);
+
+
/**
* qt_ - i18nize string and convert to unicode
*