r15028 by jghali - #9060 : centered text with umlauts gets uncentered

scribus-commit scribus-commit at lists.scribus.net
Sat May 1 16:40:19 CEST 2010


Revision: 15028
Author: jghali
Date: 2010-05-01T14:39:37.696005Z
Commit message: #9060 : centered text with umlauts gets uncentered

Changeset: 
M  /branches/Version135/Scribus/scribus/pageitem_textframe.cpp

Diffs:
Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp	(revision 15027)
+++ scribus/pageitem_textframe.cpp	(revision 15028)
@@ -336,6 +336,7 @@
 	double   colRight;
 	int      column;
 	bool     startOfCol;
+	bool     hasDropCap;
 	double   ascend;
 	double   descend;
 	double   width;
@@ -386,7 +387,8 @@
 		init fields for a new line at current position
 	 */
 	void startLine(int first)
-	{		
+	{	
+		hasDropCap = false;
 		itemsInLine = 0;
 		line.x = xPos;
 		line.y = yPos;
@@ -442,7 +444,7 @@
 	}
 	
 	/// called when a mandatory break is found
-	void breakLine(const StoryText& itemText, int last)
+	void breakLine(const StoryText& itemText, const ParagraphStyle& style, FirstLineOffsetPolicy offsetPolicy, int last)
 	{
 		breakIndex = last;
 		breakXPos  = line.x;
@@ -452,6 +454,8 @@
 		// #8194, #8717 : update line ascent and descent with sensible values
 		// so that endOfLine() returns correct result
 		updateHeightMetrics(itemText);
+		// #9060 : update line offset too
+		updateLineOffset(itemText, style, offsetPolicy);
 	}
 	
 	/// use the last remembered break to set line width and itemrange
@@ -683,7 +687,45 @@
 		}
 	}
 	
-	
+	void updateLineOffset(const StoryText& itemText, const ParagraphStyle& style, FirstLineOffsetPolicy offsetPolicy)
+	{
+		if (itemsInLine <= 0)
+			return;
+		if ((!hasDropCap) && (startOfCol) && (style.lineSpacingMode() != ParagraphStyle::BaselineGridLineSpacing))
+		{
+			//FIXME: use glyphs, not chars
+			double firstasce = itemText.charStyle(line.firstItem).font().ascent(itemText.charStyle(line.firstItem).fontSize() / 10.0);
+			double adj (0.0);
+			double currasce (this->getLineAscent(itemText));
+			if( offsetPolicy == FLOPRealGlyphHeight )
+			{
+				adj = firstasce - currasce;
+			}
+			else if( offsetPolicy == FLOPFontAscent )
+			{
+				adj = 0.0;
+			}
+			else if( offsetPolicy == FLOPLineSpacing )
+			{
+				adj = firstasce - style.lineSpacing();
+			}
+			line.ascent = currasce;
+			line.y -= adj;
+			yPos -= adj;
+		}
+		else if ((!startOfCol) && (style.lineSpacingMode() == ParagraphStyle::AutomaticLineSpacing))
+		{
+			QChar ch = itemText.text(line.firstItem);
+			double firstasce = style.lineSpacing();
+			double currasce  = getLineHeight(itemText);						
+			double adj = firstasce - currasce;
+//			qDebug() << QString("move2 line %1.. down by %2").arg(current.line.firstItem).arg(-adj);
+			line.ascent = currasce;
+			line.y -= adj;
+			yPos -= adj;
+		}
+	}
+
 private:
 	double frameWidth;
 	double frameHeight;
@@ -920,7 +962,6 @@
 	tTabValues.clear();
 	
 	bool DropCmode = false;
-	bool AbsHasDrop = false;
 	double desc=0, asce=0, maxDY=0, desc2=0, maxDX=0;
 	double DropCapDrop = 0;
 	int    DropLines = 0;
@@ -1447,7 +1488,7 @@
 					pt2 = QPoint(static_cast<int>(ceil(current.xPos)), static_cast<int>(ceil(current.yPos-TopOffset)));
 				}
 
-				if (((fBorder)) && (!AbsHasDrop))
+				if (((fBorder)) && (!current.hasDropCap))
 					current.xPos += extra.Left;
 				// indent first line of par
 				if (a > 0)
@@ -1461,7 +1502,7 @@
 						current.xPos += style.firstIndent();
 				}
 				// add left margin
