Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp	(revision 13359)
+++ scribus/pageitem_textframe.cpp	(working copy)
@@ -493,19 +493,44 @@
 	/// find x position where this line must end
 	double endOfLine(const QRegion& shape, const QMatrix& pf2, double ascent, double descent, double morespace = 0)
 	{
-		double EndX = floor(qMax(line.x, qMin(colRight,breakXPos) - 1));
-		QPoint pt1, pt2;
-		//	qDebug() << QString("endx start=%1, hl is '%2'").arg(EndX).arg(hl->ch);
-		do {
-			EndX += 0.125;
-			pt1 = QPoint(qRound(ceil(EndX + insets.Right)), static_cast<int>(yPos+descent));
-			pt2 = QPoint(qRound(ceil(EndX + insets.Right)), static_cast<int>(ceil(yPos-ascent)));
-		} while 
-			(   (EndX + (legacy? lineCorr + insets.Right : 0) < colRight - morespace)
-			  && shape.contains(pf2.map(pt1))
-			  && shape.contains(pf2.map(pt2)) 
-			  );
-		
+                // if we aren't restricted further, we'll end at this maxX:
+                double maxX = colRight - morespace;
+                if (legacy) maxX -= lineCorr + insets.Right;
+
+		double StartX = floor(qMax(line.x, qMin(colRight,breakXPos) - 1));
+                int xPos = static_cast<int>(ceil(maxX + insets.Right));
+                int yDesc = static_cast<int>(yPos+descent);
+                int yAsc = static_cast<int>(ceil(yPos-ascent));
+
+                QPoint pt1 (xPos, yDesc);
+                QPoint pt2 (xPos, yAsc);
+
+                // simple and fast case: transformed line completely falls within range
+                // this will happen if we don't wrap around anything - ie. very often
+                QPolygon p;
+                p.append (pf2.map (QPoint (StartX, yAsc)));
+                p.append (pf2.map (QPoint (StartX, yDesc)));
+                p.append (pf2.map (pt1));
+                p.append (pf2.map (pt2));
+                // check if something gets in the way
+                QRegion line = shape.intersected (p.boundingRect());
+                // if the intersection only has 1 rectangle, then nothing gets in the way
+                if (line.numRects() == 1) return maxX;
+
+                // qDebug()<<"endOfLine: going for the hard case";
+                double EndX;
+	        double Interval = 0.125;
+                EndX = StartX;
+                do {
+                        EndX += Interval;
+                        int xPos = static_cast<int>(ceil(EndX + insets.Right));
+                        pt1.setX (xPos);
+                        pt2.setX (xPos);
+                } while 
+                        ((EndX < maxX)
+                          && shape.contains(pf2.map(pt1))
+                          && shape.contains(pf2.map(pt2)) 
+                          );
 		return EndX;
 	}
 	
