r19874 by fschmid - Part of #12929 "Problems with EMF Importer", don't try to draw lines with width 0

scribus-commit scribus-commit at lists.scribus.net
Tue Feb 24 20:18:44 UTC 2015


Author: fschmid
Date: Tue Feb 24 20:18:44 2015
New Revision: 19874

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19874
Log:
Part of #12929 "Problems with EMF Importer", don't try to draw lines with width 0

Modified:
    trunk/Scribus/scribus/plugins/import/emf/importemf.cpp

Modified: trunk/Scribus/scribus/plugins/import/emf/importemf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19874&path=/trunk/Scribus/scribus/plugins/import/emf/importemf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/emf/importemf.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/emf/importemf.cpp Tue Feb 24 20:18:44 2015
@@ -17,6 +17,7 @@
 #include <QFile>
 #include <QList>
 #include <QMimeData>
+#include <QRawFont>
 #include <QRegExp>
 #include <QTextCodec>
 #include <QUuid>
@@ -1114,6 +1115,8 @@
 						break;
 					case U_EMR_SETWINDOWORGEX:
 						ds >> winOrigX >> winOrigY;
+						if ((viewPextendX != 0) && (viewPextendY != 0))
+							currentDC.winOrigin = convertLogical2Pts(QPointF(winOrigX, winOrigY));
 						break;
 					case U_EMR_SETVIEWPORTEXTEX:
 						ds >> viewPextendX >> viewPextendY;
