r18958 by fschmid - Better ORA import, supports now adjustable layers.

scribus-commit scribus-commit at lists.scribus.net
Fri Mar 28 20:34:38 UTC 2014


Author: fschmid
Date: Fri Mar 28 20:34:38 2014
New Revision: 18958

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18958
Log:
Better ORA import, supports now adjustable layers.

Modified:
    trunk/Scribus/scribus/scimage.cpp
    trunk/Scribus/scribus/scimgdataloader_ora.cpp
    trunk/Scribus/scribus/scimgdataloader_ora.h
    trunk/Scribus/scribus/ui/extimageprops.cpp

Modified: trunk/Scribus/scribus/scimage.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18958&path=/trunk/Scribus/scribus/scimage.cpp
==============================================================================
--- trunk/Scribus/scribus/scimage.cpp (original)
+++ trunk/Scribus/scribus/scimage.cpp Fri Mar 28 20:34:38 2014
@@ -1998,6 +1998,12 @@
 		if	(pDataLoader.get())
 			pDataLoader->setRequest(imgInfo.isRequest, imgInfo.RequestProps);
 	}
+	else if (ext == "ora")
+	{
+		pDataLoader.reset( new ScImgDataLoader_ORA() );
+		if	(pDataLoader.get())
+			pDataLoader->setRequest(imgInfo.isRequest, imgInfo.RequestProps);
+	}
 	else if (ext == "pat")
 		pDataLoader.reset( new ScImgDataLoader_GIMP() );
 	else if (ext == "pgf")
@@ -2268,7 +2274,10 @@
 	else if (ext == "wpg")
 		pDataLoader.reset( new ScImgDataLoader_WPG() );
 	else if (ext == "ora")
+	{
 		pDataLoader.reset( new ScImgDataLoader_ORA() );
+		pDataLoader->setRequest(imgInfo.isRequest, imgInfo.RequestProps);
+	}
 #ifdef GMAGICK_FOUND
 	else if (fmtImg.contains(ext))
 		pDataLoader.reset( new ScImgDataLoader_QT() );

Modified: trunk/Scribus/scribus/scimgdataloader_ora.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18958&path=/trunk/Scribus/scribus/scimgdataloader_ora.cpp
==============================================================================
--- trunk/Scribus/scribus/scimgdataloader_ora.cpp (original)
+++ trunk/Scribus/scribus/scimgdataloader_ora.cpp Fri Mar 28 20:34:38 2014
@@ -9,9 +9,7 @@
 #include <QByteArray>
 #include <QList>
 #include "scimgdataloader_ora.h"
-#include "scpainter.h"
 #include "util_formats.h"
