r16079 by pierremarc - Implemented Right aligned and Centered paragraph alignments

scribus-commit scribus-commit at lists.scribus.net
Wed Dec 8 16:38:16 CET 2010


Author: pierremarc
Date: Wed Dec  8 15:38:16 2010
New Revision: 16079

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16079
Log:
Implemented Right aligned and Centered paragraph alignments

Modified:
    branches/ScribusOIF/scribus/text/blocklayouter.cpp
    branches/ScribusOIF/scribus/text/blocklayouter.h

Modified: branches/ScribusOIF/scribus/text/blocklayouter.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16079&path=/branches/ScribusOIF/scribus/text/blocklayouter.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/blocklayouter.cpp (original)
+++ branches/ScribusOIF/scribus/text/blocklayouter.cpp Wed Dec  8 15:38:16 2010
@@ -38,11 +38,10 @@
 {
 	const StoryText * story(m_layout->story());
 
-	switch(story->paragraphStyle(startPos).alignment())
-	{
-		// TODO_OIF
-	default: return layoutLeft(startPos, endPos);
-	}
+	if(story->paragraphStyle(startPos).alignment() == ParagraphStyle::Justified)
+		return layoutJustified(startPos, endPos);
+
+	return layout(startPos, endPos, story->paragraphStyle(startPos).alignment());
 }
 
 
@@ -53,7 +52,7 @@
 }
 
 // In a first instance we just check it can work: prototyping
-BlockLayouterBase::BlockResult BlockLayouter::layoutLeft(int startPos, int endPos) const
+BlockLayouterBase::BlockResult BlockLayouter::layout(int startPos, int endPos,  ParagraphStyle::AlignmentType alignment) const
 {
 	qDebug()<<"BlockLayouter::layoutLeft"<<startPos<<endPos;
 	const GlyphStore * gs(m_layout->storyGlyphs());
@@ -96,7 +95,10 @@
 		if(lineR.count() > 0)
 			lResult = lineR.first();
 
-
+		if(alignment == ParagraphStyle::Rightaligned)
+			x += (width - lResult.width) - parStyle.rightMargin();
+		else if(alignment == ParagraphStyle::Centered)
+			x += (width - lResult.width) / 2.0;
 		qDebug()<<"RESULT\t"<<curPos<<lResult.endPos;
 		if(gs->findItem(curPos) == gs->findItem(lResult.endPos)) // Case where the's only 1 item for the whole line
 		{
@@ -153,7 +155,28 @@
 			}
 
 			bool first(true);
-			double cPosX(paragraphIsRTL ? lResult.width  : 0.0);
+			double cPosX(0.0);
+			if(alignment == ParagraphStyle::Leftaligned)
+			{
+				if(paragraphIsRTL)
+					cPosX = lResult.width + parStyle.leftMargin();
+				else
+					cPosX = parStyle.leftMargin();
+			}
+			else if(alignment == ParagraphStyle::Rightaligned)
+			{
+				if(paragraphIsRTL)
+					cPosX = width - parStyle.rightMargin();
+				else
+					cPosX = (width - lResult.width) - parStyle.rightMargin();
+			}
+			else if(alignment == ParagraphStyle::Centered)
+			{
+				if(paragraphIsRTL)
+					cPosX = width - ( (width - lResult.width) / 2.0 );
+				else
+					cPosX = (width - lResult.width) / 2.0;
+			}
 			// we fake a previous reverse direction
 			itemIsRTL = !story->charAttributes(gs->itemTextPosition(gs->findItem(curPos))).testFlag(TextFlag_RightToLeft);
 			double iListWidth(0);
@@ -253,9 +276,3 @@
 	return BlockResult(resultBox, curPos - 1, fitInFrame);
 }
 
-BlockLayouterBase::BlockResult BlockLayouter::layoutRight(int startPos, int endPos) const
-{
-	// FIXME_OIF
-	return BlockLayouterBase::BlockResult(0, 0, true);
-}
-

Modified: branches/ScribusOIF/scribus/text/blocklayouter.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16079&path=/branches/ScribusOIF/scribus/text/blocklayouter.h
==============================================================================
--- branches/ScribusOIF/scribus/text/blocklayouter.h (original)
+++ branches/ScribusOIF/scribus/text/blocklayouter.h Wed Dec  8 15:38:16 2010
@@ -22,6 +22,7 @@
 #define BOXLAYOUTER_H
 
 #include "text/textlayout.h"
+#include "styles/paragraphstyle.h"
 
 class PageItem_TextFrame;
 class LineLayouter;
@@ -34,8 +35,7 @@
 
 
 	BlockResult layoutJustified(int startPos, int endPos) const;
-	BlockResult layoutLeft(int startPos, int endPos) const;
-	BlockResult layoutRight(int startPos, int endPos) const;
+	BlockResult layout(int startPos, int endPos, ParagraphStyle::AlignmentType alignment) const;
 
 public:
 	BlockLayouter(TextLayout * lyt);




More information about the scribus-commit mailing list