r18012 by craig - Move MarginStruct to its own file, and move text distance to frame variables to new MarginStruct

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 30 21:26:17 UTC 2012


Author: craig
Date: Sun Dec 30 21:26:16 2012
New Revision: 18012

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18012
Log:
Move MarginStruct to its own file, and move text distance to frame variables to new MarginStruct

Added:
    trunk/Scribus/scribus/margins.h   (with props)
Modified:
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/pageitem_noteframe.cpp
    trunk/Scribus/scribus/pageitem_pathtext.cpp
    trunk/Scribus/scribus/pageitem_textframe.cpp
    trunk/Scribus/scribus/scribusstructs.h

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18012&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Sun Dec 30 21:26:16 2012
@@ -276,10 +276,7 @@
 	m_endArrowIndex(other.m_endArrowIndex),
 	m_startArrowScale(other.m_startArrowScale),
 	m_endArrowScale(other.m_endArrowScale),
-	Extra(other.Extra),
-	TExtra(other.TExtra),
-	BExtra(other.BExtra),
-	RExtra(other.RExtra),
+	m_textDistanceMargins(other.m_textDistanceMargins),
 	firstLineOffsetP(other.firstLineOffsetP),
 	RadRect(other.RadRect),
 	oldXpos(other.oldXpos),
@@ -480,10 +477,7 @@
 	FrameType = 0;
 	CurX = 0;
 	CurY = 0;
-	Extra = m_Doc->itemToolPrefs().textDistances.Left;
-	TExtra = m_Doc->itemToolPrefs().textDistances.Top;
-	BExtra = m_Doc->itemToolPrefs().textDistances.Bottom;
-	RExtra = m_Doc->itemToolPrefs().textDistances.Right;
+	m_textDistanceMargins=m_Doc->itemToolPrefs().textDistances;
 	firstChar = 0;
 	MaxChars = 0;
 	m_sampleItem = false;