@@ -1664,8 +1667,8 @@
 	}
 	else if ((currentDC.m_mapMode == 0x07) || (currentDC.m_mapMode == 0x08))
 	{
-		double ratioX = qAbs(viewPextendX / static_cast<double>(winPextendX)); // Logical --> Device
-		double ratioY = qAbs(viewPextendY / static_cast<double>(winPextendY)); // Logical --> Device
+		double ratioX = viewPextendX / static_cast<double>(winPextendX); // Logical --> Device
+		double ratioY = viewPextendY / static_cast<double>(winPextendY); // Logical --> Device
 		// logic --> device --> pts
 		out.setX(in.x() * ratioX * scaleX);
 		out.setY(in.y() * ratioY * scaleY);
@@ -1856,6 +1859,7 @@
 	ite->setTextFlowMode(PageItem::TextFlowDisabled);
 	m_Doc->AdjustItemSize(ite);
 	ite->moveBy(-docX, -docY, true);
+	ite->moveBy(-currentDC.winOrigin.x(), -currentDC.winOrigin.y());
 	ite->OldB2 = ite->width();
 	ite->OldH2 = ite->height();
 	ite->updateClip();
@@ -2182,7 +2186,7 @@
 	}
 	if (inEMFPlus)
 	{
-		if (currentDC.brushStyle == U_BT_PathGradient)
+		if ((currentDC.brushStyle == U_BT_PathGradient) || (currentDC.brushStyle == U_BT_LinearGradient))
 		{
 			if ((!currentDC.clipPath.isEmpty()) && (ite->itemType() != PageItem::ImageFrame))
 			{
@@ -2639,6 +2643,8 @@
 
 void EmfPlug::handleText(QDataStream &ds, qint64 posi, bool size)
 {
+	QString aTxt = "";
+	QPainterPath painterPath;
 	qint32 bLeft, bTop, bRight, bBottom, oLeft, oTop, oRight, oBottom;
 	quint32 grMode, numChar, offTxt, txOpts, offDx;
 	float sx, sy;
@@ -2652,59 +2658,99 @@
 	ds >> oLeft >> oTop >> oRight >> oBottom;
 	ds >> offDx;
 	ds.device()->seek(posi + offTxt);
-	QString aTxt = "";
-	for (quint32 a = 0; a < numChar; a++)
-	{
-		if (size)
-		{
-			quint16 cc;
-			ds >> cc;
-			aTxt.append(QChar(cc));
-		}
-		else
-		{
-			quint8 cc;
-			ds >> cc;
-			aTxt.append(QChar(cc));
-		}
-	}
-	ds.device()->seek(posi + offDx);
-	QList<quint32> dxTxt;
-	for (quint32 a = 0; a < numChar; a++)
-	{
-		quint32 cc;
-		ds >> cc;
-		dxTxt.append(cc);
-	}
-	if (aTxt.isEmpty())
-		return;
-	FPointArray textPath;
-	QPainterPath painterPath;
 	QFont font = QFont(currentDC.fontName, currentDC.fontSize);
 	font.setPixelSize(currentDC.fontSize);
-	if (font.exactMatch())
-	{
+	QFontMetricsF fm(font);
+	double aTextWidth = 0;
+	if (txOpts & 0x00000010)
+	{
+		QList<quint32> glyphs;
+		for (quint32 a = 0; a < numChar; a++)
+		{
+			if (size)
+			{
+				quint16 cc;
+				ds >> cc;
+				glyphs.append(cc);
+			}
+			else
+			{
+				quint8 cc;
+				ds >> cc;
+				glyphs.append(cc);
+			}
+		}
+		ds.device()->seek(posi + offDx);
+		QList<quint32> dxTxt;
+		for (quint32 a = 0; a < numChar; a++)
+		{
+			quint32 cc;
+			ds >> cc;
+			dxTxt.append(cc);
+		}
+		QRawFont rFont = QRawFont::fromFont(font);
 		double startX = p1.x();
 		for (quint32 a = 0; a < numChar; a++)
 		{
-			painterPath.addText(startX, p1.y(), font, aTxt.at(a));
+			QPainterPath gPath = rFont.pathForGlyph(glyphs[a]);
+			gPath.translate(startX, p1.y());
+			painterPath.addPath(gPath);
 			startX += convertLogical2Pts(static_cast<double>(dxTxt[a]));
 		}
+		aTextWidth = painterPath.boundingRect().width();
 	}
 	else
-		painterPath.addText(p1.x(), p1.y(), font, aTxt);
-	QFontMetricsF fm(font);
+	{
+		for (quint32 a = 0; a < numChar; a++)
+		{
+			if (size)
+			{
+				quint16 cc;
+				ds >> cc;
+				aTxt.append(QChar(cc));
+			}
+			else
+			{
+				quint8 cc;
+				ds >> cc;
+				aTxt.append(QChar(cc));
+			}
+		}
+		ds.device()->seek(posi + offDx);
+		QList<quint32> dxTxt;
+		for (quint32 a = 0; a < numChar; a++)
+		{
+			quint32 cc;
+			ds >> cc;
+			dxTxt.append(cc);
+		}
+		if (aTxt.isEmpty())
+			return;
+		if (font.exactMatch())
+		{
+			double startX = p1.x();
+			for (quint32 a = 0; a < numChar; a++)
+			{
+				painterPath.addText(startX, p1.y(), font, aTxt.at(a));
+				startX += convertLogical2Pts(static_cast<double>(dxTxt[a]));
+			}
+		}
+		else
+			painterPath.addText(p1.x(), p1.y(), font, aTxt);
+		aTextWidth = fm.width(aTxt);
+	}
 	if (currentDC.textAlignment == 0)
 		painterPath.translate(0, fm.ascent());
 	if (currentDC.textAlignment & 0x0002)
-		painterPath.translate(-fm.width(aTxt), 0);
+		painterPath.translate(-aTextWidth, 0);
 	else if (currentDC.textAlignment & 0x0006)
-		painterPath.translate(-fm.width(aTxt) / 2.0, 0);
+		painterPath.translate(-aTextWidth / 2.0, 0);
 	if (currentDC.textAlignment & 0x0008)
 		painterPath.translate(0, fm.descent());
 	QTransform bm = currentDC.m_WorldMap;
 	bm = QTransform(bm.m11(), bm.m12(), bm.m21(), bm.m22(), 0, 0);
 	painterPath = bm.map(painterPath);
+	FPointArray textPath;
 	textPath.fromQPainterPath(painterPath);
 	if (textPath.size() > 0)
 	{
@@ -2720,9 +2766,9 @@
 		if (currentDC.textAlignment & 0x0002)
 			currentDC.currentPoint = p1;
 		else if (currentDC.textAlignment & 0x0006)
-			currentDC.currentPoint = QPointF(p1.x() + (fm.width(aTxt) / 2.0), p1.y());
+			currentDC.currentPoint = QPointF(p1.x() + (aTextWidth / 2.0), p1.y());
 		else
-			currentDC.currentPoint = QPointF(p1.x() + fm.width(aTxt), p1.y());
+			currentDC.currentPoint = QPointF(p1.x() + aTextWidth, p1.y());
 	}
 }
 
@@ -2731,8 +2777,8 @@
 	QTransform bm = currentDC.m_WorldMap;
 	if ((currentDC.m_mapMode == 0x07) || (currentDC.m_mapMode == 0x08))
 	{
-		double ratioX = qAbs(viewPextendX / static_cast<double>(winPextendX)); // Logical --> Device
-		double ratioY = qAbs(viewPextendY / static_cast<double>(winPextendY)); // Logical --> Device
+		double ratioX = viewPextendX / static_cast<double>(winPextendX); // Logical --> Device
+		double ratioY = viewPextendY / static_cast<double>(winPextendY); // Logical --> Device
 		bm = QTransform(bm.m11() * ratioX, bm.m12() * ratioY, bm.m21() * ratioX, bm.m22() * ratioY, bm.dx() * ratioX, bm.dy() * ratioY);
 	}
 	QPointF p = currentDC.m_WorldMap.map(QPointF(dstX, dstY));
@@ -3037,7 +3083,12 @@
 		getPolyInfo(ds, BoxDev, countP);
 		FPointArray pointsPoly = getPolyPoints(ds, countP, size, fill);
 		if (fill)
-			z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, currentDC.LineW, currentDC.CurrColorFill, currentDC.CurrColorStroke, true);
+		{
+			if (currentDC.LineW == 0)
+				z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, currentDC.CurrColorFill, CommonStrings::None, true);
+			else
+				z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, currentDC.LineW, currentDC.CurrColorFill, currentDC.CurrColorStroke, true);
+		}
 		else
 			z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, currentDC.LineW, CommonStrings::None, currentDC.CurrColorStroke, true);
 		PageItem* ite = m_Doc->Items->at(z);
@@ -3090,7 +3141,12 @@
 				pointsPoly.setMarker();
 		}
 		if (fill)
-			z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, currentDC.LineW, currentDC.CurrColorFill, currentDC.CurrColorStroke, true);
+		{
+			if (currentDC.LineW == 0)
+				z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, currentDC.CurrColorFill, CommonStrings::None, true);
+			else
+				z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, currentDC.LineW, currentDC.CurrColorFill, currentDC.CurrColorStroke, true);
+		}
 		else
 			z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, currentDC.LineW, CommonStrings::None, currentDC.CurrColorStroke, true);
 		PageItem* ite = m_Doc->Items->at(z);




More information about the scribus-commit mailing list