tabs-support-for-scripter.patch (12,972 bytes)
From f8249e633857b899bfa0d3f902a17a138ca00717 Mon Sep 17 00:00:00 2001
From: chefe <hi@chefe.io>
Date: Sat, 28 Sep 2019 10:36:57 +0200
Subject: [PATCH] Add tabs support for scripter
---
doc/de/scripterapi-constants.html | 11 +++++
doc/de/scripterapi-styles.html | 8 ++++
doc/en/scripterapi-constants.html | 11 +++++
doc/en/scripterapi-styles.html | 8 ++++
doc/fr/scripterapi-constants.html | 11 +++++
doc/fr/scripterapi-styles.html | 8 ++++
doc/it/scripterapi-constants.html | 11 +++++
doc/it/scripterapi-styles.html | 8 ++++
scribus/plugins/scriptplugin/cmdstyle.cpp | 44 +++++++++++++++++--
scribus/plugins/scriptplugin/cmdstyle.h | 5 +++
scribus/plugins/scriptplugin/scriptplugin.cpp | 6 +++
11 files changed, 128 insertions(+), 3 deletions(-)
diff --git a/doc/de/scripterapi-constants.html b/doc/de/scripterapi-constants.html
index 36fcacf1d..1c4124a7b 100644
--- a/doc/de/scripterapi-constants.html
+++ b/doc/de/scripterapi-constants.html
@@ -295,5 +295,16 @@ you write 'value*mm/inch' .</p>
</dl>
</td></tr></table>
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+ <dt>TAB_LEFT</dt>
+ <dt>TAB_RIGHT</dt>
+ <dt>TAB_PERIOD</dt>
+ <dt>TAB_COMMA</dt>
+ <dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
</body>
</html>
diff --git a/doc/de/scripterapi-styles.html b/doc/de/scripterapi-styles.html
index ead9a9db3..c9b2c9384 100644
--- a/doc/de/scripterapi-styles.html
+++ b/doc/de/scripterapi-styles.html
@@ -163,6 +163,14 @@
<li>dropcapoffset [optional] -> offset of the caps if used</li>
<li>"charstyle" [optional] -> char style to use</li>
<li>"bullet" [optional] -> string to use as bullet</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+ <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+ <li>position [required] -> float value for the position</li>
+ <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+ <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
</ul>
</p>
<p>If you wish to skip a number of settings, unfortunately, this command will not accept null values, i.e., a series of commas. You <i>must</i> put some integer value for each of the potential parameters. For example, imagine you wish to only specify a name for the Paragraph Style, and the Character Style. Your command should be something like:
diff --git a/doc/en/scripterapi-constants.html b/doc/en/scripterapi-constants.html
index c5b814548..c79da2668 100644
--- a/doc/en/scripterapi-constants.html
+++ b/doc/en/scripterapi-constants.html
@@ -307,5 +307,16 @@ you write 'value*mm/inch' .</p>
</dl>
</td></tr></table>
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+ <dt>TAB_LEFT</dt>
+ <dt>TAB_RIGHT</dt>
+ <dt>TAB_PERIOD</dt>
+ <dt>TAB_COMMA</dt>
+ <dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
</body>
</html>
diff --git a/doc/en/scripterapi-styles.html b/doc/en/scripterapi-styles.html
index ead9a9db3..c9b2c9384 100644
--- a/doc/en/scripterapi-styles.html
+++ b/doc/en/scripterapi-styles.html
@@ -163,6 +163,14 @@
<li>dropcapoffset [optional] -> offset of the caps if used</li>
<li>"charstyle" [optional] -> char style to use</li>
<li>"bullet" [optional] -> string to use as bullet</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+ <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+ <li>position [required] -> float value for the position</li>
+ <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+ <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
</ul>
</p>
<p>If you wish to skip a number of settings, unfortunately, this command will not accept null values, i.e., a series of commas. You <i>must</i> put some integer value for each of the potential parameters. For example, imagine you wish to only specify a name for the Paragraph Style, and the Character Style. Your command should be something like:
diff --git a/doc/fr/scripterapi-constants.html b/doc/fr/scripterapi-constants.html
index e8c02d8cc..d40a49029 100644
--- a/doc/fr/scripterapi-constants.html
+++ b/doc/fr/scripterapi-constants.html
@@ -303,6 +303,17 @@ Ainsi, pour convertir les pouces en points, il suffit d'écrire 'valeur/inch'; p
</dl>
</td></tr></table>
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+ <dt>TAB_LEFT</dt>
+ <dt>TAB_RIGHT</dt>
+ <dt>TAB_PERIOD</dt>
+ <dt>TAB_COMMA</dt>
+ <dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
</body>
</html>
diff --git a/doc/fr/scripterapi-styles.html b/doc/fr/scripterapi-styles.html
index 063fd7cd7..85c009172 100644
--- a/doc/fr/scripterapi-styles.html
+++ b/doc/fr/scripterapi-styles.html
@@ -160,6 +160,14 @@
<li>dropcapoffset [optionnel] -> décalage horizontal des lettrines si l'utilisation de lettrines est activée</li>
<li>"charstyle" [optionnel] -> nom du style de caractère à utiliser</li>
<li>"bullet" [optionnel] -> chaîne de caractère à utiliser pour les puces</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+ <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+ <li>position [required] -> float value for the position</li>
+ <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+ <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
</ul>
</p>
<p>Si vous désirez omettre un certain nombre d'éléments, cette fonction n'acceptera pas de valeurs null, i.e., une série de virgule. Vous <i>devez</i> spécifier un paramètre entier pour chacun des paramètres omis. Par example, si vous désirez spécifier uniquement un nom de style de paragraphe et un nom de style de caractère, votre appel de fonction ressemblera à ceci:
diff --git a/doc/it/scripterapi-constants.html b/doc/it/scripterapi-constants.html
index e712c4966..fa054e075 100644
--- a/doc/it/scripterapi-constants.html
+++ b/doc/it/scripterapi-constants.html
@@ -295,5 +295,16 @@ you write 'value*mm/inch' .</p>
</dl>
</td></tr></table>
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+ <dt>TAB_LEFT</dt>
+ <dt>TAB_RIGHT</dt>
+ <dt>TAB_PERIOD</dt>
+ <dt>TAB_COMMA</dt>
+ <dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
</body>
</html>
diff --git a/doc/it/scripterapi-styles.html b/doc/it/scripterapi-styles.html
index ead9a9db3..c9b2c9384 100644
--- a/doc/it/scripterapi-styles.html
+++ b/doc/it/scripterapi-styles.html
@@ -163,6 +163,14 @@
<li>dropcapoffset [optional] -> offset of the caps if used</li>
<li>"charstyle" [optional] -> char style to use</li>
<li>"bullet" [optional] -> string to use as bullet</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+ <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+ <li>position [required] -> float value for the position</li>
+ <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+ <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
</ul>
</p>
<p>If you wish to skip a number of settings, unfortunately, this command will not accept null values, i.e., a series of commas. You <i>must</i> put some integer value for each of the potential parameters. For example, imagine you wish to only specify a name for the Paragraph Style, and the Character Style. Your command should be something like:
diff --git a/scribus/plugins/scriptplugin/cmdstyle.cpp b/scribus/plugins/scriptplugin/cmdstyle.cpp
index 0f907b0f9..11ad78a9b 100644
--- a/scribus/plugins/scriptplugin/cmdstyle.cpp
+++ b/scribus/plugins/scriptplugin/cmdstyle.cpp
@@ -39,17 +39,19 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
const_cast<char*>("dropcapoffset"),
const_cast<char*>("charstyle"),
const_cast<char*>("bullet"),
+ const_cast<char*>("tabs"),
nullptr};
char *name = const_cast<char*>(""), *charStyle = const_cast<char*>("");
char *bullet = const_cast<char*>("");
int lineSpacingMode = 0, alignment = 0, dropCapLines = 2, hasDropCap = 0;
double lineSpacing = 15.0, leftMargin = 0.0, rightMargin = 0.0;
double gapBefore = 0.0, gapAfter = 0.0, firstIndent = 0.0, peOffset = 0;
- if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|ididddddiideses",
+ PyObject *tabDefinitions = nullptr;
+ if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|ididddddiidesesO",
keywordargs, "utf-8", &name, &lineSpacingMode, &lineSpacing, &alignment,
&leftMargin, &rightMargin, &gapBefore, &gapAfter, &firstIndent,
&hasDropCap, &dropCapLines, &peOffset, "utf-8", &charStyle,
- "utf-8", &bullet))
+ "utf-8", &bullet, &tabDefinitions))
return nullptr;
if (!checkHaveDocument())
return nullptr;
@@ -105,10 +107,46 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
{
tmpParagraphStyle.setHasBullet(false);
}
-
+
tmpParagraphStyle.setParEffectOffset(peOffset);
tmpParagraphStyle.charStyle().setParent(charStyle);
+ if (tabDefinitions != nullptr)
+ {
+ int n = PyList_Size(tabDefinitions);
+ for (int i = 0; i < n; i++)
+ {
+ PyObject* tabDefinition = PyList_GetItem(tabDefinitions, i);
+ int size = PyTuple_Check(tabDefinition) ? PyTuple_Size(tabDefinition) : 1;
+ PyObject* tabPositionDefinition = PyTuple_Check(tabDefinition) ? PyTuple_GetItem(tabDefinition, 0) : tabDefinition;
+
+ float tabPosition = 0.0;
+ if (!PyArg_Parse(tabPositionDefinition, "f", &tabPosition))
+ {
+ PyErr_SetString(PyExc_TypeError, QObject::tr("invalid tab-position specified.","python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+
+ int tabType = 0;
+ if (size >= 2) {
+ PyArg_Parse(PyTuple_GetItem(tabDefinition, 1), "i", &tabType);
+ }
+
+ char *fillChar = const_cast<char*>("");
+ if (size == 3) {
+ PyArg_Parse(PyTuple_GetItem(tabDefinition, 2), "es", "utf-8", &fillChar);
+ }
+
+ QString fillCharString = QString::fromUtf8(fillChar).trimmed();
+
+ ParagraphStyle::TabRecord tr;
+ tr.tabFillChar = (fillCharString.size() > 0) ? fillCharString.at(0) : QChar();
+ tr.tabPosition = static_cast<qreal>(tabPosition);
+ tr.tabType = tabType;
+ tmpParagraphStyle.appendTabValue(tr);
+ }
+ }
+
StyleSet<ParagraphStyle> tmpStyleSet;
tmpStyleSet.create(tmpParagraphStyle);
ScCore->primaryMainWindow()->doc->redefineStyles(tmpStyleSet, false);
diff --git a/scribus/plugins/scriptplugin/cmdstyle.h b/scribus/plugins/scriptplugin/cmdstyle.h
index 25df7bbbc..fc3eb0746 100644
--- a/scribus/plugins/scriptplugin/cmdstyle.h
+++ b/scribus/plugins/scriptplugin/cmdstyle.h
@@ -41,6 +41,11 @@ dropcaplines [optional] -> height (in lines) of the caps if used\n\n\
dropcapoffset [optional] -> offset of the caps if used\n\n\
\"charstyle\" [optional] -> char style to use\n\n\
\"bullet\" [optional] -> string to use as bullet\n\n\
+\"tabs\" [optional] -> a list containg tab definitions\n\n\
+-> a tab is defined as a tuple with the following format (position,type,fillchar)\"\n\n\
+-> position [required] -> float value for the position\n\n\
+-> type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4\n\n\
+-> fillchar [optional] -> the char to fill the space; default is none\n\n\
"));
/*! 02.01.2007 - 05.01.2007 : Joachim Neu : Create a paragraph style.
Special thanks go to avox for helping me! */
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 2149ef910..d8b840127 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -784,6 +784,12 @@ void initscribus(ScribusMainWindow *mainWin)
PyDict_SetItemString(d, const_cast<char*>("PAGE_2"), Py_BuildValue(const_cast<char*>("i"), 1));
PyDict_SetItemString(d, const_cast<char*>("PAGE_3"), Py_BuildValue(const_cast<char*>("i"), 2));
PyDict_SetItemString(d, const_cast<char*>("PAGE_4"), Py_BuildValue(const_cast<char*>("i"), 3));
+ // tab alignment
+ PyDict_SetItemString(d, const_cast<char*>("TAB_LEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
+ PyDict_SetItemString(d, const_cast<char*>("TAB_RIGHT"), Py_BuildValue(const_cast<char*>("i"), 1));
+ PyDict_SetItemString(d, const_cast<char*>("TAB_PERIOD"), Py_BuildValue(const_cast<char*>("i"), 2));
+ PyDict_SetItemString(d, const_cast<char*>("TAB_COMMA"), Py_BuildValue(const_cast<char*>("i"), 3));
+ PyDict_SetItemString(d, const_cast<char*>("TAB_CENTER"), Py_BuildValue(const_cast<char*>("i"), 4));
// Measurement units understood by Scribus's units.cpp functions are exported as constant conversion
// factors to be used from Python.
--
2.23.0