r13907 by fschmid - WPG-Import: Added support for line join and cap styles, corrected gradient orientation.

scribus-commit scribus-commit at lists.scribus.net
Wed Aug 26 05:55:11 CEST 2009


Revision: 13907
Author: fschmid
Date: 2009-08-24T15:09:30.026839Z
Commit message: WPG-Import: Added support for line join and cap styles, corrected gradient orientation.

Changeset: 
M  /trunk/Scribus/scribus/plugins/wpgimplugin/importwpg.cpp
M  /trunk/Scribus/scribus/plugins/wpgimplugin/wpg/WPG2Parser.cpp
M  /trunk/Scribus/scribus/plugins/wpgimplugin/importwpg.h
M  /trunk/Scribus/scribus/plugins/wpgimplugin/wpg/WPGPen.cpp
M  /trunk/Scribus/scribus/plugins/wpgimplugin/wpg/WPG2Parser.h
M  /trunk/Scribus/scribus/plugins/wpgimplugin/wpg/WPGPen.h

Diffs:
Index: scribus/plugins/wpgimplugin/importwpg.cpp
===================================================================
--- scribus/plugins/wpgimplugin/importwpg.cpp	(revision 13906)
+++ scribus/plugins/wpgimplugin/importwpg.cpp	(revision 13907)
@@ -69,6 +69,8 @@
 	Coords.resize(0);
 	Coords.svgInit();
 	LineW = 1.0;
+	lineJoin = Qt::MiterJoin;
+	lineEnd = Qt::FlatCap;
 	fillrule = false;
 	gradientAngle = 0.0;
 	isGradient = false;
@@ -116,8 +118,8 @@
 	ColorList::Iterator it;
 	CurrColorStroke = "Black";
 	CurrStrokeShade = 100.0;
-	if (LineW != 0.0)
-	{
+//	if (LineW != 0.0)
+//	{
 		int Rc, Gc, Bc, hR, hG, hB;
 		bool found = false;
 		Rc = pen.foreColor.red;
@@ -155,10 +157,40 @@
 				dashArray.append(pen.dashArray.at(i)*LineW);
 			}
 		}
+		switch (pen.joinstyle)
+		{
+			case 1:
+				lineJoin = Qt::BevelJoin;
+				break;
+			case 2:
+				lineJoin = Qt::MiterJoin;
+				break;
+			case 3:
+				lineJoin = Qt::RoundJoin;
+				break;
+			default:
+				lineJoin = Qt::MiterJoin;
+				break;
+		}
+		switch (pen.capstyle)
+		{
+			case 0:
+				lineEnd = Qt::FlatCap;
+				break;
+			case 1:
+				lineEnd = Qt::RoundCap;
+				break;
+			case 2:
+				lineEnd = Qt::SquareCap;
+				break;
+			default:
+				lineEnd = Qt::FlatCap;
+				break;
+		}
 		strokeSet = true;
-	}
-	else
-		CurrColorStroke = CommonStrings::None;
+//	}
+//	else
+//		CurrColorStroke = CommonStrings::None;
 }
 
 void ScrPainter::setBrush(const libwpg::WPGBrush& brush)
@@ -257,7 +289,7 @@
 {
 	int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX, baseY, rect.width() * 72.0, rect.height() * 72.0, LineW, CurrColorFill, CurrColorStroke, true);
 	PageItem *ite = m_Doc->Items->at(z);
-	if ((rx != 0) || (ry != 0))
+	if ((rx > 0) && (ry > 0))
 	{
 		ite->setCornerRadius(qMax(72*rx, 72*ry));
 		ite->SetFrameRound();
@@ -363,6 +395,8 @@
 	ite->setLineShade(CurrStrokeShade);
 	ite->setFillTransparency(CurrFillTrans);
 	ite->setLineTransparency(CurrStrokeTrans);
+	ite->setLineJoin(lineJoin);
+	ite->setLineEnd(lineEnd);
 	ite->DashValues = dashArray;
 	FPoint wh = getMaxClipF(&ite->PoLine);
 	ite->setWidthHeight(wh.x(),wh.y());
@@ -378,7 +412,7 @@
 		m1.rotate(-gradientAngle);
 		ite->GrStartX = 0;
 		ite->GrStartY = 0;
-		QPointF target = m1.map(QPointF(ite->width(), 0.0));
+		QPointF target = m1.map(QPointF(0.0, ite->height()));
 		ite->GrEndX = target.x();
 		ite->GrEndY = target.y();
 	}
@@ -395,6 +429,8 @@
 	CurrFillTrans = 0.0;
 	Coords.resize(0);
 	Coords.svgInit();
+	lineJoin = Qt::MiterJoin;
+	lineEnd = Qt::FlatCap;
 	LineW = 1.0;
 	fillrule = false;
 	gradientAngle = 0.0;
Index: scribus/plugins/wpgimplugin/wpg/WPG2Parser.h
===================================================================
--- scribus/plugins/wpgimplugin/wpg/WPG2Parser.h	(revision 13906)
+++ scribus/plugins/wpgimplugin/wpg/WPG2Parser.h	(revision 13907)
@@ -167,6 +167,8 @@
 	void handlePenStyle();
 	void handlePenSize();
 	void handleDPPenSize();
+	void handleLineCap();
+	void handleLineJoin();
 	void handleBrushGradient();
 	void handleDPBrushGradient();
 	void handleBrushForeColor();
Index: scribus/plugins/wpgimplugin/wpg/WPGPen.h
===================================================================
--- scribus/plugins/wpgimplugin/wpg/WPGPen.h	(revision 13906)
+++ scribus/plugins/wpgimplugin/wpg/WPGPen.h	(revision 13907)
@@ -56,6 +56,8 @@
 	double width;
 	double height;
 	bool solid;
