mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-23 00:38:01 +00:00
* frontends/Painter:
- text(): now returns drawn text width() * rowpainter: - paintChars(): use the returned width from Painter::text() instead of recalculating it. All other files: implement the API change. qt3 and gtk not 100% guaranted to compile nor work. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15294 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f5f4b31f4a
commit
4add252628
@ -132,19 +132,26 @@ public:
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -196,7 +196,7 @@ inline XftFont * getXftFont(LyXFont const & f)
|
||||
} // 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)
|
||||
{
|
||||
@ -204,6 +204,8 @@ void GPainter::text(int x, int y,
|
||||
XftColor * xftClr = owner_.getColorHandler().
|
||||
getXftColor(f.realColor());
|
||||
XftDraw * draw = owner_.getXftDraw();
|
||||
int textwidth = 0;
|
||||
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
XftDrawString32(draw,
|
||||
xftClr,
|
||||
@ -211,11 +213,11 @@ void GPainter::text(int x, int y,
|
||||
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])));
|
||||
@ -223,35 +225,37 @@ void GPainter::text(int x, int y,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,16 +97,16 @@ public:
|
||||
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();
|
||||
|
@ -57,13 +57,13 @@ public:
|
||||
///
|
||||
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) {}
|
||||
|
@ -159,21 +159,21 @@ void QLPainter::image(int x, int y, int w, int h,
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -184,25 +184,27 @@ void QLPainter::smallCapsText(int x, int y,
|
||||
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;
|
||||
@ -235,18 +237,23 @@ void QLPainter::text(int x, int y, lyx::char_type const * s, size_t ls,
|
||||
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
|
||||
|
@ -98,22 +98,22 @@ public:
|
||||
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
|
||||
|
@ -183,13 +183,13 @@ void QLPainter::image(int x, int y, int w, int h,
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -222,7 +222,7 @@ int QLPainter::smallCapsText(int x, int y,
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
@ -260,6 +260,7 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls,
|
||||
underline(f, x, y, textwidth);
|
||||
}
|
||||
|
||||
return textwidth;
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,18 +103,18 @@ public:
|
||||
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
|
||||
|
@ -316,12 +316,11 @@ void RowPainter::paintChars(pos_type & vpos, LyXFont font,
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user