r19590 by jghali - #12778, patch 01/17: fix a series of warnings from clang

scribus-commit scribus-commit at lists.scribus.net
Fri Oct 17 22:07:00 UTC 2014


Author: jghali
Date: Fri Oct 17 22:07:00 2014
New Revision: 19590

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19590
Log:
#12778, patch 01/17: fix a series of warnings from clang

Modified:
    trunk/Scribus/scribus/canvasmode_magnifier.cpp
    trunk/Scribus/scribus/canvasmode_magnifier.h
    trunk/Scribus/scribus/canvasmode_nodeedit.h
    trunk/Scribus/scribus/canvasmode_objimport.cpp
    trunk/Scribus/scribus/canvasmode_objimport.h
    trunk/Scribus/scribus/fonts/scface_ttf.cpp
    trunk/Scribus/scribus/gtwriter.h
    trunk/Scribus/scribus/loadsaveplugin.cpp
    trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
    trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.h
    trunk/Scribus/scribus/plugins/gettext/xtgim/xtgim.h
    trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp
    trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
    trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
    trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
    trunk/Scribus/scribus/plugins/import/shape/importshape.cpp
    trunk/Scribus/scribus/plugins/picbrowser/iview.h
    trunk/Scribus/scribus/scimgdataloader_pict.cpp
    trunk/Scribus/scribus/scimgdataloader_pict.h
    trunk/Scribus/scribus/scpainter.h
    trunk/Scribus/scribus/scpainterex_ps2.h
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/ui/sclistwidgetdelegate.cpp

Modified: trunk/Scribus/scribus/canvasmode_magnifier.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/canvasmode_magnifier.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_magnifier.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_magnifier.cpp Fri Oct 17 22:07:00 2014
@@ -52,7 +52,7 @@
 #include "util_math.h"
 
 
-CanvasMode_Magnifier::CanvasMode_Magnifier(ScribusView* view) : CanvasMode(view), m_ScMW(view->m_ScMW) 
+CanvasMode_Magnifier::CanvasMode_Magnifier(ScribusView* view) : CanvasMode(view)
 {
 	Mxp = Myp = -1;
 	Dxp = Dyp = -1;

Modified: trunk/Scribus/scribus/canvasmode_magnifier.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/canvasmode_magnifier.h
==============================================================================
--- trunk/Scribus/scribus/canvasmode_magnifier.h (original)
+++ trunk/Scribus/scribus/canvasmode_magnifier.h Fri Oct 17 22:07:00 2014
@@ -58,8 +58,6 @@
 
 	double Mxp, Myp, Dxp, Dyp;
 	double SeRx, SeRy;
-	ScribusMainWindow* m_ScMW;
-	bool m_cursorVisible;
 	bool m_lastPosWasOverGuide;
 };
 

Modified: trunk/Scribus/scribus/canvasmode_nodeedit.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/canvasmode_nodeedit.h
==============================================================================
--- trunk/Scribus/scribus/canvasmode_nodeedit.h (original)
+++ trunk/Scribus/scribus/canvasmode_nodeedit.h Fri Oct 17 22:07:00 2014
@@ -1,77 +1,77 @@
-/*
- For general Scribus (>=1.3.2) copyright and licensing information please refer
- to the COPYING file provided with the program. Following this notice may exist
- a copyright and/or license notice that predates the release of Scribus 1.3.2
- for which a new license (GPL+exception) is in place.
- */
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-
-
-#ifndef CANVAS_MODE_NODEEDIT_H
-#define CANVAS_MODE_NODEEDIT_H
-
-#include "canvasmode.h"
-
-#include <QTransform>
-#include <QRect>
-
-class QPainter;
-
-class PageItem;
-class RectSelect;
-class ScribusMainWindow;
-
-class SCRIBUS_API CanvasMode_NodeEdit : public CanvasMode
-{
-public:
-	explicit CanvasMode_NodeEdit (ScribusView* view);
-	
-	virtual void activate(bool fromgesture);
-	virtual void deactivate(bool forGesture);
-	
-	virtual void enterEvent(QEvent *);
-	virtual void leaveEvent(QEvent *);
-	
-	virtual void mouseDoubleClickEvent(QMouseEvent *m);
-	virtual void mouseReleaseEvent(QMouseEvent *m);
-	virtual void mouseMoveEvent(QMouseEvent *m);
-	virtual void mousePressEvent(QMouseEvent *m);
-
-	virtual void keyPressEvent(QKeyEvent *e);
-	virtual void keyReleaseEvent(QKeyEvent *e);
-
-	virtual bool handleKeyEvents() { return true; }
-
-	
-	/**
-		Draws the controls for this mode
-	 */
-	virtual void drawControls(QPainter* p);
-	
-	
-	virtual ~CanvasMode_NodeEdit() {};
-	
-	
-private:
-	inline bool GetItem(PageItem** pi); 
-	void handleNodeEditPress(QMouseEvent*, QRect);
-	void handleNodeEditDrag(QMouseEvent*, PageItem*);
-	bool handleNodeEditMove(QMouseEvent*, QRect, PageItem*, QTransform);
-	
-	ScribusMainWindow* m_ScMW;
-	
-	RectSelect* m_rectangleSelect;
-	int Mxp, Myp, Dxp, Dyp, SeRx, SeRy, GxM, GyM;
-	bool MoveGX, MoveGY;
-};
-
-
-#endif
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+
+
+#ifndef CANVAS_MODE_NODEEDIT_H
+#define CANVAS_MODE_NODEEDIT_H
+
+#include "canvasmode.h"
+
+#include <QTransform>
+#include <QRect>
+
+class QPainter;
+
+class PageItem;
+class RectSelect;
+class ScribusMainWindow;
+
+class SCRIBUS_API CanvasMode_NodeEdit : public CanvasMode
+{
+public:
+	explicit CanvasMode_NodeEdit (ScribusView* view);
+	
+	virtual void activate(bool fromgesture);
+	virtual void deactivate(bool forGesture);
+	
+	virtual void enterEvent(QEvent *);
+	virtual void leaveEvent(QEvent *);
+	
+	virtual void mouseDoubleClickEvent(QMouseEvent *m);
+	virtual void mouseReleaseEvent(QMouseEvent *m);
+	virtual void mouseMoveEvent(QMouseEvent *m);
+	virtual void mousePressEvent(QMouseEvent *m);
+
+	virtual void keyPressEvent(QKeyEvent *e);
+	virtual void keyReleaseEvent(QKeyEvent *e);
+
+	virtual bool handleKeyEvents() { return true; }
+
+	
+	/**
+		Draws the controls for this mode
+	 */
+	virtual void drawControls(QPainter* p);
+	
+	
+	virtual ~CanvasMode_NodeEdit() {};
+	
+	
+private:
+	inline bool GetItem(PageItem** pi); 
+	void handleNodeEditPress(QMouseEvent*, QRect);
+	void handleNodeEditDrag(QMouseEvent*, PageItem*);
+	bool handleNodeEditMove(QMouseEvent*, QRect, PageItem*, QTransform);
+	
+	ScribusMainWindow* m_ScMW;
+	
+	RectSelect* m_rectangleSelect;
+	int Mxp, Myp, Dxp, Dyp, GxM, GyM;
+	bool MoveGX, MoveGY;
+};
+
+
+#endif

Modified: trunk/Scribus/scribus/canvasmode_objimport.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/canvasmode_objimport.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_objimport.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_objimport.cpp Fri Oct 17 22:07:00 2014
@@ -46,8 +46,7 @@
 
 
 CanvasMode_ObjImport::CanvasMode_ObjImport(ScribusView* view) :
-	CanvasMode(view),
-	m_ScMW(view->m_ScMW)
+	CanvasMode(view)
 {
 	Mxp = Myp = -1;
 	m_mimeData = NULL;

Modified: trunk/Scribus/scribus/canvasmode_objimport.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/canvasmode_objimport.h
==============================================================================
--- trunk/Scribus/scribus/canvasmode_objimport.h (original)
+++ trunk/Scribus/scribus/canvasmode_objimport.h Fri Oct 17 22:07:00 2014
@@ -58,7 +58,6 @@
 private:
 	QMimeData*          m_mimeData;
 	TransactionSettings* m_trSettings;
-	ScribusMainWindow*  m_ScMW;
 	double     Mxp, Myp;
 };
 

Modified: trunk/Scribus/scribus/fonts/scface_ttf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/fonts/scface_ttf.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/scface_ttf.cpp (original)
+++ trunk/Scribus/scribus/fonts/scface_ttf.cpp Fri Oct 17 22:07:00 2014
@@ -561,8 +561,6 @@
 	                           (face->charmap && face->charmap->encoding == FT_ENCODING_UNICODE);
 	if (!avoidFntNames)
 		return FtFace::glyphNames(GList);
-
-	const bool hasPSNames = FT_HAS_GLYPH_NAMES(face);
 	
 //	qDebug() << "reading metrics for" << face->family_name << face->style_name;
 	charcode = FT_Get_First_Char(face, &gindex);

Modified: trunk/Scribus/scribus/gtwriter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/gtwriter.h
==============================================================================
--- trunk/Scribus/scribus/gtwriter.h (original)
+++ trunk/Scribus/scribus/gtwriter.h Fri Oct 17 22:07:00 2014
@@ -78,7 +78,6 @@
 	gtStyle* paragraphStyle;
 	gtStyle* characterStyle;
 	bool errorSet;
-	bool shouldAppend;
 	void setDefaultStyle();
 };
 

Modified: trunk/Scribus/scribus/loadsaveplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/loadsaveplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/loadsaveplugin.cpp (original)
+++ trunk/Scribus/scribus/loadsaveplugin.cpp Fri Oct 17 22:07:00 2014
@@ -350,7 +350,6 @@
 void LoadSavePlugin::unregisterAll()
 {
 	QList<FileFormat>::iterator it(formats.begin());
-	QList<FileFormat>::iterator itEnd(formats.end());
 	while (it != formats.end())
 	{
 		if ((*it).plug == this)

Modified: trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp (original)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp Fri Oct 17 22:07:00 2014
@@ -1061,9 +1061,8 @@
 
 /*** ListStyle **********************************************************************************/
 
-ListStyle::ListStyle(const QString &name, bool consecutiveNumbering, uint currentLevel) :
+ListStyle::ListStyle(const QString &name, uint currentLevel) :
 m_name(name),
-m_consecutiveNumbering(consecutiveNumbering),
 m_currentLevel(currentLevel),
 m_count(0)
 {

Modified: trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.h (original)
+++ trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.h Fri Oct 17 22:07:00 2014
@@ -96,7 +96,7 @@
 class ListStyle
 {
 public:
-	ListStyle(const QString &name, bool consecutiveNumbering = false, uint currentLevel = 1);
+	ListStyle(const QString &name, uint currentLevel = 1);
 	~ListStyle();
 	void addLevel(uint level, ListLevel *llevel);
 	QString bullet();
@@ -106,7 +106,6 @@
 	QString& name();
 private:
 	QString m_name;
-	bool m_consecutiveNumbering;
 	uint m_currentLevel;
 	uint m_count;
 	ListLevel* levels[11];

Modified: trunk/Scribus/scribus/plugins/gettext/xtgim/xtgim.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/gettext/xtgim/xtgim.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/xtgim/xtgim.h (original)
+++ trunk/Scribus/scribus/plugins/gettext/xtgim/xtgim.h Fri Oct 17 22:07:00 2014
@@ -1,60 +1,57 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
- /***************************************************************************
-  *   Copyright (C) 2009 by Jain Basil Aliyas                               *
-  *   mail at jainbasil.net                                                    *
-  *                                                                         *
-  *   This program is free software; you can redistribute it and/or modify  *
-  *   it under the terms of the GNU General Public License as published by  *
-  *   the Free Software Foundation; either version 2 of the License, or     *
-  *   (at your option) any later version.                                   *
-  *                                                                         *
-  *   This program is distributed in the hope that it will be useful,       *
-  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-  *   GNU General Public License for more details.                          *
-  *                                                                         *
-  *   You should have received a copy of the GNU General Public License     *
-  *   along with this program; if not, write to the                         *
-  *   Free Software Foundation, Inc.,                                       *
-  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
-  ***************************************************************************/
-
-#ifndef XTGIM_H
-#define XTGIM_H
-
-#include "pluginapi.h"
-#include "pageitem.h"
-
-#include <QByteArray>
-#include <QList>
-#include <QString>
-#include "textwriter.h"
-
-class StyleManager;
-
-extern "C" PLUGIN_API void GetText2(QString filename, QString encoding, bool textOnly, PageItem *textItem);
-extern "C" PLUGIN_API QString FileFormatName();
-extern "C" PLUGIN_API QStringList FileExtensions();
-
-class XtgIm
-{
-private:
-	QString encoding;
-	QString filename;
-	QString in_Buffer;
-	QByteArray buffer;
-	PageItem *textFrame;
-	TextWriter *writer;
-	void loadFiletoArray();
-	QString toUnicode(const QByteArray& rawText);
-	StyleManager *StyleMan;
-public:
-	XtgIm(QString fileName,QString enc,PageItem *textItem,bool textOnly);
-	~XtgIm();
-};
-#endif			/* XTGIM_H */
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+ /***************************************************************************
+  *   Copyright (C) 2009 by Jain Basil Aliyas                               *
+  *   mail at jainbasil.net                                                    *
+  *                                                                         *
+  *   This program is free software; you can redistribute it and/or modify  *
+  *   it under the terms of the GNU General Public License as published by  *
+  *   the Free Software Foundation; either version 2 of the License, or     *
+  *   (at your option) any later version.                                   *
+  *                                                                         *
+  *   This program is distributed in the hope that it will be useful,       *
+  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+  *   GNU General Public License for more details.                          *
+  *                                                                         *
+  *   You should have received a copy of the GNU General Public License     *
+  *   along with this program; if not, write to the                         *
+  *   Free Software Foundation, Inc.,                                       *
+  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
+  ***************************************************************************/
+
+#ifndef XTGIM_H
+#define XTGIM_H
+
+#include "pluginapi.h"
+#include "pageitem.h"
+
+#include <QByteArray>
+#include <QList>
+#include <QString>
+#include "textwriter.h"
+
+class StyleManager;
+
+extern "C" PLUGIN_API void GetText2(QString filename, QString encoding, bool textOnly, PageItem *textItem);
+extern "C" PLUGIN_API QString FileFormatName();
+extern "C" PLUGIN_API QStringList FileExtensions();
+
+class XtgIm
+{
+private:
+	QString encoding;
+	QString filename;
+	QString in_Buffer;
+	QByteArray buffer;
+	void loadFiletoArray();
+	QString toUnicode(const QByteArray& rawText);
+public:
+	XtgIm(QString fileName,QString enc,PageItem *textItem,bool textOnly);
+	~XtgIm();
+};
+#endif			/* XTGIM_H */

Modified: trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp Fri Oct 17 22:07:00 2014
@@ -2532,6 +2532,10 @@
 			double s1 = getBinaryReal(ts, realPrecision, realMantissa);
 			qDebug() << "Stages " << s1;
 		}
+		Q_UNUSED(posI);
+		Q_UNUSED(type);
+		Q_UNUSED(p1);
+		Q_UNUSED(p2);
 /*		int pos = ts.device()->pos();
 		uint type = getBinaryUInt(ts, indexPrecision);
 		QPointF p, p2;

Modified: trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/odg/importodg.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/odg/importodg.cpp Fri Oct 17 22:07:00 2014
@@ -3448,7 +3448,6 @@
 					EndArrow.map(m);
 					refP = m.map(refP);
 					QPainterPath pa2 = EndArrow.toQPainterPath(true);
-					QRectF br2 = pa2.boundingRect();
 					QTransform m2;
 					FPoint grOffset2(getMinClipF(&EndArrow));
 					m2.translate(-grOffset2.x(), -grOffset2.y());

Modified: trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pct/importpct.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pct/importpct.cpp Fri Oct 17 22:07:00 2014
@@ -1716,6 +1716,7 @@
 	}
 // reading scrRect
 	QRect scrRect = readRect(ts);
+	Q_UNUSED(scrRect);
 //	qDebug() << "Src Rect" << scrRect;
 // reading dstRect
 	QRect dstRect = readRect(ts);
@@ -1881,11 +1882,11 @@
 	handleLineModeEnd();
 	alignStreamToWord(ts, 38);		// Skip version and Matrix information
 	ts >> matteSize;
-	QRect matteRect = readRect(ts);
+	/*QRect matteRect =*/ readRect(ts);
 	if (opCode == 0x8200)
 	{
 		ts >> mode;
-		QRect srcRect = readRect(ts);
+		/*QRect srcRect =*/ readRect(ts);
 		alignStreamToWord(ts, 4);
 		ts >> maskSize;
 		if (matteSize != 0)

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp Fri Oct 17 22:07:00 2014
@@ -1,4060 +1,4059 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include "slaoutput.h"
-#include <poppler/GlobalParams.h>
-#include <poppler/poppler-config.h>
-#include <poppler/FileSpec.h>
-#include <poppler/fofi/FoFiTrueType.h>
-#include <QApplication>
-#include <QFile>
-#include "commonstrings.h"
-#include "loadsaveplugin.h"
-#include "sccolorengine.h"
-#include "util.h"
-#include "util_math.h"
-#include <tiffio.h>
-
-LinkSubmitForm::LinkSubmitForm(Object *actionObj)
-{
-	Object obj1, obj2, obj3;
-	fileName = NULL;
-	m_flags = 0;
-	if (actionObj->isDict())
-	{
-		if (!actionObj->dictLookup("F", &obj1)->isNull())
-		{
-			if (obj1.isDict())
-			{
-				if (!obj1.dictLookup("FS", &obj3)->isNull())
-				{
-					if (obj3.isName())
-					{
-						char *name = obj3.getName();
-						if (!strcmp(name, "URL"))
-						{
-							if (!obj1.dictLookup("F", &obj2)->isNull())
-								fileName = obj2.getString()->copy();
-						}
-						obj2.free();
-					}
-				}
-				obj3.free();
-			}
-		}
-		obj1.free();
-		if (!actionObj->dictLookup("Flags", &obj1)->isNull())
-		{
-			if (obj1.isNum())
-				m_flags = obj1.getInt();
-		}
-		obj1.free();
-	}
-}
-
-LinkSubmitForm::~LinkSubmitForm()
-{
-	if (fileName)
-		delete fileName;
-}
-
-LinkImportData::LinkImportData(Object *actionObj)
-{
-	Object obj1, obj3;
-	fileName = NULL;
-	if (actionObj->isDict())
-	{
-		if (!actionObj->dictLookup("F", &obj1)->isNull())
-		{
-			if (getFileSpecNameForPlatform (&obj1, &obj3))
-			{
-				fileName = obj3.getString()->copy();
-				obj3.free();
-			}
-		}
-		obj1.free();
-	}
-}
-
-LinkImportData::~LinkImportData()
-{
-	if (fileName)
-		delete fileName;
-}
-
-AnoOutputDev::~AnoOutputDev()
-{
-	if (m_fontName)
-		delete m_fontName;
-	if (m_itemText)
-		delete m_itemText;
-}
-
-AnoOutputDev::AnoOutputDev(ScribusDoc* doc, QStringList *importedColors)
-{
-	m_doc = doc;
-	m_importedColors = importedColors;
-	CurrColorStroke = CommonStrings::None;
-	CurrColorFill = CommonStrings::None;
-	CurrColorText = "Black";
-	m_fontSize = 12.0;
-	m_fontName = NULL;
-	m_itemText = NULL;
-}
-
-void AnoOutputDev::eoFill(GfxState *state)
-{
-	int shade = 100;
-	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
-}
-
-void AnoOutputDev::fill(GfxState *state)
-{
-	int shade = 100;
-	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
-}
-
-void AnoOutputDev::stroke(GfxState *state)
-{
-	int shade = 100;
-	CurrColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &shade);
-}
-
-void AnoOutputDev::drawString(GfxState *state, GooString *s)
-{
-	int shade = 100;
-	CurrColorText = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
-	m_fontSize = state->getFontSize();
-	if (state->getFont())
-		m_fontName = state->getFont()->getName()->copy();
-	m_itemText = s->copy();
-}
-
-QString AnoOutputDev::getColor(GfxColorSpace *color_space, GfxColor *color, int *shade)
-{
-	QString fNam;
-	QString namPrefix = "FromPDF";
-	ScColor tmp;
-	tmp.setSpotColor(false);
-	tmp.setRegistrationColor(false);
-	*shade = 100;
-	if ((color_space->getMode() == csDeviceRGB) || (color_space->getMode() == csCalRGB))
-	{
-		GfxRGB rgb;
-		color_space->getRGB(color, &rgb);
-		int Rc = qRound(colToDbl(rgb.r) * 255);
-		int Gc = qRound(colToDbl(rgb.g) * 255);
-		int Bc = qRound(colToDbl(rgb.b) * 255);
-		tmp.setColorRGB(Rc, Gc, Bc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if (color_space->getMode() == csDeviceCMYK)
-	{
-		GfxCMYK cmyk;
-		color_space->getCMYK(color, &cmyk);
-		int Cc = qRound(colToDbl(cmyk.c) * 255);
-		int Mc = qRound(colToDbl(cmyk.m) * 255);
-		int Yc = qRound(colToDbl(cmyk.y) * 255);
-		int Kc = qRound(colToDbl(cmyk.k) * 255);
-		tmp.setColor(Cc, Mc, Yc, Kc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if ((color_space->getMode() == csCalGray) || (color_space->getMode() == csDeviceGray))
-	{
-		GfxGray gray;
-		color_space->getGray(color, &gray);
-		int Kc = 255 - qRound(colToDbl(gray) * 255);
-		tmp.setColor(0, 0, 0, Kc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if (color_space->getMode() == csSeparation)
-	{
-		GfxCMYK cmyk;
-		color_space->getCMYK(color, &cmyk);
-		int Cc = qRound(colToDbl(cmyk.c) * 255);
-		int Mc = qRound(colToDbl(cmyk.m) * 255);
-		int Yc = qRound(colToDbl(cmyk.y) * 255);
-		int Kc = qRound(colToDbl(cmyk.k) * 255);
-		tmp.setColor(Cc, Mc, Yc, Kc);
-		tmp.setSpotColor(true);
-		QString nam = QString(((GfxSeparationColorSpace*)color_space)->getName()->getCString());
-		fNam = m_doc->PageColors.tryAddColor(nam, tmp);
-		*shade = qRound(colToDbl(color->c[0]) * 100);
-	}
-	else
-	{
-		GfxRGB rgb;
-		color_space->getRGB(color, &rgb);
-		int Rc = qRound(colToDbl(rgb.r) * 255);
-		int Gc = qRound(colToDbl(rgb.g) * 255);
-		int Bc = qRound(colToDbl(rgb.b) * 255);
-		tmp.setColorRGB(Rc, Gc, Bc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	//	qDebug() << "update fill color other colorspace" << color_space->getMode() << "treating as rgb" << Rc << Gc << Bc;
-	}
-	if (fNam == namPrefix+tmp.name())
-		m_importedColors->append(fNam);
-	return fNam;
-}
-
-SlaOutputDev::SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringList *importedColors, int flags)
-{
-	m_doc = doc;
-	m_Elements = Elements;
-	m_groupStack.clear();
-	pushGroup();
-	m_clipStack.clear();
-	m_currentMask = "";
-	m_importedColors = importedColors;
-	CurrColorStroke = "Black";
-	CurrColorFill = "Black";
-	Coords = "";
-	pathIsClosed = false;
-	tmpSel = new Selection(m_doc, false);
-	grStackDepth = 0;
-	firstLayer = true;
-	layerNum = 1;
-	importerFlags = flags;
-	currentLayer = m_doc->activeLayer();
-	xref = NULL;
-	m_fontEngine = 0;
-	m_font = 0;
-	m_formWidgets = 0;
-	updateGUICounter = 0;
-	layersSetByOCG = false;
-	cropOffsetX = 0;
-	cropOffsetY = 0;
-}
-
-SlaOutputDev::~SlaOutputDev()
-{
-	m_groupStack.clear();
-	tmpSel->clear();
-	delete tmpSel;
-	delete m_fontEngine;
-}
-
-/* get Actions not implemented by Poppler */
-LinkAction* SlaOutputDev::SC_getAction(AnnotWidget *ano)
-{
-	LinkAction *linkAction = NULL;
-	Object obj;
-	Ref refa = ano->getRef();
-	Object additionalActions;
-	Object *act = xref->fetch(refa.num, refa.gen, &obj);
-	if (act)
-	{
-		if (act->isDict())
-		{
-			Dict* adic = act->getDict();
-			adic->lookupNF("A", &additionalActions);
-			Object additionalActionsObject;
-			if (additionalActions.fetch(pdfDoc->getXRef(), &additionalActionsObject)->isDict())
-			{
-				Object actionObject;
-				additionalActionsObject.dictLookup("S", &actionObject);
-				if (actionObject.isName("ImportData"))
-				{
-					linkAction = new LinkImportData(&additionalActionsObject);
-				}
-				else if (actionObject.isName("SubmitForm"))
-				{
-					linkAction = new LinkSubmitForm(&additionalActionsObject);
-				}
-				actionObject.free();
-			}
-			additionalActionsObject.free();
-			additionalActions.free();
-		}
-	}
-	obj.free();
-	return linkAction;
-}
-
-/* Replacement for the crippled Poppler function LinkAction* AnnotWidget::getAdditionalAction(AdditionalActionsType type) */
-LinkAction* SlaOutputDev::SC_getAdditionalAction(const char *key, AnnotWidget *ano)
-{
-	LinkAction *linkAction = NULL;
-	Object obj;
-	Ref refa = ano->getRef();
-	Object additionalActions;
-	Object *act = xref->fetch(refa.num, refa.gen, &obj);
-	if (act)
-	{
-		if (act->isDict())
-		{
-			Dict* adic = act->getDict();
-			adic->lookupNF("AA", &additionalActions);
-			Object additionalActionsObject;
-			if (additionalActions.fetch(pdfDoc->getXRef(), &additionalActionsObject)->isDict())
-			{
-				Object actionObject;
-				if (additionalActionsObject.dictLookup(key, &actionObject)->isDict())
-					linkAction = LinkAction::parseAction(&actionObject, pdfDoc->getCatalog()->getBaseURI());
-				actionObject.free();
-			}
-			additionalActionsObject.free();
-			additionalActions.free();
-		}
-	}
-	obj.free();
-	return linkAction;
-}
-
-GBool SlaOutputDev::annotations_callback(Annot *annota, void *user_data)
-{
-	SlaOutputDev *dev = (SlaOutputDev*)user_data;
-	PDFRectangle *box = annota->getRect();
-	double xCoor = dev->m_doc->currentPage()->xOffset() + box->x1 - dev->cropOffsetX;
-	double yCoor = dev->m_doc->currentPage()->yOffset() + dev->m_doc->currentPage()->height() - box->y2 + dev->cropOffsetY;
-	double width = box->x2 - box->x1;
-	double height = box->y2 - box->y1;
-	if (dev->rotate == 90)
-	{
-		xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + box->y2;
-		yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + box->x1;
-	}
-	else if (dev->rotate == 180)
-	{
-		xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + dev->m_doc->currentPage()->width() - box->x1;
-		yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + box->y2;
-	}
-	else if (dev->rotate == 270)
-	{
-		xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + dev->m_doc->currentPage()->width() - box->y2;
-		yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + dev->m_doc->currentPage()->height() - box->x1;
-	}
-	bool retVal = true;
-	if (annota->getType() == Annot::typeText)
-		retVal = !dev->handleTextAnnot(annota, xCoor, yCoor, width, height);
-	else if (annota->getType() == Annot::typeLink)
-		retVal = !dev->handleLinkAnnot(annota, xCoor, yCoor, width, height);
-	else if (annota->getType() == Annot::typeWidget)
-		retVal = !dev->handleWidgetAnnot(annota, xCoor, yCoor, width, height);
-	return retVal;
-}
-
-bool SlaOutputDev::handleTextAnnot(Annot* annota, double xCoor, double yCoor, double width, double height)
-{
-	AnnotText *anl = (AnnotText*)annota;
-	int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem *ite = m_doc->Items->at(z);
-	int flg = annota->getFlags();
-	if (!(flg & 16))
-		ite->setRotation(rotate, true);
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillEvenOdd(false);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->ContourLine = ite->PoLine.copy();
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	ite->setIsAnnotation(true);
-	ite->AutoName = false;
-	ite->annotation().setType(Annotation::Text);
-	ite->annotation().setActionType(Annotation::Action_None);
-	ite->annotation().setAnOpen(anl->getOpen());
-	QString iconName = UnicodeParsedString(anl->getIcon());
-	if (iconName == "Note")
-		ite->annotation().setIcon(Annotation::Icon_Note);
-	else if (iconName == "Comment")
-		ite->annotation().setIcon(Annotation::Icon_Comment);
-	else if (iconName == "Key")
-		ite->annotation().setIcon(Annotation::Icon_Key);
-	else if (iconName == "Help")
-		ite->annotation().setIcon(Annotation::Icon_Help);
-	else if (iconName == "NewParagraph")
-		ite->annotation().setIcon(Annotation::Icon_NewParagraph);
-	else if (iconName == "Paragraph")
-		ite->annotation().setIcon(Annotation::Icon_Paragraph);
-	else if (iconName == "Insert")
-		ite->annotation().setIcon(Annotation::Icon_Insert);
-	else if (iconName == "Cross")
-		ite->annotation().setIcon(Annotation::Icon_Cross);
-	else if (iconName == "Circle")
-		ite->annotation().setIcon(Annotation::Icon_Circle);
-	else
-		ite->annotation().setIcon(Annotation::Icon_Note);
-	ite->setItemName( CommonStrings::itemName_TextAnnotation + QString("%1").arg(m_doc->TotalItems));
-	ite->itemText.insertChars(UnicodeParsedString(annota->getContents()));
-	ite->itemText.trim();
-	return true;
-}
-
-bool SlaOutputDev::handleLinkAnnot(Annot* annota, double xCoor, double yCoor, double width, double height)
-{
-	AnnotLink *anl = (AnnotLink*)annota;
-	LinkAction *act = anl->getAction();
-	if (!act)
-		return false;
-	bool validLink = false;
-	int pagNum = 0;
-	int xco = 0;
-	int yco = 0;
-	QString fileName = "";
-	if (act->getKind() == actionGoTo)
-	{
-		LinkGoTo *gto = (LinkGoTo*)act;
-		LinkDest *dst = gto->getDest();
-		if (dst)
-		{
-			if (dst->getKind() == destXYZ)
-			{
-				if (dst->isPageRef())
-				{
-					Ref dstr = dst->getPageRef();
-					pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
-				}
-				else
-					pagNum = dst->getPageNum();
-				xco = dst->getLeft();
-				yco = dst->getTop();
-				validLink = true;
-			}
-		}
-		else
-		{
-			GooString *ndst = gto->getNamedDest();
-			if (ndst)
-			{
-				LinkDest *dstn = pdfDoc->findDest(ndst);
-				if (dstn)
-				{
-					if (dstn->getKind() == destXYZ)
-					{
-						if (dstn->isPageRef())
-						{
-							Ref dstr = dstn->getPageRef();
-							pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
-						}
-						else
-							pagNum = dstn->getPageNum();
-						xco = dstn->getLeft();
-						yco = dstn->getTop();
-						validLink = true;
-					}
-				}
-			}
-		}
-	}
-	else if (act->getKind() == actionGoToR)
-	{
-		LinkGoToR *gto = (LinkGoToR*)act;
-		fileName = UnicodeParsedString(gto->getFileName());
-		LinkDest *dst = gto->getDest();
-		if (dst)
-		{
-			if (dst->getKind() == destXYZ)
-			{
-				pagNum = dst->getPageNum();
-				xco = dst->getLeft();
-				yco = dst->getTop();
-				validLink = true;
-			}
-		}
-		else
-		{
-			GooString *ndst = gto->getNamedDest();
-			if (ndst)
-			{
-				LinkDest *dstn = pdfDoc->findDest(ndst);
-				if (dstn)
-				{
-					if (dstn->getKind() == destXYZ)
-					{
-						pagNum = dstn->getPageNum();
-						xco = dstn->getLeft();
-						yco = dstn->getTop();
-						validLink = true;
-					}
-				}
-			}
-		}
-	}
-	else if (act->getKind() == actionURI)
-	{
-		LinkURI *gto = (LinkURI*)act;
-		validLink = true;
-		fileName = UnicodeParsedString(gto->getURI());
-	}
-	if (validLink)
-	{
-		int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CommonStrings::None, CommonStrings::None, true);
-		PageItem *ite = m_doc->Items->at(z);
-		int flg = annota->getFlags();
-		if (!(flg & 16))
-			ite->setRotation(rotate, true);
-		ite->ClipEdited = true;
-		ite->FrameType = 3;
-		ite->setFillEvenOdd(false);
-		ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-		ite->ContourLine = ite->PoLine.copy();
-		ite->setTextFlowMode(PageItem::TextFlowDisabled);
-		m_Elements->append(ite);
-		if (m_groupStack.count() != 0)
-		{
-			m_groupStack.top().Items.append(ite);
-			applyMask(ite);
-		}
-		ite->setIsAnnotation(true);
-		ite->AutoName = false;
-		if (act->getKind() == actionGoTo)
-		{
-			ite->annotation().setZiel(pagNum - 1);
-			ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
-			ite->annotation().setActionType(2);
-		}
-		else if (act->getKind() == actionGoToR)
-		{
-			ite->annotation().setZiel(pagNum - 1);
-			ite->annotation().setExtern(fileName);
-			ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
-			ite->annotation().setActionType(9);
-		}
-		else if (act->getKind() == actionURI)
-		{
-			ite->annotation().setAction("");
-			ite->annotation().setExtern(fileName);
-			ite->annotation().setActionType(8);
-		}
-		ite->annotation().setType(Annotation::Link);
-		ite->setItemName( CommonStrings::itemName_LinkAnnotation + QString("%1").arg(m_doc->TotalItems));
-	}
-	return validLink;
-}
-
-bool SlaOutputDev::handleWidgetAnnot(Annot* annota, double xCoor, double yCoor, double width, double height)
-{
-	bool retVal = false;
-	bool found = false;
-
-	if (!m_formWidgets)
-		return false;
-
-	int formcount = m_formWidgets->getNumWidgets();
-	for (int i = 0; i < formcount; ++i)
-	{
-		FormWidget *fm = m_formWidgets->getWidget(i);
-		if (!fm)
-			continue;
-		AnnotWidget *ano = fm->getWidgetAnnotation();
-		if (!ano)
-			continue;
-		if (ano != (AnnotWidget*) annota)
-			continue;
-		found = true;
-		int wtyp = -1;
-		if (fm->getType() == formButton)
-		{
-			FormWidgetButton *btn = (FormWidgetButton*)fm;
-			if (btn)
-			{
-				if (btn->getButtonType() == formButtonCheck)
-				{
-					wtyp = Annotation::Checkbox;
-					retVal = true;
-				}
-				else if (btn->getButtonType() == formButtonPush)
-				{
-					wtyp = Annotation::Button;
-					retVal = true;
-				}
-				else if (btn->getButtonType() == formButtonRadio)
-				{
-					wtyp = Annotation::RadioButton;
-					retVal = true;
-				}
-			}
-		}
-		else if (fm->getType() == formText)
-		{
-			wtyp = Annotation::Textfield;
-			retVal = true;
-		}
-		else if (fm->getType() == formChoice)
-		{
-			FormWidgetChoice *btn = (FormWidgetChoice*)fm;
-			if (btn)
-			{
-				if (btn->isCombo())
-				{
-					wtyp = Annotation::Combobox;
-					retVal = true;
-				}
-				else if (btn->isListBox())
-				{
-					wtyp = Annotation::Listbox;
-					retVal = true;
-				}
-			}
-		}
-		if (retVal)
-		{
-			AnnotAppearanceCharacs *achar = ano->getAppearCharacs();
-			bool fgFound = false;
-			bool bgFound = false;
-			if (achar)
-			{
-				AnnotColor *bgCol = achar->getBackColor();
-				if (bgCol)
-				{
-					bgFound = true;
-					CurrColorFill = getAnnotationColor(bgCol);
-				}
-				else
-					CurrColorFill = CommonStrings::None;
-				AnnotColor *fgCol = achar->getBorderColor();
-				if (fgCol)
-				{
-					fgFound = true;
-					CurrColorStroke = getAnnotationColor(fgCol);
-				}
-				else
-				{
-					fgCol = achar->getBackColor();
-					if (fgCol)
-						CurrColorStroke = getAnnotationColor(fgCol);
-					else
-						CurrColorStroke = CommonStrings::None;
-				}
-			}
-			QString CurrColorText = "Black";
-			double fontSize = 12;
-			QString fontName = "";
-			QString itemText = "";
-			AnnotAppearance *apa = annota->getAppearStreams();
-			if (apa || !achar)
-			{
-				AnoOutputDev *Adev = new AnoOutputDev(m_doc, m_importedColors);
-				Gfx *gfx;
-#ifdef POPPLER_VERSION
-				gfx = new Gfx(pdfDoc, Adev, pdfDoc->getPage(m_actPage)->getResourceDict(), annota->getRect(), NULL);
-#else
-				gfx = new Gfx(xref, Adev, pdfDoc->getPage(m_actPage)->getResourceDict(), catalog, annota->getRect(), NULL);
-#endif
-				ano->draw(gfx, false);
-				if (!bgFound)
-					CurrColorFill = Adev->CurrColorFill;
-				if (!fgFound)
-					CurrColorStroke = Adev->CurrColorStroke;
-				CurrColorText = Adev->CurrColorText;
-				fontSize = Adev->m_fontSize;
-				fontName = UnicodeParsedString(Adev->m_fontName);
-				itemText = UnicodeParsedString(Adev->m_itemText);
-				delete gfx;
-				delete Adev;
-			}
-			int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CurrColorFill, CommonStrings::None, true);
-			PageItem *ite = m_doc->Items->at(z);
-			int flg = annota->getFlags();
-			if (!(flg & 16))
-				ite->setRotation(rotate, true);
-			ite->ClipEdited = true;
-			ite->FrameType = 3;
-			ite->setFillEvenOdd(false);
-			ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-			ite->ContourLine = ite->PoLine.copy();
-			ite->setTextFlowMode(PageItem::TextFlowDisabled);
-			m_Elements->append(ite);
-			if (m_groupStack.count() != 0)
-			{
-				m_groupStack.top().Items.append(ite);
-				applyMask(ite);
-			}
-			ite->setIsAnnotation(true);
-			ite->AutoName = false;
-			AnnotBorder *brd = annota->getBorder();
-			if (brd)
-			{
-				int bsty = brd->getStyle();
-				if (bsty == AnnotBorder::borderDashed)
-					bsty = 1;
-				else if (bsty == AnnotBorder::borderBeveled)
-					bsty = 3;
-				else if (bsty == AnnotBorder::borderInset)
-					bsty = 4;
-				else if (bsty == AnnotBorder::borderUnderlined)
-					bsty = 2;
-				ite->annotation().setBsty(bsty);
-				ite->annotation().setBorderColor(CurrColorStroke);
-				ite->annotation().setBwid(qRound(brd->getWidth()));
-			}
-			else
-			{
-				ite->annotation().setBsty(0);
-				ite->annotation().setBorderColor(CommonStrings::None);
-				ite->annotation().setBwid(0);
-			}
-			QString tmTxt = "";
-			tmTxt = UnicodeParsedString(fm->getPartialName());
-			if (!tmTxt.isEmpty())
-				ite->setItemName(tmTxt);
-			tmTxt = "";
-			tmTxt = UnicodeParsedString(fm->getAlternateUiName());
-			if (!tmTxt.isEmpty())
-				ite->annotation().setToolTip(tmTxt);
-			tmTxt = "";
-			if (achar)
-			{
-				tmTxt = UnicodeParsedString(achar->getRolloverCaption());
-				if (!tmTxt.isEmpty())
-					ite->annotation().setRollOver(tmTxt);
-				tmTxt = "";
-				tmTxt = UnicodeParsedString(achar->getAlternateCaption());
-				if (!tmTxt.isEmpty())
-					ite->annotation().setDown(tmTxt);
-			}
-			ite->annotation().setType(wtyp);
-			ite->annotation().setFlag(0);
-			if (flg & 2)
-				ite->annotation().setVis(1);
-			if (flg & 32)
-				ite->annotation().setVis(3);
-			if (wtyp == Annotation::Button)
-			{
-				ite->setFillColor(CurrColorFill);
-				if (achar)
-					ite->itemText.insertChars(UnicodeParsedString(achar->getNormalCaption()));
-				else
-					ite->itemText.insertChars(itemText);
-				applyTextStyle(ite, fontName, CurrColorText, fontSize);
-				ite->annotation().addToFlag(Annotation::Flag_PushButton);
-				FormWidgetButton *btn = (FormWidgetButton*)fm;
-				if (!btn->isReadOnly())
-					ite->annotation().addToFlag(Annotation::Flag_Edit);
-				handleActions(ite, ano);
-			}
-			else if (wtyp == Annotation::Textfield)
-			{
-				FormWidgetText *btn = (FormWidgetText*)fm;
-				if (btn)
-				{
-					ite->itemText.insertChars(UnicodeParsedString(btn->getContent()));
-					applyTextStyle(ite, fontName, CurrColorText, fontSize);
-					ite->itemText.trim();
-					if (btn->isMultiline())
-						ite->annotation().addToFlag(Annotation::Flag_Multiline);
-					if (btn->isPassword())
-						ite->annotation().addToFlag(Annotation::Flag_Password);
-					if (btn->noSpellCheck())
-						ite->annotation().addToFlag(Annotation::Flag_DoNotSpellCheck);
-					if (btn->noScroll())
-						ite->annotation().addToFlag(Annotation::Flag_DoNotScroll);
-					int mxLen = btn->getMaxLen();
-					if (mxLen > 0)
-						ite->annotation().setMaxChar(mxLen);
-					else
-						ite->annotation().setMaxChar(-1);
-					if (!btn->isReadOnly())
-						ite->annotation().addToFlag(Annotation::Flag_Edit);
-					handleActions(ite, ano);
-				}
-			}
-			else if (wtyp == Annotation::Checkbox)
-			{
-				FormWidgetButton *btn = (FormWidgetButton*)fm;
-				if (btn)
-				{
-					ite->annotation().setIsChk(btn->getState());
-					ite->annotation().setCheckState(ite->annotation().IsChk());
-					handleActions(ite, ano);
-					if (itemText == "4")
-						ite->annotation().setChkStil(0);
-					else if (itemText == "5")
-						ite->annotation().setChkStil(1);
-					else if (itemText == "F")
-						ite->annotation().setChkStil(2);
-					else if (itemText == "l")
-						ite->annotation().setChkStil(3);
-					else if (itemText == "H")
-						ite->annotation().setChkStil(4);
-					else if (itemText == "n")
-						ite->annotation().setChkStil(5);
-					else
-						ite->annotation().setChkStil(0);
-					if (!btn->isReadOnly())
-						ite->annotation().addToFlag(Annotation::Flag_Edit);
-				}
-			}
-			else if ((wtyp == Annotation::Combobox) || (wtyp == Annotation::Listbox))
-			{
-				FormWidgetChoice *btn = (FormWidgetChoice*)fm;
-				if (btn)
-				{
-					if (wtyp == 5)
-						ite->annotation().addToFlag(Annotation::Flag_Combo);
-					int co = btn->getNumChoices();
-					if (co > 0)
-					{
-						QString inh = UnicodeParsedString(btn->getChoice(0));
-						for (int a = 1; a < co; a++)
-						{
-							inh += "\n" + UnicodeParsedString(btn->getChoice(a));
-						}
-						ite->itemText.insertChars(inh);
-					}
-					applyTextStyle(ite, fontName, CurrColorText, fontSize);
-					if (!btn->isReadOnly())
-						ite->annotation().addToFlag(Annotation::Flag_Edit);
-					handleActions(ite, ano);
-				}
-			}
-			else if (wtyp == Annotation::RadioButton)
-			{
-				FormWidgetButton *btn = (FormWidgetButton*)fm;
-				if (btn)
-				{
-					ite->setItemName( CommonStrings::itemName_RadioButton + QString("%1").arg(m_doc->TotalItems));
-					ite->annotation().setIsChk(btn->getState());
-					ite->annotation().setCheckState(ite->annotation().IsChk());
-					handleActions(ite, ano);
-					m_radioButtons.insert(annota->getRef().num, ite);
-				}
-			}
-		}
-		break;
-	}
-	if (!found)
-	{
-		Object obj1;
-		Ref refa = annota->getRef();
-		Object *act = xref->fetch(refa.num, refa.gen, &obj1);
-		if (act && act->isDict())
-		{
-			Dict* dict = act->getDict();
-			Object obj2;
-			//childs
-			if (dict->lookup("Kids", &obj2)->isArray())
-			{
-				// Load children
-				QList<int> radList;
-				for (int i = 0 ; i < obj2.arrayGetLength(); i++)
-				{
-					Object childRef, childObj;
-					if (!obj2.arrayGetNF(i, &childRef)->isRef())
-					{
-						childRef.free();
-						continue;
-					}
-					if (!obj2.arrayGet(i, &childObj)->isDict())
-					{
-						childObj.free();
-						childRef.free();
-						continue;
-					}
-					const Ref ref = childRef.getRef();
-					radList.append(ref.num);
-					childObj.free();
-					childRef.free();
-				}
-				QString tmTxt = UnicodeParsedString(annota->getName());
-				m_radioMap.insert(tmTxt, radList);
-			}
-			obj2.free();
-		}
-		obj1.free();
-	}
-	return retVal;
-}
-
-void SlaOutputDev::applyTextStyle(PageItem* ite, QString fontName, QString textColor, double fontSize)
-{
-	CharStyle newStyle;
-	newStyle.setFillColor(textColor);
-	newStyle.setFontSize(fontSize * 10);
-	if (!fontName.isEmpty())
-	{
-		SCFontsIterator it(*m_doc->AllFonts);
-		for ( ; it.hasNext() ; it.next())
-		{
-			ScFace& face(it.current());
-			if ((face.psName() == fontName) && (face.usable()) && (face.type() == ScFace::TTF))
-			{
-				newStyle.setFont(face);
-				break;
-			}
-			else if ((face.family() == fontName) && (face.usable()) && (face.type() == ScFace::TTF))
-			{
-				newStyle.setFont(face);
-				break;
-			}
-			else if ((face.scName() == fontName) && (face.usable()) && (face.type() == ScFace::TTF))
-			{
-				newStyle.setFont(face);
-				break;
-			}
-		}
-	}
-	ParagraphStyle dstyle(ite->itemText.defaultStyle());
-	dstyle.charStyle().applyCharStyle(newStyle);
-	ite->itemText.setDefaultStyle(dstyle);
-	ite->itemText.applyCharStyle(0, ite->itemText.length(), newStyle);
-	ite->invalid = true;
-}
-
-void SlaOutputDev::handleActions(PageItem* ite, AnnotWidget *ano)
-{
-	LinkAction *Lact = ano->getAction();
-	if (Lact)
-	{
-		if (Lact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Lact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setActionType(1);
-				ite->annotation().setAction(UnicodeParsedString(jsa->getScript()));
-			}
-		}
-		else if (Lact->getKind() == actionGoTo)
-		{
-			int pagNum = 0;
-			int xco = 0;
-			int yco = 0;
-			LinkGoTo *gto = (LinkGoTo*)Lact;
-			LinkDest *dst = gto->getDest();
-			if (dst)
-			{
-				if (dst->getKind() == destXYZ)
-				{
-					if (dst->isPageRef())
-					{
-						Ref dstr = dst->getPageRef();
-						pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
-					}
-					else
-						pagNum = dst->getPageNum();
-					xco = dst->getLeft();
-					yco = dst->getTop();
-					ite->annotation().setZiel(pagNum - 1);
-					ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
-					ite->annotation().setActionType(2);
-				}
-			}
-			else
-			{
-				GooString *ndst = gto->getNamedDest();
-				if (ndst)
-				{
-					LinkDest *dstn = pdfDoc->findDest(ndst);
-					if (dstn)
-					{
-						if (dstn->getKind() == destXYZ)
-						{
-							if (dstn->isPageRef())
-							{
-								Ref dstr = dstn->getPageRef();
-								pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
-							}
-							else
-								pagNum = dstn->getPageNum();
-							xco = dstn->getLeft();
-							yco = dstn->getTop();
-							ite->annotation().setZiel(pagNum - 1);
-							ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
-							ite->annotation().setActionType(2);
-						}
-					}
-				}
-			}
-		}
-		else if (Lact->getKind() == actionGoToR)
-		{
-			int pagNum = 0;
-			int xco = 0;
-			int yco = 0;
-			LinkGoToR *gto = (LinkGoToR*)Lact;
-			QString fileName = UnicodeParsedString(gto->getFileName());
-			LinkDest *dst = gto->getDest();
-			if (dst)
-			{
-				if (dst->getKind() == destXYZ)
-				{
-					pagNum = dst->getPageNum();
-					xco = dst->getLeft();
-					yco = dst->getTop();
-					ite->annotation().setZiel(pagNum - 1);
-					ite->annotation().setExtern(fileName);
-					ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
-					ite->annotation().setActionType(9);
-				}
-			}
-			else
-			{
-				GooString *ndst = gto->getNamedDest();
-				if (ndst)
-				{
-					LinkDest *dstn = pdfDoc->findDest(ndst);
-					if (dstn)
-					{
-						if (dstn->getKind() == destXYZ)
-						{
-							pagNum = dstn->getPageNum();
-							xco = dstn->getLeft();
-							yco = dstn->getTop();
-							ite->annotation().setZiel(pagNum - 1);
-							ite->annotation().setExtern(fileName);
-							ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
-							ite->annotation().setActionType(9);
-						}
-					}
-				}
-			}
-		}
-		else if (Lact->getKind() == actionUnknown)
-		{
-			LinkUnknown *uno = (LinkUnknown*)Lact;
-			QString actString = UnicodeParsedString(uno->getAction());
-			if (actString == "ResetForm")
-			{
-				ite->annotation().setActionType(4);
-			}
-			else
-			{
-				LinkAction* scact = SC_getAction(ano);
-				if (scact)
-				{
-					if (actString == "ImportData")
-					{
-						LinkImportData *impo = (LinkImportData*)scact;
-						if (impo->isOk())
-						{
-							ite->annotation().setActionType(5);
-							ite->annotation().setAction(UnicodeParsedString(impo->getFileName()));
-						}
-					}
-					else if (actString == "SubmitForm")
-					{
-						LinkSubmitForm *impo = (LinkSubmitForm*)scact;
-						if (impo->isOk())
-						{
-							ite->annotation().setActionType(3);
-							ite->annotation().setAction(UnicodeParsedString(impo->getFileName()));
-							int fl = impo->getFlags();
-							if (fl == 0)
-								ite->annotation().setHTML(0);
-							else if (fl == 4)
-								ite->annotation().setHTML(1);
-							else if (fl == 64)
-								ite->annotation().setHTML(2);
-							else if (fl == 512)
-								ite->annotation().setHTML(3);
-						}
-					}
-				}
-			}
-		}
-		else if (Lact->getKind() == actionNamed)
-		{
-			LinkNamed *uno = (LinkNamed*)Lact;
-			ite->annotation().setActionType(10);
-			ite->annotation().setAction(UnicodeParsedString(uno->getName()));
-		}
-		else
-			qDebug() << "Found unsupported Action of type" << Lact->getKind();
-	}
-	LinkAction *Aact = SC_getAdditionalAction("D", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setD_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("E", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setE_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("X", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setX_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("Fo", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setFo_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("Bl", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setBl_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("C", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setC_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("F", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setF_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-				ite->annotation().setFormat(5);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("K", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setK_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-				ite->annotation().setFormat(5);
-			}
-		}
-		Aact = NULL;
-	}
-	Aact = SC_getAdditionalAction("V", ano);
-	if (Aact)
-	{
-		if (Aact->getKind() == actionJavaScript)
-		{
-			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
-			if (jsa->isOk())
-			{
-				ite->annotation().setV_act(UnicodeParsedString(jsa->getScript()));
-				ite->annotation().setAAact(true);
-			}
-		}
-		Aact = NULL;
-	}
-}
-
-void SlaOutputDev::startDoc(PDFDoc *doc, XRef *xrefA, Catalog *catA)
-{
-	xref = xrefA;
-	catalog = catA;
-	pdfDoc = doc;
-	updateGUICounter = 0;
-	m_fontEngine = new SplashFontEngine(
-#if HAVE_T1LIB_H
-	globalParams->getEnableT1lib(),
-#endif
-#if HAVE_FREETYPE_H
-	globalParams->getEnableFreeType(),
-	true,
-	true,
-#endif
-	true);
-}
-
-void SlaOutputDev::startPage(int pageNum, GfxState *)
-{
-	m_formWidgets = pdfDoc->getPage(pageNum)->getFormWidgets();
-	m_radioMap.clear();
-	m_radioButtons.clear();
-	m_actPage = pageNum;
-}
-
-void SlaOutputDev::endPage()
-{
-	if (!m_radioMap.isEmpty())
-	{
-		QHash<QString, QList<int> >::iterator it;
-		for (it = m_radioMap.begin(); it != m_radioMap.end(); ++it)
-		{
-			tmpSel->clear();
-			QList<int> refList = it.value();
-			for (int a = 0; a < refList.count(); a++)
-			{
-				if (m_radioButtons.contains(refList[a]))
-				{
-					tmpSel->addItem(m_radioButtons[refList[a]], true);
-					m_Elements->removeAll(m_radioButtons[refList[a]]);
-				}
-			}
-			if (!tmpSel->isEmpty())
-			{
-				PageItem *ite = m_doc->groupObjectsSelection(tmpSel);
-				ite->setItemName(it.key());
-				m_Elements->append(ite);
-				if (m_groupStack.count() != 0)
-				{
-					m_groupStack.top().Items.append(ite);
-				}
-			}
-		}
-	}
-	m_radioMap.clear();
-	m_radioButtons.clear();
-//	qDebug() << "ending page";
-}
-
-void SlaOutputDev::saveState(GfxState *state)
-{
-//	qDebug() << "saveState" << grStackDepth;
-	grStackDepth++;
-}
-
-void SlaOutputDev::restoreState(GfxState *state)
-{
-//	qDebug() << "restoreState" << grStackDepth;
-	grStackDepth--;
-	if (m_groupStack.count() != 0)
-		m_groupStack.top().maskName = "";
-	if (m_clipStack.count() != 0)
-	{
-		while (m_clipStack.top().grStackDepth > grStackDepth)
-		{
-			clipEntry clp = m_clipStack.pop();
-			PageItem *ite = clp.ClipItem;
-			if (m_groupStack.count() != 0)
-			{
-				groupEntry gElements = m_groupStack.pop();
-				if (gElements.Items.count() > 0)
-				{
-					for (int d = 0; d < gElements.Items.count(); d++)
-					{
-						m_Elements->removeAll(gElements.Items.at(d));
-					}
-					PageItem *sing = gElements.Items.first();
-					QPainterPath input1 = sing->PoLine.toQPainterPath(true);
-					if (sing->fillEvenOdd())
-						input1.setFillRule(Qt::OddEvenFill);
-					else
-						input1.setFillRule(Qt::WindingFill);
-					QPainterPath input2 = ite->PoLine.toQPainterPath(true);
-					if (ite->fillEvenOdd())
-						input2.setFillRule(Qt::OddEvenFill);
-					else
-						input2.setFillRule(Qt::WindingFill);
-					QPainterPath result = input1.intersected(input2);
-					if ((gElements.Items.count() == 1)
-						 && (sing->isGroup() && !result.isEmpty())
-						 && (sing->isImageFrame() || sing->isGroup() || sing->isPolygon() || sing->isPolyLine())
-						 && (ite->patternMask().isEmpty() || sing->patternMask().isEmpty() || (sing->patternMask() == ite->patternMask()))
-						 && (state->getFillOpacity() == (1.0 - ite->fillTransparency()))
-					   )
-					{
-						m_Elements->replace(m_Elements->indexOf(ite), sing);
-						m_doc->Items->removeAll(sing);
-						m_doc->Items->replace(m_doc->Items->indexOf(ite), sing);
-						if (m_groupStack.top().Items.indexOf(ite) > -1)
-							m_groupStack.top().Items.replace(m_groupStack.top().Items.indexOf(ite), sing);
-						else
-							m_groupStack.top().Items.append(sing);
-						sing->setFillTransparency(1.0 - (state->getFillOpacity() * (1.0 - ite->fillTransparency())));
-						sing->setFillBlendmode(getBlendMode(state));
-						if (!ite->patternMask().isEmpty())
-						{
-							sing->setPatternMask(ite->patternMask());
-							sing->setMaskType(ite->maskType());
-						}
-						if (sing->isGroup() || (sing->lineColor() == CommonStrings::None))
-						{
-							double dx = sing->xPos() - ite->xPos();
-							double dy = sing->yPos() - ite->yPos();
-							sing->PoLine.translate(dx, dy);
-							if (sing->isGroup())
-							{
-								QList<PageItem*> allItems = sing->asGroupFrame()->groupItemList;
-								for (int si = 0; si < allItems.count(); si++)
-								{
-									allItems[si]->moveBy(dx, dy, true);
-								}
-							}
-							sing->setXYPos(ite->xPos(), ite->yPos(), true);
-							sing->setWidthHeight(ite->width(), ite->height(), true);
-							sing->groupWidth = ite->width();
-							sing->groupHeight = ite->height();
-							sing->ClipEdited = true;
-							sing->FrameType = 3;
-							if (!result.isEmpty())
-								sing->PoLine.fromQPainterPath(result);
-							else
-								sing->SetRectFrame();
-							m_doc->AdjustItemSize(sing);
-							if (sing->isGroup())
-								sing->asGroupFrame()->adjustXYPosition();
-							if (sing->isImageFrame())
-							{
-								sing->setImageXYOffset(0, 0);
-								sing->AdjustPictScale();
-							}
-						}
-						delete ite;
-					}
-					else
-					{
-						m_doc->groupObjectsToItem(ite, gElements.Items);
-						ite->setFillTransparency(1.0 - state->getFillOpacity());
-						ite->setFillBlendmode(getBlendMode(state));
-					}
-				}
-				else
-				{
-					m_Elements->removeAll(ite);
-					m_doc->Items->removeAll(ite);
-					m_groupStack.top().Items.removeAll(ite);
-					delete ite;
-				}
-			}
-			if (m_clipStack.count() == 0)
-				break;
-		}
-	}
-}
-/*
-void SlaOutputDev::updateFillColor(GfxState *state)
-{
-	int shade = 100;
-	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
-}
-*/
-void SlaOutputDev::beginTransparencyGroup(GfxState *state, double *bbox, GfxColorSpace * /*blendingColorSpace*/, GBool /*isolated*/, GBool /*knockout*/, GBool forSoftMask)
-{
-//	qDebug() << "Start Group";
-	pushGroup("", forSoftMask);
-}
-
-void SlaOutputDev::endTransparencyGroup(GfxState *state)
-{
-//	qDebug() << "End Group";
-	if (m_groupStack.count() != 0)
-	{
-		groupEntry gElements = m_groupStack.pop();
-		tmpSel->clear();
-		if (gElements.Items.count() > 0)
-		{
-			if (gElements.forSoftMask)
-			{
-				for (int dre = 0; dre < gElements.Items.count(); ++dre)
-				{
-					tmpSel->addItem(gElements.Items.at(dre), true);
-					m_Elements->removeAll(gElements.Items.at(dre));
-				}
-				PageItem *ite = m_doc->groupObjectsSelection(tmpSel);
-				ite->setFillTransparency(1.0 - state->getFillOpacity());
-				ite->setFillBlendmode(getBlendMode(state));
-				ScPattern pat = ScPattern();
-				pat.setDoc(m_doc);
-				m_doc->DoDrawing = true;
-				pat.pattern = ite->DrawObj_toImage(qMin(qMax(ite->width(), ite->height()), 500.0));
-				pat.xoffset = 0;
-				pat.yoffset = 0;
-				m_doc->DoDrawing = false;
-				pat.width = ite->width();
-				pat.height = ite->height();
-				ite->gXpos = 0;
-				ite->gYpos = 0;
-				ite->setXYPos(ite->gXpos, ite->gYpos, true);
-				pat.items.append(ite);
-				m_doc->Items->removeAll(ite);
-				QString id = QString("Pattern_from_PDF_%1S").arg(m_doc->docPatterns.count() + 1);
-				m_doc->addPattern(id, pat);
-				m_currentMask = id;
-				tmpSel->clear();
-				return;
-			}
-			else
-			{
-				PageItem *ite;
-				for (int dre = 0; dre < gElements.Items.count(); ++dre)
-				{
-					tmpSel->addItem(gElements.Items.at(dre), true);
-					m_Elements->removeAll(gElements.Items.at(dre));
-				}
-				if (gElements.Items.count() != 1)
-					ite = m_doc->groupObjectsSelection(tmpSel);
-				else
-					ite = gElements.Items.first();
-				ite->setFillTransparency(1.0 - state->getFillOpacity());
-				ite->setFillBlendmode(getBlendMode(state));
-				for (int as = 0; as < tmpSel->count(); ++as)
-				{
-					m_Elements->append(tmpSel->itemAt(as));
-				}
-				if (m_groupStack.count() != 0)
-					applyMask(ite);
-			}
-		}
-		if (m_groupStack.count() != 0)
-		{
-			for (int as = 0; as < tmpSel->count(); ++as)
-			{
-				m_groupStack.top().Items.append(tmpSel->itemAt(as));
-			}
-		}
-		tmpSel->clear();
-	}
-}
-
-void SlaOutputDev::setSoftMask(GfxState * /*state*/, double * /*bbox*/, GBool alpha, Function *transferFunc, GfxColor * /*backdropColor*/)
-{
-	if (m_groupStack.count() != 0)
-	{
-		double lum = 0;
-		double lum2 = 0;
-		if (transferFunc)
-			transferFunc->transform(&lum, &lum2);
-		else
-			lum2 = lum;
-		if (lum == lum2)
-			m_groupStack.top().inverted = false;
-		else
-			m_groupStack.top().inverted = true;
-//		qDebug() << "Inverted Softmask" << m_groupStack.top().inverted;
-		m_groupStack.top().maskName = m_currentMask;
-		m_groupStack.top().alpha = alpha;
-	}
-}
-
-void SlaOutputDev::clearSoftMask(GfxState * /*state*/)
-{
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().maskName = "";
-	}
-}
-
-void SlaOutputDev::updateFillColor(GfxState *state)
-{
-	CurrFillShade = 100;
-	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &CurrFillShade);
-}
-
-void SlaOutputDev::updateStrokeColor(GfxState *state)
-{
-	CurrStrokeShade = 100;
-	CurrColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &CurrStrokeShade);
-}
-
-void SlaOutputDev::clip(GfxState *state)
-{
-//	qDebug() << "Clip";
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	QString output = convertPath(state->getPath());
-	FPointArray out;
-	if (!output.isEmpty())
-	{
-		out.parseSVG(output);
-		if (!pathIsClosed)
-			out.svgClosePath();
-		out.map(m_ctm);
-	}
-	double xmin, ymin, xmax, ymax;
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	int z = m_doc->itemAdd(PageItem::Group, PageItem::Rectangle, crect.x() + m_doc->currentPage()->xOffset(), crect.y() + m_doc->currentPage()->yOffset(), crect.width(), crect.height(), 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem *ite = m_doc->Items->at(z);
-	if (!output.isEmpty())
-	{
-		FPoint wh(getMinClipF(&out));
-		out.translate(-wh.x(), -wh.y());
-		FPoint dim = out.WidthHeight();
-		if (!((dim.x() == 0.0) || (dim.y() == 0.0)))		// avoid degenerate clipping paths
-			ite->PoLine = out.copy();  //FIXME: try to avoid copy if FPointArray when properly shared
-	}
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillEvenOdd(false);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->ContourLine = ite->PoLine.copy();
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	clipEntry clp;
-	clp.ClipItem = ite;
-	clp.grStackDepth = grStackDepth;
-	m_clipStack.push(clp);
-	m_doc->GroupCounter++;
-	pushGroup();
-}
-
-void SlaOutputDev::eoClip(GfxState *state)
-{
-//	qDebug() << "EoClip";
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	QString output = convertPath(state->getPath());
-	FPointArray out;
-	if (!output.isEmpty())
-	{
-		out.parseSVG(output);
-		if (!pathIsClosed)
-			out.svgClosePath();
-		out.map(m_ctm);
-	}
-	double xmin, ymin, xmax, ymax;
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	int z = m_doc->itemAdd(PageItem::Group, PageItem::Rectangle, crect.x() + m_doc->currentPage()->xOffset(), crect.y() + m_doc->currentPage()->yOffset(), crect.width(), crect.height(), 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem *ite = m_doc->Items->at(z);
-	if (!output.isEmpty())
-	{
-		FPoint wh(getMinClipF(&out));
-		out.translate(-wh.x(), -wh.y());
-		FPoint dim = out.WidthHeight();
-		if (!((dim.x() == 0.0) || (dim.y() == 0.0)))		// avoid degenerate clipping paths
-			ite->PoLine = out.copy();  //FIXME: try to avoid copy if FPointArray when properly shared
-	}
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillEvenOdd(true);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->ContourLine = ite->PoLine.copy();
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	clipEntry clp;
-	clp.ClipItem = ite;
-	clp.grStackDepth = grStackDepth;
-	m_clipStack.push(clp);
-	m_doc->GroupCounter++;
-	pushGroup();
-}
-
-void SlaOutputDev::stroke(GfxState *state)
-{
-//	qDebug() << "Stroke";
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QString output = convertPath(state->getPath());
-	getPenState(state);
-	if ((m_Elements->count() != 0) && (output == Coords))			// Path is the same as in last fill
-	{
-		PageItem* ite = m_Elements->last();
-		ite->setLineColor(CurrColorStroke);
-		ite->setLineShade(CurrStrokeShade);
-		ite->setLineEnd(PLineEnd);
-		ite->setLineJoin(PLineJoin);
-		ite->setLineWidth(state->getTransformedLineWidth());
-		ite->setDashes(DashValues);
-		ite->setDashOffset(DashOffset);
-		ite->setLineTransparency(1.0 - state->getStrokeOpacity());
-	}
-	else
-	{
-		FPointArray out;
-		out.parseSVG(output);
-		m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-		out.map(m_ctm);
-		FPoint wh = out.WidthHeight();
-		if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
-		{
-			int z;
-			if (pathIsClosed)
-				z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, state->getTransformedLineWidth(), CommonStrings::None, CurrColorStroke, true);
-			else
-				z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, state->getTransformedLineWidth(), CommonStrings::None, CurrColorStroke, true);
-			PageItem* ite = m_doc->Items->at(z);
-			ite->PoLine = out.copy();
-			ite->ClipEdited = true;
-			ite->FrameType = 3;
-			ite->setWidthHeight(wh.x(),wh.y());
-			m_doc->AdjustItemSize(ite);
-			if (m_Elements->count() != 0)
-			{
-				PageItem* lItem = m_Elements->last();
-				if ((lItem->lineColor() == CommonStrings::None) && (lItem->PoLine == ite->PoLine))
-				{
-					lItem->setLineColor(CurrColorStroke);
-					lItem->setLineWidth(state->getTransformedLineWidth());
-					lItem->setLineShade(CurrStrokeShade);
-					lItem->setLineTransparency(1.0 - state->getStrokeOpacity());
-					lItem->setLineBlendmode(getBlendMode(state));
-					lItem->setLineEnd(PLineEnd);
-					lItem->setLineJoin(PLineJoin);
-					lItem->setDashes(DashValues);
-					lItem->setDashOffset(DashOffset);
-					lItem->setTextFlowMode(PageItem::TextFlowDisabled);
-					m_doc->Items->removeAll(ite);
-				}
-				else
-				{
-					ite->setLineShade(CurrStrokeShade);
-					ite->setLineTransparency(1.0 - state->getStrokeOpacity());
-					ite->setLineBlendmode(getBlendMode(state));
-					ite->setLineEnd(PLineEnd);
-					ite->setLineJoin(PLineJoin);
-					ite->setDashes(DashValues);
-					ite->setDashOffset(DashOffset);
-					ite->setTextFlowMode(PageItem::TextFlowDisabled);
-					m_Elements->append(ite);
-					if (m_groupStack.count() != 0)
-						m_groupStack.top().Items.append(ite);
-				}
-			}
-			else
-			{
-				ite->setLineShade(CurrStrokeShade);
-				ite->setLineTransparency(1.0 - state->getStrokeOpacity());
-				ite->setLineBlendmode(getBlendMode(state));
-				ite->setLineEnd(PLineEnd);
-				ite->setLineJoin(PLineJoin);
-				ite->setDashes(DashValues);
-				ite->setDashOffset(DashOffset);
-				ite->setTextFlowMode(PageItem::TextFlowDisabled);
-				m_Elements->append(ite);
-				if (m_groupStack.count() != 0)
-					m_groupStack.top().Items.append(ite);
-			}
-		}
-	}
-}
-
-void SlaOutputDev::fill(GfxState *state)
-{
-//	qDebug() << "Fill";
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	FPointArray out;
-	QString output = convertPath(state->getPath());
-	out.parseSVG(output);
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	out.map(m_ctm);
-	Coords = output;
-	FPoint wh = out.WidthHeight();
-	if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
-	{
-		int z;
-		if (pathIsClosed)
-			z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
-		else
-			z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
-		PageItem* ite = m_doc->Items->at(z);
-		ite->PoLine = out.copy();
-		ite->ClipEdited = true;
-		ite->FrameType = 3;
-		ite->setFillShade(CurrFillShade);
-		ite->setLineShade(100);
-		ite->setFillEvenOdd(false);
-		ite->setFillTransparency(1.0 - state->getFillOpacity());
-		ite->setFillBlendmode(getBlendMode(state));
-		ite->setLineEnd(PLineEnd);
-		ite->setLineJoin(PLineJoin);
-		ite->setWidthHeight(wh.x(),wh.y());
-		ite->setTextFlowMode(PageItem::TextFlowDisabled);
-		m_doc->AdjustItemSize(ite);
-		m_Elements->append(ite);
-		if (m_groupStack.count() != 0)
-		{
-			m_groupStack.top().Items.append(ite);
-			applyMask(ite);
-		}
-	}
-}
-
-void SlaOutputDev::eoFill(GfxState *state)
-{
-//	qDebug() << "EoFill";
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	FPointArray out;
-	QString output = convertPath(state->getPath());
-	out.parseSVG(output);
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	out.map(m_ctm);
-	Coords = output;
-	FPoint wh = out.WidthHeight();
-	if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
-	{
-		int z;
-		if (pathIsClosed)
-			z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
-		else
-			z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
-		PageItem* ite = m_doc->Items->at(z);
-		ite->PoLine = out.copy();
-		ite->ClipEdited = true;
-		ite->FrameType = 3;
-		ite->setFillShade(CurrFillShade);
-		ite->setLineShade(100);
-		ite->setFillEvenOdd(true);
-		ite->setFillTransparency(1.0 - state->getFillOpacity());
-		ite->setFillBlendmode(getBlendMode(state));
-		ite->setLineEnd(PLineEnd);
-		ite->setLineJoin(PLineJoin);
-		ite->setWidthHeight(wh.x(),wh.y());
-		ite->setTextFlowMode(PageItem::TextFlowDisabled);
-		m_doc->AdjustItemSize(ite);
-		m_Elements->append(ite);
-		if (m_groupStack.count() != 0)
-		{
-			m_groupStack.top().Items.append(ite);
-			applyMask(ite);
-		}
-	}
-}
-
-GBool SlaOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax)
-{
-	double GrStartX;
-	double GrStartY;
-	double GrEndX;
-	double GrEndY;
-	int shade = 100;
-	Function *func = shading->getFunc(0);
-	VGradient FillGradient = VGradient(VGradient::linear);
-	FillGradient.clearStops();
-	GfxColorSpace *color_space = shading->getColorSpace();
-	if (func->getType() == 3)
-	{
-		StitchingFunction *stitchingFunc = (StitchingFunction*)func;
-		double *bounds = stitchingFunc->getBounds();
-		int num_funcs = stitchingFunc->getNumFuncs();
-		// Add stops from all the stitched functions
-		for ( int i = 0 ; i < num_funcs ; i++ )
-		{
-			GfxColor temp;
-			((GfxAxialShading*)shading)->getColor(bounds[i], &temp);
-			QString stopColor = getColor(color_space, &temp, &shade);
-			FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i], 0.5, 1.0, stopColor, shade );
-			if (i == num_funcs - 1)
-			{
-				((GfxAxialShading*)shading)->getColor(bounds[i+1], &temp);
-				QString stopColor = getColor(color_space, &temp, &shade);
-				FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i+1], 0.5, 1.0, stopColor, shade );
-			}
-		}
-	}
-	else if ((func->getType() == 2) || (func->getType() == 0))
-	{
-		GfxColor stop1;
-		((GfxAxialShading*)shading)->getColor(0.0, &stop1);
-		QString stopColor1 = getColor(color_space, &stop1, &shade);
-		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 0.5, 1.0, stopColor1, shade );
-		GfxColor stop2;
-		((GfxAxialShading*)shading)->getColor(1.0, &stop2);
-		QString stopColor2 = getColor(color_space, &stop2, &shade);
-		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 0.5, 1.0, stopColor2, shade );
-	}
-	((GfxAxialShading*)shading)->getCoords(&GrStartX, &GrStartY, &GrEndX, &GrEndY);
-	double xmin, ymin, xmax, ymax;
-	// get the clip region bbox
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	FPointArray gr;
-	gr.addPoint(GrStartX, GrStartY);
-	gr.addPoint(GrEndX, GrEndY);
-	gr.map(m_ctm);
-	GrStartX = gr.point(0).x() - crect.x();
-	GrStartY = gr.point(0).y() - crect.y();
-	GrEndX = gr.point(1).x() - crect.x();
-	GrEndY = gr.point(1).y() - crect.y();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(0.0);
-	output += QString("Z");
-	pathIsClosed = true;
-	Coords = output;
-	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillShade(CurrFillShade);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	ite->setLineEnd(PLineEnd);
-	ite->setLineJoin(PLineJoin);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->GrType = 6;
-	if (!shading->getExtend0() || !shading->getExtend1())
-	{
-		FillGradient.setRepeatMethod(VGradient::none);
-		ite->setGradientExtend(VGradient::none);
-	}
-	else
-	{
-		FillGradient.setRepeatMethod(VGradient::pad);
-		ite->setGradientExtend(VGradient::pad);
-	}
-	ite->fill_gradient = FillGradient;
-	ite->setGradientVector(GrStartX, GrStartY, GrEndX, GrEndY, 0, 0, 1, 0);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	return gTrue;
-}
-
-GBool SlaOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading, double sMin, double sMax)
-{
-	double GrStartX;
-	double GrStartY;
-	double GrEndX;
-	double GrEndY;
-	int shade = 100;
-	Function *func = shading->getFunc(0);
-	VGradient FillGradient = VGradient(VGradient::linear);
-	FillGradient.clearStops();
-	GfxColorSpace *color_space = shading->getColorSpace();
-	if (func->getType() == 3)
-	{
-		StitchingFunction *stitchingFunc = (StitchingFunction*)func;
-		double *bounds = stitchingFunc->getBounds();
-		int num_funcs = stitchingFunc->getNumFuncs();
-		// Add stops from all the stitched functions
-		for ( int i = 0 ; i < num_funcs ; i++ )
-		{
-			GfxColor temp;
-			((GfxRadialShading*)shading)->getColor(bounds[i], &temp);
-			QString stopColor = getColor(color_space, &temp, &shade);
-			FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i], 0.5, 1.0, stopColor, shade );
-			if (i == num_funcs - 1)
-			{
-				((GfxRadialShading*)shading)->getColor(bounds[i+1], &temp);
-				QString stopColor = getColor(color_space, &temp, &shade);
-				FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i+1], 0.5, 1.0, stopColor, shade );
-			}
-		}
-	}
-	else if ((func->getType() == 2) || (func->getType() == 0))
-	{
-		GfxColor stop1;
-		((GfxRadialShading*)shading)->getColor(0.0, &stop1);
-		QString stopColor1 = getColor(color_space, &stop1, &shade);
-		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 0.5, 1.0, stopColor1, shade );
-		GfxColor stop2;
-		((GfxRadialShading*)shading)->getColor(1.0, &stop2);
-		QString stopColor2 = getColor(color_space, &stop2, &shade);
-		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 0.5, 1.0, stopColor2, shade );
-	}
-	double r0, x1, y1, r1;
-	((GfxRadialShading*)shading)->getCoords(&GrStartX, &GrStartY, &r0, &x1, &y1, &r1);
-	double xmin, ymin, xmax, ymax;
-	// get the clip region bbox
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	double GrFocalX = x1;
-	double GrFocalY = y1;
-	GrEndX = GrFocalX + r1;
-	GrEndY = GrFocalY;
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	FPointArray gr;
-	gr.addPoint(GrStartX, GrStartY);
-	gr.addPoint(GrEndX, GrEndY);
-	gr.addPoint(GrFocalX, GrFocalY);
-	gr.map(m_ctm);
-	GrStartX = gr.point(0).x() - crect.x();
-	GrStartY = gr.point(0).y() - crect.y();
-	GrEndX = gr.point(1).x() - crect.x();
-	GrEndY = gr.point(1).y() - crect.y();
-	GrFocalX = gr.point(2).x() - crect.x();
-	GrFocalY = gr.point(2).y() - crect.y();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(0.0);
-	output += QString("Z");
-	pathIsClosed = true;
-	Coords = output;
-	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillShade(CurrFillShade);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	ite->setLineEnd(PLineEnd);
-	ite->setLineJoin(PLineJoin);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->GrType = 7;
-	if (!shading->getExtend0() || !shading->getExtend1())
-	{
-		FillGradient.setRepeatMethod(VGradient::none);
-		ite->setGradientExtend(VGradient::none);
-	}
-	else
-	{
-		FillGradient.setRepeatMethod(VGradient::pad);
-		ite->setGradientExtend(VGradient::pad);
-	}
-	ite->fill_gradient = FillGradient;
-	ite->setGradientVector(GrStartX, GrStartY, GrEndX, GrEndY, GrFocalX, GrFocalY, 1, 0);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	return gTrue;
-}
-
-GBool SlaOutputDev::gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading)
-{
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	double xmin, ymin, xmax, ymax;
-	// get the clip region bbox
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(0.0);
-	output += QString("Z");
-	pathIsClosed = true;
-	Coords = output;
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillShade(CurrFillShade);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	ite->setLineEnd(PLineEnd);
-	ite->setLineJoin(PLineJoin);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	GfxColor color[3];
-	double x0, y0, x1, y1, x2, y2;
-	for (int i = 0; i < shading->getNTriangles(); i++)
-	{
-		int shade = 100;
-		meshGradientPatch patchM;
-		shading->getTriangle(i, &x0, &y0, &color[0],  &x1, &y1, &color[1],  &x2, &y2, &color[2]);
-		patchM.BL.resetTo(FPoint(x0, y0));
-		patchM.BL.shade = 100;
-		patchM.BL.transparency = 1.0;
-		patchM.BL.colorName = getColor(shading->getColorSpace(), &color[0], &shade);
-		patchM.BL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BL.colorName], m_doc, shade);
-		patchM.TL.resetTo(FPoint(x1, y1));
-		patchM.TL.shade = 100;
-		patchM.TL.transparency = 1.0;
-		patchM.TL.colorName = getColor(shading->getColorSpace(), &color[1], &shade);
-		patchM.TL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TL.colorName], m_doc, shade);
-		patchM.TR.resetTo(FPoint(x2, y2));
-		patchM.TR.shade = 100;
-		patchM.TR.transparency = 1.0;
-		patchM.TR.colorName = getColor(shading->getColorSpace(), &color[2], &shade);
-		patchM.TR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TR.colorName], m_doc, shade);
-		patchM.BR.resetTo(FPoint(x0, y0));
-		patchM.BR.shade = 100;
-		patchM.BR.transparency = 1.0;
-		patchM.BR.colorName = getColor(shading->getColorSpace(), &color[0], &shade);
-		patchM.BR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BR.colorName], m_doc, shade);
-		patchM.TL.transform(m_ctm);
-		patchM.TL.moveRel(-crect.x(), -crect.y());
-		patchM.TR.transform(m_ctm);
-		patchM.TR.moveRel(-crect.x(), -crect.y());
-		patchM.BR.transform(m_ctm);
-		patchM.BR.moveRel(-crect.x(), -crect.y());
-		patchM.BL.transform(m_ctm);
-		patchM.BL.moveRel(-crect.x(), -crect.y());
-		ite->meshGradientPatches.append(patchM);
-	}
-	ite->GrType = 12;
-	return gTrue;
-}
-
-GBool SlaOutputDev::patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading)
-{
-//	qDebug() << "mesh shaded fill";
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	double xmin, ymin, xmax, ymax;
-	// get the clip region bbox
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(0.0);
-	output += QString("Z");
-	pathIsClosed = true;
-	Coords = output;
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillShade(CurrFillShade);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	ite->setLineEnd(PLineEnd);
-	ite->setLineJoin(PLineJoin);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-//	qDebug() << "Mesh of" << shading->getNPatches() << "Patches";
-	ite->meshGradientPatches.clear();
-	for (int i = 0; i < shading->getNPatches(); i++)
-	{
-		int shade = 100;
-		GfxPatch *patch = shading->getPatch(i);
-		GfxColor color;
-		meshGradientPatch patchM;
-		int u, v;
-		patchM.BL.resetTo(FPoint(patch->x[0][0], patch->y[0][0]));
-		patchM.BL.controlTop = FPoint(patch->x[0][1], patch->y[0][1]);
-		patchM.BL.controlRight = FPoint(patch->x[1][0], patch->y[1][0]);
-		patchM.BL.controlColor = FPoint(patch->x[1][1], patch->y[1][1]);
-		u = 0;
-		v = 0;
-		if (shading->isParameterized())
-		{
-			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
-		}
-		else
-		{
-			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
-			{
-				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
-			}
-		}
-		patchM.BL.colorName = getColor(shading->getColorSpace(), &color, &shade);
-		patchM.BL.shade = 100;
-		patchM.BL.transparency = 1.0;
-		patchM.BL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BL.colorName], m_doc, shade);
-
-		u = 0;
-		v = 1;
-		patchM.TL.resetTo(FPoint(patch->x[0][3], patch->y[0][3]));
-		patchM.TL.controlRight = FPoint(patch->x[1][3], patch->y[1][3]);
-		patchM.TL.controlBottom = FPoint(patch->x[0][2], patch->y[0][2]);
-		patchM.TL.controlColor = FPoint(patch->x[1][2], patch->y[1][2]);
-		if (shading->isParameterized())
-		{
-			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
-		}
-		else
-		{
-			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
-			{
-				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
-			}
-		}
-		patchM.TL.colorName = getColor(shading->getColorSpace(), &color, &shade);
-		patchM.TL.shade = 100;
-		patchM.TL.transparency = 1.0;
-		patchM.TL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TL.colorName], m_doc, shade);
-
-		u = 1;
-		v = 1;
-		patchM.TR.resetTo(FPoint(patch->x[3][3], patch->y[3][3]));
-		patchM.TR.controlBottom = FPoint(patch->x[3][2], patch->y[3][2]);
-		patchM.TR.controlLeft = FPoint(patch->x[2][3], patch->y[2][3]);
-		patchM.TR.controlColor = FPoint(patch->x[2][2], patch->y[2][2]);
-		if (shading->isParameterized())
-		{
-			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
-		}
-		else
-		{
-			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
-			{
-				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
-			}
-		}
-		patchM.TR.colorName = getColor(shading->getColorSpace(), &color, &shade);
-		patchM.TR.shade = 100;
-		patchM.TR.transparency = 1.0;
-		patchM.TR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TR.colorName], m_doc, shade);
-
-		u = 1;
-		v = 0;
-		patchM.BR.resetTo(FPoint(patch->x[3][0], patch->y[3][0]));
-		patchM.BR.controlLeft = FPoint(patch->x[2][0], patch->y[2][0]);
-		patchM.BR.controlTop = FPoint(patch->x[3][1], patch->y[3][1]);
-		patchM.BR.controlColor = FPoint(patch->x[2][1], patch->y[2][1]);
-		if (shading->isParameterized())
-		{
-			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
-		}
-		else
-		{
-			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
-			{
-				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
-			}
-		}
-		patchM.BR.colorName = getColor(shading->getColorSpace(), &color, &shade);
-		patchM.BR.shade = 100;
-		patchM.BR.transparency = 1.0;
-		patchM.BR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BR.colorName], m_doc, shade);
-
-		patchM.TL.transform(m_ctm);
-		patchM.TL.moveRel(-crect.x(), -crect.y());
-		patchM.TR.transform(m_ctm);
-		patchM.TR.moveRel(-crect.x(), -crect.y());
-		patchM.BR.transform(m_ctm);
-		patchM.BR.moveRel(-crect.x(), -crect.y());
-		patchM.BL.transform(m_ctm);
-		patchM.BL.moveRel(-crect.x(), -crect.y());
-		ite->meshGradientPatches.append(patchM);
-	}
-	ite->GrType = 12;
-	return gTrue;
-}
-
-GBool SlaOutputDev::tilingPatternFill(GfxState *state, Gfx * /*gfx*/, Catalog *cat, Object *str, double *pmat, int paintType, int tilingType, Dict *resDict, double *mat, double *bbox, int x0, int y0, int x1, int y1, double xStep, double yStep)
-{
-	PDFRectangle box;
-	Gfx *gfx;
-	QString id;
-	PageItem *ite;
-	groupEntry gElements;
-	gElements.forSoftMask = gFalse;
-	gElements.alpha = gFalse;
-	gElements.inverted = false;
-	gElements.maskName = "";
-	gElements.Items.clear();
-	m_groupStack.push(gElements);
-	double width, height;
-	width = bbox[2] - bbox[0];
-	height = bbox[3] - bbox[1];
-	if (xStep != width || yStep != height)
-		return gFalse;
-	box.x1 = bbox[0];
-	box.y1 = bbox[1];
-	box.x2 = bbox[2];
-	box.y2 = bbox[3];
-	double *ctm;
-	ctm = state->getCTM();
-	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-	QTransform mm = QTransform(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
-	QTransform mmx = mm * m_ctm;
-
-#ifdef POPPLER_VERSION
-	gfx = new Gfx(pdfDoc, this, resDict, &box, NULL);
-#else
-	gfx = new Gfx(xref, this, resDict, catalog, &box, NULL);
-#endif
-
-	gfx->display(str);
-	gElements = m_groupStack.pop();
-	m_doc->m_Selection->clear();
-	double pwidth = 0;
-	double pheight = 0;
-	if (gElements.Items.count() > 0)
-	{
-		for (int dre = 0; dre < gElements.Items.count(); ++dre)
-		{
-			m_doc->m_Selection->addItem(gElements.Items.at(dre), true);
-			m_Elements->removeAll(gElements.Items.at(dre));
-		}
-		m_doc->itemSelection_FlipV();
-		PageItem *ite;
-		if (m_doc->m_Selection->count() > 1)
-			ite = m_doc->groupObjectsSelection();
-		else
-			ite = m_doc->m_Selection->itemAt(0);
-		ite->setFillTransparency(1.0 - state->getFillOpacity());
-		ite->setFillBlendmode(getBlendMode(state));
-		m_doc->m_Selection->clear();
-		ScPattern pat = ScPattern();
-		pat.setDoc(m_doc);
-		m_doc->DoDrawing = true;
-		pat.pattern = ite->DrawObj_toImage(qMin(qMax(ite->width(), ite->height()), 500.0));
-		pat.xoffset = 0;
-		pat.yoffset = 0;
-		m_doc->DoDrawing = false;
-		pat.width = ite->width();
-		pat.height = ite->height();
-		pwidth = ite->width();
-		pheight = ite->height();
-		ite->gXpos = 0;
-		ite->gYpos = 0;
-		ite->setXYPos(ite->gXpos, ite->gYpos, true);
-		pat.items.append(ite);
-		m_doc->Items->removeAll(ite);
-		id = QString("Pattern_from_PDF_%1").arg(m_doc->docPatterns.count() + 1);
-		m_doc->addPattern(id, pat);
-	}
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	double xmin, ymin, xmax, ymax;
-	// get the clip region bbox
-	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
-	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-	crect = crect.normalized();
-	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
-	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(crect.height());
-	output += QString("L %1 %2").arg(0.0).arg(0.0);
-	output += QString("Z");
-	pathIsClosed = true;
-	Coords = output;
-	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
-	ite = m_doc->Items->at(z);
-	ite->ClipEdited = true;
-	ite->FrameType = 3;
-	ite->setFillShade(CurrFillShade);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	ite->setLineEnd(PLineEnd);
-	ite->setLineJoin(PLineJoin);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->GrType = 8;
-	ite->setPattern(id);
-	ite->setPatternTransform(fabs(pmat[0]) * 100, fabs(pmat[3]) * 100, mmx.dx() - ctm[4], mmx.dy() - ctm[5], 0, -1 * pmat[1], pmat[2]);
-	m_doc->AdjustItemSize(ite);
-	m_Elements->append(ite);
-	if (m_groupStack.count() != 0)
-	{
-		m_groupStack.top().Items.append(ite);
-		applyMask(ite);
-	}
-	delete gfx;
-	return gTrue;
-}
-
-void SlaOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool interpolate, GBool inlineImg)
-{
-//	qDebug() << "Draw Image Mask";
-	QImage * image = 0;
-	int invert_bit;
-	int row_stride;
-	int x, y, i, bit;
-	unsigned char *dest = 0;
-	unsigned char *buffer;
-	Guchar *pix;
-	ImageStream * imgStr = new ImageStream(str, width, 1, 1);
-	imgStr->reset();
-#ifdef WORDS_BIGENDIAN
-	image = new QImage(width, height, QImage::Format_Mono);
-#else
-	image = new QImage(width, height, QImage::Format_MonoLSB);
-#endif
-	if (image == NULL || image->isNull())
-	{
-		delete imgStr;
-		delete image;
-		return;
-	}
-	invert_bit = invert ? 1 : 0;
-	buffer = image->bits();
-	row_stride = image->bytesPerLine();
-	for (y = 0; y < height; y++)
-	{
-		pix = imgStr->getLine();
-		dest = buffer + y * row_stride;
-		i = 0;
-		bit = 0;
-		for (x = 0; x < width; x++)
-		{
-			if (bit == 0)
-				dest[i] = 0;
-			if (!(pix[x] ^ invert_bit))
-			{
-#ifdef WORDS_BIGENDIAN
-				dest[i] |= (1 << (7 - bit));
-#else
-				dest[i] |= (1 << bit);
-#endif
-			}
-			bit++;
-			if (bit > 7)
-			{
-				bit = 0;
-				i++;
-			}
-		}
-	}
-	QColor backColor = ScColorEngine::getShadeColorProof(m_doc->PageColors[CurrColorFill], m_doc, CurrFillShade);
-	QImage res = QImage(width, height, QImage::Format_ARGB32);
-	res.fill(backColor.rgb());
-	unsigned char cc, cm, cy, ck;
-	for( int yi = 0; yi < res.height(); ++yi )
-	{
-		QRgb *t = (QRgb*)(res.scanLine( yi ));
-		for(int xi = 0; xi < res.width(); ++xi )
-		{
-			cc = qRed(*t);
-			cm = qGreen(*t);
-			cy = qBlue(*t);
-			ck = image->pixel(xi, yi);
-			if (ck == 0)
-				(*t) = qRgba(cc, cm, cy, 0);
-			else
-				(*t) = qRgba(cc, cm, cy, 255);
-			t++;
-		}
-	}
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QRectF crect = QRectF(0, 0, width, height);
-	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
-	QLineF cline = QLineF(0, 0, width, 0);
-	QLineF tline = m_ctm.map(cline);
-	QRectF trect = m_ctm.mapRect(crect);
-	double sx = m_ctm.m11();
-	double sy = m_ctm.m22();
-	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
-	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
-	{
-		mm.reset();
-		mm.rotate(-tline.angle());
-		res = res.transformed(mm);
-	}
-	else
-	{
-		if ((sx < 0) || (sy < 0))
-		{
-			mm.reset();
-			if (sx < 0)
-				mm.scale(-1, 1);
-			if (sy < 0)
-				mm.scale(1, -1);
-			res = res.transformed(mm);
-		}
-	}
-	if (res.isNull())
-	{
-		delete imgStr;
-		delete image;
-		return;
-	}
-	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->SetRectFrame();
-	m_doc->setRedrawBounding(ite);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->setFillShade(100);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	m_doc->AdjustItemSize(ite);
-	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
-	tempFile->setAutoRemove(false);
-	if (tempFile->open())
-	{
-		QString fileName = getLongPathName(tempFile->fileName());
-		if (!fileName.isEmpty())
-		{
-			tempFile->close();
-			ite->isInlineImage = true;
-			ite->isTempFile = true;
-			res.save(fileName, "PNG");
-			m_doc->loadPict(fileName, ite);
-			ite->setImageScalingMode(false, false);
-			m_Elements->append(ite);
-			if (m_groupStack.count() != 0)
-			{
-				m_groupStack.top().Items.append(ite);
-				applyMask(ite);
-			}
-		}
-		else
-			m_doc->Items->removeAll(ite);
-	}
-	else
-		m_doc->Items->removeAll(ite);
-	imgStr->close();
-	delete tempFile;
-	delete imgStr;
-	delete image;
-}
-
-void SlaOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, Stream *maskStr, int maskWidth, int maskHeight,
-				   GfxImageColorMap *maskColorMap, GBool maskInterpolate)
-{
-//	qDebug() << "Masked Image Components" << colorMap->getNumPixelComps();
-	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
-	imgStr->reset();
-	unsigned int *dest = 0;
-	unsigned char * buffer = new unsigned char[width * height * 4];
-	QImage * image = 0;
-	for (int y = 0; y < height; y++)
-	{
-		dest = (unsigned int *)(buffer + y * 4 * width);
-		Guchar * pix = imgStr->getLine();
-		colorMap->getRGBLine(pix, dest, width);
-	}
-	image = new QImage(buffer, width, height, QImage::Format_RGB32);
-	if (image == NULL || image->isNull())
-	{
-		delete imgStr;
-		delete[] buffer;
-		delete image;
-		return;
-	}
-	ImageStream *mskStr = new ImageStream(maskStr, maskWidth, maskColorMap->getNumPixelComps(), maskColorMap->getBits());
-	mskStr->reset();
-	Guchar *mdest = 0;
-	unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight];
-	for (int y = 0; y < maskHeight; y++)
-	{
-		mdest = (Guchar *)(mbuffer + y * maskWidth);
-		Guchar * pix = mskStr->getLine();
-		maskColorMap->getGrayLine(pix, mdest, maskWidth);
-	}
-	if ((maskWidth != width) || (maskHeight != height))
-	{
-		delete imgStr;
-		delete[] buffer;
-		delete image;
-		delete mskStr;
-		delete[] mbuffer;
-		return;
-	}
-	QImage res = image->convertToFormat(QImage::Format_ARGB32);
-	unsigned char cc, cm, cy, ck;
-	int s = 0;
-	for( int yi=0; yi < res.height(); ++yi )
-	{
-		QRgb *t = (QRgb*)(res.scanLine( yi ));
-		for(int xi=0; xi < res.width(); ++xi )
-		{
-			cc = qRed(*t);
-			cm = qGreen(*t);
-			cy = qBlue(*t);
-			ck = mbuffer[s];
-			(*t) = qRgba(cc, cm, cy, ck);
-			s++;
-			t++;
-		}
-	}
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QRectF crect = QRectF(0, 0, width, height);
-	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
-	QLineF cline = QLineF(0, 0, width, 0);
-	QLineF tline = m_ctm.map(cline);
-	QRectF trect = m_ctm.mapRect(crect);
-	double sx = m_ctm.m11();
-	double sy = m_ctm.m22();
-	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
-	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
-	{
-		mm.reset();
-		mm.rotate(-tline.angle());
-		res = res.transformed(mm);
-	}
-	else
-	{
-		if ((sx < 0) || (sy < 0))
-		{
-			if (sx < 0)
-				mm.scale(-1, 1);
-			if (sy < 0)
-				mm.scale(1, -1);
-			res = res.transformed(mm);
-		}
-	}
-	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->SetRectFrame();
-	m_doc->setRedrawBounding(ite);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->setFillShade(100);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	m_doc->AdjustItemSize(ite);
-	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
-	tempFile->setAutoRemove(false);
-	if (tempFile->open())
-	{
-		QString fileName = getLongPathName(tempFile->fileName());
-		if (!fileName.isEmpty())
-		{
-			tempFile->close();
-			ite->isInlineImage = true;
-			ite->isTempFile = true;
-			res.save(fileName, "PNG");
-			m_doc->loadPict(fileName, ite);
-		//	ite->setImageScalingMode(false, false);
-			m_Elements->append(ite);
-			if (m_groupStack.count() != 0)
-			{
-				m_groupStack.top().Items.append(ite);
-				applyMask(ite);
-			}
-		}
-		else
-			m_doc->Items->removeAll(ite);
-	}
-	else
-		m_doc->Items->removeAll(ite);
-	delete tempFile;
-	delete imgStr;
-	delete[] buffer;
-	delete image;
-	delete mskStr;
-	delete[] mbuffer;
-}
-
-void SlaOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,  int width, int height, GfxImageColorMap *colorMap, GBool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GBool maskInterpolate)
-{
-	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
-	imgStr->reset();
-	unsigned int *dest = 0;
-	unsigned char * buffer = new unsigned char[width * height * 4];
-	QImage * image = 0;
-	for (int y = 0; y < height; y++)
-	{
-		dest = (unsigned int *)(buffer + y * 4 * width);
-		Guchar * pix = imgStr->getLine();
-		colorMap->getRGBLine(pix, dest, width);
-	}
-	image = new QImage(buffer, width, height, QImage::Format_RGB32);
-	if (image == NULL || image->isNull())
-	{
-		delete imgStr;
-		delete[] buffer;
-		delete image;
-		return;
-	}
-	ImageStream *mskStr = new ImageStream(maskStr, maskWidth, 1, 1);
-	mskStr->reset();
-	Guchar *mdest = 0;
-	int invert_bit = maskInvert ? 1 : 0;
-	unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight];
-	for (int y = 0; y < maskHeight; y++)
-	{
-		mdest = (Guchar *)(mbuffer + y * maskWidth);
-		Guchar * pix = mskStr->getLine();
-		for (int x = 0; x < maskWidth; x++)
-		{
-			if (pix[x] ^ invert_bit)
-				*mdest++ = 0;
-			else
-				*mdest++ = 255;
-		}
-	}
-	if ((maskWidth != width) || (maskHeight != height))
-	{
-		delete imgStr;
-		delete[] buffer;
-		delete image;
-		delete mskStr;
-		delete[] mbuffer;
-		return;
-	}
-	QImage res = image->convertToFormat(QImage::Format_ARGB32);
-	unsigned char cc, cm, cy, ck;
-	int s = 0;
-	for( int yi=0; yi < res.height(); ++yi )
-	{
-		QRgb *t = (QRgb*)(res.scanLine( yi ));
-		for(int xi=0; xi < res.width(); ++xi )
-		{
-			cc = qRed(*t);
-			cm = qGreen(*t);
-			cy = qBlue(*t);
-			ck = mbuffer[s];
-			(*t) = qRgba(cc, cm, cy, ck);
-			s++;
-			t++;
-		}
-	}
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QRectF crect = QRectF(0, 0, width, height);
-	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
-	QLineF cline = QLineF(0, 0, width, 0);
-	QLineF tline = m_ctm.map(cline);
-	QRectF trect = m_ctm.mapRect(crect);
-	double sx = m_ctm.m11();
-	double sy = m_ctm.m22();
-	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
-	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
-	{
-		mm.reset();
-		mm.rotate(-tline.angle());
-		res = res.transformed(mm);
-	}
-	else
-	{
-		if ((sx < 0) || (sy < 0))
-		{
-			if (sx < 0)
-				mm.scale(-1, 1);
-			if (sy < 0)
-				mm.scale(1, -1);
-			res = res.transformed(mm);
-		}
-	}
-	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->SetRectFrame();
-	m_doc->setRedrawBounding(ite);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->setFillShade(100);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	m_doc->AdjustItemSize(ite);
-	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
-	tempFile->setAutoRemove(false);
-	if (tempFile->open())
-	{
-		QString fileName = getLongPathName(tempFile->fileName());
-		if (!fileName.isEmpty())
-		{
-			tempFile->close();
-			ite->isInlineImage = true;
-			ite->isTempFile = true;
-			res.save(fileName, "PNG");
-			m_doc->loadPict(fileName, ite);
-		//	ite->setImageScalingMode(false, false);
-			m_Elements->append(ite);
-			if (m_groupStack.count() != 0)
-			{
-				m_groupStack.top().Items.append(ite);
-				applyMask(ite);
-			}
-		}
-		else
-			m_doc->Items->removeAll(ite);
-	}
-	else
-		m_doc->Items->removeAll(ite);
-	delete tempFile;
-	delete imgStr;
-	delete[] buffer;
-	delete image;
-	delete mskStr;
-	delete[] mbuffer;
-}
-
-void SlaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg)
-{
-	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
-//	qDebug() << "Image Components" << colorMap->getNumPixelComps() << "Mask" << maskColors;
-	imgStr->reset();
-	QImage * image = 0;
-	if (maskColors)
-	{
-		image = new QImage(width, height, QImage::Format_ARGB32);
-		for (int y = 0; y < height; y++)
-		{
-			QRgb *s = (QRgb*)(image->scanLine(y));
-			Guchar *pix = imgStr->getLine();
-			for (int x = 0; x < width; x++)
-			{
-				GfxRGB rgb;
-				colorMap->getRGB(pix, &rgb);
-				int Rc = qRound(colToDbl(rgb.r) * 255);
-				int Gc = qRound(colToDbl(rgb.g) * 255);
-				int Bc = qRound(colToDbl(rgb.b) * 255);
-				*s = qRgba(Rc, Gc, Bc, 255);
-				for (int i = 0; i < colorMap->getNumPixelComps(); ++i)
-				{
-					if (pix[i] < maskColors[2*i] * 255 || pix[i] > maskColors[2*i+1] * 255)
-					{
-						*s = *s | 0xff000000;
-						break;
-					}
-				}
-				s++;
-				pix += colorMap->getNumPixelComps();
-			}
-		}
-	}
-	else
-	{
-		image = new QImage(width, height, QImage::Format_ARGB32);
-		for (int y = 0; y < height; y++)
-		{
-			QRgb *s = (QRgb*)(image->scanLine(y));
-			Guchar *pix = imgStr->getLine();
-			for (int x = 0; x < width; x++)
-			{
-				if (colorMap->getNumPixelComps() == 4)
-				{
-					GfxCMYK cmyk;
-					colorMap->getCMYK(pix, &cmyk);
-					int Cc = qRound(colToDbl(cmyk.c) * 255);
-					int Mc = qRound(colToDbl(cmyk.m) * 255);
-					int Yc = qRound(colToDbl(cmyk.y) * 255);
-					int Kc = qRound(colToDbl(cmyk.k) * 255);
-					*s = qRgba(Yc, Mc, Cc, Kc);
-				}
-				else
-				{
-					GfxRGB rgb;
-					colorMap->getRGB(pix, &rgb);
-					int Rc = qRound(colToDbl(rgb.r) * 255);
-					int Gc = qRound(colToDbl(rgb.g) * 255);
-					int Bc = qRound(colToDbl(rgb.b) * 255);
-					*s = qRgba(Rc, Gc, Bc, 255);
-				}
-				s++;
-				pix += colorMap->getNumPixelComps();
-			}
-		}
-	}
-	if (image == NULL || image->isNull())
-	{
-		delete imgStr;
-		delete image;
-		return;
-	}
-	double *ctm;
-	ctm = state->getCTM();
-	double xCoor = m_doc->currentPage()->xOffset();
-	double yCoor = m_doc->currentPage()->yOffset();
-	QRectF crect = QRectF(0, 0, width, height);
-	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
-	QLineF cline = QLineF(0, 0, width, 0);
-	QLineF tline = m_ctm.map(cline);
-	QRectF trect = m_ctm.mapRect(crect);
-	double sx = m_ctm.m11();
-	double sy = m_ctm.m22();
-	QImage img = image->copy();
-	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
-	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
-	{
-		mm.reset();
-		mm.rotate(-tline.angle());
-		img = image->transformed(mm);
-	}
-	else
-	{
-		if ((sx < 0) || (sy < 0))
-		{
-			if (sx < 0)
-				mm.scale(-1, 1);
-			if (sy < 0)
-				mm.scale(1, -1);
-			img = image->transformed(mm);
-		}
-	}
-	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem* ite = m_doc->Items->at(z);
-	ite->SetRectFrame();
-	m_doc->setRedrawBounding(ite);
-	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
-	ite->setTextFlowMode(PageItem::TextFlowDisabled);
-	ite->setFillShade(100);
-	ite->setLineShade(100);
-	ite->setFillEvenOdd(false);
-	ite->setFillTransparency(1.0 - state->getFillOpacity());
-	ite->setFillBlendmode(getBlendMode(state));
-	m_doc->AdjustItemSize(ite);
-	if (colorMap->getNumPixelComps() == 4)
-	{
-		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.tif");
-		tempFile->setAutoRemove(false);
-		if (tempFile->open())
-		{
-			QString fileName = getLongPathName(tempFile->fileName());
-			if (!fileName.isEmpty())
-			{
-				tempFile->close();
-				ite->isInlineImage = true;
-				ite->isTempFile = true;
-				TIFF* tif = TIFFOpen(fileName.toLocal8Bit().data(), "w");
-				if (tif)
-				{
-					TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, img.width());
-					TIFFSetField(tif, TIFFTAG_IMAGELENGTH, img.height());
-					TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
-					TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
-					TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
-					TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED);
-					TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
-					for (int y = 0; y < img.height(); ++y)
-					{
-						TIFFWriteScanline(tif, img.scanLine(y), y);
-					}
-					TIFFClose(tif);
-					m_doc->loadPict(fileName, ite);
-				}
-				ite->setImageScalingMode(false, false);
-				m_Elements->append(ite);
-				if (m_groupStack.count() != 0)
-				{
-					m_groupStack.top().Items.append(ite);
-					applyMask(ite);
-				}
-			}
-			else
-				m_doc->Items->removeAll(ite);
-		}
-		delete tempFile;
-	}
-	else
-	{
-		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
-		tempFile->setAutoRemove(false);
-		if (tempFile->open())
-		{
-			QString fileName = getLongPathName(tempFile->fileName());
-			if (!fileName.isEmpty())
-			{
-				tempFile->close();
-				ite->isInlineImage = true;
-				ite->isTempFile = true;
-				img.save(fileName, "PNG");
-				m_doc->loadPict(fileName, ite);
-				ite->setImageScalingMode(false, false);
-				m_Elements->append(ite);
-				if (m_groupStack.count() != 0)
-				{
-					m_groupStack.top().Items.append(ite);
-					applyMask(ite);
-				}
-			}
-			else
-				m_doc->Items->removeAll(ite);
-		}
-		delete tempFile;
-	}
-	delete imgStr;
-	delete image;
-}
-
-void SlaOutputDev::beginMarkedContent(char *name, Object *dictRef)
-{
-	mContent mSte;
-	mSte.name = QString(name);
-	mSte.ocgName = "";
-	if (importerFlags & LoadSavePlugin::lfCreateDoc)
-	{
-		if (dictRef->isNull())
-			return;
-		Object dictObj;
-		Dict *dict;
-		Object dictType;
-		OCGs *contentConfig = catalog->getOptContentConfig();
-		OptionalContentGroup *oc;
-		if (dictRef->isRef())
-		{
-			oc = contentConfig->findOcgByRef(dictRef->getRef());
-			if (oc)
-			{
-//				qDebug() << "Begin OCG Content (Ref) with Name " << QString(name) << "Layer" << UnicodeParsedString(oc->getName());
-				m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));
-				mSte.ocgName = UnicodeParsedString(oc->getName());
-			}
-		}
-		else
-		{
-			dictRef->fetch(xref, &dictObj);
-			if (!dictObj.isDict())
-			{
-				dictObj.free();
-				return;
-			}
-			dict = dictObj.getDict();
-			dict->lookup("Type", &dictType);
-			if (dictType.isName("OCG"))
-			{
-				oc = contentConfig->findOcgByRef(dictRef->getRef());
-				if (oc)
-				{
-//					qDebug() << "Begin OCG Content with Name " << UnicodeParsedString(oc->getName());
-					m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));
-					mSte.ocgName = UnicodeParsedString(oc->getName());
-				}
-			}
-			dictType.free();
-			dictObj.free();
-		}
-	}
-	m_mcStack.push(mSte);
-}
-
-void SlaOutputDev::beginMarkedContent(char *name, Dict *properties)
-{
-//	qDebug() << "Begin Marked Content with Name " << QString(name);
-	QString nam = QString(name);
-	mContent mSte;
-	mSte.name = nam;
-	mSte.ocgName = "";
-	m_mcStack.push(mSte);
-	if (importerFlags & LoadSavePlugin::lfCreateDoc)
-	{
-		if (nam == "Layer")		// Handle Adobe Illustrator Layer command
-		{
-			if (layersSetByOCG)
-				return;
-			Object obj;
-			QString lName = QString("Layer_%1").arg(layerNum + 1);
-			if (properties->lookup((char*)"Title", &obj))
-			{
-				if (obj.isString())
-					lName =  QString(obj.getString()->getCString());
-				obj.free();
-			}
-			for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)
-			{
-				if (it->Name == lName)
-				{
-					m_doc->setActiveLayer(lName);
-					return;
-				}
-			}
-			layerNum++;
-			if (!firstLayer)
-				currentLayer = m_doc->addLayer(lName, true);
-			firstLayer = false;
-			if (properties->lookup((char*)"Visible", &obj))
-			{
-				if (obj.isBool())
-					m_doc->setLayerVisible(currentLayer, obj.getBool());
-				obj.free();
-			}
-			if (properties->lookup((char*)"Editable", &obj))
-			{
-				if (obj.isBool())
-					m_doc->setLayerLocked(currentLayer, !obj.getBool());
-				obj.free();
-			}
-			if (properties->lookup((char*)"Printed", &obj))
-			{
-				if (obj.isBool())
-					m_doc->setLayerPrintable(currentLayer, obj.getBool());
-				obj.free();
-			}
-			if (properties->lookup((char*)"Color", &obj))
-			{
-				if (obj.isArray())
-				{
-					Object obj1;
-					obj.arrayGet(0, &obj1);
-					int r = obj1.getNum() / 256;
-					obj1.free();
-					obj.arrayGet(1, &obj1);
-					int g = obj1.getNum() / 256;
-					obj1.free();
-					obj.arrayGet(2, &obj1);
-					int b = obj1.getNum() / 256;
-					obj1.free();
-					m_doc->setLayerMarker(currentLayer, QColor(r, g, b));
-				}
-				obj.free();
-			}
-		}
-	}
-}
-
-void SlaOutputDev::endMarkedContent(GfxState *state)
-{
-//	qDebug() << "End Marked Content";
-	if (m_mcStack.count() > 0)
-	{
-		mContent mSte = m_mcStack.pop();
-		if (importerFlags & LoadSavePlugin::lfCreateDoc)
-		{
-			if (mSte.name == "OC")
-			{
-				for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)
-				{
-					if (it->Name == mSte.ocgName)
-					{
-						m_doc->setActiveLayer(mSte.ocgName);
-						return;
-					}
-				}
-			}
-		}
-	}
-}
-
-void SlaOutputDev::markPoint(char *name)
-{
-//	qDebug() << "Begin Marked Point with Name " << QString(name);
-}
-
-void SlaOutputDev::markPoint(char *name, Dict *properties)
-{
-//	qDebug() << "Begin Marked Point with Name " << QString(name) << "and Properties";
-	beginMarkedContent(name, properties);
-}
-
-// POPPLER_VERSION appeared in 0.19.0 first
-#ifdef POPPLER_VERSION
-void SlaOutputDev::updateFont(GfxState *state)
-{
-  GfxFont *gfxFont;
-  GfxFontLoc *fontLoc;
-  GfxFontType fontType;
-  SplashOutFontFileID *id;
-  SplashFontFile *fontFile;
-  SplashFontSrc *fontsrc = NULL;
-  FoFiTrueType *ff;
-  Object refObj, strObj;
-  GooString *fileName;
-  char *tmpBuf;
-  int tmpBufLen;
-  int *codeToGID;
-  double *textMat;
-  double m11, m12, m21, m22, fontSize;
-  SplashCoord mat[4];
-  int n;
-  int faceIndex = 0;
-  SplashCoord matrix[6];
-
-  m_font = NULL;
-  fileName = NULL;
-  tmpBuf = NULL;
-  fontLoc = NULL;
-
-  if (!(gfxFont = state->getFont())) {
-	goto err1;
-  }
-  fontType = gfxFont->getType();
-  if (fontType == fontType3) {
-	goto err1;
-  }
-
-  // check the font file cache
-  id = new SplashOutFontFileID(gfxFont->getID());
-  if ((fontFile = m_fontEngine->getFontFile(id))) {
-	delete id;
-
-  } else {
-
-	if (!(fontLoc = gfxFont->locateFont(xref, gFalse))) {
-	  error(errSyntaxError, -1, "Couldn't find a font for '{0:s}'",
-		gfxFont->getName() ? gfxFont->getName()->getCString()
-						   : "(unnamed)");
-	  goto err2;
-	}
-
-	// embedded font
-	if (fontLoc->locType == gfxFontLocEmbedded) {
-	  // if there is an embedded font, read it to memory
-	  tmpBuf = gfxFont->readEmbFontFile(xref, &tmpBufLen);
-	  if (! tmpBuf)
-	goto err2;
-
-	// external font
-	} else { // gfxFontLocExternal
-	  fileName = fontLoc->path;
-	  fontType = fontLoc->fontType;
-	}
-
-	fontsrc = new SplashFontSrc;
-	if (fileName)
-	  fontsrc->setFile(fileName, gFalse);
-	else
-	  fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue);
-
-	// load the font file
-	switch (fontType) {
-	case fontType1:
-	  if (!(fontFile = m_fontEngine->loadType1Font(
-			   id,
-			   fontsrc,
-			   (const char **)((Gfx8BitFont *)gfxFont)->getEncoding()))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	case fontType1C:
-	  if (!(fontFile = m_fontEngine->loadType1CFont(
-			   id,
-			   fontsrc,
-			   (const char **)((Gfx8BitFont *)gfxFont)->getEncoding()))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	case fontType1COT:
-	  if (!(fontFile = m_fontEngine->loadOpenTypeT1CFont(
-			   id,
-			   fontsrc,
-			   (const char **)((Gfx8BitFont *)gfxFont)->getEncoding()))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	case fontTrueType:
-	case fontTrueTypeOT:
-	if (fileName)
-	 ff = FoFiTrueType::load(fileName->getCString());
-	else
-	ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
-	  if (ff) {
-	codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff);
-	n = 256;
-	delete ff;
-	  } else {
-	codeToGID = NULL;
-	n = 0;
-	  }
-	  if (!(fontFile = m_fontEngine->loadTrueTypeFont(
-			   id,
-			   fontsrc,
-			   codeToGID, n))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	case fontCIDType0:
-	case fontCIDType0C:
-	  if (!(fontFile = m_fontEngine->loadCIDFont(
-			   id,
-			   fontsrc))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	case fontCIDType0COT:
-	  if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
-	n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
-	codeToGID = (int *)gmallocn(n, sizeof(int));
-	memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
-		   n * sizeof(int));
-	  } else {
-	codeToGID = NULL;
-	n = 0;
-	  }
-	  if (!(fontFile = m_fontEngine->loadOpenTypeCFFFont(
-			   id,
-			   fontsrc,
-			   codeToGID, n))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	case fontCIDType2:
-	case fontCIDType2OT:
-	  codeToGID = NULL;
-	  n = 0;
-	  if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
-	n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
-	if (n) {
-	  codeToGID = (int *)gmallocn(n, sizeof(int));
-	  memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
-		  n * sizeof(Gushort));
-	}
-	  } else {
-	if (fileName)
-	  ff = FoFiTrueType::load(fileName->getCString());
-	else
-	  ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
-	if (! ff)
-	  goto err2;
-	codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff, &n);
-	delete ff;
-	  }
-	  if (!(fontFile = m_fontEngine->loadTrueTypeFont(
-			   id,
-			   fontsrc,
-			   codeToGID, n, faceIndex))) {
-	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
-		  gfxFont->getName() ? gfxFont->getName()->getCString()
-							 : "(unnamed)");
-	goto err2;
-	  }
-	  break;
-	default:
-	  // this shouldn't happen
-	  goto err2;
-	}
-  }
-
-  // get the font matrix
-  textMat = state->getTextMat();
-  fontSize = state->getFontSize();
-  m11 = textMat[0] * fontSize * state->getHorizScaling();
-  m12 = textMat[1] * fontSize * state->getHorizScaling();
-  m21 = textMat[2] * fontSize;
-  m22 = textMat[3] * fontSize;
-  matrix[0] = 1;
-  matrix[1] = 0;
-  matrix[2] = 0;
-  matrix[3] = 1;
-  matrix[4] = 0;
-  matrix[5] = 0;
-// create the scaled font
-  mat[0] = m11;
-  mat[1] = -m12;
-  mat[2] = m21;
-  mat[3] = -m22;
-  m_font = m_fontEngine->getFont(fontFile, mat, matrix);
-
-  delete fontLoc;
-  if (fontsrc && !fontsrc->isFile)
-	  fontsrc->unref();
-  return;
-
- err2:
-  delete id;
-  delete fontLoc;
- err1:
-  if (fontsrc && !fontsrc->isFile)
-	  fontsrc->unref();
-  return;
-}
-#else
-void SlaOutputDev::updateFont(GfxState *state)
-{
-	GfxFont *gfxFont;
-	GfxFontType fontType;
-	SplashOutFontFileID *id;
-	SplashFontFile *fontFile;
-	SplashFontSrc *fontsrc = NULL;
-	FoFiTrueType *ff;
-	Ref embRef;
-	Object refObj, strObj;
-	GooString *fileName;
-	char *tmpBuf;
-	int tmpBufLen;
-	Gushort *codeToGID;
-	DisplayFontParam *dfp;
-	double *textMat;
-	double m11, m12, m21, m22, fontSize;
-	SplashCoord mat[4];
-	int n;
-	int faceIndex = 0;
-	SplashCoord matrix[6];
-
-	m_font = NULL;
-	fileName = NULL;
-	tmpBuf = NULL;
-
-	if (!(gfxFont = state->getFont()))
-		goto err1;
-	fontType = gfxFont->getType();
-	if (fontType == fontType3)
-		goto err1;
-
-  // check the font file cache
-	id = new SplashOutFontFileID(gfxFont->getID());
-	if ((fontFile = m_fontEngine->getFontFile(id)))
-	{
-		delete id;
-	}
-	else
-	{
-		// if there is an embedded font, write it to disk
-		if (gfxFont->getEmbeddedFontID(&embRef))
-		{
-			tmpBuf = gfxFont->readEmbFontFile(xref, &tmpBufLen);
-			if (!tmpBuf)
-				goto err2;
-		// if there is an external font file, use it
-		}
-		else if (!(fileName = gfxFont->getExtFontFile()))
-		{
-	  // look for a display font mapping or a substitute font
-			dfp = NULL;
-			if (gfxFont->getName())
-			{
-				dfp = globalParams->getDisplayFont(gfxFont);
-			}
-			if (!dfp)
-			{
-		//		error(-1, "Couldn't find a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-				goto err2;
-			}
-			switch (dfp->kind)
-			{
-				case displayFontT1:
-					fileName = dfp->t1.fileName;
-					fontType = gfxFont->isCIDFont() ? fontCIDType0 : fontType1;
-					break;
-				case displayFontTT:
-					fileName = dfp->tt.fileName;
-					fontType = gfxFont->isCIDFont() ? fontCIDType2 : fontTrueType;
-					faceIndex = dfp->tt.faceIndex;
-					break;
-			}
-		}
-		fontsrc = new SplashFontSrc;
-		if (fileName)
-			fontsrc->setFile(fileName, gFalse);
-		else
-			fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue);
-	// load the font file
-		switch (fontType)
-		{
-			case fontType1:
-				if (!(fontFile = m_fontEngine->loadType1Font( id, fontsrc, ((Gfx8BitFont *)gfxFont)->getEncoding())))
-				{
-			//		error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-					goto err2;
-				}
-				break;
-			case fontType1C:
-				if (!(fontFile = m_fontEngine->loadType1CFont( id, fontsrc, ((Gfx8BitFont *)gfxFont)->getEncoding())))
-				{
-		//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-					goto err2;
-				}
-				break;
-			case fontType1COT:
-				if (!(fontFile = m_fontEngine->loadOpenTypeT1CFont( id, fontsrc, ((Gfx8BitFont *)gfxFont)->getEncoding())))
-				{
-		//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-					goto err2;
-				}
-				break;
-			case fontTrueType:
-			case fontTrueTypeOT:
-				if (fileName)
-					ff = FoFiTrueType::load(fileName->getCString());
-				else
-					ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
-				if (ff)
-				{
-					codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff);
-					n = 256;
-					delete ff;
-				}
-				else
-				{
-					codeToGID = NULL;
-					n = 0;
-				}
-				if (!(fontFile = m_fontEngine->loadTrueTypeFont( id, fontsrc, codeToGID, n)))
-				{
-	//				error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-					goto err2;
-				}
-			break;
-		case fontCIDType0:
-		case fontCIDType0C:
-			if (!(fontFile = m_fontEngine->loadCIDFont( id, fontsrc)))
-			{
-	//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-				goto err2;
-			}
-			break;
-		case fontCIDType0COT:
-			if (!(fontFile = m_fontEngine->loadOpenTypeCFFFont( id, fontsrc)))
-			{
-	//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-				goto err2;
-			}
-			break;
-		case fontCIDType2:
-		case fontCIDType2OT:
-			codeToGID = NULL;
-			n = 0;
-			if (((GfxCIDFont *)gfxFont)->getCIDToGID())
-			{
-				n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
-				if (n)
-				{
-					codeToGID = (Gushort *)gmallocn(n, sizeof(Gushort));
-					memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(), n * sizeof(Gushort));
-				}
-			}
-			else
-			{
-				if (fileName)
-					ff = FoFiTrueType::load(fileName->getCString());
-				else
-					ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
-				if (!ff)
-					goto err2;
-				codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff, &n);
-				delete ff;
-			}
-			if (!(fontFile = m_fontEngine->loadTrueTypeFont( id, fontsrc, codeToGID, n, faceIndex)))
-			{
-	//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
-				goto err2;
-			}
-			break;
-		default:
-	  // this shouldn't happen
-			goto err2;
-		}
-	}
-	// get the font matrix
-	textMat = state->getTextMat();
-	fontSize = state->getFontSize();
-	m11 = textMat[0] * fontSize * state->getHorizScaling();
-	m12 = textMat[1] * fontSize * state->getHorizScaling();
-	m21 = textMat[2] * fontSize;
-	m22 = textMat[3] * fontSize;
-	matrix[0] = 1;
-	matrix[1] = 0;
-	matrix[2] = 0;
-	matrix[3] = 1;
-	matrix[4] = 0;
-	matrix[5] = 0;
-  // create the scaled font
-	mat[0] = m11;
-	mat[1] = -m12;
-	mat[2] = m21;
-	mat[3] = -m22;
-	m_font = m_fontEngine->getFont(fontFile, mat, matrix);
-	if (fontsrc && !fontsrc->isFile)
-		fontsrc->unref();
-	return;
-
-err2:
-	delete id;
-err1:
-	if (fontsrc && !fontsrc->isFile)
-		fontsrc->unref();
-	return;
-}
-#endif
-
-void SlaOutputDev::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode *u, int uLen)
-{
-	double x1, y1, x2, y2;
-	int render;
-	updateFont(state);
-	if (!m_font)
-		return;
-  // check for invisible text -- this is used by Acrobat Capture
-	render = state->getRender();
-	if (render == 3)
-		return;
-	if (!(render & 1))
-	{
-		SplashPath * fontPath;
-		fontPath = m_font->getGlyphPath(code);
-		if (fontPath)
-		{
-			QPainterPath qPath;
-			qPath.setFillRule(Qt::WindingFill);
-			for (int i = 0; i < fontPath->getLength(); ++i)
-			{
-				Guchar f;
-				fontPath->getPoint(i, &x1, &y1, &f);
-				if (f & splashPathFirst)
-					qPath.moveTo(x1,y1);
-				else if (f & splashPathCurve)
-				{
-					double x3, y3;
-					++i;
-					fontPath->getPoint(i, &x2, &y2, &f);
-					++i;
-					fontPath->getPoint(i, &x3, &y3, &f);
-					qPath.cubicTo(x1,y1,x2,y2,x3,y3);
-				}
-				else
-					qPath.lineTo(x1,y1);
-				if (f & splashPathLast)
-					qPath.closeSubpath();
-			}
-			double *ctm;
-			ctm = state->getCTM();
-			m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
-			double xCoor = m_doc->currentPage()->xOffset();
-			double yCoor = m_doc->currentPage()->yOffset();
-			FPointArray textPath;
-			textPath.fromQPainterPath(qPath);
-			FPoint wh = textPath.WidthHeight();
-			if ((textPath.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
-			{
-				int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
-				PageItem* ite = m_doc->Items->at(z);
-				FPoint tp2(getMinClipF(&textPath));
-				QTransform mm;
-				mm.scale(1, -1);
-				mm.translate(x, -y);
-				textPath.map(mm);
-				textPath.map(m_ctm);
-				ite->PoLine = textPath.copy();
-				ite->ClipEdited = true;
-				ite->FrameType = 3;
-				ite->setFillShade(CurrFillShade);
-				ite->setFillEvenOdd(false);
-				ite->setFillTransparency(1.0 - state->getFillOpacity());
-				ite->setFillBlendmode(getBlendMode(state));
-				ite->setLineEnd(PLineEnd);
-				ite->setLineJoin(PLineJoin);
-				ite->setTextFlowMode(PageItem::TextFlowDisabled);
-				m_doc->AdjustItemSize(ite);
-				if ((render & 3) == 1 || (render & 3) == 2)
-				{
-					ite->setLineColor(CurrColorStroke);
-					ite->setLineWidth(state->getTransformedLineWidth());
-					ite->setLineTransparency(1.0 - state->getStrokeOpacity());
-					ite->setLineBlendmode(getBlendMode(state));
-					ite->setLineShade(CurrStrokeShade);
-				}
-				m_Elements->append(ite);
-				if (m_groupStack.count() != 0)
-				{
-					m_groupStack.top().Items.append(ite);
-					applyMask(ite);
-				}
-				delete fontPath;
-			}
-		}
-	}
-}
-
-GBool SlaOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
-{
-//	qDebug() << "beginType3Char";
-	GfxFont *gfxFont;
-	if (!(gfxFont = state->getFont()))
-		return gTrue;
-	if (gfxFont->getType() != fontType3)
-		return gTrue;
-	F3Entry f3e;
-	f3e.colored = false;
-	m_F3Stack.push(f3e);
-	pushGroup();
-	return gFalse;
-}
-
-void SlaOutputDev::endType3Char(GfxState *state)
-{
-//	qDebug() << "endType3Char";
-	F3Entry f3e = m_F3Stack.pop();
-	groupEntry gElements = m_groupStack.pop();
-	m_doc->m_Selection->clear();
-	if (gElements.Items.count() > 0)
-	{
-		m_doc->m_Selection->delaySignalsOn();
-		for (int dre = 0; dre < gElements.Items.count(); ++dre)
-		{
-			m_doc->m_Selection->addItem(gElements.Items.at(dre), true);
-			m_Elements->removeAll(gElements.Items.at(dre));
-		}
-		PageItem *ite;
-		if (m_doc->m_Selection->count() > 1)
-			ite = m_doc->groupObjectsSelection();
-		else
-			ite = m_doc->m_Selection->itemAt(0);
-		if (!f3e.colored)
-		{
-			m_doc->itemSelection_SetItemBrush(CurrColorFill);
-			m_doc->itemSelection_SetItemBrushShade(CurrFillShade);
-			m_doc->itemSelection_SetItemFillTransparency(1.0 - state->getFillOpacity());
-			m_doc->itemSelection_SetItemFillBlend(getBlendMode(state));
-		}
-		m_Elements->append(ite);
-		m_doc->m_Selection->clear();
-		m_doc->m_Selection->delaySignalsOff();
-	}
-}
-
-void SlaOutputDev::type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/)
-{
-//	qDebug() << "type3D0";
-	if (m_F3Stack.count() > 0)
-		m_F3Stack.top().colored = true;
-}
-
-void SlaOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
-{
-//	qDebug() << "type3D1";
-	if (m_F3Stack.count() > 0)
-		m_F3Stack.top().colored = false;
-}
-
-void SlaOutputDev::beginTextObject(GfxState *state)
-{
-	pushGroup();
-}
-
-void SlaOutputDev::endTextObject(GfxState *state)
-{
-//	qDebug() << "End Text Object";
-	if (m_groupStack.count() != 0)
-	{
-		groupEntry gElements = m_groupStack.pop();
-		tmpSel->clear();
-		if (gElements.Items.count() > 0)
-		{
-			for (int dre = 0; dre < gElements.Items.count(); ++dre)
-			{
-				tmpSel->addItem(gElements.Items.at(dre), true);
-				m_Elements->removeAll(gElements.Items.at(dre));
-			}
-			PageItem *ite;
-			if (gElements.Items.count() != 1)
-				ite = m_doc->groupObjectsSelection(tmpSel);
-			else
-				ite = gElements.Items.first();
-			ite->setFillTransparency(1.0 - state->getFillOpacity());
-			ite->setFillBlendmode(getBlendMode(state));
-			for (int as = 0; as < tmpSel->count(); ++as)
-			{
-				m_Elements->append(tmpSel->itemAt(as));
-			}
-			if (m_groupStack.count() != 0)
-				applyMask(ite);
-		}
-		if (m_groupStack.count() != 0)
-		{
-			for (int as = 0; as < tmpSel->count(); ++as)
-			{
-				m_groupStack.top().Items.append(tmpSel->itemAt(as));
-			}
-		}
-		tmpSel->clear();
-	}
-}
-
-QString SlaOutputDev::getColor(GfxColorSpace *color_space, GfxColor *color, int *shade)
-{
-	QString fNam;
-	QString namPrefix = "FromPDF";
-	ScColor tmp;
-	tmp.setSpotColor(false);
-	tmp.setRegistrationColor(false);
-	*shade = 100;
-	if (m_F3Stack.count() > 0)
-	{
-		if (!m_F3Stack.top().colored)
-			return "Black";
-	}
-	if ((color_space->getMode() == csDeviceRGB) || (color_space->getMode() == csCalRGB))
-	{
-		GfxRGB rgb;
-		color_space->getRGB(color, &rgb);
-		int Rc = qRound(colToDbl(rgb.r) * 255);
-		int Gc = qRound(colToDbl(rgb.g) * 255);
-		int Bc = qRound(colToDbl(rgb.b) * 255);
-		tmp.setColorRGB(Rc, Gc, Bc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if (color_space->getMode() == csDeviceCMYK)
-	{
-		GfxCMYK cmyk;
-		color_space->getCMYK(color, &cmyk);
-		int Cc = qRound(colToDbl(cmyk.c) * 255);
-		int Mc = qRound(colToDbl(cmyk.m) * 255);
-		int Yc = qRound(colToDbl(cmyk.y) * 255);
-		int Kc = qRound(colToDbl(cmyk.k) * 255);
-		tmp.setColor(Cc, Mc, Yc, Kc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if ((color_space->getMode() == csCalGray) || (color_space->getMode() == csDeviceGray))
-	{
-		GfxGray gray;
-		color_space->getGray(color, &gray);
-		int Kc = 255 - qRound(colToDbl(gray) * 255);
-		tmp.setColor(0, 0, 0, Kc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if (color_space->getMode() == csSeparation)
-	{
-		GfxCMYK cmyk;
-		color_space->getCMYK(color, &cmyk);
-		int Cc = qRound(colToDbl(cmyk.c) * 255);
-		int Mc = qRound(colToDbl(cmyk.m) * 255);
-		int Yc = qRound(colToDbl(cmyk.y) * 255);
-		int Kc = qRound(colToDbl(cmyk.k) * 255);
-		tmp.setColor(Cc, Mc, Yc, Kc);
-		tmp.setSpotColor(true);
-		QString nam = QString(((GfxSeparationColorSpace*)color_space)->getName()->getCString());
-		fNam = m_doc->PageColors.tryAddColor(nam, tmp);
-		*shade = qRound(colToDbl(color->c[0]) * 100);
-	}
-	else
-	{
-		GfxRGB rgb;
-		color_space->getRGB(color, &rgb);
-		int Rc = qRound(colToDbl(rgb.r) * 255);
-		int Gc = qRound(colToDbl(rgb.g) * 255);
-		int Bc = qRound(colToDbl(rgb.b) * 255);
-		tmp.setColorRGB(Rc, Gc, Bc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	//	qDebug() << "update fill color other colorspace" << color_space->getMode() << "treating as rgb" << Rc << Gc << Bc;
-	}
-	if (fNam == namPrefix+tmp.name())
-		m_importedColors->append(fNam);
-	return fNam;
-}
-
-QString SlaOutputDev::getAnnotationColor(AnnotColor *color)
-{
-	QString fNam;
-	QString namPrefix = "FromPDF";
-	ScColor tmp;
-	tmp.setSpotColor(false);
-	tmp.setRegistrationColor(false);
-	if (color->getSpace() == AnnotColor::colorTransparent)
-		return CommonStrings::None;
-	else if (color->getSpace() == AnnotColor::colorRGB)
-	{
-		const double *color_data = color->getValues();
-		int Rc = qRound(color_data[0] * 255);
-		int Gc = qRound(color_data[1] * 255);
-		int Bc = qRound(color_data[2] * 255);
-		tmp.setColorRGB(Rc, Gc, Bc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if (color->getSpace() == AnnotColor::colorCMYK)
-	{
-		const double *color_data = color->getValues();
-		int Cc = qRound(color_data[0] * 255);
-		int Mc = qRound(color_data[1] * 255);
-		int Yc = qRound(color_data[2] * 255);
-		int Kc = qRound(color_data[3] * 255);
-		tmp.setColor(Cc, Mc, Yc, Kc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	else if (color->getSpace() == AnnotColor::colorGray)
-	{
-		const double *color_data = color->getValues();
-		int Kc = 255 - qRound(color_data[0] * 255);
-		tmp.setColor(0, 0, 0, Kc);
-		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
-	}
-	if (fNam == namPrefix+tmp.name())
-		m_importedColors->append(fNam);
-	return fNam;
-}
-
-QString SlaOutputDev::convertPath(GfxPath *path)
-{
-    if (! path)
-		return QString();
-
-    QString output;
-	pathIsClosed = false;
-
-	for (int i = 0; i < path->getNumSubpaths(); ++i)
-	{
-        GfxSubpath * subpath = path->getSubpath(i);
-		if (subpath->getNumPoints() > 0)
-		{
-			output += QString("M %1 %2").arg(subpath->getX(0)).arg(subpath->getY(0));
-            int j = 1;
-			while (j < subpath->getNumPoints())
-			{
-				if (subpath->getCurve(j))
-				{
-					output += QString("C %1 %2 %3 %4 %5 %6")
-                              .arg(subpath->getX(j)).arg(subpath->getY(j))
-                              .arg(subpath->getX(j + 1)).arg(subpath->getY(j + 1))
-                              .arg(subpath->getX(j + 2)).arg(subpath->getY(j + 2));
-                    j += 3;
-				}
-				else
-				{
-					output += QString("L %1 %2").arg(subpath->getX(j)).arg(subpath->getY(j));
-                    ++j;
-                }
-            }
-			if (subpath->isClosed())
-			{
-                output += QString("Z");
-				pathIsClosed = true;
-            }
-        }
-	}
-	return output;
-}
-
-void SlaOutputDev::getPenState(GfxState *state)
-{
-	switch (state->getLineCap())
-	{
-		case 0:
-			PLineEnd = Qt::FlatCap;
-			break;
-		case 1:
-			PLineEnd = Qt::RoundCap;
-			break;
-		case 2:
-			PLineEnd = Qt::SquareCap;
-			break;
-	}
-	switch (state->getLineJoin())
-	{
-		case 0:
-			PLineJoin = Qt::MiterJoin;
-			break;
-		case 1:
-			PLineJoin = Qt::RoundJoin;
-			break;
-		case 2:
-			PLineJoin = Qt::BevelJoin;
-			break;
-	}
-	double lw = state->getLineWidth();
-	double *dashPattern;
-	int dashLength;
-	state->getLineDash(&dashPattern, &dashLength, &DashOffset);
-	QVector<double> pattern(dashLength);
-	for (int i = 0; i < dashLength; ++i)
-	{
-		pattern[i] = dashPattern[i] / lw;
-	}
-	DashValues = pattern;
-}
-
-int SlaOutputDev::getBlendMode(GfxState *state)
-{
-	int mode = 0;
-	switch (state->getBlendMode())
-	{
-		default:
-		case gfxBlendNormal:
-			mode = 0;
-			break;
-		case gfxBlendDarken:
-			mode = 1;
-			break;
-		case gfxBlendLighten:
-			mode = 2;
-			break;
-		case gfxBlendMultiply:
-			mode = 3;
-			break;
-		case gfxBlendScreen:
-			mode = 4;
-			break;
-		case gfxBlendOverlay:
-			mode = 5;
-			break;
-		case gfxBlendHardLight:
-			mode = 6;
-			break;
-		case gfxBlendSoftLight:
-			mode = 7;
-			break;
-		case gfxBlendDifference:
-			mode = 8;
-			break;
-		case gfxBlendExclusion:
-			mode = 9;
-			break;
-		case gfxBlendColorDodge:
-			mode = 10;
-			break;
-		case gfxBlendColorBurn:
-			mode = 11;
-			break;
-		case gfxBlendHue:
-			mode = 12;
-			break;
-		case gfxBlendSaturation:
-			mode = 13;
-			break;
-		case gfxBlendColor:
-			mode = 14;
-			break;
-		case gfxBlendLuminosity:
-			mode = 15;
-			break;
-	}
-	return mode;
-}
-
-void SlaOutputDev::applyMask(PageItem *ite)
-{
-	if (m_groupStack.count() != 0)
-	{
-		if (!m_groupStack.top().maskName.isEmpty())
-		{
-			ite->setPatternMask(m_groupStack.top().maskName);
-			if (m_groupStack.top().alpha)
-			{
-				if (m_groupStack.top().inverted)
-					ite->setMaskType(8);
-				else
-					ite->setMaskType(3);
-			}
-			else
-			{
-				if (m_groupStack.top().inverted)
-					ite->setMaskType(7);
-				else
-					ite->setMaskType(6);
-			}
-		}
-	}
-	// Code for updating our Progressbar, needs to be called this way, as we have no
-	// possibility to get the current fileposition.
-	updateGUICounter++;
-	if (updateGUICounter > 20)
-	{
-		qApp->processEvents();
-		updateGUICounter = 0;
-	}
-}
-
-void SlaOutputDev::pushGroup(QString maskName, GBool forSoftMask, GBool alpha, bool inverted)
-{
-	groupEntry gElements;
-	gElements.forSoftMask = forSoftMask;
-	gElements.alpha = alpha;
-	gElements.inverted = inverted;
-	gElements.maskName = maskName;
-	m_groupStack.push(gElements);
-}
-
-QString SlaOutputDev::UnicodeParsedString(GooString *s1)
-{
-	if ( !s1 || s1->getLength() == 0 )
-		return QString();
-	GBool isUnicode;
-	int i;
-	Unicode u;
-	QString result;
-	if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getLength() > 1 && (s1->getChar(1) & 0xff) == 0xff))
-	{
-		isUnicode = gTrue;
-		i = 2;
-		result.reserve((s1->getLength() - 2) / 2);
-	}
-	else
-	{
-		isUnicode = gFalse;
-		i = 0;
-		result.reserve(s1->getLength());
-	}
-	while (i < s1->getLength())
-	{
-		if (isUnicode)
-		{
-			u = ((s1->getChar(i) & 0xff) << 8) | (s1->getChar(i+1) & 0xff);
-			i += 2;
-		}
-		else
-		{
-			u = s1->getChar(i) & 0xff;
-			++i;
-		}
-		result += QChar( u );
-	}
-	return result;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include "slaoutput.h"
+#include <poppler/GlobalParams.h>
+#include <poppler/poppler-config.h>
+#include <poppler/FileSpec.h>
+#include <poppler/fofi/FoFiTrueType.h>
+#include <QApplication>
+#include <QFile>
+#include "commonstrings.h"
+#include "loadsaveplugin.h"
+#include "sccolorengine.h"
+#include "util.h"
+#include "util_math.h"
+#include <tiffio.h>
+
+LinkSubmitForm::LinkSubmitForm(Object *actionObj)
+{
+	Object obj1, obj2, obj3;
+	fileName = NULL;
+	m_flags = 0;
+	if (actionObj->isDict())
+	{
+		if (!actionObj->dictLookup("F", &obj1)->isNull())
+		{
+			if (obj1.isDict())
+			{
+				if (!obj1.dictLookup("FS", &obj3)->isNull())
+				{
+					if (obj3.isName())
+					{
+						char *name = obj3.getName();
+						if (!strcmp(name, "URL"))
+						{
+							if (!obj1.dictLookup("F", &obj2)->isNull())
+								fileName = obj2.getString()->copy();
+						}
+						obj2.free();
+					}
+				}
+				obj3.free();
+			}
+		}
+		obj1.free();
+		if (!actionObj->dictLookup("Flags", &obj1)->isNull())
+		{
+			if (obj1.isNum())
+				m_flags = obj1.getInt();
+		}
+		obj1.free();
+	}
+}
+
+LinkSubmitForm::~LinkSubmitForm()
+{
+	if (fileName)
+		delete fileName;
+}
+
+LinkImportData::LinkImportData(Object *actionObj)
+{
+	Object obj1, obj3;
+	fileName = NULL;
+	if (actionObj->isDict())
+	{
+		if (!actionObj->dictLookup("F", &obj1)->isNull())
+		{
+			if (getFileSpecNameForPlatform (&obj1, &obj3))
+			{
+				fileName = obj3.getString()->copy();
+				obj3.free();
+			}
+		}
+		obj1.free();
+	}
+}
+
+LinkImportData::~LinkImportData()
+{
+	if (fileName)
+		delete fileName;
+}
+
+AnoOutputDev::~AnoOutputDev()
+{
+	if (m_fontName)
+		delete m_fontName;
+	if (m_itemText)
+		delete m_itemText;
+}
+
+AnoOutputDev::AnoOutputDev(ScribusDoc* doc, QStringList *importedColors)
+{
+	m_doc = doc;
+	m_importedColors = importedColors;
+	CurrColorStroke = CommonStrings::None;
+	CurrColorFill = CommonStrings::None;
+	CurrColorText = "Black";
+	m_fontSize = 12.0;
+	m_fontName = NULL;
+	m_itemText = NULL;
+}
+
+void AnoOutputDev::eoFill(GfxState *state)
+{
+	int shade = 100;
+	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
+}
+
+void AnoOutputDev::fill(GfxState *state)
+{
+	int shade = 100;
+	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
+}
+
+void AnoOutputDev::stroke(GfxState *state)
+{
+	int shade = 100;
+	CurrColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &shade);
+}
+
+void AnoOutputDev::drawString(GfxState *state, GooString *s)
+{
+	int shade = 100;
+	CurrColorText = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
+	m_fontSize = state->getFontSize();
+	if (state->getFont())
+		m_fontName = state->getFont()->getName()->copy();
+	m_itemText = s->copy();
+}
+
+QString AnoOutputDev::getColor(GfxColorSpace *color_space, GfxColor *color, int *shade)
+{
+	QString fNam;
+	QString namPrefix = "FromPDF";
+	ScColor tmp;
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	*shade = 100;
+	if ((color_space->getMode() == csDeviceRGB) || (color_space->getMode() == csCalRGB))
+	{
+		GfxRGB rgb;
+		color_space->getRGB(color, &rgb);
+		int Rc = qRound(colToDbl(rgb.r) * 255);
+		int Gc = qRound(colToDbl(rgb.g) * 255);
+		int Bc = qRound(colToDbl(rgb.b) * 255);
+		tmp.setColorRGB(Rc, Gc, Bc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if (color_space->getMode() == csDeviceCMYK)
+	{
+		GfxCMYK cmyk;
+		color_space->getCMYK(color, &cmyk);
+		int Cc = qRound(colToDbl(cmyk.c) * 255);
+		int Mc = qRound(colToDbl(cmyk.m) * 255);
+		int Yc = qRound(colToDbl(cmyk.y) * 255);
+		int Kc = qRound(colToDbl(cmyk.k) * 255);
+		tmp.setColor(Cc, Mc, Yc, Kc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if ((color_space->getMode() == csCalGray) || (color_space->getMode() == csDeviceGray))
+	{
+		GfxGray gray;
+		color_space->getGray(color, &gray);
+		int Kc = 255 - qRound(colToDbl(gray) * 255);
+		tmp.setColor(0, 0, 0, Kc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if (color_space->getMode() == csSeparation)
+	{
+		GfxCMYK cmyk;
+		color_space->getCMYK(color, &cmyk);
+		int Cc = qRound(colToDbl(cmyk.c) * 255);
+		int Mc = qRound(colToDbl(cmyk.m) * 255);
+		int Yc = qRound(colToDbl(cmyk.y) * 255);
+		int Kc = qRound(colToDbl(cmyk.k) * 255);
+		tmp.setColor(Cc, Mc, Yc, Kc);
+		tmp.setSpotColor(true);
+		QString nam = QString(((GfxSeparationColorSpace*)color_space)->getName()->getCString());
+		fNam = m_doc->PageColors.tryAddColor(nam, tmp);
+		*shade = qRound(colToDbl(color->c[0]) * 100);
+	}
+	else
+	{
+		GfxRGB rgb;
+		color_space->getRGB(color, &rgb);
+		int Rc = qRound(colToDbl(rgb.r) * 255);
+		int Gc = qRound(colToDbl(rgb.g) * 255);
+		int Bc = qRound(colToDbl(rgb.b) * 255);
+		tmp.setColorRGB(Rc, Gc, Bc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	//	qDebug() << "update fill color other colorspace" << color_space->getMode() << "treating as rgb" << Rc << Gc << Bc;
+	}
+	if (fNam == namPrefix+tmp.name())
+		m_importedColors->append(fNam);
+	return fNam;
+}
+
+SlaOutputDev::SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringList *importedColors, int flags)
+{
+	m_doc = doc;
+	m_Elements = Elements;
+	m_groupStack.clear();
+	pushGroup();
+	m_clipStack.clear();
+	m_currentMask = "";
+	m_importedColors = importedColors;
+	CurrColorStroke = "Black";
+	CurrColorFill = "Black";
+	Coords = "";
+	pathIsClosed = false;
+	tmpSel = new Selection(m_doc, false);
+	grStackDepth = 0;
+	firstLayer = true;
+	layerNum = 1;
+	importerFlags = flags;
+	currentLayer = m_doc->activeLayer();
+	xref = NULL;
+	m_fontEngine = 0;
+	m_font = 0;
+	m_formWidgets = 0;
+	updateGUICounter = 0;
+	layersSetByOCG = false;
+	cropOffsetX = 0;
+	cropOffsetY = 0;
+}
+
+SlaOutputDev::~SlaOutputDev()
+{
+	m_groupStack.clear();
+	tmpSel->clear();
+	delete tmpSel;
+	delete m_fontEngine;
+}
+
+/* get Actions not implemented by Poppler */
+LinkAction* SlaOutputDev::SC_getAction(AnnotWidget *ano)
+{
+	LinkAction *linkAction = NULL;
+	Object obj;
+	Ref refa = ano->getRef();
+	Object additionalActions;
+	Object *act = xref->fetch(refa.num, refa.gen, &obj);
+	if (act)
+	{
+		if (act->isDict())
+		{
+			Dict* adic = act->getDict();
+			adic->lookupNF("A", &additionalActions);
+			Object additionalActionsObject;
+			if (additionalActions.fetch(pdfDoc->getXRef(), &additionalActionsObject)->isDict())
+			{
+				Object actionObject;
+				additionalActionsObject.dictLookup("S", &actionObject);
+				if (actionObject.isName("ImportData"))
+				{
+					linkAction = new LinkImportData(&additionalActionsObject);
+				}
+				else if (actionObject.isName("SubmitForm"))
+				{
+					linkAction = new LinkSubmitForm(&additionalActionsObject);
+				}
+				actionObject.free();
+			}
+			additionalActionsObject.free();
+			additionalActions.free();
+		}
+	}
+	obj.free();
+	return linkAction;
+}
+
+/* Replacement for the crippled Poppler function LinkAction* AnnotWidget::getAdditionalAction(AdditionalActionsType type) */
+LinkAction* SlaOutputDev::SC_getAdditionalAction(const char *key, AnnotWidget *ano)
+{
+	LinkAction *linkAction = NULL;
+	Object obj;
+	Ref refa = ano->getRef();
+	Object additionalActions;
+	Object *act = xref->fetch(refa.num, refa.gen, &obj);
+	if (act)
+	{
+		if (act->isDict())
+		{
+			Dict* adic = act->getDict();
+			adic->lookupNF("AA", &additionalActions);
+			Object additionalActionsObject;
+			if (additionalActions.fetch(pdfDoc->getXRef(), &additionalActionsObject)->isDict())
+			{
+				Object actionObject;
+				if (additionalActionsObject.dictLookup(key, &actionObject)->isDict())
+					linkAction = LinkAction::parseAction(&actionObject, pdfDoc->getCatalog()->getBaseURI());
+				actionObject.free();
+			}
+			additionalActionsObject.free();
+			additionalActions.free();
+		}
+	}
+	obj.free();
+	return linkAction;
+}
+
+GBool SlaOutputDev::annotations_callback(Annot *annota, void *user_data)
+{
+	SlaOutputDev *dev = (SlaOutputDev*)user_data;
+	PDFRectangle *box = annota->getRect();
+	double xCoor = dev->m_doc->currentPage()->xOffset() + box->x1 - dev->cropOffsetX;
+	double yCoor = dev->m_doc->currentPage()->yOffset() + dev->m_doc->currentPage()->height() - box->y2 + dev->cropOffsetY;
+	double width = box->x2 - box->x1;
+	double height = box->y2 - box->y1;
+	if (dev->rotate == 90)
+	{
+		xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + box->y2;
+		yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + box->x1;
+	}
+	else if (dev->rotate == 180)
+	{
+		xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + dev->m_doc->currentPage()->width() - box->x1;
+		yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + box->y2;
+	}
+	else if (dev->rotate == 270)
+	{
+		xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + dev->m_doc->currentPage()->width() - box->y2;
+		yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + dev->m_doc->currentPage()->height() - box->x1;
+	}
+	bool retVal = true;
+	if (annota->getType() == Annot::typeText)
+		retVal = !dev->handleTextAnnot(annota, xCoor, yCoor, width, height);
+	else if (annota->getType() == Annot::typeLink)
+		retVal = !dev->handleLinkAnnot(annota, xCoor, yCoor, width, height);
+	else if (annota->getType() == Annot::typeWidget)
+		retVal = !dev->handleWidgetAnnot(annota, xCoor, yCoor, width, height);
+	return retVal;
+}
+
+bool SlaOutputDev::handleTextAnnot(Annot* annota, double xCoor, double yCoor, double width, double height)
+{
+	AnnotText *anl = (AnnotText*)annota;
+	int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem *ite = m_doc->Items->at(z);
+	int flg = annota->getFlags();
+	if (!(flg & 16))
+		ite->setRotation(rotate, true);
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillEvenOdd(false);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->ContourLine = ite->PoLine.copy();
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	ite->setIsAnnotation(true);
+	ite->AutoName = false;
+	ite->annotation().setType(Annotation::Text);
+	ite->annotation().setActionType(Annotation::Action_None);
+	ite->annotation().setAnOpen(anl->getOpen());
+	QString iconName = UnicodeParsedString(anl->getIcon());
+	if (iconName == "Note")
+		ite->annotation().setIcon(Annotation::Icon_Note);
+	else if (iconName == "Comment")
+		ite->annotation().setIcon(Annotation::Icon_Comment);
+	else if (iconName == "Key")
+		ite->annotation().setIcon(Annotation::Icon_Key);
+	else if (iconName == "Help")
+		ite->annotation().setIcon(Annotation::Icon_Help);
+	else if (iconName == "NewParagraph")
+		ite->annotation().setIcon(Annotation::Icon_NewParagraph);
+	else if (iconName == "Paragraph")
+		ite->annotation().setIcon(Annotation::Icon_Paragraph);
+	else if (iconName == "Insert")
+		ite->annotation().setIcon(Annotation::Icon_Insert);
+	else if (iconName == "Cross")
+		ite->annotation().setIcon(Annotation::Icon_Cross);
+	else if (iconName == "Circle")
+		ite->annotation().setIcon(Annotation::Icon_Circle);
+	else
+		ite->annotation().setIcon(Annotation::Icon_Note);
+	ite->setItemName( CommonStrings::itemName_TextAnnotation + QString("%1").arg(m_doc->TotalItems));
+	ite->itemText.insertChars(UnicodeParsedString(annota->getContents()));
+	ite->itemText.trim();
+	return true;
+}
+
+bool SlaOutputDev::handleLinkAnnot(Annot* annota, double xCoor, double yCoor, double width, double height)
+{
+	AnnotLink *anl = (AnnotLink*)annota;
+	LinkAction *act = anl->getAction();
+	if (!act)
+		return false;
+	bool validLink = false;
+	int pagNum = 0;
+	int xco = 0;
+	int yco = 0;
+	QString fileName = "";
+	if (act->getKind() == actionGoTo)
+	{
+		LinkGoTo *gto = (LinkGoTo*)act;
+		LinkDest *dst = gto->getDest();
+		if (dst)
+		{
+			if (dst->getKind() == destXYZ)
+			{
+				if (dst->isPageRef())
+				{
+					Ref dstr = dst->getPageRef();
+					pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
+				}
+				else
+					pagNum = dst->getPageNum();
+				xco = dst->getLeft();
+				yco = dst->getTop();
+				validLink = true;
+			}
+		}
+		else
+		{
+			GooString *ndst = gto->getNamedDest();
+			if (ndst)
+			{
+				LinkDest *dstn = pdfDoc->findDest(ndst);
+				if (dstn)
+				{
+					if (dstn->getKind() == destXYZ)
+					{
+						if (dstn->isPageRef())
+						{
+							Ref dstr = dstn->getPageRef();
+							pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
+						}
+						else
+							pagNum = dstn->getPageNum();
+						xco = dstn->getLeft();
+						yco = dstn->getTop();
+						validLink = true;
+					}
+				}
+			}
+		}
+	}
+	else if (act->getKind() == actionGoToR)
+	{
+		LinkGoToR *gto = (LinkGoToR*)act;
+		fileName = UnicodeParsedString(gto->getFileName());
+		LinkDest *dst = gto->getDest();
+		if (dst)
+		{
+			if (dst->getKind() == destXYZ)
+			{
+				pagNum = dst->getPageNum();
+				xco = dst->getLeft();
+				yco = dst->getTop();
+				validLink = true;
+			}
+		}
+		else
+		{
+			GooString *ndst = gto->getNamedDest();
+			if (ndst)
+			{
+				LinkDest *dstn = pdfDoc->findDest(ndst);
+				if (dstn)
+				{
+					if (dstn->getKind() == destXYZ)
+					{
+						pagNum = dstn->getPageNum();
+						xco = dstn->getLeft();
+						yco = dstn->getTop();
+						validLink = true;
+					}
+				}
+			}
+		}
+	}
+	else if (act->getKind() == actionURI)
+	{
+		LinkURI *gto = (LinkURI*)act;
+		validLink = true;
+		fileName = UnicodeParsedString(gto->getURI());
+	}
+	if (validLink)
+	{
+		int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CommonStrings::None, CommonStrings::None, true);
+		PageItem *ite = m_doc->Items->at(z);
+		int flg = annota->getFlags();
+		if (!(flg & 16))
+			ite->setRotation(rotate, true);
+		ite->ClipEdited = true;
+		ite->FrameType = 3;
+		ite->setFillEvenOdd(false);
+		ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+		ite->ContourLine = ite->PoLine.copy();
+		ite->setTextFlowMode(PageItem::TextFlowDisabled);
+		m_Elements->append(ite);
+		if (m_groupStack.count() != 0)
+		{
+			m_groupStack.top().Items.append(ite);
+			applyMask(ite);
+		}
+		ite->setIsAnnotation(true);
+		ite->AutoName = false;
+		if (act->getKind() == actionGoTo)
+		{
+			ite->annotation().setZiel(pagNum - 1);
+			ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
+			ite->annotation().setActionType(2);
+		}
+		else if (act->getKind() == actionGoToR)
+		{
+			ite->annotation().setZiel(pagNum - 1);
+			ite->annotation().setExtern(fileName);
+			ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
+			ite->annotation().setActionType(9);
+		}
+		else if (act->getKind() == actionURI)
+		{
+			ite->annotation().setAction("");
+			ite->annotation().setExtern(fileName);
+			ite->annotation().setActionType(8);
+		}
+		ite->annotation().setType(Annotation::Link);
+		ite->setItemName( CommonStrings::itemName_LinkAnnotation + QString("%1").arg(m_doc->TotalItems));
+	}
+	return validLink;
+}
+
+bool SlaOutputDev::handleWidgetAnnot(Annot* annota, double xCoor, double yCoor, double width, double height)
+{
+	bool retVal = false;
+	bool found = false;
+
+	if (!m_formWidgets)
+		return false;
+
+	int formcount = m_formWidgets->getNumWidgets();
+	for (int i = 0; i < formcount; ++i)
+	{
+		FormWidget *fm = m_formWidgets->getWidget(i);
+		if (!fm)
+			continue;
+		AnnotWidget *ano = fm->getWidgetAnnotation();
+		if (!ano)
+			continue;
+		if (ano != (AnnotWidget*) annota)
+			continue;
+		found = true;
+		int wtyp = -1;
+		if (fm->getType() == formButton)
+		{
+			FormWidgetButton *btn = (FormWidgetButton*)fm;
+			if (btn)
+			{
+				if (btn->getButtonType() == formButtonCheck)
+				{
+					wtyp = Annotation::Checkbox;
+					retVal = true;
+				}
+				else if (btn->getButtonType() == formButtonPush)
+				{
+					wtyp = Annotation::Button;
+					retVal = true;
+				}
+				else if (btn->getButtonType() == formButtonRadio)
+				{
+					wtyp = Annotation::RadioButton;
+					retVal = true;
+				}
+			}
+		}
+		else if (fm->getType() == formText)
+		{
+			wtyp = Annotation::Textfield;
+			retVal = true;
+		}
+		else if (fm->getType() == formChoice)
+		{
+			FormWidgetChoice *btn = (FormWidgetChoice*)fm;
+			if (btn)
+			{
+				if (btn->isCombo())
+				{
+					wtyp = Annotation::Combobox;
+					retVal = true;
+				}
+				else if (btn->isListBox())
+				{
+					wtyp = Annotation::Listbox;
+					retVal = true;
+				}
+			}
+		}
+		if (retVal)
+		{
+			AnnotAppearanceCharacs *achar = ano->getAppearCharacs();
+			bool fgFound = false;
+			bool bgFound = false;
+			if (achar)
+			{
+				AnnotColor *bgCol = achar->getBackColor();
+				if (bgCol)
+				{
+					bgFound = true;
+					CurrColorFill = getAnnotationColor(bgCol);
+				}
+				else
+					CurrColorFill = CommonStrings::None;
+				AnnotColor *fgCol = achar->getBorderColor();
+				if (fgCol)
+				{
+					fgFound = true;
+					CurrColorStroke = getAnnotationColor(fgCol);
+				}
+				else
+				{
+					fgCol = achar->getBackColor();
+					if (fgCol)
+						CurrColorStroke = getAnnotationColor(fgCol);
+					else
+						CurrColorStroke = CommonStrings::None;
+				}
+			}
+			QString CurrColorText = "Black";
+			double fontSize = 12;
+			QString fontName = "";
+			QString itemText = "";
+			AnnotAppearance *apa = annota->getAppearStreams();
+			if (apa || !achar)
+			{
+				AnoOutputDev *Adev = new AnoOutputDev(m_doc, m_importedColors);
+				Gfx *gfx;
+#ifdef POPPLER_VERSION
+				gfx = new Gfx(pdfDoc, Adev, pdfDoc->getPage(m_actPage)->getResourceDict(), annota->getRect(), NULL);
+#else
+				gfx = new Gfx(xref, Adev, pdfDoc->getPage(m_actPage)->getResourceDict(), catalog, annota->getRect(), NULL);
+#endif
+				ano->draw(gfx, false);
+				if (!bgFound)
+					CurrColorFill = Adev->CurrColorFill;
+				if (!fgFound)
+					CurrColorStroke = Adev->CurrColorStroke;
+				CurrColorText = Adev->CurrColorText;
+				fontSize = Adev->m_fontSize;
+				fontName = UnicodeParsedString(Adev->m_fontName);
+				itemText = UnicodeParsedString(Adev->m_itemText);
+				delete gfx;
+				delete Adev;
+			}
+			int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CurrColorFill, CommonStrings::None, true);
+			PageItem *ite = m_doc->Items->at(z);
+			int flg = annota->getFlags();
+			if (!(flg & 16))
+				ite->setRotation(rotate, true);
+			ite->ClipEdited = true;
+			ite->FrameType = 3;
+			ite->setFillEvenOdd(false);
+			ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+			ite->ContourLine = ite->PoLine.copy();
+			ite->setTextFlowMode(PageItem::TextFlowDisabled);
+			m_Elements->append(ite);
+			if (m_groupStack.count() != 0)
+			{
+				m_groupStack.top().Items.append(ite);
+				applyMask(ite);
+			}
+			ite->setIsAnnotation(true);
+			ite->AutoName = false;
+			AnnotBorder *brd = annota->getBorder();
+			if (brd)
+			{
+				int bsty = brd->getStyle();
+				if (bsty == AnnotBorder::borderDashed)
+					bsty = 1;
+				else if (bsty == AnnotBorder::borderBeveled)
+					bsty = 3;
+				else if (bsty == AnnotBorder::borderInset)
+					bsty = 4;
+				else if (bsty == AnnotBorder::borderUnderlined)
+					bsty = 2;
+				ite->annotation().setBsty(bsty);
+				ite->annotation().setBorderColor(CurrColorStroke);
+				ite->annotation().setBwid(qRound(brd->getWidth()));
+			}
+			else
+			{
+				ite->annotation().setBsty(0);
+				ite->annotation().setBorderColor(CommonStrings::None);
+				ite->annotation().setBwid(0);
+			}
+			QString tmTxt = "";
+			tmTxt = UnicodeParsedString(fm->getPartialName());
+			if (!tmTxt.isEmpty())
+				ite->setItemName(tmTxt);
+			tmTxt = "";
+			tmTxt = UnicodeParsedString(fm->getAlternateUiName());
+			if (!tmTxt.isEmpty())
+				ite->annotation().setToolTip(tmTxt);
+			tmTxt = "";
+			if (achar)
+			{
+				tmTxt = UnicodeParsedString(achar->getRolloverCaption());
+				if (!tmTxt.isEmpty())
+					ite->annotation().setRollOver(tmTxt);
+				tmTxt = "";
+				tmTxt = UnicodeParsedString(achar->getAlternateCaption());
+				if (!tmTxt.isEmpty())
+					ite->annotation().setDown(tmTxt);
+			}
+			ite->annotation().setType(wtyp);
+			ite->annotation().setFlag(0);
+			if (flg & 2)
+				ite->annotation().setVis(1);
+			if (flg & 32)
+				ite->annotation().setVis(3);
+			if (wtyp == Annotation::Button)
+			{
+				ite->setFillColor(CurrColorFill);
+				if (achar)
+					ite->itemText.insertChars(UnicodeParsedString(achar->getNormalCaption()));
+				else
+					ite->itemText.insertChars(itemText);
+				applyTextStyle(ite, fontName, CurrColorText, fontSize);
+				ite->annotation().addToFlag(Annotation::Flag_PushButton);
+				FormWidgetButton *btn = (FormWidgetButton*)fm;
+				if (!btn->isReadOnly())
+					ite->annotation().addToFlag(Annotation::Flag_Edit);
+				handleActions(ite, ano);
+			}
+			else if (wtyp == Annotation::Textfield)
+			{
+				FormWidgetText *btn = (FormWidgetText*)fm;
+				if (btn)
+				{
+					ite->itemText.insertChars(UnicodeParsedString(btn->getContent()));
+					applyTextStyle(ite, fontName, CurrColorText, fontSize);
+					ite->itemText.trim();
+					if (btn->isMultiline())
+						ite->annotation().addToFlag(Annotation::Flag_Multiline);
+					if (btn->isPassword())
+						ite->annotation().addToFlag(Annotation::Flag_Password);
+					if (btn->noSpellCheck())
+						ite->annotation().addToFlag(Annotation::Flag_DoNotSpellCheck);
+					if (btn->noScroll())
+						ite->annotation().addToFlag(Annotation::Flag_DoNotScroll);
+					int mxLen = btn->getMaxLen();
+					if (mxLen > 0)
+						ite->annotation().setMaxChar(mxLen);
+					else
+						ite->annotation().setMaxChar(-1);
+					if (!btn->isReadOnly())
+						ite->annotation().addToFlag(Annotation::Flag_Edit);
+					handleActions(ite, ano);
+				}
+			}
+			else if (wtyp == Annotation::Checkbox)
+			{
+				FormWidgetButton *btn = (FormWidgetButton*)fm;
+				if (btn)
+				{
+					ite->annotation().setIsChk(btn->getState());
+					ite->annotation().setCheckState(ite->annotation().IsChk());
+					handleActions(ite, ano);
+					if (itemText == "4")
+						ite->annotation().setChkStil(0);
+					else if (itemText == "5")
+						ite->annotation().setChkStil(1);
+					else if (itemText == "F")
+						ite->annotation().setChkStil(2);
+					else if (itemText == "l")
+						ite->annotation().setChkStil(3);
+					else if (itemText == "H")
+						ite->annotation().setChkStil(4);
+					else if (itemText == "n")
+						ite->annotation().setChkStil(5);
+					else
+						ite->annotation().setChkStil(0);
+					if (!btn->isReadOnly())
+						ite->annotation().addToFlag(Annotation::Flag_Edit);
+				}
+			}
+			else if ((wtyp == Annotation::Combobox) || (wtyp == Annotation::Listbox))
+			{
+				FormWidgetChoice *btn = (FormWidgetChoice*)fm;
+				if (btn)
+				{
+					if (wtyp == 5)
+						ite->annotation().addToFlag(Annotation::Flag_Combo);
+					int co = btn->getNumChoices();
+					if (co > 0)
+					{
+						QString inh = UnicodeParsedString(btn->getChoice(0));
+						for (int a = 1; a < co; a++)
+						{
+							inh += "\n" + UnicodeParsedString(btn->getChoice(a));
+						}
+						ite->itemText.insertChars(inh);
+					}
+					applyTextStyle(ite, fontName, CurrColorText, fontSize);
+					if (!btn->isReadOnly())
+						ite->annotation().addToFlag(Annotation::Flag_Edit);
+					handleActions(ite, ano);
+				}
+			}
+			else if (wtyp == Annotation::RadioButton)
+			{
+				FormWidgetButton *btn = (FormWidgetButton*)fm;
+				if (btn)
+				{
+					ite->setItemName( CommonStrings::itemName_RadioButton + QString("%1").arg(m_doc->TotalItems));
+					ite->annotation().setIsChk(btn->getState());
+					ite->annotation().setCheckState(ite->annotation().IsChk());
+					handleActions(ite, ano);
+					m_radioButtons.insert(annota->getRef().num, ite);
+				}
+			}
+		}
+		break;
+	}
+	if (!found)
+	{
+		Object obj1;
+		Ref refa = annota->getRef();
+		Object *act = xref->fetch(refa.num, refa.gen, &obj1);
+		if (act && act->isDict())
+		{
+			Dict* dict = act->getDict();
+			Object obj2;
+			//childs
+			if (dict->lookup("Kids", &obj2)->isArray())
+			{
+				// Load children
+				QList<int> radList;
+				for (int i = 0 ; i < obj2.arrayGetLength(); i++)
+				{
+					Object childRef, childObj;
+					if (!obj2.arrayGetNF(i, &childRef)->isRef())
+					{
+						childRef.free();
+						continue;
+					}
+					if (!obj2.arrayGet(i, &childObj)->isDict())
+					{
+						childObj.free();
+						childRef.free();
+						continue;
+					}
+					const Ref ref = childRef.getRef();
+					radList.append(ref.num);
+					childObj.free();
+					childRef.free();
+				}
+				QString tmTxt = UnicodeParsedString(annota->getName());
+				m_radioMap.insert(tmTxt, radList);
+			}
+			obj2.free();
+		}
+		obj1.free();
+	}
+	return retVal;
+}
+
+void SlaOutputDev::applyTextStyle(PageItem* ite, QString fontName, QString textColor, double fontSize)
+{
+	CharStyle newStyle;
+	newStyle.setFillColor(textColor);
+	newStyle.setFontSize(fontSize * 10);
+	if (!fontName.isEmpty())
+	{
+		SCFontsIterator it(*m_doc->AllFonts);
+		for ( ; it.hasNext() ; it.next())
+		{
+			ScFace& face(it.current());
+			if ((face.psName() == fontName) && (face.usable()) && (face.type() == ScFace::TTF))
+			{
+				newStyle.setFont(face);
+				break;
+			}
+			else if ((face.family() == fontName) && (face.usable()) && (face.type() == ScFace::TTF))
+			{
+				newStyle.setFont(face);
+				break;
+			}
+			else if ((face.scName() == fontName) && (face.usable()) && (face.type() == ScFace::TTF))
+			{
+				newStyle.setFont(face);
+				break;
+			}
+		}
+	}
+	ParagraphStyle dstyle(ite->itemText.defaultStyle());
+	dstyle.charStyle().applyCharStyle(newStyle);
+	ite->itemText.setDefaultStyle(dstyle);
+	ite->itemText.applyCharStyle(0, ite->itemText.length(), newStyle);
+	ite->invalid = true;
+}
+
+void SlaOutputDev::handleActions(PageItem* ite, AnnotWidget *ano)
+{
+	LinkAction *Lact = ano->getAction();
+	if (Lact)
+	{
+		if (Lact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Lact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setActionType(1);
+				ite->annotation().setAction(UnicodeParsedString(jsa->getScript()));
+			}
+		}
+		else if (Lact->getKind() == actionGoTo)
+		{
+			int pagNum = 0;
+			int xco = 0;
+			int yco = 0;
+			LinkGoTo *gto = (LinkGoTo*)Lact;
+			LinkDest *dst = gto->getDest();
+			if (dst)
+			{
+				if (dst->getKind() == destXYZ)
+				{
+					if (dst->isPageRef())
+					{
+						Ref dstr = dst->getPageRef();
+						pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
+					}
+					else
+						pagNum = dst->getPageNum();
+					xco = dst->getLeft();
+					yco = dst->getTop();
+					ite->annotation().setZiel(pagNum - 1);
+					ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
+					ite->annotation().setActionType(2);
+				}
+			}
+			else
+			{
+				GooString *ndst = gto->getNamedDest();
+				if (ndst)
+				{
+					LinkDest *dstn = pdfDoc->findDest(ndst);
+					if (dstn)
+					{
+						if (dstn->getKind() == destXYZ)
+						{
+							if (dstn->isPageRef())
+							{
+								Ref dstr = dstn->getPageRef();
+								pagNum = pdfDoc->findPage(dstr.num, dstr.gen);
+							}
+							else
+								pagNum = dstn->getPageNum();
+							xco = dstn->getLeft();
+							yco = dstn->getTop();
+							ite->annotation().setZiel(pagNum - 1);
+							ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
+							ite->annotation().setActionType(2);
+						}
+					}
+				}
+			}
+		}
+		else if (Lact->getKind() == actionGoToR)
+		{
+			int pagNum = 0;
+			int xco = 0;
+			int yco = 0;
+			LinkGoToR *gto = (LinkGoToR*)Lact;
+			QString fileName = UnicodeParsedString(gto->getFileName());
+			LinkDest *dst = gto->getDest();
+			if (dst)
+			{
+				if (dst->getKind() == destXYZ)
+				{
+					pagNum = dst->getPageNum();
+					xco = dst->getLeft();
+					yco = dst->getTop();
+					ite->annotation().setZiel(pagNum - 1);
+					ite->annotation().setExtern(fileName);
+					ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
+					ite->annotation().setActionType(9);
+				}
+			}
+			else
+			{
+				GooString *ndst = gto->getNamedDest();
+				if (ndst)
+				{
+					LinkDest *dstn = pdfDoc->findDest(ndst);
+					if (dstn)
+					{
+						if (dstn->getKind() == destXYZ)
+						{
+							pagNum = dstn->getPageNum();
+							xco = dstn->getLeft();
+							yco = dstn->getTop();
+							ite->annotation().setZiel(pagNum - 1);
+							ite->annotation().setExtern(fileName);
+							ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco));
+							ite->annotation().setActionType(9);
+						}
+					}
+				}
+			}
+		}
+		else if (Lact->getKind() == actionUnknown)
+		{
+			LinkUnknown *uno = (LinkUnknown*)Lact;
+			QString actString = UnicodeParsedString(uno->getAction());
+			if (actString == "ResetForm")
+			{
+				ite->annotation().setActionType(4);
+			}
+			else
+			{
+				LinkAction* scact = SC_getAction(ano);
+				if (scact)
+				{
+					if (actString == "ImportData")
+					{
+						LinkImportData *impo = (LinkImportData*)scact;
+						if (impo->isOk())
+						{
+							ite->annotation().setActionType(5);
+							ite->annotation().setAction(UnicodeParsedString(impo->getFileName()));
+						}
+					}
+					else if (actString == "SubmitForm")
+					{
+						LinkSubmitForm *impo = (LinkSubmitForm*)scact;
+						if (impo->isOk())
+						{
+							ite->annotation().setActionType(3);
+							ite->annotation().setAction(UnicodeParsedString(impo->getFileName()));
+							int fl = impo->getFlags();
+							if (fl == 0)
+								ite->annotation().setHTML(0);
+							else if (fl == 4)
+								ite->annotation().setHTML(1);
+							else if (fl == 64)
+								ite->annotation().setHTML(2);
+							else if (fl == 512)
+								ite->annotation().setHTML(3);
+						}
+					}
+				}
+			}
+		}
+		else if (Lact->getKind() == actionNamed)
+		{
+			LinkNamed *uno = (LinkNamed*)Lact;
+			ite->annotation().setActionType(10);
+			ite->annotation().setAction(UnicodeParsedString(uno->getName()));
+		}
+		else
+			qDebug() << "Found unsupported Action of type" << Lact->getKind();
+	}
+	LinkAction *Aact = SC_getAdditionalAction("D", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setD_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("E", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setE_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("X", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setX_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("Fo", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setFo_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("Bl", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setBl_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("C", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setC_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("F", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setF_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+				ite->annotation().setFormat(5);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("K", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setK_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+				ite->annotation().setFormat(5);
+			}
+		}
+		Aact = NULL;
+	}
+	Aact = SC_getAdditionalAction("V", ano);
+	if (Aact)
+	{
+		if (Aact->getKind() == actionJavaScript)
+		{
+			LinkJavaScript *jsa = (LinkJavaScript*)Aact;
+			if (jsa->isOk())
+			{
+				ite->annotation().setV_act(UnicodeParsedString(jsa->getScript()));
+				ite->annotation().setAAact(true);
+			}
+		}
+		Aact = NULL;
+	}
+}
+
+void SlaOutputDev::startDoc(PDFDoc *doc, XRef *xrefA, Catalog *catA)
+{
+	xref = xrefA;
+	catalog = catA;
+	pdfDoc = doc;
+	updateGUICounter = 0;
+	m_fontEngine = new SplashFontEngine(
+#if HAVE_T1LIB_H
+	globalParams->getEnableT1lib(),
+#endif
+#if HAVE_FREETYPE_H
+	globalParams->getEnableFreeType(),
+	true,
+	true,
+#endif
+	true);
+}
+
+void SlaOutputDev::startPage(int pageNum, GfxState *)
+{
+	m_formWidgets = pdfDoc->getPage(pageNum)->getFormWidgets();
+	m_radioMap.clear();
+	m_radioButtons.clear();
+	m_actPage = pageNum;
+}
+
+void SlaOutputDev::endPage()
+{
+	if (!m_radioMap.isEmpty())
+	{
+		QHash<QString, QList<int> >::iterator it;
+		for (it = m_radioMap.begin(); it != m_radioMap.end(); ++it)
+		{
+			tmpSel->clear();
+			QList<int> refList = it.value();
+			for (int a = 0; a < refList.count(); a++)
+			{
+				if (m_radioButtons.contains(refList[a]))
+				{
+					tmpSel->addItem(m_radioButtons[refList[a]], true);
+					m_Elements->removeAll(m_radioButtons[refList[a]]);
+				}
+			}
+			if (!tmpSel->isEmpty())
+			{
+				PageItem *ite = m_doc->groupObjectsSelection(tmpSel);
+				ite->setItemName(it.key());
+				m_Elements->append(ite);
+				if (m_groupStack.count() != 0)
+				{
+					m_groupStack.top().Items.append(ite);
+				}
+			}
+		}
+	}
+	m_radioMap.clear();
+	m_radioButtons.clear();
+//	qDebug() << "ending page";
+}
+
+void SlaOutputDev::saveState(GfxState *state)
+{
+//	qDebug() << "saveState" << grStackDepth;
+	grStackDepth++;
+}
+
+void SlaOutputDev::restoreState(GfxState *state)
+{
+//	qDebug() << "restoreState" << grStackDepth;
+	grStackDepth--;
+	if (m_groupStack.count() != 0)
+		m_groupStack.top().maskName = "";
+	if (m_clipStack.count() != 0)
+	{
+		while (m_clipStack.top().grStackDepth > grStackDepth)
+		{
+			clipEntry clp = m_clipStack.pop();
+			PageItem *ite = clp.ClipItem;
+			if (m_groupStack.count() != 0)
+			{
+				groupEntry gElements = m_groupStack.pop();
+				if (gElements.Items.count() > 0)
+				{
+					for (int d = 0; d < gElements.Items.count(); d++)
+					{
+						m_Elements->removeAll(gElements.Items.at(d));
+					}
+					PageItem *sing = gElements.Items.first();
+					QPainterPath input1 = sing->PoLine.toQPainterPath(true);
+					if (sing->fillEvenOdd())
+						input1.setFillRule(Qt::OddEvenFill);
+					else
+						input1.setFillRule(Qt::WindingFill);
+					QPainterPath input2 = ite->PoLine.toQPainterPath(true);
+					if (ite->fillEvenOdd())
+						input2.setFillRule(Qt::OddEvenFill);
+					else
+						input2.setFillRule(Qt::WindingFill);
+					QPainterPath result = input1.intersected(input2);
+					if ((gElements.Items.count() == 1)
+						 && (sing->isGroup() && !result.isEmpty())
+						 && (sing->isImageFrame() || sing->isGroup() || sing->isPolygon() || sing->isPolyLine())
+						 && (ite->patternMask().isEmpty() || sing->patternMask().isEmpty() || (sing->patternMask() == ite->patternMask()))
+						 && (state->getFillOpacity() == (1.0 - ite->fillTransparency()))
+					   )
+					{
+						m_Elements->replace(m_Elements->indexOf(ite), sing);
+						m_doc->Items->removeAll(sing);
+						m_doc->Items->replace(m_doc->Items->indexOf(ite), sing);
+						if (m_groupStack.top().Items.indexOf(ite) > -1)
+							m_groupStack.top().Items.replace(m_groupStack.top().Items.indexOf(ite), sing);
+						else
+							m_groupStack.top().Items.append(sing);
+						sing->setFillTransparency(1.0 - (state->getFillOpacity() * (1.0 - ite->fillTransparency())));
+						sing->setFillBlendmode(getBlendMode(state));
+						if (!ite->patternMask().isEmpty())
+						{
+							sing->setPatternMask(ite->patternMask());
+							sing->setMaskType(ite->maskType());
+						}
+						if (sing->isGroup() || (sing->lineColor() == CommonStrings::None))
+						{
+							double dx = sing->xPos() - ite->xPos();
+							double dy = sing->yPos() - ite->yPos();
+							sing->PoLine.translate(dx, dy);
+							if (sing->isGroup())
+							{
+								QList<PageItem*> allItems = sing->asGroupFrame()->groupItemList;
+								for (int si = 0; si < allItems.count(); si++)
+								{
+									allItems[si]->moveBy(dx, dy, true);
+								}
+							}
+							sing->setXYPos(ite->xPos(), ite->yPos(), true);
+							sing->setWidthHeight(ite->width(), ite->height(), true);
+							sing->groupWidth = ite->width();
+							sing->groupHeight = ite->height();
+							sing->ClipEdited = true;
+							sing->FrameType = 3;
+							if (!result.isEmpty())
+								sing->PoLine.fromQPainterPath(result);
+							else
+								sing->SetRectFrame();
+							m_doc->AdjustItemSize(sing);
+							if (sing->isGroup())
+								sing->asGroupFrame()->adjustXYPosition();
+							if (sing->isImageFrame())
+							{
+								sing->setImageXYOffset(0, 0);
+								sing->AdjustPictScale();
+							}
+						}
+						delete ite;
+					}
+					else
+					{
+						m_doc->groupObjectsToItem(ite, gElements.Items);
+						ite->setFillTransparency(1.0 - state->getFillOpacity());
+						ite->setFillBlendmode(getBlendMode(state));
+					}
+				}
+				else
+				{
+					m_Elements->removeAll(ite);
+					m_doc->Items->removeAll(ite);
+					m_groupStack.top().Items.removeAll(ite);
+					delete ite;
+				}
+			}
+			if (m_clipStack.count() == 0)
+				break;
+		}
+	}
+}
+/*
+void SlaOutputDev::updateFillColor(GfxState *state)
+{
+	int shade = 100;
+	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
+}
+*/
+void SlaOutputDev::beginTransparencyGroup(GfxState *state, double *bbox, GfxColorSpace * /*blendingColorSpace*/, GBool /*isolated*/, GBool /*knockout*/, GBool forSoftMask)
+{
+//	qDebug() << "Start Group";
+	pushGroup("", forSoftMask);
+}
+
+void SlaOutputDev::endTransparencyGroup(GfxState *state)
+{
+//	qDebug() << "End Group";
+	if (m_groupStack.count() != 0)
+	{
+		groupEntry gElements = m_groupStack.pop();
+		tmpSel->clear();
+		if (gElements.Items.count() > 0)
+		{
+			if (gElements.forSoftMask)
+			{
+				for (int dre = 0; dre < gElements.Items.count(); ++dre)
+				{
+					tmpSel->addItem(gElements.Items.at(dre), true);
+					m_Elements->removeAll(gElements.Items.at(dre));
+				}
+				PageItem *ite = m_doc->groupObjectsSelection(tmpSel);
+				ite->setFillTransparency(1.0 - state->getFillOpacity());
+				ite->setFillBlendmode(getBlendMode(state));
+				ScPattern pat = ScPattern();
+				pat.setDoc(m_doc);
+				m_doc->DoDrawing = true;
+				pat.pattern = ite->DrawObj_toImage(qMin(qMax(ite->width(), ite->height()), 500.0));
+				pat.xoffset = 0;
+				pat.yoffset = 0;
+				m_doc->DoDrawing = false;
+				pat.width = ite->width();
+				pat.height = ite->height();
+				ite->gXpos = 0;
+				ite->gYpos = 0;
+				ite->setXYPos(ite->gXpos, ite->gYpos, true);
+				pat.items.append(ite);
+				m_doc->Items->removeAll(ite);
+				QString id = QString("Pattern_from_PDF_%1S").arg(m_doc->docPatterns.count() + 1);
+				m_doc->addPattern(id, pat);
+				m_currentMask = id;
+				tmpSel->clear();
+				return;
+			}
+			else
+			{
+				PageItem *ite;
+				for (int dre = 0; dre < gElements.Items.count(); ++dre)
+				{
+					tmpSel->addItem(gElements.Items.at(dre), true);
+					m_Elements->removeAll(gElements.Items.at(dre));
+				}
+				if (gElements.Items.count() != 1)
+					ite = m_doc->groupObjectsSelection(tmpSel);
+				else
+					ite = gElements.Items.first();
+				ite->setFillTransparency(1.0 - state->getFillOpacity());
+				ite->setFillBlendmode(getBlendMode(state));
+				for (int as = 0; as < tmpSel->count(); ++as)
+				{
+					m_Elements->append(tmpSel->itemAt(as));
+				}
+				if (m_groupStack.count() != 0)
+					applyMask(ite);
+			}
+		}
+		if (m_groupStack.count() != 0)
+		{
+			for (int as = 0; as < tmpSel->count(); ++as)
+			{
+				m_groupStack.top().Items.append(tmpSel->itemAt(as));
+			}
+		}
+		tmpSel->clear();
+	}
+}
+
+void SlaOutputDev::setSoftMask(GfxState * /*state*/, double * /*bbox*/, GBool alpha, Function *transferFunc, GfxColor * /*backdropColor*/)
+{
+	if (m_groupStack.count() != 0)
+	{
+		double lum = 0;
+		double lum2 = 0;
+		if (transferFunc)
+			transferFunc->transform(&lum, &lum2);
+		else
+			lum2 = lum;
+		if (lum == lum2)
+			m_groupStack.top().inverted = false;
+		else
+			m_groupStack.top().inverted = true;
+//		qDebug() << "Inverted Softmask" << m_groupStack.top().inverted;
+		m_groupStack.top().maskName = m_currentMask;
+		m_groupStack.top().alpha = alpha;
+	}
+}
+
+void SlaOutputDev::clearSoftMask(GfxState * /*state*/)
+{
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().maskName = "";
+	}
+}
+
+void SlaOutputDev::updateFillColor(GfxState *state)
+{
+	CurrFillShade = 100;
+	CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &CurrFillShade);
+}
+
+void SlaOutputDev::updateStrokeColor(GfxState *state)
+{
+	CurrStrokeShade = 100;
+	CurrColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &CurrStrokeShade);
+}
+
+void SlaOutputDev::clip(GfxState *state)
+{
+//	qDebug() << "Clip";
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	QString output = convertPath(state->getPath());
+	FPointArray out;
+	if (!output.isEmpty())
+	{
+		out.parseSVG(output);
+		if (!pathIsClosed)
+			out.svgClosePath();
+		out.map(m_ctm);
+	}
+	double xmin, ymin, xmax, ymax;
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	int z = m_doc->itemAdd(PageItem::Group, PageItem::Rectangle, crect.x() + m_doc->currentPage()->xOffset(), crect.y() + m_doc->currentPage()->yOffset(), crect.width(), crect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem *ite = m_doc->Items->at(z);
+	if (!output.isEmpty())
+	{
+		FPoint wh(getMinClipF(&out));
+		out.translate(-wh.x(), -wh.y());
+		FPoint dim = out.WidthHeight();
+		if (!((dim.x() == 0.0) || (dim.y() == 0.0)))		// avoid degenerate clipping paths
+			ite->PoLine = out.copy();  //FIXME: try to avoid copy if FPointArray when properly shared
+	}
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillEvenOdd(false);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->ContourLine = ite->PoLine.copy();
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	clipEntry clp;
+	clp.ClipItem = ite;
+	clp.grStackDepth = grStackDepth;
+	m_clipStack.push(clp);
+	m_doc->GroupCounter++;
+	pushGroup();
+}
+
+void SlaOutputDev::eoClip(GfxState *state)
+{
+//	qDebug() << "EoClip";
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	QString output = convertPath(state->getPath());
+	FPointArray out;
+	if (!output.isEmpty())
+	{
+		out.parseSVG(output);
+		if (!pathIsClosed)
+			out.svgClosePath();
+		out.map(m_ctm);
+	}
+	double xmin, ymin, xmax, ymax;
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	int z = m_doc->itemAdd(PageItem::Group, PageItem::Rectangle, crect.x() + m_doc->currentPage()->xOffset(), crect.y() + m_doc->currentPage()->yOffset(), crect.width(), crect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem *ite = m_doc->Items->at(z);
+	if (!output.isEmpty())
+	{
+		FPoint wh(getMinClipF(&out));
+		out.translate(-wh.x(), -wh.y());
+		FPoint dim = out.WidthHeight();
+		if (!((dim.x() == 0.0) || (dim.y() == 0.0)))		// avoid degenerate clipping paths
+			ite->PoLine = out.copy();  //FIXME: try to avoid copy if FPointArray when properly shared
+	}
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillEvenOdd(true);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->ContourLine = ite->PoLine.copy();
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	clipEntry clp;
+	clp.ClipItem = ite;
+	clp.grStackDepth = grStackDepth;
+	m_clipStack.push(clp);
+	m_doc->GroupCounter++;
+	pushGroup();
+}
+
+void SlaOutputDev::stroke(GfxState *state)
+{
+//	qDebug() << "Stroke";
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QString output = convertPath(state->getPath());
+	getPenState(state);
+	if ((m_Elements->count() != 0) && (output == Coords))			// Path is the same as in last fill
+	{
+		PageItem* ite = m_Elements->last();
+		ite->setLineColor(CurrColorStroke);
+		ite->setLineShade(CurrStrokeShade);
+		ite->setLineEnd(PLineEnd);
+		ite->setLineJoin(PLineJoin);
+		ite->setLineWidth(state->getTransformedLineWidth());
+		ite->setDashes(DashValues);
+		ite->setDashOffset(DashOffset);
+		ite->setLineTransparency(1.0 - state->getStrokeOpacity());
+	}
+	else
+	{
+		FPointArray out;
+		out.parseSVG(output);
+		m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+		out.map(m_ctm);
+		FPoint wh = out.WidthHeight();
+		if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
+		{
+			int z;
+			if (pathIsClosed)
+				z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, state->getTransformedLineWidth(), CommonStrings::None, CurrColorStroke, true);
+			else
+				z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, state->getTransformedLineWidth(), CommonStrings::None, CurrColorStroke, true);
+			PageItem* ite = m_doc->Items->at(z);
+			ite->PoLine = out.copy();
+			ite->ClipEdited = true;
+			ite->FrameType = 3;
+			ite->setWidthHeight(wh.x(),wh.y());
+			m_doc->AdjustItemSize(ite);
+			if (m_Elements->count() != 0)
+			{
+				PageItem* lItem = m_Elements->last();
+				if ((lItem->lineColor() == CommonStrings::None) && (lItem->PoLine == ite->PoLine))
+				{
+					lItem->setLineColor(CurrColorStroke);
+					lItem->setLineWidth(state->getTransformedLineWidth());
+					lItem->setLineShade(CurrStrokeShade);
+					lItem->setLineTransparency(1.0 - state->getStrokeOpacity());
+					lItem->setLineBlendmode(getBlendMode(state));
+					lItem->setLineEnd(PLineEnd);
+					lItem->setLineJoin(PLineJoin);
+					lItem->setDashes(DashValues);
+					lItem->setDashOffset(DashOffset);
+					lItem->setTextFlowMode(PageItem::TextFlowDisabled);
+					m_doc->Items->removeAll(ite);
+				}
+				else
+				{
+					ite->setLineShade(CurrStrokeShade);
+					ite->setLineTransparency(1.0 - state->getStrokeOpacity());
+					ite->setLineBlendmode(getBlendMode(state));
+					ite->setLineEnd(PLineEnd);
+					ite->setLineJoin(PLineJoin);
+					ite->setDashes(DashValues);
+					ite->setDashOffset(DashOffset);
+					ite->setTextFlowMode(PageItem::TextFlowDisabled);
+					m_Elements->append(ite);
+					if (m_groupStack.count() != 0)
+						m_groupStack.top().Items.append(ite);
+				}
+			}
+			else
+			{
+				ite->setLineShade(CurrStrokeShade);
+				ite->setLineTransparency(1.0 - state->getStrokeOpacity());
+				ite->setLineBlendmode(getBlendMode(state));
+				ite->setLineEnd(PLineEnd);
+				ite->setLineJoin(PLineJoin);
+				ite->setDashes(DashValues);
+				ite->setDashOffset(DashOffset);
+				ite->setTextFlowMode(PageItem::TextFlowDisabled);
+				m_Elements->append(ite);
+				if (m_groupStack.count() != 0)
+					m_groupStack.top().Items.append(ite);
+			}
+		}
+	}
+}
+
+void SlaOutputDev::fill(GfxState *state)
+{
+//	qDebug() << "Fill";
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	FPointArray out;
+	QString output = convertPath(state->getPath());
+	out.parseSVG(output);
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	out.map(m_ctm);
+	Coords = output;
+	FPoint wh = out.WidthHeight();
+	if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
+	{
+		int z;
+		if (pathIsClosed)
+			z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
+		else
+			z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
+		PageItem* ite = m_doc->Items->at(z);
+		ite->PoLine = out.copy();
+		ite->ClipEdited = true;
+		ite->FrameType = 3;
+		ite->setFillShade(CurrFillShade);
+		ite->setLineShade(100);
+		ite->setFillEvenOdd(false);
+		ite->setFillTransparency(1.0 - state->getFillOpacity());
+		ite->setFillBlendmode(getBlendMode(state));
+		ite->setLineEnd(PLineEnd);
+		ite->setLineJoin(PLineJoin);
+		ite->setWidthHeight(wh.x(),wh.y());
+		ite->setTextFlowMode(PageItem::TextFlowDisabled);
+		m_doc->AdjustItemSize(ite);
+		m_Elements->append(ite);
+		if (m_groupStack.count() != 0)
+		{
+			m_groupStack.top().Items.append(ite);
+			applyMask(ite);
+		}
+	}
+}
+
+void SlaOutputDev::eoFill(GfxState *state)
+{
+//	qDebug() << "EoFill";
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	FPointArray out;
+	QString output = convertPath(state->getPath());
+	out.parseSVG(output);
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	out.map(m_ctm);
+	Coords = output;
+	FPoint wh = out.WidthHeight();
+	if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
+	{
+		int z;
+		if (pathIsClosed)
+			z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
+		else
+			z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
+		PageItem* ite = m_doc->Items->at(z);
+		ite->PoLine = out.copy();
+		ite->ClipEdited = true;
+		ite->FrameType = 3;
+		ite->setFillShade(CurrFillShade);
+		ite->setLineShade(100);
+		ite->setFillEvenOdd(true);
+		ite->setFillTransparency(1.0 - state->getFillOpacity());
+		ite->setFillBlendmode(getBlendMode(state));
+		ite->setLineEnd(PLineEnd);
+		ite->setLineJoin(PLineJoin);
+		ite->setWidthHeight(wh.x(),wh.y());
+		ite->setTextFlowMode(PageItem::TextFlowDisabled);
+		m_doc->AdjustItemSize(ite);
+		m_Elements->append(ite);
+		if (m_groupStack.count() != 0)
+		{
+			m_groupStack.top().Items.append(ite);
+			applyMask(ite);
+		}
+	}
+}
+
+GBool SlaOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax)
+{
+	double GrStartX;
+	double GrStartY;
+	double GrEndX;
+	double GrEndY;
+	int shade = 100;
+	Function *func = shading->getFunc(0);
+	VGradient FillGradient = VGradient(VGradient::linear);
+	FillGradient.clearStops();
+	GfxColorSpace *color_space = shading->getColorSpace();
+	if (func->getType() == 3)
+	{
+		StitchingFunction *stitchingFunc = (StitchingFunction*)func;
+		double *bounds = stitchingFunc->getBounds();
+		int num_funcs = stitchingFunc->getNumFuncs();
+		// Add stops from all the stitched functions
+		for ( int i = 0 ; i < num_funcs ; i++ )
+		{
+			GfxColor temp;
+			((GfxAxialShading*)shading)->getColor(bounds[i], &temp);
+			QString stopColor = getColor(color_space, &temp, &shade);
+			FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i], 0.5, 1.0, stopColor, shade );
+			if (i == num_funcs - 1)
+			{
+				((GfxAxialShading*)shading)->getColor(bounds[i+1], &temp);
+				QString stopColor = getColor(color_space, &temp, &shade);
+				FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i+1], 0.5, 1.0, stopColor, shade );
+			}
+		}
+	}
+	else if ((func->getType() == 2) || (func->getType() == 0))
+	{
+		GfxColor stop1;
+		((GfxAxialShading*)shading)->getColor(0.0, &stop1);
+		QString stopColor1 = getColor(color_space, &stop1, &shade);
+		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 0.5, 1.0, stopColor1, shade );
+		GfxColor stop2;
+		((GfxAxialShading*)shading)->getColor(1.0, &stop2);
+		QString stopColor2 = getColor(color_space, &stop2, &shade);
+		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 0.5, 1.0, stopColor2, shade );
+	}
+	((GfxAxialShading*)shading)->getCoords(&GrStartX, &GrStartY, &GrEndX, &GrEndY);
+	double xmin, ymin, xmax, ymax;
+	// get the clip region bbox
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	FPointArray gr;
+	gr.addPoint(GrStartX, GrStartY);
+	gr.addPoint(GrEndX, GrEndY);
+	gr.map(m_ctm);
+	GrStartX = gr.point(0).x() - crect.x();
+	GrStartY = gr.point(0).y() - crect.y();
+	GrEndX = gr.point(1).x() - crect.x();
+	GrEndY = gr.point(1).y() - crect.y();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(0.0);
+	output += QString("Z");
+	pathIsClosed = true;
+	Coords = output;
+	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillShade(CurrFillShade);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	ite->setLineEnd(PLineEnd);
+	ite->setLineJoin(PLineJoin);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->GrType = 6;
+	if (!shading->getExtend0() || !shading->getExtend1())
+	{
+		FillGradient.setRepeatMethod(VGradient::none);
+		ite->setGradientExtend(VGradient::none);
+	}
+	else
+	{
+		FillGradient.setRepeatMethod(VGradient::pad);
+		ite->setGradientExtend(VGradient::pad);
+	}
+	ite->fill_gradient = FillGradient;
+	ite->setGradientVector(GrStartX, GrStartY, GrEndX, GrEndY, 0, 0, 1, 0);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	return gTrue;
+}
+
+GBool SlaOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading, double sMin, double sMax)
+{
+	double GrStartX;
+	double GrStartY;
+	double GrEndX;
+	double GrEndY;
+	int shade = 100;
+	Function *func = shading->getFunc(0);
+	VGradient FillGradient = VGradient(VGradient::linear);
+	FillGradient.clearStops();
+	GfxColorSpace *color_space = shading->getColorSpace();
+	if (func->getType() == 3)
+	{
+		StitchingFunction *stitchingFunc = (StitchingFunction*)func;
+		double *bounds = stitchingFunc->getBounds();
+		int num_funcs = stitchingFunc->getNumFuncs();
+		// Add stops from all the stitched functions
+		for ( int i = 0 ; i < num_funcs ; i++ )
+		{
+			GfxColor temp;
+			((GfxRadialShading*)shading)->getColor(bounds[i], &temp);
+			QString stopColor = getColor(color_space, &temp, &shade);
+			FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i], 0.5, 1.0, stopColor, shade );
+			if (i == num_funcs - 1)
+			{
+				((GfxRadialShading*)shading)->getColor(bounds[i+1], &temp);
+				QString stopColor = getColor(color_space, &temp, &shade);
+				FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), bounds[i+1], 0.5, 1.0, stopColor, shade );
+			}
+		}
+	}
+	else if ((func->getType() == 2) || (func->getType() == 0))
+	{
+		GfxColor stop1;
+		((GfxRadialShading*)shading)->getColor(0.0, &stop1);
+		QString stopColor1 = getColor(color_space, &stop1, &shade);
+		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 0.5, 1.0, stopColor1, shade );
+		GfxColor stop2;
+		((GfxRadialShading*)shading)->getColor(1.0, &stop2);
+		QString stopColor2 = getColor(color_space, &stop2, &shade);
+		FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 0.5, 1.0, stopColor2, shade );
+	}
+	double r0, x1, y1, r1;
+	((GfxRadialShading*)shading)->getCoords(&GrStartX, &GrStartY, &r0, &x1, &y1, &r1);
+	double xmin, ymin, xmax, ymax;
+	// get the clip region bbox
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	double GrFocalX = x1;
+	double GrFocalY = y1;
+	GrEndX = GrFocalX + r1;
+	GrEndY = GrFocalY;
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	FPointArray gr;
+	gr.addPoint(GrStartX, GrStartY);
+	gr.addPoint(GrEndX, GrEndY);
+	gr.addPoint(GrFocalX, GrFocalY);
+	gr.map(m_ctm);
+	GrStartX = gr.point(0).x() - crect.x();
+	GrStartY = gr.point(0).y() - crect.y();
+	GrEndX = gr.point(1).x() - crect.x();
+	GrEndY = gr.point(1).y() - crect.y();
+	GrFocalX = gr.point(2).x() - crect.x();
+	GrFocalY = gr.point(2).y() - crect.y();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(0.0);
+	output += QString("Z");
+	pathIsClosed = true;
+	Coords = output;
+	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillShade(CurrFillShade);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	ite->setLineEnd(PLineEnd);
+	ite->setLineJoin(PLineJoin);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->GrType = 7;
+	if (!shading->getExtend0() || !shading->getExtend1())
+	{
+		FillGradient.setRepeatMethod(VGradient::none);
+		ite->setGradientExtend(VGradient::none);
+	}
+	else
+	{
+		FillGradient.setRepeatMethod(VGradient::pad);
+		ite->setGradientExtend(VGradient::pad);
+	}
+	ite->fill_gradient = FillGradient;
+	ite->setGradientVector(GrStartX, GrStartY, GrEndX, GrEndY, GrFocalX, GrFocalY, 1, 0);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	return gTrue;
+}
+
+GBool SlaOutputDev::gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading)
+{
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	double xmin, ymin, xmax, ymax;
+	// get the clip region bbox
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(0.0);
+	output += QString("Z");
+	pathIsClosed = true;
+	Coords = output;
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillShade(CurrFillShade);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	ite->setLineEnd(PLineEnd);
+	ite->setLineJoin(PLineJoin);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	GfxColor color[3];
+	double x0, y0, x1, y1, x2, y2;
+	for (int i = 0; i < shading->getNTriangles(); i++)
+	{
+		int shade = 100;
+		meshGradientPatch patchM;
+		shading->getTriangle(i, &x0, &y0, &color[0],  &x1, &y1, &color[1],  &x2, &y2, &color[2]);
+		patchM.BL.resetTo(FPoint(x0, y0));
+		patchM.BL.shade = 100;
+		patchM.BL.transparency = 1.0;
+		patchM.BL.colorName = getColor(shading->getColorSpace(), &color[0], &shade);
+		patchM.BL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BL.colorName], m_doc, shade);
+		patchM.TL.resetTo(FPoint(x1, y1));
+		patchM.TL.shade = 100;
+		patchM.TL.transparency = 1.0;
+		patchM.TL.colorName = getColor(shading->getColorSpace(), &color[1], &shade);
+		patchM.TL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TL.colorName], m_doc, shade);
+		patchM.TR.resetTo(FPoint(x2, y2));
+		patchM.TR.shade = 100;
+		patchM.TR.transparency = 1.0;
+		patchM.TR.colorName = getColor(shading->getColorSpace(), &color[2], &shade);
+		patchM.TR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TR.colorName], m_doc, shade);
+		patchM.BR.resetTo(FPoint(x0, y0));
+		patchM.BR.shade = 100;
+		patchM.BR.transparency = 1.0;
+		patchM.BR.colorName = getColor(shading->getColorSpace(), &color[0], &shade);
+		patchM.BR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BR.colorName], m_doc, shade);
+		patchM.TL.transform(m_ctm);
+		patchM.TL.moveRel(-crect.x(), -crect.y());
+		patchM.TR.transform(m_ctm);
+		patchM.TR.moveRel(-crect.x(), -crect.y());
+		patchM.BR.transform(m_ctm);
+		patchM.BR.moveRel(-crect.x(), -crect.y());
+		patchM.BL.transform(m_ctm);
+		patchM.BL.moveRel(-crect.x(), -crect.y());
+		ite->meshGradientPatches.append(patchM);
+	}
+	ite->GrType = 12;
+	return gTrue;
+}
+
+GBool SlaOutputDev::patchMeshShadedFill(GfxState *state, GfxPatchMeshShading *shading)
+{
+//	qDebug() << "mesh shaded fill";
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	double xmin, ymin, xmax, ymax;
+	// get the clip region bbox
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(0.0);
+	output += QString("Z");
+	pathIsClosed = true;
+	Coords = output;
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillShade(CurrFillShade);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	ite->setLineEnd(PLineEnd);
+	ite->setLineJoin(PLineJoin);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+//	qDebug() << "Mesh of" << shading->getNPatches() << "Patches";
+	ite->meshGradientPatches.clear();
+	for (int i = 0; i < shading->getNPatches(); i++)
+	{
+		int shade = 100;
+		GfxPatch *patch = shading->getPatch(i);
+		GfxColor color;
+		meshGradientPatch patchM;
+		int u, v;
+		patchM.BL.resetTo(FPoint(patch->x[0][0], patch->y[0][0]));
+		patchM.BL.controlTop = FPoint(patch->x[0][1], patch->y[0][1]);
+		patchM.BL.controlRight = FPoint(patch->x[1][0], patch->y[1][0]);
+		patchM.BL.controlColor = FPoint(patch->x[1][1], patch->y[1][1]);
+		u = 0;
+		v = 0;
+		if (shading->isParameterized())
+		{
+			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
+		}
+		else
+		{
+			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
+			{
+				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
+			}
+		}
+		patchM.BL.colorName = getColor(shading->getColorSpace(), &color, &shade);
+		patchM.BL.shade = 100;
+		patchM.BL.transparency = 1.0;
+		patchM.BL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BL.colorName], m_doc, shade);
+
+		u = 0;
+		v = 1;
+		patchM.TL.resetTo(FPoint(patch->x[0][3], patch->y[0][3]));
+		patchM.TL.controlRight = FPoint(patch->x[1][3], patch->y[1][3]);
+		patchM.TL.controlBottom = FPoint(patch->x[0][2], patch->y[0][2]);
+		patchM.TL.controlColor = FPoint(patch->x[1][2], patch->y[1][2]);
+		if (shading->isParameterized())
+		{
+			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
+		}
+		else
+		{
+			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
+			{
+				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
+			}
+		}
+		patchM.TL.colorName = getColor(shading->getColorSpace(), &color, &shade);
+		patchM.TL.shade = 100;
+		patchM.TL.transparency = 1.0;
+		patchM.TL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TL.colorName], m_doc, shade);
+
+		u = 1;
+		v = 1;
+		patchM.TR.resetTo(FPoint(patch->x[3][3], patch->y[3][3]));
+		patchM.TR.controlBottom = FPoint(patch->x[3][2], patch->y[3][2]);
+		patchM.TR.controlLeft = FPoint(patch->x[2][3], patch->y[2][3]);
+		patchM.TR.controlColor = FPoint(patch->x[2][2], patch->y[2][2]);
+		if (shading->isParameterized())
+		{
+			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
+		}
+		else
+		{
+			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
+			{
+				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
+			}
+		}
+		patchM.TR.colorName = getColor(shading->getColorSpace(), &color, &shade);
+		patchM.TR.shade = 100;
+		patchM.TR.transparency = 1.0;
+		patchM.TR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TR.colorName], m_doc, shade);
+
+		u = 1;
+		v = 0;
+		patchM.BR.resetTo(FPoint(patch->x[3][0], patch->y[3][0]));
+		patchM.BR.controlLeft = FPoint(patch->x[2][0], patch->y[2][0]);
+		patchM.BR.controlTop = FPoint(patch->x[3][1], patch->y[3][1]);
+		patchM.BR.controlColor = FPoint(patch->x[2][1], patch->y[2][1]);
+		if (shading->isParameterized())
+		{
+			shading->getParameterizedColor (patch->color[u][v].c[0], &color);
+		}
+		else
+		{
+			for (int k = 0; k < shading->getColorSpace()->getNComps(); k++)
+			{
+				color.c[k] = GfxColorComp (patch->color[u][v].c[k]);
+			}
+		}
+		patchM.BR.colorName = getColor(shading->getColorSpace(), &color, &shade);
+		patchM.BR.shade = 100;
+		patchM.BR.transparency = 1.0;
+		patchM.BR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BR.colorName], m_doc, shade);
+
+		patchM.TL.transform(m_ctm);
+		patchM.TL.moveRel(-crect.x(), -crect.y());
+		patchM.TR.transform(m_ctm);
+		patchM.TR.moveRel(-crect.x(), -crect.y());
+		patchM.BR.transform(m_ctm);
+		patchM.BR.moveRel(-crect.x(), -crect.y());
+		patchM.BL.transform(m_ctm);
+		patchM.BL.moveRel(-crect.x(), -crect.y());
+		ite->meshGradientPatches.append(patchM);
+	}
+	ite->GrType = 12;
+	return gTrue;
+}
+
+GBool SlaOutputDev::tilingPatternFill(GfxState *state, Gfx * /*gfx*/, Catalog *cat, Object *str, double *pmat, int paintType, int tilingType, Dict *resDict, double *mat, double *bbox, int x0, int y0, int x1, int y1, double xStep, double yStep)
+{
+	PDFRectangle box;
+	Gfx *gfx;
+	QString id;
+	PageItem *ite;
+	groupEntry gElements;
+	gElements.forSoftMask = gFalse;
+	gElements.alpha = gFalse;
+	gElements.inverted = false;
+	gElements.maskName = "";
+	gElements.Items.clear();
+	m_groupStack.push(gElements);
+	double width, height;
+	width = bbox[2] - bbox[0];
+	height = bbox[3] - bbox[1];
+	if (xStep != width || yStep != height)
+		return gFalse;
+	box.x1 = bbox[0];
+	box.y1 = bbox[1];
+	box.x2 = bbox[2];
+	box.y2 = bbox[3];
+	double *ctm;
+	ctm = state->getCTM();
+	m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+	QTransform mm = QTransform(mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
+	QTransform mmx = mm * m_ctm;
+
+#ifdef POPPLER_VERSION
+	gfx = new Gfx(pdfDoc, this, resDict, &box, NULL);
+#else
+	gfx = new Gfx(xref, this, resDict, catalog, &box, NULL);
+#endif
+
+	gfx->display(str);
+	gElements = m_groupStack.pop();
+	m_doc->m_Selection->clear();
+	double pwidth = 0;
+	double pheight = 0;
+	if (gElements.Items.count() > 0)
+	{
+		for (int dre = 0; dre < gElements.Items.count(); ++dre)
+		{
+			m_doc->m_Selection->addItem(gElements.Items.at(dre), true);
+			m_Elements->removeAll(gElements.Items.at(dre));
+		}
+		m_doc->itemSelection_FlipV();
+		PageItem *ite;
+		if (m_doc->m_Selection->count() > 1)
+			ite = m_doc->groupObjectsSelection();
+		else
+			ite = m_doc->m_Selection->itemAt(0);
+		ite->setFillTransparency(1.0 - state->getFillOpacity());
+		ite->setFillBlendmode(getBlendMode(state));
+		m_doc->m_Selection->clear();
+		ScPattern pat = ScPattern();
+		pat.setDoc(m_doc);
+		m_doc->DoDrawing = true;
+		pat.pattern = ite->DrawObj_toImage(qMin(qMax(ite->width(), ite->height()), 500.0));
+		pat.xoffset = 0;
+		pat.yoffset = 0;
+		m_doc->DoDrawing = false;
+		pat.width = ite->width();
+		pat.height = ite->height();
+		pwidth = ite->width();
+		pheight = ite->height();
+		ite->gXpos = 0;
+		ite->gYpos = 0;
+		ite->setXYPos(ite->gXpos, ite->gYpos, true);
+		pat.items.append(ite);
+		m_doc->Items->removeAll(ite);
+		id = QString("Pattern_from_PDF_%1").arg(m_doc->docPatterns.count() + 1);
+		m_doc->addPattern(id, pat);
+	}
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	double xmin, ymin, xmax, ymax;
+	// get the clip region bbox
+	state->getClipBBox(&xmin, &ymin, &xmax, &ymax);
+	QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+	crect = crect.normalized();
+	QString output = QString("M %1 %2").arg(0.0).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(0.0);
+	output += QString("L %1 %2").arg(crect.width()).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(crect.height());
+	output += QString("L %1 %2").arg(0.0).arg(0.0);
+	output += QString("Z");
+	pathIsClosed = true;
+	Coords = output;
+	int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, CurrColorFill, CommonStrings::None, true);
+	ite = m_doc->Items->at(z);
+	ite->ClipEdited = true;
+	ite->FrameType = 3;
+	ite->setFillShade(CurrFillShade);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	ite->setLineEnd(PLineEnd);
+	ite->setLineJoin(PLineJoin);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->GrType = 8;
+	ite->setPattern(id);
+	ite->setPatternTransform(fabs(pmat[0]) * 100, fabs(pmat[3]) * 100, mmx.dx() - ctm[4], mmx.dy() - ctm[5], 0, -1 * pmat[1], pmat[2]);
+	m_doc->AdjustItemSize(ite);
+	m_Elements->append(ite);
+	if (m_groupStack.count() != 0)
+	{
+		m_groupStack.top().Items.append(ite);
+		applyMask(ite);
+	}
+	delete gfx;
+	return gTrue;
+}
+
+void SlaOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool interpolate, GBool inlineImg)
+{
+//	qDebug() << "Draw Image Mask";
+	QImage * image = 0;
+	int invert_bit;
+	int row_stride;
+	int x, y, i, bit;
+	unsigned char *dest = 0;
+	unsigned char *buffer;
+	Guchar *pix;
+	ImageStream * imgStr = new ImageStream(str, width, 1, 1);
+	imgStr->reset();
+#ifdef WORDS_BIGENDIAN
+	image = new QImage(width, height, QImage::Format_Mono);
+#else
+	image = new QImage(width, height, QImage::Format_MonoLSB);
+#endif
+	if (image == NULL || image->isNull())
+	{
+		delete imgStr;
+		delete image;
+		return;
+	}
+	invert_bit = invert ? 1 : 0;
+	buffer = image->bits();
+	row_stride = image->bytesPerLine();
+	for (y = 0; y < height; y++)
+	{
+		pix = imgStr->getLine();
+		dest = buffer + y * row_stride;
+		i = 0;
+		bit = 0;
+		for (x = 0; x < width; x++)
+		{
+			if (bit == 0)
+				dest[i] = 0;
+			if (!(pix[x] ^ invert_bit))
+			{
+#ifdef WORDS_BIGENDIAN
+				dest[i] |= (1 << (7 - bit));
+#else
+				dest[i] |= (1 << bit);
+#endif
+			}
+			bit++;
+			if (bit > 7)
+			{
+				bit = 0;
+				i++;
+			}
+		}
+	}
+	QColor backColor = ScColorEngine::getShadeColorProof(m_doc->PageColors[CurrColorFill], m_doc, CurrFillShade);
+	QImage res = QImage(width, height, QImage::Format_ARGB32);
+	res.fill(backColor.rgb());
+	unsigned char cc, cm, cy, ck;
+	for( int yi = 0; yi < res.height(); ++yi )
+	{
+		QRgb *t = (QRgb*)(res.scanLine( yi ));
+		for(int xi = 0; xi < res.width(); ++xi )
+		{
+			cc = qRed(*t);
+			cm = qGreen(*t);
+			cy = qBlue(*t);
+			ck = image->pixel(xi, yi);
+			if (ck == 0)
+				(*t) = qRgba(cc, cm, cy, 0);
+			else
+				(*t) = qRgba(cc, cm, cy, 255);
+			t++;
+		}
+	}
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QRectF crect = QRectF(0, 0, width, height);
+	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
+	QLineF cline = QLineF(0, 0, width, 0);
+	QLineF tline = m_ctm.map(cline);
+	QRectF trect = m_ctm.mapRect(crect);
+	double sx = m_ctm.m11();
+	double sy = m_ctm.m22();
+	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
+	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
+	{
+		mm.reset();
+		mm.rotate(-tline.angle());
+		res = res.transformed(mm);
+	}
+	else
+	{
+		if ((sx < 0) || (sy < 0))
+		{
+			mm.reset();
+			if (sx < 0)
+				mm.scale(-1, 1);
+			if (sy < 0)
+				mm.scale(1, -1);
+			res = res.transformed(mm);
+		}
+	}
+	if (res.isNull())
+	{
+		delete imgStr;
+		delete image;
+		return;
+	}
+	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->SetRectFrame();
+	m_doc->setRedrawBounding(ite);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->setFillShade(100);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	m_doc->AdjustItemSize(ite);
+	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
+	tempFile->setAutoRemove(false);
+	if (tempFile->open())
+	{
+		QString fileName = getLongPathName(tempFile->fileName());
+		if (!fileName.isEmpty())
+		{
+			tempFile->close();
+			ite->isInlineImage = true;
+			ite->isTempFile = true;
+			res.save(fileName, "PNG");
+			m_doc->loadPict(fileName, ite);
+			ite->setImageScalingMode(false, false);
+			m_Elements->append(ite);
+			if (m_groupStack.count() != 0)
+			{
+				m_groupStack.top().Items.append(ite);
+				applyMask(ite);
+			}
+		}
+		else
+			m_doc->Items->removeAll(ite);
+	}
+	else
+		m_doc->Items->removeAll(ite);
+	imgStr->close();
+	delete tempFile;
+	delete imgStr;
+	delete image;
+}
+
+void SlaOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, Stream *maskStr, int maskWidth, int maskHeight,
+				   GfxImageColorMap *maskColorMap, GBool maskInterpolate)
+{
+//	qDebug() << "Masked Image Components" << colorMap->getNumPixelComps();
+	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
+	imgStr->reset();
+	unsigned int *dest = 0;
+	unsigned char * buffer = new unsigned char[width * height * 4];
+	QImage * image = 0;
+	for (int y = 0; y < height; y++)
+	{
+		dest = (unsigned int *)(buffer + y * 4 * width);
+		Guchar * pix = imgStr->getLine();
+		colorMap->getRGBLine(pix, dest, width);
+	}
+	image = new QImage(buffer, width, height, QImage::Format_RGB32);
+	if (image == NULL || image->isNull())
+	{
+		delete imgStr;
+		delete[] buffer;
+		delete image;
+		return;
+	}
+	ImageStream *mskStr = new ImageStream(maskStr, maskWidth, maskColorMap->getNumPixelComps(), maskColorMap->getBits());
+	mskStr->reset();
+	Guchar *mdest = 0;
+	unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight];
+	for (int y = 0; y < maskHeight; y++)
+	{
+		mdest = (Guchar *)(mbuffer + y * maskWidth);
+		Guchar * pix = mskStr->getLine();
+		maskColorMap->getGrayLine(pix, mdest, maskWidth);
+	}
+	if ((maskWidth != width) || (maskHeight != height))
+	{
+		delete imgStr;
+		delete[] buffer;
+		delete image;
+		delete mskStr;
+		delete[] mbuffer;
+		return;
+	}
+	QImage res = image->convertToFormat(QImage::Format_ARGB32);
+	unsigned char cc, cm, cy, ck;
+	int s = 0;
+	for( int yi=0; yi < res.height(); ++yi )
+	{
+		QRgb *t = (QRgb*)(res.scanLine( yi ));
+		for(int xi=0; xi < res.width(); ++xi )
+		{
+			cc = qRed(*t);
+			cm = qGreen(*t);
+			cy = qBlue(*t);
+			ck = mbuffer[s];
+			(*t) = qRgba(cc, cm, cy, ck);
+			s++;
+			t++;
+		}
+	}
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QRectF crect = QRectF(0, 0, width, height);
+	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
+	QLineF cline = QLineF(0, 0, width, 0);
+	QLineF tline = m_ctm.map(cline);
+	QRectF trect = m_ctm.mapRect(crect);
+	double sx = m_ctm.m11();
+	double sy = m_ctm.m22();
+	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
+	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
+	{
+		mm.reset();
+		mm.rotate(-tline.angle());
+		res = res.transformed(mm);
+	}
+	else
+	{
+		if ((sx < 0) || (sy < 0))
+		{
+			if (sx < 0)
+				mm.scale(-1, 1);
+			if (sy < 0)
+				mm.scale(1, -1);
+			res = res.transformed(mm);
+		}
+	}
+	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->SetRectFrame();
+	m_doc->setRedrawBounding(ite);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->setFillShade(100);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	m_doc->AdjustItemSize(ite);
+	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
+	tempFile->setAutoRemove(false);
+	if (tempFile->open())
+	{
+		QString fileName = getLongPathName(tempFile->fileName());
+		if (!fileName.isEmpty())
+		{
+			tempFile->close();
+			ite->isInlineImage = true;
+			ite->isTempFile = true;
+			res.save(fileName, "PNG");
+			m_doc->loadPict(fileName, ite);
+		//	ite->setImageScalingMode(false, false);
+			m_Elements->append(ite);
+			if (m_groupStack.count() != 0)
+			{
+				m_groupStack.top().Items.append(ite);
+				applyMask(ite);
+			}
+		}
+		else
+			m_doc->Items->removeAll(ite);
+	}
+	else
+		m_doc->Items->removeAll(ite);
+	delete tempFile;
+	delete imgStr;
+	delete[] buffer;
+	delete image;
+	delete mskStr;
+	delete[] mbuffer;
+}
+
+void SlaOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,  int width, int height, GfxImageColorMap *colorMap, GBool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GBool maskInterpolate)
+{
+	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
+	imgStr->reset();
+	unsigned int *dest = 0;
+	unsigned char * buffer = new unsigned char[width * height * 4];
+	QImage * image = 0;
+	for (int y = 0; y < height; y++)
+	{
+		dest = (unsigned int *)(buffer + y * 4 * width);
+		Guchar * pix = imgStr->getLine();
+		colorMap->getRGBLine(pix, dest, width);
+	}
+	image = new QImage(buffer, width, height, QImage::Format_RGB32);
+	if (image == NULL || image->isNull())
+	{
+		delete imgStr;
+		delete[] buffer;
+		delete image;
+		return;
+	}
+	ImageStream *mskStr = new ImageStream(maskStr, maskWidth, 1, 1);
+	mskStr->reset();
+	Guchar *mdest = 0;
+	int invert_bit = maskInvert ? 1 : 0;
+	unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight];
+	for (int y = 0; y < maskHeight; y++)
+	{
+		mdest = (Guchar *)(mbuffer + y * maskWidth);
+		Guchar * pix = mskStr->getLine();
+		for (int x = 0; x < maskWidth; x++)
+		{
+			if (pix[x] ^ invert_bit)
+				*mdest++ = 0;
+			else
+				*mdest++ = 255;
+		}
+	}
+	if ((maskWidth != width) || (maskHeight != height))
+	{
+		delete imgStr;
+		delete[] buffer;
+		delete image;
+		delete mskStr;
+		delete[] mbuffer;
+		return;
+	}
+	QImage res = image->convertToFormat(QImage::Format_ARGB32);
+	unsigned char cc, cm, cy, ck;
+	int s = 0;
+	for( int yi=0; yi < res.height(); ++yi )
+	{
+		QRgb *t = (QRgb*)(res.scanLine( yi ));
+		for(int xi=0; xi < res.width(); ++xi )
+		{
+			cc = qRed(*t);
+			cm = qGreen(*t);
+			cy = qBlue(*t);
+			ck = mbuffer[s];
+			(*t) = qRgba(cc, cm, cy, ck);
+			s++;
+			t++;
+		}
+	}
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QRectF crect = QRectF(0, 0, width, height);
+	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
+	QLineF cline = QLineF(0, 0, width, 0);
+	QLineF tline = m_ctm.map(cline);
+	QRectF trect = m_ctm.mapRect(crect);
+	double sx = m_ctm.m11();
+	double sy = m_ctm.m22();
+	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
+	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
+	{
+		mm.reset();
+		mm.rotate(-tline.angle());
+		res = res.transformed(mm);
+	}
+	else
+	{
+		if ((sx < 0) || (sy < 0))
+		{
+			if (sx < 0)
+				mm.scale(-1, 1);
+			if (sy < 0)
+				mm.scale(1, -1);
+			res = res.transformed(mm);
+		}
+	}
+	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->SetRectFrame();
+	m_doc->setRedrawBounding(ite);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->setFillShade(100);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	m_doc->AdjustItemSize(ite);
+	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
+	tempFile->setAutoRemove(false);
+	if (tempFile->open())
+	{
+		QString fileName = getLongPathName(tempFile->fileName());
+		if (!fileName.isEmpty())
+		{
+			tempFile->close();
+			ite->isInlineImage = true;
+			ite->isTempFile = true;
+			res.save(fileName, "PNG");
+			m_doc->loadPict(fileName, ite);
+		//	ite->setImageScalingMode(false, false);
+			m_Elements->append(ite);
+			if (m_groupStack.count() != 0)
+			{
+				m_groupStack.top().Items.append(ite);
+				applyMask(ite);
+			}
+		}
+		else
+			m_doc->Items->removeAll(ite);
+	}
+	else
+		m_doc->Items->removeAll(ite);
+	delete tempFile;
+	delete imgStr;
+	delete[] buffer;
+	delete image;
+	delete mskStr;
+	delete[] mbuffer;
+}
+
+void SlaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg)
+{
+	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
+//	qDebug() << "Image Components" << colorMap->getNumPixelComps() << "Mask" << maskColors;
+	imgStr->reset();
+	QImage * image = 0;
+	if (maskColors)
+	{
+		image = new QImage(width, height, QImage::Format_ARGB32);
+		for (int y = 0; y < height; y++)
+		{
+			QRgb *s = (QRgb*)(image->scanLine(y));
+			Guchar *pix = imgStr->getLine();
+			for (int x = 0; x < width; x++)
+			{
+				GfxRGB rgb;
+				colorMap->getRGB(pix, &rgb);
+				int Rc = qRound(colToDbl(rgb.r) * 255);
+				int Gc = qRound(colToDbl(rgb.g) * 255);
+				int Bc = qRound(colToDbl(rgb.b) * 255);
+				*s = qRgba(Rc, Gc, Bc, 255);
+				for (int i = 0; i < colorMap->getNumPixelComps(); ++i)
+				{
+					if (pix[i] < maskColors[2*i] * 255 || pix[i] > maskColors[2*i+1] * 255)
+					{
+						*s = *s | 0xff000000;
+						break;
+					}
+				}
+				s++;
+				pix += colorMap->getNumPixelComps();
+			}
+		}
+	}
+	else
+	{
+		image = new QImage(width, height, QImage::Format_ARGB32);
+		for (int y = 0; y < height; y++)
+		{
+			QRgb *s = (QRgb*)(image->scanLine(y));
+			Guchar *pix = imgStr->getLine();
+			for (int x = 0; x < width; x++)
+			{
+				if (colorMap->getNumPixelComps() == 4)
+				{
+					GfxCMYK cmyk;
+					colorMap->getCMYK(pix, &cmyk);
+					int Cc = qRound(colToDbl(cmyk.c) * 255);
+					int Mc = qRound(colToDbl(cmyk.m) * 255);
+					int Yc = qRound(colToDbl(cmyk.y) * 255);
+					int Kc = qRound(colToDbl(cmyk.k) * 255);
+					*s = qRgba(Yc, Mc, Cc, Kc);
+				}
+				else
+				{
+					GfxRGB rgb;
+					colorMap->getRGB(pix, &rgb);
+					int Rc = qRound(colToDbl(rgb.r) * 255);
+					int Gc = qRound(colToDbl(rgb.g) * 255);
+					int Bc = qRound(colToDbl(rgb.b) * 255);
+					*s = qRgba(Rc, Gc, Bc, 255);
+				}
+				s++;
+				pix += colorMap->getNumPixelComps();
+			}
+		}
+	}
+	if (image == NULL || image->isNull())
+	{
+		delete imgStr;
+		delete image;
+		return;
+	}
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QRectF crect = QRectF(0, 0, width, height);
+	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
+	QLineF cline = QLineF(0, 0, width, 0);
+	QLineF tline = m_ctm.map(cline);
+	QRectF trect = m_ctm.mapRect(crect);
+	double sx = m_ctm.m11();
+	double sy = m_ctm.m22();
+	QImage img = image->copy();
+	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
+	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
+	{
+		mm.reset();
+		mm.rotate(-tline.angle());
+		img = image->transformed(mm);
+	}
+	else
+	{
+		if ((sx < 0) || (sy < 0))
+		{
+			if (sx < 0)
+				mm.scale(-1, 1);
+			if (sy < 0)
+				mm.scale(1, -1);
+			img = image->transformed(mm);
+		}
+	}
+	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->SetRectFrame();
+	m_doc->setRedrawBounding(ite);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->setFillShade(100);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	m_doc->AdjustItemSize(ite);
+	if (colorMap->getNumPixelComps() == 4)
+	{
+		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.tif");
+		tempFile->setAutoRemove(false);
+		if (tempFile->open())
+		{
+			QString fileName = getLongPathName(tempFile->fileName());
+			if (!fileName.isEmpty())
+			{
+				tempFile->close();
+				ite->isInlineImage = true;
+				ite->isTempFile = true;
+				TIFF* tif = TIFFOpen(fileName.toLocal8Bit().data(), "w");
+				if (tif)
+				{
+					TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, img.width());
+					TIFFSetField(tif, TIFFTAG_IMAGELENGTH, img.height());
+					TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
+					TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
+					TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+					TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED);
+					TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
+					for (int y = 0; y < img.height(); ++y)
+					{
+						TIFFWriteScanline(tif, img.scanLine(y), y);
+					}
+					TIFFClose(tif);
+					m_doc->loadPict(fileName, ite);
+				}
+				ite->setImageScalingMode(false, false);
+				m_Elements->append(ite);
+				if (m_groupStack.count() != 0)
+				{
+					m_groupStack.top().Items.append(ite);
+					applyMask(ite);
+				}
+			}
+			else
+				m_doc->Items->removeAll(ite);
+		}
+		delete tempFile;
+	}
+	else
+	{
+		QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
+		tempFile->setAutoRemove(false);
+		if (tempFile->open())
+		{
+			QString fileName = getLongPathName(tempFile->fileName());
+			if (!fileName.isEmpty())
+			{
+				tempFile->close();
+				ite->isInlineImage = true;
+				ite->isTempFile = true;
+				img.save(fileName, "PNG");
+				m_doc->loadPict(fileName, ite);
+				ite->setImageScalingMode(false, false);
+				m_Elements->append(ite);
+				if (m_groupStack.count() != 0)
+				{
+					m_groupStack.top().Items.append(ite);
+					applyMask(ite);
+				}
+			}
+			else
+				m_doc->Items->removeAll(ite);
+		}
+		delete tempFile;
+	}
+	delete imgStr;
+	delete image;
+}
+
+void SlaOutputDev::beginMarkedContent(char *name, Object *dictRef)
+{
+	mContent mSte;
+	mSte.name = QString(name);
+	mSte.ocgName = "";
+	if (importerFlags & LoadSavePlugin::lfCreateDoc)
+	{
+		if (dictRef->isNull())
+			return;
+		Object dictObj;
+		Dict *dict;
+		Object dictType;
+		OCGs *contentConfig = catalog->getOptContentConfig();
+		OptionalContentGroup *oc;
+		if (dictRef->isRef())
+		{
+			oc = contentConfig->findOcgByRef(dictRef->getRef());
+			if (oc)
+			{
+//				qDebug() << "Begin OCG Content (Ref) with Name " << QString(name) << "Layer" << UnicodeParsedString(oc->getName());
+				m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));
+				mSte.ocgName = UnicodeParsedString(oc->getName());
+			}
+		}
+		else
+		{
+			dictRef->fetch(xref, &dictObj);
+			if (!dictObj.isDict())
+			{
+				dictObj.free();
+				return;
+			}
+			dict = dictObj.getDict();
+			dict->lookup("Type", &dictType);
+			if (dictType.isName("OCG"))
+			{
+				oc = contentConfig->findOcgByRef(dictRef->getRef());
+				if (oc)
+				{
+//					qDebug() << "Begin OCG Content with Name " << UnicodeParsedString(oc->getName());
+					m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));
+					mSte.ocgName = UnicodeParsedString(oc->getName());
+				}
+			}
+			dictType.free();
+			dictObj.free();
+		}
+	}
+	m_mcStack.push(mSte);
+}
+
+void SlaOutputDev::beginMarkedContent(char *name, Dict *properties)
+{
+//	qDebug() << "Begin Marked Content with Name " << QString(name);
+	QString nam = QString(name);
+	mContent mSte;
+	mSte.name = nam;
+	mSte.ocgName = "";
+	m_mcStack.push(mSte);
+	if (importerFlags & LoadSavePlugin::lfCreateDoc)
+	{
+		if (nam == "Layer")		// Handle Adobe Illustrator Layer command
+		{
+			if (layersSetByOCG)
+				return;
+			Object obj;
+			QString lName = QString("Layer_%1").arg(layerNum + 1);
+			if (properties->lookup((char*)"Title", &obj))
+			{
+				if (obj.isString())
+					lName =  QString(obj.getString()->getCString());
+				obj.free();
+			}
+			for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)
+			{
+				if (it->Name == lName)
+				{
+					m_doc->setActiveLayer(lName);
+					return;
+				}
+			}
+			layerNum++;
+			if (!firstLayer)
+				currentLayer = m_doc->addLayer(lName, true);
+			firstLayer = false;
+			if (properties->lookup((char*)"Visible", &obj))
+			{
+				if (obj.isBool())
+					m_doc->setLayerVisible(currentLayer, obj.getBool());
+				obj.free();
+			}
+			if (properties->lookup((char*)"Editable", &obj))
+			{
+				if (obj.isBool())
+					m_doc->setLayerLocked(currentLayer, !obj.getBool());
+				obj.free();
+			}
+			if (properties->lookup((char*)"Printed", &obj))
+			{
+				if (obj.isBool())
+					m_doc->setLayerPrintable(currentLayer, obj.getBool());
+				obj.free();
+			}
+			if (properties->lookup((char*)"Color", &obj))
+			{
+				if (obj.isArray())
+				{
+					Object obj1;
+					obj.arrayGet(0, &obj1);
+					int r = obj1.getNum() / 256;
+					obj1.free();
+					obj.arrayGet(1, &obj1);
+					int g = obj1.getNum() / 256;
+					obj1.free();
+					obj.arrayGet(2, &obj1);
+					int b = obj1.getNum() / 256;
+					obj1.free();
+					m_doc->setLayerMarker(currentLayer, QColor(r, g, b));
+				}
+				obj.free();
+			}
+		}
+	}
+}
+
+void SlaOutputDev::endMarkedContent(GfxState *state)
+{
+//	qDebug() << "End Marked Content";
+	if (m_mcStack.count() > 0)
+	{
+		mContent mSte = m_mcStack.pop();
+		if (importerFlags & LoadSavePlugin::lfCreateDoc)
+		{
+			if (mSte.name == "OC")
+			{
+				for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)
+				{
+					if (it->Name == mSte.ocgName)
+					{
+						m_doc->setActiveLayer(mSte.ocgName);
+						return;
+					}
+				}
+			}
+		}
+	}
+}
+
+void SlaOutputDev::markPoint(char *name)
+{
+//	qDebug() << "Begin Marked Point with Name " << QString(name);
+}
+
+void SlaOutputDev::markPoint(char *name, Dict *properties)
+{
+//	qDebug() << "Begin Marked Point with Name " << QString(name) << "and Properties";
+	beginMarkedContent(name, properties);
+}
+
+// POPPLER_VERSION appeared in 0.19.0 first
+#ifdef POPPLER_VERSION
+void SlaOutputDev::updateFont(GfxState *state)
+{
+  GfxFont *gfxFont;
+  GfxFontLoc *fontLoc;
+  GfxFontType fontType;
+  SplashOutFontFileID *id;
+  SplashFontFile *fontFile;
+  SplashFontSrc *fontsrc = NULL;
+  FoFiTrueType *ff;
+  Object refObj, strObj;
+  GooString *fileName;
+  char *tmpBuf;
+  int tmpBufLen;
+  int *codeToGID;
+  double *textMat;
+  double m11, m12, m21, m22, fontSize;
+  SplashCoord mat[4];
+  int n;
+  int faceIndex = 0;
+  SplashCoord matrix[6];
+
+  m_font = NULL;
+  fileName = NULL;
+  tmpBuf = NULL;
+  fontLoc = NULL;
+
+  if (!(gfxFont = state->getFont())) {
+	goto err1;
+  }
+  fontType = gfxFont->getType();
+  if (fontType == fontType3) {
+	goto err1;
+  }
+
+  // check the font file cache
+  id = new SplashOutFontFileID(gfxFont->getID());
+  if ((fontFile = m_fontEngine->getFontFile(id))) {
+	delete id;
+
+  } else {
+
+	if (!(fontLoc = gfxFont->locateFont(xref, gFalse))) {
+	  error(errSyntaxError, -1, "Couldn't find a font for '{0:s}'",
+		gfxFont->getName() ? gfxFont->getName()->getCString()
+						   : "(unnamed)");
+	  goto err2;
+	}
+
+	// embedded font
+	if (fontLoc->locType == gfxFontLocEmbedded) {
+	  // if there is an embedded font, read it to memory
+	  tmpBuf = gfxFont->readEmbFontFile(xref, &tmpBufLen);
+	  if (! tmpBuf)
+	goto err2;
+
+	// external font
+	} else { // gfxFontLocExternal
+	  fileName = fontLoc->path;
+	  fontType = fontLoc->fontType;
+	}
+
+	fontsrc = new SplashFontSrc;
+	if (fileName)
+	  fontsrc->setFile(fileName, gFalse);
+	else
+	  fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue);
+
+	// load the font file
+	switch (fontType) {
+	case fontType1:
+	  if (!(fontFile = m_fontEngine->loadType1Font(
+			   id,
+			   fontsrc,
+			   (const char **)((Gfx8BitFont *)gfxFont)->getEncoding()))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	case fontType1C:
+	  if (!(fontFile = m_fontEngine->loadType1CFont(
+			   id,
+			   fontsrc,
+			   (const char **)((Gfx8BitFont *)gfxFont)->getEncoding()))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	case fontType1COT:
+	  if (!(fontFile = m_fontEngine->loadOpenTypeT1CFont(
+			   id,
+			   fontsrc,
+			   (const char **)((Gfx8BitFont *)gfxFont)->getEncoding()))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	case fontTrueType:
+	case fontTrueTypeOT:
+	if (fileName)
+	 ff = FoFiTrueType::load(fileName->getCString());
+	else
+	ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
+	  if (ff) {
+	codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff);
+	n = 256;
+	delete ff;
+	  } else {
+	codeToGID = NULL;
+	n = 0;
+	  }
+	  if (!(fontFile = m_fontEngine->loadTrueTypeFont(
+			   id,
+			   fontsrc,
+			   codeToGID, n))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	case fontCIDType0:
+	case fontCIDType0C:
+	  if (!(fontFile = m_fontEngine->loadCIDFont(
+			   id,
+			   fontsrc))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	case fontCIDType0COT:
+	  if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
+	n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
+	codeToGID = (int *)gmallocn(n, sizeof(int));
+	memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
+		   n * sizeof(int));
+	  } else {
+	codeToGID = NULL;
+	n = 0;
+	  }
+	  if (!(fontFile = m_fontEngine->loadOpenTypeCFFFont(
+			   id,
+			   fontsrc,
+			   codeToGID, n))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	case fontCIDType2:
+	case fontCIDType2OT:
+	  codeToGID = NULL;
+	  n = 0;
+	  if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
+	n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
+	if (n) {
+	  codeToGID = (int *)gmallocn(n, sizeof(int));
+	  memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
+		  n * sizeof(Gushort));
+	}
+	  } else {
+	if (fileName)
+	  ff = FoFiTrueType::load(fileName->getCString());
+	else
+	  ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
+	if (! ff)
+	  goto err2;
+	codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff, &n);
+	delete ff;
+	  }
+	  if (!(fontFile = m_fontEngine->loadTrueTypeFont(
+			   id,
+			   fontsrc,
+			   codeToGID, n, faceIndex))) {
+	error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'",
+		  gfxFont->getName() ? gfxFont->getName()->getCString()
+							 : "(unnamed)");
+	goto err2;
+	  }
+	  break;
+	default:
+	  // this shouldn't happen
+	  goto err2;
+	}
+  }
+
+  // get the font matrix
+  textMat = state->getTextMat();
+  fontSize = state->getFontSize();
+  m11 = textMat[0] * fontSize * state->getHorizScaling();
+  m12 = textMat[1] * fontSize * state->getHorizScaling();
+  m21 = textMat[2] * fontSize;
+  m22 = textMat[3] * fontSize;
+  matrix[0] = 1;
+  matrix[1] = 0;
+  matrix[2] = 0;
+  matrix[3] = 1;
+  matrix[4] = 0;
+  matrix[5] = 0;
+// create the scaled font
+  mat[0] = m11;
+  mat[1] = -m12;
+  mat[2] = m21;
+  mat[3] = -m22;
+  m_font = m_fontEngine->getFont(fontFile, mat, matrix);
+
+  delete fontLoc;
+  if (fontsrc && !fontsrc->isFile)
+	  fontsrc->unref();
+  return;
+
+ err2:
+  delete id;
+  delete fontLoc;
+ err1:
+  if (fontsrc && !fontsrc->isFile)
+	  fontsrc->unref();
+  return;
+}
+#else
+void SlaOutputDev::updateFont(GfxState *state)
+{
+	GfxFont *gfxFont;
+	GfxFontType fontType;
+	SplashOutFontFileID *id;
+	SplashFontFile *fontFile;
+	SplashFontSrc *fontsrc = NULL;
+	FoFiTrueType *ff;
+	Ref embRef;
+	Object refObj, strObj;
+	GooString *fileName;
+	char *tmpBuf;
+	int tmpBufLen;
+	Gushort *codeToGID;
+	DisplayFontParam *dfp;
+	double *textMat;
+	double m11, m12, m21, m22, fontSize;
+	SplashCoord mat[4];
+	int n;
+	int faceIndex = 0;
+	SplashCoord matrix[6];
+
+	m_font = NULL;
+	fileName = NULL;
+	tmpBuf = NULL;
+
+	if (!(gfxFont = state->getFont()))
+		goto err1;
+	fontType = gfxFont->getType();
+	if (fontType == fontType3)
+		goto err1;
+
+  // check the font file cache
+	id = new SplashOutFontFileID(gfxFont->getID());
+	if ((fontFile = m_fontEngine->getFontFile(id)))
+	{
+		delete id;
+	}
+	else
+	{
+		// if there is an embedded font, write it to disk
+		if (gfxFont->getEmbeddedFontID(&embRef))
+		{
+			tmpBuf = gfxFont->readEmbFontFile(xref, &tmpBufLen);
+			if (!tmpBuf)
+				goto err2;
+		// if there is an external font file, use it
+		}
+		else if (!(fileName = gfxFont->getExtFontFile()))
+		{
+	  // look for a display font mapping or a substitute font
+			dfp = NULL;
+			if (gfxFont->getName())
+			{
+				dfp = globalParams->getDisplayFont(gfxFont);
+			}
+			if (!dfp)
+			{
+		//		error(-1, "Couldn't find a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+				goto err2;
+			}
+			switch (dfp->kind)
+			{
+				case displayFontT1:
+					fileName = dfp->t1.fileName;
+					fontType = gfxFont->isCIDFont() ? fontCIDType0 : fontType1;
+					break;
+				case displayFontTT:
+					fileName = dfp->tt.fileName;
+					fontType = gfxFont->isCIDFont() ? fontCIDType2 : fontTrueType;
+					faceIndex = dfp->tt.faceIndex;
+					break;
+			}
+		}
+		fontsrc = new SplashFontSrc;
+		if (fileName)
+			fontsrc->setFile(fileName, gFalse);
+		else
+			fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue);
+	// load the font file
+		switch (fontType)
+		{
+			case fontType1:
+				if (!(fontFile = m_fontEngine->loadType1Font( id, fontsrc, ((Gfx8BitFont *)gfxFont)->getEncoding())))
+				{
+			//		error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+					goto err2;
+				}
+				break;
+			case fontType1C:
+				if (!(fontFile = m_fontEngine->loadType1CFont( id, fontsrc, ((Gfx8BitFont *)gfxFont)->getEncoding())))
+				{
+		//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+					goto err2;
+				}
+				break;
+			case fontType1COT:
+				if (!(fontFile = m_fontEngine->loadOpenTypeT1CFont( id, fontsrc, ((Gfx8BitFont *)gfxFont)->getEncoding())))
+				{
+		//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+					goto err2;
+				}
+				break;
+			case fontTrueType:
+			case fontTrueTypeOT:
+				if (fileName)
+					ff = FoFiTrueType::load(fileName->getCString());
+				else
+					ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
+				if (ff)
+				{
+					codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff);
+					n = 256;
+					delete ff;
+				}
+				else
+				{
+					codeToGID = NULL;
+					n = 0;
+				}
+				if (!(fontFile = m_fontEngine->loadTrueTypeFont( id, fontsrc, codeToGID, n)))
+				{
+	//				error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+					goto err2;
+				}
+			break;
+		case fontCIDType0:
+		case fontCIDType0C:
+			if (!(fontFile = m_fontEngine->loadCIDFont( id, fontsrc)))
+			{
+	//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+				goto err2;
+			}
+			break;
+		case fontCIDType0COT:
+			if (!(fontFile = m_fontEngine->loadOpenTypeCFFFont( id, fontsrc)))
+			{
+	//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+				goto err2;
+			}
+			break;
+		case fontCIDType2:
+		case fontCIDType2OT:
+			codeToGID = NULL;
+			n = 0;
+			if (((GfxCIDFont *)gfxFont)->getCIDToGID())
+			{
+				n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
+				if (n)
+				{
+					codeToGID = (Gushort *)gmallocn(n, sizeof(Gushort));
+					memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(), n * sizeof(Gushort));
+				}
+			}
+			else
+			{
+				if (fileName)
+					ff = FoFiTrueType::load(fileName->getCString());
+				else
+					ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
+				if (!ff)
+					goto err2;
+				codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff, &n);
+				delete ff;
+			}
+			if (!(fontFile = m_fontEngine->loadTrueTypeFont( id, fontsrc, codeToGID, n, faceIndex)))
+			{
+	//			error(-1, "Couldn't create a font for '%s'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)");
+				goto err2;
+			}
+			break;
+		default:
+	  // this shouldn't happen
+			goto err2;
+		}
+	}
+	// get the font matrix
+	textMat = state->getTextMat();
+	fontSize = state->getFontSize();
+	m11 = textMat[0] * fontSize * state->getHorizScaling();
+	m12 = textMat[1] * fontSize * state->getHorizScaling();
+	m21 = textMat[2] * fontSize;
+	m22 = textMat[3] * fontSize;
+	matrix[0] = 1;
+	matrix[1] = 0;
+	matrix[2] = 0;
+	matrix[3] = 1;
+	matrix[4] = 0;
+	matrix[5] = 0;
+  // create the scaled font
+	mat[0] = m11;
+	mat[1] = -m12;
+	mat[2] = m21;
+	mat[3] = -m22;
+	m_font = m_fontEngine->getFont(fontFile, mat, matrix);
+	if (fontsrc && !fontsrc->isFile)
+		fontsrc->unref();
+	return;
+
+err2:
+	delete id;
+err1:
+	if (fontsrc && !fontsrc->isFile)
+		fontsrc->unref();
+	return;
+}
+#endif
+
+void SlaOutputDev::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode *u, int uLen)
+{
+	double x1, y1, x2, y2;
+	int render;
+	updateFont(state);
+	if (!m_font)
+		return;
+  // check for invisible text -- this is used by Acrobat Capture
+	render = state->getRender();
+	if (render == 3)
+		return;
+	if (!(render & 1))
+	{
+		SplashPath * fontPath;
+		fontPath = m_font->getGlyphPath(code);
+		if (fontPath)
+		{
+			QPainterPath qPath;
+			qPath.setFillRule(Qt::WindingFill);
+			for (int i = 0; i < fontPath->getLength(); ++i)
+			{
+				Guchar f;
+				fontPath->getPoint(i, &x1, &y1, &f);
+				if (f & splashPathFirst)
+					qPath.moveTo(x1,y1);
+				else if (f & splashPathCurve)
+				{
+					double x3, y3;
+					++i;
+					fontPath->getPoint(i, &x2, &y2, &f);
+					++i;
+					fontPath->getPoint(i, &x3, &y3, &f);
+					qPath.cubicTo(x1,y1,x2,y2,x3,y3);
+				}
+				else
+					qPath.lineTo(x1,y1);
+				if (f & splashPathLast)
+					qPath.closeSubpath();
+			}
+			double *ctm;
+			ctm = state->getCTM();
+			m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
+			double xCoor = m_doc->currentPage()->xOffset();
+			double yCoor = m_doc->currentPage()->yOffset();
+			FPointArray textPath;
+			textPath.fromQPainterPath(qPath);
+			FPoint wh = textPath.WidthHeight();
+			if ((textPath.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)))
+			{
+				int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CurrColorFill, CommonStrings::None, true);
+				PageItem* ite = m_doc->Items->at(z);
+				QTransform mm;
+				mm.scale(1, -1);
+				mm.translate(x, -y);
+				textPath.map(mm);
+				textPath.map(m_ctm);
+				ite->PoLine = textPath.copy();
+				ite->ClipEdited = true;
+				ite->FrameType = 3;
+				ite->setFillShade(CurrFillShade);
+				ite->setFillEvenOdd(false);
+				ite->setFillTransparency(1.0 - state->getFillOpacity());
+				ite->setFillBlendmode(getBlendMode(state));
+				ite->setLineEnd(PLineEnd);
+				ite->setLineJoin(PLineJoin);
+				ite->setTextFlowMode(PageItem::TextFlowDisabled);
+				m_doc->AdjustItemSize(ite);
+				if ((render & 3) == 1 || (render & 3) == 2)
+				{
+					ite->setLineColor(CurrColorStroke);
+					ite->setLineWidth(state->getTransformedLineWidth());
+					ite->setLineTransparency(1.0 - state->getStrokeOpacity());
+					ite->setLineBlendmode(getBlendMode(state));
+					ite->setLineShade(CurrStrokeShade);
+				}
+				m_Elements->append(ite);
+				if (m_groupStack.count() != 0)
+				{
+					m_groupStack.top().Items.append(ite);
+					applyMask(ite);
+				}
+				delete fontPath;
+			}
+		}
+	}
+}
+
+GBool SlaOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
+{
+//	qDebug() << "beginType3Char";
+	GfxFont *gfxFont;
+	if (!(gfxFont = state->getFont()))
+		return gTrue;
+	if (gfxFont->getType() != fontType3)
+		return gTrue;
+	F3Entry f3e;
+	f3e.colored = false;
+	m_F3Stack.push(f3e);
+	pushGroup();
+	return gFalse;
+}
+
+void SlaOutputDev::endType3Char(GfxState *state)
+{
+//	qDebug() << "endType3Char";
+	F3Entry f3e = m_F3Stack.pop();
+	groupEntry gElements = m_groupStack.pop();
+	m_doc->m_Selection->clear();
+	if (gElements.Items.count() > 0)
+	{
+		m_doc->m_Selection->delaySignalsOn();
+		for (int dre = 0; dre < gElements.Items.count(); ++dre)
+		{
+			m_doc->m_Selection->addItem(gElements.Items.at(dre), true);
+			m_Elements->removeAll(gElements.Items.at(dre));
+		}
+		PageItem *ite;
+		if (m_doc->m_Selection->count() > 1)
+			ite = m_doc->groupObjectsSelection();
+		else
+			ite = m_doc->m_Selection->itemAt(0);
+		if (!f3e.colored)
+		{
+			m_doc->itemSelection_SetItemBrush(CurrColorFill);
+			m_doc->itemSelection_SetItemBrushShade(CurrFillShade);
+			m_doc->itemSelection_SetItemFillTransparency(1.0 - state->getFillOpacity());
+			m_doc->itemSelection_SetItemFillBlend(getBlendMode(state));
+		}
+		m_Elements->append(ite);
+		m_doc->m_Selection->clear();
+		m_doc->m_Selection->delaySignalsOff();
+	}
+}
+
+void SlaOutputDev::type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/)
+{
+//	qDebug() << "type3D0";
+	if (m_F3Stack.count() > 0)
+		m_F3Stack.top().colored = true;
+}
+
+void SlaOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
+{
+//	qDebug() << "type3D1";
+	if (m_F3Stack.count() > 0)
+		m_F3Stack.top().colored = false;
+}
+
+void SlaOutputDev::beginTextObject(GfxState *state)
+{
+	pushGroup();
+}
+
+void SlaOutputDev::endTextObject(GfxState *state)
+{
+//	qDebug() << "End Text Object";
+	if (m_groupStack.count() != 0)
+	{
+		groupEntry gElements = m_groupStack.pop();
+		tmpSel->clear();
+		if (gElements.Items.count() > 0)
+		{
+			for (int dre = 0; dre < gElements.Items.count(); ++dre)
+			{
+				tmpSel->addItem(gElements.Items.at(dre), true);
+				m_Elements->removeAll(gElements.Items.at(dre));
+			}
+			PageItem *ite;
+			if (gElements.Items.count() != 1)
+				ite = m_doc->groupObjectsSelection(tmpSel);
+			else
+				ite = gElements.Items.first();
+			ite->setFillTransparency(1.0 - state->getFillOpacity());
+			ite->setFillBlendmode(getBlendMode(state));
+			for (int as = 0; as < tmpSel->count(); ++as)
+			{
+				m_Elements->append(tmpSel->itemAt(as));
+			}
+			if (m_groupStack.count() != 0)
+				applyMask(ite);
+		}
+		if (m_groupStack.count() != 0)
+		{
+			for (int as = 0; as < tmpSel->count(); ++as)
+			{
+				m_groupStack.top().Items.append(tmpSel->itemAt(as));
+			}
+		}
+		tmpSel->clear();
+	}
+}
+
+QString SlaOutputDev::getColor(GfxColorSpace *color_space, GfxColor *color, int *shade)
+{
+	QString fNam;
+	QString namPrefix = "FromPDF";
+	ScColor tmp;
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	*shade = 100;
+	if (m_F3Stack.count() > 0)
+	{
+		if (!m_F3Stack.top().colored)
+			return "Black";
+	}
+	if ((color_space->getMode() == csDeviceRGB) || (color_space->getMode() == csCalRGB))
+	{
+		GfxRGB rgb;
+		color_space->getRGB(color, &rgb);
+		int Rc = qRound(colToDbl(rgb.r) * 255);
+		int Gc = qRound(colToDbl(rgb.g) * 255);
+		int Bc = qRound(colToDbl(rgb.b) * 255);
+		tmp.setColorRGB(Rc, Gc, Bc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if (color_space->getMode() == csDeviceCMYK)
+	{
+		GfxCMYK cmyk;
+		color_space->getCMYK(color, &cmyk);
+		int Cc = qRound(colToDbl(cmyk.c) * 255);
+		int Mc = qRound(colToDbl(cmyk.m) * 255);
+		int Yc = qRound(colToDbl(cmyk.y) * 255);
+		int Kc = qRound(colToDbl(cmyk.k) * 255);
+		tmp.setColor(Cc, Mc, Yc, Kc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if ((color_space->getMode() == csCalGray) || (color_space->getMode() == csDeviceGray))
+	{
+		GfxGray gray;
+		color_space->getGray(color, &gray);
+		int Kc = 255 - qRound(colToDbl(gray) * 255);
+		tmp.setColor(0, 0, 0, Kc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if (color_space->getMode() == csSeparation)
+	{
+		GfxCMYK cmyk;
+		color_space->getCMYK(color, &cmyk);
+		int Cc = qRound(colToDbl(cmyk.c) * 255);
+		int Mc = qRound(colToDbl(cmyk.m) * 255);
+		int Yc = qRound(colToDbl(cmyk.y) * 255);
+		int Kc = qRound(colToDbl(cmyk.k) * 255);
+		tmp.setColor(Cc, Mc, Yc, Kc);
+		tmp.setSpotColor(true);
+		QString nam = QString(((GfxSeparationColorSpace*)color_space)->getName()->getCString());
+		fNam = m_doc->PageColors.tryAddColor(nam, tmp);
+		*shade = qRound(colToDbl(color->c[0]) * 100);
+	}
+	else
+	{
+		GfxRGB rgb;
+		color_space->getRGB(color, &rgb);
+		int Rc = qRound(colToDbl(rgb.r) * 255);
+		int Gc = qRound(colToDbl(rgb.g) * 255);
+		int Bc = qRound(colToDbl(rgb.b) * 255);
+		tmp.setColorRGB(Rc, Gc, Bc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	//	qDebug() << "update fill color other colorspace" << color_space->getMode() << "treating as rgb" << Rc << Gc << Bc;
+	}
+	if (fNam == namPrefix+tmp.name())
+		m_importedColors->append(fNam);
+	return fNam;
+}
+
+QString SlaOutputDev::getAnnotationColor(AnnotColor *color)
+{
+	QString fNam;
+	QString namPrefix = "FromPDF";
+	ScColor tmp;
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	if (color->getSpace() == AnnotColor::colorTransparent)
+		return CommonStrings::None;
+	else if (color->getSpace() == AnnotColor::colorRGB)
+	{
+		const double *color_data = color->getValues();
+		int Rc = qRound(color_data[0] * 255);
+		int Gc = qRound(color_data[1] * 255);
+		int Bc = qRound(color_data[2] * 255);
+		tmp.setColorRGB(Rc, Gc, Bc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if (color->getSpace() == AnnotColor::colorCMYK)
+	{
+		const double *color_data = color->getValues();
+		int Cc = qRound(color_data[0] * 255);
+		int Mc = qRound(color_data[1] * 255);
+		int Yc = qRound(color_data[2] * 255);
+		int Kc = qRound(color_data[3] * 255);
+		tmp.setColor(Cc, Mc, Yc, Kc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	else if (color->getSpace() == AnnotColor::colorGray)
+	{
+		const double *color_data = color->getValues();
+		int Kc = 255 - qRound(color_data[0] * 255);
+		tmp.setColor(0, 0, 0, Kc);
+		fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	}
+	if (fNam == namPrefix+tmp.name())
+		m_importedColors->append(fNam);
+	return fNam;
+}
+
+QString SlaOutputDev::convertPath(GfxPath *path)
+{
+    if (! path)
+		return QString();
+
+    QString output;
+	pathIsClosed = false;
+
+	for (int i = 0; i < path->getNumSubpaths(); ++i)
+	{
+        GfxSubpath * subpath = path->getSubpath(i);
+		if (subpath->getNumPoints() > 0)
+		{
+			output += QString("M %1 %2").arg(subpath->getX(0)).arg(subpath->getY(0));
+            int j = 1;
+			while (j < subpath->getNumPoints())
+			{
+				if (subpath->getCurve(j))
+				{
+					output += QString("C %1 %2 %3 %4 %5 %6")
+                              .arg(subpath->getX(j)).arg(subpath->getY(j))
+                              .arg(subpath->getX(j + 1)).arg(subpath->getY(j + 1))
+                              .arg(subpath->getX(j + 2)).arg(subpath->getY(j + 2));
+                    j += 3;
+				}
+				else
+				{
+					output += QString("L %1 %2").arg(subpath->getX(j)).arg(subpath->getY(j));
+                    ++j;
+                }
+            }
+			if (subpath->isClosed())
+			{
+                output += QString("Z");
+				pathIsClosed = true;
+            }
+        }
+	}
+	return output;
+}
+
+void SlaOutputDev::getPenState(GfxState *state)
+{
+	switch (state->getLineCap())
+	{
+		case 0:
+			PLineEnd = Qt::FlatCap;
+			break;
+		case 1:
+			PLineEnd = Qt::RoundCap;
+			break;
+		case 2:
+			PLineEnd = Qt::SquareCap;
+			break;
+	}
+	switch (state->getLineJoin())
+	{
+		case 0:
+			PLineJoin = Qt::MiterJoin;
+			break;
+		case 1:
+			PLineJoin = Qt::RoundJoin;
+			break;
+		case 2:
+			PLineJoin = Qt::BevelJoin;
+			break;
+	}
+	double lw = state->getLineWidth();
+	double *dashPattern;
+	int dashLength;
+	state->getLineDash(&dashPattern, &dashLength, &DashOffset);
+	QVector<double> pattern(dashLength);
+	for (int i = 0; i < dashLength; ++i)
+	{
+		pattern[i] = dashPattern[i] / lw;
+	}
+	DashValues = pattern;
+}
+
+int SlaOutputDev::getBlendMode(GfxState *state)
+{
+	int mode = 0;
+	switch (state->getBlendMode())
+	{
+		default:
+		case gfxBlendNormal:
+			mode = 0;
+			break;
+		case gfxBlendDarken:
+			mode = 1;
+			break;
+		case gfxBlendLighten:
+			mode = 2;
+			break;
+		case gfxBlendMultiply:
+			mode = 3;
+			break;
+		case gfxBlendScreen:
+			mode = 4;
+			break;
+		case gfxBlendOverlay:
+			mode = 5;
+			break;
+		case gfxBlendHardLight:
+			mode = 6;
+			break;
+		case gfxBlendSoftLight:
+			mode = 7;
+			break;
+		case gfxBlendDifference:
+			mode = 8;
+			break;
+		case gfxBlendExclusion:
+			mode = 9;
+			break;
+		case gfxBlendColorDodge:
+			mode = 10;
+			break;
+		case gfxBlendColorBurn:
+			mode = 11;
+			break;
+		case gfxBlendHue:
+			mode = 12;
+			break;
+		case gfxBlendSaturation:
+			mode = 13;
+			break;
+		case gfxBlendColor:
+			mode = 14;
+			break;
+		case gfxBlendLuminosity:
+			mode = 15;
+			break;
+	}
+	return mode;
+}
+
+void SlaOutputDev::applyMask(PageItem *ite)
+{
+	if (m_groupStack.count() != 0)
+	{
+		if (!m_groupStack.top().maskName.isEmpty())
+		{
+			ite->setPatternMask(m_groupStack.top().maskName);
+			if (m_groupStack.top().alpha)
+			{
+				if (m_groupStack.top().inverted)
+					ite->setMaskType(8);
+				else
+					ite->setMaskType(3);
+			}
+			else
+			{
+				if (m_groupStack.top().inverted)
+					ite->setMaskType(7);
+				else
+					ite->setMaskType(6);
+			}
+		}
+	}
+	// Code for updating our Progressbar, needs to be called this way, as we have no
+	// possibility to get the current fileposition.
+	updateGUICounter++;
+	if (updateGUICounter > 20)
+	{
+		qApp->processEvents();
+		updateGUICounter = 0;
+	}
+}
+
+void SlaOutputDev::pushGroup(QString maskName, GBool forSoftMask, GBool alpha, bool inverted)
+{
+	groupEntry gElements;
+	gElements.forSoftMask = forSoftMask;
+	gElements.alpha = alpha;
+	gElements.inverted = inverted;
+	gElements.maskName = maskName;
+	m_groupStack.push(gElements);
+}
+
+QString SlaOutputDev::UnicodeParsedString(GooString *s1)
+{
+	if ( !s1 || s1->getLength() == 0 )
+		return QString();
+	GBool isUnicode;
+	int i;
+	Unicode u;
+	QString result;
+	if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getLength() > 1 && (s1->getChar(1) & 0xff) == 0xff))
+	{
+		isUnicode = gTrue;
+		i = 2;
+		result.reserve((s1->getLength() - 2) / 2);
+	}
+	else
+	{
+		isUnicode = gFalse;
+		i = 0;
+		result.reserve(s1->getLength());
+	}
+	while (i < s1->getLength())
+	{
+		if (isUnicode)
+		{
+			u = ((s1->getChar(i) & 0xff) << 8) | (s1->getChar(i+1) & 0xff);
+			i += 2;
+		}
+		else
+		{
+			u = s1->getChar(i) & 0xff;
+			++i;
+		}
+		result += QChar( u );
+	}
+	return result;
+}

Modified: trunk/Scribus/scribus/plugins/import/shape/importshape.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/import/shape/importshape.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/shape/importshape.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/shape/importshape.cpp Fri Oct 17 22:07:00 2014
@@ -666,8 +666,6 @@
 {
 	QString FillCol = "White";
 	QString StrokeCol = "Black";
-	QColor stroke = Qt::black;
-	QColor fill = Qt::white;
 	while(!DOC.isNull())
 	{
 		double x1, y1, x2, y2;

Modified: trunk/Scribus/scribus/plugins/picbrowser/iview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/plugins/picbrowser/iview.h
==============================================================================
--- trunk/Scribus/scribus/plugins/picbrowser/iview.h (original)
+++ trunk/Scribus/scribus/plugins/picbrowser/iview.h Fri Oct 17 22:07:00 2014
@@ -1,56 +1,55 @@
-//
-// C++ Interface: iview
-//
-// Description:
-//
-//
-// Author: Pierre Marchand <pierremarc at oep-h.com>, (C) 2009
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#ifndef IVIEW_H
-#define IVIEW_H
-
-#include <QGraphicsView>
-#include <QGraphicsPixmapItem>
-#include <QGraphicsPolygonItem>
-#include <QRect>
-#include <QPixmap>
-
-class IView: public QGraphicsView
-{
-	public:
-		IView ( QWidget* parent );
-		~IView();
-
-		void setImage ( const QPixmap& pixmap );
-		QPixmap getPixmap();
-
-		void fitImage();
-		void setKeepFitted ( bool theValue ) { m_keepFitted = theValue; }
-
-		void setZoom(double xz, double yz = 0);
-		double getZoom() const;
-
-	protected:
-		void mouseMoveEvent ( QMouseEvent * e );
-		void mousePressEvent ( QMouseEvent * e );
-		void mouseReleaseEvent ( QMouseEvent * e );
-		void resizeEvent ( QResizeEvent * event );
-
-	private:
-		QGraphicsPixmapItem * curImage;
-
-		QPointF mouseStartPoint;
-		QRect theRect;
-		bool isSelecting;
-		bool isPanning;
-
-		bool m_keepFitted;
-
-
-};
-
-#endif
+//
+// C++ Interface: iview
+//
+// Description:
+//
+//
+// Author: Pierre Marchand <pierremarc at oep-h.com>, (C) 2009
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef IVIEW_H
+#define IVIEW_H
+
+#include <QGraphicsView>
+#include <QGraphicsPixmapItem>
+#include <QGraphicsPolygonItem>
+#include <QRect>
+#include <QPixmap>
+
+class IView: public QGraphicsView
+{
+	public:
+		IView ( QWidget* parent );
+		~IView();
+
+		void setImage ( const QPixmap& pixmap );
+		QPixmap getPixmap();
+
+		void fitImage();
+		void setKeepFitted ( bool theValue ) { m_keepFitted = theValue; }
+
+		void setZoom(double xz, double yz = 0);
+		double getZoom() const;
+
+	protected:
+		void mouseMoveEvent ( QMouseEvent * e );
+		void mousePressEvent ( QMouseEvent * e );
+		void mouseReleaseEvent ( QMouseEvent * e );
+		void resizeEvent ( QResizeEvent * event );
+
+	private:
+		QGraphicsPixmapItem * curImage;
+
+		QPointF mouseStartPoint;
+		QRect theRect;
+		bool isPanning;
+
+		bool m_keepFitted;
+
+
+};
+
+#endif

Modified: trunk/Scribus/scribus/scimgdataloader_pict.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/scimgdataloader_pict.cpp
==============================================================================
--- trunk/Scribus/scribus/scimgdataloader_pict.cpp (original)
+++ trunk/Scribus/scribus/scimgdataloader_pict.cpp Fri Oct 17 22:07:00 2014
@@ -1,1768 +1,1769 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <QByteArray>
-#include <QCursor>
-#include <QDrag>
-#include <QFile>
-#include <QList>
-#include <QMimeData>
-#include <QRegExp>
-#include <QTextCodec>
-#include <QStack>
-#include <QDebug>
-
-#include <cstdlib>
-
-#include "scimgdataloader_pict.h"
-#include "ui/customfdialog.h"
-#include "ui/missing.h"
-#include "pagesize.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "prefstable.h"
-#include "ui/propertiespalette.h"
-#include "scclocale.h"
-#include "sccolorengine.h"
-#include "scconfig.h"
-#include "scmimedata.h"
-#include "scpaths.h"
-
-#include "scribusXml.h"
-#include "scribuscore.h"
-#include "sctextstream.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "util.h"
-#include "util_formats.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-ScImgDataLoader_PICT::ScImgDataLoader_PICT(void) : ScImgDataLoader()
-{
-	initSupportedFormatList();
-}
-
-void ScImgDataLoader_PICT::initSupportedFormatList(void)
-{
-	m_supportedFormats.clear();
-	m_supportedFormats.append( "pct" );
-	m_supportedFormats.append( "pic" );
-	m_supportedFormats.append( "pict" );
-}
-
-bool ScImgDataLoader_PICT::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)
-{
-	initialize();
-	hasAlpha = false;
-	return true;
-}
-
-void ScImgDataLoader_PICT::loadEmbeddedProfile(const QString& fn, int /*page*/)
-{
-	m_embeddedProfile.resize(0);
-	m_profileComponents = 0;
-}
-
-void ScImgDataLoader_PICT::parseHeader(QString fName, double &x, double &y, double &w, double &h)
-{
-	QFile f(fName);
-	if (f.open(QIODevice::ReadOnly))
-	{
-		QDataStream ts(&f);
-		ts.setByteOrder(QDataStream::BigEndian);
-		ts.device()->seek(512);
-		qint16 pgX, pgY, pgW, pgH, dummy;
-		ts >> dummy >> pgX >> pgY >> pgW >> pgH;
-		quint16 vers, vers2, vers3;
-		ts >> vers;
-		if (vers == 0x1101)
-		{
-			pctVersion = 1;
-			h = pgW - pgX;
-			w = pgH - pgY;
-			x = pgY;
-			y = pgX;
-			resX = 72.0;
-			resY = 72.0;
-		}
-		else if (vers == 0x0011)
-		{
-			ts >> vers2 >> vers3;
-			if ((vers2 == 0x02FF) && (vers3 == 0x0C00))
-			{
-				pctVersion = 2;
-				qint16 vExt;
-				ts >> vExt;
-				if (vExt == -1)
-				{
-					ts >> dummy;
-					quint32 xres, yres;
-					xres = 72;
-					yres = 72;
-					qint32 pgX2, pgY2, pgW2, pgH2;
-					ts >> pgX2 >> pgY2 >> pgW2 >> pgH2;
-					ts >> dummy;
-					ts >> dummy;
-					resX = 72.0;
-					resY = 72.0;
-					h = pgW - pgX;
-					w = pgH - pgY;
-					x = pgY;
-					y = pgX;
-				}
-				else if (vExt == -2)
-				{
-					ts >> dummy;
-					quint16 xres, yres;
-					ts >> xres >> dummy >> yres >> dummy;
-					ts >> pgX >> pgY >> pgW >> pgH;
-					ts >> dummy;
-					h = pgW - pgX;
-					w = pgH - pgY;
-					x = pgY;
-					y = pgX;
-					resX = xres;
-					resY = yres;
-				}
-			}
-		}
-		f.close();
-	}
-}
-
-bool ScImgDataLoader_PICT::loadPicture(const QString& fn, int /*page*/, int /*res*/, bool /*thumbnail*/)
-{
-	if (!QFile::exists(fn))
-		return false;
-	initialize();
-	double x=0.0, y=0.0, w=0.0, h=0.0;
-	parseHeader(fn, x, y, w, h);
-	docWidth = w;
-	docHeight = h;
-	baseX = -x;
-	baseY = -y;
-	QFile f(fn);
-	if (f.open(QIODevice::ReadOnly))
-	{
-		QDataStream ts(&f);
-		ts.device()->seek(522);
-		m_image = QImage(docWidth, docHeight, QImage::Format_ARGB32);
-		if (m_image.isNull())
-			return false;
-		m_image.fill(qRgba(255, 255, 255, 255));
-		imagePainter.begin(&m_image);
-		imagePainter.setRenderHint(QPainter::Antialiasing , true);
-		imagePainter.translate(baseX, baseY);
-		patternMode = false;
-		patternData.resize(0);
-		backColor = Qt::white;
-		foreColor = Qt::black;
-		Coords = QPainterPath();
-		LineW = 1.0;
-		currentPoint = QPoint(0, 0);
-		currentPointT = QPoint(0, 0);
-		ovalSize = QPoint(0, 0);
-		fontMap.clear();
-		currentTextSize = 12;
-		currentFontID = 0;
-		currentFontStyle = 0;
-		imageData.resize(0);
-		skipOpcode = false;
-		postscriptMode = false;
-		textIsPostScript = false;
-		quint16 vers = 0;
-		ts >> vers;
-		while (vers == 0)
-		{
-			ts >> vers;
-			if (vers == 0x00FF)
-			{
-				f.close();
-				return false;
-			}
-		}
-		if (vers == 0x1101)
-		{
-			pctVersion = 1;		// Pict Version 1
-			parsePict(ts);
-		}
-		else
-		{
-			ts.skipRawData(4);	// skip the next 4 Bytes
-			ts >> vers;		// read the version info
-			pctVersion = 2;	// Pict Extended Version 2
-			ts.skipRawData(22);
-			parsePict(ts);
-		}
-		imagePainter.end();
-		m_imageInfoRecord.type = ImageTypeOther;
-		m_imageInfoRecord.exifDataValid = false;
-		m_imageInfoRecord.xres = resX;
-		m_imageInfoRecord.yres = resY;
-		m_imageInfoRecord.BBoxX = 0;
-		m_imageInfoRecord.colorspace = ColorSpaceRGB;
-		m_imageInfoRecord.BBoxH = m_image.height();
-		m_pixelFormat = Format_BGRA_8;
-		f.close();
-		return true;
-	}
-	return true;
-}
-
-void ScImgDataLoader_PICT::parsePict(QDataStream &ts)
-{
-	while (!ts.atEnd())
-	{
-		quint16 opCode, dataLen;
-		quint8 dataLenByte;
-		quint32 dataLenLong;
-		if (pctVersion == 1)
-		{
-			ts >> dataLenByte;
-			opCode = dataLenByte;
-		}
-		else
-			ts >> opCode;
-		if (((opCode >= 0x0092) && (opCode <= 0x0097)) || ((opCode >= 0x009C) && (opCode <= 0x009F)) || ((opCode >= 0x00A2) && (opCode <= 0x00AF)))
-		{
-			// Reserved by Apple
-//			qDebug() << "Reserved by Apple";
-			ts >> dataLen;
-			alignStreamToWord(ts, dataLen);
-		}
-		else if (((opCode >= 0x00B0) && (opCode <= 0x00CF)) || ((opCode >= 0x8000) && (opCode <= 0x80FF)))
-		{
-			// Reserved by Apple
-//			qDebug() << "Reserved by Apple";
-		}
-		else if (((opCode >= 0x00D0) && (opCode <= 0x00FE)) || ((opCode >= 0x8100) && (opCode <= 0x81FF)))
-		{
-			// Reserved by Apple
-//			qDebug() << "Reserved by Apple";
-			ts >> dataLenLong;
-			alignStreamToWord(ts, dataLenLong);
-		}
-		else if (((opCode >= 0x0100) && (opCode <= 0x01FF)) || ((opCode >= 0x02FF) && (opCode <= 0x0BFE)))
-		{
-			// Reserved by Apple
-//			qDebug() << "Reserved by Apple";
-			alignStreamToWord(ts, 2);
-		}
-		else if ((opCode >= 0x0C00) && (opCode <= 0x7EFF))
-		{
-			// Reserved by Apple
-//			qDebug() << "Reserved by Apple";
-			alignStreamToWord(ts, 24);
-		}
-		else if ((opCode >= 0x7F00) && (opCode <= 0x7FFF))
-		{
-			// Reserved by Apple
-//			qDebug() << "Reserved by Apple";
-			alignStreamToWord(ts, 254);
-		}
-		else
-		{
-			switch (opCode)
-			{
-				case 0x0000:		// NOP
-//					qDebug() << "NOP";
-					break;
-				case 0x0001:		// Clipping Region
-//					qDebug() << "Clipping Region";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0002:		// Background Pattern
-//					qDebug() << "Background Pattern";
-					alignStreamToWord(ts, 8);
-					break;
-				case 0x0003:		// Text Font
-					handleTextFont(ts);
-					break;
-				case 0x0004:		// Text Style
-					handleTextStyle(ts);
-					break;
-				case 0x0005:		// Text Mode
-					handleTextMode(ts);
-					break;
-				case 0x0006:		// Extra Space
-//					qDebug() << "Extra Space";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x0007:		// Pen Size
-					handlePenSize(ts);
-					break;
-				case 0x0008:		// Pen Mode
-					handlePenMode(ts);
-					break;
-				case 0x0009:		// Pen Pattern
-					handlePenPattern(ts);
-					break;
-				case 0x000A:		// Fill Pattern
-//					qDebug() << "Fill Pattern";
-					alignStreamToWord(ts, 8);
-					break;
-				case 0x000B:		// Oval Size
-					handleOvalSize(ts);
-					break;
-				case 0x000C:		// Origin
-//					qDebug() << "Origin";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x000D:		// Text Size
-					handleTextSize(ts);
-					break;
-				case 0x000E:		// Foreground Color
-					handleColor(ts, false);
-					break;
-				case 0x000F:		// Background Color
-					handleColor(ts, true);
-					break;
-				case 0x0010:		// Text Ratio
-//					qDebug() << "Text Ratio";
-					alignStreamToWord(ts, 8);
-					break;
-				case 0x0011:		// Version
-//					qDebug() << "Version";
-					alignStreamToWord(ts, 1);
-					break;
-				case 0x0015:		// Fractional pen position
-//					qDebug() << "Fractional pen position at" << ts.device()->pos();
-					alignStreamToWord(ts, 2);
-					break;
-				case 0x0016:		// Extra char space
-//					qDebug() << "Extra char space";
-					alignStreamToWord(ts, 2);
-					break;
-				case 0x0017:
-				case 0x0018:
-				case 0x0019:
-//					qDebug() << "Reserved by Apple";
-					break;
-				case 0x001A:		// Foreground color RGB
-					handleColorRGB(ts, false);
-					break;
-				case 0x001B:		// Background color RGB
-					handleColorRGB(ts, true);
-					break;
-				case 0x001C:		// Highlight mode
-//					qDebug() << "Highlight mode";
-					break;
-				case 0x001D:		// Highlight color RGB
-//					qDebug() << "Highlight color RGB";
-					alignStreamToWord(ts, 6);
-					break;
-				case 0x001E:		// Use default highlight color
-//					qDebug() << "Use default highlight color";
-					break;
-				case 0x0020:		// Line
-					handleLine(ts);
-					break;
-				case 0x0021:		// Line To
-					handleLineFrom(ts);
-					break;
-				case 0x0022:		// Short Line
-					handleShortLine(ts);
-					break;
-				case 0x0023:		// Short Line To
-					handleShortLineFrom(ts);
-					break;
-				case 0x0024:
-				case 0x0025:
-				case 0x0026:
-				case 0x0027:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen);
-					break;
-				case 0x0028:		// Long Text
-					handleLongText(ts);
-					break;
-				case 0x0029:		// Text DH
-					handleDHText(ts);
-					break;
-				case 0x002A:		// Text DV
-					handleDVText(ts);
-					break;
-				case 0x002B:		// Text DHV
-					handleDHVText(ts);
-					break;
-				case 0x002C:		// Font Name
-					handleFontName(ts);
-					break;
-				case 0x002D:		// Line justify
-//					qDebug() << "Line justify";
-					alignStreamToWord(ts, 10);
-					break;
-				case 0x002E:		// Glyph state
-//					qDebug() << "Glyph state";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen);
-					break;
-				case 0x002F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen);
-					break;
-				case 0x0030:		// Frame rect
-				case 0x0031:		// Paint rect
-				case 0x0032:		// Erase rect
-				case 0x0033:		// Invert rect
-				case 0x0034:		// Fill rect
-					handleShape(ts, opCode);
-					break;
-				case 0x0035:
-				case 0x0036:
-				case 0x0037:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					alignStreamToWord(ts, 8);
-					break;
-				case 0x0038:		// Frame same rect
-				case 0x0039:		// Paint same rect
-				case 0x003A:		// Erase same rect
-				case 0x003B:		// Invert same rect
-				case 0x003C:		// Fill same rect
-					handleSameShape(ts, opCode);
-					break;
-				case 0x003D:
-				case 0x003E:
-				case 0x003F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					break;
-				case 0x0040:		// Frame round rect
-				case 0x0041:		// Paint round rect
-				case 0x0042:		// Erase round rect
-				case 0x0043:		// Invert round rect
-				case 0x0044:		// Fill round rect
-					handleShape(ts, opCode);
-					break;
-				case 0x0045:
-				case 0x0046:
-				case 0x0047:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					alignStreamToWord(ts, 8);
-					break;
-				case 0x0048:		// Frame same round rect
-				case 0x0049:		// Paint same round rect
-				case 0x004A:		// Erase same round rect
-				case 0x004B:		// Invert same round rect
-				case 0x004C:		// Fill same round rect
-					handleSameShape(ts, opCode);
-					break;
-				case 0x004D:
-				case 0x004E:
-				case 0x004F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					break;
-				case 0x0050:		// Frame oval
-				case 0x0051:		// Paint oval
-				case 0x0052:		// Erase oval
-				case 0x0053:		// Invert oval
-				case 0x0054:		// Fill oval
-					handleShape(ts, opCode);
-					break;
-				case 0x0055:
-				case 0x0056:
-				case 0x0057:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					alignStreamToWord(ts, 8);
-					break;
-				case 0x0058:		// Frame same oval
-				case 0x0059:		// Paint same oval
-				case 0x005A:		// Erase same oval
-				case 0x005B:		// Invert same oval
-				case 0x005C:		// Fill same oval
-					handleSameShape(ts, opCode);
-					break;
-				case 0x005D:
-				case 0x005E:
-				case 0x005F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					break;
-				case 0x0060:		// Frame arc
-//					qDebug() << "Frame arc";
-					alignStreamToWord(ts, 12);
-					break;
-				case 0x0061:		// Paint arc
-//					qDebug() << "Paint arc";
-					alignStreamToWord(ts, 12);
-					break;
-				case 0x0062:		// Erase arc
-//					qDebug() << "Erase arc";
-					alignStreamToWord(ts, 12);
-					break;
-				case 0x0063:		// Invert arc
-//					qDebug() << "Invert arc";
-					alignStreamToWord(ts, 12);
-					break;
-				case 0x0064:		// Fill arc
-//					qDebug() << "Fill arc";
-					alignStreamToWord(ts, 12);
-					break;
-				case 0x0065:
-				case 0x0066:
-				case 0x0067:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					alignStreamToWord(ts, 12);
-					break;
-				case 0x0068:		// Frame same arc
-//					qDebug() << "Frame same arc";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x0069:		// Paint same arc
-//					qDebug() << "Paint same arc";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x006A:		// Erase same arc
-//					qDebug() << "Erase same arc";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x006B:		// Invert same arc
-//					qDebug() << "Invert same arc";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x006C:		// Fill same arc
-//					qDebug() << "Fill same arc";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x006D:
-				case 0x006E:
-				case 0x006F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x0070:		// Frame poly
-				case 0x0071:		// Paint poly
-				case 0x0072:		// Erase poly
-				case 0x0073:		// Invert poly
-				case 0x0074:		// Fill poly
-					handlePolygon(ts, opCode);
-					break;
-				case 0x0075:
-				case 0x0076:
-				case 0x0077:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0078:		// Frame same poly
-//					qDebug() << "Frame same poly";
-					break;
-				case 0x0079:		// Paint same poly
-//					qDebug() << "Paint same poly";
-					break;
-				case 0x007A:		// Erase same poly
-//					qDebug() << "Erase same poly";
-					break;
-				case 0x007B:		// Invert same poly
-//					qDebug() << "Invert same poly";
-					break;
-				case 0x007C:		// Fill same poly
-//					qDebug() << "Fill same poly";
-					break;
-				case 0x007D:
-				case 0x007E:
-				case 0x007F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					break;
-				case 0x0080:		// Frame region
-//					qDebug() << "Frame region";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0081:		// Paint region
-//					qDebug() << "Paint region";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0082:		// Erase region
-//					qDebug() << "Erase region";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0083:		// Invert region
-//					qDebug() << "Invert region";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0084:		// Fill region
-//					qDebug() << "Fill region";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0085:
-				case 0x0086:
-				case 0x0087:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					ts >> dataLen;
-					alignStreamToWord(ts, dataLen-2);
-					break;
-				case 0x0088:		// Frame same region
-//					qDebug() << "Frame same region";
-					break;
-				case 0x0089:		// Paint same region
-//					qDebug() << "Paint same region";
-					break;
-				case 0x008A:		// Erase same region
-//					qDebug() << "Erase same region";
-					break;
-				case 0x008B:		// Invert same region
-//					qDebug() << "Invert same region";
-					break;
-				case 0x008C:		// Fill same region
-//					qDebug() << "Fill same region";
-					break;
-				case 0x008D:
-				case 0x008E:
-				case 0x008F:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					break;
-				case 0x0090:		// Bits Rect
-//					qDebug() << "Bits Rect";
-					handlePixmap(ts, opCode);
-					break;
-				case 0x0091:		// Bits Region
-//					qDebug() << "Bits Region";
-					handlePixmap(ts, opCode);
-					break;
-				case 0x0098:		// Pack Bits Rect
-//					qDebug() << "Pack Bits Rect";
-					handlePixmap(ts, opCode);
-					break;
-				case 0x0099:		// Pack Bits Region
-//					qDebug() << "Pack Bits Region";
-					handlePixmap(ts, opCode);
-					break;
-				case 0x009A:		// Direct Bits Rect
-//					qDebug() << "Direct Bits Rect";
-					handlePixmap(ts, opCode);
-					break;
-				case 0x009B:		// Direct Bits Region
-//					qDebug() << "Direct Bits Region";
-					handlePixmap(ts, opCode);
-					break;
-				case 0x00A0:		// Short Comment
-					handleComment(ts, false);
-					break;
-				case 0x00A1:		// Long Comment
-					handleComment(ts, true);
-					break;
-				case 0x00FF:		// End of Pict
-					if (imageData.size() > 0)
-					{
-						QImage image;
-						image.loadFromData(imageData);
-						image = image.convertToFormat(QImage::Format_ARGB32);
-						imagePainter.drawImage(0, 0, image);
-					}
-//					qDebug() << "End of Pict";
-					return;
-					break;
-				case 0x0200:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					alignStreamToWord(ts, 4);
-					break;
-				case 0x8200:		// Compressed QuickTime
-				case 0x8201:		// Uncompressed QuickTime
-					handleQuickTime(ts, opCode);
-					break;
-				case 0xFFFF:		// Reserved by Apple
-//					qDebug() << "Reserved by Apple";
-					ts >> dataLenLong;
-					alignStreamToWord(ts, dataLenLong);
-					break;
-				default:
-//					qDebug() << QString("Not implemented OpCode: 0x%1 at %3").arg(opCode, 4, 16, QLatin1Char('0')).arg(ts.device()->pos()-2);
-					return;
-					break;
-			}
-		}
-	}
-}
-
-void ScImgDataLoader_PICT::alignStreamToWord(QDataStream &ts, uint len)
-{
-	ts.skipRawData(len);
-	if (pctVersion == 1)
-		return;
-	uint adj = ts.device()->pos() % 2;
-	if (adj != 0)
-		ts.skipRawData(1);
-}
-
-void ScImgDataLoader_PICT::handleColor(QDataStream &ts, bool back)
-{
-	quint16 Rc, Gc, Bc;
-	quint32 colVal;
-	ts >> colVal;
-//	qDebug() << "Color" << colVal << back;
-	switch (colVal)
-	{
-		case 30:
-			Rc = 0xFFFF;
-			Gc = 0xFFFF;
-			Bc = 0xFFFF;
-			break;
-		case 33:
-			Rc = 0x0000;
-			Gc = 0x0000;
-			Bc = 0x0000;
-			break;
-		case 69:
-			Rc = 0xFC00;
-			Gc = 0xF37D;
-			Bc = 0x052F;
-			break;
-		case 137:
-			Rc = 0xF2D7;
-			Gc = 0x0856;
-			Bc = 0x84EC;
-			break;
-		case 205:
-			Rc = 0xDD6B;
-			Gc = 0x08C2;
-			Bc = 0x06A2;
-			break;
-		case 273:
-			Rc = 0x0241;
-			Gc = 0xAB54;
-			Bc = 0xEAFF;
-			break;
-		case 341:
-			Rc = 0x0000;
-			Gc = 0x64AF;
-			Bc = 0x11B0;
-			break;
-		case 409:
-			Rc = 0x0000;
-			Gc = 0x0000;
-			Bc = 0xD400;
-			break;
-		default:
-			Rc = 0x0000;
-			Gc = 0x0000;
-			Bc = 0x0000;
-			break;
-	}
-	int redC, greenC, blueC;
-	redC = qRound((Rc / 65535.0) * 255.0);
-	greenC = qRound((Gc / 65535.0) * 255.0);
-	blueC = qRound((Bc / 65535.0) * 255.0);
-	QColor c = QColor(redC, greenC, blueC);
-	if (back)
-		backColor = c;
-	else
-		foreColor = c;
-}
-
-void ScImgDataLoader_PICT::handleColorRGB(QDataStream &ts, bool back)
-{
-	quint16 Rc, Gc, Bc;
-	int redC, greenC, blueC;
-	ts >> Rc >> Gc >> Bc;
-	redC = qRound((Rc / 65535.0) * 255.0);
-	greenC = qRound((Gc / 65535.0) * 255.0);
-	blueC = qRound((Bc / 65535.0) * 255.0);
-	QColor c = QColor(redC, greenC, blueC);
-	if (back)
-		backColor = c;
-	else
-		foreColor = c;
-}
-
-void ScImgDataLoader_PICT::handlePenPattern(QDataStream &ts)
-{
-	patternData.resize(8);
-	ts.readRawData(patternData.data(), 8);
-	patternMode = false;
-	for (int a = 0; a < patternData.size(); a++)
-	{
-		uchar d = patternData[a];
-		if ((d != 0x00) && (d != 0xFF))
-		{
-			patternMode = true;
-			break;
-		}
-	}
-}
-
-void ScImgDataLoader_PICT::handlePolygon(QDataStream &ts, quint16 opCode)
-{
-//	qDebug() << "Handle Polygon";
-	quint16 polySize;
-	ts >> polySize;				// read polygon size
-	ts.skipRawData(8);			// skip bounding rect;
-	polySize -= 14;				// subtract size count, bounding rect and first point from size
-	qint16 x, y;
-	ts >> y >> x;
-	Coords = QPainterPath();
-	Coords.moveTo(x, y);
-	QBrush fillBrush;
-	if (patternMode)
-		fillBrush = setFillPattern();
-	else
-		fillBrush = QBrush(foreColor);
-	for(unsigned i = 0; i < polySize; i += 4)
-	{
-		ts >> y >> x;
-		Coords.lineTo(x, y);
-	}
-	if (opCode == 0x0070)
-		imagePainter.strokePath(Coords, QPen(foreColor, LineW));
-	else if (opCode == 0x0071)
-		imagePainter.fillPath(Coords, fillBrush);
-	else if (opCode == 0x0072)
-		imagePainter.fillPath(Coords, QBrush(backColor));
-	else if (opCode == 0x0074)
-		imagePainter.fillPath(Coords, fillBrush);
-	else
-	{
-//		qDebug() << QString("Not implemented OpCode: 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
-		return;
-	}
-}
-
-void ScImgDataLoader_PICT::handleShape(QDataStream &ts, quint16 opCode)
-{
-	QRect bounds = readRect(ts);
-	QBrush fillBrush;
-	if (patternMode)
-		fillBrush = setFillPattern();
-	else
-		fillBrush = QBrush(foreColor);
-//	qDebug() << QString("Handle Rect/Oval 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
-	if (opCode == 0x0030)
-	{
-		imagePainter.setPen(QPen(foreColor, LineW));
-		imagePainter.setBrush(Qt::NoBrush);
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x0031)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x0032)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(QBrush(backColor));
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x0034)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x0040)
-	{
-		imagePainter.setPen(QPen(foreColor, LineW));
-		imagePainter.setBrush(Qt::NoBrush);
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x0041)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x0042)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(QBrush(backColor));
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x0044)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x0050)
-	{
-		imagePainter.setPen(QPen(foreColor, LineW));
-		imagePainter.setBrush(Qt::NoBrush);
-		imagePainter.drawEllipse(bounds);
-	}
-	else if (opCode == 0x0051)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawEllipse(bounds);
-	}
-	else if (opCode == 0x0052)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(QBrush(backColor));
-		imagePainter.drawEllipse(bounds);
-	}
-	else if (opCode == 0x0054)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawEllipse(bounds);
-	}
-	else
-	{
-//		qDebug() << QString("Not implemented OpCode: 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
-		return;
-	}
-	currRect = bounds;
-}
-
-void ScImgDataLoader_PICT::handleSameShape(QDataStream &ts, quint16 opCode)
-{
-//	qDebug() << QString("Handle Same Rect/Oval 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
-	QRect bounds = currRect;
-	QBrush fillBrush;
-	if (patternMode)
-		fillBrush = setFillPattern();
-	else
-		fillBrush = QBrush(foreColor);
-	if (opCode == 0x0038)
-	{
-		imagePainter.setPen(QPen(foreColor, LineW));
-		imagePainter.setBrush(Qt::NoBrush);
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x0039)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x003A)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(QBrush(backColor));
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x003C)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRect(bounds);
-	}
-	else if (opCode == 0x0048)
-	{
-		imagePainter.setPen(QPen(foreColor, LineW));
-		imagePainter.setBrush(Qt::NoBrush);
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x0049)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x004A)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(QBrush(backColor));
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x004C)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
-	}
-	else if (opCode == 0x0058)
-	{
-		imagePainter.setPen(QPen(foreColor, LineW));
-		imagePainter.setBrush(Qt::NoBrush);
-		imagePainter.drawEllipse(bounds);
-	}
-	else if (opCode == 0x0059)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawEllipse(bounds);
-	}
-	else if (opCode == 0x005A)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(QBrush(backColor));
-		imagePainter.drawEllipse(bounds);
-	}
-	else if (opCode == 0x005C)
-	{
-		imagePainter.setPen(Qt::NoPen);
-		imagePainter.setBrush(fillBrush);
-		imagePainter.drawEllipse(bounds);
-	}
-	else
-	{
-//		qDebug() << QString("Not implemented OpCode: 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
-		return;
-	}
-}
-
-void ScImgDataLoader_PICT::handleFontName(QDataStream &ts)
-{
-	quint16 dataLen, fontID;
-	quint8 nameLen;
-	ts >> dataLen >> fontID;
-	ts >> nameLen;
-	QByteArray fontRawName;
-	fontRawName.resize(nameLen);
-	ts.readRawData(fontRawName.data(), nameLen);
-	QString fontName = fontRawName;
-	fontName = fontName.simplified();
-	SCFonts fonts = PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts;
-	SCFontsIterator it(fonts);
-	for ( ; it.hasNext() ; it.next())
-	{
-		
-		if (fonts[it.currentKey()].scName().simplified() == fontName)
-		{
-			fontName = fonts[it.currentKey()].family();
-			break;
-		}
-	}
-	fontMap.insert(fontID, fontName);
-	alignStreamToWord(ts, 0);
-//	qDebug() << "Handle FontName" << fontName << "ID" << fontID;
-}
-
-void ScImgDataLoader_PICT::handleTextSize(QDataStream &ts)
-{
-	quint16 fontSize;
-	ts >> fontSize;
-	currentTextSize = fontSize;
-//	qDebug() << "Handle Text Size" << fontSize;
-}
-
-void ScImgDataLoader_PICT::handleTextFont(QDataStream &ts)
-{
-	quint16 fontID;
-	ts >> fontID;
-	currentFontID = fontID;
-//	qDebug() << "Handle Text Font" << fontID;
-}
-
-void ScImgDataLoader_PICT::handleTextStyle(QDataStream &ts)
-{
-	quint8 style;
-	ts >> style;
-	alignStreamToWord(ts, 0);
-	currentFontStyle = style;
-//	qDebug() << "Text Style" << style;
-}
-
-void ScImgDataLoader_PICT::handleTextMode(QDataStream &ts)
-{
-	quint16 mode;
-	ts >> mode;
-//	qDebug() << "Handle Text Mode" << mode;
-	switch (mode)
-	{
-		case 0:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
-			break;
-		case 1:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
-			break;
-		case 2:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
-			break;
-		case 3:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
-			break;
-		default:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
-			break;
-	}
-}
-
-void ScImgDataLoader_PICT::handleLongText(QDataStream &ts)
-{
-	quint8 textLen;
-	qint16 x, y;
-	ts >> y >> x;
-	ts >> textLen;
-	QByteArray text;
-	text.resize(textLen);
-	ts.readRawData(text.data(), textLen);
-	if (!textIsPostScript)
-	{
-		currentPointT = QPoint(x, y);
-		createTextPath(text);
-//		qDebug() << "Handle Long Text at" << x << y << text;
-	}
-	alignStreamToWord(ts, 0);
-}
-
-void ScImgDataLoader_PICT::handleDHText(QDataStream &ts)
-{
-	quint8 textLen, dh;
-	ts >> dh >> textLen;
-	QByteArray text;
-	text.resize(textLen);
-	ts.readRawData(text.data(), textLen);
-	if (!textIsPostScript)
-	{
-		QPoint s = currentPointT;
-		currentPointT = QPoint(s.x()+dh, s.y());
-		createTextPath(text);
-//		qDebug() << "Handle DH Text at" << currentPointT << text;
-	}
-	alignStreamToWord(ts, 0);
-}
-
-void ScImgDataLoader_PICT::handleDVText(QDataStream &ts)
-{
-	quint8 textLen, dv;
-	ts >> dv >> textLen;
-	QByteArray text;
-	text.resize(textLen);
-	ts.readRawData(text.data(), textLen);
-	if (!textIsPostScript)
-	{
-		QPoint s = currentPointT;
-		currentPointT = QPoint(s.x(), s.y()+dv);
-		createTextPath(text);
-//		qDebug() << "Handle DV Text at" << currentPointT << text;
-	}
-	alignStreamToWord(ts, 0);
-}
-
-void ScImgDataLoader_PICT::handleDHVText(QDataStream &ts)
-{
-	quint8 textLen, dv, dh;
-	ts >> dh >> dv >> textLen;
-	QByteArray text;
-	text.resize(textLen);
-	ts.readRawData(text.data(), textLen);
-	if (!textIsPostScript)
-	{
-		QPoint s = currentPointT;
-		currentPointT = QPoint(s.x()+dh, s.y()+dv);
-		createTextPath(text);
-//		qDebug() << "Handle DHV Text" << dh << dv << "->" << currentPointT << text;
-	}
-	alignStreamToWord(ts, 0);
-}
-
-void ScImgDataLoader_PICT::createTextPath(QByteArray textString)
-{
-	QTextCodec *codec = QTextCodec::codecForName("Apple Roman");
-	QString string = codec->toUnicode(textString);
-	QFont textFont;
-	if (!fontMap.contains(currentFontID))
-		textFont = QFont();
-	else
-	{
-		QString fontName = fontMap[currentFontID];
-		textFont = QFont(fontName, currentTextSize);
-		QFontInfo inf(textFont);
-//		qDebug() << "Using Font" << inf.family() << "for" << fontName;
-	}
-	textFont.setPixelSize(currentTextSize);
-	if (currentFontStyle & 1)
-		textFont.setBold(true);
-	if (currentFontStyle & 2)
-		textFont.setItalic(true);
-	if (currentFontStyle & 4)
-		textFont.setUnderline(true);
-	QPainterPath painterPath;
-	painterPath.addText( currentPointT.x(), currentPointT.y(), textFont, string);
-	QBrush fillBrush;
-	if (patternMode)
-		fillBrush = setFillPattern();
-	else
-		fillBrush = QBrush(foreColor);
-	imagePainter.fillPath(painterPath, fillBrush);
-}
-
-void ScImgDataLoader_PICT::handlePenMode(QDataStream &ts)
-{
-	quint16 mode;
-	ts >> mode;
-//	qDebug() << "Handle Pen Mode" << mode;
-	switch (mode)
-	{
-		case 0:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
-			break;
-		case 1:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
-			break;
-		case 8:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
-			break;
-		case 9:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
-			break;
-		default:
-			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
-			break;
-	}
-}
-
-void ScImgDataLoader_PICT::handlePenSize(QDataStream &ts)
-{
-//	qDebug() << "Handle Pen Size";
-	quint16 x, y;
-	ts >> y >> x;
-	LineW = qMax(x, y);
-}
-
-void ScImgDataLoader_PICT::handleOvalSize(QDataStream &ts)
-{
-//	qDebug() << "Handle Oval Size";
-	quint16 x, y;
-	ts >> y >> x;
-	ovalSize = QPoint(x, y);
-}
-
-void ScImgDataLoader_PICT::handleShortLine(QDataStream &ts)
-{
-	quint16 x, y;
-	qint8 dh, dv;
-	ts >> y >> x;
-	ts >> dh >> dv;
-	imagePainter.setPen(QPen(foreColor, LineW));
-	imagePainter.drawLine(x, y, x + dh, y + dv);
-	currentPoint = QPoint(x+dh, y+dv);
-//	qDebug() << "Handle Short Line" << x << y << "+" << dh << dv << "->" << currentPoint;
-}
-
-void ScImgDataLoader_PICT::handleShortLineFrom(QDataStream &ts)
-{
-	qint8 dh, dv;
-	ts >> dh >> dv;
-	if ((dh == 0) && (dv == 0))
-		return;
-	QPoint s = currentPoint;
-	imagePainter.setPen(QPen(foreColor, LineW));
-	imagePainter.drawLine(s.x(), s.y(), s.x() + dh, s.y() + dv);
-	currentPoint = QPoint(s.x()+dh, s.y()+dv);
-//	qDebug() << "Handle Short Line from" << dh << dv << "->" << currentPoint;
-}
-
-void ScImgDataLoader_PICT::handleLine(QDataStream &ts)
-{
-	qint16 x1, x2, y1, y2;
-	ts >> y1 >> x1;
-	ts >> y2 >> x2;
-	imagePainter.setPen(QPen(foreColor, LineW));
-	imagePainter.drawLine(x1, y1, x2, y2);
-	currentPoint = QPoint(x2, y2);
-//	qDebug() << "Handle Line" << x1 << y1 << "->" << currentPoint;
-}
-
-void ScImgDataLoader_PICT::handleLineFrom(QDataStream &ts)
-{
-	qint16 x, y;
-	ts >> y >> x;
-	if ((x == 0) && (y == 0))
-		return;
-	QPoint s = currentPoint;
-	imagePainter.setPen(QPen(foreColor, LineW));
-	imagePainter.drawLine(s.x(), s.y(), x, y);
-	currentPoint = QPoint(x, y);
-//	qDebug() << "Handle Line from" << s << "->" << currentPoint;
-}
-
-void ScImgDataLoader_PICT::handlePixmap(QDataStream &ts, quint16 opCode)
-{
-	quint16 bytesPerLine, packType, pixel_type, bits_per_pixel, component_count, component_size;
-	quint32 packSize, horizontal_resolution, vertical_resolution, color_table, plane_bytes;
-	if ((opCode == 0x009A) || (opCode == 0x009B))
-		ts.skipRawData(4);
-	ts >> bytesPerLine;
-	QRect bounds = readRect(ts);
-	bool isPixmap = bytesPerLine & 0x8000;
-	bytesPerLine &= 0x7FFF;
-//	qDebug() << "Bytes per Line" << bytesPerLine << "Pixmap" << isPixmap;
-//	qDebug() << "Bounds" << bounds.right() - bounds.left() << bounds.bottom() - bounds.top();
-	QVector<QRgb> colors;
-	if (isPixmap)
-	{
-		ts.skipRawData(2);	// skip Version info, always 0
-		ts >> packType;
-		ts >> packSize;
-		ts >> horizontal_resolution >> vertical_resolution;
-		ts >> pixel_type >> bits_per_pixel >> component_count >> component_size;
-		ts >> plane_bytes >> color_table;
-		ts.skipRawData(4);
-//		qDebug() << "Pack Type" << packType;
-//		qDebug() << "Pack Size" << packSize;
-//		qDebug() << "Pixel Type" << pixel_type;
-//		qDebug() << "Bits per Pixel" << bits_per_pixel;
-//		qDebug() << "Component Count" << component_count << "Size" << component_size;
-	// now reading color Table
-		if ((opCode != 0x009A) && (opCode != 0x009B))
-		{
-			quint32 ct_seed;
-			quint16 ct_flags, ct_size;
-			ts >> ct_seed;
-			ts >> ct_flags >> ct_size;
-//			qDebug() << "ColorTable has" << ct_size << "Entries";
-			for (quint16 cc = 0; cc < ct_size+1; cc++)
-			{
-				quint16 cev, cRed, cGreen, cBlue;
-				ts >> cev >> cRed >> cGreen >> cBlue;
-				colors.append(qRgb(cRed, cGreen, cBlue));
-			}
-		}
-	}
-// reading scrRect
-	QRect scrRect = readRect(ts);
-//	qDebug() << "Src Rect" << scrRect;
-// reading dstRect
-	QRect dstRect = readRect(ts);
-//	qDebug() << "Dst Rect" << dstRect;
-	ts.skipRawData(2);
-	if ((opCode == 0x0091) || (opCode == 0x0099) || (opCode == 0x009B))
-	{
-		quint16 dataLen;
-		ts >> dataLen;
-		alignStreamToWord(ts, dataLen-2);
-	}
-	quint16 pixRows = bounds.bottom() - bounds.top();
-	quint16 pixCols = bounds.right() - bounds.left();
-	QImage image;
-	if (isPixmap)
-	{
-		if (component_count == 1)
-		{
-			image = QImage(pixCols, pixRows, QImage::Format_Indexed8);
-			image.setColorTable(colors);
-		}
-		else
-			image = QImage(pixCols, pixRows, QImage::Format_ARGB32);
-	}
-	else
-		image = QImage(pixCols, pixRows, QImage::Format_Mono);
-	for (quint16 rr = 0; rr < pixRows; rr++)
-	{
-		quint16 pixByteCount;
-		if (bytesPerLine < 250)
-		{
-			quint8 byteCount;
-			ts >> byteCount;
-			pixByteCount = byteCount;
-		}
-		else
-			ts >> pixByteCount;
-		if (!skipOpcode)
-		{
-			QByteArray data;
-			data.resize(pixByteCount);
-			ts.readRawData(data.data(), pixByteCount);
-			int twoByte = 1;
-			if (component_size == 5)
-				twoByte = 2;
-			QByteArray img;
-			if (bytesPerLine < 8)
-				img = data;
-			else
-				img = decodeRLE(data, bytesPerLine, twoByte);
-			if ((opCode == 0x0098) || (opCode == 0x0099))
-			{
-				if (!isPixmap)
-				{
-					memcpy(image.scanLine(rr), img.data(), bytesPerLine);
-				}
-				else if (component_count == 1)
-				{
-					if (component_size == 4)
-					{
-						uchar *q = (uchar*)(image.scanLine(rr));
-						for (int xx = 0; xx < img.size(); xx++)
-						{
-							uchar i = (img[xx] >> 4) & 0x0F;
-							uchar j = img[xx] & 0x0F;
-							*q++ = i;
-							*q++ = j;
-						}
-					}
-					else
-						memcpy(image.scanLine(rr), img.data(), bytesPerLine);
-				}
-			}
-			else if ((opCode == 0x009A) || (opCode == 0x009B))
-			{
-				if (component_size == 5)
-				{
-					QRgb *q = (QRgb*)(image.scanLine(rr));
-					int imgDcount = 0;
-					for (quint16 xx = 0; xx < pixCols; xx++)
-					{
-						uchar i = img[imgDcount++];
-						uchar j = img[imgDcount++];
-						quint16 r = (i & 0x7c) << 1;
-						quint16 g = ((i & 0x03) << 6) | ((j & 0xe0) >> 2);
-						quint16 b = (j & 0x1f) << 3;
-						*q++ = qRgba(r, g, b, 255);
-					}
-				}
-				else if ((component_size == 8) || (component_size == 24))
-				{
-					QRgb *q = (QRgb*)(image.scanLine(rr));
-					for (uint xx = 0; xx < (uint) pixCols; xx++)
-					{
-						uchar r = 0;
-						uchar g = 0;
-						uchar b = 0;
-						uchar a = 255;
-						if (component_count == 3)
-						{
-							r = img[xx];
-							g = img[xx + pixCols];
-							b = img[xx + 2 * pixCols];
-						}
-						else if (component_count == 4)
-						{
-							a = 255 - img[xx];
-							r = img[xx + pixCols];
-							g = img[xx + 2 * pixCols];
-							b = img[xx + 3 * pixCols];
-						}
-						*q++ = qRgba(r, g, b, a);
-					}
-				}
-			}
-		}
-		else
-		{
-			ts.skipRawData(pixByteCount);
-		}
-	}
-	if (skipOpcode)
-	{
-		image.loadFromData(imageData);
-		isPixmap = true;
-		imageData.resize(0);
-	}
-	if ((component_size == 24) || (component_size == 8) || (component_size == 1) || (component_size == 5) || (component_size == 4) || (!isPixmap) || (skipOpcode))
-	{
-		image = image.convertToFormat(QImage::Format_ARGB32);
-		if (!isPixmap)
-			image.invertPixels();
-		imagePainter.drawImage(dstRect, image);
-		skipOpcode = false;
-	}
-	alignStreamToWord(ts, 0);
-}
-
-void ScImgDataLoader_PICT::handleQuickTime(QDataStream &ts, quint16 opCode)
-{
-//	qDebug() << "Handle QuickTime Data";
-	quint32 dataLenLong, matteSize, maskSize, dataLen;
-	quint16 mode;
-	ts >> dataLenLong;
-	uint pos = ts.device()->pos();
-	alignStreamToWord(ts, 38);		// Skip version and Matrix information
-	ts >> matteSize;
-	QRect matteRect = readRect(ts);
-	if (opCode == 0x8200)
-	{
-		ts >> mode;
-		QRect srcRect = readRect(ts);
-		alignStreamToWord(ts, 4);
-		ts >> maskSize;
-		if (matteSize != 0)
-		{
-			ts >> dataLen;
-			alignStreamToWord(ts, dataLen);
-			alignStreamToWord(ts, matteSize);
-		}
-		if (maskSize != 0)
-		{
-			ts >> dataLen;
-			alignStreamToWord(ts, dataLen);
-			alignStreamToWord(ts, maskSize);
-		}
-		quint32 cType, vendor, dummyLong, imgDataSize;
-		quint16 width, height, dummyShort;
-		ts >> dataLen;
-		ts >> cType;
-		if (cType == 0x6A706567)
-		{
-			ts >> dummyLong;
-			ts >> dummyShort;
-			ts >> dummyShort;
-			ts >> dummyShort;
-			ts >> dummyShort;
-			ts >> vendor;
-			ts >> dummyLong;
-			ts >> dummyLong;
-			ts >> width;
-			ts >> height;
-			ts >> dummyLong;
-			ts >> dummyLong;
-			ts >> imgDataSize;
-			alignStreamToWord(ts, 38);
-			imageData.resize(imgDataSize);
-			ts.readRawData(imageData.data(), imgDataSize);
-			skipOpcode = true;
-		}
-	}
-	else
-	{
-		if (matteSize != 0)
-		{
-			ts >> dataLen;
-			alignStreamToWord(ts, dataLen);
-			alignStreamToWord(ts, matteSize);
-		}
-		ts >> mode;
-		handlePixmap(ts, mode);
-		skipOpcode = true;
-	}
-	ts.device()->seek(pos + dataLenLong);
-//	qDebug() << "File Pos" << ts.device()->pos();
-}
-
-void ScImgDataLoader_PICT::handleComment(QDataStream &ts, bool longComment)
-{
-	quint16 commentCode;
-	ts >> commentCode;
-	switch (commentCode)
-	{
-/*		case 100:			// picAppComment
-			qDebug() << "Comment type: picAppComment";
-			break;
-		case 130:			// picDwgBeg
-			qDebug() << "Comment type: picDwgBeg";
-			break;
-		case 131:			// picDwgEnd
-			qDebug() << "Comment type: picDwgEnd";
-			break;
-		case 140:			// picGrpBeg
-			qDebug() << "Comment type: picGrpBeg";
-			break;
-		case 141:			// picGrpEnd
-			qDebug() << "Comment type: picGrpEnd";
-			break;
-		case 142:			// picBitBeg
-			qDebug() << "Comment type: picBitBeg";
-			break;
-		case 143:			// picBitEnd
-			qDebug() << "Comment type: picBitEnd";
-			break;
-		case 150:			// TextBegin
-			qDebug() << "Comment type: TextBegin";
-			break;
-		case 151:			// TextEnd
-			qDebug() << "Comment type: TextEnd";
-			break;
-		case 152:			// StringBegin
-			qDebug() << "Comment type: StringBegin";
-			break;
-		case 153:			// StringEnd
-			qDebug() << "Comment type: StringEnd";
-			break;
-		case 154:			// TextCenter
-			qDebug() << "Comment type: TextCenter";
-			break;
-		case 155:			// LineLayoutOff
-			qDebug() << "Comment type: LineLayoutOff";
-			break;
-		case 156:			// LineLayoutOn
-			qDebug() << "Comment type: LineLayoutOn";
-			break;
-		case 157:			// ClientLineLayout
-			qDebug() << "Comment type: ClientLineLayout";
-			break;
-		case 160:			// PolyBegin
-			qDebug() << "Comment type: PolyBegin";
-			break;
-		case 161:			// PolyEnd
-			qDebug() << "Comment type: PolyEnd";
-			break;
-		case 163:			// PolyIgnore
-			qDebug() << "Comment type: PolyIgnore";
-			break;
-		case 164:			// PolySmooth
-			qDebug() << "Comment type: PolySmooth";
-			break;
-		case 165:			// PolyClose
-			qDebug() << "Comment type: PolyClose";
-			break;
-		case 170:			// picArrw1 Arrowhead on 2nd point of line
-			qDebug() << "Comment type: picArrw1";
-			break;
-		case 171:			// picArrw2 Arrowhead on 1nd point of line
-			qDebug() << "Comment type: picArrw2";
-			break;
-		case 172:			// picArrw3 Arrowhead on both endpoints
-			qDebug() << "Comment type: picArrw3";
-			break;
-		case 173:			// picArrwEnd End of arrowhead comment
-			qDebug() << "Comment type: picArrwEnd";
-			break;
-		case 180:			// DashedLine
-			qDebug() << "Comment type: DashedLine";
-			break;
-		case 181:			// DashedStop
-			qDebug() << "Comment type: DashedStop";
-			break;
-		case 182:			// SetLineWidth
-			qDebug() << "Comment type: SetLineWidth";
-			break; */
-		case 190:			// PostScriptBegin
-			postscriptMode = true;
-//			qDebug() << "Comment type: PostScriptBegin";
-			break;
-		case 191:			// PostScriptEnd
-			postscriptMode = false;
-			textIsPostScript = false;
-//			qDebug() << "Comment type: PostScriptEnd";
-			break;
-		case 192:			// PostScriptHandle
-//			qDebug() << "Comment type: PostScriptHandle";
-			break;
-		case 193:			// PostScriptFile
-//			qDebug() << "Comment type: PostScriptFile";
-			break;
-		case 194:			// TextIsPostScript
-			textIsPostScript = true;
-//			qDebug() << "Comment type: TextIsPostScript";
-			break;
-/*		case 195:			// ResourcePS
-			qDebug() << "Comment type: ResourcePS";
-			break;
-		case 196:			// PSBeginNoSave
-			qDebug() << "Comment type: PSBeginNoSave";
-			break;
-		case 200:			// RotateBegin
-			qDebug() << "Comment type: RotateBegin";
-			break;
-		case 201:			// RotateEnd
-			qDebug() << "Comment type: RotateEnd";
-			break;
-		case 210:			// FormsPrinting
-			qDebug() << "Comment type: FormsPrinting";
-			break;
-		case 211:			// EndFormsPrinting
-			qDebug() << "Comment type: EndFormsPrinting";
-			break;
-		case 220:			// CMBeginProfile
-			qDebug() << "Comment type: CMBeginProfile";
-			break;
-		case 221:			// CMEndProfile
-			qDebug() << "Comment type: CMEndProfile";
-			break;
-		case 222:			// CMEnableMatching
-			qDebug() << "Comment type: CMEnableMatching";
-			break;
-		case 223:			// CMDisableMatching
-			qDebug() << "Comment type: CMDisableMatching";
-			break; */
-		default:
-//			qDebug() << "Unknown Pict-Comment" << commentCode;
-			break;
-	}
-	if (longComment)
-	{
-		quint16 dataLen;
-		ts >> dataLen;
-		alignStreamToWord(ts, dataLen);
-	}
-}
-
-QRect ScImgDataLoader_PICT::readRect(QDataStream &ts)
-{
-	qint16 RectX, RectY, RectW, RectH;
-	ts >> RectX >> RectY >> RectW >> RectH;
-	return QRect(QPoint(RectY, RectX), QPoint(RectH, RectW));
-}
-
-QByteArray ScImgDataLoader_PICT::decodeRLE(QByteArray &in, quint16 bytesPerLine, int multByte)
-{
-	QByteArray ret = QByteArray(bytesPerLine, ' ');
-	uchar *ptrOut, *ptrIn;
-	ptrOut = (uchar*)ret.data();
-	ptrIn = (uchar*)in.data();
-	quint16 count = 0;
-	uchar c, c2;
-	quint16 len;
-	while( count < in.size() )
-	{
-		c = *ptrIn++;
-		count++;
-		len = c;
-		if( len < 128 )
-		{
-			// Copy next len+1 bytes literally.
-			len++;
-			len *= multByte;
-			while( len != 0 )
-			{
-				*ptrOut++ = *ptrIn++;
-				len--;
-				count++;
-				if (multByte == 2)
-				{
-					*ptrOut++ = *ptrIn++;
-					len--;
-					count++;
-				}
-			}
-		}
-		else if( len > 128 )
-		{
-			// Next -len+1 bytes in the dest are replicated from next source byte.
-			// (Interpret len as a negative 8-bit int.)
-			len ^= 0xFF;
-			len += 2;
-			len *= multByte;
-			if (multByte == 2)
-			{
-				c = *ptrIn++;
-				count++;
-				c2 = *ptrIn++;
-				count++;
-				while( len != 0 )
-				{
-					*ptrOut++ = c;
-					*ptrOut++ = c2;
-					len--;
-					len--;
-				}
-			}
-			else
-			{
-				c = *ptrIn++;
-				count++;
-				while( len != 0 )
-				{
-					*ptrOut++ = c;
-					len--;
-				}
-			}
-		}
-		else if( len == 128 )
-		{
-			// No-op.
-		}
-	}
-	return ret;
-}
-
-QBrush ScImgDataLoader_PICT::setFillPattern()
-{
-	QImage image = QImage(8, 8, QImage::Format_Mono);
-	QVector<QRgb> colors;
-	colors.append(backColor.rgb());
-	colors.append(foreColor.rgb());
-	image.setColorTable(colors);
-	for (int rr = 0; rr < 8; rr++)
-	{
-		uchar *q = (uchar*)(image.scanLine(rr));
-		*q = patternData[rr];
-	}
-	image = image.convertToFormat(QImage::Format_ARGB32);
-	return QBrush(image);
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <QByteArray>
+#include <QCursor>
+#include <QDrag>
+#include <QFile>
+#include <QList>
+#include <QMimeData>
+#include <QRegExp>
+#include <QTextCodec>
+#include <QStack>
+#include <QDebug>
+
+#include <cstdlib>
+
+#include "scimgdataloader_pict.h"
+#include "ui/customfdialog.h"
+#include "ui/missing.h"
+#include "pagesize.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "prefstable.h"
+#include "ui/propertiespalette.h"
+#include "scclocale.h"
+#include "sccolorengine.h"
+#include "scconfig.h"
+#include "scmimedata.h"
+#include "scpaths.h"
+
+#include "scribusXml.h"
+#include "scribuscore.h"
+#include "sctextstream.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "util.h"
+#include "util_formats.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+ScImgDataLoader_PICT::ScImgDataLoader_PICT(void) : ScImgDataLoader()
+{
+	initSupportedFormatList();
+}
+
+void ScImgDataLoader_PICT::initSupportedFormatList(void)
+{
+	m_supportedFormats.clear();
+	m_supportedFormats.append( "pct" );
+	m_supportedFormats.append( "pic" );
+	m_supportedFormats.append( "pict" );
+}
+
+bool ScImgDataLoader_PICT::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)
+{
+	initialize();
+	hasAlpha = false;
+	return true;
+}
+
+void ScImgDataLoader_PICT::loadEmbeddedProfile(const QString& fn, int /*page*/)
+{
+	m_embeddedProfile.resize(0);
+	m_profileComponents = 0;
+}
+
+void ScImgDataLoader_PICT::parseHeader(QString fName, double &x, double &y, double &w, double &h)
+{
+	QFile f(fName);
+	if (f.open(QIODevice::ReadOnly))
+	{
+		QDataStream ts(&f);
+		ts.setByteOrder(QDataStream::BigEndian);
+		ts.device()->seek(512);
+		qint16 pgX, pgY, pgW, pgH, dummy;
+		ts >> dummy >> pgX >> pgY >> pgW >> pgH;
+		quint16 vers, vers2, vers3;
+		ts >> vers;
+		if (vers == 0x1101)
+		{
+			pctVersion = 1;
+			h = pgW - pgX;
+			w = pgH - pgY;
+			x = pgY;
+			y = pgX;
+			resX = 72.0;
+			resY = 72.0;
+		}
+		else if (vers == 0x0011)
+		{
+			ts >> vers2 >> vers3;
+			if ((vers2 == 0x02FF) && (vers3 == 0x0C00))
+			{
+				pctVersion = 2;
+				qint16 vExt;
+				ts >> vExt;
+				if (vExt == -1)
+				{
+					ts >> dummy;
+					quint32 xres, yres;
+					xres = 72;
+					yres = 72;
+					qint32 pgX2, pgY2, pgW2, pgH2;
+					ts >> pgX2 >> pgY2 >> pgW2 >> pgH2;
+					ts >> dummy;
+					ts >> dummy;
+					resX = 72.0;
+					resY = 72.0;
+					h = pgW - pgX;
+					w = pgH - pgY;
+					x = pgY;
+					y = pgX;
+				}
+				else if (vExt == -2)
+				{
+					ts >> dummy;
+					quint16 xres, yres;
+					ts >> xres >> dummy >> yres >> dummy;
+					ts >> pgX >> pgY >> pgW >> pgH;
+					ts >> dummy;
+					h = pgW - pgX;
+					w = pgH - pgY;
+					x = pgY;
+					y = pgX;
+					resX = xres;
+					resY = yres;
+				}
+			}
+		}
+		f.close();
+	}
+}
+
+bool ScImgDataLoader_PICT::loadPicture(const QString& fn, int /*page*/, int /*res*/, bool /*thumbnail*/)
+{
+	if (!QFile::exists(fn))
+		return false;
+	initialize();
+	double x=0.0, y=0.0, w=0.0, h=0.0;
+	parseHeader(fn, x, y, w, h);
+	docWidth = w;
+	docHeight = h;
+	baseX = -x;
+	baseY = -y;
+	QFile f(fn);
+	if (f.open(QIODevice::ReadOnly))
+	{
+		QDataStream ts(&f);
+		ts.device()->seek(522);
+		m_image = QImage(docWidth, docHeight, QImage::Format_ARGB32);
+		if (m_image.isNull())
+			return false;
+		m_image.fill(qRgba(255, 255, 255, 255));
+		imagePainter.begin(&m_image);
+		imagePainter.setRenderHint(QPainter::Antialiasing , true);
+		imagePainter.translate(baseX, baseY);
+		patternMode = false;
+		patternData.resize(0);
+		backColor = Qt::white;
+		foreColor = Qt::black;
+		Coords = QPainterPath();
+		LineW = 1.0;
+		currentPoint = QPoint(0, 0);
+		currentPointT = QPoint(0, 0);
+		ovalSize = QPoint(0, 0);
+		fontMap.clear();
+		currentTextSize = 12;
+		currentFontID = 0;
+		currentFontStyle = 0;
+		imageData.resize(0);
+		skipOpcode = false;
+		postscriptMode = false;
+		textIsPostScript = false;
+		quint16 vers = 0;
+		ts >> vers;
+		while (vers == 0)
+		{
+			ts >> vers;
+			if (vers == 0x00FF)
+			{
+				f.close();
+				return false;
+			}
+		}
+		if (vers == 0x1101)
+		{
+			pctVersion = 1;		// Pict Version 1
+			parsePict(ts);
+		}
+		else
+		{
+			ts.skipRawData(4);	// skip the next 4 Bytes
+			ts >> vers;		// read the version info
+			pctVersion = 2;	// Pict Extended Version 2
+			ts.skipRawData(22);
+			parsePict(ts);
+		}
+		imagePainter.end();
+		m_imageInfoRecord.type = ImageTypeOther;
+		m_imageInfoRecord.exifDataValid = false;
+		m_imageInfoRecord.xres = resX;
+		m_imageInfoRecord.yres = resY;
+		m_imageInfoRecord.BBoxX = 0;
+		m_imageInfoRecord.colorspace = ColorSpaceRGB;
+		m_imageInfoRecord.BBoxH = m_image.height();
+		m_pixelFormat = Format_BGRA_8;
+		f.close();
+		return true;
+	}
+	return true;
+}
+
+void ScImgDataLoader_PICT::parsePict(QDataStream &ts)
+{
+	while (!ts.atEnd())
+	{
+		quint16 opCode, dataLen;
+		quint8 dataLenByte;
+		quint32 dataLenLong;
+		if (pctVersion == 1)
+		{
+			ts >> dataLenByte;
+			opCode = dataLenByte;
+		}
+		else
+			ts >> opCode;
+		if (((opCode >= 0x0092) && (opCode <= 0x0097)) || ((opCode >= 0x009C) && (opCode <= 0x009F)) || ((opCode >= 0x00A2) && (opCode <= 0x00AF)))
+		{
+			// Reserved by Apple
+//			qDebug() << "Reserved by Apple";
+			ts >> dataLen;
+			alignStreamToWord(ts, dataLen);
+		}
+		else if (((opCode >= 0x00B0) && (opCode <= 0x00CF)) || ((opCode >= 0x8000) && (opCode <= 0x80FF)))
+		{
+			// Reserved by Apple
+//			qDebug() << "Reserved by Apple";
+		}
+		else if (((opCode >= 0x00D0) && (opCode <= 0x00FE)) || ((opCode >= 0x8100) && (opCode <= 0x81FF)))
+		{
+			// Reserved by Apple
+//			qDebug() << "Reserved by Apple";
+			ts >> dataLenLong;
+			alignStreamToWord(ts, dataLenLong);
+		}
+		else if (((opCode >= 0x0100) && (opCode <= 0x01FF)) || ((opCode >= 0x02FF) && (opCode <= 0x0BFE)))
+		{
+			// Reserved by Apple
+//			qDebug() << "Reserved by Apple";
+			alignStreamToWord(ts, 2);
+		}
+		else if ((opCode >= 0x0C00) && (opCode <= 0x7EFF))
+		{
+			// Reserved by Apple
+//			qDebug() << "Reserved by Apple";
+			alignStreamToWord(ts, 24);
+		}
+		else if ((opCode >= 0x7F00) && (opCode <= 0x7FFF))
+		{
+			// Reserved by Apple
+//			qDebug() << "Reserved by Apple";
+			alignStreamToWord(ts, 254);
+		}
+		else
+		{
+			switch (opCode)
+			{
+				case 0x0000:		// NOP
+//					qDebug() << "NOP";
+					break;
+				case 0x0001:		// Clipping Region
+//					qDebug() << "Clipping Region";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0002:		// Background Pattern
+//					qDebug() << "Background Pattern";
+					alignStreamToWord(ts, 8);
+					break;
+				case 0x0003:		// Text Font
+					handleTextFont(ts);
+					break;
+				case 0x0004:		// Text Style
+					handleTextStyle(ts);
+					break;
+				case 0x0005:		// Text Mode
+					handleTextMode(ts);
+					break;
+				case 0x0006:		// Extra Space
+//					qDebug() << "Extra Space";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x0007:		// Pen Size
+					handlePenSize(ts);
+					break;
+				case 0x0008:		// Pen Mode
+					handlePenMode(ts);
+					break;
+				case 0x0009:		// Pen Pattern
+					handlePenPattern(ts);
+					break;
+				case 0x000A:		// Fill Pattern
+//					qDebug() << "Fill Pattern";
+					alignStreamToWord(ts, 8);
+					break;
+				case 0x000B:		// Oval Size
+					handleOvalSize(ts);
+					break;
+				case 0x000C:		// Origin
+//					qDebug() << "Origin";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x000D:		// Text Size
+					handleTextSize(ts);
+					break;
+				case 0x000E:		// Foreground Color
+					handleColor(ts, false);
+					break;
+				case 0x000F:		// Background Color
+					handleColor(ts, true);
+					break;
+				case 0x0010:		// Text Ratio
+//					qDebug() << "Text Ratio";
+					alignStreamToWord(ts, 8);
+					break;
+				case 0x0011:		// Version
+//					qDebug() << "Version";
+					alignStreamToWord(ts, 1);
+					break;
+				case 0x0015:		// Fractional pen position
+//					qDebug() << "Fractional pen position at" << ts.device()->pos();
+					alignStreamToWord(ts, 2);
+					break;
+				case 0x0016:		// Extra char space
+//					qDebug() << "Extra char space";
+					alignStreamToWord(ts, 2);
+					break;
+				case 0x0017:
+				case 0x0018:
+				case 0x0019:
+//					qDebug() << "Reserved by Apple";
+					break;
+				case 0x001A:		// Foreground color RGB
+					handleColorRGB(ts, false);
+					break;
+				case 0x001B:		// Background color RGB
+					handleColorRGB(ts, true);
+					break;
+				case 0x001C:		// Highlight mode
+//					qDebug() << "Highlight mode";
+					break;
+				case 0x001D:		// Highlight color RGB
+//					qDebug() << "Highlight color RGB";
+					alignStreamToWord(ts, 6);
+					break;
+				case 0x001E:		// Use default highlight color
+//					qDebug() << "Use default highlight color";
+					break;
+				case 0x0020:		// Line
+					handleLine(ts);
+					break;
+				case 0x0021:		// Line To
+					handleLineFrom(ts);
+					break;
+				case 0x0022:		// Short Line
+					handleShortLine(ts);
+					break;
+				case 0x0023:		// Short Line To
+					handleShortLineFrom(ts);
+					break;
+				case 0x0024:
+				case 0x0025:
+				case 0x0026:
+				case 0x0027:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen);
+					break;
+				case 0x0028:		// Long Text
+					handleLongText(ts);
+					break;
+				case 0x0029:		// Text DH
+					handleDHText(ts);
+					break;
+				case 0x002A:		// Text DV
+					handleDVText(ts);
+					break;
+				case 0x002B:		// Text DHV
+					handleDHVText(ts);
+					break;
+				case 0x002C:		// Font Name
+					handleFontName(ts);
+					break;
+				case 0x002D:		// Line justify
+//					qDebug() << "Line justify";
+					alignStreamToWord(ts, 10);
+					break;
+				case 0x002E:		// Glyph state
+//					qDebug() << "Glyph state";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen);
+					break;
+				case 0x002F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen);
+					break;
+				case 0x0030:		// Frame rect
+				case 0x0031:		// Paint rect
+				case 0x0032:		// Erase rect
+				case 0x0033:		// Invert rect
+				case 0x0034:		// Fill rect
+					handleShape(ts, opCode);
+					break;
+				case 0x0035:
+				case 0x0036:
+				case 0x0037:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					alignStreamToWord(ts, 8);
+					break;
+				case 0x0038:		// Frame same rect
+				case 0x0039:		// Paint same rect
+				case 0x003A:		// Erase same rect
+				case 0x003B:		// Invert same rect
+				case 0x003C:		// Fill same rect
+					handleSameShape(ts, opCode);
+					break;
+				case 0x003D:
+				case 0x003E:
+				case 0x003F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					break;
+				case 0x0040:		// Frame round rect
+				case 0x0041:		// Paint round rect
+				case 0x0042:		// Erase round rect
+				case 0x0043:		// Invert round rect
+				case 0x0044:		// Fill round rect
+					handleShape(ts, opCode);
+					break;
+				case 0x0045:
+				case 0x0046:
+				case 0x0047:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					alignStreamToWord(ts, 8);
+					break;
+				case 0x0048:		// Frame same round rect
+				case 0x0049:		// Paint same round rect
+				case 0x004A:		// Erase same round rect
+				case 0x004B:		// Invert same round rect
+				case 0x004C:		// Fill same round rect
+					handleSameShape(ts, opCode);
+					break;
+				case 0x004D:
+				case 0x004E:
+				case 0x004F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					break;
+				case 0x0050:		// Frame oval
+				case 0x0051:		// Paint oval
+				case 0x0052:		// Erase oval
+				case 0x0053:		// Invert oval
+				case 0x0054:		// Fill oval
+					handleShape(ts, opCode);
+					break;
+				case 0x0055:
+				case 0x0056:
+				case 0x0057:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					alignStreamToWord(ts, 8);
+					break;
+				case 0x0058:		// Frame same oval
+				case 0x0059:		// Paint same oval
+				case 0x005A:		// Erase same oval
+				case 0x005B:		// Invert same oval
+				case 0x005C:		// Fill same oval
+					handleSameShape(ts, opCode);
+					break;
+				case 0x005D:
+				case 0x005E:
+				case 0x005F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					break;
+				case 0x0060:		// Frame arc
+//					qDebug() << "Frame arc";
+					alignStreamToWord(ts, 12);
+					break;
+				case 0x0061:		// Paint arc
+//					qDebug() << "Paint arc";
+					alignStreamToWord(ts, 12);
+					break;
+				case 0x0062:		// Erase arc
+//					qDebug() << "Erase arc";
+					alignStreamToWord(ts, 12);
+					break;
+				case 0x0063:		// Invert arc
+//					qDebug() << "Invert arc";
+					alignStreamToWord(ts, 12);
+					break;
+				case 0x0064:		// Fill arc
+//					qDebug() << "Fill arc";
+					alignStreamToWord(ts, 12);
+					break;
+				case 0x0065:
+				case 0x0066:
+				case 0x0067:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					alignStreamToWord(ts, 12);
+					break;
+				case 0x0068:		// Frame same arc
+//					qDebug() << "Frame same arc";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x0069:		// Paint same arc
+//					qDebug() << "Paint same arc";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x006A:		// Erase same arc
+//					qDebug() << "Erase same arc";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x006B:		// Invert same arc
+//					qDebug() << "Invert same arc";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x006C:		// Fill same arc
+//					qDebug() << "Fill same arc";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x006D:
+				case 0x006E:
+				case 0x006F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x0070:		// Frame poly
+				case 0x0071:		// Paint poly
+				case 0x0072:		// Erase poly
+				case 0x0073:		// Invert poly
+				case 0x0074:		// Fill poly
+					handlePolygon(ts, opCode);
+					break;
+				case 0x0075:
+				case 0x0076:
+				case 0x0077:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0078:		// Frame same poly
+//					qDebug() << "Frame same poly";
+					break;
+				case 0x0079:		// Paint same poly
+//					qDebug() << "Paint same poly";
+					break;
+				case 0x007A:		// Erase same poly
+//					qDebug() << "Erase same poly";
+					break;
+				case 0x007B:		// Invert same poly
+//					qDebug() << "Invert same poly";
+					break;
+				case 0x007C:		// Fill same poly
+//					qDebug() << "Fill same poly";
+					break;
+				case 0x007D:
+				case 0x007E:
+				case 0x007F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					break;
+				case 0x0080:		// Frame region
+//					qDebug() << "Frame region";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0081:		// Paint region
+//					qDebug() << "Paint region";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0082:		// Erase region
+//					qDebug() << "Erase region";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0083:		// Invert region
+//					qDebug() << "Invert region";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0084:		// Fill region
+//					qDebug() << "Fill region";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0085:
+				case 0x0086:
+				case 0x0087:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					ts >> dataLen;
+					alignStreamToWord(ts, dataLen-2);
+					break;
+				case 0x0088:		// Frame same region
+//					qDebug() << "Frame same region";
+					break;
+				case 0x0089:		// Paint same region
+//					qDebug() << "Paint same region";
+					break;
+				case 0x008A:		// Erase same region
+//					qDebug() << "Erase same region";
+					break;
+				case 0x008B:		// Invert same region
+//					qDebug() << "Invert same region";
+					break;
+				case 0x008C:		// Fill same region
+//					qDebug() << "Fill same region";
+					break;
+				case 0x008D:
+				case 0x008E:
+				case 0x008F:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					break;
+				case 0x0090:		// Bits Rect
+//					qDebug() << "Bits Rect";
+					handlePixmap(ts, opCode);
+					break;
+				case 0x0091:		// Bits Region
+//					qDebug() << "Bits Region";
+					handlePixmap(ts, opCode);
+					break;
+				case 0x0098:		// Pack Bits Rect
+//					qDebug() << "Pack Bits Rect";
+					handlePixmap(ts, opCode);
+					break;
+				case 0x0099:		// Pack Bits Region
+//					qDebug() << "Pack Bits Region";
+					handlePixmap(ts, opCode);
+					break;
+				case 0x009A:		// Direct Bits Rect
+//					qDebug() << "Direct Bits Rect";
+					handlePixmap(ts, opCode);
+					break;
+				case 0x009B:		// Direct Bits Region
+//					qDebug() << "Direct Bits Region";
+					handlePixmap(ts, opCode);
+					break;
+				case 0x00A0:		// Short Comment
+					handleComment(ts, false);
+					break;
+				case 0x00A1:		// Long Comment
+					handleComment(ts, true);
+					break;
+				case 0x00FF:		// End of Pict
+					if (imageData.size() > 0)
+					{
+						QImage image;
+						image.loadFromData(imageData);
+						image = image.convertToFormat(QImage::Format_ARGB32);
+						imagePainter.drawImage(0, 0, image);
+					}
+//					qDebug() << "End of Pict";
+					return;
+					break;
+				case 0x0200:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					alignStreamToWord(ts, 4);
+					break;
+				case 0x8200:		// Compressed QuickTime
+				case 0x8201:		// Uncompressed QuickTime
+					handleQuickTime(ts, opCode);
+					break;
+				case 0xFFFF:		// Reserved by Apple
+//					qDebug() << "Reserved by Apple";
+					ts >> dataLenLong;
+					alignStreamToWord(ts, dataLenLong);
+					break;
+				default:
+//					qDebug() << QString("Not implemented OpCode: 0x%1 at %3").arg(opCode, 4, 16, QLatin1Char('0')).arg(ts.device()->pos()-2);
+					return;
+					break;
+			}
+		}
+	}
+}
+
+void ScImgDataLoader_PICT::alignStreamToWord(QDataStream &ts, uint len)
+{
+	ts.skipRawData(len);
+	if (pctVersion == 1)
+		return;
+	uint adj = ts.device()->pos() % 2;
+	if (adj != 0)
+		ts.skipRawData(1);
+}
+
+void ScImgDataLoader_PICT::handleColor(QDataStream &ts, bool back)
+{
+	quint16 Rc, Gc, Bc;
+	quint32 colVal;
+	ts >> colVal;
+//	qDebug() << "Color" << colVal << back;
+	switch (colVal)
+	{
+		case 30:
+			Rc = 0xFFFF;
+			Gc = 0xFFFF;
+			Bc = 0xFFFF;
+			break;
+		case 33:
+			Rc = 0x0000;
+			Gc = 0x0000;
+			Bc = 0x0000;
+			break;
+		case 69:
+			Rc = 0xFC00;
+			Gc = 0xF37D;
+			Bc = 0x052F;
+			break;
+		case 137:
+			Rc = 0xF2D7;
+			Gc = 0x0856;
+			Bc = 0x84EC;
+			break;
+		case 205:
+			Rc = 0xDD6B;
+			Gc = 0x08C2;
+			Bc = 0x06A2;
+			break;
+		case 273:
+			Rc = 0x0241;
+			Gc = 0xAB54;
+			Bc = 0xEAFF;
+			break;
+		case 341:
+			Rc = 0x0000;
+			Gc = 0x64AF;
+			Bc = 0x11B0;
+			break;
+		case 409:
+			Rc = 0x0000;
+			Gc = 0x0000;
+			Bc = 0xD400;
+			break;
+		default:
+			Rc = 0x0000;
+			Gc = 0x0000;
+			Bc = 0x0000;
+			break;
+	}
+	int redC, greenC, blueC;
+	redC = qRound((Rc / 65535.0) * 255.0);
+	greenC = qRound((Gc / 65535.0) * 255.0);
+	blueC = qRound((Bc / 65535.0) * 255.0);
+	QColor c = QColor(redC, greenC, blueC);
+	if (back)
+		backColor = c;
+	else
+		foreColor = c;
+}
+
+void ScImgDataLoader_PICT::handleColorRGB(QDataStream &ts, bool back)
+{
+	quint16 Rc, Gc, Bc;
+	int redC, greenC, blueC;
+	ts >> Rc >> Gc >> Bc;
+	redC = qRound((Rc / 65535.0) * 255.0);
+	greenC = qRound((Gc / 65535.0) * 255.0);
+	blueC = qRound((Bc / 65535.0) * 255.0);
+	QColor c = QColor(redC, greenC, blueC);
+	if (back)
+		backColor = c;
+	else
+		foreColor = c;
+}
+
+void ScImgDataLoader_PICT::handlePenPattern(QDataStream &ts)
+{
+	patternData.resize(8);
+	ts.readRawData(patternData.data(), 8);
+	patternMode = false;
+	for (int a = 0; a < patternData.size(); a++)
+	{
+		uchar d = patternData[a];
+		if ((d != 0x00) && (d != 0xFF))
+		{
+			patternMode = true;
+			break;
+		}
+	}
+}
+
+void ScImgDataLoader_PICT::handlePolygon(QDataStream &ts, quint16 opCode)
+{
+//	qDebug() << "Handle Polygon";
+	quint16 polySize;
+	ts >> polySize;				// read polygon size
+	ts.skipRawData(8);			// skip bounding rect;
+	polySize -= 14;				// subtract size count, bounding rect and first point from size
+	qint16 x, y;
+	ts >> y >> x;
+	Coords = QPainterPath();
+	Coords.moveTo(x, y);
+	QBrush fillBrush;
+	if (patternMode)
+		fillBrush = setFillPattern();
+	else
+		fillBrush = QBrush(foreColor);
+	for(unsigned i = 0; i < polySize; i += 4)
+	{
+		ts >> y >> x;
+		Coords.lineTo(x, y);
+	}
+	if (opCode == 0x0070)
+		imagePainter.strokePath(Coords, QPen(foreColor, LineW));
+	else if (opCode == 0x0071)
+		imagePainter.fillPath(Coords, fillBrush);
+	else if (opCode == 0x0072)
+		imagePainter.fillPath(Coords, QBrush(backColor));
+	else if (opCode == 0x0074)
+		imagePainter.fillPath(Coords, fillBrush);
+	else
+	{
+//		qDebug() << QString("Not implemented OpCode: 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
+		return;
+	}
+}
+
+void ScImgDataLoader_PICT::handleShape(QDataStream &ts, quint16 opCode)
+{
+	QRect bounds = readRect(ts);
+	QBrush fillBrush;
+	if (patternMode)
+		fillBrush = setFillPattern();
+	else
+		fillBrush = QBrush(foreColor);
+//	qDebug() << QString("Handle Rect/Oval 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
+	if (opCode == 0x0030)
+	{
+		imagePainter.setPen(QPen(foreColor, LineW));
+		imagePainter.setBrush(Qt::NoBrush);
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x0031)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x0032)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(QBrush(backColor));
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x0034)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x0040)
+	{
+		imagePainter.setPen(QPen(foreColor, LineW));
+		imagePainter.setBrush(Qt::NoBrush);
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x0041)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x0042)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(QBrush(backColor));
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x0044)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x0050)
+	{
+		imagePainter.setPen(QPen(foreColor, LineW));
+		imagePainter.setBrush(Qt::NoBrush);
+		imagePainter.drawEllipse(bounds);
+	}
+	else if (opCode == 0x0051)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawEllipse(bounds);
+	}
+	else if (opCode == 0x0052)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(QBrush(backColor));
+		imagePainter.drawEllipse(bounds);
+	}
+	else if (opCode == 0x0054)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawEllipse(bounds);
+	}
+	else
+	{
+//		qDebug() << QString("Not implemented OpCode: 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
+		return;
+	}
+	currRect = bounds;
+}
+
+void ScImgDataLoader_PICT::handleSameShape(QDataStream &ts, quint16 opCode)
+{
+//	qDebug() << QString("Handle Same Rect/Oval 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
+	QRect bounds = currRect;
+	QBrush fillBrush;
+	if (patternMode)
+		fillBrush = setFillPattern();
+	else
+		fillBrush = QBrush(foreColor);
+	if (opCode == 0x0038)
+	{
+		imagePainter.setPen(QPen(foreColor, LineW));
+		imagePainter.setBrush(Qt::NoBrush);
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x0039)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x003A)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(QBrush(backColor));
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x003C)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRect(bounds);
+	}
+	else if (opCode == 0x0048)
+	{
+		imagePainter.setPen(QPen(foreColor, LineW));
+		imagePainter.setBrush(Qt::NoBrush);
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x0049)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x004A)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(QBrush(backColor));
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x004C)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawRoundedRect(bounds, ovalSize.x(), ovalSize.y());
+	}
+	else if (opCode == 0x0058)
+	{
+		imagePainter.setPen(QPen(foreColor, LineW));
+		imagePainter.setBrush(Qt::NoBrush);
+		imagePainter.drawEllipse(bounds);
+	}
+	else if (opCode == 0x0059)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawEllipse(bounds);
+	}
+	else if (opCode == 0x005A)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(QBrush(backColor));
+		imagePainter.drawEllipse(bounds);
+	}
+	else if (opCode == 0x005C)
+	{
+		imagePainter.setPen(Qt::NoPen);
+		imagePainter.setBrush(fillBrush);
+		imagePainter.drawEllipse(bounds);
+	}
+	else
+	{
+//		qDebug() << QString("Not implemented OpCode: 0x%1").arg(opCode, 4, 16, QLatin1Char('0'));
+		return;
+	}
+}
+
+void ScImgDataLoader_PICT::handleFontName(QDataStream &ts)
+{
+	quint16 dataLen, fontID;
+	quint8 nameLen;
+	ts >> dataLen >> fontID;
+	ts >> nameLen;
+	QByteArray fontRawName;
+	fontRawName.resize(nameLen);
+	ts.readRawData(fontRawName.data(), nameLen);
+	QString fontName = fontRawName;
+	fontName = fontName.simplified();
+	SCFonts fonts = PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts;
+	SCFontsIterator it(fonts);
+	for ( ; it.hasNext() ; it.next())
+	{
+		
+		if (fonts[it.currentKey()].scName().simplified() == fontName)
+		{
+			fontName = fonts[it.currentKey()].family();
+			break;
+		}
+	}
+	fontMap.insert(fontID, fontName);
+	alignStreamToWord(ts, 0);
+//	qDebug() << "Handle FontName" << fontName << "ID" << fontID;
+}
+
+void ScImgDataLoader_PICT::handleTextSize(QDataStream &ts)
+{
+	quint16 fontSize;
+	ts >> fontSize;
+	currentTextSize = fontSize;
+//	qDebug() << "Handle Text Size" << fontSize;
+}
+
+void ScImgDataLoader_PICT::handleTextFont(QDataStream &ts)
+{
+	quint16 fontID;
+	ts >> fontID;
+	currentFontID = fontID;
+//	qDebug() << "Handle Text Font" << fontID;
+}
+
+void ScImgDataLoader_PICT::handleTextStyle(QDataStream &ts)
+{
+	quint8 style;
+	ts >> style;
+	alignStreamToWord(ts, 0);
+	currentFontStyle = style;
+//	qDebug() << "Text Style" << style;
+}
+
+void ScImgDataLoader_PICT::handleTextMode(QDataStream &ts)
+{
+	quint16 mode;
+	ts >> mode;
+//	qDebug() << "Handle Text Mode" << mode;
+	switch (mode)
+	{
+		case 0:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+			break;
+		case 1:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+			break;
+		case 2:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
+			break;
+		case 3:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
+			break;
+		default:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+			break;
+	}
+}
+
+void ScImgDataLoader_PICT::handleLongText(QDataStream &ts)
+{
+	quint8 textLen;
+	qint16 x, y;
+	ts >> y >> x;
+	ts >> textLen;
+	QByteArray text;
+	text.resize(textLen);
+	ts.readRawData(text.data(), textLen);
+	if (!textIsPostScript)
+	{
+		currentPointT = QPoint(x, y);
+		createTextPath(text);
+//		qDebug() << "Handle Long Text at" << x << y << text;
+	}
+	alignStreamToWord(ts, 0);
+}
+
+void ScImgDataLoader_PICT::handleDHText(QDataStream &ts)
+{
+	quint8 textLen, dh;
+	ts >> dh >> textLen;
+	QByteArray text;
+	text.resize(textLen);
+	ts.readRawData(text.data(), textLen);
+	if (!textIsPostScript)
+	{
+		QPoint s = currentPointT;
+		currentPointT = QPoint(s.x()+dh, s.y());
+		createTextPath(text);
+//		qDebug() << "Handle DH Text at" << currentPointT << text;
+	}
+	alignStreamToWord(ts, 0);
+}
+
+void ScImgDataLoader_PICT::handleDVText(QDataStream &ts)
+{
+	quint8 textLen, dv;
+	ts >> dv >> textLen;
+	QByteArray text;
+	text.resize(textLen);
+	ts.readRawData(text.data(), textLen);
+	if (!textIsPostScript)
+	{
+		QPoint s = currentPointT;
+		currentPointT = QPoint(s.x(), s.y()+dv);
+		createTextPath(text);
+//		qDebug() << "Handle DV Text at" << currentPointT << text;
+	}
+	alignStreamToWord(ts, 0);
+}
+
+void ScImgDataLoader_PICT::handleDHVText(QDataStream &ts)
+{
+	quint8 textLen, dv, dh;
+	ts >> dh >> dv >> textLen;
+	QByteArray text;
+	text.resize(textLen);
+	ts.readRawData(text.data(), textLen);
+	if (!textIsPostScript)
+	{
+		QPoint s = currentPointT;
+		currentPointT = QPoint(s.x()+dh, s.y()+dv);
+		createTextPath(text);
+//		qDebug() << "Handle DHV Text" << dh << dv << "->" << currentPointT << text;
+	}
+	alignStreamToWord(ts, 0);
+}
+
+void ScImgDataLoader_PICT::createTextPath(QByteArray textString)
+{
+	QTextCodec *codec = QTextCodec::codecForName("Apple Roman");
+	QString string = codec->toUnicode(textString);
+	QFont textFont;
+	if (!fontMap.contains(currentFontID))
+		textFont = QFont();
+	else
+	{
+		QString fontName = fontMap[currentFontID];
+		textFont = QFont(fontName, currentTextSize);
+		QFontInfo inf(textFont);
+//		qDebug() << "Using Font" << inf.family() << "for" << fontName;
+	}
+	textFont.setPixelSize(currentTextSize);
+	if (currentFontStyle & 1)
+		textFont.setBold(true);
+	if (currentFontStyle & 2)
+		textFont.setItalic(true);
+	if (currentFontStyle & 4)
+		textFont.setUnderline(true);
+	QPainterPath painterPath;
+	painterPath.addText( currentPointT.x(), currentPointT.y(), textFont, string);
+	QBrush fillBrush;
+	if (patternMode)
+		fillBrush = setFillPattern();
+	else
+		fillBrush = QBrush(foreColor);
+	imagePainter.fillPath(painterPath, fillBrush);
+}
+
+void ScImgDataLoader_PICT::handlePenMode(QDataStream &ts)
+{
+	quint16 mode;
+	ts >> mode;
+//	qDebug() << "Handle Pen Mode" << mode;
+	switch (mode)
+	{
+		case 0:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+			break;
+		case 1:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
+			break;
+		case 8:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+			break;
+		case 9:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_Xor);
+			break;
+		default:
+			imagePainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+			break;
+	}
+}
+
+void ScImgDataLoader_PICT::handlePenSize(QDataStream &ts)
+{
+//	qDebug() << "Handle Pen Size";
+	quint16 x, y;
+	ts >> y >> x;
+	LineW = qMax(x, y);
+}
+
+void ScImgDataLoader_PICT::handleOvalSize(QDataStream &ts)
+{
+//	qDebug() << "Handle Oval Size";
+	quint16 x, y;
+	ts >> y >> x;
+	ovalSize = QPoint(x, y);
+}
+
+void ScImgDataLoader_PICT::handleShortLine(QDataStream &ts)
+{
+	quint16 x, y;
+	qint8 dh, dv;
+	ts >> y >> x;
+	ts >> dh >> dv;
+	imagePainter.setPen(QPen(foreColor, LineW));
+	imagePainter.drawLine(x, y, x + dh, y + dv);
+	currentPoint = QPoint(x+dh, y+dv);
+//	qDebug() << "Handle Short Line" << x << y << "+" << dh << dv << "->" << currentPoint;
+}
+
+void ScImgDataLoader_PICT::handleShortLineFrom(QDataStream &ts)
+{
+	qint8 dh, dv;
+	ts >> dh >> dv;
+	if ((dh == 0) && (dv == 0))
+		return;
+	QPoint s = currentPoint;
+	imagePainter.setPen(QPen(foreColor, LineW));
+	imagePainter.drawLine(s.x(), s.y(), s.x() + dh, s.y() + dv);
+	currentPoint = QPoint(s.x()+dh, s.y()+dv);
+//	qDebug() << "Handle Short Line from" << dh << dv << "->" << currentPoint;
+}
+
+void ScImgDataLoader_PICT::handleLine(QDataStream &ts)
+{
+	qint16 x1, x2, y1, y2;
+	ts >> y1 >> x1;
+	ts >> y2 >> x2;
+	imagePainter.setPen(QPen(foreColor, LineW));
+	imagePainter.drawLine(x1, y1, x2, y2);
+	currentPoint = QPoint(x2, y2);
+//	qDebug() << "Handle Line" << x1 << y1 << "->" << currentPoint;
+}
+
+void ScImgDataLoader_PICT::handleLineFrom(QDataStream &ts)
+{
+	qint16 x, y;
+	ts >> y >> x;
+	if ((x == 0) && (y == 0))
+		return;
+	QPoint s = currentPoint;
+	imagePainter.setPen(QPen(foreColor, LineW));
+	imagePainter.drawLine(s.x(), s.y(), x, y);
+	currentPoint = QPoint(x, y);
+//	qDebug() << "Handle Line from" << s << "->" << currentPoint;
+}
+
+void ScImgDataLoader_PICT::handlePixmap(QDataStream &ts, quint16 opCode)
+{
+	quint16 bytesPerLine, packType, pixel_type, bits_per_pixel, component_count, component_size;
+	quint32 packSize, horizontal_resolution, vertical_resolution, color_table, plane_bytes;
+	if ((opCode == 0x009A) || (opCode == 0x009B))
+		ts.skipRawData(4);
+	ts >> bytesPerLine;
+	QRect bounds = readRect(ts);
+	bool isPixmap = bytesPerLine & 0x8000;
+	bytesPerLine &= 0x7FFF;
+//	qDebug() << "Bytes per Line" << bytesPerLine << "Pixmap" << isPixmap;
+//	qDebug() << "Bounds" << bounds.right() - bounds.left() << bounds.bottom() - bounds.top();
+	QVector<QRgb> colors;
+	if (isPixmap)
+	{
+		ts.skipRawData(2);	// skip Version info, always 0
+		ts >> packType;
+		ts >> packSize;
+		ts >> horizontal_resolution >> vertical_resolution;
+		ts >> pixel_type >> bits_per_pixel >> component_count >> component_size;
+		ts >> plane_bytes >> color_table;
+		ts.skipRawData(4);
+//		qDebug() << "Pack Type" << packType;
+//		qDebug() << "Pack Size" << packSize;
+//		qDebug() << "Pixel Type" << pixel_type;
+//		qDebug() << "Bits per Pixel" << bits_per_pixel;
+//		qDebug() << "Component Count" << component_count << "Size" << component_size;
+	// now reading color Table
+		if ((opCode != 0x009A) && (opCode != 0x009B))
+		{
+			quint32 ct_seed;
+			quint16 ct_flags, ct_size;
+			ts >> ct_seed;
+			ts >> ct_flags >> ct_size;
+//			qDebug() << "ColorTable has" << ct_size << "Entries";
+			for (quint16 cc = 0; cc < ct_size+1; cc++)
+			{
+				quint16 cev, cRed, cGreen, cBlue;
+				ts >> cev >> cRed >> cGreen >> cBlue;
+				colors.append(qRgb(cRed, cGreen, cBlue));
+			}
+		}
+	}
+// reading scrRect
+	QRect scrRect = readRect(ts);
+	Q_UNUSED(scrRect);
+//	qDebug() << "Src Rect" << scrRect;
+// reading dstRect
+	QRect dstRect = readRect(ts);
+//	qDebug() << "Dst Rect" << dstRect;
+	ts.skipRawData(2);
+	if ((opCode == 0x0091) || (opCode == 0x0099) || (opCode == 0x009B))
+	{
+		quint16 dataLen;
+		ts >> dataLen;
+		alignStreamToWord(ts, dataLen-2);
+	}
+	quint16 pixRows = bounds.bottom() - bounds.top();
+	quint16 pixCols = bounds.right() - bounds.left();
+	QImage image;
+	if (isPixmap)
+	{
+		if (component_count == 1)
+		{
+			image = QImage(pixCols, pixRows, QImage::Format_Indexed8);
+			image.setColorTable(colors);
+		}
+		else
+			image = QImage(pixCols, pixRows, QImage::Format_ARGB32);
+	}
+	else
+		image = QImage(pixCols, pixRows, QImage::Format_Mono);
+	for (quint16 rr = 0; rr < pixRows; rr++)
+	{
+		quint16 pixByteCount;
+		if (bytesPerLine < 250)
+		{
+			quint8 byteCount;
+			ts >> byteCount;
+			pixByteCount = byteCount;
+		}
+		else
+			ts >> pixByteCount;
+		if (!skipOpcode)
+		{
+			QByteArray data;
+			data.resize(pixByteCount);
+			ts.readRawData(data.data(), pixByteCount);
+			int twoByte = 1;
+			if (component_size == 5)
+				twoByte = 2;
+			QByteArray img;
+			if (bytesPerLine < 8)
+				img = data;
+			else
+				img = decodeRLE(data, bytesPerLine, twoByte);
+			if ((opCode == 0x0098) || (opCode == 0x0099))
+			{
+				if (!isPixmap)
+				{
+					memcpy(image.scanLine(rr), img.data(), bytesPerLine);
+				}
+				else if (component_count == 1)
+				{
+					if (component_size == 4)
+					{
+						uchar *q = (uchar*)(image.scanLine(rr));
+						for (int xx = 0; xx < img.size(); xx++)
+						{
+							uchar i = (img[xx] >> 4) & 0x0F;
+							uchar j = img[xx] & 0x0F;
+							*q++ = i;
+							*q++ = j;
+						}
+					}
+					else
+						memcpy(image.scanLine(rr), img.data(), bytesPerLine);
+				}
+			}
+			else if ((opCode == 0x009A) || (opCode == 0x009B))
+			{
+				if (component_size == 5)
+				{
+					QRgb *q = (QRgb*)(image.scanLine(rr));
+					int imgDcount = 0;
+					for (quint16 xx = 0; xx < pixCols; xx++)
+					{
+						uchar i = img[imgDcount++];
+						uchar j = img[imgDcount++];
+						quint16 r = (i & 0x7c) << 1;
+						quint16 g = ((i & 0x03) << 6) | ((j & 0xe0) >> 2);
+						quint16 b = (j & 0x1f) << 3;
+						*q++ = qRgba(r, g, b, 255);
+					}
+				}
+				else if ((component_size == 8) || (component_size == 24))
+				{
+					QRgb *q = (QRgb*)(image.scanLine(rr));
+					for (uint xx = 0; xx < (uint) pixCols; xx++)
+					{
+						uchar r = 0;
+						uchar g = 0;
+						uchar b = 0;
+						uchar a = 255;
+						if (component_count == 3)
+						{
+							r = img[xx];
+							g = img[xx + pixCols];
+							b = img[xx + 2 * pixCols];
+						}
+						else if (component_count == 4)
+						{
+							a = 255 - img[xx];
+							r = img[xx + pixCols];
+							g = img[xx + 2 * pixCols];
+							b = img[xx + 3 * pixCols];
+						}
+						*q++ = qRgba(r, g, b, a);
+					}
+				}
+			}
+		}
+		else
+		{
+			ts.skipRawData(pixByteCount);
+		}
+	}
+	if (skipOpcode)
+	{
+		image.loadFromData(imageData);
+		isPixmap = true;
+		imageData.resize(0);
+	}
+	if ((component_size == 24) || (component_size == 8) || (component_size == 1) || (component_size == 5) || (component_size == 4) || (!isPixmap) || (skipOpcode))
+	{
+		image = image.convertToFormat(QImage::Format_ARGB32);
+		if (!isPixmap)
+			image.invertPixels();
+		imagePainter.drawImage(dstRect, image);
+		skipOpcode = false;
+	}
+	alignStreamToWord(ts, 0);
+}
+
+void ScImgDataLoader_PICT::handleQuickTime(QDataStream &ts, quint16 opCode)
+{
+//	qDebug() << "Handle QuickTime Data";
+	quint32 dataLenLong, matteSize, maskSize, dataLen;
+	quint16 mode;
+	ts >> dataLenLong;
+	uint pos = ts.device()->pos();
+	alignStreamToWord(ts, 38);		// Skip version and Matrix information
+	ts >> matteSize;
+	/*QRect matteRect =*/ readRect(ts);
+	if (opCode == 0x8200)
+	{
+		ts >> mode;
+		/*QRect srcRect =*/ readRect(ts);
+		alignStreamToWord(ts, 4);
+		ts >> maskSize;
+		if (matteSize != 0)
+		{
+			ts >> dataLen;
+			alignStreamToWord(ts, dataLen);
+			alignStreamToWord(ts, matteSize);
+		}
+		if (maskSize != 0)
+		{
+			ts >> dataLen;
+			alignStreamToWord(ts, dataLen);
+			alignStreamToWord(ts, maskSize);
+		}
+		quint32 cType, vendor, dummyLong, imgDataSize;
+		quint16 width, height, dummyShort;
+		ts >> dataLen;
+		ts >> cType;
+		if (cType == 0x6A706567)
+		{
+			ts >> dummyLong;
+			ts >> dummyShort;
+			ts >> dummyShort;
+			ts >> dummyShort;
+			ts >> dummyShort;
+			ts >> vendor;
+			ts >> dummyLong;
+			ts >> dummyLong;
+			ts >> width;
+			ts >> height;
+			ts >> dummyLong;
+			ts >> dummyLong;
+			ts >> imgDataSize;
+			alignStreamToWord(ts, 38);
+			imageData.resize(imgDataSize);
+			ts.readRawData(imageData.data(), imgDataSize);
+			skipOpcode = true;
+		}
+	}
+	else
+	{
+		if (matteSize != 0)
+		{
+			ts >> dataLen;
+			alignStreamToWord(ts, dataLen);
+			alignStreamToWord(ts, matteSize);
+		}
+		ts >> mode;
+		handlePixmap(ts, mode);
+		skipOpcode = true;
+	}
+	ts.device()->seek(pos + dataLenLong);
+//	qDebug() << "File Pos" << ts.device()->pos();
+}
+
+void ScImgDataLoader_PICT::handleComment(QDataStream &ts, bool longComment)
+{
+	quint16 commentCode;
+	ts >> commentCode;
+	switch (commentCode)
+	{
+/*		case 100:			// picAppComment
+			qDebug() << "Comment type: picAppComment";
+			break;
+		case 130:			// picDwgBeg
+			qDebug() << "Comment type: picDwgBeg";
+			break;
+		case 131:			// picDwgEnd
+			qDebug() << "Comment type: picDwgEnd";
+			break;
+		case 140:			// picGrpBeg
+			qDebug() << "Comment type: picGrpBeg";
+			break;
+		case 141:			// picGrpEnd
+			qDebug() << "Comment type: picGrpEnd";
+			break;
+		case 142:			// picBitBeg
+			qDebug() << "Comment type: picBitBeg";
+			break;
+		case 143:			// picBitEnd
+			qDebug() << "Comment type: picBitEnd";
+			break;
+		case 150:			// TextBegin
+			qDebug() << "Comment type: TextBegin";
+			break;
+		case 151:			// TextEnd
+			qDebug() << "Comment type: TextEnd";
+			break;
+		case 152:			// StringBegin
+			qDebug() << "Comment type: StringBegin";
+			break;
+		case 153:			// StringEnd
+			qDebug() << "Comment type: StringEnd";
+			break;
+		case 154:			// TextCenter
+			qDebug() << "Comment type: TextCenter";
+			break;
+		case 155:			// LineLayoutOff
+			qDebug() << "Comment type: LineLayoutOff";
+			break;
+		case 156:			// LineLayoutOn
+			qDebug() << "Comment type: LineLayoutOn";
+			break;
+		case 157:			// ClientLineLayout
+			qDebug() << "Comment type: ClientLineLayout";
+			break;
+		case 160:			// PolyBegin
+			qDebug() << "Comment type: PolyBegin";
+			break;
+		case 161:			// PolyEnd
+			qDebug() << "Comment type: PolyEnd";
+			break;
+		case 163:			// PolyIgnore
+			qDebug() << "Comment type: PolyIgnore";
+			break;
+		case 164:			// PolySmooth
+			qDebug() << "Comment type: PolySmooth";
+			break;
+		case 165:			// PolyClose
+			qDebug() << "Comment type: PolyClose";
+			break;
+		case 170:			// picArrw1 Arrowhead on 2nd point of line
+			qDebug() << "Comment type: picArrw1";
+			break;
+		case 171:			// picArrw2 Arrowhead on 1nd point of line
+			qDebug() << "Comment type: picArrw2";
+			break;
+		case 172:			// picArrw3 Arrowhead on both endpoints
+			qDebug() << "Comment type: picArrw3";
+			break;
+		case 173:			// picArrwEnd End of arrowhead comment
+			qDebug() << "Comment type: picArrwEnd";
+			break;
+		case 180:			// DashedLine
+			qDebug() << "Comment type: DashedLine";
+			break;
+		case 181:			// DashedStop
+			qDebug() << "Comment type: DashedStop";
+			break;
+		case 182:			// SetLineWidth
+			qDebug() << "Comment type: SetLineWidth";
+			break; */
+		case 190:			// PostScriptBegin
+			postscriptMode = true;
+//			qDebug() << "Comment type: PostScriptBegin";
+			break;
+		case 191:			// PostScriptEnd
+			postscriptMode = false;
+			textIsPostScript = false;
+//			qDebug() << "Comment type: PostScriptEnd";
+			break;
+		case 192:			// PostScriptHandle
+//			qDebug() << "Comment type: PostScriptHandle";
+			break;
+		case 193:			// PostScriptFile
+//			qDebug() << "Comment type: PostScriptFile";
+			break;
+		case 194:			// TextIsPostScript
+			textIsPostScript = true;
+//			qDebug() << "Comment type: TextIsPostScript";
+			break;
+/*		case 195:			// ResourcePS
+			qDebug() << "Comment type: ResourcePS";
+			break;
+		case 196:			// PSBeginNoSave
+			qDebug() << "Comment type: PSBeginNoSave";
+			break;
+		case 200:			// RotateBegin
+			qDebug() << "Comment type: RotateBegin";
+			break;
+		case 201:			// RotateEnd
+			qDebug() << "Comment type: RotateEnd";
+			break;
+		case 210:			// FormsPrinting
+			qDebug() << "Comment type: FormsPrinting";
+			break;
+		case 211:			// EndFormsPrinting
+			qDebug() << "Comment type: EndFormsPrinting";
+			break;
+		case 220:			// CMBeginProfile
+			qDebug() << "Comment type: CMBeginProfile";
+			break;
+		case 221:			// CMEndProfile
+			qDebug() << "Comment type: CMEndProfile";
+			break;
+		case 222:			// CMEnableMatching
+			qDebug() << "Comment type: CMEnableMatching";
+			break;
+		case 223:			// CMDisableMatching
+			qDebug() << "Comment type: CMDisableMatching";
+			break; */
+		default:
+//			qDebug() << "Unknown Pict-Comment" << commentCode;
+			break;
+	}
+	if (longComment)
+	{
+		quint16 dataLen;
+		ts >> dataLen;
+		alignStreamToWord(ts, dataLen);
+	}
+}
+
+QRect ScImgDataLoader_PICT::readRect(QDataStream &ts)
+{
+	qint16 RectX, RectY, RectW, RectH;
+	ts >> RectX >> RectY >> RectW >> RectH;
+	return QRect(QPoint(RectY, RectX), QPoint(RectH, RectW));
+}
+
+QByteArray ScImgDataLoader_PICT::decodeRLE(QByteArray &in, quint16 bytesPerLine, int multByte)
+{
+	QByteArray ret = QByteArray(bytesPerLine, ' ');
+	uchar *ptrOut, *ptrIn;
+	ptrOut = (uchar*)ret.data();
+	ptrIn = (uchar*)in.data();
+	quint16 count = 0;
+	uchar c, c2;
+	quint16 len;
+	while( count < in.size() )
+	{
+		c = *ptrIn++;
+		count++;
+		len = c;
+		if( len < 128 )
+		{
+			// Copy next len+1 bytes literally.
+			len++;
+			len *= multByte;
+			while( len != 0 )
+			{
+				*ptrOut++ = *ptrIn++;
+				len--;
+				count++;
+				if (multByte == 2)
+				{
+					*ptrOut++ = *ptrIn++;
+					len--;
+					count++;
+				}
+			}
+		}
+		else if( len > 128 )
+		{
+			// Next -len+1 bytes in the dest are replicated from next source byte.
+			// (Interpret len as a negative 8-bit int.)
+			len ^= 0xFF;
+			len += 2;
+			len *= multByte;
+			if (multByte == 2)
+			{
+				c = *ptrIn++;
+				count++;
+				c2 = *ptrIn++;
+				count++;
+				while( len != 0 )
+				{
+					*ptrOut++ = c;
+					*ptrOut++ = c2;
+					len--;
+					len--;
+				}
+			}
+			else
+			{
+				c = *ptrIn++;
+				count++;
+				while( len != 0 )
+				{
+					*ptrOut++ = c;
+					len--;
+				}
+			}
+		}
+		else if( len == 128 )
+		{
+			// No-op.
+		}
+	}
+	return ret;
+}
+
+QBrush ScImgDataLoader_PICT::setFillPattern()
+{
+	QImage image = QImage(8, 8, QImage::Format_Mono);
+	QVector<QRgb> colors;
+	colors.append(backColor.rgb());
+	colors.append(foreColor.rgb());
+	image.setColorTable(colors);
+	for (int rr = 0; rr < 8; rr++)
+	{
+		uchar *q = (uchar*)(image.scanLine(rr));
+		*q = patternData[rr];
+	}
+	image = image.convertToFormat(QImage::Format_ARGB32);
+	return QBrush(image);
+}

Modified: trunk/Scribus/scribus/scimgdataloader_pict.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/scimgdataloader_pict.h
==============================================================================
--- trunk/Scribus/scribus/scimgdataloader_pict.h (original)
+++ trunk/Scribus/scribus/scimgdataloader_pict.h Fri Oct 17 22:07:00 2014
@@ -1,100 +1,98 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-#ifndef SCIMGDATALOADER_PICT_H
-#define SCIMGDATALOADER_PICT_H
-
-#include "scimgdataloader.h"
-#include <QList>
-#include <QTransform>
-#include <QMultiMap>
-#include <QtGlobal>
-#include <QObject>
-#include <QString>
-#include <QRect>
-#include <QPainter>
-#include <QPainterPath>
-
-class ScImgDataLoader_PICT : public ScImgDataLoader
-{
-protected:
-
-	void initSupportedFormatList();
-
-public:
-	ScImgDataLoader_PICT(void);
-
-	virtual bool preloadAlphaChannel(const QString& fn, int page, int res, bool& hasAlpha);
-	virtual void loadEmbeddedProfile(const QString& fn, int page = 0);
-	virtual bool loadPicture(const QString& fn, int page, int res, bool thumbnail);
-
-private:
-	void parseHeader(QString fName, double &x, double &y, double &w, double &h);
-	void parsePict(QDataStream &ts);
-	void alignStreamToWord(QDataStream &ts, uint len);
-	void handleColor(QDataStream &ts, bool back);
-	void handleColorRGB(QDataStream &ts, bool back);
-	void handlePenPattern(QDataStream &ts);
-	void handlePolygon(QDataStream &ts, quint16 opCode);
-	void handleShape(QDataStream &ts, quint16 opCode);
-	void handleSameShape(QDataStream &ts, quint16 opCode);
-	void handleFontName(QDataStream &ts);
-	void handleTextSize(QDataStream &ts);
-	void handleTextFont(QDataStream &ts);
-	void handleTextStyle(QDataStream &ts);
-	void handleTextMode(QDataStream &ts);
-	void handleLongText(QDataStream &ts);
-	void handleDHText(QDataStream &ts);
-	void handleDVText(QDataStream &ts);
-	void handleDHVText(QDataStream &ts);
-	void createTextPath(QByteArray textString);
-	void handlePenMode(QDataStream &ts);
-	void handlePenSize(QDataStream &ts);
-	void handleOvalSize(QDataStream &ts);
-	void handleShortLine(QDataStream &ts);
-	void handleShortLineFrom(QDataStream &ts);
-	void handleLine(QDataStream &ts);
-	void handleLineFrom(QDataStream &ts);
-	void handlePixmap(QDataStream &ts, quint16 opCode);
-	void handleQuickTime(QDataStream &ts, quint16 opCode);
-	void handleComment(QDataStream &ts, bool longComment);
-	QRect readRect(QDataStream &ts);
-	QByteArray decodeRLE(QByteArray &in, quint16 bytesPerLine, int twoByte);
-	QBrush setFillPattern();
-
-	int baseX, baseY;
-	int docWidth;
-	int docHeight;
-	double resX, resY;
-
-	double LineW;
-	QColor backColor;
-	QColor foreColor;
-	bool patternMode;
-	QByteArray patternData;
-	QRect currRect;
-	QBrush currPatternBrush;
-	int currRectItemNr;
-	int currRectType;
-	QRect lastImageRect;
-	QPoint ovalSize;
-	QMap<int, QString> fontMap;
-	int currentTextSize;
-	int currentFontID;
-	int currentFontStyle;
-	QByteArray imageData;
-
-	QPainterPath Coords;
-	QPoint currentPoint;
-	QPoint currentPointT;
-	QPainter imagePainter;
-	bool postscriptMode;
-	bool textIsPostScript;
-	int pctVersion;
-	bool skipOpcode;
-};
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#ifndef SCIMGDATALOADER_PICT_H
+#define SCIMGDATALOADER_PICT_H
+
+#include "scimgdataloader.h"
+#include <QList>
+#include <QTransform>
+#include <QMultiMap>
+#include <QtGlobal>
+#include <QObject>
+#include <QString>
+#include <QRect>
+#include <QPainter>
+#include <QPainterPath>
+
+class ScImgDataLoader_PICT : public ScImgDataLoader
+{
+protected:
+
+	void initSupportedFormatList();
+
+public:
+	ScImgDataLoader_PICT(void);
+
+	virtual bool preloadAlphaChannel(const QString& fn, int page, int res, bool& hasAlpha);
+	virtual void loadEmbeddedProfile(const QString& fn, int page = 0);
+	virtual bool loadPicture(const QString& fn, int page, int res, bool thumbnail);
+
+private:
+	void parseHeader(QString fName, double &x, double &y, double &w, double &h);
+	void parsePict(QDataStream &ts);
+	void alignStreamToWord(QDataStream &ts, uint len);
+	void handleColor(QDataStream &ts, bool back);
+	void handleColorRGB(QDataStream &ts, bool back);
+	void handlePenPattern(QDataStream &ts);
+	void handlePolygon(QDataStream &ts, quint16 opCode);
+	void handleShape(QDataStream &ts, quint16 opCode);
+	void handleSameShape(QDataStream &ts, quint16 opCode);
+	void handleFontName(QDataStream &ts);
+	void handleTextSize(QDataStream &ts);
+	void handleTextFont(QDataStream &ts);
+	void handleTextStyle(QDataStream &ts);
+	void handleTextMode(QDataStream &ts);
+	void handleLongText(QDataStream &ts);
+	void handleDHText(QDataStream &ts);
+	void handleDVText(QDataStream &ts);
+	void handleDHVText(QDataStream &ts);
+	void createTextPath(QByteArray textString);
+	void handlePenMode(QDataStream &ts);
+	void handlePenSize(QDataStream &ts);
+	void handleOvalSize(QDataStream &ts);
+	void handleShortLine(QDataStream &ts);
+	void handleShortLineFrom(QDataStream &ts);
+	void handleLine(QDataStream &ts);
+	void handleLineFrom(QDataStream &ts);
+	void handlePixmap(QDataStream &ts, quint16 opCode);
+	void handleQuickTime(QDataStream &ts, quint16 opCode);
+	void handleComment(QDataStream &ts, bool longComment);
+	QRect readRect(QDataStream &ts);
+	QByteArray decodeRLE(QByteArray &in, quint16 bytesPerLine, int twoByte);
+	QBrush setFillPattern();
+
+	int baseX, baseY;
+	int docWidth;
+	int docHeight;
+	double resX, resY;
+
+	double LineW;
+	QColor backColor;
+	QColor foreColor;
+	bool patternMode;
+	QByteArray patternData;
+	QRect currRect;
+	QBrush currPatternBrush;
+	QRect lastImageRect;
+	QPoint ovalSize;
+	QMap<int, QString> fontMap;
+	int currentTextSize;
+	int currentFontID;
+	int currentFontStyle;
+	QByteArray imageData;
+
+	QPainterPath Coords;
+	QPoint currentPoint;
+	QPoint currentPointT;
+	QPainter imagePainter;
+	bool postscriptMode;
+	bool textIsPostScript;
+	int pctVersion;
+	bool skipOpcode;
+};
+
+#endif

Modified: trunk/Scribus/scribus/scpainter.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/scpainter.h
==============================================================================
--- trunk/Scribus/scribus/scpainter.h (original)
+++ trunk/Scribus/scribus/scpainter.h Fri Oct 17 22:07:00 2014
@@ -183,7 +183,6 @@
 	double fill_trans;
 	bool m_fillRule;
 	int fillMode;				// 0 = none, 1 = solid, 2 = gradient 3 = pattern 4 = hatch
-	int gradientMode;		// 1 = linear, 2 = radial, 3 = 4colour
 	double patternScaleX;
 	double patternScaleY;
 	double patternOffsetX;

Modified: trunk/Scribus/scribus/scpainterex_ps2.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/scpainterex_ps2.h
==============================================================================
--- trunk/Scribus/scribus/scpainterex_ps2.h (original)
+++ trunk/Scribus/scribus/scpainterex_ps2.h Fri Oct 17 22:07:00 2014
@@ -210,7 +210,6 @@
 	double m_fillTrans;
 	bool   m_fillRule;
 	int    m_fillMode;			// 0 = none, 1 = solid, 2 = gradient
-	int    m_gradientMode;		// 1 = linear, 2 = radial
 
 	double m_patternScaleX;
 	double m_patternScaleY;
@@ -236,8 +235,6 @@
 	double m_offset;
 /* Transformation Stack */
 	QStack<QTransform> m_stack;
-/* Zoom Factor of the Painter */
-	double m_zoomFactor;
 
 /* Some data to describe state of drawing */	
 	bool m_pathIsClosed;

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Fri Oct 17 22:07:00 2014
@@ -9893,7 +9893,6 @@
 			ss->set("IS_CONTOUR", true);
 			undoManager->action(currItem, ss, Um::IBorder);
 		}
-		FPoint tp2(getMinClipF(&currItem->ContourLine));
 		FPoint tp(getMaxClipF(&currItem->ContourLine));
 		ma.translate(0, qRound(tp.y()));
 		ma.scale(1, -1);

Modified: trunk/Scribus/scribus/ui/sclistwidgetdelegate.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19590&path=/trunk/Scribus/scribus/ui/sclistwidgetdelegate.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/sclistwidgetdelegate.cpp (original)
+++ trunk/Scribus/scribus/ui/sclistwidgetdelegate.cpp Fri Oct 17 22:07:00 2014
@@ -1,66 +1,64 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/***************************************************************************
-						  sclistwidgetdelegate.cpp  -  description
-							 -------------------
-	begin                : Sat June 18 2011
-	copyright            : (C) 2011 by Franz Schmid
-	email                : Franz.Schmid at altmuehlnet.de
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include <QPainter>
-#include "sclistwidgetdelegate.h"
-
-ScListWidgetDelegate::ScListWidgetDelegate(QListWidget *view, QWidget *parent) : QItemDelegate(parent), m_view(view)
-{
-	m_dispIconOnly = false;
-}
-
-void ScListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
-	const QAbstractItemModel *model = index.model();
-	Q_ASSERT(model);
-	if (m_dispIconOnly)
-	{
-		painter->save();
-		QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
-		painter->drawPixmap(option.rect, icon.pixmap(m_view->iconSize()));
-		painter->restore();
-	}
-	else
-		QItemDelegate::paint(painter, option, index);
-}
-
-QSize ScListWidgetDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const
-{
-	QStyleOptionViewItem option = opt;
-	if (m_dispIconOnly)
-	{
-		QSize sz = m_view->iconSize();
-		return sz;
-	}
-	return QItemDelegate::sizeHint(opt, index);
-}
-
-void ScListWidgetDelegate::setIconOnly(bool setter)
-{
-	m_dispIconOnly = setter;
-}
-
-bool ScListWidgetDelegate::iconOnly()
-{
-	return m_dispIconOnly;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/***************************************************************************
+						  sclistwidgetdelegate.cpp  -  description
+							 -------------------
+	begin                : Sat June 18 2011
+	copyright            : (C) 2011 by Franz Schmid
+	email                : Franz.Schmid at altmuehlnet.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include <QPainter>
+#include "sclistwidgetdelegate.h"
+
+ScListWidgetDelegate::ScListWidgetDelegate(QListWidget *view, QWidget *parent) : QItemDelegate(parent), m_view(view)
+{
+	m_dispIconOnly = false;
+}
+
+void ScListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+	if (m_dispIconOnly)
+	{
+		painter->save();
+		QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
+		painter->drawPixmap(option.rect, icon.pixmap(m_view->iconSize()));
+		painter->restore();
+	}
+	else
+		QItemDelegate::paint(painter, option, index);
+}
+
+QSize ScListWidgetDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const
+{
+	QStyleOptionViewItem option = opt;
+	if (m_dispIconOnly)
+	{
+		QSize sz = m_view->iconSize();
+		return sz;
+	}
+	return QItemDelegate::sizeHint(opt, index);
+}
+
+void ScListWidgetDelegate::setIconOnly(bool setter)
+{
+	m_dispIconOnly = setter;
+}
+
+bool ScListWidgetDelegate::iconOnly()
+{
+	return m_dispIconOnly;
+}




More information about the scribus-commit mailing list