Optimize speed of QTextLayout and QPainter::drawText
Optimize speed of QTextLayout and QPainter::drawText

QFontEngine::boundingBox() is potentially an expensive function, because
the font engines have to consult the underlying font system for the
values and usually do not cache the results. To account for negative
right bearing in the case of text layouts, we would call the
boundingBox() function at every potential break point in the text,
causing a great performance hit on text drawing. To minimize the impact
of this, we only calculate the right bearing when we have to:

1. If subtracting the minimum right bearing from the width would cause
   the line to expand beyond its maximum line width, then we have to
   get the actual metrics of the last glyph to check if we need to break.

2. The line's final textWidth should include the negative right bearing,
   so unless it has already been calculated, we calculate it when the
   correct line width has been found.

This gives us a potentially huge speed-up, since boundingBox() will in
the common case only be called once for the last glyph in each text
line.

Task-number: QTBUG-9074
Reviewed-by: Simon Hausmann

pruiz/wkhtmltopdf-qt,pruiz/wkhtmltopdf-qt,pruiz/wkhtmltopdf-qt,igor-sfdc/qt-wk,igor-sfdc/qt-wk,pruiz/wkhtmltopdf-qt,igor-sfdc/qt-wk,pruiz/wkhtmltopdf-qt,igor-sfdc/qt-wk,pruiz/wkhtmltopdf-qt,igor-sfdc/qt-wk,igor-sfdc/qt-wk,pruiz/wkhtmltopdf-qt,igor-sfdc/qt-wk,igor-sfdc/qt-wk,igor-sfdc/qt-wk,igor-sfdc/qt-wk,pruiz/wkhtmltopdf-qt,pruiz/wkhtmltopdf-qt,pruiz/wkhtmltopdf-qt,igor-sfdc/qt-wk,pruiz/wkhtmltopdf-qt