From fe9ad998d18567c88d6139222ee2cac2dcfd524c Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Wed, 22 Apr 2020 00:20:28 -0400 Subject: [PATCH 1/8] Add positionToPoint() and getMark() functions to the Scripter API. --- scribus/plugins/scriptplugin/cmdtext.cpp | 61 +++++++++++++++++++ scribus/plugins/scriptplugin/cmdtext.h | 22 +++++++ scribus/plugins/scriptplugin/scriptplugin.cpp | 2 + 3 files changed, 85 insertions(+) diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index a0516efce8..1d6a2ecb8c 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1354,6 +1354,65 @@ PyObject *scribus_ispdfbookmark(PyObject* /* self */, PyObject* args) return PyBool_FromLong(0); } +PyObject *scribus_positiontopoint(PyObject* /* self */, PyObject* args) +{ + int pos; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "i|es", &pos, "utf-8", &Name)) + return nullptr; + if (!checkHaveDocument()) + return nullptr; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == nullptr) + return nullptr; + if (!(item->isTextFrame()) && !(item->isPathText())) + { + PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData()); + return nullptr; + } + if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds.","python error").toLocal8Bit().constData()); + return nullptr; + } + QLineF box = item->textLayout.positionToPoint(pos); + return Py_BuildValue("(dddd)", + docUnitXToPageX(item->xPos() + box.x1()), + docUnitYToPageY(item->yPos() + box.y1()), + PointToValue(box.x2() - box.x1()), + PointToValue(box.y2() - box.y1())); +} + +PyObject *scribus_getmark(PyObject* /* self */, PyObject* args) +{ + int pos; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "i|es", &pos, "utf-8", &Name)) + return nullptr; + if (!checkHaveDocument()) + return nullptr; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == nullptr) + return nullptr; + if (!(item->isTextFrame()) && !(item->isPathText())) + { + PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData()); + return nullptr; + } + if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Insert index out of bounds.","python error").toLocal8Bit().constData()); + return nullptr; + } + Mark* mark = item->itemText.mark(pos); + if (mark) { + return Py_BuildValue("(is)", mark->getType(), + mark->getData().strtxt.toUtf8().data()); + } else { + return Py_BuildValue("(is)", MARKNoType, ""); + } +} + /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV */ @@ -1369,6 +1428,7 @@ void cmdtextdocwarnings() << scribus_getfontsize__doc__ << scribus_getframetext__doc__ << scribus_getlinespace__doc__ + << scribus_getmark__doc__ << scribus_gettext__doc__ << scribus_gettextcolor__doc__ << scribus_gettextdistances__doc__ @@ -1385,6 +1445,7 @@ void cmdtextdocwarnings() << scribus_layouttextchain__doc__ << scribus_linktextframes__doc__ << scribus_outlinetext__doc__ + << scribus_positiontopoint__doc__ << scribus_selecttext__doc__ << scribus_setalign__doc__ << scribus_setboxtext__doc__ diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h index 578511c5b7..cdc784fcf1 100644 --- a/scribus/plugins/scriptplugin/cmdtext.h +++ b/scribus/plugins/scriptplugin/cmdtext.h @@ -561,4 +561,26 @@ May raise WrongFrameTypeError if the target frame is not a text frame\n\ /*! Is PDF bookmark? */ PyObject *scribus_ispdfbookmark(PyObject * /*self*/, PyObject* args); +/*! docstring */ +PyDoc_STRVAR(scribus_positiontopoint__doc__, +QT_TR_NOOP("positionToPoint(pos, [\"name\"]) -> (x,y,width,height)\n\ +\n\ +Returns a (x, y, width, height) tuple based on the character at position\n\ +\"pos\" in the text frame \"name\". If \"name\" is not given the currently\n\ +selected item is used.\n\ +")); +/*! Point for glyth at position */ +PyObject *scribus_positiontopoint(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getmark__doc__, +QT_TR_NOOP("getMark(pos, [\"name\"]) -> (type,text)\n\ +\n\ +Returns a (type, text) tuple for the mark at position pos in object \"name\".\n\ +If \"name\" is not given the currently selected item is used. If there is no\n\ +mark at that position, type is -1.\n\ +")); +/*! Returns info about mark */ +PyObject *scribus_getmark(PyObject * /*self*/, PyObject* args); + #endif diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index 65b5fb4eaf..a988ace764 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -407,6 +407,8 @@ PyMethodDef scribus_methods[] = { {const_cast("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)}, {const_cast("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)}, {const_cast("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)}, + {const_cast("positionToPoint"), scribus_positiontopoint, METH_VARARGS, tr(scribus_positiontopoint__doc__)}, + {const_cast("getMark"), scribus_getmark, METH_VARARGS, tr(scribus_getmark__doc__)}, {const_cast("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)}, {const_cast("groupObjects"), (PyCFunction)scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)}, {const_cast("haveDoc"), (PyCFunction)scribus_havedoc, METH_NOARGS, tr(scribus_havedoc__doc__)}, From f6bbffa0bc4cb891e51eec122e0c47a2d2a6a4ae Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Wed, 22 Apr 2020 10:58:18 -0400 Subject: [PATCH 2/8] Rename positionToPoint() to getCharCoordinates() and fix error messages. Fix positionToPoint() to work with text frames that aren't the first in a chain. --- scribus/plugins/scriptplugin/cmdtext.cpp | 16 ++++++++++------ scribus/plugins/scriptplugin/cmdtext.h | 12 +++++++----- scribus/plugins/scriptplugin/scriptplugin.cpp | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index 1d6a2ecb8c..825de83675 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1354,7 +1354,7 @@ PyObject *scribus_ispdfbookmark(PyObject* /* self */, PyObject* args) return PyBool_FromLong(0); } -PyObject *scribus_positiontopoint(PyObject* /* self */, PyObject* args) +PyObject *scribus_getcharcoordinates(PyObject* /* self */, PyObject* args) { int pos; char *Name = const_cast(""); @@ -1367,14 +1367,18 @@ PyObject *scribus_positiontopoint(PyObject* /* self */, PyObject* args) return nullptr; if (!(item->isTextFrame()) && !(item->isPathText())) { - PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData()); + PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get character positions from a non-text frame.","python error").toLocal8Bit().constData()); return nullptr; } - if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) + if ((pos < -1) || (pos > item->lastInFrame() - item->firstInFrame())) { - PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds.","python error").toLocal8Bit().constData()); + PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds for this text frame.","python error").toLocal8Bit().constData()); return nullptr; } + if (pos == -1) + pos = item->lastInFrame(); + else + pos += item->firstInFrame(); QLineF box = item->textLayout.positionToPoint(pos); return Py_BuildValue("(dddd)", docUnitXToPageX(item->xPos() + box.x1()), @@ -1396,7 +1400,7 @@ PyObject *scribus_getmark(PyObject* /* self */, PyObject* args) return nullptr; if (!(item->isTextFrame()) && !(item->isPathText())) { - PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData()); + PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get mark info from a non-text frame.","python error").toLocal8Bit().constData()); return nullptr; } if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) @@ -1445,7 +1449,7 @@ void cmdtextdocwarnings() << scribus_layouttextchain__doc__ << scribus_linktextframes__doc__ << scribus_outlinetext__doc__ - << scribus_positiontopoint__doc__ + << scribus_getcharcoordinates__doc__ << scribus_selecttext__doc__ << scribus_setalign__doc__ << scribus_setboxtext__doc__ diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h index cdc784fcf1..9b8ed4b704 100644 --- a/scribus/plugins/scriptplugin/cmdtext.h +++ b/scribus/plugins/scriptplugin/cmdtext.h @@ -562,15 +562,17 @@ May raise WrongFrameTypeError if the target frame is not a text frame\n\ PyObject *scribus_ispdfbookmark(PyObject * /*self*/, PyObject* args); /*! docstring */ -PyDoc_STRVAR(scribus_positiontopoint__doc__, -QT_TR_NOOP("positionToPoint(pos, [\"name\"]) -> (x,y,width,height)\n\ +PyDoc_STRVAR(scribus_getcharcoordinates__doc__, +QT_TR_NOOP("getCharCoordinates(pos, [\"name\"]) -> (x,y,width,height)\n\ \n\ Returns a (x, y, width, height) tuple based on the character at position\n\ -\"pos\" in the text frame \"name\". If \"name\" is not given the currently\n\ -selected item is used.\n\ +\"pos\" in the text frame \"name\". Even if the text frame is chained from\n\ +another text frame, \"pos\" is related to the named text frame, not the\n\ +overall story text. If \"name\" is not given the currently selected item is\n\ +used.\n\ ")); /*! Point for glyth at position */ -PyObject *scribus_positiontopoint(PyObject * /*self*/, PyObject* args); +PyObject *scribus_getcharcoordinates(PyObject * /*self*/, PyObject* args); /*! docstring */ PyDoc_STRVAR(scribus_getmark__doc__, diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index a988ace764..0cf6b77dcc 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -407,7 +407,7 @@ PyMethodDef scribus_methods[] = { {const_cast("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)}, {const_cast("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)}, {const_cast("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)}, - {const_cast("positionToPoint"), scribus_positiontopoint, METH_VARARGS, tr(scribus_positiontopoint__doc__)}, + {const_cast("getCharCoordinates"), scribus_getcharcoordinates, METH_VARARGS, tr(scribus_getcharcoordinates__doc__)}, {const_cast("getMark"), scribus_getmark, METH_VARARGS, tr(scribus_getmark__doc__)}, {const_cast("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)}, {const_cast("groupObjects"), (PyCFunction)scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)}, From 014314430d753ae3b82b6b6a1541c48241217001 Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Thu, 23 Apr 2020 13:41:09 -0400 Subject: [PATCH 3/8] Remove -1 functionality from scribus_getcharcoordinates(). --- scribus/plugins/scriptplugin/cmdtext.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index 825de83675..500ec3a3e8 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1370,15 +1370,12 @@ PyObject *scribus_getcharcoordinates(PyObject* /* self */, PyObject* args) PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get character positions from a non-text frame.","python error").toLocal8Bit().constData()); return nullptr; } - if ((pos < -1) || (pos > item->lastInFrame() - item->firstInFrame())) + if ((pos < 0) || (pos > item->lastInFrame() - item->firstInFrame())) { PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds for this text frame.","python error").toLocal8Bit().constData()); return nullptr; } - if (pos == -1) - pos = item->lastInFrame(); - else - pos += item->firstInFrame(); + pos += item->firstInFrame(); QLineF box = item->textLayout.positionToPoint(pos); return Py_BuildValue("(dddd)", docUnitXToPageX(item->xPos() + box.x1()), From 0f4fb5002d384a411d090276d5ae680993ce69a4 Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Fri, 24 Apr 2020 12:02:08 -0400 Subject: [PATCH 4/8] Allow character to be anywhere in the story text, and return page it's on as well. --- scribus/plugins/scriptplugin/cmdtext.cpp | 20 ++++++++++++-------- scribus/plugins/scriptplugin/cmdtext.h | 11 +++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index 500ec3a3e8..164b4e7489 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1370,16 +1370,20 @@ PyObject *scribus_getcharcoordinates(PyObject* /* self */, PyObject* args) PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get character positions from a non-text frame.","python error").toLocal8Bit().constData()); return nullptr; } - if ((pos < 0) || (pos > item->lastInFrame() - item->firstInFrame())) + if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) { - PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds for this text frame.","python error").toLocal8Bit().constData()); + PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds.","python error").toLocal8Bit().constData()); return nullptr; } - pos += item->firstInFrame(); - QLineF box = item->textLayout.positionToPoint(pos); - return Py_BuildValue("(dddd)", - docUnitXToPageX(item->xPos() + box.x1()), - docUnitYToPageY(item->yPos() + box.y1()), + // When chaining the frame the char is in doesn't necessarily match + // the selected frame. + PageItem* actual = item->frameOfChar(pos); + QLineF box = actual->textLayout.positionToPoint(pos); + return Py_BuildValue("(idddd)", + // Scripter API page starts at 1, not 0. + actual->OwnPage + 1, + docUnitXToPageX(actual->xPos() + box.x1()), + docUnitYToPageY(actual->yPos() + box.y1()), PointToValue(box.x2() - box.x1()), PointToValue(box.y2() - box.y1())); } @@ -1402,7 +1406,7 @@ PyObject *scribus_getmark(PyObject* /* self */, PyObject* args) } if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) { - PyErr_SetString(PyExc_IndexError, QObject::tr("Insert index out of bounds.","python error").toLocal8Bit().constData()); + PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds.","python error").toLocal8Bit().constData()); return nullptr; } Mark* mark = item->itemText.mark(pos); diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h index 9b8ed4b704..1c62fc1d48 100644 --- a/scribus/plugins/scriptplugin/cmdtext.h +++ b/scribus/plugins/scriptplugin/cmdtext.h @@ -563,13 +563,12 @@ PyObject *scribus_ispdfbookmark(PyObject * /*self*/, PyObject* args); /*! docstring */ PyDoc_STRVAR(scribus_getcharcoordinates__doc__, -QT_TR_NOOP("getCharCoordinates(pos, [\"name\"]) -> (x,y,width,height)\n\ +QT_TR_NOOP("getCharCoordinates(pos, [\"name\"]) -> (page,x,y,width,height)\n\ \n\ -Returns a (x, y, width, height) tuple based on the character at position\n\ -\"pos\" in the text frame \"name\". Even if the text frame is chained from\n\ -another text frame, \"pos\" is related to the named text frame, not the\n\ -overall story text. If \"name\" is not given the currently selected item is\n\ -used.\n\ +Returns a (page, x, y, width, height) tuple based on the character at\n\ +position \"pos\" in the text frame \"name\". If the text frame is chained\n\ +from another text frame, \"pos\" is based on the overall story text. If\n\ + \"name\" is not given the currently selected item is used.\n\ ")); /*! Point for glyth at position */ PyObject *scribus_getcharcoordinates(PyObject * /*self*/, PyObject* args); From 516cd93c7e121a037efd0d84bb295afaa86fee2f Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Fri, 24 Apr 2020 12:07:46 -0400 Subject: [PATCH 5/8] Add documentation about layout for getCharCoordinates(). --- scribus/plugins/scriptplugin/cmdtext.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h index 1c62fc1d48..df700fe08d 100644 --- a/scribus/plugins/scriptplugin/cmdtext.h +++ b/scribus/plugins/scriptplugin/cmdtext.h @@ -569,6 +569,9 @@ Returns a (page, x, y, width, height) tuple based on the character at\n\ position \"pos\" in the text frame \"name\". If the text frame is chained\n\ from another text frame, \"pos\" is based on the overall story text. If\n\ \"name\" is not given the currently selected item is used.\n\ +\n\ +Will only work properly if the text has been layed out; you may need to call\n\ +layoutText() or layoutTextChain() first for correct results.\n\ ")); /*! Point for glyth at position */ PyObject *scribus_getcharcoordinates(PyObject * /*self*/, PyObject* args); From cdcd40523b0f2d9deb18edec47109292e4c549ad Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Fri, 24 Apr 2020 13:57:17 -0400 Subject: [PATCH 6/8] Fix getCharCoordinates() when the pos is not visible in a frame. --- scribus/plugins/scriptplugin/cmdtext.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index 164b4e7489..dd59b0a358 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1378,6 +1378,10 @@ PyObject *scribus_getcharcoordinates(PyObject* /* self */, PyObject* args) // When chaining the frame the char is in doesn't necessarily match // the selected frame. PageItem* actual = item->frameOfChar(pos); + if (actual == nullptr) { + PyErr_SetString(PyExc_IndexError, QObject::tr("Character index not visible in a frame.","python error").toLocal8Bit().constData()); + return nullptr; + } QLineF box = actual->textLayout.positionToPoint(pos); return Py_BuildValue("(idddd)", // Scripter API page starts at 1, not 0. From e0907fffdf33bacfbd9bf045ffd781d756042fc6 Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Wed, 27 May 2020 00:11:57 -0400 Subject: [PATCH 7/8] Fix scribus.getCharCoordinates() to convert coordinates properly when the character is not on the current page. --- scribus/plugins/scriptplugin/cmdtext.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index 6bc8f5bf5f..af3189a256 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1383,11 +1383,20 @@ PyObject *scribus_getcharcoordinates(PyObject* /* self */, PyObject* args) return nullptr; } QLineF box = actual->textLayout.positionToPoint(pos); + // Can't use docUnitXToPageX and docUnitYToPageY because it might not + // be on the current page. + ScPage* actual_page + = ScCore->primaryMainWindow()->doc->Pages->at(actual->OwnPage); + double page_x + = PointToValue(actual->xPos() + box.x1() - actual_page->xOffset()); + double page_y + = PointToValue(actual->yPos() + box.y1() - actual_page->yOffset()); + return Py_BuildValue("(idddd)", // Scripter API page starts at 1, not 0. actual->OwnPage + 1, - docUnitXToPageX(actual->xPos() + box.x1()), - docUnitYToPageY(actual->yPos() + box.y1()), + page_x, + page_y, PointToValue(box.x2() - box.x1()), PointToValue(box.y2() - box.y1())); } From 7cef8f6c646ea0ebb365dc0ca457ff684c19eb86 Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Sat, 12 Sep 2020 10:31:48 -0400 Subject: [PATCH 8/8] Add an updateDocument() function that's equivalent to the Update Document menu item. Make getMark() return a dictionary. Add a setMarkText() function. --- scribus/plugins/scriptplugin/cmddoc.cpp | 9 +++- scribus/plugins/scriptplugin/cmddoc.h | 7 +++ scribus/plugins/scriptplugin/cmdtext.cpp | 43 +++++++++++++++++-- scribus/plugins/scriptplugin/cmdtext.h | 11 +++++ scribus/plugins/scriptplugin/scriptplugin.cpp | 2 + 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/scribus/plugins/scriptplugin/cmddoc.cpp b/scribus/plugins/scriptplugin/cmddoc.cpp index d26a391987..a472e4168a 100644 --- a/scribus/plugins/scriptplugin/cmddoc.cpp +++ b/scribus/plugins/scriptplugin/cmddoc.cpp @@ -470,6 +470,12 @@ PyObject* scribus_applymasterpage(PyObject* /* self */, PyObject* args) Py_RETURN_NONE; } +PyObject* scribus_updatedocument(PyObject* /* self */, PyObject* args) +{ + ScCore->primaryMainWindow()->updateDocument(); + Py_RETURN_NONE; +} + /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV */ @@ -498,5 +504,6 @@ void cmddocdocwarnings() << scribus_setdoctype__doc__ << scribus_setinfo__doc__ << scribus_setmargins__doc__ - << scribus_setunit__doc__; + << scribus_setunit__doc__ + << scribus_updatedocument__doc__; } diff --git a/scribus/plugins/scriptplugin/cmddoc.h b/scribus/plugins/scriptplugin/cmddoc.h index 110db951af..2625f0300c 100644 --- a/scribus/plugins/scriptplugin/cmddoc.h +++ b/scribus/plugins/scriptplugin/cmddoc.h @@ -313,6 +313,13 @@ Apply master page masterPageName on page pageNumber.\n\ ")); PyObject* scribus_applymasterpage(PyObject* self, PyObject* args); +PyDoc_STRVAR(scribus_updatedocument__doc__, +QT_TR_NOOP("updateDocument()\n\ +\n\ +Update the document.\n\ +")); +PyObject* scribus_updatedocument(PyObject* self, PyObject* args); + #endif diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp index af3189a256..c8f6123fa3 100644 --- a/scribus/plugins/scriptplugin/cmdtext.cpp +++ b/scribus/plugins/scriptplugin/cmdtext.cpp @@ -1424,13 +1424,49 @@ PyObject *scribus_getmark(PyObject* /* self */, PyObject* args) } Mark* mark = item->itemText.mark(pos); if (mark) { - return Py_BuildValue("(is)", mark->getType(), - mark->getData().strtxt.toUtf8().data()); + return Py_BuildValue( + "{s:i,s:s,s:s}", + "Type", mark->getType(), + "Text", mark->getData().strtxt.toUtf8().data(), + "Label", mark->label.toUtf8().data()); } else { - return Py_BuildValue("(is)", MARKNoType, ""); + Py_RETURN_NONE; } } +PyObject *scribus_setmarktext(PyObject* /* self */, PyObject* args) +{ + int pos; + char *val = const_cast(""); + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "ies|es", &pos, "utf-8", &val, + "utf-8", &Name)) + return nullptr; + if (!checkHaveDocument()) + return nullptr; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == nullptr) + return nullptr; + if (!(item->isTextFrame()) && !(item->isPathText())) + { + PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set mark text in a non-text frame.","python error").toLocal8Bit().constData()); + return nullptr; + } + if ((pos < 0) || (pos >= static_cast(item->itemText.length()))) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Character index out of bounds.","python error").toLocal8Bit().constData()); + return nullptr; + } + Mark* mark = item->itemText.mark(pos); + if (!mark) { + PyErr_SetString(PyExc_ValueError, QObject::tr("No mark at that index.","python error").toLocal8Bit().constData()); + return nullptr; + } + + mark->setString(QString::fromUtf8(val)); + Py_RETURN_NONE; +} + /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV */ @@ -1475,6 +1511,7 @@ void cmdtextdocwarnings() << scribus_setfontsize__doc__ << scribus_setlinespace__doc__ << scribus_setlinespacemode__doc__ + << scribus_setmarktext__doc__ << scribus_setpdfbookmark__doc__ << scribus_settextdistances__doc__ << scribus_settext__doc__ diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h index 3a0f5cbe4c..1b5c5ba2bd 100644 --- a/scribus/plugins/scriptplugin/cmdtext.h +++ b/scribus/plugins/scriptplugin/cmdtext.h @@ -607,4 +607,15 @@ mark at that position, type is -1.\n\ /*! Returns info about mark */ PyObject *scribus_getmark(PyObject * /*self*/, PyObject* args); +/*! docstring */ +PyDoc_STRVAR(scribus_setmarktext__doc__, +QT_TR_NOOP("setMarkText(pos, \"text\", [\"name\"])\n\ +\n\ +Returns a (type, text) tuple for the mark at position pos in object \"name\".\n\ +If \"name\" is not given the currently selected item is used. If there is no\n\ +mark at that position, type is -1.\n\ +")); +/*! Returns info about mark */ +PyObject *scribus_setmarktext(PyObject * /*self*/, PyObject* args); + #endif diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index 644e8313dd..438726e9ca 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -433,6 +433,7 @@ PyMethodDef scribus_methods[] = { {const_cast("isLocked"), scribus_islocked, METH_VARARGS, tr(scribus_islocked__doc__)}, {const_cast("layoutText"), scribus_layouttext, METH_VARARGS, tr(scribus_layouttext__doc__)}, {const_cast("layoutTextChain"), scribus_layouttextchain, METH_VARARGS, tr(scribus_layouttextchain__doc__)}, + {const_cast("updateDocument"), scribus_updatedocument, METH_VARARGS, tr(scribus_updatedocument__doc__)}, {const_cast("linkTextFrames"), scribus_linktextframes, METH_VARARGS, tr(scribus_linktextframes__doc__)}, {const_cast("loadImage"), scribus_loadimage, METH_VARARGS, tr(scribus_loadimage__doc__)}, {const_cast("loadStylesFromFile"), scribus_loadstylesfromfile, METH_VARARGS, tr(scribus_loadstylesfromfile__doc__)}, @@ -539,6 +540,7 @@ PyMethodDef scribus_methods[] = { {const_cast("setLineWidth"), scribus_setlinewidth, METH_VARARGS, tr(scribus_setlinewidth__doc__)}, {const_cast("setBleeds"), scribus_setbleeds, METH_VARARGS, tr(scribus_setbleeds__doc__)}, {const_cast("setMargins"), scribus_setmargins, METH_VARARGS, tr(scribus_setmargins__doc__)}, + {const_cast("setMarkText"), scribus_setmarktext, METH_VARARGS, tr(scribus_setmarktext__doc__)}, {const_cast("setBaseLine"), scribus_setbaseline, METH_VARARGS, tr(scribus_setbaseline__doc__)}, {const_cast("setItemName"), scribus_setitemname, METH_VARARGS, tr(scribus_setitemname__doc__)}, {const_cast("setMultiLine"), scribus_setmultiline, METH_VARARGS, tr(scribus_setmultiline__doc__)},