summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-05-19 05:18:27 (GMT)
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-05-21 14:48:47 (GMT)
commitc9607f069f0fb98021daf0af9f1d1b2981018e0c (patch)
tree354bcaa0d906550a2ec931a466d44bf97c6632ea /src/gui/text/qtextlayout.cpp
parent45d2c1ef0a9f8e1f035e122ffe69c15edc3fcb98 (diff)
downloadQt-c9607f069f0fb98021daf0af9f1d1b2981018e0c.zip
Qt-c9607f069f0fb98021daf0af9f1d1b2981018e0c.tar.gz
Qt-c9607f069f0fb98021daf0af9f1d1b2981018e0c.tar.bz2
Use binarysort to find items.
Task: http://bugreports.qt.nokia.com/browse/QTBUG-231 Reviwed-by: Eskil
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index ce7915d..94d9d67 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1208,7 +1208,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang
bool hasText = (selection.format.foreground().style() != Qt::NoBrush);
bool hasBackground= (selection.format.background().style() != Qt::NoBrush);
-
+
if (hasBackground) {
selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush));
// don't just clear the property, set an empty brush that overrides a potential
@@ -1715,7 +1715,7 @@ namespace {
};
inline bool LineBreakHelper::checkFullOtherwiseExtend(QScriptLine &line)
-{
+{
LB_DEBUG("possible break width %f, spacew=%f", tmpData.textWidth.toReal(), spaceData.textWidth.toReal());
QFixed newWidth = calculateNewWidth(line);
@@ -1781,13 +1781,23 @@ void QTextLine::layout_helper(int maxGlyphs)
bool breakany = (wrapMode == QTextOption::WrapAnywhere);
lbh.manualWrap = (wrapMode == QTextOption::ManualWrap || wrapMode == QTextOption::NoWrap);
- // #### binary search!
int item = -1;
- int newItem;
- for (newItem = eng->layoutData->items.size()-1; newItem > 0; --newItem) {
- if (eng->layoutData->items[newItem].position <= line.from)
+ int newItem = -1;
+ int left = 0;
+ int right = eng->layoutData->items.size()-1;
+ while(left <= right) {
+ int middle = ((right-left)/2)+left;
+ if (line.from > eng->layoutData->items[middle].position)
+ left = middle+1;
+ else if(line.from < eng->layoutData->items[middle].position)
+ right = middle-1;
+ else {
+ newItem = middle;
break;
+ }
}
+ if (newItem == -1)
+ newItem = right;
LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, eng->layoutData->items.size(), line.width.toReal());
@@ -1939,7 +1949,7 @@ void QTextLine::layout_helper(int maxGlyphs)
}
LB_DEBUG("reached end of line");
lbh.checkFullOtherwiseExtend(line);
-found:
+found:
if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted
lbh.adjustRightBearing();
line.textAdvance = line.textWidth;