Index: Version135/Scribus/scribus/pageitem_textframe.cpp
===================================================================
--- Version135/Scribus/scribus/pageitem_textframe.cpp	(wersja 16641)
+++ Version135/Scribus/scribus/pageitem_textframe.cpp	(kopia robocza)
@@ -155,9 +155,7 @@
 					if ((currentGroup != -1) && (docItem->Groups.count() != 0) && (currentGroup == docItem->Groups.top()))
 						continue;
 					if (docItem->textFlowAroundObject())
-					{
-						result = result.subtract(itemShape(docItem, Mp->xOffset() - Dp->xOffset(), Mp->yOffset() - Dp->yOffset()));
-					}
+						result = result.subtracted(itemShape(docItem, Mp->xOffset() - Dp->xOffset(), Mp->yOffset() - Dp->yOffset()));
 					if (docItem->isGroupControl)
 						currentGroup = docItem->Groups.top();
 				}
@@ -192,7 +190,7 @@
 					if ((currentGroup != -1) && (docItem->Groups.count() != 0) && (currentGroup == docItem->Groups.top()))
 						continue;
 					if (docItem->textFlowAroundObject())
-						result = result.subtract(itemShape(docItem, 0, 0));
+						result = result.subtracted(itemShape(docItem, 0, 0));
 					if (docItem->isGroupControl)
 						currentGroup = docItem->Groups.top();
 				}
@@ -522,7 +520,7 @@
 		double maxX = colRight - morespace;
 		if (legacy) maxX -= (lineCorr + insets.Right);
 
-		double StartX = floor(qMax(line.x, qMin(colRight,breakXPos) - 1));
+		double StartX = floor(qMax(line.x, qMin(maxX,breakXPos-maxShrink))-1);
 		int xPos  = static_cast<int>(ceil(maxX + insets.Right));
 		int yDesc = static_cast<int>(yPos+line.descent);
 		int yAsc  = static_cast<int>(ceil(yPos-line.ascent));
@@ -560,7 +558,7 @@
 		double Interval = 0.125;
 		do {
 			EndX2 += Interval;
-			int xPos = qRound(ceil(EndX2 + insets.Right));
+			int xPos = qRound(ceil(EndX2));
 			pt12.setX (xPos);
 			pt22.setX (xPos);
 		} while ((EndX2 < maxX) && shape.contains(pf2.map(pt12)) && shape.contains(pf2.map(pt22)));
@@ -1420,6 +1418,17 @@
 				// find linelength:
 				pt1 = QPoint(static_cast<int>(ceil(current.xPos)), static_cast<int>(current.yPos+BotOffset));
 				pt2 = QPoint(static_cast<int>(ceil(current.xPos)), static_cast<int>(ceil(current.yPos-TopOffset)));
+				while (current.xPos < current.colRight)
+				{
+					if (!cl.contains(pf2.map(pt1)) || !cl.contains(pf2.map(pt2)))
+					{
+						current.xPos += 0.125;
+						pt1.setX(static_cast<int>(ceil(current.xPos)));
+						pt2.setX(static_cast<int>(ceil(current.xPos)));
+					}
+					else break;
+				}
+				// find linelength:
 				// increase pt1/pt2 until i-beam reaches end of line
 //				qDebug() << QString("linestart: %1 + %2 + %3 < %4").arg(current.xPos).arg(wide).arg(style.rightMargin()).arg(current.colRight);
 				double leftIndent = 0;
