From 95823488a8f82faa16b0ed363fb1a2dfa40be7d7 Mon Sep 17 00:00:00 2001
From: ale rimoldi <ale@graphicslab.org>
Date: Mon, 8 Dec 2025 21:02:38 +0100
Subject: scripter: set the parent style for char and paragraph style


diff --git a/scribus/plugins/scriptplugin/cmdstyle.cpp b/scribus/plugins/scriptplugin/cmdstyle.cpp
index 123f33c40..6e8ee4add 100644
--- a/scribus/plugins/scriptplugin/cmdstyle.cpp
+++ b/scribus/plugins/scriptplugin/cmdstyle.cpp
@@ -27,6 +27,7 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
 	//TODO - new paragraph properties for bullets and numbering
 	char* keywordargs[] = {
 			const_cast<char*>("name"),
+			const_cast<char*>("parent"),
 			const_cast<char*>("linespacingmode"),
 			const_cast<char*>("linespacing"),
 			const_cast<char*>("alignment"),
@@ -44,14 +45,15 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
 			const_cast<char*>("unit"),
 			nullptr};
 	PyESString name;
+	PyESString parent;
 	PyESString charStyle;
 	PyESString bullet;
 	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;
 	PyObject *tabDefinitions = nullptr;
-	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|ididddddiidesesOi",
-		 keywordargs, "utf-8", name.ptr(), &lineSpacingMode, &lineSpacing, &alignment,
+	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esididddddiidesesOi",
+		 keywordargs, "utf-8", name.ptr(), "utf-8", parent.ptr(), &lineSpacingMode, &lineSpacing, &alignment,
 		&leftMargin, &rightMargin, &gapBefore, &gapAfter, &firstIndent,
 		&hasDropCap, &dropCapLines, &peOffset, "utf-8", charStyle.ptr(),
 		"utf-8", bullet.ptr(), &tabDefinitions))
@@ -78,6 +80,7 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
 
 	ParagraphStyle tmpParagraphStyle;
 	tmpParagraphStyle.setName(name.c_str());
+	tmpParagraphStyle.setParent(parent.c_str());
 	tmpParagraphStyle.setLineSpacingMode((ParagraphStyle::LineSpacingMode) lineSpacingMode);
 	tmpParagraphStyle.setLineSpacing(lineSpacing);
 	tmpParagraphStyle.setAlignment((ParagraphStyle::AlignmentType) alignment);
@@ -170,6 +173,7 @@ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject
 {
 	char* keywordargs[] = {
 		const_cast<char*>("name"),
+		const_cast<char*>("parent"),
 		const_cast<char*>("font"),
 		const_cast<char*>("fontsize"),
 		const_cast<char*>("features"),
@@ -203,6 +207,7 @@ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject
 	const CharStyle* defaultStyle = charStyles.getDefault();
 
 	PyESString name;
+	PyESString parent;
 	PyESString font;
 	PyESString features;
 	PyESString fillColor;
@@ -219,8 +224,8 @@ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject
 	double strikethruOffset = dbl_min, strikethruWidth = dbl_min;
 	double tracking = dbl_min;
 	
-	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesdsdddddddddddeses", keywordargs,
-									"utf-8", name.ptr(), "utf-8", font.ptr(), &fontSize, "utf-8", features.ptr(),
+	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esesdesesdesdsdddddddddddeses", keywordargs,
+									"utf-8", name.ptr(), "utf-8", parent.ptr(), "utf-8", font.ptr(), &fontSize, "utf-8", features.ptr(),
 									"utf-8", fillColor.ptr(), &fillShade, "utf-8", strokeColor.ptr(), &strokeShade, bgColor.ptr(), &baselineOffset, &shadowXOffset,
 									&shadowYOffset, &outlineWidth, &underlineOffset, &underlineWidth, &strikethruOffset, &strikethruWidth,
 									&scaleH, &scaleV, &tracking, "utf-8", language.ptr(), "utf-8", fontFeatures.ptr()))
@@ -281,6 +286,8 @@ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject
 
 	CharStyle tmpCharStyle;
 	tmpCharStyle.setName(name.c_str());
+	if (!parent.isEmpty())
+		tmpCharStyle.setParent(parent.c_str());
 	if (!realFont.isEmpty())
 		tmpCharStyle.setFont((*currentDoc->AllFonts)[realFont]);
 	if (fontSize > 0)
diff --git a/scribus/plugins/scriptplugin/cmdstyle.h b/scribus/plugins/scriptplugin/cmdstyle.h
index 87b3287bc..c6b24bd00 100644
--- a/scribus/plugins/scriptplugin/cmdstyle.h
+++ b/scribus/plugins/scriptplugin/cmdstyle.h
@@ -22,6 +22,7 @@ PyDoc_STRVAR(scribus_createparagraphstyle__doc__,
 QT_TR_NOOP("createParagraphStyle(...)\n\n\
 Creates a paragraph style. This function takes the following keyword parameters:\n\n\
 \"name\" [required] -> specifies the name of the paragraphstyle to create\n\n\
+\"parent\" [optional] -> specifies the name of parent of the the paragraphstyle to create\n\n\
 linespacingmode [optional] -> specifies the linespacing mode; possible modes are:\n\n\
 fixed linespacing:          0\n\n\
 automatic linespacing:      1\n\n\
@@ -58,6 +59,7 @@ PyDoc_STRVAR(scribus_createcharstyle__doc__,
 QT_TR_NOOP("createCharStyle(...)\n\n\
 Creates a character style. This function takes the following keyword parameters:\n\n\
 \"name\" [required] -> name of the char style to create\n\n\
+\"parent\" [optional] -> specifies the name of parent of the the paragraphstyle to create\n\n\
 \"font\" [optional] -> name of the font to use\n\n\
 fontsize [optional] -> font size to set (double)\n\n\
 \"features\" [optional] -> nearer typographic details can be defined by a string that might contain the following phrases comma-separated (without spaces!):\n\n\
