r15833 by pierremarc - various fixes and adjustments in the *Layouters + changed BoxGroup::addBox to update BoxGroup geometry

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 9 18:29:44 CET 2010


Author: pierremarc
Date: Tue Nov  9 17:29:44 2010
New Revision: 15833

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15833
Log:
various fixes and adjustments in the *Layouters + changed BoxGroup::addBox to update BoxGroup geometry

Modified:
    branches/ScribusOIF/scribus/text/blocklayouter.cpp
    branches/ScribusOIF/scribus/text/boxes.cpp
    branches/ScribusOIF/scribus/text/boxes.h
    branches/ScribusOIF/scribus/text/linelayouter.cpp
    branches/ScribusOIF/scribus/text/textlayout.cpp

Modified: branches/ScribusOIF/scribus/text/blocklayouter.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15833&path=/branches/ScribusOIF/scribus/text/blocklayouter.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/blocklayouter.cpp (original)
+++ branches/ScribusOIF/scribus/text/blocklayouter.cpp Tue Nov  9 17:29:44 2010
@@ -54,12 +54,15 @@
 // In a first instance we just check it can work: prototyping
 BlockLayouterBase::BlockResult BlockLayouter::layoutLeft(int startPos, int endPos) const
 {
+	qDebug()<<"BlockLayouter::layoutLeft"<<startPos<<endPos;
 	const GlyphStore * gs(m_layout->storyGlyphs());
 	const StoryText * story(m_layout->story());
 	const ParagraphStyle parStyle(story->paragraphStyle(startPos));
 	const CharStyle charStyle(parStyle.charStyle());
 	const BoxGroup * bg(m_layout->box());
 
+	double asc(charStyle.font().ascent() * charStyle.fontSize() / 10.0);
+	double desc(charStyle.font().descent() * charStyle.fontSize() / 10.0);
 	double y(0.0);
 	double x(parStyle.leftMargin() + parStyle.firstIndent());
 	if(bg->boxCount() > 0)
@@ -79,11 +82,12 @@
 		HBox * line(new HBox);
 
 		LineLayouter::ResultSet lineR(m_lineLayouter->layoutLine( curPos, width ));
-		LineLayouterBase::LineResult lResult(0,0, endPos);
+		LineLayouterBase::LineResult lResult(width,0, endPos);
 		if(lineR.count() > 0)
 			lResult = lineR.first();
 
 
+		qDebug()<<"\t"<<curPos<<lResult.endPos;
 		if(gs->findItem(curPos) == gs->findItem(lResult.endPos))
 		{
 			GlyphBox * glyphs(new GlyphBox(const_cast<GlyphStore*>(gs),
@@ -93,11 +97,11 @@
 						       lResult.endPos));
 			glyphs->moveTo(x,y);
 			glyphs->setWidth(lResult.width);
-			glyphs->setAscent(charStyle.font().ascent());
-			glyphs->setDescent(charStyle.font().descent());
+			glyphs->setAscent(asc);
+			glyphs->setDescent(-desc);
 			line->addBox(glyphs);
 		}
-		else // we need as many GlyphBoxes as items
+		else // we need at least as many GlyphBoxes as items
 		{
 			int item(gs->findItem(curPos));
 			int c(curPos);
@@ -105,8 +109,8 @@
 			GlyphBox * glyphs(new GlyphBox(const_cast<GlyphStore*>(gs),  m_textFrame->doc()->PageColors, item, c, e));
 			glyphs->moveTo(x,y);
 			glyphs->setWidth(lResult.width);
-			glyphs->setAscent(charStyle.font().ascent());
-			glyphs->setDescent(charStyle.font().descent());
+			glyphs->setAscent(asc);
+			glyphs->setDescent(-desc);
 			line->addBox(glyphs);
 			while(e < lResult.endPos)
 			{
@@ -116,8 +120,8 @@
 				glyphs = new GlyphBox(const_cast<GlyphStore*>(gs),  m_textFrame->doc()->PageColors, item, c, e);
 				glyphs->moveTo(x,y);
 				glyphs->setWidth(lResult.width);
-				glyphs->setAscent(charStyle.font().ascent());
-				glyphs->setDescent(charStyle.font().descent());
+				glyphs->setAscent(asc);
+				glyphs->setDescent(-desc);
 				line->addBox(glyphs);
 			}
 

Modified: branches/ScribusOIF/scribus/text/boxes.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15833&path=/branches/ScribusOIF/scribus/text/boxes.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/boxes.cpp (original)
+++ branches/ScribusOIF/scribus/text/boxes.cpp Tue Nov  9 17:29:44 2010
@@ -21,7 +21,7 @@
 		 Box(type),
 		 m_boxes(QList<Box*>())
 {
-	qDebug()<<"Create BoxGroup of Type:"<<type;
+//	qDebug()<<"Create BoxGroup of Type:"<<type;
 }
 
 QString BoxGroup::toString() const
@@ -29,6 +29,31 @@
 	return QString("%6[%1; %2; %3; %4 + %5] %7 boxes").arg(x()).arg(y()).arg(width()).arg(ascent()).arg(descent()).arg(m_type==T_Line? "Line" : m_type==T_Block? "Block" : "BoxGroup").arg(m_boxes.count());
 }
 
+void BoxGroup::addBox(Box *b)
+{
+	m_boxes.append(b);
+	double bRight(b->x() + b->width());
+	double tRight(m_x + m_width);
+	double maxRight(qMax(bRight, tRight));
+	m_x = qMin(m_x, b->x());
+	m_width = maxRight - m_x;
+	if(m_type == T_Block)
+	{
+		double bBottom(b->y() + b->height());
+		double tBottom(m_y + height());
+		double maxBottom(qMax(bBottom, tBottom));
+		m_y = qMin(m_y, b->y());
+		m_ascent = maxBottom - m_y;
+		m_descent = 0;
+	}
+	else
+	{
+		m_ascent = qMax(b->ascent(), m_ascent);
+		m_descent = qMax(b->descent(), m_descent);
+	}
+	m_y = qMin(m_y, b->y());
+	qDebug()<<"BoxGroup::addBox"<< b->toString()<<toString();
+}
 
 void BoxGroup::render(ScPainter* p, const RenderOptions& renderOptions) const
 {
@@ -469,7 +494,7 @@
 	for (unsigned int i(0); i < m_glyphs->itemGlyphCount(rItem); ++i)
 	{
 		uint glyph = layout->glyph;
-		qDebug() << "render glyph" << glyph << "width" << layout->xadvance  << "font" << style.font().scName() << "@" << x() << y() ;
+//		qDebug() << "render glyph" << glyph << "width" << layout->xadvance  << "font" << style.font().scName() << "@" << x() << y() ;
 		if ((renderOptions.showControls) && 
 			(glyph == style.font().char2CMap(QChar(' ')) || glyph >=  ScFace::CONTROL_GLYPHS))
 		{

Modified: branches/ScribusOIF/scribus/text/boxes.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15833&path=/branches/ScribusOIF/scribus/text/boxes.h
==============================================================================
--- branches/ScribusOIF/scribus/text/boxes.h (original)
+++ branches/ScribusOIF/scribus/text/boxes.h Tue Nov  9 17:29:44 2010
@@ -48,7 +48,7 @@
 	qreal m_ascent;
 	
 public:
-	Box(BoxType type) { m_type = type; m_width = m_ascent = m_descent = 0; }
+	Box(BoxType type) { m_x = m_y = m_type = type; m_width = m_ascent = m_descent = 0; }
 	virtual ~Box() {}
 	
 	virtual GlyphBox* asGlyphBox() { return NULL; }
@@ -100,7 +100,8 @@
 
 	int boxCount() const { return m_boxes.count(); }
 	Box* box(uint n) { return m_boxes[n]; }
-	void addBox(Box* b) { m_boxes.append(b); }
+	// Add a box to the boxes list and update geometry
+	void addBox(Box* b);
 	const QList<Box*> boxes() const { return m_boxes; }
 	void render(ScPainter* p, const RenderOptions& renderOptions) const;
 	int screenToPosition(FPoint coord) const;

Modified: branches/ScribusOIF/scribus/text/linelayouter.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15833&path=/branches/ScribusOIF/scribus/text/linelayouter.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/linelayouter.cpp (original)
+++ branches/ScribusOIF/scribus/text/linelayouter.cpp Tue Nov  9 17:29:44 2010
@@ -79,25 +79,34 @@
 			currentClusterWidth = gs->clusterWidth(cluster) * wordSpacing;
 			if(0 == resultCount)
 			{
-				if(m_layout->story()->charAttributes(cluster.textPosition()).testFlag(TextFlag_HyphenationPossible)
-					|| SpecialChars::isBreakingSpace(m_layout->story()->text(cluster.textPosition())))
-				{
-					lastBreak = cluster.textPosition();
-					lastBreakWidth = stackWidth + currentClusterWidth;
-				}
 				if((stackWidth + currentClusterWidth) > lineWidth)
 				{
-					LineResult lr(lastBreakWidth, 0, lastBreak);
-					ret << lr;
-					qDebug()<<"Inserting Line Result0"<<lr.width<<lr.endPos;
+					if(lastBreak > 0)
+					{
+						LineResult lr(lastBreakWidth, 0, lastBreak);
+						ret << lr;
+					}
+					else
+					{
+						LineResult lr(stackWidth + currentClusterWidth, 1, cluster.textPosition()); // overbox
+						ret << lr;
+					}
+//					qDebug()<<"Inserting Line Result0"<<lr.width<<lr.endPos;
 					resultCount = 1;
 				}
 				else if(cluster.textPosition() + 1 == m_layout->story()->length())
 				{
 					LineResult lr(stackWidth + currentClusterWidth, 0, cluster.textPosition());
 					ret << lr;
-					qDebug()<<"Inserting Line Result1"<<lr.width<<lr.endPos;
+//					qDebug()<<"Inserting Line Result1"<<lr.width<<lr.endPos;
 					resultCount = 2;
+				}
+				// put a possible break for next iteration
+				if(m_layout->story()->charAttributes(cluster.textPosition()).testFlag(TextFlag_HyphenationPossible)
+					|| SpecialChars::isBreakingSpace(m_layout->story()->text(cluster.textPosition())))
+				{
+					lastBreak = cluster.textPosition();
+					lastBreakWidth = stackWidth + currentClusterWidth;
 				}
 			}
 			else if(m_layout->story()->charAttributes(cluster.textPosition()).testFlag(TextFlag_HyphenationPossible)
@@ -105,7 +114,7 @@
 			{
 				LineResult lr(stackWidth + currentClusterWidth, 1, cluster.textPosition());
 				ret << lr;
-				qDebug()<<"Inserting Line Result2"<<lr.width<<lr.endPos;
+//				qDebug()<<"Inserting Line Result2"<<lr.width<<lr.endPos;
 				resultCount = 2;
 				break;
 			}
@@ -119,7 +128,7 @@
 		if(resultCount > 1)
 			break;
 	}
-qDebug()<<"Result len"<<ret.length();
+//qDebug()<<"Result len"<<ret.length();
 	return ret;
 }
 

Modified: branches/ScribusOIF/scribus/text/textlayout.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15833&path=/branches/ScribusOIF/scribus/text/textlayout.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/textlayout.cpp (original)
+++ branches/ScribusOIF/scribus/text/textlayout.cpp Tue Nov  9 17:29:44 2010
@@ -362,6 +362,7 @@
 		if(result.lastPos >= 0)
 		{
 			m_layout->addBox( result.box );
+			qDebug()<<"Add Par Box:"<<result.box->toString();
 			m_lastInFrame = result.lastPos;
 			int nextPar(m_story->nrOfParagraph(result.lastPos + 1));
 			if(nextPar > parIdx)




More information about the scribus-commit mailing list