Make the different Painter::text void methods

The textwidth value that was returned is not used anymore. Now in some
cases we can avoid to compute it at all.
This commit is contained in:
Jean-Marc Lasgouttes 2016-03-19 17:52:07 +01:00
parent 51b1cfab72
commit 333f6fcf07
3 changed files with 35 additions and 49 deletions

View File

@ -133,28 +133,29 @@ public:
virtual void image(int x, int y, int w, int h,
graphics::Image const & image) = 0;
/** draw a character at position x, y (y is the baseline)
*/
virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
/** draw a string at position x, y (y is the baseline). The
* text direction is given by \c rtl.
* \return the width of the drawn text.
*/
virtual int text(int x, int y, docstring const & str, FontInfo const & f,
bool rtl = false, double wordspacing = 0.0) = 0;
virtual void text(int x, int y, docstring const & str, FontInfo const & f,
bool rtl = false, double wordspacing = 0.0) = 0;
/** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font.
* \return the width of the drawn text.
*/
virtual int text(int x, int y, docstring const & str, Font const & f,
double wordspacing = 0.0) = 0;
virtual void text(int x, int y, docstring const & str, Font const & f,
double wordspacing = 0.0) = 0;
/** draw a string at position x, y (y is the baseline), but
* make sure that the part between \c from and \c to is in
* \c other color. The text direction is enforced by the \c Font.
* \return the width of the drawn text.
*/
virtual int text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to,
double const wordspacing) = 0;
virtual void text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to,
double const wordspacing) = 0;
void setDrawingEnabled(bool drawing_enabled)
{ drawing_enabled_ = drawing_enabled; }
@ -164,12 +165,6 @@ public:
double pixelRatio() const { return pixel_ratio_; }
/// draw a char at position x, y (y is the baseline)
/**
* \return the width of the drawn text.
*/
virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
/// draw the underbar, strikeout, uuline and uwave font attributes
virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;

View File

@ -327,9 +327,9 @@ void GuiPainter::image(int x, int y, int w, int h, graphics::Image const & i)
}
int GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
void GuiPainter::text(int x, int y, char_type c, FontInfo const & f)
{
return text(x, y, docstring(1, c), f);
text(x, y, docstring(1, c), f);
}
@ -368,13 +368,13 @@ void GuiPainter::do_drawText(int x, int y, QString str, bool rtl, FontInfo const
}
int GuiPainter::text(int x, int y, docstring const & s,
FontInfo const & f, bool const rtl,
double const wordspacing)
void GuiPainter::text(int x, int y, docstring const & s,
FontInfo const & f, bool const rtl,
double const wordspacing)
{
//LYXERR0("text: x=" << x << ", s=" << s);
if (s.empty())
return 0;
if (s.empty() || !isDrawingEnabled())
return;
/* Caution: The following ucs4 to QString conversions work for symbol fonts
only because they are no real conversions but simple casts in reality.
@ -406,9 +406,6 @@ int GuiPainter::text(int x, int y, docstring const & s,
// Note that we have to take in account space stretching (word spacing)
int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') * wordspacing;
if (!isDrawingEnabled())
return textwidth;
textDecoration(f, x, y, textwidth);
if (use_pixmap_cache_) {
@ -428,7 +425,7 @@ int GuiPainter::text(int x, int y, docstring const & s,
if (QPixmapCache::find(key, pm)) {
// Draw the cached pixmap.
drawPixmap(x + lb, y - mA, pm);
return textwidth;
return;
}
// Only the right bearing of the last character is
@ -456,27 +453,26 @@ int GuiPainter::text(int x, int y, docstring const & s,
drawPixmap(x + lb, y - mA, pm);
//rectangle(x-lb, y-mA, w, h, Color_green);
}
return textwidth;
return;
}
// don't use the pixmap cache,
do_drawText(x, y, str, rtl, f, ff);
//LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
// << " at " << x << "," << y);
return textwidth;
}
int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
double const wordspacing)
void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
double const wordspacing)
{
return text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing);
text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing);
}
int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
Color other, size_type const from, size_type const to,
double const wordspacing)
void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
Color other, size_type const from, size_type const to,
double const wordspacing)
{
GuiFontMetrics const & fm = getFontMetrics(f.fontInfo());
FontInfo fi = f.fontInfo();
@ -495,7 +491,7 @@ int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
fi.setPaintColor(other);
QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
setClipRegion(clip);
int const textwidth = text(x, y, str, fi, rtl, wordspacing);
text(x, y, str, fi, rtl, wordspacing);
// Then the part in normal color
// Note that in Qt5, it is not possible to use Qt::UniteClip,
@ -505,8 +501,6 @@ int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
setClipRegion(region - clip);
text(x, y, str, fi, rtl, wordspacing);
setClipping(false);
return textwidth;
}

View File

@ -107,29 +107,26 @@ public:
/** draw a string at position x, y (y is the baseline). The
* text direction is given by \c rtl.
* \return the width of the drawn text.
*/
virtual int text(int x, int y, docstring const & str, FontInfo const & f,
bool rtl = false, double wordspacing = 0.0);
virtual void text(int x, int y, docstring const & str, FontInfo const & f,
bool rtl = false, double wordspacing = 0.0);
/** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font.
* \return the width of the drawn text.
*/
virtual int text(int x, int y, docstring const & str, Font const & f,
double wordspacing = 0.0);
virtual void text(int x, int y, docstring const & str, Font const & f,
double wordspacing = 0.0);
/** draw a string at position x, y (y is the baseline), but
* make sure that the part between \c from and \c to is in
* \c other color. The text direction is enforced by the \c Font.
* \return the width of the drawn text.
*/
virtual int text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to,
double const wordspacing);
virtual void text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to,
double const wordspacing);
/// draw a char at position x, y (y is the baseline)
virtual int text(int x, int y, char_type c, FontInfo const & f);
virtual void text(int x, int y, char_type c, FontInfo const & f);
///
virtual void textDecoration(FontInfo const & f, int x, int y, int width);