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,26 +133,27 @@ public:
virtual void image(int x, int y, int w, int h, virtual void image(int x, int y, int w, int h,
graphics::Image const & image) = 0; 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 /** draw a string at position x, y (y is the baseline). The
* text direction is given by \c rtl. * 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, virtual void text(int x, int y, docstring const & str, FontInfo const & f,
bool rtl = false, double wordspacing = 0.0) = 0; bool rtl = false, double wordspacing = 0.0) = 0;
/** draw a string at position x, y (y is the baseline). The /** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font. * 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, virtual void text(int x, int y, docstring const & str, Font const & f,
double wordspacing = 0.0) = 0; double wordspacing = 0.0) = 0;
/** draw a string at position x, y (y is the baseline), but /** 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 * 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. * \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, virtual void text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to, Color other, size_type from, size_type to,
double const wordspacing) = 0; double const wordspacing) = 0;
@ -164,12 +165,6 @@ public:
double pixelRatio() const { return pixel_ratio_; } 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 /// draw the underbar, strikeout, uuline and uwave font attributes
virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0; 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, void GuiPainter::text(int x, int y, docstring const & s,
FontInfo const & f, bool const rtl, FontInfo const & f, bool const rtl,
double const wordspacing) double const wordspacing)
{ {
//LYXERR0("text: x=" << x << ", s=" << s); //LYXERR0("text: x=" << x << ", s=" << s);
if (s.empty()) if (s.empty() || !isDrawingEnabled())
return 0; return;
/* Caution: The following ucs4 to QString conversions work for symbol fonts /* Caution: The following ucs4 to QString conversions work for symbol fonts
only because they are no real conversions but simple casts in reality. 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) // Note that we have to take in account space stretching (word spacing)
int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') * wordspacing; int const textwidth = fm.width(s) + count(s.begin(), s.end(), ' ') * wordspacing;
if (!isDrawingEnabled())
return textwidth;
textDecoration(f, x, y, textwidth); textDecoration(f, x, y, textwidth);
if (use_pixmap_cache_) { if (use_pixmap_cache_) {
@ -428,7 +425,7 @@ int GuiPainter::text(int x, int y, docstring const & s,
if (QPixmapCache::find(key, pm)) { if (QPixmapCache::find(key, pm)) {
// Draw the cached pixmap. // Draw the cached pixmap.
drawPixmap(x + lb, y - mA, pm); drawPixmap(x + lb, y - mA, pm);
return textwidth; return;
} }
// Only the right bearing of the last character is // Only the right bearing of the last character is
@ -456,25 +453,24 @@ int GuiPainter::text(int x, int y, docstring const & s,
drawPixmap(x + lb, y - mA, pm); drawPixmap(x + lb, y - mA, pm);
//rectangle(x-lb, y-mA, w, h, Color_green); //rectangle(x-lb, y-mA, w, h, Color_green);
} }
return textwidth; return;
} }
// don't use the pixmap cache, // don't use the pixmap cache,
do_drawText(x, y, str, rtl, f, ff); do_drawText(x, y, str, rtl, f, ff);
//LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8()) //LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
// << " at " << x << "," << y); // << " at " << x << "," << y);
return textwidth;
} }
int GuiPainter::text(int x, int y, docstring const & str, Font const & f, void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
double const wordspacing) 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, void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
Color other, size_type const from, size_type const to, Color other, size_type const from, size_type const to,
double const wordspacing) double const wordspacing)
{ {
@ -495,7 +491,7 @@ int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
fi.setPaintColor(other); fi.setPaintColor(other);
QRegion const clip(x + xmin, y - ascent, xmax - xmin, height); QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
setClipRegion(clip); 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 // Then the part in normal color
// Note that in Qt5, it is not possible to use Qt::UniteClip, // 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); setClipRegion(region - clip);
text(x, y, str, fi, rtl, wordspacing); text(x, y, str, fi, rtl, wordspacing);
setClipping(false); setClipping(false);
return textwidth;
} }

View File

@ -107,29 +107,26 @@ public:
/** draw a string at position x, y (y is the baseline). The /** draw a string at position x, y (y is the baseline). The
* text direction is given by \c rtl. * 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, virtual void text(int x, int y, docstring const & str, FontInfo const & f,
bool rtl = false, double wordspacing = 0.0); bool rtl = false, double wordspacing = 0.0);
/** draw a string at position x, y (y is the baseline). The /** draw a string at position x, y (y is the baseline). The
* text direction is enforced by the \c Font. * 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, virtual void text(int x, int y, docstring const & str, Font const & f,
double wordspacing = 0.0); double wordspacing = 0.0);
/** draw a string at position x, y (y is the baseline), but /** 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 * 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. * \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, virtual void text(int x, int y, docstring const & str, Font const & f,
Color other, size_type from, size_type to, Color other, size_type from, size_type to,
double const wordspacing); double const wordspacing);
/// draw a char at position x, y (y is the baseline) /// 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); virtual void textDecoration(FontInfo const & f, int x, int y, int width);