@@ -1469,65 +1463,65 @@
 
 void PageItem::setTextToFrameDistLeft(double newLeft)
 {
-	if(Extra==newLeft)
+	if(m_textDistanceMargins.Left==newLeft)
 		return;
 	if (UndoManager::undoEnabled())
 	{
 		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
 		ss->set("LEFT_TEXTFRAMEDIST", "left_textframedist");
-		ss->set("OLD_DIST",Extra);
+		ss->set("OLD_DIST",m_textDistanceMargins.Left);
 		ss->set("NEW_DIST",newLeft);
 		undoManager->action(this, ss);
 	}
-	Extra=newLeft;
+	m_textDistanceMargins.Left=newLeft;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDistRight(double newRight)
 {
-	if(RExtra==newRight)
+	if(m_textDistanceMargins.Right==newRight)
 		return;
 	if (UndoManager::undoEnabled())
 	{
 		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
 		ss->set("RIGHT_TEXTFRAMEDIST", "right_textframedist");
-		ss->set("OLD_DIST",RExtra);
+		ss->set("OLD_DIST",m_textDistanceMargins.Right);
 		ss->set("NEW_DIST",newRight);
 		undoManager->action(this, ss);
 	}
-	RExtra=newRight;
+	m_textDistanceMargins.Right=newRight;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDistTop(double newTop)
 {
-	if(TExtra==newTop)
+	if(m_textDistanceMargins.Top==newTop)
 		return;
 	if (UndoManager::undoEnabled())
 	{
 		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
 		ss->set("TOP_TEXTFRAMEDIST", "top_textframedist");
-		ss->set("OLD_DIST",TExtra);
+		ss->set("OLD_DIST",m_textDistanceMargins.Top);
 		ss->set("NEW_DIST",newTop);
 		undoManager->action(this, ss);
 	}
-	TExtra=newTop;
+	m_textDistanceMargins.Top=newTop;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
 void PageItem::setTextToFrameDistBottom(double newBottom)
 {
-	if(BExtra==newBottom)
+	if(m_textDistanceMargins.Bottom==newBottom)
 		return;
 	if (UndoManager::undoEnabled())
 	{
 		SimpleState *ss = new SimpleState(Um::TextFrameDist, "", Um::ITextFrame);
 		ss->set("BOTTOM_TEXTFRAMEDIST", "bottom_textframedist");
-		ss->set("OLD_DIST",BExtra);
+		ss->set("OLD_DIST",m_textDistanceMargins.Bottom);
 		ss->set("NEW_DIST",newBottom);
 		undoManager->action(this, ss);
 	}
-	BExtra=newBottom;
+	m_textDistanceMargins.Bottom=newBottom;
 	//emit textToFrameDistances(Extra, TExtra, BExtra, RExtra);
 }
 
@@ -6272,36 +6266,36 @@
 void PageItem::restoreLeftTextFrameDist(SimpleState *ss, bool isUndo)
 {
 	if (isUndo)
-		Extra = ss->getInt("OLD_DIST");
-	else
-		Extra = ss->getInt("NEW_DIST");
+		m_textDistanceMargins.Left = ss->getInt("OLD_DIST");
+	else
+		m_textDistanceMargins.Left = ss->getInt("NEW_DIST");
 	update();
 }
 
 void PageItem::restoreRightTextFrameDist(SimpleState *ss, bool isUndo)
 {
 	if (isUndo)
-		RExtra = ss->getInt("OLD_DIST");
-	else
-		RExtra = ss->getInt("NEW_DIST");
+		m_textDistanceMargins.Right = ss->getInt("OLD_DIST");
+	else
+		m_textDistanceMargins.Right = ss->getInt("NEW_DIST");
 	update();
 }
 
 void PageItem::restoreTopTextFrameDist(SimpleState *ss, bool isUndo)
 {
 	if (isUndo)
-		TExtra = ss->getInt("OLD_DIST");
-	else
-		TExtra = ss->getInt("NEW_DIST");
+		m_textDistanceMargins.Top = ss->getInt("OLD_DIST");
+	else
+		m_textDistanceMargins.Top = ss->getInt("NEW_DIST");
 	update();
 }
 
 void PageItem::restoreBottomTextFrameDist(SimpleState *ss, bool isUndo)
 {
 	if (isUndo)
-		BExtra = ss->getInt("OLD_DIST");
-	else
-		BExtra = ss->getInt("NEW_DIST");
+		m_textDistanceMargins.Bottom = ss->getInt("OLD_DIST");
+	else
+		m_textDistanceMargins.Bottom = ss->getInt("NEW_DIST");
 	update();
 }
 

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18012&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h (original)
+++ trunk/Scribus/scribus/pageitem.h Sun Dec 30 21:26:16 2012
@@ -43,6 +43,7 @@
 #include "observable.h"
 #include "pagestructs.h"
 #include "scimage.h"
+#include "margins.h"
 #include "sctextstruct.h"
 #include "text/nlsconfig.h"
 #include "text/storytext.h"
@@ -428,6 +429,11 @@
 	double ColGap;
 	double gridOffset_;
 	double gridValue_;
+	int m_startArrowIndex;
+	int m_endArrowIndex;
+	int m_startArrowScale;
+	int m_endArrowScale;
+
 
 	/** Linestyle */
 	Qt::PenStyle PLineArt;
@@ -559,7 +565,9 @@
 	uint firstChar;
 	uint MaxChars;
 	bool m_sampleItem; //Used to not draw the frame for sample items
-public:
+	/** Left, Top, Bottom, Right distances of text from the frame */
+	MarginStruct m_textDistanceMargins;
+	public:
 	void setSampleItem(bool b) {m_sampleItem=b;}
 	bool inPdfArticle;
 	bool isRaster;
@@ -828,10 +836,10 @@
 	void makeImageExternal(QString path);
 	
 	//Text Data - Move to PageItem_TextFrame at some point? --- no, to FrameStyle, av
-	double textToFrameDistLeft() const { return Extra; }
-	double textToFrameDistRight() const { return RExtra; }
-	double textToFrameDistTop() const { return TExtra; }
-	double textToFrameDistBottom() const { return BExtra; }
+	double textToFrameDistLeft() const { return m_textDistanceMargins.Left; }
+	double textToFrameDistRight() const { return m_textDistanceMargins.Right; }
+	double textToFrameDistTop() const { return m_textDistanceMargins.Top; }
+	double textToFrameDistBottom() const { return m_textDistanceMargins.Bottom; }
 	int columns() const { return Cols; }
 	double columnGap() const { return ColGap; }
 	double gridOffset() const;
@@ -1645,18 +1653,7 @@
 	/** If the frame is reversed */
 	bool Reverse;
 
-	int m_startArrowIndex;
-	int m_endArrowIndex;
-	int m_startArrowScale;
-	int m_endArrowScale;
-
 protected:
-  	/** Left, Top, Bottom, Right distances of text from the frame */
-	double Extra;
-	double TExtra;
-	double BExtra;
-	double RExtra;
-	
 	FirstLineOffsetPolicy firstLineOffsetP;
 	
 public:

Modified: trunk/Scribus/scribus/pageitem_noteframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18012&path=/trunk/Scribus/scribus/pageitem_noteframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_noteframe.cpp Sun Dec 30 21:26:16 2012
@@ -218,7 +218,7 @@
 			}
 		}
 		double hackValue = 0.5;
-		oldHeight = Height = ceil(maxY) + BExtra + hackValue;
+		oldHeight = Height = ceil(maxY) + m_textDistanceMargins.Bottom + hackValue;
 		updateConstants();
 		updateClip();
 		invalid = true;

Modified: trunk/Scribus/scribus/pageitem_pathtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18012&path=/trunk/Scribus/scribus/pageitem_pathtext.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_pathtext.cpp (original)
+++ trunk/Scribus/scribus/pageitem_pathtext.cpp Sun Dec 30 21:26:16 2012
@@ -82,7 +82,7 @@
 	FPoint point = FPoint(0, 0);
 	FPoint tangent = FPoint(0, 0);
 	QColor tmp;
-	CurX = Extra;
+	CurX = m_textDistanceMargins.Left;
 	QString cachedStroke = "";
 	QString cachedFill = "";
 	double cachedFillShade = -1;
@@ -225,12 +225,12 @@
 	{
 		totalCurveLen += PoLine.lenPathSeg(segs);
 	}
-	if ((itemRenderText.paragraphStyle(0).alignment() != 0) && (totalCurveLen >= totalTextLen + Extra))
+	if ((itemRenderText.paragraphStyle(0).alignment() != 0) && (totalCurveLen >= totalTextLen + m_textDistanceMargins.Left))
 	{
 		if (itemRenderText.paragraphStyle(0).alignment() == 2)
 		{
 			CurX = totalCurveLen  - totalTextLen;
-			CurX -= Extra;
+			CurX -= m_textDistanceMargins.Left;
 		}
 		if (itemRenderText.paragraphStyle(0).alignment() == 1)
 			CurX = (totalCurveLen - totalTextLen) / 2.0;
@@ -239,16 +239,16 @@
 			if (spaceCount != 0)
 			{
 				extraOffset = 0;
-				wordExtra = (totalCurveLen - Extra  - totalTextLen) / static_cast<double>(spaceCount);
+				wordExtra = (totalCurveLen - m_textDistanceMargins.Left  - totalTextLen) / static_cast<double>(spaceCount);
 			}
 			else
 			{
-				extraOffset = (totalCurveLen - Extra  - totalTextLen) / static_cast<double>(itemRenderText.length());
+				extraOffset = (totalCurveLen - m_textDistanceMargins.Left  - totalTextLen) / static_cast<double>(itemRenderText.length());
 				wordExtra = 0;
 			}
 		}
 		if (itemRenderText.paragraphStyle(0).alignment() == 4)
-			extraOffset = (totalCurveLen - Extra  - totalTextLen) / static_cast<double>(itemRenderText.length());
+			extraOffset = (totalCurveLen - m_textDistanceMargins.Left - totalTextLen) / static_cast<double>(itemRenderText.length());
 	}
 #ifndef NLS_PROTO
 	QPainterPath guidePath = PoLine.toQPainterPath(false);

Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18012&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp Sun Dec 30 21:26:16 2012
@@ -1370,14 +1370,10 @@
 		lineCorr = m_lineWidth / 2.0;
 	
 	// TODO: refactor this into PageItem
