lyx::graphics::Image const & image) = 0;
/// draw a string at position x, y (y is the baseline)
- virtual void text(int x, int y,
+ /**
+ * \return the width of the drawn text.
+ */
+ virtual int text(int x, int y,
lyx::docstring const & str, LyXFont const & f) = 0;
/**
* 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 void text(int x, int y,
+ virtual int text(int x, int y,
lyx::char_type const * str, size_t l,
LyXFont const & f) = 0;
/// draw a char at position x, y (y is the baseline)
- virtual void text(int x, int y,
+ /**
+ * \return the width of the drawn text.
+ */
+ virtual int text(int x, int y,
lyx::char_type c, LyXFont const & f) = 0;
/**
} // anon namespace
-void GPainter::text(int x, int y,
+int GPainter::text(int x, int y,
char_type const * s, size_t ls,
LyXFont const & f)
{
XftColor * xftClr = owner_.getColorHandler().
getXftColor(f.realColor());
XftDraw * draw = owner_.getXftDraw();
+ int textwidth = 0;
+
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
XftDrawString32(draw,
xftClr,
x, y,
reinterpret_cast<FcChar32 const *>(s),
ls);
+ textwidth = font_metrics::width(s, ls, f);
} else {
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
XftFont * fontS = getXftFont(smallfont);
- int tmpx = x;
for (unsigned int i = 0; i < ls; ++i) {
// Ok, this looks quite ugly...
char_type c = gdk_keyval_to_unicode(gdk_keyval_to_upper(gdk_unicode_to_keyval(s[i])));
XftDrawString32(draw,
xftClr,
fontS,
- tmpx, y,
+ x + textwidth, y,
reinterpret_cast<FcChar32 *>(&c),
1);
- tmpx += font_metrics::width(c, smallfont);
+ textwidth += font_metrics::width(c, smallfont);
} else {
XftDrawString32(draw,
xftClr,
font,
- tmpx, y,
+ x + textwidth, y,
reinterpret_cast<FcChar32 *>(&c),
1);
- tmpx += font_metrics::width(c, f);
+ textwidth += font_metrics::width(c, f);
}
}
}
if (f.underbar() == LyXFont::ON)
- underline(f, x, y, font_metrics::width(s, ls, f));
+ underline(f, x, y, textwidth);
+
+ return textwidth;
}
-void GPainter::text(int x, int y, docstring const & s, LyXFont const & f)
+int GPainter::text(int x, int y, docstring const & s, LyXFont const & f)
{
- text (x, y, reinterpret_cast<char_type const *>(s.data()), s.size(), f);
+ return text (x, y, reinterpret_cast<char_type const *>(s.data()), s.size(), f);
}
-void GPainter::text(int x, int y, char_type c, LyXFont const & f)
+int GPainter::text(int x, int y, char_type c, LyXFont const & f)
{
- text (x, y, &c, 1, f);
+ return text (x, y, &c, 1, f);
}
graphics::Image const & image);
/// draw a string at position x, y (y is the baseline)
- virtual void text(int x, int y,
+ 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)
- virtual void text(int x, int y,
+ 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 void text(int x, int y,
+ virtual int text(int x, int y,
lyx::char_type c, LyXFont const & f);
void start();
///
void image(int, int, int, int, lyx::graphics::Image const &) {}
///
- void text(int, int, lyx::docstring const &, LyXFont const &) {}
+ int text(int, int, lyx::docstring const &, LyXFont const &) { return 0; }
// ///
-// void text(int, int, char const *, size_t, LyXFont const &) {}
+// int text(int, int, char const *, size_t, LyXFont const &) { return 0; }
///
- void text(int, int, lyx::char_type const *, size_t, LyXFont const &) {}
+ int text(int, int, lyx::char_type const *, size_t, LyXFont const &) { return 0; }
///
- void text(int, int, lyx::char_type, LyXFont const &) {}
+ int text(int, int, lyx::char_type, LyXFont const &) { return 0; }
///
void rectText(int, int, lyx::docstring const &,
LyXFont const &, LColor_color, LColor_color) {}
}
-void QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
+int QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
{
lyxerr << "Drawing string" << endl;
return text(x, y, reinterpret_cast<lyx::char_type const *>(s.data()), s.length(), f);
}
-void QLPainter::text(int x, int y, lyx::char_type c, LyXFont const & f)
+int QLPainter::text(int x, int y, lyx::char_type c, LyXFont const & f)
{
char_type s[2] = { c, L'\0' };
return text(x, y, s, 1, f);
}
-void QLPainter::smallCapsText(int x, int y,
+int QLPainter::smallCapsText(int x, int y,
QString const & s, LyXFont const & f)
{
LyXFont smallfont(f);
QFontMetrics const & qfontm = QFontMetrics(qfont);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
- int tmpx = x;
size_t ls = s.length();
+ int textwidth = 0;
for (size_t i = 0; i < ls; ++i) {
// Brain-dead MSVC wants at(i) rather than operator[]
QChar const c = s.at(i).upper();
if (c != s.at(i)) {
qp_->setFont(qsmallfont);
- qp_->drawText(tmpx, y, c);
- tmpx += qsmallfontm.width(c);
+ qp_->drawText(x + textwidth, y, c);
+ textwidth += qsmallfontm.width(c);
} else {
qp_->setFont(qfont);
- qp_->drawText(tmpx, y, c);
- tmpx += qfontm.width(c);
+ qp_->drawText(x + textwidth, y, c);
+ textwidth += qfontm.width(c);
}
}
+
+ return textwidth;
}
-void QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
+int QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
LyXFont const & f)
{
lyxerr << "Drawing lyx::char_type const * s" << endl;
str = ' ' + str;
#endif
+ int textwidth;
+
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
qp_->setFont(fontloader.get(f));
// We need to draw the text as LTR as we use our own bidi
// code.
qp_->drawText(x, y, str, -1, QPainter::LTR);
+ textwidth = qp_->fontMetrics().width(str);
} else {
- smallCapsText(x, y, str, f);
+ textwidth = smallCapsText(x, y, str, f);
}
if (f.underbar() == LyXFont::ON) {
- underline(f, x, y, qp_->fontMetrics().width(str));
+ underline(f, x, y, textwidth);
}
+
+ return textwidth;
}
} // namespace frontend
lyx::graphics::Image const & image);
/// draw a string at position x, y (y is the baseline)
- virtual void text(int x, int y,
+ 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 void text(int x, int y,
+ 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 void text(int x, int y,
+ virtual int text(int x, int y,
lyx::char_type c, LyXFont const & f);
private:
/// draw small caps text
- void smallCapsText(int x, int y,
+ int smallCapsText(int x, int y,
QString const & str, LyXFont const & f);
/// set pen parameters
}
-void QLPainter::text(int x, int y, docstring const & s, LyXFont const & f)
+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);
}
-void QLPainter::text(int x, int y, char_type c, LyXFont const & 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);
}
-void QLPainter::text(int x, int y, char_type const * s, size_t ls,
+int QLPainter::text(int x, int y, char_type const * s, size_t ls,
LyXFont const & f)
{
#if 0
underline(f, x, y, textwidth);
}
+ return textwidth;
}
lyx::graphics::Image const & image);
/// draw a string at position x, y (y is the baseline)
- virtual void text(int x, int y,
+ 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 void text(int x, int y,
+ 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 void text(int x, int y,
+ virtual int text(int x, int y,
lyx::char_type c, LyXFont const & f);
/// draw a pixmap from the image cache
// Draw text and set the new x position
//lyxerr << "paint row: yo_ " << yo_ << "\n";
#if 0
- pain_.text(int(x_), yo_, str, font);
- x_ += theApp->fontLoader().metrics(font).width(str);
+ int width = pain_.text(int(x_), yo_, str, font);
#else
- pain_.text(int(x_), yo_, &str[0], str.size(), font);
- x_ += theApp->fontLoader().metrics(font).width(&str[0], str.size());
+ int width = pain_.text(int(x_), yo_, &str[0], str.size(), font);
#endif
+ x_ += width;
}