Back to index

scribus-ng  1.3.4.dfsg+svn20071115
cmdtext.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "cmdtext.h"
00008 #include "cmdutil.h"
00009 #include "pageitem_textframe.h"
00010 #include "prefsmanager.h"
00011 #include "selection.h"
00012 #include "util.h"
00013 #include "scribuscore.h"
00014 
00015 PyObject *scribus_getfontsize(PyObject* /* self */, PyObject* args)
00016 {
00017        char *Name = const_cast<char*>("");
00018        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00019               return NULL;
00020        if(!checkHaveDocument())
00021               return NULL;
00022        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00023        if (it == NULL)
00024               return NULL;
00025        if (!(it->asTextFrame()) && !(it->asPathText()))
00026        {
00027               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font size of non-text frame.","python error"));
00028               return NULL;
00029        }
00030        if (it->HasSel)
00031        {
00032               for (int b = 0; b < it->itemText.length(); b++)
00033                      if (it->itemText.selected(b))
00034                             return PyFloat_FromDouble(static_cast<double>(it->itemText.charStyle(b).fontSize() / 10.0));
00035               return NULL;
00036        }
00037        else
00038               return PyFloat_FromDouble(static_cast<long>(it->currentCharStyle().fontSize() / 10.0));
00039 }
00040 
00041 PyObject *scribus_getfont(PyObject* /* self */, PyObject* args)
00042 {
00043        char *Name = const_cast<char*>("");
00044        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00045               return NULL;
00046        if(!checkHaveDocument())
00047               return NULL;
00048        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00049        if (it == NULL)
00050               return NULL;
00051        if (!(it->asTextFrame()) && !(it->asPathText()))
00052        {
00053               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font of non-text frame.","python error"));
00054               return NULL;
00055        }
00056        if (it->HasSel)
00057        {
00058               for (int b = 0; b < it->itemText.length(); b++)
00059                      if (it->itemText.selected(b))
00060                             return PyString_FromString(it->itemText.charStyle(b).font().scName().utf8());
00061               return NULL;
00062        }
00063        else
00064               return PyString_FromString(it->currentCharStyle().font().scName().utf8());
00065 }
00066 
00067 PyObject *scribus_gettextsize(PyObject* /* self */, PyObject* args)
00068 {
00069        char *Name = const_cast<char*>("");
00070        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00071               return NULL;
00072        if(!checkHaveDocument())
00073               return NULL;
00074        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00075        if (i == NULL)
00076               return NULL;
00077        if (!(i->asTextFrame()) && !(i->asPathText()))
00078        {
00079               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text size of non-text frame.","python error"));
00080               return NULL;
00081        }
00082        return PyInt_FromLong(static_cast<long>(i->itemText.length()));
00083 }
00084 
00085 PyObject *scribus_gettextlines(PyObject* /* self */, PyObject* args)
00086 {
00087        char *Name = const_cast<char*>("");
00088        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00089               return NULL;
00090        if(!checkHaveDocument())
00091               return NULL;
00092        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00093        if (i == NULL)
00094               return NULL;
00095        if (!(i->asTextFrame()) && !(i->asPathText()))
00096        {
00097               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get number of lines of non-text frame.","python error"));
00098               return NULL;
00099        }
00100        return PyInt_FromLong(static_cast<long>(i->itemText.lines()));
00101 }
00102 
00103 PyObject *scribus_getcolumns(PyObject* /* self */, PyObject* args)
00104 {
00105        char *Name = const_cast<char*>("");
00106        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00107               return NULL;
00108        if(!checkHaveDocument())
00109               return NULL;
00110        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00111        if (i == NULL)
00112               return NULL;
00113        if (!i->asTextFrame())
00114        {
00115               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column count of non-text frame.","python error"));
00116               return NULL;
00117        }
00118        return PyInt_FromLong(static_cast<long>(i->Cols));
00119 }
00120 
00121 PyObject *scribus_getlinespace(PyObject* /* self */, PyObject* args)
00122 {
00123        char *Name = const_cast<char*>("");
00124        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00125               return NULL;
00126        if(!checkHaveDocument())
00127               return NULL;
00128        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00129        if (i == NULL)
00130               return NULL;
00131        if (!i->asTextFrame())
00132        {
00133               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get line space of non-text frame.","python error"));
00134               return NULL;
00135        }
00136        return PyFloat_FromDouble(static_cast<double>(i->currentStyle().lineSpacing()));
00137 }
00138 
00139 PyObject *scribus_getcolumngap(PyObject* /* self */, PyObject* args)
00140 {
00141        char *Name = const_cast<char*>("");
00142        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00143               return NULL;
00144        if(!checkHaveDocument())
00145               return NULL;
00146        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00147        if (i == NULL)
00148               return NULL;
00149        if (!i->asTextFrame())
00150        {
00151               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column gap of non-text frame.","python error"));
00152               return NULL;
00153        }
00154        return PyFloat_FromDouble(PointToValue(static_cast<double>(i->ColGap)));
00155 }
00156 
00157 PyObject *scribus_getframetext(PyObject* /* self */, PyObject* args)
00158 {
00159        char *Name = const_cast<char*>("");
00160        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00161               return NULL;
00162        if(!checkHaveDocument())
00163               return NULL;
00164        QString text = "";
00165        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00166        if (it == NULL)
00167               return NULL;
00168        if (!(it->asTextFrame()) && !(it->asPathText()))
00169        {
00170               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error"));
00171               return NULL;
00172        }
00173        for (int a = it->firstInFrame(); a < it->lastInFrame(); a++)
00174        {
00175               if (it->HasSel)
00176               {
00177                      if (it->itemText.selected(a))
00178                             text += it->itemText.text(a);
00179               }
00180               else
00181               {
00182                      text += it->itemText.text(a);
00183               }
00184        }
00185        return PyString_FromString(text.utf8());
00186 }
00187 
00188 PyObject *scribus_gettext(PyObject* /* self */, PyObject* args)
00189 {
00190        char *Name = const_cast<char*>("");
00191        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00192               return NULL;
00193        if(!checkHaveDocument())
00194               return NULL;
00195        QString text = "";
00196        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00197        if (it == NULL)
00198               return NULL;
00199        if (!(it->asTextFrame()) && !(it->asPathText()))
00200        {
00201               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error"));
00202               return NULL;
00203        }
00204 
00205        // collect all chars from a storytext
00206        for (int a = 0; a < it->itemText.length(); a++)
00207        {
00208               if (it->HasSel)
00209               {
00210                      if (it->itemText.selected(a))
00211                             text += it->itemText.text(a);
00212               }
00213               else
00214               {
00215                      text += it->itemText.text(a);
00216               }
00217        } // for
00218        return PyString_FromString(text.utf8());
00219 }
00220 
00221 PyObject *scribus_setboxtext(PyObject* /* self */, PyObject* args)
00222 {
00223        char *Name = const_cast<char*>("");
00224        char *Text;
00225        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Text, "utf-8", &Name))
00226               return NULL;
00227        if(!checkHaveDocument())
00228               return NULL;
00229        PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
00230        if (currItem == NULL)
00231               return NULL;
00232        if (!(currItem->asTextFrame()) && !(currItem->asPathText()))
00233        {
00234               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text of non-text frame.","python error"));
00235               return NULL;
00236        }
00237        QString Daten = QString::fromUtf8(Text);
00238        PyMem_Free(Text);
00239        currItem->itemText.clear();
00240        currItem->CPos = 0;
00241        for (uint a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a)
00242        {
00243               ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a;
00244        }
00245        currItem->itemText.insertChars(0, Daten);
00246        currItem->Dirty = false;
00247 //     Py_INCREF(Py_None);
00248 //     return Py_None;
00249        Py_RETURN_NONE;
00250 }
00251 
00252 PyObject *scribus_inserttext(PyObject* /* self */, PyObject* args)
00253 {
00254        char *Name = const_cast<char*>("");
00255        char *Text;
00256        int pos;
00257        if (!PyArg_ParseTuple(args, "esi|es", "utf-8", &Text, &pos, "utf-8", &Name))
00258               return NULL;
00259        if(!checkHaveDocument())
00260               return NULL;
00261        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00262        if (it == NULL)
00263               return NULL;
00264        if (!(it->asTextFrame()) && !(it->asPathText()))
00265        {
00266               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error"));
00267               return NULL;
00268        }
00269        QString Daten = QString::fromUtf8(Text);
00270        PyMem_Free(Text);
00271        if ((pos < -1) || (pos > static_cast<int>(it->itemText.length())))
00272        {
00273               PyErr_SetString(PyExc_IndexError, QObject::tr("Insert index out of bounds.","python error"));
00274               return NULL;
00275        }
00276        if (pos == -1)
00277               pos = it->itemText.length();
00278        it->itemText.insertChars(pos, Daten);
00279        it->CPos = pos + Daten.length();
00280        it->Dirty = true;
00281        if (ScCore->primaryMainWindow()->doc->DoDrawing)
00282        {
00283               it->paintObj();
00284               it->Dirty = false;
00285        }
00286 //     Py_INCREF(Py_None);
00287 //     return Py_None;
00288        Py_RETURN_NONE;
00289 }
00290 
00291 PyObject *scribus_setalign(PyObject* /* self */, PyObject* args)
00292 {
00293        char *Name = const_cast<char*>("");
00294        int alignment;
00295        if (!PyArg_ParseTuple(args, "i|es", &alignment, "utf-8", &Name))
00296               return NULL;
00297        if(!checkHaveDocument())
00298               return NULL;
00299        if ((alignment > 4) || (alignment < 0))
00300        {
00301               PyErr_SetString(PyExc_ValueError, QObject::tr("Alignment out of range. Use one of the scribus.ALIGN* constants.","python error"));
00302               return NULL;
00303        }
00304        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00305        if (i == NULL)
00306               return NULL;
00307        if (!i->asTextFrame())
00308        {
00309               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text alignment on a non-text frame.","python error"));
00310               return NULL;
00311        }
00312        int Apm = ScCore->primaryMainWindow()->doc->appMode;
00313        ScCore->primaryMainWindow()->doc->m_Selection->clear();
00314        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
00315        if (i->HasSel)
00316               ScCore->primaryMainWindow()->doc->appMode = modeEdit;
00317        ScCore->primaryMainWindow()->setNewAlignment(alignment);
00318        ScCore->primaryMainWindow()->doc->appMode = Apm;
00319        ScCore->primaryMainWindow()->view->Deselect();
00320 //     Py_INCREF(Py_None);
00321 //     return Py_None;
00322        Py_RETURN_NONE;
00323 }
00324 
00325 PyObject *scribus_setfontsize(PyObject* /* self */, PyObject* args)
00326 {
00327        char *Name = const_cast<char*>("");
00328        double size;
00329        if (!PyArg_ParseTuple(args, "d|es", &size, "utf-8", &Name))
00330               return NULL;
00331        if(!checkHaveDocument())
00332               return NULL;
00333        if ((size > 512) || (size < 1))
00334        {
00335               PyErr_SetString(PyExc_ValueError, QObject::tr("Font size out of bounds - must be 1 <= size <= 512.","python error"));
00336               return NULL;
00337        }
00338        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00339        if (i == NULL)
00340               return NULL;
00341 
00342        if (!i->asTextFrame())
00343        {
00344               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error"));
00345               return NULL;
00346        }
00347        int Apm = ScCore->primaryMainWindow()->doc->appMode;
00348        ScCore->primaryMainWindow()->doc->m_Selection->clear();
00349        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
00350        if (i->HasSel)
00351               ScCore->primaryMainWindow()->doc->appMode = modeEdit;
00352        ScCore->primaryMainWindow()->doc->itemSelection_SetFontSize(qRound(size * 10.0));
00353        ScCore->primaryMainWindow()->doc->appMode = Apm;
00354        ScCore->primaryMainWindow()->view->Deselect();
00355 //     Py_INCREF(Py_None);
00356 //     return Py_None;
00357        Py_RETURN_NONE;
00358 }
00359 
00360 PyObject *scribus_setfont(PyObject* /* self */, PyObject* args)
00361 {
00362        char *Name = const_cast<char*>("");
00363        char *Font = const_cast<char*>("");
00364        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Font, "utf-8", &Name))
00365               return NULL;
00366        if(!checkHaveDocument())
00367               return NULL;
00368        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00369        if (i == NULL)
00370               return NULL;
00371        if (!(i->asTextFrame()) && !(i->asPathText()))
00372        {
00373               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font on a non-text frame.","python error"));
00374               return NULL;
00375        }
00376        if (PrefsManager::instance()->appPrefs.AvailFonts.contains(QString::fromUtf8(Font)))
00377        {
00378               int Apm = ScCore->primaryMainWindow()->doc->appMode;
00379               ScCore->primaryMainWindow()->doc->m_Selection->clear();
00380               ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
00381               if (i->HasSel)
00382                      ScCore->primaryMainWindow()->doc->appMode = modeEdit;
00383               ScCore->primaryMainWindow()->SetNewFont(QString::fromUtf8(Font));
00384               ScCore->primaryMainWindow()->doc->appMode = Apm;
00385               ScCore->primaryMainWindow()->view->Deselect();
00386        }
00387        else
00388        {
00389               PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.","python error"));
00390               return NULL;
00391        }
00392 //     Py_INCREF(Py_None);
00393 //     return Py_None;
00394        Py_RETURN_NONE;
00395 }
00396 
00397 PyObject *scribus_setlinespace(PyObject* /* self */, PyObject* args)
00398 {
00399        char *Name = const_cast<char*>("");
00400        double w;
00401        if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
00402               return NULL;
00403        if(!checkHaveDocument())
00404               return NULL;
00405        if (w < 0.1)
00406        {
00407               PyErr_SetString(PyExc_ValueError, QObject::tr("Line space out of bounds, must be >= 0.1.","python error"));
00408               return NULL;
00409        }
00410        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00411        if (i == NULL)
00412               return NULL;
00413        if (!i->asTextFrame())
00414        {
00415               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing on a non-text frame.","python error"));
00416               return NULL;
00417        }
00418 //     i->setLineSpacing(w);
00419 //     Py_INCREF(Py_None);
00420 //     return Py_None;
00421        Py_RETURN_NONE;
00422 }
00423 
00424 PyObject *scribus_setcolumngap(PyObject* /* self */, PyObject* args)
00425 {
00426        char *Name = const_cast<char*>("");
00427        double w;
00428        if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
00429               return NULL;
00430        if(!checkHaveDocument())
00431               return NULL;
00432        if (w < 0.0)
00433        {
00434               PyErr_SetString(PyExc_ValueError, QObject::tr("Column gap out of bounds, must be positive.","python error"));
00435               return NULL;
00436        }
00437        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00438        if (i == NULL)
00439               return NULL;
00440        if (!i->asTextFrame())
00441        {
00442               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set column gap on a non-text frame.","python error"));
00443               return NULL;
00444        }
00445        i->ColGap = ValueToPoint(w);
00446 //     Py_INCREF(Py_None);
00447 //     return Py_None;
00448        Py_RETURN_NONE;
00449 }
00450 
00451 PyObject *scribus_setcolumns(PyObject* /* self */, PyObject* args)
00452 {
00453        char *Name = const_cast<char*>("");
00454        int w;
00455        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00456               return NULL;
00457        if(!checkHaveDocument())
00458               return NULL;
00459        if (w < 1)
00460        {
00461               PyErr_SetString(PyExc_ValueError, QObject::tr("Column count out of bounds, must be > 1.","python error"));
00462               return NULL;
00463        }
00464        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00465        if (i == NULL)
00466               return NULL;
00467        if (!i->asTextFrame())
00468        {
00469               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set number of columns on a non-text frame.","python error"));
00470               return NULL;
00471        }
00472        i->Cols = w;
00473 //     Py_INCREF(Py_None);
00474 //     return Py_None;
00475        Py_RETURN_NONE;
00476 }
00477 
00478 PyObject *scribus_selecttext(PyObject* /* self */, PyObject* args)
00479 {
00480        char *Name = const_cast<char*>("");
00481        int start, selcount;
00482        if (!PyArg_ParseTuple(args, "ii|es", &start, &selcount, "utf-8", &Name))
00483               return NULL;
00484        if(!checkHaveDocument())
00485               return NULL;
00486        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00487        if (it == NULL)
00488               return NULL;
00489        if (selcount == -1)
00490        {
00491               // user wants to select all after the start point -- CR
00492               selcount = it->itemText.length() - start;
00493               if (selcount < 0)
00494                      // user passed start that's > text in the frame
00495                      selcount = 0;
00496        }
00497        // cr 2005-01-18 fixed off-by-one with end bound that made selecting the last char impossible
00498        if ((start < 0) || ((start + selcount) > static_cast<int>(it->itemText.length())))
00499        {
00500               PyErr_SetString(PyExc_IndexError, QObject::tr("Selection index out of bounds", "python error"));
00501               return NULL;
00502        }
00503        if (!(it->asTextFrame()) && !(it->asPathText()))
00504        {
00505               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot select text in a non-text frame", "python error"));
00506               return NULL;
00507        }
00508        /* FIXME: not sure if we should make this check or not
00509        if (start > ende)
00510        {
00511               PyErr_SetString(PyExc_ValueError, QString("Selection start > selection end"));
00512               return NULL;
00513        }
00514        */
00515        it->itemText.deselectAll();
00516        if (selcount == 0)
00517        {
00518               it->HasSel = false;
00519 //            Py_INCREF(Py_None);
00520 //            return Py_None;
00521               Py_RETURN_NONE;
00522        }
00523        it->itemText.select(start, selcount, true);
00524        it->HasSel = true;
00525 //     Py_INCREF(Py_None);
00526 //     return Py_None;
00527        Py_RETURN_NONE;
00528 }
00529 
00530 PyObject *scribus_deletetext(PyObject* /* self */, PyObject* args)
00531 {
00532        char *Name = const_cast<char*>("");
00533        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00534               return NULL;
00535        if(!checkHaveDocument())
00536               return NULL;
00537        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00538        if (it == NULL)
00539               return NULL;
00540        if (!(it->asTextFrame()) && !(it->asPathText()))
00541        {
00542               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot delete text from a non-text frame.","python error"));
00543               return NULL;
00544        }
00545        if (it->HasSel)
00546               dynamic_cast<PageItem_TextFrame*>(it)->deleteSelectedTextFromFrame();
00547        else
00548        {
00549               it->itemText.clear();
00550               it->CPos = 0;
00551               for (uint a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a)
00552               {
00553                      ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a;
00554               }
00555        }
00556 //     Py_INCREF(Py_None);
00557 //     return Py_None;
00558        Py_RETURN_NONE;
00559 }
00560 
00561 PyObject *scribus_settextfill(PyObject* /* self */, PyObject* args)
00562 {
00563        char *Name = const_cast<char*>("");
00564        char *Color;
00565        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name))
00566               return NULL;
00567        if(!checkHaveDocument())
00568               return NULL;
00569        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00570        if (it == NULL)
00571               return NULL;
00572        if (!(it->asTextFrame()) && !(it->asPathText()))
00573        {
00574               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text fill on a non-text frame.","python error"));
00575               return NULL;
00576        }
00577        else
00578        {
00579               for (int b = 0; b < it->itemText.length(); b++)
00580               {
00581                      //FIXME: doc method
00582                      if (it->HasSel)
00583                      {
00584                             if (it->itemText.selected(b))
00585                                    it->itemText.item(b)->setFillColor(QString::fromUtf8(Color));
00586                      }
00587                      else
00588                             it->itemText.item(b)->setFillColor(QString::fromUtf8(Color));
00589               }
00590 //            it->TxtFill = QString::fromUtf8(Color);
00591        }
00592 //     Py_INCREF(Py_None);
00593 //     return Py_None;
00594        Py_RETURN_NONE;
00595 }
00596 
00597 PyObject *scribus_settextstroke(PyObject* /* self */, PyObject* args)
00598 {
00599        char *Name = const_cast<char*>("");
00600        char *Color;
00601        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name))
00602               return NULL;
00603        if(!checkHaveDocument())
00604               return NULL;
00605        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00606        if (it == NULL)
00607               return NULL;
00608        if (!(it->asTextFrame()) && (it->asPathText()))
00609        {
00610               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text stroke on a non-text frame.","python error"));
00611               return NULL;
00612        }
00613        else
00614        {
00615               for (int b = 0; b < it->itemText.length(); b++)
00616               {
00617                      //FIXME:NLS use document method for this
00618                      if (it->HasSel)
00619                      {
00620                             if (it->itemText.selected(b))
00621                                    it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color));
00622                      }
00623                      else
00624                             it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color));
00625               }
00626 //            it->TxtStroke = QString::fromUtf8(Color);
00627        }
00628 //     Py_INCREF(Py_None);
00629 //     return Py_None;
00630        Py_RETURN_NONE;
00631 }
00632 
00633 PyObject *scribus_settextshade(PyObject* /* self */, PyObject* args)
00634 {
00635        char *Name = const_cast<char*>("");
00636        int w;
00637        if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
00638               return NULL;
00639        if(!checkHaveDocument())
00640               return NULL;
00641        if ((w < 0) || (w > 100))
00642        {
00643 //            Py_INCREF(Py_None);
00644 //            return Py_None;
00645               Py_RETURN_NONE;
00646        }
00647        PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
00648        if (it == NULL)
00649               return NULL;
00650        if (!(it->asTextFrame()) && !(it->asPathText()))
00651        {
00652               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text shade on a non-text frame.","python error"));
00653               return NULL;
00654        }
00655        else
00656        {
00657               //FIXME:NLS use document method for that
00658               for (int b = 0; b < it->itemText.length(); ++b)
00659               {
00660                      if (it->HasSel)
00661                      {
00662                             if (it->itemText.selected(b))
00663                                    it->itemText.item(b)->setFillShade(w);
00664                      }
00665                      else
00666                             it->itemText.item(b)->setFillShade(w);
00667               }
00668 //     it->ShTxtFill = w;
00669        }
00670 //     Py_INCREF(Py_None);
00671 //     return Py_None;
00672        Py_RETURN_NONE;
00673 }
00674 
00675 PyObject *scribus_linktextframes(PyObject* /* self */, PyObject* args)
00676 {
00677        char *name1;
00678        char *name2;
00679 
00680        if (!PyArg_ParseTuple(args, "eses", "utf-8", &name1, "utf-8", &name2))
00681               return NULL;
00682        if(!checkHaveDocument())
00683               return NULL;
00684        PageItem *fromitem = GetUniqueItem(QString::fromUtf8(name1));
00685        if (fromitem == NULL)
00686               return NULL;
00687        PageItem *toitem = GetUniqueItem(QString::fromUtf8(name2));
00688        if (toitem == NULL)
00689               return NULL;
00690        if (!(fromitem->asTextFrame()) || !(toitem->asTextFrame()))
00691        {
00692               PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only link text frames.","python error"));
00693               return NULL;
00694        }
00695 /*     if (toitem->itemText.length() > 0)
00696        {
00697               PyErr_SetString(ScribusException, QObject::tr("Target frame must be empty.","python error"));
00698               return NULL;
00699        }*/
00700        if (toitem->nextInChain() != 0)
00701        {
00702               PyErr_SetString(ScribusException, QObject::tr("Target frame links to another frame.","python error"));
00703               return NULL;
00704        }
00705        if (toitem->prevInChain() != 0)
00706        {
00707               PyErr_SetString(ScribusException, QObject::tr("Target frame is linked to by another frame.","python error"));
00708               return NULL;
00709        }
00710        if (toitem == fromitem)
00711        {
00712               PyErr_SetString(ScribusException, QObject::tr("Source and target are the same object.","python error"));
00713               return NULL;
00714        }
00715        // references to the others boxes
00716        fromitem->link(toitem);
00717        ScCore->primaryMainWindow()->view->DrawNew();
00718        // enable 'save icon' stuff
00719        ScCore->primaryMainWindow()->slotDocCh();
00720 //     Py_INCREF(Py_None);
00721 //     return Py_None;
00722        Py_RETURN_NONE;
00723 }
00724 
00725 PyObject *scribus_unlinktextframes(PyObject* /* self */, PyObject* args)
00726 {
00727        char *name;
00728        if (!PyArg_ParseTuple(args, "es", "utf-8", &name))
00729               return NULL;
00730        if(!checkHaveDocument())
00731               return NULL;
00732        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
00733        if (item == NULL)
00734               return NULL;
00735        if (!item->asTextFrame())
00736        {
00737               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot unlink a non-text frame.","python error"));
00738               return NULL;
00739        }
00740        // only linked
00741        if (item->prevInChain() == 0)
00742        {
00743               PyErr_SetString(ScribusException, QObject::tr("Object is not a linked text frame, can't unlink.","python error"));
00744               return NULL;
00745        }
00746 /*     if (item->NextBox == 0)
00747        {
00748               PyErr_SetString(ScribusException, QObject::tr("Object the last frame in a series, can't unlink. Unlink the previous frame instead.","python error"));
00749               return NULL;
00750        }
00751        */
00752 /*     PageItem* nextbox = item->NextBox;
00753 
00754        while (nextbox != 0)
00755        {
00756               uint a = nextbox->itemText.count();
00757               for (uint s=0; s<a; ++s)
00758                      item->itemText.append(nextbox->itemText.take(0));
00759               nextbox = nextbox->NextBox;
00760        } // while
00761        uint a2 = item->itemText.count();
00762        for (uint s = 0; s < a2; ++s)
00763               item->BackBox->itemText.append(item->itemText.take(0));
00764 */
00765        item->prevInChain()->unlink();
00766        // enable 'save icon' stuff
00767        ScCore->primaryMainWindow()->slotDocCh();
00768        ScCore->primaryMainWindow()->view->DrawNew();
00769 //     Py_INCREF(Py_None);
00770 //     return Py_None;
00771        Py_RETURN_NONE;
00772 }
00773 
00774 /*
00775  * Convert the selected text frame to outlines.
00776  *
00777  * 2004-09-07 (Craig Ringer)
00778  * 2004-09-14 pv frame type, optional frame name param
00779  */
00780 PyObject *scribus_tracetext(PyObject* /* self */, PyObject* args)
00781 {
00782        char *name = const_cast<char*>("");
00783        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
00784               return NULL;
00785        if(!checkHaveDocument())
00786               return NULL;
00787        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
00788        if (item == NULL)
00789               return NULL;
00790        if (!item->asTextFrame())
00791        {
00792               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot convert a non-text frame to outlines.","python error"));
00793               return NULL;
00794        }
00795        ScCore->primaryMainWindow()->view->Deselect(true);
00796        ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr);
00797        ScCore->primaryMainWindow()->view->TextToPath();
00798 //     Py_INCREF(Py_None);
00799 //     return Py_None;
00800        Py_RETURN_NONE;
00801 }
00802 
00803 PyObject *scribus_istextoverflowing(PyObject * self, PyObject* args, PyObject* kw)
00804 {
00805        char *name = const_cast<char*>("");
00806        bool nolinks = false;
00807        char *kwargs[] = {const_cast<char*>("name"), const_cast<char*>("nolinks"), NULL};
00808        if (!PyArg_ParseTupleAndKeywords(args, kw, "|esi", kwargs, "utf-8", &name, &nolinks))
00809               return NULL;
00810        if(!checkHaveDocument())
00811               return NULL;
00812        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
00813        if (item == NULL)
00814               return NULL;
00815        if (!item->asTextFrame())
00816        {
00817               PyErr_SetString(WrongFrameTypeError, QObject::tr("Only text frames can be checked for overflowing", "python error"));
00818               return NULL;
00819        }
00820        /* original solution
00821        if (item->itemText.count() > item->MaxChars)
00822        return PyBool_FromLong(static_cast<long>(true));
00823        return PyBool_FromLong(static_cast<long>(false)); */
00824        /*
00825         uint firstFrame = 0;
00826        if (nolinks)
00827               firstFrame = item->itemText.count();
00828        uint chars = item->itemText.count();
00829        uint maxchars = item->MaxChars;
00830        while (item->NextBox != 0) {
00831               item = item->NextBox;
00832               chars += item->itemText.count();
00833               maxchars += item->MaxChars;
00834        }
00835        // no overrun
00836        if (nolinks)
00837               return PyInt_FromLong(maxchars - firstFrame);
00838 
00839        if (maxchars > chars)
00840               return PyInt_FromLong(0);
00841        // number of overrunning letters
00842        return PyInt_FromLong(static_cast<long>(chars - maxchars));
00843         */
00844        return PyInt_FromLong(static_cast<long>(item->frameOverflows()));
00845 }
00846 
00847 PyObject *scribus_setpdfbookmark(PyObject* /* self */, PyObject* args)
00848 {
00849        char *name = const_cast<char*>("");
00850        bool toggle;
00851        if (!PyArg_ParseTuple(args, "b|es", &toggle, "utf-8", &name))
00852               return NULL;
00853        if (!checkHaveDocument())
00854               return NULL;
00855        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
00856        if (i == NULL)
00857               return NULL;
00858        if (!i->asTextFrame())
00859        {
00860               PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't set bookmark on a non-text frame", "python error"));
00861               return NULL;
00862        }
00863        if (i->isBookmark == toggle)
00864        {
00865 //            Py_INCREF(Py_None);
00866 //            return Py_None;
00867               Py_RETURN_NONE;
00868        }
00869        if (toggle)
00870        {
00871               i->setIsAnnotation(false);
00872               ScCore->primaryMainWindow()->AddBookMark(i);
00873        }
00874        else
00875               ScCore->primaryMainWindow()->DelBookMark(i);
00876        i->isBookmark = toggle;
00877 //     Py_INCREF(Py_None);
00878 //     return Py_None;
00879        Py_RETURN_NONE;
00880 }
00881 
00882 PyObject *scribus_ispdfbookmark(PyObject* /* self */, PyObject* args)
00883 {
00884        char *name = const_cast<char*>("");
00885        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
00886               return NULL;
00887        if (!checkHaveDocument())
00888               return NULL;
00889        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
00890        if (i == NULL)
00891               return NULL;
00892        if (i->asTextFrame())
00893        {
00894               PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't get info from a non-text frame", "python error"));
00895               return NULL;
00896        }
00897        if (i->isBookmark)
00898               return PyBool_FromLong(1);
00899        return PyBool_FromLong(0);
00900 }
00901 
00905 void cmdtextdocwarnings()
00906 {
00907     QStringList s;
00908     s << scribus_getfontsize__doc__ << scribus_getfont__doc__ << scribus_gettextlines__doc__ << scribus_gettextsize__doc__ << scribus_getframetext__doc__ << scribus_gettext__doc__ << scribus_getlinespace__doc__ << scribus_getcolumngap__doc__ << scribus_getcolumns__doc__ <<scribus_setboxtext__doc__ <<scribus_inserttext__doc__ <<scribus_setfont__doc__ <<scribus_setfontsize__doc__ <<scribus_setlinespace__doc__ <<scribus_setcolumngap__doc__ <<scribus_setcolumns__doc__ <<scribus_setalign__doc__ <<scribus_selecttext__doc__ <<scribus_deletetext__doc__ <<scribus_settextfill__doc__ <<scribus_settextstroke__doc__ <<scribus_settextshade__doc__ <<scribus_linktextframes__doc__ <<scribus_unlinktextframes__doc__ <<scribus_tracetext__doc__ <<scribus_istextoverflowing__doc__ <<scribus_setpdfbookmark__doc__ <<scribus_ispdfbookmark__doc__;
00909 }