-	MarginStruct extra;
-	extra.Top = TExtra;
-	extra.Left = Extra;
-	extra.Right = RExtra;
-	extra.Bottom = BExtra;
+	MarginStruct savedTextDistanceMargins(m_textDistanceMargins);
 
 	LineControl current;
-	current.init(Width, Height, extra, lineCorr);
+	current.init(Width, Height, m_textDistanceMargins, lineCorr);
 	current.initColumns(columnWidth(), ColGap);
 	current.hyphenCount = 0;
 
@@ -1452,7 +1448,7 @@
 		}
 		
 		current.nextColumn();
-		lastLineY = extra.Top;
+		lastLineY = m_textDistanceMargins.Top;
 
 		//automatic line spacing factor (calculated once)
 		double autoLS = static_cast<double>(m_Doc->typographicPrefs().autoLineSpacing) / 100.0;
@@ -1473,13 +1469,13 @@
 			else 
 				chs = hl->fontSize();
 			desc = -hl->font().descent(chs / 10.0);
-			current.yPos = extra.Top + lineCorr;
+			current.yPos = m_textDistanceMargins.Top + lineCorr;
 //			qDebug() << QString("first line at y=%1").arg(current.yPos);
 		}
 		else // empty itemText:
 		{
 			desc = -itemText.defaultStyle().charStyle().font().descent(itemText.defaultStyle().charStyle().fontSize() / 10.0);
-			current.yPos = itemText.defaultStyle().lineSpacing() + extra.Top + lineCorr - desc;
+			current.yPos = itemText.defaultStyle().lineSpacing() + m_textDistanceMargins.Top + lineCorr - desc;
 		}
 		current.startLine(firstInFrame());
 