+	int joinstyle;
+	int capstyle;
 	WPGDashArray dashArray;
 
 	WPGPen(); 
Index: scribus/plugins/wpgimplugin/wpg/WPG2Parser.cpp
===================================================================
--- scribus/plugins/wpgimplugin/wpg/WPG2Parser.cpp	(revision 13906)
+++ scribus/plugins/wpgimplugin/wpg/WPG2Parser.cpp	(revision 13907)
@@ -287,8 +287,8 @@
 		{ 0x2a, "Pen Pattern",          0 },
 		{ 0x2b, "Pen Size",             &WPG2Parser::handlePenSize },
 		{ 0x2c, "DP Pen Size",          &WPG2Parser::handleDPPenSize  },
-		{ 0x2d, "Line Cap",             0 },
-		{ 0x2e, "Line Join",            0 },
+		{ 0x2d, "Line Cap",             &WPG2Parser::handleLineCap },
+		{ 0x2e, "Line Join",            &WPG2Parser::handleLineJoin },
 		{ 0x2f, "Brush Gradient",       &WPG2Parser::handleBrushGradient },
 		{ 0x30, "DP Brush Gradient",    &WPG2Parser::handleDPBrushGradient },
 		{ 0x31, "Brush Fore Color",     &WPG2Parser::handleBrushForeColor },
@@ -587,6 +587,7 @@
 
 void WPG2Parser::handleFormSettings()
 {
+#ifdef DEBUG
 	unsigned int w = (m_doublePrecision) ? readU32() : readU16();
 	unsigned int h = (m_doublePrecision) ? readU32() : readU16();
 	double width = (TO_DOUBLE(w)) / m_xres;
@@ -603,6 +604,7 @@
 	
 	WPG_DEBUG_MSG(("Form Settings: width: %f height : %f\n", width, height));
 	WPG_DEBUG_MSG(("Form Margins:  left: %f right : %f top: %f bottom: %f\n", margL, margR, margT, margB));
+#endif
 }
 
 void WPG2Parser::handleLayer()
@@ -648,6 +650,8 @@
 	else
 		m_painter->setFillRule(libwpg::WPGPaintInterface::AlternatingFill);
 	context.compoundPath.closed = context.compoundClosed;
+	context.compoundPath.filled = context.compoundFilled;
+	context.compoundPath.framed = context.compoundFramed;
 	m_painter->drawPath(context.compoundPath);
 }
 
@@ -866,6 +870,38 @@
 	WPG_DEBUG_MSG(("  Height: %li\n", height));
 }
 
+void WPG2Parser::handleLineCap()
+{
+	if (!m_graphicsStarted)
+		return;
+	if(!m_groupStack.empty())
+	{
+		if (m_groupStack.top().isCompoundPolygon())
+			return;
+		if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now
+			return;
+	}
+	unsigned int style = readU8();
+	m_pen.capstyle = style;
+	WPG_DEBUG_MSG(("   Line cap : %d\n", style));
+}
+
+void WPG2Parser::handleLineJoin()
+{
+	if (!m_graphicsStarted)
+		return;
+	if(!m_groupStack.empty())
+	{
+		if (m_groupStack.top().isCompoundPolygon())
+			return;
+		if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now
+			return;
+	}
+	unsigned int style = readU8();
+	m_pen.joinstyle = style;
+	WPG_DEBUG_MSG(("   Line join : %d\n", style));
+}
+
 void WPG2Parser::handleBrushGradient()
 {
 	if (!m_graphicsStarted)
Index: scribus/plugins/wpgimplugin/wpg/WPGPen.cpp
===================================================================
--- scribus/plugins/wpgimplugin/wpg/WPGPen.cpp	(revision 13906)
+++ scribus/plugins/wpgimplugin/wpg/WPGPen.cpp	(revision 13907)
@@ -79,6 +79,8 @@
 	width(0), 
 	height(0), 
 	solid(true) ,
+	joinstyle(2),
+	capstyle(0),
 	dashArray(WPGDashArray())
 {
 }
@@ -89,6 +91,8 @@
 	width(0), 
 	height(0), 
 	solid(true),
+	joinstyle(2),
+	capstyle(0),
 	dashArray(WPGDashArray()) 
 {
 }
@@ -99,6 +103,8 @@
 	width(0), 
 	height(0), 
 	solid(true) ,
+	joinstyle(2),
+	capstyle(0),
 	dashArray(WPGDashArray())
 {
 }
@@ -109,6 +115,8 @@
 	width(pen.width),
 	height(pen.height),
 	solid(pen.solid),
+	joinstyle(pen.joinstyle),
+	capstyle(pen.capstyle),
 	dashArray(pen.dashArray)
 {
 }
@@ -120,6 +128,8 @@
 	width = pen.width;
 	height = pen.height;
 	solid = pen.solid;
+	joinstyle = pen.joinstyle;
+	capstyle = pen.capstyle;
 	dashArray = pen.dashArray;
 	return *this;
 }
Index: scribus/plugins/wpgimplugin/importwpg.h
===================================================================
--- scribus/plugins/wpgimplugin/importwpg.h	(revision 13906)
+++ scribus/plugins/wpgimplugin/importwpg.h	(revision 13907)
@@ -66,6 +66,8 @@
 	bool strokeSet;
 	VGradient currentGradient;
 	QVector<double> dashArray;
+	Qt::PenJoinStyle lineJoin;
+	Qt::PenCapStyle lineEnd;
 	int flags;
 	bool firstLayer;
 };




More information about the scribus-commit mailing list