-#include "third_party/zip/scribus_zip.h"
 
 ScImgDataLoader_ORA::ScImgDataLoader_ORA(void) : ScImgDataLoader()
 {
@@ -34,9 +32,15 @@
 {
 	if (!QFile::exists(fn))
 		return false;
+	bool valid = m_imageInfoRecord.isRequest;
+	QMap<int, ImageLoadRequest> req = m_imageInfoRecord.RequestProps;
 	initialize();
+	m_imageInfoRecord.RequestProps = req;
+	m_imageInfoRecord.isRequest = valid;
 	m_imageInfoRecord.type = ImageTypeOther;
 	m_imageInfoRecord.exifDataValid = false;
+	m_imageInfoRecord.layerInfo.clear();
+	m_imageInfoRecord.PDSpathData.clear();
 	ScZipHandler *uz = new ScZipHandler();
 	if (!uz->open(fn))
 	{
@@ -87,89 +91,40 @@
 				QDomDocument designMapDom;
 				if(designMapDom.setContent(f))
 				{
+					inSubLayer = 0;
+					layerCount = 0;
 					QDomElement docElem = designMapDom.documentElement();
+					m_imageInfoRecord.exifInfo.height = docElem.attribute("h", "0").toInt();
+					m_imageInfoRecord.exifInfo.width = docElem.attribute("w", "0").toInt();
+					m_imageInfoRecord.xres = docElem.attribute("xres", "72").toInt();
+					m_imageInfoRecord.yres = docElem.attribute("yres", "72").toInt();
+					m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32_Premultiplied);
+					if (m_image.isNull())
+					{
+						uz->close();
+						delete uz;
+						return false;
+					}
+					m_image.fill( qRgba(0, 0, 0, 0) );
+					ScPainter *painter = new ScPainter(&m_image, m_image.width(), m_image.height(), 1, 0);
+					painter->setZoomFactor(1);
 					for(QDomElement drawPag = docElem.firstChildElement(); !drawPag.isNull(); drawPag = drawPag.nextSiblingElement())
 					{
 						if (drawPag.tagName() == "stack")
 						{
-							parseStackXML(drawPag);
+							parseStackXML(drawPag, painter, uz);
 						}
 					}
-					m_imageInfoRecord.exifInfo.height = docElem.attribute("h", "0").toInt();
-					m_imageInfoRecord.exifInfo.width = docElem.attribute("w", "0").toInt();
-					m_imageInfoRecord.xres = docElem.attribute("xres", "72").toInt();
-					m_imageInfoRecord.yres = docElem.attribute("yres", "72").toInt();
+					delete painter;
+					m_image = m_image.convertToFormat(QImage::Format_ARGB32);
+					m_imageInfoRecord.valid = true;
+					m_image.setDotsPerMeterX((int) (m_imageInfoRecord.xres / 0.0254));
+					m_image.setDotsPerMeterY((int) (m_imageInfoRecord.yres / 0.0254));
+					m_imageInfoRecord.BBoxX = 0;
+					m_imageInfoRecord.BBoxH = m_image.height();
+					m_imageInfoRecord.colorspace = ColorSpaceRGB;
+					m_pixelFormat = Format_BGRA_8;
 				}
-				m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32_Premultiplied);
-				if (m_image.isNull())
-				{
-					uz->close();
-					delete uz;
-					return false;
-				}
-				m_image.fill( qRgba(0, 0, 0, 0) );
-				ScPainter *painter = new ScPainter(&m_image, m_image.width(), m_image.height(), 1, 0);
-				painter->setZoomFactor(1);
-				while (OraLayerStack.count() > 0)
-				{
-					oraLayer layer = OraLayerStack.pop();
-					if (layer.visible)
-					{
-						QByteArray lf;
-						if (!uz->read(layer.fileName, lf))
-							break;
-						QImage img = QImage::fromData(lf).convertToFormat(QImage::Format_ARGB32_Premultiplied);
-						painter->save();
-						painter->setOpacity(layer.opacity);
-						if (layer.compositeOp == "svg:multiply")
-							painter->setBlendModeFill(3);
-						else if (layer.compositeOp == "svg:screen")
-							painter->setBlendModeFill(4);
-						else if (layer.compositeOp == "svg:overlay")
-							painter->setBlendModeFill(5);
-						else if (layer.compositeOp == "svg:darken")
-							painter->setBlendModeFill(1);
-						else if (layer.compositeOp == "svg:lighten")
-							painter->setBlendModeFill(2);
-						else if (layer.compositeOp == "svg:color-dodge")
-							painter->setBlendModeFill(10);
-						else if (layer.compositeOp == "svg:color-burn")
-							painter->setBlendModeFill(11);
-						else if (layer.compositeOp == "svg:hard-light")
-							painter->setBlendModeFill(6);
-						else if (layer.compositeOp == "svg:soft-light")
-							painter->setBlendModeFill(7);
-						else if (layer.compositeOp == "svg:difference")
-							painter->setBlendModeFill(8);
-						else if (layer.compositeOp == "svg:color")
-							painter->setBlendModeFill(14);
-						else if (layer.compositeOp == "svg:luminosity")
-							painter->setBlendModeFill(15);
-						else if (layer.compositeOp == "svg:hue")
-							painter->setBlendModeFill(12);
-						else if (layer.compositeOp == "svg:saturation")
-							painter->setBlendModeFill(13);
-						else if (layer.compositeOp == "svg:plus")
-							painter->setBlendModeFill(16);
-						else if (layer.compositeOp == "svg:dst-in")
-							painter->setBlendModeFill(17);
-						else if (layer.compositeOp == "svg:dst-out")
-							painter->setBlendModeFill(18);
-						else
-							painter->setBlendModeFill(0);
-						painter->translate(layer.x, layer.y);
-						painter->drawImage(&img);
-						painter->restore();
-					}
-				}
-				delete painter;
-				m_image = m_image.convertToFormat(QImage::Format_ARGB32);
-				m_image.setDotsPerMeterX ((int) (m_imageInfoRecord.xres / 0.0254));
-				m_image.setDotsPerMeterY ((int) (m_imageInfoRecord.yres / 0.0254));
-				m_imageInfoRecord.BBoxX = 0;
-				m_imageInfoRecord.BBoxH = m_image.height();
-				m_imageInfoRecord.colorspace = ColorSpaceRGB;
-				m_pixelFormat = Format_BGRA_8;
 			}
 		}
 	}
