r13885 by fschmid - Initial committ for the WPG (WordPerfect Graphics) importer, needs libwpd-0.8.14 and libwpg-0.1.3 to work.
scribus-commit
scribus-commit at lists.scribus.net
Wed Aug 26 05:48:14 CEST 2009
Revision: 13885
Author: fschmid
Date: 2009-08-20T11:55:47.444335Z
Commit message: Initial committ for the WPG (WordPerfect Graphics) importer, needs libwpd-0.8.14 and libwpg-0.1.3 to work.
Changeset:
M /trunk/Scribus/scribus/util_formats.cpp
A /trunk/Scribus/scribus/plugins/wpgimplugin/importwpgplugin.cpp
A /trunk/Scribus/scribus/plugins/wpgimplugin/importwpg.cpp
M /trunk/Scribus/scribus/plugins/CMakeLists.txt
M /trunk/Scribus/scribus/util_formats.h
A /trunk/Scribus/scribus/plugins/wpgimplugin/CMakeLists.txt
A /trunk/Scribus/scribus/plugins/wpgimplugin/importwpgplugin.h
A /trunk/Scribus/scribus/plugins/wpgimplugin/importwpg.h
A /trunk/Scribus/scribus/plugins/wpgimplugin
M /trunk/Scribus/scribus/plugins/formatidlist.h
Diffs:
Index: scribus/util_formats.cpp
===================================================================
--- scribus/util_formats.cpp (revision 13884)
+++ scribus/util_formats.cpp (revision 13885)
@@ -31,6 +31,7 @@
m_fmts.insert(FormatsManager::AI, QStringList() << "ai");
m_fmts.insert(FormatsManager::XFIG, QStringList() << "fig");
m_fmts.insert(FormatsManager::CVG, QStringList() << "cvg");
+ m_fmts.insert(FormatsManager::WPG, QStringList() << "wpg");
m_fmtNames[FormatsManager::EPS] = QObject::tr("Encapsulated PostScript");
m_fmtNames[FormatsManager::GIF] = QObject::tr("GIF");
@@ -47,6 +48,7 @@
m_fmtNames[FormatsManager::AI] = QObject::tr("Adobe Illustrator");
m_fmtNames[FormatsManager::XFIG] = QObject::tr("Xfig File");
m_fmtNames[FormatsManager::CVG] = QObject::tr("Calamus Cvg File");
+ m_fmtNames[FormatsManager::WPG] = QObject::tr("Word Perfect Wpg File");
m_fmtMimeTypes.insert(FormatsManager::EPS, QStringList() << "application/postscript");
m_fmtMimeTypes.insert(FormatsManager::GIF, QStringList() << "image/gif");
@@ -63,6 +65,7 @@
m_fmtMimeTypes.insert(FormatsManager::AI, QStringList() << "application/illustrator");
m_fmtMimeTypes.insert(FormatsManager::XFIG, QStringList() << "image/x-xfig");
m_fmtMimeTypes.insert(FormatsManager::CVG, QStringList() << "");
+ m_fmtMimeTypes.insert(FormatsManager::WPG, QStringList() << "");
QMapIterator<int, QStringList> i(m_fmts);
while (i.hasNext())
Index: scribus/util_formats.h
===================================================================
--- scribus/util_formats.h (revision 13884)
+++ scribus/util_formats.h (revision 13885)
@@ -36,9 +36,9 @@
enum ScImageFormatType
{
- ALLIMAGES = 1|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384,
+ ALLIMAGES = 1|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768,
IMAGESIMGFRAME = 1|2|4|16|32|64|128|256|512, // all Types suitable for Image Frames
- VECTORIMAGES = 1|64|1024|2048|16384, // All pure vector image types
+ VECTORIMAGES = 1|64|1024|2048|16384|32768, // All pure vector image types
RASTORIMAGES = 2|4|8|32|512, // All pure rastor image types
EPS = 1, // Encapsulated PostScript
GIF = 2, // GIF files
@@ -51,10 +51,11 @@
TIFF = 256, // TIFF
XPM = 512, // XPM files
WMF = 1024, // WMF files
- SVG = 2048, // WMF files
+ SVG = 2048, // SVG files
AI = 4096, // Adobe Illustrator files
XFIG = 8192, // Xfig files
CVG = 16384, // Calamus Cvg files
+ WPG = 32768, // Word Perfect WPG files
};
/*
Index: scribus/plugins/formatidlist.h
===================================================================
--- scribus/plugins/formatidlist.h (revision 13884)
+++ scribus/plugins/formatidlist.h (revision 13885)
@@ -23,6 +23,7 @@
#define FORMATID_AIIMPORT 105
#define FORMATID_XFIGIMPORT 106
#define FORMATID_CVGIMPORT 107
+#define FORMATID_WPGIMPORT 108
#define FORMATID_PDFIMPORT 120
// EXPORT
Index: scribus/plugins/wpgimplugin/importwpgplugin.cpp
===================================================================
--- scribus/plugins/wpgimplugin/importwpgplugin.cpp (revision 0)
+++ scribus/plugins/wpgimplugin/importwpgplugin.cpp (revision 13885)
@@ -0,0 +1,162 @@
+/*
+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 "commonstrings.h"
+#include "ui/customfdialog.h"
+#include "importwpg.h"
+#include "importwpgplugin.h"
+#include "menumanager.h"
+#include "page.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "scraction.h"
+#include "scribuscore.h"
+#include "undomanager.h"
+#include "util_formats.h"
+
+
+int importwpg_getPluginAPIVersion()
+{
+ return PLUGIN_API_VERSION;
+}
+
+ScPlugin* importwpg_getPlugin()
+{
+ ImportWpgPlugin* plug = new ImportWpgPlugin();
+ Q_CHECK_PTR(plug);
+ return plug;
+}
+
+void importwpg_freePlugin(ScPlugin* plugin)
+{
+ ImportWpgPlugin* plug = dynamic_cast<ImportWpgPlugin*>(plugin);
+ Q_ASSERT(plug);
+ delete plug;
+}
+
+ImportWpgPlugin::ImportWpgPlugin() : LoadSavePlugin(),
+ importAction(new ScrAction(ScrAction::DLL, QPixmap(), QPixmap(), "", QKeySequence(), this))
+{
+ // Set action info in languageChange, so we only have to do it in one
+ // place. This includes registering file format support.
+ languageChange();
+}
+/*
+void ImportXfigPlugin::addToMainWindowMenu(ScribusMainWindow *mw)
+{
+ importAction->setEnabled(true);
+ connect( importAction, SIGNAL(triggered()), SLOT(import()) );
+ mw->scrMenuMgr->addMenuItem(importAction, "FileImport");
+}
+*/
+void ImportWpgPlugin::languageChange()
+{
+ importAction->setText( tr("Import WPG..."));
+ // (Re)register file format support
+ unregisterAll();
+ registerFormats();
+}
+
+ImportWpgPlugin::~ImportWpgPlugin()
+{
+ unregisterAll();
+};
+
+const QString ImportWpgPlugin::fullTrName() const
+{
+ return QObject::tr("WPG Importer");
+}
+
+
+const ScActionPlugin::AboutData* ImportWpgPlugin::getAboutData() const
+{
+ AboutData* about = new AboutData;
+ about->authors = "Franz Schmid <franz at scribus.info>";
+ about->shortDescription = tr("Imports WPG Files");
+ about->description = tr("Imports most WPG files into the current document,\nconverting their vector data into Scribus objects.");
+ about->license = "GPL";
+ Q_CHECK_PTR(about);
+ return about;
+}
+
+void ImportWpgPlugin::deleteAboutData(const AboutData* about) const
+{
+ Q_ASSERT(about);
+ delete about;
+}
+
+void ImportWpgPlugin::registerFormats()
+{
+ FileFormat fmt(this);
+ fmt.trName = FormatsManager::instance()->nameOfFormat(FormatsManager::WPG); // Human readable name
+ fmt.formatId = FORMATID_WPGIMPORT;
+ fmt.filter = FormatsManager::instance()->extensionsForFormat(FormatsManager::WPG); // QFileDialog filter
+ fmt.nameMatch = QRegExp("\\."+FormatsManager::instance()->extensionListForFormat(FormatsManager::WPG, 1)+"$", Qt::CaseInsensitive);
+ fmt.load = true;
+ fmt.save = false;
+ fmt.mimeTypes = FormatsManager::instance()->mimetypeOfFormat(FormatsManager::WPG); // MIME types
+ fmt.priority = 64; // Priority
+ registerFormat(fmt);
+}
+
+bool ImportWpgPlugin::fileSupported(QIODevice* /* file */, const QString & fileName) const
+{
+ return true;
+}
+
+bool ImportWpgPlugin::loadFile(const QString & fileName, const FileFormat &, int flags, int /*index*/)
+{
+ // There's only one format to handle, so we just call import(...)
+ return import(fileName, flags);
+}
+
+bool ImportWpgPlugin::import(QString fileName, int flags)
+{
+ if (!checkFlags(flags))
+ return false;
+ if( fileName.isEmpty() )
+ {
+ flags |= lfInteractive;
+ PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("importwpg");
+ QString wdir = prefs->get("wdir", ".");
+ CustomFDialog diaf(ScCore->primaryMainWindow(), wdir, QObject::tr("Open"), tr("All Supported Formats")+" (*.wpg *.WPG);;All Files (*)");
+ if (diaf.exec())
+ {
+ fileName = diaf.selectedFile();
+ prefs->set("wdir", fileName.left(fileName.lastIndexOf("/")));
+ }
+ else
+ return true;
+ }
+ m_Doc=ScCore->primaryMainWindow()->doc;
+ UndoTransaction* activeTransaction = NULL;
+ bool emptyDoc = (m_Doc == NULL);
+ bool hasCurrentPage = (m_Doc && m_Doc->currentPage());
+ TransactionSettings trSettings;
+ trSettings.targetName = hasCurrentPage ? m_Doc->currentPage()->getUName() : "";
+ trSettings.targetPixmap = Um::IImageFrame;
+ trSettings.actionName = Um::ImportXfig;
+ trSettings.description = fileName;
+ trSettings.actionPixmap = Um::IXFIG;
+ if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
+ UndoManager::instance()->setUndoEnabled(false);
+ if (UndoManager::undoEnabled())
+ activeTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction(trSettings));
+ WpgPlug *dia = new WpgPlug(m_Doc, flags);
+ Q_CHECK_PTR(dia);
+ dia->import(fileName, trSettings, flags);
+ if (activeTransaction)
+ {
+ activeTransaction->commit();
+ delete activeTransaction;
+ activeTransaction = NULL;
+ }
+ if (emptyDoc || !(flags & lfInteractive) || !(flags & lfScripted))
+ UndoManager::instance()->setUndoEnabled(true);
+ delete dia;
+ return true;
+}
Index: scribus/plugins/wpgimplugin/importwpg.cpp
===================================================================
--- scribus/plugins/wpgimplugin/importwpg.cpp (revision 0)
+++ scribus/plugins/wpgimplugin/importwpg.cpp (revision 13885)
@@ -0,0 +1,678 @@
+/*
+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 <QStack>
+#include <QDebug>
+
+#include <cmath>
+#include <cstdlib>
+
+#include "commonstrings.h"
+#include "ui/customfdialog.h"
+#include "importwpg.h"
+#include "loadsaveplugin.h"
+#include "ui/missing.h"
+#include "ui/multiprogressdialog.h"
+#include "pagesize.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "prefsmanager.h"
+#include "prefstable.h"
+#include "ui/propertiespalette.h"
+#include "rawimage.h"
+#include "scclocale.h"
+#include "sccolorengine.h"
+#include "scconfig.h"
+#include "scmimedata.h"
+#include "scpaths.h"
+#include "scpattern.h"
+#include "scpattern.h"
+#include "scribus.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"
+#include <stdio.h>
+#include <libwpg/WPGStreamImplementation.h>
+
+extern SCRIBUS_API ScribusQApp * ScQApp;
+
+ScrPainter::ScrPainter(): libwpg::WPGPaintInterface()
+{
+}
+
+void ScrPainter::startGraphics(double width, double height)
+{
+ CurrColorFill = "White";
+ CurrFillShade = 100.0;
+ CurrColorStroke = "Black";
+ CurrStrokeShade = 100.0;
+ CurrStrokeTrans = 0.0;
+ CurrFillTrans = 0.0;
+ Coords.resize(0);
+ Coords.svgInit();
+ LineW = 1.0;
+ fillrule = false;
+ gradientAngle = 0.0;
+ isGradient = false;
+ currentGradient = VGradient(VGradient::linear);
+ currentGradient.clearStops();
+ currentGradient.setRepeatMethod( VGradient::none );
+ dashArray.clear();
+// printf("RawPainter::startGraphics(width: %.4fin, height: %.4fin)\n", width, height);
+}
+
+void ScrPainter::endGraphics()
+{
+// printf("RawPainter::endGraphics\n");
+}
+
+void ScrPainter::startLayer(unsigned int id)
+{
+ printf("RawPainter::startLayer %d\n", id);
+}
+
+void ScrPainter::endLayer(unsigned int id)
+{
+ printf("RawPainter::endLayer %d\n", id);
+}
+
+void ScrPainter::setPen(const libwpg::WPGPen& pen)
+{
+ LineW = 72 * pen.width;
+ ScColor tmp;
+ ColorList::Iterator it;
+ CurrColorStroke = CommonStrings::None;
+ CurrStrokeShade = 100.0;
+ if (LineW != 0.0)
+ {
+ int Rc, Gc, Bc, hR, hG, hB;
+ bool found = false;
+ Rc = pen.foreColor.red;
+ Gc = pen.foreColor.green;
+ Bc = pen.foreColor.blue;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ CurrColorStroke = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setColorRGB(Rc, Gc, Bc);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString newColorName = "FromWPG"+tmp.name();
+ m_Doc->PageColors.insert(newColorName, tmp);
+ importedColors.append(newColorName);
+ CurrColorStroke = newColorName;
+ }
+ CurrStrokeTrans = pen.foreColor.alpha / 256.0;
+ if(!pen.solid)
+ {
+ dashArray.clear();
+ for(unsigned i = 0; i < pen.dashArray.count(); i++)
+ {
+ dashArray.append(pen.dashArray.at(i)*LineW);
+ }
+ }
+ }
+}
+
+void ScrPainter::setBrush(const libwpg::WPGBrush& brush)
+{
+ ScColor tmp;
+ ColorList::Iterator it;
+ CurrColorFill = CommonStrings::None;
+ CurrFillShade = 100.0;
+ QColor c;
+ int Rc, Gc, Bc, hR, hG, hB;
+ if (brush.style != libwpg::WPGBrush::NoBrush)
+ {
+ if(brush.style == libwpg::WPGBrush::Solid)
+ {
+ bool found = false;
+ Rc = brush.foreColor.red;
+ Gc = brush.foreColor.green;
+ Bc = brush.foreColor.blue;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ CurrColorFill = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setColorRGB(Rc, Gc, Bc);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString newColorName = "FromWPG"+tmp.name();
+ m_Doc->PageColors.insert(newColorName, tmp);
+ importedColors.append(newColorName);
+ CurrColorFill = newColorName;
+ }
+ CurrFillTrans = brush.foreColor.alpha / 256.0;
+ }
+ else if (brush.style == libwpg::WPGBrush::Gradient)
+ {
+ gradientAngle = brush.gradient.angle();
+ isGradient = true;
+ currentGradient = VGradient(VGradient::linear);
+ currentGradient.clearStops();
+ for(unsigned c = 0; c < brush.gradient.count(); c++)
+ {
+ QString currStopColor = CommonStrings::None;
+ bool found = false;
+ Rc = brush.gradient.stopColor(c).red;
+ Gc = brush.gradient.stopColor(c).green;
+ Bc = brush.gradient.stopColor(c).blue;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ currStopColor = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setColorRGB(Rc, Gc, Bc);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString newColorName = "FromWPG"+tmp.name();
+ m_Doc->PageColors.insert(newColorName, tmp);
+ importedColors.append(newColorName);
+ currStopColor = newColorName;
+ }
+ const ScColor& gradC = m_Doc->PageColors[currStopColor];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), fabs(brush.gradient.stopOffset(c)), 0.5, 1.0, currStopColor, 100 );
+ }
+ }
+ }
+ switch(brush.style)
+ {
+ case libwpg::WPGBrush::NoBrush: break;
+ case libwpg::WPGBrush::Solid: break;
+ case libwpg::WPGBrush::Pattern: printf("pattern\n"); break;
+ case libwpg::WPGBrush::Gradient: break;
+ default: printf("unknown\n"); break;
+ }
+}
+
+void ScrPainter::setFillRule(FillRule rule)
+{
+ if(rule == libwpg::WPGPaintInterface::WindingFill)
+ fillrule = false;
+ else
+ fillrule = true;
+}
+
+void ScrPainter::drawRectangle(const libwpg::WPGRect& rect, double rx, double ry)
+{
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX, baseY, rect.width() * 72.0, rect.height() * 72.0, LineW, CurrColorFill, CurrColorStroke, true);
+ PageItem *ite = m_Doc->Items->at(z);
+ if ((rx != 0) || (ry != 0))
+ {
+ ite->setCornerRadius(qMax(72*rx, 72*ry));
+ ite->SetFrameRound();
+ m_Doc->setRedrawBounding(ite);
+ }
+ QMatrix mm = QMatrix();
+ mm.translate(72*rect.x1, 72*rect.y1);
+ ite->PoLine.map(mm);
+ finishItem(ite);
+}
+
+void ScrPainter::drawEllipse(const libwpg::WPGPoint& center, double rx, double ry)
+{
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX, baseY, rx * 144.0, ry * 144.0, LineW, CurrColorFill, CurrColorStroke, true);
+ PageItem *ite = m_Doc->Items->at(z);
+ QMatrix mm = QMatrix();
+ mm.translate(72*center.x, 72*center.y);
+ ite->PoLine.map(mm);
+ finishItem(ite);
+}
+
+void ScrPainter::drawPolygon(const libwpg::WPGPointArray& vertices)
+{
+ if(vertices.count() < 2)
+ return;
+ Coords.resize(0);
+ Coords.svgInit();
+ PageItem *ite;
+ Coords.svgMoveTo(72 * vertices[0].x, 72 * vertices[0].y);
+ for(unsigned i = 1; i < vertices.count(); i++)
+ {
+ Coords.svgLineTo(72 * vertices[i].x, 72 * vertices[i].y);
+ }
+ Coords.svgClosePath();
+ if (Coords.size() > 0)
+ {
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+ }
+}
+
+void ScrPainter::drawPath(const libwpg::WPGPath& path)
+{
+ Coords.resize(0);
+ Coords.svgInit();
+ PageItem *ite;
+ for(unsigned i = 0; i < path.count(); i++)
+ {
+ libwpg::WPGPathElement element = path.element(i);
+ libwpg::WPGPoint point = element.point;
+ switch(element.type)
+ {
+ case libwpg::WPGPathElement::MoveToElement:
+ Coords.svgMoveTo(72 * point.x, 72 * point.y);
+ break;
+ case libwpg::WPGPathElement::LineToElement:
+ Coords.svgLineTo(72 * point.x, 72 * point.y);
+ break;
+ case libwpg::WPGPathElement::CurveToElement:
+ Coords.svgCurveToCubic(72*element.extra1.x, 72*element.extra1.y, 72*element.extra2.x, 72*element.extra2.y, 72 * point.x, 72 * point.y);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if(path.closed)
+ Coords.svgClosePath();
+ if (Coords.size() > 0)
+ {
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+ }
+}
+
+void ScrPainter::finishItem(PageItem* ite)
+{
+ ite->ClipEdited = true;
+ ite->Frame = false;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setFillEvenOdd(fillrule);
+ ite->setLineShade(CurrStrokeShade);
+ ite->setFillTransparency(CurrFillTrans);
+ ite->setLineTransparency(CurrStrokeTrans);
+ ite->DashValues = dashArray;
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ ite->OldB2 = ite->width();
+ ite->OldH2 = ite->height();
+ if (isGradient)
+ {
+ ite->fill_gradient = currentGradient;
+ ite->GrType = 6;
+ QMatrix m1;
+ m1.rotate(-gradientAngle);
+ ite->GrStartX = 0;
+ ite->GrStartY = 0;
+ QPointF target = m1.map(QPointF(ite->width(), 0.0));
+ ite->GrEndX = target.x();
+ ite->GrEndY = target.y();
+ }
+ ite->updateClip();
+ Elements.append(ite);
+ isGradient = false;
+}
+
+void ScrPainter::drawBitmap(const libwpg::WPGBitmap& /*bitmap*/)
+{
+ printf("RawPainter::drawBitmap\n");
+}
+
+void ScrPainter::drawImageObject(const libwpg::WPGBinaryData& /*binaryData*/)
+{
+ printf("RawPainter::drawBinaryData\n");
+}
+
+
+WpgPlug::WpgPlug(ScribusDoc* doc, int flags)
+{
+ tmpSel=new Selection(this, false);
+ m_Doc=doc;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+}
+
+bool WpgPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
+{
+ QString fName = fNameIn;
+ bool success = false;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+ importerFlags = flags;
+ cancel = false;
+ double x, y, b, h;
+ bool ret = false;
+ QFileInfo fi = QFileInfo(fName);
+ if ( !ScCore->usingGUI() )
+ {
+ interactive = false;
+ showProgress = false;
+ }
+ baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/"));
+ if ( showProgress )
+ {
+ ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
+ progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
+ QStringList barNames, barTexts;
+ barNames << "GI";
+ barTexts << tr("Analyzing File:");
+ QList<bool> barsNumeric;
+ barsNumeric << false;
+ progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
+ progressDialog->setOverallTotalSteps(3);
+ progressDialog->setOverallProgress(0);
+ progressDialog->setProgress("GI", 0);
+ progressDialog->show();
+ connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
+ qApp->processEvents();
+ }
+ else
+ progressDialog = NULL;
+/* Set default Page to size defined in Preferences */
+ x = 0.0;
+ y = 0.0;
+ b = 0.0;
+ h = 0.0;
+ if (progressDialog)
+ {
+ progressDialog->setOverallProgress(1);
+ qApp->processEvents();
+ }
+// parseHeader(fName, b, h);
+ if (b == 0.0)
+ b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
+ if (h == 0.0)
+ h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
+ docWidth = b;
+ docHeight = h;
+ baseX = 0;
+ baseY = 0;
+ if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
+ {
+ m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
+ m_Doc->addPage(0);
+ m_Doc->view()->addPage(0, true);
+ baseX = 0;
+ baseY = 0;
+ }
+ else
+ {
+ if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
+ {
+ m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+ ScCore->primaryMainWindow()->HaveNewDoc();
+ ret = true;
+ baseX = 0;
+ baseY = 0;
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ }
+ }
+ if ((!ret) && (interactive))
+ {
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ }
+ if ((ret) || (!interactive))
+ {
+ if (docWidth > docHeight)
+ m_Doc->PageOri = 1;
+ else
+ m_Doc->PageOri = 0;
+ m_Doc->m_pageSize = "Custom";
+ }
+ Elements.clear();
+ FPoint minSize = m_Doc->minCanvasCoordinate;
+ FPoint maxSize = m_Doc->maxCanvasCoordinate;
+ FPoint cOrigin = m_Doc->view()->canvasOrigin();
+ m_Doc->setLoading(true);
+ m_Doc->DoDrawing = false;
+ m_Doc->view()->updatesOn(false);
+ m_Doc->scMW()->ScriptRunning = true;
+ qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+ QString CurDirP = QDir::currentPath();
+ QDir::setCurrent(fi.path());
+ if (convert(fName))
+ {
+ tmpSel->clear();
+ QDir::setCurrent(CurDirP);
+ if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
+ {
+ bool isGroup = true;
+ int firstElem = -1;
+ if (Elements.at(0)->Groups.count() != 0)
+ firstElem = Elements.at(0)->Groups.top();
+ for (int bx = 0; bx < Elements.count(); ++bx)
+ {
+ PageItem* bxi = Elements.at(bx);
+ if (bxi->Groups.count() != 0)
+ {
+ if (bxi->Groups.top() != firstElem)
+ isGroup = false;
+ }
+ else
+ isGroup = false;
+ }
+ if (!isGroup)
+ {
+ double minx = 99999.9;
+ double miny = 99999.9;
+ double maxx = -99999.9;
+ double maxy = -99999.9;
+ uint lowestItem = 999999;
+ uint highestItem = 0;
+ for (int a = 0; a < Elements.count(); ++a)
+ {
+ Elements.at(a)->Groups.push(m_Doc->GroupCounter);
+ PageItem* currItem = Elements.at(a);
+ lowestItem = qMin(lowestItem, currItem->ItemNr);
+ highestItem = qMax(highestItem, currItem->ItemNr);
+ double x1, x2, y1, y2;
+ currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+ minx = qMin(minx, x1);
+ miny = qMin(miny, y1);
+ maxx = qMax(maxx, x2);
+ maxy = qMax(maxy, y2);
+ }
+ double gx = minx;
+ double gy = miny;
+ double gw = maxx - minx;
+ double gh = maxy - miny;
+ PageItem *high = m_Doc->Items->at(highestItem);
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
+ PageItem *neu = m_Doc->Items->takeAt(z);
+ m_Doc->Items->insert(lowestItem, neu);
+ neu->Groups.push(m_Doc->GroupCounter);
+ neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
+ neu->AutoName = false;
+ neu->isGroupControl = true;
+ neu->groupsLastItem = high;
+ neu->setTextFlowMode(PageItem::TextFlowDisabled);
+ for (int a = 0; a < m_Doc->Items->count(); ++a)
+ {
+ m_Doc->Items->at(a)->ItemNr = a;
+ }
+ Elements.prepend(neu);
+ m_Doc->GroupCounter++;
+ }
+ }
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->setLoading(false);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ if ((Elements.count() > 0) && (!ret) && (interactive))
+ {
+ if (flags & LoadSavePlugin::lfScripted)
+ {
+ bool loadF = m_Doc->isLoading();
+ m_Doc->setLoading(false);
+ m_Doc->changed();
+ m_Doc->setLoading(loadF);
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->m_Selection->addItem(Elements.at(dre), true);
+ }
+ m_Doc->m_Selection->delaySignalsOff();
+ m_Doc->m_Selection->setGroupRect();
+ m_Doc->view()->updatesOn(true);
+ }
+ else
+ {
+ m_Doc->DragP = true;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
+ tmpSel->addItem(Elements.at(dre), true);
+ }
+ tmpSel->setGroupRect();
+ ScriXmlDoc *ss = new ScriXmlDoc();
+ ScElemMimeData* md = new ScElemMimeData();
+ md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
+ delete ss;
+ m_Doc->itemSelection_DeleteItem(tmpSel);
+ m_Doc->view()->updatesOn(true);
+ m_Doc->m_Selection->delaySignalsOff();
+ // We must copy the TransationSettings object as it is owned
+ // by handleObjectImport method afterwards
+ TransactionSettings* transacSettings = new TransactionSettings(trSettings);
+ m_Doc->view()->handleObjectImport(md, transacSettings);
+ m_Doc->DragP = false;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ }
+ }
+ else
+ {
+ m_Doc->changed();
+ m_Doc->reformPages();
+ m_Doc->view()->updatesOn(true);
+ }
+ success = true;
+ }
+ else
+ {
+ QDir::setCurrent(CurDirP);
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->view()->updatesOn(true);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ }
+ if (interactive)
+ m_Doc->setLoading(false);
+ //CB If we have a gui we must refresh it if we have used the progressbar
+ if ((showProgress) && (!interactive))
+ m_Doc->view()->DrawNew();
+ return success;
+}
+
+WpgPlug::~WpgPlug()
+{
+ if (progressDialog)
+ delete progressDialog;
+ delete tmpSel;
+}
+
+bool WpgPlug::convert(QString fn)
+{
+ QString tmp;
+ importedColors.clear();
+
+ QFile file(fn);
+ if ( !file.exists() )
+ {
+ qDebug() << "File " << QFile::encodeName(fn).data() << " does not exist" << endl;
+ return false;
+ }
+ if ( !file.open( QIODevice::ReadOnly ) )
+ {
+ qDebug() << "Cannot open file " << QFile::encodeName(fn).data() << endl;
+ return false;
+ }
+ QByteArray ba = file.readAll();
+ file.close();
+
+ libwpg::WPGMemoryStream input(ba.constData(), ba.size());
+ if (!libwpg::WPGraphics::isSupported(&input))
+ {
+ fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
+ return false;
+ }
+ ScrPainter painter;
+ painter.m_Doc = m_Doc;
+ painter.baseX = baseX;
+ painter.baseY = baseY;
+ libwpg::WPGraphics::parse(&input, &painter);
+ Elements = painter.Elements;
+ importedColors = painter.importedColors;
+ if (Elements.count() == 0)
+ {
+ if (importedColors.count() != 0)
+ {
+ for (int cd = 0; cd < importedColors.count(); cd++)
+ {
+ m_Doc->PageColors.remove(importedColors[cd]);
+ }
+ }
+ }
+/* if(progressDialog)
+ {
+ progressDialog->setOverallProgress(2);
+ progressDialog->setLabel("GI", tr("Generating Items"));
+ qApp->processEvents();
+ } */
+ if (progressDialog)
+ progressDialog->close();
+ return true;
+}
Index: scribus/plugins/wpgimplugin/CMakeLists.txt
===================================================================
--- scribus/plugins/wpgimplugin/CMakeLists.txt (revision 0)
+++ scribus/plugins/wpgimplugin/CMakeLists.txt (revision 13885)
@@ -0,0 +1,42 @@
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(LIBWPG libwpg-0.1)
+pkg_check_modules(LIBWPG_STREAM libwpg-stream-0.1)
+pkg_check_modules(LIBWPD libwpd-0.8)
+pkg_check_modules(LIBWPD_STREAM libwpd-stream-0.8)
+
+IF(LIBWPG_FOUND AND LIBWPD_FOUND AND LIBWPD_STREAM_FOUND AND LIBWPG_STREAM_FOUND)
+ INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/scribus
+ ${LIBWPG_INCLUDE_DIRS}
+ ${LIBWPD_INCLUDE_DIRS}
+ ${LIBWPD_STREAM_INCLUDE_DIRS}
+ )
+
+ SET(IMPORTWPG_PLUGIN_MOC_CLASSES
+ importwpg.h
+ importwpgplugin.h
+ )
+
+ SET(IMPORTWPG_PLUGIN_SOURCES
+ importwpg.cpp
+ importwpgplugin.cpp
+ )
+
+ SET(SCRIBUS_IMPORTWPG_PLUGIN "importwpg")
+
+ QT4_WRAP_CPP(IMPORTWPG_PLUGIN_MOC_SOURCES ${IMPORTWPG_PLUGIN_MOC_CLASSES})
+
+ ADD_LIBRARY(${SCRIBUS_IMPORTWPG_PLUGIN} MODULE ${IMPORTWPG_PLUGIN_SOURCES} ${IMPORTWPG_PLUGIN_MOC_SOURCES})
+
+ TARGET_LINK_LIBRARIES(${SCRIBUS_IMPORTWPG_PLUGIN} ${PLUGIN_LIBRARIES} ${LIBWPG_LDFLAGS} ${LIBWPG_STREAM_LDFLAGS} ${LIBWPD_LDFLAGS} ${LIBWPD_STREAM_LDFLAGS})
+
+ INSTALL(TARGETS ${SCRIBUS_IMPORTWPG_PLUGIN}
+ LIBRARY
+ DESTINATION ${PLUGINDIR}
+ PERMISSIONS ${PLUGIN_PERMISSIONS}
+ )
+
+ ADD_DEPENDENCIES(${SCRIBUS_IMPORTWPG_PLUGIN} ${EXE_NAME})
+ENDIF(LIBWPG_FOUND AND LIBWPD_FOUND AND LIBWPD_STREAM_FOUND AND LIBWPG_STREAM_FOUND)
Index: scribus/plugins/wpgimplugin/importwpgplugin.h
===================================================================
--- scribus/plugins/wpgimplugin/importwpgplugin.h (revision 0)
+++ scribus/plugins/wpgimplugin/importwpgplugin.h (revision 13885)
@@ -0,0 +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.
+*/
+#ifndef IMPORTWPGPLUGIN_H
+#define IMPORTWPGPLUGIN_H
+
+#include "pluginapi.h"
+#include "loadsaveplugin.h"
+#include "../formatidlist.h"
+
+class ScrAction;
+
+class PLUGIN_API ImportWpgPlugin : public LoadSavePlugin
+{
+ Q_OBJECT
+
+ public:
+ // Standard plugin implementation
+ ImportWpgPlugin();
+ virtual ~ImportWpgPlugin();
+ /*!
+ \author Franz Schmid
+ \date
+ \brief Returns name of plugin
+ \retval QString containing name of plugin: Import EPS/PDF/PS...
+ */
+ virtual const QString fullTrName() const;
+ virtual const AboutData* getAboutData() const;
+ virtual void deleteAboutData(const AboutData* about) const;
+ virtual void languageChange();
+ virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const;
+ virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
+ virtual void addToMainWindowMenu(ScribusMainWindow *) {};
+
+ public slots:
+ /*!
+ \author Franz Schmid
+ \date
+ \brief Run the EPS import
+ \param fileName input filename, or QString::null to prompt.
+ \retval bool always true
+ */
+ virtual bool import(QString fileName = QString::null, int flags = lfUseCurrentPage|lfInteractive);
+
+ private:
+ void registerFormats();
+ ScrAction* importAction;
+};
+
+extern "C" PLUGIN_API int importwpg_getPluginAPIVersion();
+extern "C" PLUGIN_API ScPlugin* importwpg_getPlugin();
+extern "C" PLUGIN_API void importwpg_freePlugin(ScPlugin* plugin);
+
+#endif
Index: scribus/plugins/wpgimplugin/importwpg.h
===================================================================
--- scribus/plugins/wpgimplugin/importwpg.h (revision 0)
+++ scribus/plugins/wpgimplugin/importwpg.h (revision 13885)
@@ -0,0 +1,124 @@
+/*
+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 IMPORTWPG_H
+#define IMPORTWPG_H
+
+#include "qglobal.h"
+#include "qobject.h"
+#include "qstring.h"
+
+#include "pluginapi.h"
+#include "pageitem.h"
+#include "sccolor.h"
+#include "fpointarray.h"
+#include "vgradient.h"
+#include <QList>
+#include <QMatrix>
+#include <QMultiMap>
+#include <QVector>
+#include <libwpg/libwpg.h>
+
+class MultiProgressDialog;
+class ScribusDoc;
+class Selection;
+class TransactionSettings;
+
+class ScrPainter : public libwpg::WPGPaintInterface
+{
+public:
+ ScrPainter();
+
+ void startGraphics(double imageWidth, double imageHeight);
+ void endGraphics();
+ void startLayer(unsigned int id);
+ void endLayer(unsigned int id);
+
+ void setPen(const libwpg::WPGPen& pen);
+ void setBrush(const libwpg::WPGBrush& brush);
+ void setFillRule(FillRule rule);
+
+ void drawRectangle(const libwpg::WPGRect& rect, double rx, double ry);
+ void drawEllipse(const libwpg::WPGPoint& center, double rx, double ry);
+ void drawPolygon(const libwpg::WPGPointArray& vertices);
+ void drawPath(const libwpg::WPGPath& path);
+ void drawBitmap(const libwpg::WPGBitmap& bitmap);
+ void drawImageObject(const libwpg::WPGBinaryData& binaryData);
+ void finishItem(PageItem* ite);
+ QList<PageItem*> Elements;
+ QStringList importedColors;
+ ScribusDoc* m_Doc;
+ double LineW;
+ QString CurrColorFill;
+ QString CurrColorStroke;
+ double CurrStrokeShade;
+ double CurrFillShade;
+ double CurrStrokeTrans;
+ double CurrFillTrans;
+ FPointArray Coords;
+ double baseX, baseY;
+ bool fillrule;
+ double gradientAngle;
+ bool isGradient;
+ VGradient currentGradient;
+ QVector<double> dashArray;
+};
+
+//! \brief WPG importer plugin
+class WpgPlug : public QObject
+{
+ Q_OBJECT
+
+public:
+ /*!
+ \author Franz Schmid
+ \date
+ \brief Create the Wpg importer window.
+ \param fName QString
+ \param flags combination of loadFlags
+ \param showProgress if progress must be displayed
+ \retval EPSPlug plugin
+ */
+ WpgPlug( ScribusDoc* doc, int flags );
+ ~WpgPlug();
+
+ /*!
+ \author Franz Schmid
+ \date
+ \brief Perform import.
+ \param fn QString
+ \param trSettings undo transaction settings
+ \param flags combination of loadFlags
+ \param showProgress if progress must be displayed
+ \retval bool true if import was ok
+ */
+ bool import(QString fn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
+
+private:
+ bool convert(QString fn);
+
+ QList<PageItem*> Elements;
+ double baseX, baseY;
+ double docWidth;
+ double docHeight;
+ qreal scPg;
+
+ QStringList importedColors;
+
+ bool interactive;
+ MultiProgressDialog * progressDialog;
+ bool cancel;
+ ScribusDoc* m_Doc;
+ Selection* tmpSel;
+ int importerFlags;
+ int oldDocItemCount;
+ QString baseFile;
+
+public slots:
+ void cancelRequested() { cancel = true; }
+};
+
+#endif
Index: scribus/plugins/CMakeLists.txt
===================================================================
--- scribus/plugins/CMakeLists.txt (revision 13884)
+++ scribus/plugins/CMakeLists.txt (revision 13885)
@@ -17,6 +17,7 @@
ADD_SUBDIRECTORY(wmfimplugin)
ADD_SUBDIRECTORY(xfigimplugin)
ADD_SUBDIRECTORY(cvgimplugin)
+ADD_SUBDIRECTORY(wpgimplugin)
ADD_SUBDIRECTORY(tools)
#ADD_SUBDIRECTORY(picbrowser)
More information about the scribus-commit
mailing list