@@ -1631,24 +1640,24 @@
 			{
 				if (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN)
 				{
-					pt1 = QPoint(qRound(ceil(current.xPos+extra.Right - current.maxShrink + charStyle.font().charWidth('-', charStyle.fontSize() / 10.0) * (charStyle.scaleH() / 1000.0))), qRound(current.yPos+desc));
-					pt2 = QPoint(qRound(ceil(current.xPos+extra.Right - current.maxShrink + charStyle.font().charWidth('-', charStyle.fontSize() / 10.0) * (charStyle.scaleH() / 1000.0))), qRound(ceil(current.yPos-asce)));
+					pt1 = QPoint(qRound(ceil(current.xPos - current.maxShrink + charStyle.font().charWidth('-', charStyle.fontSize() / 10.0) * (charStyle.scaleH() / 1000.0))), qRound(current.yPos+desc));
+					pt2 = QPoint(qRound(ceil(current.xPos - current.maxShrink + charStyle.font().charWidth('-', charStyle.fontSize() / 10.0) * (charStyle.scaleH() / 1000.0))), qRound(ceil(current.yPos-asce)));
 				}
 				else
 				{
-					pt1 = QPoint(qRound(ceil(current.xPos+extra.Right - current.maxShrink )), qRound(current.yPos+desc));
-					pt2 = QPoint(qRound(ceil(current.xPos+extra.Right - current.maxShrink )), qRound(ceil(current.yPos-asce)));
+					pt1 = QPoint(qRound(ceil(current.xPos - current.maxShrink )), qRound(current.yPos+desc));
+					pt2 = QPoint(qRound(ceil(current.xPos - current.maxShrink )), qRound(ceil(current.yPos-asce)));
 				}
 			}
 			else if (!legacy && SpecialChars::isBreakingSpace(hl->ch))
 			{
-				pt1 = QPoint(qRound(ceil(breakPos + extra.Right - current.maxShrink )), qRound(current.yPos+desc));
-				pt2 = QPoint(qRound(ceil(breakPos + extra.Right - current.maxShrink )), qRound(ceil(current.yPos-asce)));
+				pt1 = QPoint(qRound(ceil(breakPos - current.maxShrink )), qRound(current.yPos+desc));
+				pt2 = QPoint(qRound(ceil(breakPos - current.maxShrink )), qRound(ceil(current.yPos-asce)));
 			}
 			else
 			{
-				pt1 = QPoint(qRound(ceil(current.xPos+extra.Right - current.maxShrink)), qRound(current.yPos+desc));
-				pt2 = QPoint(qRound(ceil(current.xPos+extra.Right - current.maxShrink)), qRound(ceil(current.yPos-asce)));
+				pt1 = QPoint(qRound(ceil(current.xPos - current.maxShrink)), qRound(current.yPos+desc));
+				pt2 = QPoint(qRound(ceil(current.xPos - current.maxShrink)), qRound(ceil(current.yPos-asce)));
 			}
 			
 			// test if end of line reached
@@ -1728,7 +1737,6 @@
 //				qDebug() << QString("dropcapoffset: %1 -> %2").arg(current.xPos-style.dropCapOffset()).arg(current.xPos);
 				current.xPos = qMax(current.xPos, current.colLeft);
 				maxDX = current.xPos;
-				QPolygon tcli(4);
 				if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing)
 				{
 					current.yPos -= m_Doc->typographicSettings.valueBaseGrid * (DropLines-1);
@@ -1739,9 +1747,6 @@
 					int ol2 = static_cast<int>(ol1 / m_Doc->typographicSettings.valueBaseGrid);
 //					qDebug() << QString("baseline adjust after dropcaps: y=%1->%2").arg(current.yPos).arg(ceil(  ol2 / 10000.0 ) * m_Doc->typographicSettings.valueBaseGrid + m_Doc->typographicSettings.offsetBaseGrid - by);
 					current.yPos = ceil(  ol2 / 10000.0 ) * m_Doc->typographicSettings.valueBaseGrid + m_Doc->typographicSettings.offsetBaseGrid - by;
-					//FIXME: use current.colLeft instead of xOffset?
-					tcli.setPoint(0, QPoint(qRound(hl->glyph.xoffset), qRound(maxDY-DropLines*m_Doc->typographicSettings.valueBaseGrid)));
-					tcli.setPoint(1, QPoint(qRound(maxDX), qRound(maxDY-DropLines*m_Doc->typographicSettings.valueBaseGrid)));
 				}
 				else
 				{
@@ -1749,25 +1754,14 @@
 					{
 						current.yPos -= style.lineSpacing() * (DropLines-1);
 //						qDebug() << QString("after dropcaps: y=%1").arg(current.yPos);
-						tcli.setPoint(0, QPoint(qRound(hl->glyph.xoffset), qRound(maxDY - DropLines * style.lineSpacing())));
-						tcli.setPoint(1, QPoint(qRound(maxDX), qRound(maxDY-DropLines*style.lineSpacing())));
 					}
 					else
 					{
 						double currasce = charStyle.font().height(style.charStyle().fontSize() / 10.0);
 						current.yPos -= currasce * (DropLines-1);
 //						qDebug() << QString("after dropcaps: y=%1").arg(current.yPos);
-						tcli.setPoint(0, QPoint(qRound(hl->glyph.xoffset), qRound(maxDY-DropLines*currasce)));
-						tcli.setPoint(1, QPoint(qRound(maxDX), qRound(maxDY-DropLines*currasce)));
 					}
 				}
