r21640 by jghali - exit early in grid and guide drawing functions when possible

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 11 19:54:01 UTC 2016


Author: jghali
Date: Sun Dec 11 19:54:01 2016
New Revision: 21640

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21640
Log:
exit early in grid and guide drawing functions when possible

Modified:
    trunk/Scribus/scribus/canvas.cpp

Modified: trunk/Scribus/scribus/canvas.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21640&path=/trunk/Scribus/scribus/canvas.cpp
==============================================================================
--- trunk/Scribus/scribus/canvas.cpp	(original)
+++ trunk/Scribus/scribus/canvas.cpp	Sun Dec 11 19:54:01 2016
@@ -1923,6 +1923,9 @@
  */
 void Canvas::DrawPageGridSub(ScPainter *p, ScPage *page, QRectF clip)
 {
+	if (!m_doc->guidesPrefs().gridShown)
+		return;
+
 	p->save();
 	FPointArray PoLine;
 	getClipPathForPages(&PoLine);
@@ -1935,79 +1938,78 @@
 	p->setFillMode(ScPainter::None);
 	p->setStrokeMode(ScPainter::Solid);
 	p->setPen(Qt::black, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
-	if (m_doc->guidesPrefs().gridShown)
-	{
-		double lowerBx = qMax(clip.x() / m_viewMode.scale + m_doc->minCanvasCoordinate.x() - page->xOffset(), 0.0);
-		double lowerBy = qMax(clip.y() / m_viewMode.scale + m_doc->minCanvasCoordinate.y() - page->yOffset(), 0.0);
-		double highBx = qMin(lowerBx + clip.width() / m_viewMode.scale, pageWidth);
-		double highBy = qMin(lowerBy + clip.height() / m_viewMode.scale, pageHeight);
-		if (m_viewMode.scale > 0.49)
-		{
-			if (m_doc->guidesPrefs().gridType == 0)
-			{
-				double i,start;
-				i = m_doc->guidesPrefs().majorGridSpacing;
-				p->setPen(m_doc->guidesPrefs().majorGridColor, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
-				start = floor(lowerBy / i);
-				start *= i;
-				for (double b = start; b <= highBy; b+=i)
+
+	double lowerBx = qMax(clip.x() / m_viewMode.scale + m_doc->minCanvasCoordinate.x() - page->xOffset(), 0.0);
+	double lowerBy = qMax(clip.y() / m_viewMode.scale + m_doc->minCanvasCoordinate.y() - page->yOffset(), 0.0);
+	double highBx = qMin(lowerBx + clip.width() / m_viewMode.scale, pageWidth);
+	double highBy = qMin(lowerBy + clip.height() / m_viewMode.scale, pageHeight);
+	if (m_viewMode.scale > 0.49)
+	{
+		if (m_doc->guidesPrefs().gridType == 0)
+		{
+			double i,start;
+			i = m_doc->guidesPrefs().majorGridSpacing;
+			p->setPen(m_doc->guidesPrefs().majorGridColor, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+			start = floor(lowerBy / i);
+			start *= i;
+			for (double b = start; b <= highBy; b+=i)
+			{
+				p->drawLine(FPoint(qMax(lowerBx, 0.0), b), FPoint(qMin(pageWidth, highBx), b));
+			}
+			start=floor(lowerBx/i);
+			start*=i;
+			for (double b = start; b <= highBx; b+=i)
+			{
+				p->drawLine(FPoint(b, qMax(lowerBy, 0.0)), FPoint(b, qMin(pageHeight, highBy)));
+			}
+			i = m_doc->guidesPrefs().minorGridSpacing;
+			p->setPen(m_doc->guidesPrefs().minorGridColor, lineWidth, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
+			start = floor(lowerBy / i);
+			start *= i;
+			for (double b = start; b <= highBy; b+=i)
+			{
+				p->drawLine(FPoint(qMax(lowerBx, 0.0), b), FPoint(qMin(pageWidth, highBx), b));
+			}
+			start=floor(lowerBx/i);
+			start*=i;
+			for (double b = start; b <= highBx; b+=i)
+			{
+				p->drawLine(FPoint(b, qMax(lowerBy, 0.0)), FPoint(b, qMin(pageHeight, highBy)));
+			}
+		}
+		else if (m_doc->guidesPrefs().gridType == 1)
+		{
+			double i, startX, startY;
+			i = m_doc->guidesPrefs().minorGridSpacing;
+			p->setPen(m_doc->guidesPrefs().minorGridColor, 3.0 / m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin);
+			startY = floor(lowerBy / i);
+			startY *= i;
+			startX = floor(lowerBx / i);
+			startX *= i;
+			for (double b = startY; b <= highBy; b += i)
+			{
+				for (double bb = startX; bb <= highBx; bb += i)
 				{
-					p->drawLine(FPoint(qMax(lowerBx, 0.0), b), FPoint(qMin(pageWidth, highBx), b));
+					p->drawLine(FPoint(bb, b), FPoint(bb, b));
 				}
-				start=floor(lowerBx/i);
-				start*=i;
-				for (double b = start; b <= highBx; b+=i)
+			}
+			i = m_doc->guidesPrefs().majorGridSpacing;
+			p->setPen(m_doc->guidesPrefs().majorGridColor, lineWidth * 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+			startY = floor(lowerBy / i);
+			startY *= i;
+			startX = floor(lowerBx / i);
+			startX *= i;
+			for (double b = startY; b <= highBy; b += i)
+			{
+				for (double bb = startX; bb <= highBx; bb += i)
 				{
-					p->drawLine(FPoint(b, qMax(lowerBy, 0.0)), FPoint(b, qMin(pageHeight, highBy)));
+					p->drawLine(FPoint(bb - 4, b), FPoint(bb + 4, b));
+					p->drawLine(FPoint(bb, b - 4), FPoint(bb, b + 4));
 				}
-				i = m_doc->guidesPrefs().minorGridSpacing;
-				p->setPen(m_doc->guidesPrefs().minorGridColor, lineWidth, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
-				start = floor(lowerBy / i);
-				start *= i;
-				for (double b = start; b <= highBy; b+=i)
-				{
-					p->drawLine(FPoint(qMax(lowerBx, 0.0), b), FPoint(qMin(pageWidth, highBx), b));
-				}
-				start=floor(lowerBx/i);
-				start*=i;
-				for (double b = start; b <= highBx; b+=i)
-				{
-					p->drawLine(FPoint(b, qMax(lowerBy, 0.0)), FPoint(b, qMin(pageHeight, highBy)));
-				}
-			}
-			else if (m_doc->guidesPrefs().gridType == 1)
-			{
-				double i, startX, startY;
-				i = m_doc->guidesPrefs().minorGridSpacing;
-				p->setPen(m_doc->guidesPrefs().minorGridColor, 3.0 / m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin);
-				startY = floor(lowerBy / i);
-				startY *= i;
-				startX = floor(lowerBx / i);
-				startX *= i;
-				for (double b = startY; b <= highBy; b += i)
-				{
-					for (double bb = startX; bb <= highBx; bb += i)
-					{
-						p->drawLine(FPoint(bb, b), FPoint(bb, b));
-					}
-				}
-				i = m_doc->guidesPrefs().majorGridSpacing;
-				p->setPen(m_doc->guidesPrefs().majorGridColor, lineWidth * 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
-				startY = floor(lowerBy / i);
-				startY *= i;
-				startX = floor(lowerBx / i);
-				startX *= i;
-				for (double b = startY; b <= highBy; b += i)
-				{
-					for (double bb = startX; bb <= highBx; bb += i)
-					{
-						p->drawLine(FPoint(bb - 4, b), FPoint(bb + 4, b));
-						p->drawLine(FPoint(bb, b - 4), FPoint(bb, b + 4));
-					}
-				}
-			}
-		}
-	}
+			}
+		}
+	}
+
 	p->setAntialiasing(true);
 	p->endLayer();
 	p->restore();
@@ -2015,6 +2017,9 @@
 
 void Canvas::DrawPageGrid(ScPainter *p, QRectF clip, bool master)
 {
+	if (!m_doc->guidesPrefs().gridShown)
+		return;
+
 	if (master)
 	{
 		ScPage *page = m_doc->currentPage();
@@ -2046,6 +2051,9 @@
  */
 void Canvas::DrawPageGuidesSub(ScPainter *p, ScPage *page)
 {
+	if (!m_doc->guidesPrefs().guidesShown)
+		return;
+
 	p->save();
 	p->setAntialiasing(false);
 	p->translate(page->xOffset(), page->yOffset());
@@ -2053,14 +2061,16 @@
 	p->setFillMode(ScPainter::None);
 	p->setStrokeMode(ScPainter::Solid);
 	p->setPen(Qt::black, lineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
-	if (m_doc->guidesPrefs().guidesShown)
-		page->guides.drawPage(p, m_doc, lineWidth);
+	page->guides.drawPage(p, m_doc, lineWidth);
 	p->setAntialiasing(true);
 	p->restore();
 }
 
 void Canvas::DrawPageGuides(ScPainter *p, QRectF clip, bool master)
 {
+	if (!m_doc->guidesPrefs().guidesShown)
+		return;
+
 	if (master)
 	{
 		ScPage *page = m_doc->currentPage();




More information about the scribus-commit mailing list