Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
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
65 changes: 65 additions & 0 deletions scribus/plugins/scriptplugin/cmdtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,69 @@ PyObject *scribus_ispdfbookmark(PyObject* /* self */, PyObject* args)
return PyBool_FromLong(0);
}

PyObject *scribus_getcharcoordinates(PyObject* /* self */, PyObject* args)
{
int pos;
char *Name = const_cast<char*>("");
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 get character positions from a non-text frame.","python error").toLocal8Bit().constData());
return nullptr;
}
if ((pos < -1) || (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();
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<char*>("");
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 get mark info from a non-text frame.","python error").toLocal8Bit().constData());
return nullptr;
}
if ((pos < 0) || (pos >= static_cast<int>(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 */
Expand All @@ -1369,6 +1432,7 @@ void cmdtextdocwarnings()
<< scribus_getfontsize__doc__
<< scribus_getframetext__doc__
<< scribus_getlinespace__doc__
<< scribus_getmark__doc__
<< scribus_gettext__doc__
<< scribus_gettextcolor__doc__
<< scribus_gettextdistances__doc__
Expand All @@ -1385,6 +1449,7 @@ void cmdtextdocwarnings()
<< scribus_layouttextchain__doc__
<< scribus_linktextframes__doc__
<< scribus_outlinetext__doc__
<< scribus_getcharcoordinates__doc__
<< scribus_selecttext__doc__
<< scribus_setalign__doc__
<< scribus_setboxtext__doc__
Expand Down
24 changes: 24 additions & 0 deletions scribus/plugins/scriptplugin/cmdtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,28 @@ 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_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\". 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_getcharcoordinates(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
2 changes: 2 additions & 0 deletions scribus/plugins/scriptplugin/scriptplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ 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*>("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__)},
{const_cast<char*>("haveDoc"), (PyCFunction)scribus_havedoc, METH_NOARGS, tr(scribus_havedoc__doc__)},
Expand Down