-				tcli.setPoint(2, QPoint(qRound(maxDX), qRound(maxDY)));
-				tcli.setPoint(3, QPoint(qRound(hl->glyph.xoffset), qRound(maxDY)));
-				// #6821 : the following two lines are causing bad text flow around drop caps 
-				// in some case, discarding them put more emphasis on user control of line spacing
-				/*cm = QRegion(pf2.map(tcli));
-				cl = cl.subtract(cm);*/
-//				current.yPos = maxDY;
 			}
 			// end of line
 			if ( SpecialChars::isBreak(hl->ch, Cols > 1) || (outs))
@@ -1909,8 +1903,16 @@
 							}
 							else
 							{
-								--a;
-								--current.itemsInLine;
+								if (current.line.firstItem == 0)
+								{
+									a = -1;
+									current.itemsInLine = 0;
+								}
+								else
+								{
+									--a;
+									--current.itemsInLine;
+								}
 							}
 						}
 						if (a >= 0)
@@ -1925,17 +1927,6 @@
 							else if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing)
 								style.setLineSpacing(m_Doc->typographicSettings.valueBaseGrid);
 						}
-						current.breakLine(itemText, style, firstLineOffset(), a);
-//						qDebug() << QString("style no break pos %1: %2 (%3)").arg(a).arg(style.alignment()).arg(style.parent());
-//						qDebug() << QString("style nb @%6: %1 -- %2, %4/%5 char: %3").arg(style.leftMargin()).arg(style.rightMargin())
-//							   .arg(style.charStyle().asString()).arg(style.name()).arg(style.parent())
-//							   .arg(a);
-						EndX = current.endOfLine(cl, pf2, style.rightMargin());
-						current.finishLine(EndX);
-//						qDebug() << QString("no break pos: %1-%2 @ %3 wid %4 nat %5 endX %6")
-//							   .arg(current.line.firstItem).arg(current.line.firstItem)
-//							   .arg(current.line.x).arg(current.line.width).arg(current.line.naturalWidth).arg(EndX);
-						indentLine(itemText, current.line, 0);
 					}
 				}
 				if ( outs || SpecialChars::isBreak(hl->ch, (Cols > 1)) )
@@ -1946,8 +1937,6 @@
 							&& current.hasDropCap)
 						{
 							current.hasDropCap = false;
-							if (current.yPos < maxDY)
-								current.yPos = maxDY;
 //							qDebug() << QString("after dropcaps: y=%1 maxDY=%2").arg(current.yPos).arg(maxDY);
 						}
 						bool fromOut = true;
@@ -1981,7 +1970,10 @@
 										current.xPos = current.colLeft;
 									}
 									else
-										current.xPos = maxDX;
+										if (current.itemsInLine > 0)
+											current.xPos = maxDX;
+										else
+											current.xPos = current.colLeft;
 								}
 								else
 									current.xPos = current.colLeft;
@@ -2080,7 +2072,7 @@
 
 				// calc. needed vertical space
 				// Let’s try to change into "calc. _wanted_ vertical space" - pm
-				if (current.itemsInLine != 0)
+				if (current.itemsInLine > 0)
 				{
 					if ( itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap)
 					{
@@ -2090,12 +2082,12 @@
 					}
 				}
 				
-				fillInTabLeaders(itemText, current.line);
-
+				if (current.itemsInLine > 0)
+					fillInTabLeaders(itemText, current.line);
 				current.startOfCol = false;
 //				qDebug() << QString("layout: line %1 - %2 @ (%3,%4) wd %5/%6").arg(current.line.firstItem).arg(current.line.lastItem)
 //					   .arg(current.line.x).arg(current.line.y).arg(current.line.naturalWidth).arg(current.line.width);
-				if (current.line.firstItem > current.line.lastItem)
+				if (current.line.firstItem >= current.line.lastItem)
 					; //qDebug() << QString("layout: empty line %1 - %2").arg(current.line.firstItem).arg(current.line.lastItem);
 				else if (current.itemsInLine > 0)
 					itemText.appendLine(current.line);
