#include "lyxrc.h"
#include "debug.h"
#include "LyXView.h"
-
+#include "encoding.h"
+#include "language.h"
+
#include "QWorkArea.h"
#include "qfont_loader.h"
#include "QLPainter.h"
void QLPainter::smallCapsText(int x, int y,
- char const * s, size_t ls,
- LyXFont const & f)
+ QString const & s, LyXFont const & f)
{
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
int tmpx = x;
+ size_t ls = s.length();
for (size_t i = 0; i < ls; ++i) {
- char const c = uppercase(s[i]);
+ QChar const c = s[i].upper();
if (c != s[i]) {
qp_->setFont(qsmallfont);
- qp_->drawText(tmpx, y, &c, 1);
- tmpx += qsmallfontm.width(&c, 1);
+ qp_->drawText(tmpx, y, c);
+ tmpx += qsmallfontm.width(c);
} else {
qp_->setFont(qfont);
- qp_->drawText(tmpx, y, &c, 1);
- tmpx += qfontm.width(&c, 1);
+ qp_->drawText(tmpx, y, c);
+ tmpx += qfontm.width(c);
}
}
}
{
setPen(f.color());
+ Encoding const * encoding = f.language()->encoding();
+ if (f.isSymbolFont())
+ encoding = encodings.symbol_encoding();
+
+ QString str;
+ str.setLength(ls);
+ for (size_t i = 0; i < ls; ++i)
+ str[i] = QChar(encoding->ucs(s[i]));
+
+#if QT_VERSION >= 0x030000
+ // HACK: QT3 refuses to show single compose characters
+ if (ls = 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2)
+ str = ' '+str;
+#endif
+
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
qp_->setFont(fontloader.get(f));
- qp_->drawText(x, y, s, ls);
+#if QT_VERSION >= 0x030000
+ // We need to draw the text as LTR as we use our own bidi
+ // code.
+ qp_->drawText(x, y, str, -1, QPainter::LTR);
+#else
+ qp_->drawText(x, y, str);
+#endif
} else {
- smallCapsText(x, y, s, ls, f);
+ smallCapsText(x, y, str, f);
}
if (f.underbar() == LyXFont::ON) {
#include "font_metrics.h"
#include "qfont_loader.h"
#include "debug.h"
+#include "encoding.h"
+#include "language.h"
#include <qfontmetrics.h>
#include <qfont.h>
int width(char const * s, size_t ls, LyXFont const & f)
{
+ Encoding const * encoding = f.language()->encoding();
+ if (f.isSymbolFont())
+ encoding = encodings.symbol_encoding();
+
+ QString str;
+ str.setLength(ls);
+ for (size_t i = 0; i < ls; ++i)
+ str[i] = QChar(encoding->ucs(s[i]));
+
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
- return metrics(f).width(s, ls);
+ return metrics(f).width(str);
}
// handle small caps ourselves ...
int w = 0;
for (size_t i = 0; i < ls; ++i) {
- char const c = uppercase(s[i]);
- if (c != s[i])
- w += qsmallm.width(&c, 1);
+ QChar const c = str[i].upper();
+ if (c != str[i])
+ w += qsmallm.width(c);
else
- w += qm.width(&c, 1);
+ w += qm.width(c);
}
return w;
}