View Issue Details

IDProjectCategoryView StatusLast Update
0017334ScribusScripterpublic2024-12-16 21:12
Reporterybon Assigned Tocbradney  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version1.7.0.svn 
Fixed in Version1.7.0.svn 
Summary0017334: Add API endpoint setTracking and getTracking
DescriptionThis is an attempt to make python endpoints for setting and getting tracking from a text.
TagsNo tags attached.
PatchYes

Activities

ybon

2024-12-12 13:37

reporter  

tracking.diff (5,435 bytes)   
Index: scribus/plugins/scriptplugin/cmdtext.cpp
===================================================================
--- scribus/plugins/scriptplugin/cmdtext.cpp	(revision 26476)
+++ scribus/plugins/scriptplugin/cmdtext.cpp	(working copy)
@@ -153,6 +153,33 @@
 	return PyLong_FromLong(item->currentCharStyle().fillShade());
 }
 
+PyObject *scribus_gettracking(PyObject* /* self */, PyObject* args)
+{
+	PyESString name;
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", name.ptr()))
+		return nullptr;
+	if (!checkHaveDocument())
+		return nullptr;
+	const PageItem *item = GetUniqueItem(QString::fromUtf8(name.c_str()));
+	if (item == nullptr)
+		return nullptr;
+	if (!(item->isTextFrame()) && !(item->isPathText()))
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get tracking of non-text frame.", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+	if (item->HasSel)
+	{
+		for (int i = 0; i < item->itemText.length(); ++i)
+		{
+			if (item->itemText.selected(i))
+				return PyLong_FromLong(item->itemText.charStyle(i).tracking());
+		}
+		return nullptr;
+	}
+	return PyLong_FromLong(item->currentCharStyle().tracking());
+}
+
 PyObject *scribus_gettextlength(PyObject* /* self */, PyObject* args)
 {
 	PyESString name;
@@ -878,6 +905,36 @@
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_settracking(PyObject* /* self */, PyObject* args)
+{
+	PyESString name;
+	int kern;
+	if (!PyArg_ParseTuple(args, "d|es", &kern, "utf-8", name.ptr()))
+		return nullptr;
+	if (!checkHaveDocument())
+		return nullptr;
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name.c_str()));
+	if (item == nullptr)
+		return nullptr;
+	if (!item->isTextFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set tracking on a non-text frame.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
+	if (item->HasSel)
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetTracking(kern, &tmpSelection);
+	doc->appMode = oldAppMode;
+
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_setlinespacingmode(PyObject* /* self */, PyObject* args)
 {
 	PyESString name;
Index: scribus/plugins/scriptplugin/cmdtext.h
===================================================================
--- scribus/plugins/scriptplugin/cmdtext.h	(revision 26476)
+++ scribus/plugins/scriptplugin/cmdtext.h	(working copy)
@@ -188,6 +188,17 @@
 PyObject *scribus_getfirstlineoffset(PyObject * /*self*/, PyObject* args);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_gettracking__doc__,
+	QT_TR_NOOP("getTracking([\"name\"]) -> integer\n\
+\n\
+Gets the tracking of text inside text frame \"name\".\n\
+If \"name\" is not given the currently selected item is used. \n\
+If there is some text selected only the selected text tracking is returned.\n\
+"));
+/*! Get tracking */
+PyObject *scribus_gettracking(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_getlinespacing__doc__,
 QT_TR_NOOP("getLineSpacing([\"name\"]) -> float\n\
 \n\
@@ -593,6 +604,18 @@
 PyObject *scribus_settextshade(PyObject * /*self*/, PyObject* args);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_settracking__doc__,
+QT_TR_NOOP("setTracking(kern, [\"name\"])\n\
+\n\
+Sets the tracking of the text the object \"name\" to \"kern\". If\n\
+there is some text selected only the selected text is changed. \"kern\" must\n\
+be an integer. If \"name\" is not given the currently selected item is\n\
+used.\n\
+"));
+/*! Set text tracking */
+PyObject *scribus_settracking(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_linktextframes__doc__,
 QT_TR_NOOP("linkTextFrames(\"fromname\", \"toname\")\n\
 \n\
Index: scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 26476)
+++ scribus/plugins/scriptplugin/scriptplugin.cpp	(working copy)
@@ -430,6 +430,7 @@
 	{ "getTextLines", scribus_gettextlines, METH_VARARGS, tr(scribus_gettextlines__doc__)},
 	{ "getTextShade", scribus_gettextshade, METH_VARARGS, tr(scribus_gettextshade__doc__)},
 	{ "getTextVerticalAlignment", scribus_gettextverticalalignment, METH_VARARGS, tr(scribus_gettextverticalalignment__doc__)},
+	{ "getTracking", scribus_gettracking, METH_VARARGS, tr(scribus_gettracking__doc__)},
 	{ "getUnit", (PyCFunction) scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)},
 	{ "pointsToDocUnit", scribus_pointstodocunit, METH_VARARGS, tr(scribus_pointstodocunit__doc__)},
 	{ "docUnitToPoints", scribus_docunittopoints, METH_VARARGS, tr(scribus_docunittopoints__doc__)},
@@ -600,6 +601,7 @@
 	{ "setTextShade", scribus_settextshade, METH_VARARGS, tr(scribus_settextshade__doc__)},
 	{ "setTextStroke", scribus_settextstroke, METH_VARARGS, tr(scribus_settextstroke__doc__)},
 	{ "setTextVerticalAlignment", scribus_settextverticalalignment, METH_VARARGS, tr(scribus_settextverticalalignment__doc__)},
+	{ "setTracking", scribus_settracking, METH_VARARGS, tr(scribus_settracking__doc__)},
 	{ "setUnit", scribus_setunit, METH_VARARGS, tr(scribus_setunit__doc__)},
 	{ "setVGuides", scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
 	{ "sizeObject", scribus_sizeobject, METH_VARARGS, tr(scribus_sizeobject__doc__)},
tracking.diff (5,435 bytes)   

Issue History

Date Modified Username Field Change
2024-12-12 13:37 ybon New Issue
2024-12-12 13:37 ybon File Added: tracking.diff
2024-12-14 11:32 cbradney Assigned To => cbradney
2024-12-14 11:32 cbradney Status new => resolved
2024-12-14 11:32 cbradney Resolution open => fixed
2024-12-14 11:32 cbradney Fixed in Version => 1.7.0.svn
2024-12-16 21:12 cbradney Status resolved => closed