Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions scribus/plugins/scriptplugin/cmdtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>("");
Expand All @@ -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<int>(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()),
Expand All @@ -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<int>(item->itemText.length())))
Expand Down Expand Up @@ -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__
Expand Down
12 changes: 7 additions & 5 deletions scribus/plugins/scriptplugin/cmdtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
Expand Down
2 changes: 1 addition & 1 deletion scribus/plugins/scriptplugin/scriptplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ PyMethodDef scribus_methods[] = {
{const_cast<char*>("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)},
{const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
{const_cast<char*>("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)},
{const_cast<char*>("positionToPoint"), scribus_positiontopoint, METH_VARARGS, tr(scribus_positiontopoint__doc__)},
{const_cast<char*>("getCharCoordinates"), scribus_getcharcoordinates, METH_VARARGS, tr(scribus_getcharcoordinates__doc__)},
{const_cast<char*>("getMark"), scribus_getmark, METH_VARARGS, tr(scribus_getmark__doc__)},
{const_cast<char*>("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)},
{const_cast<char*>("groupObjects"), (PyCFunction)scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)},
Expand Down