Rev 2674 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2674 | fschmid | 1 | /*************************************************************************** |
2 | * * |
||
3 | * This program is free software; you can redistribute it and/or modify * |
||
4 | * it under the terms of the GNU General Public License as published by * |
||
5 | * the Free Software Foundation; either version 2 of the License, or * |
||
6 | * (at your option) any later version. * |
||
7 | * * |
||
8 | ***************************************************************************/ |
||
103 | Franz | 9 | #include "cmdtext.h" |
10 | #include "cmdutil.h" |
||
82 | Franz | 11 | |
935 | subik | 12 | PyObject *scribus_getfontsize(PyObject */*self*/, PyObject* args) |
82 | Franz | 13 | { |
935 | subik | 14 | char *Name = const_cast<char*>(""); |
869 | cbradney | 15 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 16 | return NULL; |
535 | subik | 17 | if(!checkHaveDocument()) |
18 | return NULL; |
||
869 | cbradney | 19 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 20 | if (it == NULL) |
21 | return NULL; |
||
852 | subik | 22 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
23 | { |
||
24 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font size of non-text frame.","python error")); |
||
25 | return NULL; |
||
26 | } |
||
719 | subik | 27 | if (it->HasSel) |
213 | Franz | 28 | { |
719 | subik | 29 | for (uint b = 0; b < it->Ptext.count(); b++) |
30 | if (it->Ptext.at(b)->cselect) |
||
31 | return PyFloat_FromDouble(static_cast<double>(it->Ptext.at(b)->csize / 10.0)); |
||
1161 | cbradney | 32 | return NULL; |
213 | Franz | 33 | } |
719 | subik | 34 | else |
35 | return PyFloat_FromDouble(static_cast<long>(it->ISize / 10.0)); |
||
82 | Franz | 36 | } |
37 | |||
935 | subik | 38 | PyObject *scribus_getfont(PyObject */*self*/, PyObject* args) |
82 | Franz | 39 | { |
935 | subik | 40 | char *Name = const_cast<char*>(""); |
869 | cbradney | 41 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 42 | return NULL; |
535 | subik | 43 | if(!checkHaveDocument()) |
44 | return NULL; |
||
869 | cbradney | 45 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 46 | if (it == NULL) |
47 | return NULL; |
||
852 | subik | 48 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
49 | { |
||
50 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font of non-text frame.","python error")); |
||
51 | return NULL; |
||
52 | } |
||
719 | subik | 53 | if (it->HasSel) |
213 | Franz | 54 | { |
719 | subik | 55 | for (uint b = 0; b < it->Ptext.count(); b++) |
56 | if (it->Ptext.at(b)->cselect) |
||
869 | cbradney | 57 | return PyString_FromString(it->Ptext.at(b)->cfont.utf8()); |
1161 | cbradney | 58 | return NULL; |
213 | Franz | 59 | } |
719 | subik | 60 | else |
869 | cbradney | 61 | return PyString_FromString(it->IFont.utf8()); |
82 | Franz | 62 | } |
63 | |||
935 | subik | 64 | PyObject *scribus_gettextsize(PyObject */*self*/, PyObject* args) |
82 | Franz | 65 | { |
935 | subik | 66 | char *Name = const_cast<char*>(""); |
869 | cbradney | 67 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 68 | return NULL; |
535 | subik | 69 | if(!checkHaveDocument()) |
70 | return NULL; |
||
869 | cbradney | 71 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
852 | subik | 72 | if (i == NULL) |
73 | return NULL; |
||
74 | if ((i->PType != FRAME_TEXT) && (i->PType != FRAME_PATHTEXT)) |
||
75 | { |
||
76 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text size of non-text frame.","python error")); |
||
77 | return NULL; |
||
78 | } |
||
79 | return PyInt_FromLong(static_cast<long>(i->Ptext.count())); |
||
82 | Franz | 80 | } |
81 | |||
935 | subik | 82 | PyObject *scribus_getcolumns(PyObject */*self*/, PyObject* args) |
138 | Franz | 83 | { |
935 | subik | 84 | char *Name = const_cast<char*>(""); |
869 | cbradney | 85 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
138 | Franz | 86 | return NULL; |
535 | subik | 87 | if(!checkHaveDocument()) |
88 | return NULL; |
||
869 | cbradney | 89 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
852 | subik | 90 | if (i == NULL) |
91 | return NULL; |
||
92 | if (i->PType != FRAME_TEXT) |
||
93 | { |
||
94 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column count of non-text frame.","python error")); |
||
95 | return NULL; |
||
96 | } |
||
97 | return PyInt_FromLong(static_cast<long>(i->Cols)); |
||
138 | Franz | 98 | } |
99 | |||
935 | subik | 100 | PyObject *scribus_getlinespace(PyObject */*self*/, PyObject* args) |
82 | Franz | 101 | { |
935 | subik | 102 | char *Name = const_cast<char*>(""); |
869 | cbradney | 103 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 104 | return NULL; |
535 | subik | 105 | if(!checkHaveDocument()) |
106 | return NULL; |
||
869 | cbradney | 107 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
852 | subik | 108 | if (i == NULL) |
109 | return NULL; |
||
110 | if (i->PType != FRAME_TEXT) |
||
111 | { |
||
112 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get line space of non-text frame.","python error")); |
||
113 | return NULL; |
||
114 | } |
||
115 | return PyFloat_FromDouble(static_cast<double>(i->LineSp)); |
||
82 | Franz | 116 | } |
117 | |||
935 | subik | 118 | PyObject *scribus_getcolumngap(PyObject */*self*/, PyObject* args) |
138 | Franz | 119 | { |
935 | subik | 120 | char *Name = const_cast<char*>(""); |
869 | cbradney | 121 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
138 | Franz | 122 | return NULL; |
535 | subik | 123 | if(!checkHaveDocument()) |
124 | return NULL; |
||
869 | cbradney | 125 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
852 | subik | 126 | if (i == NULL) |
127 | return NULL; |
||
128 | if (i->PType != FRAME_TEXT) |
||
129 | { |
||
130 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column gap of non-text frame.","python error")); |
||
131 | return NULL; |
||
132 | } |
||
1511 | craig | 133 | return PyFloat_FromDouble(PointToValue(static_cast<double>(i->ColGap))); |
138 | Franz | 134 | } |
135 | |||
935 | subik | 136 | PyObject *scribus_getframetext(PyObject */*self*/, PyObject* args) |
95 | Franz | 137 | { |
935 | subik | 138 | char *Name = const_cast<char*>(""); |
869 | cbradney | 139 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
95 | Franz | 140 | return NULL; |
535 | subik | 141 | if(!checkHaveDocument()) |
142 | return NULL; |
||
95 | Franz | 143 | QString text = ""; |
869 | cbradney | 144 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 145 | if (it == NULL) |
146 | return NULL; |
||
852 | subik | 147 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
148 | { |
||
149 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error")); |
||
150 | return NULL; |
||
151 | } |
||
719 | subik | 152 | for (uint a = 0; a < it->Ptext.count(); a++) |
213 | Franz | 153 | { |
719 | subik | 154 | if (it->HasSel) |
213 | Franz | 155 | { |
719 | subik | 156 | if (it->Ptext.at(a)->cselect) |
95 | Franz | 157 | text += it->Ptext.at(a)->ch; |
213 | Franz | 158 | } |
719 | subik | 159 | else |
160 | { |
||
161 | text += it->Ptext.at(a)->ch; |
||
162 | } |
||
213 | Franz | 163 | } |
869 | cbradney | 164 | return PyString_FromString(text.utf8()); |
95 | Franz | 165 | } |
166 | |||
935 | subik | 167 | PyObject *scribus_gettext(PyObject */*self*/, PyObject* args) |
82 | Franz | 168 | { |
935 | subik | 169 | char *Name = const_cast<char*>(""); |
869 | cbradney | 170 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 171 | return NULL; |
535 | subik | 172 | if(!checkHaveDocument()) |
173 | return NULL; |
||
87 | Franz | 174 | QString text = ""; |
869 | cbradney | 175 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 176 | if (it == NULL) |
177 | return NULL; |
||
852 | subik | 178 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
179 | { |
||
180 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error")); |
||
181 | return NULL; |
||
182 | } |
||
719 | subik | 183 | PageItem *is = NULL; |
184 | // Scan backwards to find the first frame in a linked series |
||
185 | while (it->BackBox != 0) |
||
213 | Franz | 186 | { |
719 | subik | 187 | is = GetUniqueItem(it->BackBox->AnName); |
188 | if (is == NULL) |
||
213 | Franz | 189 | { |
719 | subik | 190 | // While GetUniqueItem has already set an exception, we'll |
191 | // overwrite that with a more suitable one for this particular case. |
||
852 | subik | 192 | // Not making this translatable, since it shouldnt' be seen and it's more important for |
193 | // us to be able to understand the error if it's reported. |
||
194 | PyErr_SetString(ScribusException, QString("(System Error) Broken linked frame series when scanning back")); |
||
719 | subik | 195 | return NULL; |
196 | } |
||
197 | it = is; |
||
198 | } // while |
||
199 | ///FIXME: What does this do? Could use a comment for explanation |
||
200 | for (uint a = 0; a < it->Ptext.count(); a++) |
||
201 | { |
||
202 | if (it->HasSel) |
||
203 | { |
||
204 | if (it->Ptext.at(a)->cselect) |
||
205 | text += it->Ptext.at(a)->ch; |
||
206 | } |
||
207 | else |
||
208 | { |
||
209 | text += it->Ptext.at(a)->ch; |
||
210 | } |
||
211 | } // for |
||
212 | // Scan forward through linked frames and ... what? |
||
213 | while (it->NextBox != 0) |
||
214 | { |
||
215 | is = GetUniqueItem(it->NextBox->AnName); |
||
216 | if (is == NULL) |
||
217 | { |
||
218 | // While GetUniqueItem has already set an exception, we'll |
||
219 | // overwrite that with a more suitable one for this particular case. |
||
852 | subik | 220 | // Not making this translatable, since it shouldnt' be seen and it's more important for |
221 | // us to be able to understand the error if it's reported. |
||
719 | subik | 222 | PyErr_SetString(ScribusException, QString("(System Error) Broken linked frame series when scanning forward")); |
223 | return NULL; |
||
224 | } |
||
225 | it = is; |
||
226 | assert(it != NULL); |
||
82 | Franz | 227 | for (uint a = 0; a < it->Ptext.count(); a++) |
213 | Franz | 228 | { |
229 | if (it->HasSel) |
||
82 | Franz | 230 | { |
231 | if (it->Ptext.at(a)->cselect) |
||
232 | text += it->Ptext.at(a)->ch; |
||
213 | Franz | 233 | } |
82 | Franz | 234 | else |
332 | Franz | 235 | { |
82 | Franz | 236 | text += it->Ptext.at(a)->ch; |
332 | Franz | 237 | } |
238 | } // for |
||
719 | subik | 239 | } // while |
869 | cbradney | 240 | return PyString_FromString(text.utf8()); |
82 | Franz | 241 | } |
242 | |||
935 | subik | 243 | PyObject *scribus_setboxtext(PyObject */*self*/, PyObject* args) |
82 | Franz | 244 | { |
935 | subik | 245 | char *Name = const_cast<char*>(""); |
82 | Franz | 246 | char *Text; |
869 | cbradney | 247 | if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Text, "utf-8", &Name)) |
82 | Franz | 248 | return NULL; |
535 | subik | 249 | if(!checkHaveDocument()) |
250 | return NULL; |
||
869 | cbradney | 251 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 252 | if (it == NULL) |
253 | return NULL; |
||
852 | subik | 254 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
255 | { |
||
256 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text of non-text frame.","python error")); |
||
257 | return NULL; |
||
258 | } |
||
391 | Franz | 259 | QString Daten = QString::fromUtf8(Text); |
260 | PyMem_Free(Text); |
||
719 | subik | 261 | if (it->NextBox != 0) |
213 | Franz | 262 | { |
719 | subik | 263 | PageItem *nb = it->NextBox; |
264 | while (nb != 0) |
||
213 | Franz | 265 | { |
719 | subik | 266 | nb->Ptext.clear(); |
267 | nb->CPos = 0; |
||
268 | nb = nb->NextBox; |
||
213 | Franz | 269 | } |
270 | } |
||
719 | subik | 271 | it->Ptext.clear(); |
272 | it->CPos = 0; |
||
273 | for (uint a = 0; a < Daten.length(); ++a) |
||
274 | { |
||
275 | struct Pti *hg = new Pti; |
||
276 | hg->ch = Daten.at(a); |
||
277 | if (hg->ch == QChar(10)) |
||
278 | hg->ch = QChar(13); |
||
279 | hg->cfont = it->IFont; |
||
280 | hg->csize = it->ISize; |
||
281 | hg->ccolor = it->TxtFill; |
||
282 | hg->cshade = it->ShTxtFill; |
||
283 | hg->cstroke = it->TxtStroke; |
||
284 | hg->cshade2 = it->ShTxtStroke; |
||
285 | hg->cscale = it->TxtScale; |
||
286 | hg->cextra = 0; |
||
287 | hg->cselect = false; |
||
288 | hg->cstyle = 0; |
||
289 | hg->cab = Carrier->doc->CurrentABStil; |
||
290 | hg->xp = 0; |
||
291 | hg->yp = 0; |
||
292 | hg->PRot = 0; |
||
293 | hg->PtransX = 0; |
||
294 | hg->PtransY = 0; |
||
295 | it->Ptext.append(hg); |
||
296 | } |
||
474 | subik | 297 | Py_INCREF(Py_None); |
82 | Franz | 298 | return Py_None; |
299 | } |
||
300 | |||
935 | subik | 301 | PyObject *scribus_inserttext(PyObject */*self*/, PyObject* args) |
82 | Franz | 302 | { |
935 | subik | 303 | char *Name = const_cast<char*>(""); |
82 | Franz | 304 | char *Text; |
87 | Franz | 305 | int pos; |
869 | cbradney | 306 | if (!PyArg_ParseTuple(args, "esi|es", "utf-8", &Text, &pos, "utf-8", &Name)) |
82 | Franz | 307 | return NULL; |
535 | subik | 308 | if(!checkHaveDocument()) |
309 | return NULL; |
||
869 | cbradney | 310 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 311 | if (it == NULL) |
312 | return NULL; |
||
852 | subik | 313 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
314 | { |
||
315 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error")); |
||
316 | return NULL; |
||
317 | } |
||
391 | Franz | 318 | QString Daten = QString::fromUtf8(Text); |
319 | PyMem_Free(Text); |
||
1979 | craig | 320 | if ((pos < -1) || (pos > static_cast<int>(it->Ptext.count()))) |
213 | Franz | 321 | { |
1522 | cbradney | 322 | PyErr_SetString(PyExc_IndexError, QObject::tr("Insert index out of bounds.","python error")); |
719 | subik | 323 | return NULL; |
213 | Franz | 324 | } |
1979 | craig | 325 | if (pos == -1) |
326 | pos = it->Ptext.count(); |
||
719 | subik | 327 | for (uint a = 0; a < Daten.length(); ++a) |
328 | { |
||
329 | struct Pti *hg = new Pti; |
||
330 | hg->ch = Daten.at(Daten.length()-1-a); |
||
331 | if (hg->ch == QChar(10)) |
||
332 | hg->ch = QChar(13); |
||
333 | hg->cfont = it->IFont; |
||
334 | hg->csize = it->ISize; |
||
335 | hg->ccolor = it->TxtFill; |
||
336 | hg->cshade = it->ShTxtFill; |
||
337 | hg->cstroke = it->TxtStroke; |
||
338 | hg->cshade2 = it->ShTxtStroke; |
||
339 | hg->cscale = it->TxtScale; |
||
340 | hg->cextra = 0; |
||
341 | hg->cselect = false; |
||
342 | hg->cstyle = 0; |
||
343 | hg->cab = Carrier->doc->CurrentABStil; |
||
344 | hg->xp = 0; |
||
345 | hg->yp = 0; |
||
346 | hg->PRot = 0; |
||
347 | hg->PtransX = 0; |
||
348 | hg->PtransY = 0; |
||
349 | it->Ptext.insert(pos, hg); |
||
350 | } |
||
351 | it->CPos = pos + Daten.length(); |
||
352 | it->paintObj(); |
||
474 | subik | 353 | Py_INCREF(Py_None); |
82 | Franz | 354 | return Py_None; |
355 | } |
||
356 | |||
935 | subik | 357 | PyObject *scribus_setalign(PyObject */*self*/, PyObject* args) |
82 | Franz | 358 | { |
935 | subik | 359 | char *Name = const_cast<char*>(""); |
719 | subik | 360 | int alignment; |
869 | cbradney | 361 | if (!PyArg_ParseTuple(args, "i|es", &alignment, "utf-8", &Name)) |
82 | Franz | 362 | return NULL; |
535 | subik | 363 | if(!checkHaveDocument()) |
364 | return NULL; |
||
815 | subik | 365 | if ((alignment > 4) || (alignment < 0)) |
474 | subik | 366 | { |
852 | subik | 367 | PyErr_SetString(PyExc_ValueError, QObject::tr("Alignment out of range. Use one of the scribus.ALIGN* constants.","python error")); |
368 | return NULL; |
||
474 | subik | 369 | } |
869 | cbradney | 370 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 371 | if (i == NULL) |
372 | return NULL; |
||
852 | subik | 373 | if (i->PType != FRAME_TEXT) |
213 | Franz | 374 | { |
1522 | cbradney | 375 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text alignment on a non-text frame.","python error")); |
719 | subik | 376 | return NULL; |
213 | Franz | 377 | } |
719 | subik | 378 | int Apm = Carrier->doc->AppMode; |
379 | i->OwnPage->SelItem.clear(); |
||
380 | i->OwnPage->SelItem.append(i); |
||
381 | if (i->HasSel) |
||
382 | Carrier->doc->AppMode = 7; |
||
383 | Carrier->setNewAbStyle(alignment); |
||
384 | Carrier->doc->AppMode = Apm; |
||
385 | i->OwnPage->Deselect(); |
||
474 | subik | 386 | Py_INCREF(Py_None); |
82 | Franz | 387 | return Py_None; |
388 | } |
||
389 | |||
935 | subik | 390 | PyObject *scribus_setfontsize(PyObject */*self*/, PyObject* args) |
82 | Franz | 391 | { |
935 | subik | 392 | char *Name = const_cast<char*>(""); |
111 | Franz | 393 | double size; |
869 | cbradney | 394 | if (!PyArg_ParseTuple(args, "d|es", &size, "utf-8", &Name)) |
82 | Franz | 395 | return NULL; |
535 | subik | 396 | if(!checkHaveDocument()) |
397 | return NULL; |
||
82 | Franz | 398 | if ((size > 512) || (size < 1)) |
474 | subik | 399 | { |
1522 | cbradney | 400 | PyErr_SetString(PyExc_ValueError, QObject::tr("Font size out of bounds - must be 1 <= size <= 512.","python error")); |
719 | subik | 401 | return NULL; |
474 | subik | 402 | } |
869 | cbradney | 403 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 404 | if (i == NULL) |
405 | return NULL; |
||
815 | subik | 406 | |
852 | subik | 407 | if (i->PType != FRAME_TEXT) |
213 | Franz | 408 | { |
1522 | cbradney | 409 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error")); |
719 | subik | 410 | return NULL; |
213 | Franz | 411 | } |
719 | subik | 412 | int Apm = Carrier->doc->AppMode; |
413 | i->OwnPage->SelItem.clear(); |
||
414 | i->OwnPage->SelItem.append(i); |
||
415 | if (i->HasSel) |
||
416 | Carrier->doc->AppMode = 7; |
||
417 | i->OwnPage->chFSize(qRound(size * 10.0)); |
||
418 | Carrier->doc->AppMode = Apm; |
||
419 | i->OwnPage->Deselect(); |
||
474 | subik | 420 | Py_INCREF(Py_None); |
82 | Franz | 421 | return Py_None; |
422 | } |
||
423 | |||
935 | subik | 424 | PyObject *scribus_setfont(PyObject */*self*/, PyObject* args) |
82 | Franz | 425 | { |
935 | subik | 426 | char *Name = const_cast<char*>(""); |
427 | char *Font = const_cast<char*>(""); |
||
869 | cbradney | 428 | if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Font, "utf-8", &Name)) |
82 | Franz | 429 | return NULL; |
535 | subik | 430 | if(!checkHaveDocument()) |
431 | return NULL; |
||
869 | cbradney | 432 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 433 | if (i == NULL) |
434 | return NULL; |
||
852 | subik | 435 | if ((i->PType != FRAME_TEXT) && (i->PType != FRAME_PATHTEXT)) |
213 | Franz | 436 | { |
1522 | cbradney | 437 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font on a non-text frame.","python error")); |
719 | subik | 438 | return NULL; |
439 | } |
||
869 | cbradney | 440 | if (Carrier->Prefs.AvailFonts.find(QString::fromUtf8(Font))) |
719 | subik | 441 | { |
332 | Franz | 442 | int Apm = Carrier->doc->AppMode; |
443 | i->OwnPage->SelItem.clear(); |
||
444 | i->OwnPage->SelItem.append(i); |
||
445 | if (i->HasSel) |
||
446 | Carrier->doc->AppMode = 7; |
||
869 | cbradney | 447 | Carrier->SetNewFont(QString::fromUtf8(Font)); |
332 | Franz | 448 | Carrier->doc->AppMode = Apm; |
449 | i->OwnPage->Deselect(); |
||
213 | Franz | 450 | } |
719 | subik | 451 | else |
452 | { |
||
1522 | cbradney | 453 | PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.","python error")); |
719 | subik | 454 | return NULL; |
455 | } |
||
474 | subik | 456 | Py_INCREF(Py_None); |
82 | Franz | 457 | return Py_None; |
458 | } |
||
459 | |||
935 | subik | 460 | PyObject *scribus_setlinespace(PyObject */*self*/, PyObject* args) |
82 | Franz | 461 | { |
935 | subik | 462 | char *Name = const_cast<char*>(""); |
82 | Franz | 463 | double w; |
869 | cbradney | 464 | if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) |
82 | Franz | 465 | return NULL; |
535 | subik | 466 | if(!checkHaveDocument()) |
467 | return NULL; |
||
474 | subik | 468 | if (w < 0.1) |
469 | { |
||
1522 | cbradney | 470 | PyErr_SetString(PyExc_ValueError, QObject::tr("Line space out of bounds, must be >= 0.1.","python error")); |
719 | subik | 471 | return NULL; |
474 | subik | 472 | } |
869 | cbradney | 473 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 474 | if (i == NULL) |
475 | return NULL; |
||
852 | subik | 476 | if (i->PType != FRAME_TEXT) |
477 | { |
||
1522 | cbradney | 478 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing on a non-text frame.","python error")); |
852 | subik | 479 | return NULL; |
480 | } |
||
719 | subik | 481 | i->LineSp = w; |
474 | subik | 482 | Py_INCREF(Py_None); |
82 | Franz | 483 | return Py_None; |
484 | } |
||
485 | |||
935 | subik | 486 | PyObject *scribus_setcolumngap(PyObject */*self*/, PyObject* args) |
138 | Franz | 487 | { |
935 | subik | 488 | char *Name = const_cast<char*>(""); |
138 | Franz | 489 | double w; |
869 | cbradney | 490 | if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) |
138 | Franz | 491 | return NULL; |
535 | subik | 492 | if(!checkHaveDocument()) |
493 | return NULL; |
||
474 | subik | 494 | if (w < 0.0) |
495 | { |
||
1522 | cbradney | 496 | PyErr_SetString(PyExc_ValueError, QObject::tr("Column gap out of bounds, must be positive.","python error")); |
719 | subik | 497 | return NULL; |
474 | subik | 498 | } |
869 | cbradney | 499 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 500 | if (i == NULL) |
501 | return NULL; |
||
852 | subik | 502 | if (i->PType != FRAME_TEXT) |
503 | { |
||
1522 | cbradney | 504 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set column gap on a non-text frame.","python error")); |
852 | subik | 505 | return NULL; |
506 | } |
||
1511 | craig | 507 | i->ColGap = ValueToPoint(w); |
474 | subik | 508 | Py_INCREF(Py_None); |
138 | Franz | 509 | return Py_None; |
510 | } |
||
511 | |||
935 | subik | 512 | PyObject *scribus_setcolumns(PyObject */*self*/, PyObject* args) |
138 | Franz | 513 | { |
935 | subik | 514 | char *Name = const_cast<char*>(""); |
138 | Franz | 515 | int w; |
869 | cbradney | 516 | if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) |
138 | Franz | 517 | return NULL; |
535 | subik | 518 | if(!checkHaveDocument()) |
519 | return NULL; |
||
474 | subik | 520 | if (w < 1) |
521 | { |
||
1522 | cbradney | 522 | PyErr_SetString(PyExc_ValueError, QObject::tr("Column count out of bounds, must be > 1.","python error")); |
719 | subik | 523 | return NULL; |
474 | subik | 524 | } |
869 | cbradney | 525 | PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 526 | if (i == NULL) |
527 | return NULL; |
||
852 | subik | 528 | if (i->PType != FRAME_TEXT) |
529 | { |
||
1522 | cbradney | 530 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set number of columns on a non-text frame.","python error")); |
852 | subik | 531 | return NULL; |
532 | } |
||
719 | subik | 533 | i->Cols = w; |
474 | subik | 534 | Py_INCREF(Py_None); |
138 | Franz | 535 | return Py_None; |
536 | } |
||
537 | |||
935 | subik | 538 | PyObject *scribus_selecttext(PyObject */*self*/, PyObject* args) |
82 | Franz | 539 | { |
935 | subik | 540 | char *Name = const_cast<char*>(""); |
1214 | subik | 541 | int start, selcount; |
542 | if (!PyArg_ParseTuple(args, "ii|es", &start, &selcount, "utf-8", &Name)) |
||
82 | Franz | 543 | return NULL; |
535 | subik | 544 | if(!checkHaveDocument()) |
545 | return NULL; |
||
869 | cbradney | 546 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 547 | if (it == NULL) |
548 | return NULL; |
||
1214 | subik | 549 | if (selcount == -1) |
213 | Franz | 550 | { |
1214 | subik | 551 | // user wants to select all after the start point -- CR |
552 | selcount = it->Ptext.count() - start; |
||
553 | if (selcount < 0) |
||
554 | // user passed start that's > text in the frame |
||
555 | selcount = 0; |
||
556 | } |
||
557 | // cr 2005-01-18 fixed off-by-one with end bound that made selecting the last char impossible |
||
558 | if ((start < 0) || ((start + selcount) > static_cast<int>(it->Ptext.count()))) |
||
559 | { |
||
560 | PyErr_SetString(PyExc_IndexError, QObject::tr("Selection index out of bounds", "python error")); |
||
719 | subik | 561 | return NULL; |
213 | Franz | 562 | } |
852 | subik | 563 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
564 | { |
||
1522 | cbradney | 565 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot select text in a non-text frame", "python error")); |
852 | subik | 566 | return NULL; |
567 | } |
||
719 | subik | 568 | /* FIXME: not sure if we should make this check or not |
1214 | subik | 569 | if (start > selcount) |
719 | subik | 570 | { |
571 | PyErr_SetString(PyExc_ValueError, QString("Selection start > selection end")); |
||
572 | return NULL; |
||
573 | } |
||
574 | */ |
||
575 | for (uint a = 0; a < it->Ptext.count(); ++a) |
||
576 | it->Ptext.at(a)->cselect = false; |
||
1214 | subik | 577 | if (selcount == 0) |
719 | subik | 578 | { |
579 | it->HasSel = false; |
||
580 | Py_INCREF(Py_None); |
||
581 | return Py_None; |
||
582 | } |
||
1214 | subik | 583 | for (int aa = start; aa < (start + selcount); ++aa) |
719 | subik | 584 | it->Ptext.at(aa)->cselect = true; |
585 | it->HasSel = true; |
||
474 | subik | 586 | Py_INCREF(Py_None); |
587 | return Py_None; |
||
82 | Franz | 588 | } |
589 | |||
935 | subik | 590 | PyObject *scribus_deletetext(PyObject */*self*/, PyObject* args) |
82 | Franz | 591 | { |
935 | subik | 592 | char *Name = const_cast<char*>(""); |
869 | cbradney | 593 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) |
82 | Franz | 594 | return NULL; |
535 | subik | 595 | if(!checkHaveDocument()) |
596 | return NULL; |
||
869 | cbradney | 597 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 598 | if (it == NULL) |
599 | return NULL; |
||
852 | subik | 600 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
601 | { |
||
1522 | cbradney | 602 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot delete text from a non-text frame.","python error")); |
852 | subik | 603 | return NULL; |
604 | } |
||
719 | subik | 605 | if (it->HasSel) |
606 | Carrier->DeleteSel(it); |
||
607 | else |
||
213 | Franz | 608 | { |
719 | subik | 609 | it->Ptext.clear(); |
610 | it->CPos = 0; |
||
213 | Franz | 611 | } |
474 | subik | 612 | Py_INCREF(Py_None); |
82 | Franz | 613 | return Py_None; |
614 | } |
||
615 | |||
935 | subik | 616 | PyObject *scribus_settextfill(PyObject */*self*/, PyObject* args) |
82 | Franz | 617 | { |
935 | subik | 618 | char *Name = const_cast<char*>(""); |
82 | Franz | 619 | char *Color; |
869 | cbradney | 620 | if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name)) |
82 | Franz | 621 | return NULL; |
535 | subik | 622 | if(!checkHaveDocument()) |
623 | return NULL; |
||
869 | cbradney | 624 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 625 | if (it == NULL) |
626 | return NULL; |
||
852 | subik | 627 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
213 | Franz | 628 | { |
1522 | cbradney | 629 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text fill on a non-text frame.","python error")); |
852 | subik | 630 | return NULL; |
631 | } |
||
632 | else |
||
633 | { |
||
332 | Franz | 634 | for (uint b = 0; b < it->Ptext.count(); b++) |
213 | Franz | 635 | { |
332 | Franz | 636 | if (it->HasSel) |
82 | Franz | 637 | { |
332 | Franz | 638 | if (it->Ptext.at(b)->cselect) |
869 | cbradney | 639 | it->Ptext.at(b)->ccolor = QString::fromUtf8(Color); |
213 | Franz | 640 | } |
332 | Franz | 641 | else |
869 | cbradney | 642 | it->Ptext.at(b)->ccolor = QString::fromUtf8(Color); |
82 | Franz | 643 | } |
869 | cbradney | 644 | it->TxtFill = QString::fromUtf8(Color); |
719 | subik | 645 | } |
474 | subik | 646 | Py_INCREF(Py_None); |
82 | Franz | 647 | return Py_None; |
648 | } |
||
649 | |||
935 | subik | 650 | PyObject *scribus_settextstroke(PyObject */*self*/, PyObject* args) |
82 | Franz | 651 | { |
935 | subik | 652 | char *Name = const_cast<char*>(""); |
82 | Franz | 653 | char *Color; |
869 | cbradney | 654 | if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name)) |
82 | Franz | 655 | return NULL; |
535 | subik | 656 | if(!checkHaveDocument()) |
657 | return NULL; |
||
869 | cbradney | 658 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 659 | if (it == NULL) |
660 | return NULL; |
||
852 | subik | 661 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
213 | Franz | 662 | { |
1522 | cbradney | 663 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text stroke on a non-text frame.","python error")); |
852 | subik | 664 | return NULL; |
665 | } |
||
666 | else |
||
667 | { |
||
332 | Franz | 668 | for (uint b = 0; b < it->Ptext.count(); b++) |
213 | Franz | 669 | { |
332 | Franz | 670 | if (it->HasSel) |
82 | Franz | 671 | { |
332 | Franz | 672 | if (it->Ptext.at(b)->cselect) |
869 | cbradney | 673 | it->Ptext.at(b)->cstroke = QString::fromUtf8(Color); |
213 | Franz | 674 | } |
332 | Franz | 675 | else |
869 | cbradney | 676 | it->Ptext.at(b)->cstroke = QString::fromUtf8(Color); |
82 | Franz | 677 | } |
869 | cbradney | 678 | it->TxtStroke = QString::fromUtf8(Color); |
719 | subik | 679 | } |
474 | subik | 680 | Py_INCREF(Py_None); |
82 | Franz | 681 | return Py_None; |
682 | } |
||
683 | |||
935 | subik | 684 | PyObject *scribus_settextshade(PyObject */*self*/, PyObject* args) |
82 | Franz | 685 | { |
935 | subik | 686 | char *Name = const_cast<char*>(""); |
87 | Franz | 687 | int w; |
869 | cbradney | 688 | if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) |
82 | Franz | 689 | return NULL; |
535 | subik | 690 | if(!checkHaveDocument()) |
691 | return NULL; |
||
474 | subik | 692 | if ((w < 0) || (w > 100)) |
693 | { |
||
694 | Py_INCREF(Py_None); |
||
82 | Franz | 695 | return Py_None; |
474 | subik | 696 | } |
869 | cbradney | 697 | PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); |
719 | subik | 698 | if (it == NULL) |
699 | return NULL; |
||
852 | subik | 700 | if ((it->PType != FRAME_TEXT) && (it->PType != FRAME_PATHTEXT)) |
213 | Franz | 701 | { |
1522 | cbradney | 702 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text shade on a non-text frame.","python error")); |
852 | subik | 703 | return NULL; |
704 | } |
||
705 | else |
||
706 | { |
||
332 | Franz | 707 | for (uint b = 0; b < it->Ptext.count(); ++b) |
213 | Franz | 708 | { |
332 | Franz | 709 | if (it->HasSel) |
82 | Franz | 710 | { |
332 | Franz | 711 | if (it->Ptext.at(b)->cselect) |
82 | Franz | 712 | it->Ptext.at(b)->cshade = w; |
713 | } |
||
332 | Franz | 714 | else |
715 | it->Ptext.at(b)->cshade = w; |
||
213 | Franz | 716 | } |
332 | Franz | 717 | it->ShTxtFill = w; |
213 | Franz | 718 | } |
474 | subik | 719 | Py_INCREF(Py_None); |
82 | Franz | 720 | return Py_None; |
721 | } |
||
722 | |||
935 | subik | 723 | PyObject *scribus_linktextframes(PyObject */*self*/, PyObject* args) |
213 | Franz | 724 | { |
725 | char *name1; |
||
726 | char *name2; |
||
727 | |||
869 | cbradney | 728 | if (!PyArg_ParseTuple(args, "eses", "utf-8", &name1, "utf-8", &name2)) |
213 | Franz | 729 | return NULL; |
535 | subik | 730 | if(!checkHaveDocument()) |
731 | return NULL; |
||
869 | cbradney | 732 | PageItem *fromitem = GetUniqueItem(QString::fromUtf8(name1)); |
719 | subik | 733 | if (fromitem == NULL) |
734 | return NULL; |
||
869 | cbradney | 735 | PageItem *toitem = GetUniqueItem(QString::fromUtf8(name2)); |
719 | subik | 736 | if (toitem == NULL) |
737 | return NULL; |
||
852 | subik | 738 | if ((fromitem->PType != FRAME_TEXT) || (toitem->PType != FRAME_TEXT)) |
739 | { |
||
1522 | cbradney | 740 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only link text frames.","python error")); |
852 | subik | 741 | return NULL; |
742 | } |
||
719 | subik | 743 | if (toitem->Ptext.count()) |
474 | subik | 744 | { |
1522 | cbradney | 745 | PyErr_SetString(ScribusException, QObject::tr("Target frame must be empty.","python error")); |
719 | subik | 746 | return NULL; |
474 | subik | 747 | } |
719 | subik | 748 | if (toitem->NextBox != 0) |
474 | subik | 749 | { |
1522 | cbradney | 750 | PyErr_SetString(ScribusException, QObject::tr("Target frame links to another frame.","python error")); |
719 | subik | 751 | return NULL; |
474 | subik | 752 | } |
719 | subik | 753 | if (toitem->BackBox != 0) |
213 | Franz | 754 | { |
1522 | cbradney | 755 | PyErr_SetString(ScribusException, QObject::tr("Target frame is linked to by another frame.","python error")); |
719 | subik | 756 | return NULL; |
757 | } |
||
758 | if (toitem == fromitem) |
||
759 | { |
||
1522 | cbradney | 760 | PyErr_SetString(ScribusException, QObject::tr("Source and target are the same object.","python error")); |
719 | subik | 761 | return NULL; |
762 | } |
||
763 | // references to the others boxes |
||
764 | fromitem->NextBox = toitem; |
||
765 | toitem->BackBox = fromitem; |
||
766 | fromitem->OwnPage->repaint(); |
||
767 | toitem->OwnPage->repaint(); |
||
768 | // enable 'save icon' stuff |
||
769 | Carrier->slotDocCh(); |
||
474 | subik | 770 | Py_INCREF(Py_None); |
213 | Franz | 771 | return Py_None; |
772 | } |
||
773 | |||
935 | subik | 774 | PyObject *scribus_unlinktextframes(PyObject */*self*/, PyObject* args) |
213 | Franz | 775 | { |
776 | char *name; |
||
869 | cbradney | 777 | if (!PyArg_ParseTuple(args, "es", "utf-8", &name)) |
213 | Franz | 778 | return NULL; |
535 | subik | 779 | if(!checkHaveDocument()) |
780 | return NULL; |
||
869 | cbradney | 781 | PageItem *item = GetUniqueItem(QString::fromUtf8(name)); |
719 | subik | 782 | if (item == NULL) |
783 | return NULL; |
||
852 | subik | 784 | if (item->PType != FRAME_TEXT) |
785 | { |
||
1522 | cbradney | 786 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot unlink a non-text frame.","python error")); |
852 | subik | 787 | return NULL; |
788 | } |
||
719 | subik | 789 | // only linked |
790 | if (item->BackBox == 0) |
||
474 | subik | 791 | { |
1522 | cbradney | 792 | PyErr_SetString(ScribusException, QObject::tr("Object is not a linked text frame, cannot unlink.","python error")); |
719 | subik | 793 | return NULL; |
474 | subik | 794 | } |
719 | subik | 795 | if (item->NextBox == 0) |
213 | Franz | 796 | { |
1522 | cbradney | 797 | PyErr_SetString(ScribusException, QObject::tr("Object the last frame in a series, cannot unlink. Unlink the previous frame instead.","python error")); |
719 | subik | 798 | return NULL; |
799 | } |
||
800 | PageItem* nextbox = item->NextBox; |
||
801 | while (nextbox != 0) |
||
802 | { |
||
803 | uint a = nextbox->Ptext.count(); |
||
804 | for (uint s=0; s<a; ++s) |
||
805 | item->Ptext.append(nextbox->Ptext.take(0)); |
||
806 | nextbox = nextbox->NextBox; |
||
807 | } // while |
||
808 | uint a2 = item->Ptext.count(); |
||
809 | for (uint s = 0; s < a2; ++s) |
||
810 | item->BackBox->Ptext.append(item->Ptext.take(0)); |
||
811 | item->BackBox->NextBox = 0; |
||
812 | item->BackBox = 0; |
||
213 | Franz | 813 | // enable 'save icon' stuff |
814 | Carrier->slotDocCh(); |
||
815 | item->OwnPage->repaint(); |
||
474 | subik | 816 | Py_INCREF(Py_None); |
213 | Franz | 817 | return Py_None; |
818 | } |
||
819 | |||
411 | Franz | 820 | /* |
719 | subik | 821 | * Convert the selected text frame to outlines. |
411 | Franz | 822 | * |
823 | * 2004-09-07 (Craig Ringer) |
||
719 | subik | 824 | * 2004-09-14 pv frame type, optional frame name param |
411 | Franz | 825 | */ |
935 | subik | 826 | PyObject *scribus_tracetext(PyObject */*self*/, PyObject* args) |
411 | Franz | 827 | { |
935 | subik | 828 | char *name = const_cast<char*>(""); |
869 | cbradney | 829 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) |
411 | Franz | 830 | return NULL; |
535 | subik | 831 | if(!checkHaveDocument()) |
832 | return NULL; |
||
869 | cbradney | 833 | PageItem *item = GetUniqueItem(QString::fromUtf8(name)); |
719 | subik | 834 | if (item == NULL) |
835 | return NULL; |
||
852 | subik | 836 | if (item->PType != FRAME_TEXT) |
411 | Franz | 837 | { |
1522 | cbradney | 838 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot convert a non-text frame to outlines.","python error")); |
719 | subik | 839 | return NULL; |
411 | Franz | 840 | } |
719 | subik | 841 | Carrier->doc->ActPage = item->OwnPage; |
842 | Carrier->doc->ActPage->Deselect(true); |
||
843 | Carrier->doc->ActPage->SelectItemNr(item->ItemNr); |
||
844 | Carrier->doc->ActPage->TextToPath(); |
||
474 | subik | 845 | Py_INCREF(Py_None); |
411 | Franz | 846 | return Py_None; |
847 | } |
||
1533 | subik | 848 | |
3927 | subik | 849 | PyObject *scribus_istextoverflowing(PyObject * /*self*/, PyObject* args, PyObject* kw) |
850 | { |
||
851 | char *name = const_cast<char*>(""); |
||
852 | bool nolinks = false; |
||
853 | char *kwargs[] = {const_cast<char*>("name"), const_cast<char*>("nolinks"), NULL}; |
||
854 | if (!PyArg_ParseTupleAndKeywords(args, kw, "|esi", kwargs, "utf-8", &name, &nolinks)) |
||
855 | return NULL; |
||
856 | if(!checkHaveDocument()) |
||
857 | return NULL; |
||
858 | PageItem *item = GetUniqueItem(QString::fromUtf8(name)); |
||
859 | if (item == NULL) |
||
860 | return NULL; |
||
861 | if (item->PType != FRAME_TEXT) |
||
862 | { |
||
863 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Only text frames can be checked for overflowing", "python error")); |
||
864 | return NULL; |
||
865 | } |
||
866 | /* original solution |
||
867 | if (item->itemText.count() > item->MaxChars) |
||
868 | return PyBool_FromLong(static_cast<long>(true)); |
||
869 | return PyBool_FromLong(static_cast<long>(false)); */ |
||
870 | uint firstFrame = 0; |
||
871 | if (nolinks) |
||
872 | firstFrame = item->Ptext.count(); |
||
873 | uint chars = item->Ptext.count(); |
||
874 | uint maxchars = item->MaxChars; |
||
875 | while (item->NextBox != 0) { |
||
876 | item = item->NextBox; |
||
877 | chars += item->Ptext.count(); |
||
878 | maxchars += item->MaxChars; |
||
879 | } |
||
880 | // no overrun |
||
881 | if (nolinks) |
||
882 | return PyInt_FromLong(maxchars - firstFrame); |
||
883 | |||
884 | if (maxchars > chars) |
||
885 | return PyInt_FromLong(0); |
||
886 | // number of overrunning letters |
||
887 | return PyInt_FromLong(static_cast<long>(chars - maxchars)); |
||
888 | } |
||
889 | |||
1533 | subik | 890 | PyObject *scribus_setpdfbookmark(PyObject */*self*/, PyObject* args) |
891 | { |
||
892 | char *name = const_cast<char*>(""); |
||
893 | bool toggle; |
||
894 | if (!PyArg_ParseTuple(args, "b|es", &toggle, "utf-8", &name)) |
||
895 | return NULL; |
||
896 | if (!checkHaveDocument()) |
||
897 | return NULL; |
||
898 | PageItem *i = GetUniqueItem(QString::fromUtf8(name)); |
||
899 | if (i == NULL) |
||
900 | return NULL; |
||
901 | if (i->PType != FRAME_TEXT) |
||
902 | { |
||
903 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't set bookmark on a non-text frame", "python error")); |
||
904 | return NULL; |
||
905 | } |
||
906 | if (i->isBookmark == toggle) |
||
907 | { |
||
908 | Py_INCREF(Py_None); |
||
909 | return Py_None; |
||
910 | } |
||
911 | if (toggle) |
||
912 | { |
||
913 | i->isAnnotation = false; |
||
914 | Carrier->AddBookMark(i); |
||
915 | } |
||
916 | else |
||
917 | Carrier->DelBookMark(i); |
||
918 | i->isBookmark = toggle; |
||
919 | Py_INCREF(Py_None); |
||
920 | return Py_None; |
||
921 | } |
||
922 | |||
923 | PyObject *scribus_ispdfbookmark(PyObject */*self*/, PyObject* args) |
||
924 | { |
||
925 | char *name = const_cast<char*>(""); |
||
926 | if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) |
||
927 | return NULL; |
||
928 | if (!checkHaveDocument()) |
||
929 | return NULL; |
||
930 | PageItem *i = GetUniqueItem(QString::fromUtf8(name)); |
||
931 | if (i == NULL) |
||
932 | return NULL; |
||
933 | if (i->PType != FRAME_TEXT) |
||
934 | { |
||
935 | PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't get info from a non-text frame", "python error")); |
||
936 | return NULL; |
||
937 | } |
||
938 | if (i->isBookmark) |
||
939 | return PyBool_FromLong(1); |
||
940 | return PyBool_FromLong(0); |
||
941 | } |