@@ -1681,7 +1677,7 @@
 				}
 				current.breakIndex = -1;
 				if (current.startOfCol && !current.afterOverflow && current.recalculateY)
-					current.yPos = qMax(current.yPos, extra.Top);
+					current.yPos = qMax(current.yPos, m_textDistanceMargins.Top);
 				// more about par gap and dropcaps
 				if ((a > firstInFrame() && itemText.text(a-1) == SpecialChars::PARSEP) || (a == 0 && BackBox == 0 && current.startOfCol))
 				{
@@ -1936,7 +1932,7 @@
 					//if top of column Y position depends on first line offset
 					if (current.startOfCol)
 					{
-						lastLineY = qMax(lastLineY, extra.Top + lineCorr);
+						lastLineY = qMax(lastLineY, m_textDistanceMargins.Top + lineCorr);
 						//fix for proper rendering first empty line (only with PARSEP)
 						if (chstr[0] == SpecialChars::PARSEP)
 							current.yPos += style.lineSpacing();
@@ -2839,7 +2835,7 @@
 						current.nextColumn();
 						current.mustLineEnd = current.colRight;
 						current.addLeftIndent = true;
-						lastLineY = extra.Top;
+						lastLineY = m_textDistanceMargins.Top;
 						current.rowDesc = 0;
 						current.recalculateY = true;
 					}
@@ -3116,10 +3112,7 @@
 			p->fillPath();
 		}
 	}
-	double S_TExtra = TExtra;
-	double S_Extra = Extra;
-	double S_RExtra = RExtra;
-	double S_BExtra = BExtra;
+	MarginStruct savedTextDistanceMargins(m_textDistanceMargins);
 	if (isAnnotation() && !((m_Doc->appMode == modeEdit) && (m_Doc->m_Selection->findItem(this) != -1)) && (((annotation().Type() > 1) && (annotation().Type() < 11)) || (annotation().Type() > 12)))
 	{
 		QColor fontColor;
@@ -3241,10 +3234,7 @@
 		else if (annotation().Type() == Annotation::Textfield)
 		{
 			int wdt = annotation().Bwid();
-			TExtra = wdt;
-			Extra = wdt;
-			RExtra = wdt;
-			BExtra = wdt;
+			m_textDistanceMargins.set(wdt, wdt, wdt, wdt);
 			invalid = true;
 			layout();
 		}
@@ -3732,10 +3722,7 @@
 	//	}
 		//	pf2.end();
 	}
-	TExtra = S_TExtra;
-	Extra = S_Extra;
-	RExtra = S_RExtra;
-	BExtra = S_BExtra;
+	m_textDistanceMargins=savedTextDistanceMargins;
 	p->restore();//RE1
 }
 
@@ -5003,8 +4990,8 @@
 		lineCorr = m_lineWidth / 2.0;
 	else
 		lineCorr = 0;
