1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #include "svgimport.h"
8 #include "cmdvar.h"
9 #include "cmdutil.h"
10
11 // We need svgpluginid.h for the SVG format ID, and
12 // loadsaveplugin.h for the FileFormat interface.
13 #include "fileloader.h"
14 #include "../formatidlist.h"
15 #include "loadsaveplugin.h"
16 #include "scribuscore.h"
17 #include "scribusview.h"
18 #include "selection.h"
19 #include "ui/propertiespalette.h"
20 #include "ui/propertiespalette_line.h"
21
22 #include <QString>
23
scribus_placevec(PyObject *,PyObject * args)24 PyObject *scribus_placevec(PyObject* /* self */, PyObject* args)
25 {
26 char *Image;
27 double x = 0.0;
28 double y = 0.0;
29 if (!PyArg_ParseTuple(args, "es|dd", "utf-8", &Image, &x, &y))
30 return nullptr;
31 if (!checkHaveDocument())
32 return nullptr;
33 QStringList allFormatsV = LoadSavePlugin::getExtensionsForImport(FORMATID_FIRSTUSER);
34 QString fName = QString::fromUtf8(Image);
35 QFileInfo fi = QFileInfo(fName);
36 QString ext = fi.suffix().toLower();
37 if (!allFormatsV.contains(ext))
38 {
39 PyErr_SetString(PyExc_Exception, "Requested Import plugin not available");
40 return nullptr;
41 }
42 FileLoader *fileLoader = new FileLoader(fName);
43 int testResult = fileLoader->testFile();
44 delete fileLoader;
45 if ((testResult != -1) && (testResult >= FORMATID_FIRSTUSER))
46 {
47 const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
48 if (fmt)
49 {
50 fmt->loadFile(fName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted);
51 if (ScCore->primaryMainWindow()->doc->m_Selection->count() >= 1)
52 {
53 double x2, y2, w, h;
54 ScCore->primaryMainWindow()->doc->m_Selection->getGroupRect(&x2, &y2, &w, &h);
55 ScCore->primaryMainWindow()->view->startGroupTransaction();
56 ScCore->primaryMainWindow()->doc->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2);
57 ScCore->primaryMainWindow()->view->endGroupTransaction();
58 ScCore->primaryMainWindow()->requestUpdate(reqColorsUpdate | reqLineStylesUpdate | reqTextStylesUpdate);
59 }
60 }
61 }
62 else
63 {
64 PyErr_SetString(PyExc_Exception, "Requested File cannot be imported");
65 return nullptr;
66 }
67 Py_RETURN_NONE;
68 }
69
70 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
71 with header files structure untouched (docstrings are kept near declarations)
72 PV */
svgimportdocwarnings()73 void svgimportdocwarnings()
74 {
75 QStringList s;
76 s << scribus_placeeps__doc__
77 << scribus_placeodg__doc__
78 << scribus_placesvg__doc__
79 << scribus_placesxd__doc__
80 << scribus_placevec__doc__;
81 }
82