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