@@ -178,27 +133,225 @@
 	return true; //TODO: I think this should be false!
 }
 
-void ScImgDataLoader_ORA::parseStackXML(QDomElement &elem)
-{
-	for(QDomElement lay = elem.firstChildElement(); !lay.isNull(); lay = lay.nextSiblingElement())
+void ScImgDataLoader_ORA::parseStackXML(QDomElement &elem, ScPainter* painter, ScZipHandler *uz)
+{
+	for(QDomElement lay = elem.lastChildElement(); !lay.isNull(); lay = lay.previousSiblingElement())
 	{
 		if (lay.tagName() == "layer")
 		{
-			oraLayer layer;
-			layer.fileName = lay.attribute("src");
-			layer.compositeOp = lay.attribute("composite-op");
-			layer.opacity = lay.attribute("opacity", "1.0").toDouble();
-			layer.visible = lay.attribute("visibility", "visible") == "visible";
-			layer.x = lay.attribute("x", "0").toInt();
-			layer.y = lay.attribute("y", "0").toInt();
-			OraLayerStack.push(layer);
+			struct PSDLayer layer;
+			QString layerName = lay.attribute("name", QString("layer%1").arg(layerCount+1));
+			QString compositeOp = lay.attribute("composite-op");
+			double opacity = lay.attribute("opacity", "1.0").toDouble();
+			int x = lay.attribute("x", "0").toInt();
+			int y = lay.attribute("y", "0").toInt();
+			bool visible = lay.attribute("visibility", "visible") == "visible";
+			QString fileName = lay.attribute("src");
+			QImage img = QImage();
+			if (!fileName.isEmpty())
+			{
+				QByteArray lf;
+				if (!uz->read(fileName, lf))
+					break;
+				img = QImage::fromData(lf).convertToFormat(QImage::Format_ARGB32_Premultiplied);
+			}
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0;
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				visible = m_imageInfoRecord.RequestProps[layerCount].visible;
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend;
+			layer.layerName = layerName;
+			layer.channelType.clear();
+			layer.channelLen.clear();
+			layer.opacity = qRound(opacity * 255);
+			layer.blend = blendModeToString(compositeOp);
+			layer.maskYpos = 0;
+			layer.maskXpos = 0;
+			layer.maskHeight = 0;
+			layer.maskWidth = 0;
+			layer.flags = visible ? 0 : 2;
+			QImage imt;
+			double sx = img.width() / 40.0;
+			double sy = img.height() / 40.0;
+			imt = sy < sx ?  img.scaled(qRound(img.width() / sx), qRound(img.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) :
+				  img.scaled(qRound(img.width() / sy), qRound(img.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+			layer.thumb = imt.copy();
+			if (inSubLayer == 0)
+			{
+				m_imageInfoRecord.layerInfo.append(layer);
+				layerCount++;
+			}
+			if (visible)
+			{
+				painter->save();
+				painter->setOpacity(opacity);
+				painter->setBlendModeFill(blendModeToInt(compositeOp));
+				painter->translate(x, y);
+				painter->drawImage(&img);
+				painter->restore();
+			}
 		}
 		else if (lay.tagName() == "stack")
 		{
 			qDebug() << "Parsing SubStack";
-			parseStackXML(lay);
+			inSubLayer++;
+			struct PSDLayer layer;
+			QString layerName = lay.attribute("name", QString("layer%1").arg(layerCount+1));
+			QString compositeOp = lay.attribute("composite-op");
+			double opacity = lay.attribute("opacity", "1.0").toDouble();
+			int x = lay.attribute("x", "0").toInt();
+			int y = lay.attribute("y", "0").toInt();
+			bool visible = lay.attribute("visibility", "visible") == "visible";
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0;
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				visible = m_imageInfoRecord.RequestProps[layerCount].visible;
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend;
+			layer.layerName = layerName;
+			layer.channelType.clear();
+			layer.channelLen.clear();
+			layer.opacity = qRound(opacity * 255);
+			layer.blend = blendModeToString(compositeOp);
+			layer.maskYpos = 0;
+			layer.maskXpos = 0;
+			layer.maskHeight = 0;
+			layer.maskWidth = 0;
+			layer.flags = visible ? 0 : 2;
+			if (inSubLayer == 0)
+			{
+				m_imageInfoRecord.layerInfo.append(layer);
+				layerCount++;
+			}
+			if (visible)
+			{
+				painter->save();
+				painter->beginLayer(opacity, blendModeToInt(compositeOp));
+				painter->translate(x, y);
+				parseStackXML(lay, painter, uz);
+				painter->endLayer();
+				painter->restore();
+			}
+			inSubLayer--;
 		}
 	}
+}
+
+int ScImgDataLoader_ORA::blendModeToInt(QString compositeOp)
+{
+	int ret = 0;
+	if (compositeOp == "svg:darken")
+		ret = 1;
+	else if (compositeOp == "svg:lighten")
+		ret = 2;
+	else if (compositeOp == "svg:multiply")
+		ret = 3;
+	else if (compositeOp == "svg:screen")
+		ret = 4;
+	else if (compositeOp == "svg:overlay")
+		ret = 5;
+	else if (compositeOp == "svg:hard-light")
+		ret = 6;
+	else if (compositeOp == "svg:soft-light")
+		ret = 7;
+	else if (compositeOp == "svg:difference")
+		ret = 8;
+	else if (compositeOp == "svg:color-dodge")
+		ret = 10;
+	else if (compositeOp == "svg:color-burn")
+		ret = 11;
+	else if (compositeOp == "svg:color")
+		ret = 14;
+	else if (compositeOp == "svg:luminosity")
+		ret = 15;
+	else if (compositeOp == "svg:hue")
+		ret = 12;
+	else if (compositeOp == "svg:saturation")
+		ret = 13;
+	else if (compositeOp == "svg:plus")
+		ret = 16;
+	else if (compositeOp == "svg:dst-in")
+		ret = 17;
+	else if (compositeOp == "svg:dst-out")
+		ret = 18;
+	else if (compositeOp == "norm")
+		ret = 0;
+	else if (compositeOp == "dark")
+		ret = 1;
+	else if (compositeOp == "lite")
+		ret = 2;
+	else if (compositeOp == "mul ")
+		ret = 3;
+	else if (compositeOp == "scrn")
+		ret = 4;
+	else if (compositeOp == "over")
+		ret = 5;
+	else if (compositeOp == "hLit")
+		ret = 6;
+	else if (compositeOp == "sLit")
+		ret = 7;
+	else if (compositeOp == "diff")
+		ret = 8;
+	else if (compositeOp == "div ")
+		ret = 10;
+	else if (compositeOp == "idiv")
+		ret = 11;
+	else if (compositeOp == "colr")
+		ret = 14;
+	else if (compositeOp == "lum ")
+		ret = 15;
+	else if (compositeOp == "hue ")
+		ret = 12;
+	else if (compositeOp == "sat ")
+		ret = 13;
+	else if (compositeOp == "plus")
+		ret = 16;
+	else if (compositeOp == "dsti")
+		ret = 17;
+	else if (compositeOp == "dsto")
+		ret = 18;
+	return ret;
+}
+
+QString ScImgDataLoader_ORA::blendModeToString(QString compositeOp)
+{
+	QString ret = compositeOp;
+	if (compositeOp == "svg:darken")
+		ret = "dark";
+	else if (compositeOp == "svg:lighten")
+		ret = "lite";
+	else if (compositeOp == "svg:multiply")
+		ret = "mul ";
+	else if (compositeOp == "svg:screen")
+		ret = "scrn";
+	else if (compositeOp == "svg:overlay")
+		ret = "over";
+	else if (compositeOp == "svg:hard-light")
+		ret = "hLit";
+	else if (compositeOp == "svg:soft-light")
+		ret = "sLit";
+	else if (compositeOp == "svg:difference")
+		ret = "diff";
+	else if (compositeOp == "svg:color-dodge")
+		ret = "div ";
+	else if (compositeOp == "svg:color-burn")
+		ret = "idiv";
+	else if (compositeOp == "svg:color")
+		ret = "colr";
+	else if (compositeOp == "svg:luminosity")
+		ret = "lum ";
+	else if (compositeOp == "svg:hue")
+		ret = "hue ";
+	else if (compositeOp == "svg:saturation")
+		ret = "sat ";
+	else if (compositeOp == "svg:plus")
+		ret = "plus";
+	else if (compositeOp == "svg:dst-in")
+		ret = "dsti";
+	else if (compositeOp == "svg:dst-out")
+		ret = "dsto";
+	return ret;
 }
 
 bool ScImgDataLoader_ORA::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)

Modified: trunk/Scribus/scribus/scimgdataloader_ora.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18958&path=/trunk/Scribus/scribus/scimgdataloader_ora.h
==============================================================================
--- trunk/Scribus/scribus/scimgdataloader_ora.h (original)
+++ trunk/Scribus/scribus/scimgdataloader_ora.h Fri Mar 28 20:34:38 2014
@@ -8,9 +8,10 @@
 #define SCIMGDATALOADER_ORA_H
 
 #include "scimgdataloader.h"
+#include "scpainter.h"
+#include "third_party/zip/scribus_zip.h"
 #include <QDomDocument>
 #include <QDomElement>
-#include <QStack>
 
 class ScImgDataLoader_ORA : public ScImgDataLoader
 {
@@ -22,17 +23,11 @@
 	virtual bool loadPicture(const QString& fn, int page, int res, bool thumbnail);
 protected:
 	void initSupportedFormatList();
-	struct oraLayer
-	{
-		int x;
-		int y;
-		double opacity;
-		bool visible;
-		QString compositeOp;
-		QString fileName;
-	};
-	QStack<oraLayer> OraLayerStack;
-	void parseStackXML(QDomElement &elem);
+	void parseStackXML(QDomElement &elem, ScPainter *painter, ScZipHandler *uz);
+	int blendModeToInt(QString compositeOp);
+	QString blendModeToString(QString compositeOp);
+	int inSubLayer;
+	int layerCount;
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/extimageprops.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18958&path=/trunk/Scribus/scribus/ui/extimageprops.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/extimageprops.cpp (original)
+++ trunk/Scribus/scribus/ui/extimageprops.cpp Fri Mar 28 20:34:38 2014
@@ -64,6 +64,9 @@
 	blendModes.insert("smud", tr("Exclusion"));
 	blendModes.insert("div ", tr("Color Dodge"));
 	blendModes.insert("idiv", tr("Color Burn"));
+	blendModes.insert("plus", tr("Plus"));
+	blendModes.insert("dsti", tr("Destination In"));
+	blendModes.insert("dsto", tr("Destination Out"));
 	blendModesRev.clear();
 	blendModesRev.insert( tr("Normal"), "norm");
 	blendModesRev.insert( tr("Darken"), "dark");
@@ -82,6 +85,9 @@
 	blendModesRev.insert( tr("Exclusion"), "smud");
 	blendModesRev.insert( tr("Color Dodge"), "div ");
 	blendModesRev.insert( tr("Color Burn"), "idiv");
+	blendModesRev.insert( tr("Plus"), "plus");
+	blendModesRev.insert( tr("Destination In"), "dsti");
+	blendModesRev.insert( tr("Destination Out"), "dsto");
 	propsTab = new QTabWidget( this );
 	QPalette palette;
 	palette.setColor(backgroundRole(), Qt::white);
@@ -116,6 +122,9 @@
 		blendMode->addItem( tr("Exclusion"));
 		blendMode->addItem( tr("Color Dodge"));
 		blendMode->addItem( tr("Color Burn"));
+		blendMode->addItem( tr("Plus"));
+		blendMode->addItem( tr("Destination In"));
+		blendMode->addItem( tr("Destination Out"));
 		layout1->addWidget( blendMode );
 		textLabel2 = new QLabel( tab );
 		textLabel2->setText( tr( "Opacity:" ) );




More information about the scribus-commit mailing list