Rev 1283 | Rev 1394 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
103 | Franz | 1 | #include "cmdobj.h" |
2 | #include "cmdutil.h" |
||
82 | Franz | 3 | |
1065 | cbradney | 4 | extern FPoint getMinClipF(FPointArray* Clip); |
740 | fschmid | 5 | |
934 | subik | 6 | PyObject *scribus_newrect(PyObject */*self*/, PyObject* args) |
82 | Franz | 7 | { |
8 | double x, y, b, h; |
||
934 | subik | 9 | char *Name = const_cast<char*>(""); |
900 | cbradney | 10 | if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name)) |
82 | Franz | 11 | return NULL; |
649 | fschmid | 12 | if(!checkHaveDocument()) |
13 | return NULL; |
||
900 | cbradney | 14 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 15 | { |
899 | cbradney | 16 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 17 | return NULL; |
18 | } |
||
1283 | subik | 19 | int i = Carrier->view->PaintRect(pageUnitXToDocX(x), pageUnitYToDocY(y), |
20 | pageUnitXToDocX(b), pageUnitYToDocY(h), |
||
21 | Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dBrush, |
||
22 | Carrier->doc->toolSettings.dPen); |
||
662 | fschmid | 23 | Carrier->view->SetRectFrame(Carrier->doc->Items.at(i)); |
720 | subik | 24 | if (Name != "") |
1361 | tsoots | 25 | Carrier->doc->Items.at(i)->setItemName(QString::fromUtf8(Name)); |
26 | return PyString_FromString(Carrier->doc->Items.at(i)->itemName().utf8()); |
||
82 | Franz | 27 | } |
28 | |||
243 | Franz | 29 | |
934 | subik | 30 | PyObject *scribus_newellipse(PyObject */*self*/, PyObject* args) |
82 | Franz | 31 | { |
32 | double x, y, b, h; |
||
934 | subik | 33 | char *Name = const_cast<char*>(""); |
900 | cbradney | 34 | if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name)) |
82 | Franz | 35 | return NULL; |
649 | fschmid | 36 | if(!checkHaveDocument()) |
37 | return NULL; |
||
1283 | subik | 38 | int i = Carrier->view->PaintEllipse(pageUnitXToDocX(x), pageUnitYToDocY(y), |
39 | pageUnitXToDocX(b), pageUnitYToDocY(h), |
||
40 | Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dBrush, |
||
41 | Carrier->doc->toolSettings.dPen); |
||
900 | cbradney | 42 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 43 | { |
899 | cbradney | 44 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 45 | return NULL; |
46 | } |
||
662 | fschmid | 47 | Carrier->view->SetOvalFrame(Carrier->doc->Items.at(i)); |
720 | subik | 48 | if (Name != "") |
1361 | tsoots | 49 | Carrier->doc->Items.at(i)->setItemName(QString::fromUtf8(Name)); |
50 | return PyString_FromString(Carrier->doc->Items.at(i)->itemName().utf8()); |
||
82 | Franz | 51 | } |
52 | |||
243 | Franz | 53 | |
934 | subik | 54 | PyObject *scribus_newimage(PyObject */*self*/, PyObject* args) |
82 | Franz | 55 | { |
56 | double x, y, b, h; |
||
934 | subik | 57 | char *Name = const_cast<char*>(""); |
900 | cbradney | 58 | if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name)) |
82 | Franz | 59 | return NULL; |
649 | fschmid | 60 | if(!checkHaveDocument()) |
61 | return NULL; |
||
1283 | subik | 62 | int i = Carrier->view->PaintPict(pageUnitXToDocX(x), pageUnitYToDocY(y), |
63 | pageUnitXToDocX(b), pageUnitYToDocY(h)); |
||
900 | cbradney | 64 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 65 | { |
899 | cbradney | 66 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 67 | return NULL; |
68 | } |
||
662 | fschmid | 69 | Carrier->view->SetRectFrame(Carrier->doc->Items.at(i)); |
720 | subik | 70 | if (Name != "") |
1361 | tsoots | 71 | Carrier->doc->Items.at(i)->setItemName(QString::fromUtf8(Name)); |
72 | return PyString_FromString(Carrier->doc->Items.at(i)->itemName().utf8()); |
||
82 | Franz | 73 | } |
74 | |||
243 | Franz | 75 | |
934 | subik | 76 | PyObject *scribus_newtext(PyObject */*self*/, PyObject* args) |
82 | Franz | 77 | { |
78 | double x, y, b, h; |
||
934 | subik | 79 | char *Name = const_cast<char*>(""); |
900 | cbradney | 80 | if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name)) |
82 | Franz | 81 | return NULL; |
649 | fschmid | 82 | if(!checkHaveDocument()) |
83 | return NULL; |
||
1283 | subik | 84 | int i = Carrier->view->PaintText(pageUnitXToDocX(x), pageUnitYToDocY(y), |
85 | pageUnitXToDocX(b), pageUnitYToDocY(h), |
||
86 | Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dPenText); |
||
900 | cbradney | 87 | if (ItemExists(QString::fromUtf8(Name))) |
332 | Franz | 88 | { |
899 | cbradney | 89 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 90 | return NULL; |
332 | Franz | 91 | } |
720 | subik | 92 | Carrier->view->SetRectFrame(Carrier->doc->Items.at(i)); |
93 | if (Name != "") |
||
1361 | tsoots | 94 | Carrier->doc->Items.at(i)->setItemName(QString::fromUtf8(Name)); |
95 | return PyString_FromString(Carrier->doc->Items.at(i)->itemName().utf8()); |
||
82 | Franz | 96 | } |
97 | |||
243 | Franz | 98 | |
934 | subik | 99 | PyObject *scribus_newline(PyObject */*self*/, PyObject* args) |
82 | Franz | 100 | { |
101 | double x, y, b, h; |
||
934 | subik | 102 | char *Name = const_cast<char*>(""); |
900 | cbradney | 103 | if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name)) |
82 | Franz | 104 | return NULL; |
649 | fschmid | 105 | if(!checkHaveDocument()) |
106 | return NULL; |
||
1283 | subik | 107 | x = pageUnitXToDocX(x); |
108 | y = pageUnitYToDocY(y); |
||
109 | b = pageUnitXToDocX(b); |
||
110 | h = pageUnitYToDocY(h); |
||
900 | cbradney | 111 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 112 | { |
899 | cbradney | 113 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 114 | return NULL; |
115 | } |
||
1194 | fschmid | 116 | int i = Carrier->view->PaintPolyLine(x, y, 1, 1, Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dBrush, Carrier->doc->toolSettings.dPen); |
662 | fschmid | 117 | PageItem *it = Carrier->doc->Items.at(i); |
82 | Franz | 118 | it->PoLine.resize(4); |
119 | it->PoLine.setPoint(0, 0, 0); |
||
120 | it->PoLine.setPoint(1, 0, 0); |
||
121 | it->PoLine.setPoint(2, b-x, h-y); |
||
122 | it->PoLine.setPoint(3, b-x, h-y); |
||
1065 | cbradney | 123 | FPoint np2 = getMinClipF(&it->PoLine); |
82 | Franz | 124 | if (np2.x() < 0) |
647 | fschmid | 125 | { |
82 | Franz | 126 | it->PoLine.translate(-np2.x(), 0); |
662 | fschmid | 127 | Carrier->view->MoveItem(np2.x(), 0, it); |
647 | fschmid | 128 | } |
82 | Franz | 129 | if (np2.y() < 0) |
647 | fschmid | 130 | { |
82 | Franz | 131 | it->PoLine.translate(0, -np2.y()); |
662 | fschmid | 132 | Carrier->view->MoveItem(0, np2.y(), it); |
647 | fschmid | 133 | } |
662 | fschmid | 134 | Carrier->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), i, false, false); |
135 | Carrier->view->AdjustItemSize(it); |
||
720 | subik | 136 | if (Name != "") |
1361 | tsoots | 137 | it->setItemName(QString::fromUtf8(Name)); |
138 | return PyString_FromString(it->itemName().utf8()); |
||
82 | Franz | 139 | } |
140 | |||
243 | Franz | 141 | |
934 | subik | 142 | PyObject *scribus_polyline(PyObject */*self*/, PyObject* args) |
82 | Franz | 143 | { |
934 | subik | 144 | char *Name = const_cast<char*>(""); |
82 | Franz | 145 | PyObject *il; |
900 | cbradney | 146 | // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check. |
147 | if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il))) |
||
82 | Franz | 148 | return NULL; |
649 | fschmid | 149 | if(!checkHaveDocument()) |
150 | return NULL; |
||
87 | Franz | 151 | int len = PyList_Size(il); |
720 | subik | 152 | if (len < 4) |
153 | { |
||
899 | cbradney | 154 | PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values)","python error")); |
720 | subik | 155 | return NULL; |
156 | } |
||
157 | if ((len % 2) != 0) |
||
158 | { |
||
899 | cbradney | 159 | PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values","python error")); |
720 | subik | 160 | return NULL; |
161 | } |
||
900 | cbradney | 162 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 163 | { |
899 | cbradney | 164 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 165 | return NULL; |
166 | } |
||
87 | Franz | 167 | double x, y, b, h; |
237 | Franz | 168 | int i = 0; |
1283 | subik | 169 | x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 170 | i++; |
1283 | subik | 171 | y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 172 | i++; |
1194 | fschmid | 173 | int ic = Carrier->view->PaintPolyLine(x, y, 1, 1, Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dBrush, Carrier->doc->toolSettings.dPen); |
662 | fschmid | 174 | PageItem *it = Carrier->doc->Items.at(ic); |
82 | Franz | 175 | it->PoLine.resize(2); |
176 | it->PoLine.setPoint(0, 0, 0); |
||
177 | it->PoLine.setPoint(1, 0, 0); |
||
87 | Franz | 178 | int pp = 6; |
82 | Franz | 179 | for (i = 2; i < len - 2; i += 2) |
647 | fschmid | 180 | { |
1283 | subik | 181 | b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
182 | h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1)))); |
||
82 | Franz | 183 | it->PoLine.resize(pp); |
184 | it->PoLine.setPoint(pp-4, b-x, h-y); |
||
185 | it->PoLine.setPoint(pp-3, b-x, h-y); |
||
186 | it->PoLine.setPoint(pp-2, b-x, h-y); |
||
187 | it->PoLine.setPoint(pp-1, b-x, h-y); |
||
188 | pp += 4; |
||
647 | fschmid | 189 | } |
82 | Franz | 190 | pp -= 2; |
1283 | subik | 191 | b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2)))); |
192 | h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1)))); |
||
82 | Franz | 193 | it->PoLine.resize(pp); |
194 | it->PoLine.setPoint(pp-2, b-x, h-y); |
||
195 | it->PoLine.setPoint(pp-1, b-x, h-y); |
||
1065 | cbradney | 196 | FPoint np2 = getMinClipF(&it->PoLine); |
82 | Franz | 197 | if (np2.x() < 0) |
647 | fschmid | 198 | { |
82 | Franz | 199 | it->PoLine.translate(-np2.x(), 0); |
662 | fschmid | 200 | Carrier->view->MoveItem(np2.x(), 0, it); |
647 | fschmid | 201 | } |
82 | Franz | 202 | if (np2.y() < 0) |
647 | fschmid | 203 | { |
82 | Franz | 204 | it->PoLine.translate(0, -np2.y()); |
662 | fschmid | 205 | Carrier->view->MoveItem(0, np2.y(), it); |
647 | fschmid | 206 | } |
662 | fschmid | 207 | Carrier->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false); |
208 | Carrier->view->AdjustItemSize(it); |
||
720 | subik | 209 | if (Name != "") |
210 | { |
||
1361 | tsoots | 211 | it->setItemName(QString::fromUtf8(Name)); |
720 | subik | 212 | } |
1361 | tsoots | 213 | return PyString_FromString(it->itemName().utf8()); |
82 | Franz | 214 | } |
215 | |||
243 | Franz | 216 | |
934 | subik | 217 | PyObject *scribus_polygon(PyObject */*self*/, PyObject* args) |
82 | Franz | 218 | { |
934 | subik | 219 | char *Name = const_cast<char*>(""); |
82 | Franz | 220 | PyObject *il; |
900 | cbradney | 221 | // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check. |
222 | if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il))) |
||
82 | Franz | 223 | return NULL; |
649 | fschmid | 224 | if(!checkHaveDocument()) |
225 | return NULL; |
||
87 | Franz | 226 | int len = PyList_Size(il); |
720 | subik | 227 | if (len < 6) |
228 | { |
||
899 | cbradney | 229 | PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values)","python error")); |
720 | subik | 230 | return NULL; |
231 | } |
||
232 | if ((len % 2) != 0) |
||
233 | { |
||
899 | cbradney | 234 | PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values","python error")); |
720 | subik | 235 | return NULL; |
236 | } |
||
900 | cbradney | 237 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 238 | { |
899 | cbradney | 239 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 240 | return NULL; |
241 | } |
||
87 | Franz | 242 | double x, y, b, h; |
237 | Franz | 243 | int i = 0; |
1283 | subik | 244 | x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 245 | i++; |
1283 | subik | 246 | y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 247 | i++; |
1194 | fschmid | 248 | int ic = Carrier->view->PaintPoly(x, y, 1, 1, Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dBrush, Carrier->doc->toolSettings.dPen); |
662 | fschmid | 249 | PageItem *it = Carrier->doc->Items.at(ic); |
82 | Franz | 250 | it->PoLine.resize(2); |
251 | it->PoLine.setPoint(0, 0, 0); |
||
252 | it->PoLine.setPoint(1, 0, 0); |
||
87 | Franz | 253 | int pp = 6; |
82 | Franz | 254 | for (i = 2; i < len - 2; i += 2) |
647 | fschmid | 255 | { |
1283 | subik | 256 | b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
257 | h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1)))); |
||
82 | Franz | 258 | it->PoLine.resize(pp); |
259 | it->PoLine.setPoint(pp-4, b-x, h-y); |
||
260 | it->PoLine.setPoint(pp-3, b-x, h-y); |
||
261 | it->PoLine.setPoint(pp-2, b-x, h-y); |
||
262 | it->PoLine.setPoint(pp-1, b-x, h-y); |
||
263 | pp += 4; |
||
647 | fschmid | 264 | } |
1283 | subik | 265 | b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2)))); |
266 | h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1)))); |
||
82 | Franz | 267 | it->PoLine.resize(pp); |
268 | it->PoLine.setPoint(pp-4, b-x, h-y); |
||
269 | it->PoLine.setPoint(pp-3, b-x, h-y); |
||
270 | it->PoLine.setPoint(pp-2, b-x, h-y); |
||
271 | it->PoLine.setPoint(pp-1, b-x, h-y); |
||
272 | pp += 2; |
||
273 | it->PoLine.resize(pp); |
||
274 | it->PoLine.setPoint(pp-2, 0, 0); |
||
275 | it->PoLine.setPoint(pp-1, 0, 0); |
||
1065 | cbradney | 276 | FPoint np2 = getMinClipF(&it->PoLine); |
82 | Franz | 277 | if (np2.x() < 0) |
647 | fschmid | 278 | { |
82 | Franz | 279 | it->PoLine.translate(-np2.x(), 0); |
662 | fschmid | 280 | Carrier->view->MoveItem(np2.x(), 0, it); |
647 | fschmid | 281 | } |
82 | Franz | 282 | if (np2.y() < 0) |
647 | fschmid | 283 | { |
82 | Franz | 284 | it->PoLine.translate(0, -np2.y()); |
662 | fschmid | 285 | Carrier->view->MoveItem(0, np2.y(), it); |
647 | fschmid | 286 | } |
662 | fschmid | 287 | Carrier->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false); |
288 | Carrier->view->AdjustItemSize(it); |
||
720 | subik | 289 | if (Name != "") |
1361 | tsoots | 290 | it->setItemName(QString::fromUtf8(Name)); |
291 | return PyString_FromString(it->itemName().utf8()); |
||
82 | Franz | 292 | } |
293 | |||
934 | subik | 294 | PyObject *scribus_bezierline(PyObject */*self*/, PyObject* args) |
82 | Franz | 295 | { |
934 | subik | 296 | char *Name = const_cast<char*>(""); |
82 | Franz | 297 | PyObject *il; |
900 | cbradney | 298 | // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check. |
299 | if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il))) |
||
82 | Franz | 300 | return NULL; |
649 | fschmid | 301 | if(!checkHaveDocument()) |
302 | return NULL; |
||
87 | Franz | 303 | int len = PyList_Size(il); |
720 | subik | 304 | if (len < 8) |
305 | { |
||
899 | cbradney | 306 | PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values)","python error")); |
720 | subik | 307 | return NULL; |
308 | } |
||
309 | if ((len % 6) != 0) |
||
310 | { |
||
899 | cbradney | 311 | PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values","python error")); |
720 | subik | 312 | return NULL; |
313 | } |
||
900 | cbradney | 314 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 315 | { |
899 | cbradney | 316 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 317 | return NULL; |
318 | } |
||
87 | Franz | 319 | double x, y, b, h, kx, ky, kx2, ky2; |
237 | Franz | 320 | int i = 0; |
1283 | subik | 321 | x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 322 | i++; |
1283 | subik | 323 | y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 324 | i++; |
1283 | subik | 325 | kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 326 | i++; |
1283 | subik | 327 | ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 328 | i++; |
1283 | subik | 329 | kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 330 | i++; |
1283 | subik | 331 | ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
82 | Franz | 332 | i++; |
1194 | fschmid | 333 | int ic = Carrier->view->PaintPolyLine(x, y, 1, 1, Carrier->doc->toolSettings.dWidth, Carrier->doc->toolSettings.dBrush, Carrier->doc->toolSettings.dPen); |
662 | fschmid | 334 | PageItem *it = Carrier->doc->Items.at(ic); |
82 | Franz | 335 | it->PoLine.resize(2); |
336 | it->PoLine.setPoint(0, 0, 0); |
||
337 | it->PoLine.setPoint(1, kx-x, ky-y); |
||
87 | Franz | 338 | int pp = 6; |
82 | Franz | 339 | for (i = 6; i < len - 6; i += 6) |
647 | fschmid | 340 | { |
1283 | subik | 341 | b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i)))); |
342 | h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1)))); |
||
343 | kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2)))); |
||
344 | ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3)))); |
||
345 | kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4)))); |
||
346 | ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5)))); |
||
82 | Franz | 347 | it->PoLine.resize(pp); |
348 | it->PoLine.setPoint(pp-4, b-x, h-y); |
||
349 | it->PoLine.setPoint(pp-3, kx-x, ky-y); |
||
350 | it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4)); |
||
351 | it->PoLine.setPoint(pp-1, kx2-x, ky2-y); |
||
352 | pp += 4; |
||
647 | fschmid | 353 | } |
82 | Franz | 354 | pp -= 2; |
1283 | subik | 355 | b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6)))); |
356 | h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5)))); |
||
357 | kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4)))); |
||
358 | ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3)))); |
||
82 | Franz | 359 | it->PoLine.resize(pp); |
360 | it->PoLine.setPoint(pp-2, b-x, h-y); |
||
361 | it->PoLine.setPoint(pp-1, kx-x, ky-y); |
||
1065 | cbradney | 362 | FPoint np2 = getMinClipF(&it->PoLine); |
82 | Franz | 363 | if (np2.x() < 0) |
647 | fschmid | 364 | { |
82 | Franz | 365 | it->PoLine.translate(-np2.x(), 0); |
662 | fschmid | 366 | Carrier->view->MoveItem(np2.x(), 0, it); |
647 | fschmid | 367 | } |
82 | Franz | 368 | if (np2.y() < 0) |
647 | fschmid | 369 | { |
82 | Franz | 370 | it->PoLine.translate(0, -np2.y()); |
662 | fschmid | 371 | Carrier->view->MoveItem(0, np2.y(), it); |
647 | fschmid | 372 | } |
662 | fschmid | 373 | Carrier->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false); |
374 | Carrier->view->AdjustItemSize(it); |
||
720 | subik | 375 | if (Name != "") |
1361 | tsoots | 376 | it->setItemName(QString::fromUtf8(Name)); |
377 | return PyString_FromString(it->itemName().utf8()); |
||
82 | Franz | 378 | } |
379 | |||
243 | Franz | 380 | |
381 | /* 03/31/2004 - xception handling |
||
382 | */ |
||
934 | subik | 383 | PyObject *scribus_pathtext(PyObject */*self*/, PyObject* args) |
82 | Franz | 384 | { |
385 | double x, y; |
||
934 | subik | 386 | char *Name = const_cast<char*>(""); |
387 | char *TextB = const_cast<char*>(""); |
||
388 | char *PolyB = const_cast<char*>(""); |
||
900 | cbradney | 389 | if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name)) |
82 | Franz | 390 | return NULL; |
649 | fschmid | 391 | if(!checkHaveDocument()) |
392 | return NULL; |
||
900 | cbradney | 393 | if (ItemExists(QString::fromUtf8(Name))) |
720 | subik | 394 | { |
899 | cbradney | 395 | PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error")); |
720 | subik | 396 | return NULL; |
397 | } |
||
398 | //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions |
||
399 | // its sets for us? |
||
900 | cbradney | 400 | int i = GetItem(QString::fromUtf8(TextB)); |
401 | int ii = GetItem(QString::fromUtf8(PolyB)); |
||
82 | Franz | 402 | if ((i == -1) || (ii == -1)) |
243 | Franz | 403 | { |
899 | cbradney | 404 | PyErr_SetString(NotFoundError, QObject::tr("Object not found","python error")); |
243 | Franz | 405 | return NULL; |
406 | } |
||
662 | fschmid | 407 | Carrier->view->SelItem.clear(); |
408 | Carrier->view->SelItem.append(Carrier->doc->Items.at(i)); |
||
409 | Carrier->view->SelItem.append(Carrier->doc->Items.at(ii)); |
||
410 | PageItem *it = Carrier->doc->Items.at(i); |
||
411 | Carrier->view->ToPathText(); |
||
1283 | subik | 412 | Carrier->view->MoveItem(pageUnitXToDocX(x) - it->Xpos, pageUnitYToDocY(y) - it->Ypos, it); |
720 | subik | 413 | if (Name != "") |
1361 | tsoots | 414 | it->setItemName(QString::fromUtf8(Name)); |
415 | return PyString_FromString(it->itemName().utf8()); |
||
82 | Franz | 416 | } |
417 | |||
243 | Franz | 418 | |
237 | Franz | 419 | /* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik) |
420 | */ |
||
934 | subik | 421 | PyObject *scribus_deleteobj(PyObject */*self*/, PyObject* args) |
82 | Franz | 422 | { |
934 | subik | 423 | char *Name = const_cast<char*>(""); |
900 | cbradney | 424 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 425 | return NULL; |
649 | fschmid | 426 | if(!checkHaveDocument()) |
427 | return NULL; |
||
900 | cbradney | 428 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
720 | subik | 429 | if (i == NULL) |
332 | Franz | 430 | return NULL; |
720 | subik | 431 | Carrier->view->SelItem.clear(); |
432 | Carrier->view->SelItem.append(i); |
||
433 | Carrier->view->DeleteItem(); |
||
647 | fschmid | 434 | Py_INCREF(Py_None); |
82 | Franz | 435 | return Py_None; |
436 | } |
||
437 | |||
243 | Franz | 438 | |
237 | Franz | 439 | /* 03/21/2004 - exception raises by non existent name (subik) |
440 | */ |
||
934 | subik | 441 | PyObject *scribus_textflow(PyObject */*self*/, PyObject* args) |
214 | Franz | 442 | { |
934 | subik | 443 | char *name = const_cast<char*>(""); |
332 | Franz | 444 | int state = -1; |
214 | Franz | 445 | |
900 | cbradney | 446 | if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state)) |
214 | Franz | 447 | return NULL; |
649 | fschmid | 448 | if(!checkHaveDocument()) |
449 | return NULL; |
||
900 | cbradney | 450 | PageItem *i = GetUniqueItem(QString::fromUtf8(name)); |
332 | Franz | 451 | if (i == NULL) |
237 | Franz | 452 | return NULL; |
214 | Franz | 453 | if (state == -1) |
332 | Franz | 454 | i->Textflow = !i->Textflow; |
214 | Franz | 455 | else |
332 | Franz | 456 | state ? i->Textflow = true : i->Textflow = false; |
214 | Franz | 457 | Carrier->view->DrawNew(); |
458 | Carrier->slotDocCh(true); |
||
647 | fschmid | 459 | Py_INCREF(Py_None); |
214 | Franz | 460 | return Py_None; |
461 | } |
||
243 | Franz | 462 | |
463 | |||
934 | subik | 464 | PyObject *scribus_objectexists(PyObject */*self*/, PyObject* args) |
243 | Franz | 465 | { |
934 | subik | 466 | char* name = const_cast<char*>(""); |
900 | cbradney | 467 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) |
243 | Franz | 468 | return NULL; |
649 | fschmid | 469 | if(!checkHaveDocument()) |
470 | return NULL; |
||
900 | cbradney | 471 | if (ItemExists(QString::fromUtf8(name))) |
720 | subik | 472 | return PyBool_FromLong(static_cast<long>(true)); |
473 | return PyBool_FromLong(static_cast<long>(false)); |
||
243 | Franz | 474 | } |
475 | |||
411 | Franz | 476 | /* |
477 | * Craig Ringer, 2004-09-09 |
||
478 | * Apply the named style to the currently selected object. |
||
479 | * pv, 2004-09-13, optionaly param objectName + "check the page" stuff |
||
480 | */ |
||
934 | subik | 481 | PyObject *scribus_setstyle(PyObject */*self*/, PyObject* args) |
411 | Franz | 482 | { |
934 | subik | 483 | char *style = const_cast<char*>(""); |
484 | char *name = const_cast<char*>(""); |
||
900 | cbradney | 485 | if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name)) |
411 | Franz | 486 | return NULL; |
649 | fschmid | 487 | if(!checkHaveDocument()) |
488 | return NULL; |
||
900 | cbradney | 489 | PageItem *item = GetUniqueItem(QString::fromUtf8(name)); |
720 | subik | 490 | if (item == NULL) |
491 | return NULL; |
||
900 | cbradney | 492 | if ((item->PType == FRAME_TEXT) || (item->PType == FRAME_PATHTEXT)) |
411 | Franz | 493 | { |
494 | /* |
||
495 | * First, find the style number associated with the requested style |
||
496 | * by scanning through the styles looking for the name. If |
||
497 | * we can't find it, raise PyExc_Exception. |
||
498 | * FIXME: Should use a more specific exception. |
||
499 | */ |
||
500 | bool found = false; |
||
501 | uint styleid = 0; |
||
502 | // We start at zero here because it's OK to match an internal name |
||
1065 | cbradney | 503 | for (uint i=0; i < Carrier->doc->docParagraphStyles.count(); ++i) |
411 | Franz | 504 | { |
1065 | cbradney | 505 | if (Carrier->doc->docParagraphStyles[i].Vname == QString::fromUtf8(style)) { |
411 | Franz | 506 | found = true; |
507 | styleid = i; |
||
508 | break; |
||
509 | } |
||
510 | } |
||
511 | if (!found) { |
||
512 | // whoops, the user specified an invalid style, complain loudly. |
||
899 | cbradney | 513 | PyErr_SetString(NotFoundError, QObject::tr("Style not found","python error")); |
411 | Franz | 514 | return NULL; |
515 | } |
||
516 | // quick hack to always apply on the right frame - pv |
||
662 | fschmid | 517 | Carrier->view->Deselect(true); |
518 | Carrier->view->SelectItemNr(item->ItemNr); |
||
411 | Franz | 519 | // Now apply the style. |
520 | Carrier->setNewAbStyle(styleid); |
||
521 | } |
||
720 | subik | 522 | else |
523 | { |
||
899 | cbradney | 524 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't set style on a non-text frame","python error")); |
720 | subik | 525 | return NULL; |
526 | } |
||
411 | Franz | 527 | Py_INCREF(Py_None); |
528 | return Py_None; |
||
529 | } |
||
530 | |||
531 | /* |
||
532 | * Craig Ringer, 2004-09-09 |
||
533 | * Enumerate all known paragraph styles |
||
534 | */ |
||
934 | subik | 535 | PyObject *scribus_getstylenames(PyObject */*self*/) |
411 | Franz | 536 | { |
537 | PyObject *styleList; |
||
649 | fschmid | 538 | if(!checkHaveDocument()) |
539 | return NULL; |
||
411 | Franz | 540 | styleList = PyList_New(0); |
541 | /* |
||
421 | Franz | 542 | We start at 5 because the lower styles are internal names. |
543 | pv - changet to get all (with system) objects |
||
649 | fschmid | 544 | FIXME: this should be a constant defined by the scribus core |
421 | Franz | 545 | */ |
1065 | cbradney | 546 | for (uint i=0; i < Carrier->doc->docParagraphStyles.count(); ++i) |
411 | Franz | 547 | { |
1065 | cbradney | 548 | if (PyList_Append(styleList, PyString_FromString(Carrier->doc->docParagraphStyles[i].Vname.utf8()))) |
411 | Franz | 549 | { |
550 | // An exception will have already been set by PyList_Append apparently. |
||
551 | return NULL; |
||
552 | } |
||
553 | } |
||
554 | return styleList; |
||
555 | } |
||
852 | subik | 556 | |
557 | /*! 2004-12-08 CR |
||
558 | * Return the internal frame type number for a frame. |
||
559 | */ |
||
934 | subik | 560 | PyObject* scribus_getframetype(PyObject */*self*/, PyObject* args, PyObject* kw) |
852 | subik | 561 | { |
934 | subik | 562 | char* frameName = const_cast<char*>(""); |
563 | char* kwds[] = {const_cast<char*>("frame="), const_cast<char*>("")}; |
||
852 | subik | 564 | if (!PyArg_ParseTupleAndKeywords(args, kw, "|s", kwds, &frameName)) |
565 | return NULL; |
||
566 | PageItem *it = GetUniqueItem(QString(frameName)); |
||
567 | if (it == NULL) |
||
568 | return NULL; |
||
569 | return PyInt_FromLong( (long)(it->PType) ); |
||
570 | } |