Subversion Repositories Scribus

Rev

Rev 214 | Rev 243 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
104 Franz 1
#include <Python.h>
2
 
103 Franz 3
#include "cmdobj.h"
4
#include "cmdutil.h"
82 Franz 5
#include "cmdvar.h"
6
 
7
PyObject *scribus_newrect(PyObject *self, PyObject* args)
8
{
9
        double x, y, b, h;
10
        char *Name = "";
11
        if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
12
                return NULL;
13
        if (!Carrier->HaveDoc)
14
                return PyString_FromString("");
164 Franz 15
        int i = Carrier->doc->ActPage->PaintRect(ValueToPoint(x), ValueToPoint(y),
82 Franz 16
                                                                                                                        ValueToPoint(b), ValueToPoint(h),
164 Franz 17
                                                                                                                        Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
18
        Carrier->doc->ActPage->SetRectFrame(Carrier->doc->ActPage->Items.at(i));
82 Franz 19
        if (Name != "")
164 Franz 20
                Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
21
        return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
82 Franz 22
}
23
 
24
PyObject *scribus_newellipse(PyObject *self, PyObject* args)
25
{
26
        double x, y, b, h;
27
        char *Name = "";
28
        if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
29
                return NULL;
30
        if (!Carrier->HaveDoc)
31
                return PyString_FromString("");
164 Franz 32
        int i = Carrier->doc->ActPage->PaintEllipse(ValueToPoint(x), ValueToPoint(y),
82 Franz 33
                                                                                                                                 ValueToPoint(b), ValueToPoint(h),
164 Franz 34
                                                                                                                                 Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
35
        Carrier->doc->ActPage->SetOvalFrame(Carrier->doc->ActPage->Items.at(i));
82 Franz 36
        if (Name != "")
164 Franz 37
                Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
38
        return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
82 Franz 39
}
40
 
41
PyObject *scribus_newimage(PyObject *self, PyObject* args)
42
{
43
        double x, y, b, h;
44
        char *Name = "";
45
        if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
46
                return NULL;
47
        if (!Carrier->HaveDoc)
48
                return PyString_FromString("");
164 Franz 49
        int i = Carrier->doc->ActPage->PaintPict(ValueToPoint(x), ValueToPoint(y), ValueToPoint(b), ValueToPoint(h));
50
        Carrier->doc->ActPage->SetRectFrame(Carrier->doc->ActPage->Items.at(i));
82 Franz 51
        if (Name != "")
164 Franz 52
                Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
53
        return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
82 Franz 54
}
55
 
56
PyObject *scribus_newtext(PyObject *self, PyObject* args)
57
{
58
        double x, y, b, h;
59
        char *Name = "";
60
        if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
61
                return NULL;
62
        if (!Carrier->HaveDoc)
63
                return PyString_FromString("");
164 Franz 64
        int i = Carrier->doc->ActPage->PaintText(ValueToPoint(x), ValueToPoint(y),
82 Franz 65
                                                                                                                        ValueToPoint(b), ValueToPoint(h),
164 Franz 66
                                                                                                                        Carrier->doc->Dwidth, Carrier->doc->DpenText);
67
        Carrier->doc->ActPage->SetRectFrame(Carrier->doc->ActPage->Items.at(i));
82 Franz 68
        if (Name != "")
164 Franz 69
                Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
70
        return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
82 Franz 71
}
72
 
73
PyObject *scribus_newline(PyObject *self, PyObject* args)
74
{
75
        double x, y, b, h;
76
        char *Name = "";
77
        if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
78
                return NULL;
79
        if (!Carrier->HaveDoc)
80
                return PyString_FromString("");
81
        x =     ValueToPoint(x);
82
        y = ValueToPoint(y);
83
        b = ValueToPoint(b);
84
        h = ValueToPoint(h);
164 Franz 85
        int i = Carrier->doc->ActPage->PaintPolyLine(x, y, 1, 1,        Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
86
        PageItem *it = Carrier->doc->ActPage->Items.at(i);
82 Franz 87
        it->PoLine.resize(4);
88
        it->PoLine.setPoint(0, 0, 0);
89
        it->PoLine.setPoint(1, 0, 0);
90
        it->PoLine.setPoint(2, b-x, h-y);
91
        it->PoLine.setPoint(3, b-x, h-y);
164 Franz 92
        FPoint np2 = Carrier->doc->ActPage->GetMinClipF(it->PoLine);
82 Franz 93
        if (np2.x() < 0)
94
                {
95
                it->PoLine.translate(-np2.x(), 0);
164 Franz 96
                Carrier->doc->ActPage->MoveItem(np2.x(), 0, it);
82 Franz 97
                }
98
        if (np2.y() < 0)
99
                {
100
                it->PoLine.translate(0, -np2.y());
164 Franz 101
                Carrier->doc->ActPage->MoveItem(0, np2.y(), it);
82 Franz 102
                }
164 Franz 103
        Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), i, false, false);
104
        Carrier->doc->ActPage->AdjustItemSize(it);
82 Franz 105
        if (Name != "")
106
                it->AnName = QString(Name);
107
        return PyString_FromString(it->AnName);
108
}
109
 
110
PyObject *scribus_polyline(PyObject *self, PyObject* args)
111
{
112
        char *Name = "";
113
        PyObject *il;
114
        if ((!PyArg_ParseTuple(args, "O|s", &il, &Name)) || (!PyList_Check(il)))
115
                return NULL;
116
        if (!Carrier->HaveDoc)
237 Franz 117
                return PyString_FromString("");
87 Franz 118
        int len = PyList_Size(il);
82 Franz 119
        if ((len < 4) || ((len % 2) != 0))
120
                return PyString_FromString("");
87 Franz 121
        double x, y, b, h;
237 Franz 122
        int i = 0;
82 Franz 123
        x = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
124
        i++;
125
        y = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
126
        i++;
164 Franz 127
        int ic = Carrier->doc->ActPage->PaintPolyLine(x, y, 1, 1,       Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
128
        PageItem *it = Carrier->doc->ActPage->Items.at(ic);
82 Franz 129
        it->PoLine.resize(2);
130
        it->PoLine.setPoint(0, 0, 0);
131
        it->PoLine.setPoint(1, 0, 0);
87 Franz 132
        int pp = 6;
82 Franz 133
        for (i = 2; i < len - 2; i += 2)
134
                {
135
                b = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
136
                h = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
137
                it->PoLine.resize(pp);
138
                it->PoLine.setPoint(pp-4, b-x, h-y);
139
                it->PoLine.setPoint(pp-3, b-x, h-y);
140
                it->PoLine.setPoint(pp-2, b-x, h-y);
141
                it->PoLine.setPoint(pp-1, b-x, h-y);
142
                pp += 4;
143
                }
144
        pp -= 2;
145
        b = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
146
        h = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
147
        it->PoLine.resize(pp);
148
        it->PoLine.setPoint(pp-2, b-x, h-y);
149
        it->PoLine.setPoint(pp-1, b-x, h-y);
164 Franz 150
        FPoint np2 = Carrier->doc->ActPage->GetMinClipF(it->PoLine);
82 Franz 151
        if (np2.x() < 0)
152
                {
153
                it->PoLine.translate(-np2.x(), 0);
164 Franz 154
                Carrier->doc->ActPage->MoveItem(np2.x(), 0, it);
82 Franz 155
                }
156
        if (np2.y() < 0)
157
                {
158
                it->PoLine.translate(0, -np2.y());
164 Franz 159
                Carrier->doc->ActPage->MoveItem(0, np2.y(), it);
82 Franz 160
                }
164 Franz 161
        Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
162
        Carrier->doc->ActPage->AdjustItemSize(it);
82 Franz 163
        if (Name != "")
164
                it->AnName = QString(Name);
165
        return PyString_FromString(it->AnName);
166
}
167
 
168
PyObject *scribus_polygon(PyObject *self, PyObject* args)
169
{
170
        char *Name = "";
171
        PyObject *il;
172
        if ((!PyArg_ParseTuple(args, "O|s", &il, &Name)) || (!PyList_Check(il)))
173
                return NULL;
174
        if (!Carrier->HaveDoc)
175
                return PyString_FromString("");
87 Franz 176
        int len = PyList_Size(il);
82 Franz 177
        if ((len < 6) || ((len % 2) != 0))
178
                return PyString_FromString("");
87 Franz 179
        double x, y, b, h;
237 Franz 180
        int i = 0;
82 Franz 181
        x = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
182
        i++;
183
        y = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
184
        i++;
164 Franz 185
        int ic = Carrier->doc->ActPage->PaintPoly(x, y, 1, 1,   Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
186
        PageItem *it = Carrier->doc->ActPage->Items.at(ic);
82 Franz 187
        it->PoLine.resize(2);
188
        it->PoLine.setPoint(0, 0, 0);
189
        it->PoLine.setPoint(1, 0, 0);
87 Franz 190
        int pp = 6;
82 Franz 191
        for (i = 2; i < len - 2; i += 2)
192
                {
193
                b = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
194
                h = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
195
                it->PoLine.resize(pp);
196
                it->PoLine.setPoint(pp-4, b-x, h-y);
197
                it->PoLine.setPoint(pp-3, b-x, h-y);
198
                it->PoLine.setPoint(pp-2, b-x, h-y);
199
                it->PoLine.setPoint(pp-1, b-x, h-y);
200
                pp += 4;
201
                }
202
        b = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
203
        h = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
204
        it->PoLine.resize(pp);
205
        it->PoLine.setPoint(pp-4, b-x, h-y);
206
        it->PoLine.setPoint(pp-3, b-x, h-y);
207
        it->PoLine.setPoint(pp-2, b-x, h-y);
208
        it->PoLine.setPoint(pp-1, b-x, h-y);
209
        pp += 2;
210
        it->PoLine.resize(pp);
211
        it->PoLine.setPoint(pp-2, 0, 0);
212
        it->PoLine.setPoint(pp-1, 0, 0);
164 Franz 213
        FPoint np2 = Carrier->doc->ActPage->GetMinClipF(it->PoLine);
82 Franz 214
        if (np2.x() < 0)
215
                {
216
                it->PoLine.translate(-np2.x(), 0);
164 Franz 217
                Carrier->doc->ActPage->MoveItem(np2.x(), 0, it);
82 Franz 218
                }
219
        if (np2.y() < 0)
220
                {
221
                it->PoLine.translate(0, -np2.y());
164 Franz 222
                Carrier->doc->ActPage->MoveItem(0, np2.y(), it);
82 Franz 223
                }
164 Franz 224
        Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
225
        Carrier->doc->ActPage->AdjustItemSize(it);
82 Franz 226
        if (Name != "")
227
                it->AnName = QString(Name);
228
        return PyString_FromString(it->AnName);
229
}
230
 
231
PyObject *scribus_bezierline(PyObject *self, PyObject* args)
232
{
233
        char *Name = "";
234
        PyObject *il;
235
        if ((!PyArg_ParseTuple(args, "O|s", &il, &Name)) || (!PyList_Check(il)))
236
                return NULL;
237
        if (!Carrier->HaveDoc)
238
                return PyString_FromString("");
87 Franz 239
        int len = PyList_Size(il);
82 Franz 240
        if ((len < 8) || ((len % 6) != 0))
241
                return PyString_FromString("");
87 Franz 242
        double x, y, b, h, kx, ky, kx2, ky2;
237 Franz 243
        int i = 0;
82 Franz 244
        x = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
245
        i++;
246
        y = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
247
        i++;
248
        kx = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
249
        i++;
250
        ky = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
251
        i++;
252
        kx2 = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
253
        i++;
254
        ky2 = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
255
        i++;
164 Franz 256
        int ic = Carrier->doc->ActPage->PaintPolyLine(x, y, 1, 1,       Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
257
        PageItem *it = Carrier->doc->ActPage->Items.at(ic);
82 Franz 258
        it->PoLine.resize(2);
259
        it->PoLine.setPoint(0, 0, 0);
260
        it->PoLine.setPoint(1, kx-x, ky-y);
87 Franz 261
        int pp = 6;
82 Franz 262
        for (i = 6; i < len - 6; i += 6)
263
                {
264
                b = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
265
                h = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
266
                kx = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
267
                ky = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
268
                kx2 = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
269
                ky2 = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
270
                it->PoLine.resize(pp);
271
                it->PoLine.setPoint(pp-4, b-x, h-y);
272
                it->PoLine.setPoint(pp-3, kx-x, ky-y);
273
                it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
274
                it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
275
                pp += 4;
276
                }
277
        pp -= 2;
278
        b = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
279
        h = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
280
        kx = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
281
        ky = ValueToPoint(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
282
        it->PoLine.resize(pp);
283
        it->PoLine.setPoint(pp-2, b-x, h-y);
284
        it->PoLine.setPoint(pp-1, kx-x, ky-y);
164 Franz 285
        FPoint np2 = Carrier->doc->ActPage->GetMinClipF(it->PoLine);
82 Franz 286
        if (np2.x() < 0)
287
                {
288
                it->PoLine.translate(-np2.x(), 0);
164 Franz 289
                Carrier->doc->ActPage->MoveItem(np2.x(), 0, it);
82 Franz 290
                }
291
        if (np2.y() < 0)
292
                {
293
                it->PoLine.translate(0, -np2.y());
164 Franz 294
                Carrier->doc->ActPage->MoveItem(0, np2.y(), it);
82 Franz 295
                }
164 Franz 296
        Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
297
        Carrier->doc->ActPage->AdjustItemSize(it);
82 Franz 298
        if (Name != "")
299
                it->AnName = QString(Name);
300
        return PyString_FromString(it->AnName);
301
}
302
 
303
PyObject *scribus_pathtext(PyObject *self, PyObject* args)
304
{
305
        double x, y;
306
        char *Name = "";
307
        char *TextB = "";
308
        char *PolyB = "";
309
        if (!PyArg_ParseTuple(args, "ddss|s", &x, &y, &TextB, &PolyB, &Name))
310
                return NULL;
311
        if ((!Carrier->HaveDoc) || ((TextB == "") || (PolyB == "")))
312
                return PyString_FromString("");
87 Franz 313
        int i = GetItem(QString(TextB));
314
        int ii = GetItem(QString(PolyB));
82 Franz 315
        if ((i == -1) || (ii == -1))
316
                return PyString_FromString("");
164 Franz 317
        Carrier->doc->ActPage->SelItem.clear();
318
        Carrier->doc->ActPage->SelItem.append(Carrier->doc->ActPage->Items.at(i));
319
        Carrier->doc->ActPage->SelItem.append(Carrier->doc->ActPage->Items.at(ii));
320
        PageItem *it = Carrier->doc->ActPage->Items.at(i);
321
        Carrier->doc->ActPage->ToPathText();
322
        Carrier->doc->ActPage->MoveItem(ValueToPoint(x) - it->Xpos, ValueToPoint(y) - it->Ypos, it);
82 Franz 323
        if (Name != "")
324
                it->AnName = QString(Name);
325
        return PyString_FromString(it->AnName);
326
}
327
 
237 Franz 328
/* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik)
329
 */
82 Franz 330
PyObject *scribus_deleteobj(PyObject *self, PyObject* args)
331
{
332
        char *Name = "";
333
        if (!PyArg_ParseTuple(args, "|s", &Name))
334
                return NULL;
335
        Py_INCREF(Py_None);
336
        if (!Carrier->HaveDoc)
337
                return Py_None;
338
        if (Name != "")
237 Franz 339
        {
164 Franz 340
                Carrier->doc->ActPage->SelItem.clear();
87 Franz 341
                int i = GetItem(QString(Name));
82 Franz 342
                if (i != -1)
164 Franz 343
                        Carrier->doc->ActPage->SelItem.append(Carrier->doc->ActPage->Items.at(i));
237 Franz 344
                else
345
                {
346
                        PyErr_SetString(PyExc_Exception, "Oook! You're trying to erase an object doesn't exist!");
347
                        Py_DECREF(Py_None);
348
                        return NULL;
82 Franz 349
                }
237 Franz 350
        }
164 Franz 351
        Carrier->doc->ActPage->DeleteItem();
82 Franz 352
        return Py_None;
353
}
354
 
237 Franz 355
/* 03/21/2004 - exception raises by non existent name (subik)
356
 */
214 Franz 357
PyObject *scribus_textflow(PyObject *self, PyObject* args)
358
{
359
        char* name;
360
        int id, state = -1;
361
 
362
        if (!PyArg_ParseTuple(args, "s|i", &name, &state))
363
                return NULL;
364
        Py_INCREF(Py_None);
365
        if (!Carrier->HaveDoc)
366
                return Py_None;
367
 
368
        id = GetItem(QString(name));
369
        if (id == -1)
237 Franz 370
        {
371
                PyErr_SetString(PyExc_Exception, "Oook! An object you're trying to textflow doesn't exist!");
372
                Py_DECREF(Py_None);
373
                return NULL;
374
        }
214 Franz 375
 
376
        if (state == -1)
377
        {
378
                Carrier->doc->ActPage->Items.at(id)->Textflow =
379
                        !Carrier->doc->ActPage->Items.at(id)->Textflow;
380
        }
381
        else
382
        {
383
                state
384
                        ? Carrier->doc->ActPage->Items.at(id)->Textflow = true
385
                        : Carrier->doc->ActPage->Items.at(id)->Textflow = false;
386
        } // if state null
387
 
388
        Carrier->view->DrawNew();
389
        Carrier->slotDocCh(true);
390
        return Py_None;
391
}