-	return (Width - (ColGap * (Cols - 1)) - Extra - RExtra - 2 * lineCorr) / Cols;
-//	return (Width - (ColGap * (Cols - 1)) - Extra - RExtra - lineCorr) / Cols;
+	return (Width - (ColGap * (Cols - 1)) - m_textDistanceMargins.Left - m_textDistanceMargins.Right - 2 * lineCorr) / Cols;
+//	return (Width - (ColGap * (Cols - 1)) - m_textDistanceMargins.Left - m_textDistanceMargins.Right - lineCorr) / Cols;
 }
 
 /*
@@ -5052,13 +5039,13 @@
 	double lineCorr=0;
 	if (lineColor() != CommonStrings::None)
 		lineCorr = m_lineWidth / 2.0;
-	if (TExtra + lineCorr!=0.0)
-		p->drawSharpLine(FPoint(0, TExtra + lineCorr), FPoint(Width, TExtra + lineCorr));
-	if (BExtra + lineCorr!=0.0)
-		p->drawSharpLine(FPoint(0, Height - BExtra - lineCorr), FPoint(Width, Height - BExtra - lineCorr));
+	if (m_textDistanceMargins.Top + lineCorr!=0.0)
+		p->drawSharpLine(FPoint(0, m_textDistanceMargins.Top + lineCorr), FPoint(Width, m_textDistanceMargins.Top + lineCorr));
+	if (m_textDistanceMargins.Bottom + lineCorr!=0.0)
+		p->drawSharpLine(FPoint(0, Height - m_textDistanceMargins.Bottom - lineCorr), FPoint(Width, Height - m_textDistanceMargins.Bottom - lineCorr));
 	while(curCol < Cols)
 	{
-		colLeft=(colWidth + ColGap) * curCol + Extra + lineCorr;
+		colLeft=(colWidth + ColGap) * curCol + m_textDistanceMargins.Left + lineCorr;
 		if (colLeft != 0.0)
 			p->drawSharpLine(FPoint(colLeft, 0), FPoint(colLeft, 0+Height));
 		if (colLeft + colWidth != Width)
@@ -5961,7 +5948,7 @@
 	//ugly hack increasing min frame`s haeight against strange glyph painting if it is too close of bottom
 	double hackValue = 0.5;
 
-	setHeight(ceil(maxY) + BExtra + hackValue);
+	setHeight(ceil(maxY) + m_textDistanceMargins.Bottom + hackValue);
 	updateClip();
 	invalid = true;
 	m_Doc->changed();

Modified: trunk/Scribus/scribus/scribusstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18012&path=/trunk/Scribus/scribus/scribusstructs.h
==============================================================================
--- trunk/Scribus/scribus/scribusstructs.h (original)
+++ trunk/Scribus/scribus/scribusstructs.h Sun Dec 30 21:26:16 2012
@@ -29,6 +29,7 @@
 #include "annotation.h"
 #include "fpointarray.h"
 #include "pageitem.h"
+#include "margins.h"
 #include "scfonts.h"
 #include "scimagestructs.h"
 #include "sctextstruct.h"
@@ -69,28 +70,6 @@
 	QString inputProfile;
 	bool   useEmbedded;
 	eRenderIntent renderingIntent;
-};
-
-/** \brief Pagemargins and bleeds*/
-class MarginStruct
-{
-	public:
-		MarginStruct() : Top(0), Left(0), Bottom(0), Right(0) {}
-		MarginStruct(double top, double left, double bottom, double right) :
-			Top(top), Left(left), Bottom(bottom), Right(right) {}
-		MarginStruct(const MarginStruct& rhs) {Top=rhs.Top;Bottom=rhs.Bottom;Left=rhs.Left;Right=rhs.Right;}
-		void set(double top, double left, double bottom, double right) {Top=top;Bottom=bottom;Left=left;Right=right;}
-		void resetToZero() {Top=0.0;Bottom=0.0;Left=0.0;Right=0.0;}
-		bool hasNonZeroValue() const { return Top!=0.0 || Bottom!=0.0 || Left!=0.0 || Right!=0.0;}
-		void print() const {qDebug() << Top << Left << Bottom << Right;}
-		double leftMargin() const { return Left; }
-		double topMargin() const { return Top; }
-		double bottomMargin() const { return Bottom; }
-		double rightMargin() const { return Right; }
-		double Top;
-		double Left;
-		double Bottom;
-		double Right;
 };
 
 struct DocPagesSetup




More information about the scribus-commit mailing list