-				if (!AbsHasDrop)
+				if (!current.hasDropCap)
 					current.xPos += style.leftMargin();
 				if (opticalMargins & ParagraphStyle::OM_LeftHangingPunct) {
 					current.xPos += opticalLeftMargin(itemText, current.line);
@@ -1666,9 +1707,9 @@
 			if (DropCmode)
 			{
 				DropCmode = false;
-				AbsHasDrop = true;
 				DropLinesCount = 0;
 				maxDY = current.yPos;
+				current.hasDropCap = true;
 				current.xPos += style.dropCapOffset();
 				hl->glyph.xadvance += style.dropCapOffset();
 //				qDebug() << QString("dropcapoffset: %1 -> %2").arg(current.xPos-style.dropCapOffset()).arg(current.xPos);
@@ -1723,7 +1764,7 @@
 				if (SpecialChars::isBreak(hl->ch, Cols > 1))
 				{
 					// find end of line
-					current.breakLine(itemText, a);
+					current.breakLine(itemText, style, firstLineOffset(), a);
 					EndX = current.endOfLine(cl, pf2, style.rightMargin());
 					current.finishLine(EndX);
 					
@@ -1792,6 +1833,7 @@
 						}
 						
 						current.updateHeightMetrics(itemText);
+						current.updateLineOffset(itemText, style, firstLineOffset());
 						EndX = current.endOfLine(cl, pf2, style.rightMargin());
 						current.finishLine(EndX);
 
@@ -1870,7 +1912,7 @@
 							else if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing)
 								style.setLineSpacing(m_Doc->typographicSettings.valueBaseGrid);
 						}
-						current.breakLine(itemText, a);
+						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())
@@ -1888,9 +1930,9 @@
 					if (outs && !current.isEndOfLine(hl->glyph.wide() + style.rightMargin()))
 					{
 						if (( hl->ch == SpecialChars::PARSEP || hl->ch == SpecialChars::LINEBREAK) 
-							&& AbsHasDrop)
+							&& current.hasDropCap)
 						{
-							AbsHasDrop = false;
+							current.hasDropCap = false;
 							if (current.yPos < maxDY)
 								current.yPos = maxDY;
 //							qDebug() << QString("after dropcaps: y=%1 maxDY=%2").arg(current.yPos).arg(maxDY);
@@ -1917,12 +1959,12 @@
 //									qDebug() << QString("go no room 1: %1").arg(a));
 									break;
 								}
-								if (AbsHasDrop)
+								if (current.hasDropCap)
 								{
 									++DropLinesCount;
 									if (DropLinesCount >= DropLines)
 									{
-										AbsHasDrop = false;
+										current.hasDropCap = false;
 										current.xPos = current.colLeft;
 									}
 									else
@@ -1968,9 +2010,9 @@
 					else
 					{
 						if (( hl->ch == SpecialChars::PARSEP || hl->ch == SpecialChars::LINEBREAK ) 
-							&& AbsHasDrop)
+							&& current.hasDropCap)
 						{
-							AbsHasDrop = false;
+							current.hasDropCap = false;
 							if (current.yPos < maxDY)
 								current.yPos = maxDY;
 //							qDebug() << QString("after dropcap2: y=%1+%2").arg(current.yPos).arg(maxDY);
@@ -1997,12 +2039,12 @@
 								lineSpacing = m_Doc->typographicSettings.valueBaseGrid;
 							current.yPos += lineSpacing;
 						}
-						if (AbsHasDrop)
+						if (current.hasDropCap)
 						{
 							++DropLinesCount;
 							if (DropLinesCount >= DropLines)
 							{
-								AbsHasDrop = false;
+								current.hasDropCap = false;
 								current.xPos = current.colLeft;
 							}
 							else
@@ -2027,89 +2069,6 @@
 				// Let’s try to change into "calc. _wanted_ vertical space" - pm
 				if (current.itemsInLine != 0)
 				{
-					if ((!AbsHasDrop) && (current.startOfCol) && (style.lineSpacingMode() != ParagraphStyle::BaselineGridLineSpacing))
-					{
-						//FIXME: use glyphs, not chars
-						double firstasce = itemText.charStyle(current.line.firstItem).font().ascent(itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-						double adj (0.0);
-						double currasce (current.getLineAscent(itemText));
-						if( firstLineOffset() == FLOPRealGlyphHeight )
-						{
-							adj = firstasce - currasce;
-						}
-						else if( firstLineOffset() == FLOPFontAscent )
-						{
-							adj = 0.0;
-						}
-						else if( firstLineOffset() == FLOPLineSpacing )
-						{
-							adj = firstasce - style.lineSpacing();
-						}
-// 						qDebug() << QString("firstLineOffsetP ADJ FASC CASC %1 %2 %3 %4").arg(firstLineOffsetP).arg(adj).arg(firstasce).arg(currasce).toAscii();
-							/*0;
-						if ((itemText.text(current.line.firstItem) == SpecialChars::PARSEP) || (itemText.text(current.line.firstItem) == SpecialChars::LINEBREAK))
-							currasce = itemText.charStyle(current.line.firstItem).font().ascent(itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-						else if (itemText.object(current.line.firstItem) != 0)
-							currasce = qMax(currasce, (itemText.object(current.line.firstItem)->gHeight + itemText.object(current.line.firstItem)->lineWidth()) * (itemText.charStyle(current.line.firstItem).scaleV() / 1000.0));
-						else //if (itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap == 0)
-							currasce = itemText.charStyle(current.line.firstItem).font().realCharAscent(itemText.text(current.line.firstItem), itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-						for (int zc = 0; zc < current.itemsInLine; ++zc)
-						{
-							QChar ch = itemText.text(current.line.firstItem + zc);
-							if (ch == SpecialChars::PAGENUMBER)
-								ch = '8'; //should have highest ascender even in oldstyle
-							const CharStyle& cStyle(itemText.charStyle(current.line.firstItem + zc));
-							if ((ch == SpecialChars::TAB) || (ch == QChar(10))
-								|| (ch == SpecialChars::PARSEP) || (ch == SpecialChars::NBHYPHEN)
-								|| (ch == SpecialChars::COLBREAK) || (ch == SpecialChars::LINEBREAK)
-								|| (ch == SpecialChars::FRAMEBREAK) || (ch.isSpace()))
-								continue;
-							double asce;
-							if (itemText.object(current.line.firstItem + zc) != 0)
-								asce = (itemText.object(current.line.firstItem + zc)->gHeight + itemText.object(current.line.firstItem + zc)->lineWidth()) * (cStyle.scaleV() / 1000.0);
-							else //if (itemText.charStyle(current.line.firstItem + zc).effects() & ScStyle_DropCap == 0)
-								asce = cStyle.font().realCharAscent(ch, cStyle.fontSize() / 10.0);
-//							qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(currasce);
-						currasce = qMax(currasce, asce);
-						}*/
-//						qDebug() << QString("move1 line %1.. down by %2").arg(current.line.firstItem).arg(-adj);
-						current.line.ascent = currasce;
-						current.line.y -= adj;
-						current.yPos -= adj;
-					}
-					else if ((!current.startOfCol) && (style.lineSpacingMode() == ParagraphStyle::AutomaticLineSpacing))
-					{
-						QChar ch = itemText.text(current.line.firstItem);
-						double firstasce = style.lineSpacing();
-						double currasce = current.getLineHeight(itemText);
-						/*0;
-						if (itemText.object(current.line.firstItem) != 0)
-							currasce = qMax(currasce, (itemText.object(current.line.firstItem)->gHeight + itemText.object(current.line.firstItem)->lineWidth()) * (itemText.charStyle(current.line.firstItem).scaleV() / 1000.0));
-						else //if (itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap == 0)
-							currasce = itemText.charStyle(current.line.firstItem).font().height(itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-						for (int zc = 0; zc < current.itemsInLine; ++zc)
-						{
-							QChar ch = itemText.text(current.line.firstItem + zc);
-							if ((ch == SpecialChars::TAB) || (ch == QChar(10))
-								|| (ch == SpecialChars::PARSEP) || (ch == SpecialChars::NBHYPHEN)
-								|| (ch == SpecialChars::COLBREAK) || (ch == SpecialChars::FRAMEBREAK)
-								|| (ch == SpecialChars::LINEBREAK) || (ch.isSpace()))
-								continue;
-							double asce;
-							if (itemText.object(current.line.firstItem + zc) != 0)
-								asce = (itemText.object(current.line.firstItem + zc)->gHeight + itemText.object(current.line.firstItem + zc)->lineWidth()) * (itemText.charStyle(current.line.firstItem + zc).scaleV() / 1000.0);
-							else //if (itemText.charStyle(current.line.firstItem + zc).effects() & ScStyle_DropCap == 0)
-								asce = itemText.charStyle(current.line.firstItem + zc).font().height(itemText.charStyle(current.line.firstItem + zc).fontSize() / 10.0);
-//							qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(currasce);
-							currasce = qMax(currasce, asce);
-						}
-						*/							
-						double adj = firstasce - currasce;
-//						qDebug() << QString("move2 line %1.. down by %2").arg(current.line.firstItem).arg(-adj);
-						current.line.ascent = currasce;
-						current.line.y -= adj;
-						current.yPos -= adj;
-					}
 					if ( itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap)
 					{
 						// put line back to top
@@ -2121,42 +2080,6 @@
 				fillInTabLeaders(itemText, current.line);
 
 				current.startOfCol = false;
-/* has no effect except setting wide, asce and desc
- 				uint loopC = BuPos3;
-				if (m_Doc->guidesSettings.showControls)
-					loopC++;  // ??? AV
-				for (int zc = 0; zc < loopC; ++zc)
-				{
-					if ( zc >= current.itemsInLine) {
-						qDebug("layout: zc too large %d / %d", zc, current.itemsInLine);
-						continue;
-					}
-					if ( startLin + zc >= itemText.length()) {
-						qDebug("layout: startLin+zc too large %d+%d / %d", startLin, zc, itemText.length());
-						continue;
-					}
-//					else
-//						qDebug("layout: startLin, zc ok. %d, %d, %d", startLin, zc, LiList.count());
-					double wide2 = 0;
-					double xcoZli = itemText.item(current.line.firstItem + zc)->glyph.xoffset;
-//					itemText.item(startLin+zc)->glyph.xoffset = Zli2->xco;
-///					itemText.item(startLin+zc)->glyph.yoffset = Zli2->yco;
-					tTabValues = itemText.paragraphStyle(startLin+zc).tabValues();
-					desc = - itemText.charStyle(startLin+zc).font().descent(itemText.charStyle(startLin+zc).fontSize() / 10.0);
-					asce = itemText.charStyle(startLin+zc).font().ascent(itemText.charStyle(startLin+zc).fontSize() / 10.0);
-					bool Sele = itemText.selected(startLin+zc);
-					if (((Sele && (Select)) || (((NextBox != 0) || (BackBox != 0)) && Sele)) && (m_Doc->appMode == modeEdit))
-					{
-						wide = itemText.item(startLin+zc)->glyph.xadvance;
-						if ((zc > 0) && (itemText.text(startLin+zc) == SpecialChars::TAB))
-						{
-							wide2 = itemText.item(startLin+zc-1)->glyph.xadvance;
-							xcoZli = itemText.item(startLin+zc-1)->glyph.xoffset + wide2;
-							wide = itemText.item(startLin+zc)->glyph.xoffset - xcoZli + itemText.item(startLin+zc)->glyph.xadvance;
-						}
-					}
-				}
-				*/
 //				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)
@@ -2197,7 +2120,7 @@
 // end of itemText
 		int a = itemText.length()-1;
 		hl = a >=0 ? itemText.item(a) : NULL;
-		current.breakLine(itemText, a);
+		current.breakLine(itemText, style, firstLineOffset(), a);
 		EndX = current.endOfLine(cl, pf2, style.rightMargin());
 		current.finishLine(EndX);
 
@@ -2234,92 +2157,6 @@
 
 		if (current.itemsInLine != 0)
 		{
-			if ((!AbsHasDrop) && (current.startOfCol) && (style.lineSpacingMode() != ParagraphStyle::BaselineGridLineSpacing))
-			{
-				double firstasce = itemText.charStyle(current.line.firstItem).font().ascent(itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-				double adj (0.0);
-				double currasce (current.getLineAscent(itemText));
-				if( firstLineOffset() == FLOPRealGlyphHeight )
-				{
-					adj = firstasce - currasce;
-				}
-				else if( firstLineOffset() == FLOPFontAscent )
-				{
-					adj = 0.0;
-				}
-				else if( firstLineOffset() == FLOPLineSpacing )
-				{
-					adj = firstasce - style.lineSpacing();
-				}
-				/*0;
-				double asce;
-				if ((itemText.text(current.line.firstItem) == SpecialChars::PARSEP) || (itemText.text(current.line.firstItem) == SpecialChars::LINEBREAK))
-					asce = itemText.charStyle(current.line.firstItem).font().ascent(itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-				else if (itemText.object(current.line.firstItem) != 0)
-					asce = (itemText.object(current.line.firstItem)->gHeight + itemText.object(current.line.firstItem)->lineWidth()) * (itemText.charStyle(current.line.firstItem).scaleV() / 1000.0));
-				else //if (itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap == 0)
-					asce = itemText.charStyle(current.line.firstItem).font().realCharAscent(itemText.text(current.line.firstItem), itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-				qDebug() << QString("starting with ascender %1 (firstasce=%2)").arg(asce).arg(firstasce);
-				currasce = asce;
-				for (int zc = 0; zc < current.itemsInLine; ++zc)
-				{
-					QChar ch = itemText.text(current.line.firstItem+zc);
-					if (ch == SpecialChars::PAGENUMBER)
-						ch = '8'; // should have highest ascender even in oldstyle
-					if ((ch == SpecialChars::TAB) || (ch == QChar(10))
-						|| (ch == SpecialChars::PARSEP) || (ch == SpecialChars::NBHYPHEN)
-						|| (ch == SpecialChars::FRAMEBREAK) || (ch == SpecialChars::COLBREAK)
-						|| (ch == SpecialChars::LINEBREAK) || (ch.isSpace()))
-						continue;
-					if (itemText.object(current.line.firstItem+zc) != 0)
-						asce = (itemText.object(current.line.firstItem+zc)->gHeight + itemText.object(current.line.firstItem+zc)->lineWidth()) * itemText.charStyle(current.line.firstItem+zc).scaleV() / 1000.0);
-					else //if (itemText.charStyle(current.line.firstItem+zc).effects() & ScStyle_DropCap == 0)
-						asce = itemText.charStyle(current.line.firstItem+zc).font().realCharAscent(itemText.text(current.line.firstItem+zc), itemText.charStyle(current.line.firstItem+zc).fontSize() / 10.0));
-//					qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(currasce);
-					currasce = qMax(currasce, asce);
-				}
-				*/
-//				qDebug() << QString("move3 line %1.. down by %2 current ascender=%3").arg(current.line.firstItem).arg(-adj).arg(currasce);
-
-				current.line.ascent = currasce;
-				current.line.y -= adj;
-				current.yPos -= adj;
-			}
-			else if ((!current.startOfCol) && (style.lineSpacingMode() == ParagraphStyle::AutomaticLineSpacing))
-			{
-				double firstasce = style.lineSpacing();
-				double currasce = current.getLineHeight(itemText);
-				/*0;
-				if (itemText.object(current.line.firstItem) != 0)
-					currasce = qMax(currasce, (itemText.object(current.line.firstItem)->gHeight + itemText.object(current.line.firstItem)->lineWidth()) * (itemText.charStyle(current.line.firstItem).scaleV() / 1000.0));
-				else //if (itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap == 0)
-					currasce = itemText.charStyle(current.line.firstItem).font().height(itemText.charStyle(current.line.firstItem).fontSize() / 10.0);
-				for (int zc = 0; zc < current.itemsInLine; ++zc)
-				{
-					QChar ch = itemText.text(current.line.firstItem+zc);
-					if (ch == SpecialChars::PAGENUMBER)
-						ch = '8'; // should have highest ascender even in oldstyle
-					if ((ch == SpecialChars::TAB) || (ch == QChar(10))
-						|| (ch == SpecialChars::PARSEP) || (ch == SpecialChars::NBHYPHEN)
-						|| (ch == SpecialChars::COLBREAK) || (ch == SpecialChars::FRAMEBREAK)
-						|| (ch == SpecialChars::LINEBREAK) || (ch.isSpace()))
-						continue;
-					double asce;
-					if (itemText.object(current.line.firstItem+zc) != 0)
-						asce = (itemText.object(current.line.firstItem+zc)->gHeight + itemText.object(current.line.firstItem+zc)->lineWidth()) * (itemText.charStyle(current.line.firstItem+zc).scaleV() / 1000.0);
-					else //if (itemText.charStyle(current.line.firstItem+zc).effects() & ScStyle_DropCap == 0)
-						asce = itemText.charStyle(current.line.firstItem+zc).font().height(itemText.charStyle(current.line.firstItem+zc).fontSize() / 10.0);
-//					qDebug() << QString("checking char 'x%2' with ascender %1 > %3").arg(asce).arg(ch.unicode()).arg(currasce);
-					currasce = qMax(currasce, asce);
-				}
-				*/
-				double adj = firstasce - currasce;
-//				qDebug() << QString(QString("move4 line %1.. down by %2").arg(current.line.firstItem).arg(-adj);
-
-				current.line.ascent = currasce;
-				current.line.y -= adj;
-				current.yPos -= adj;
-			}
 			if ( itemText.charStyle(current.line.firstItem).effects() & ScStyle_DropCap )
 			{
 				// put line back to top




More information about the scribus-commit mailing list