r22969 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Fri Apr 26 23:44:03 UTC 2019
Author: jghali
Date: Fri Apr 26 23:44:03 2019
New Revision: 22969
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22969
Log:
#15629: When calling createCharStyle(), inherit any attribute not explicitly defined from default character style
Modified:
trunk/Scribus/doc/de/scripterapi-styles.html
trunk/Scribus/doc/en/scripterapi-styles.html
trunk/Scribus/doc/fr/scripterapi-styles.html
trunk/Scribus/doc/it/scripterapi-styles.html
trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
Modified: trunk/Scribus/doc/de/scripterapi-styles.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22969&path=/trunk/Scribus/doc/de/scripterapi-styles.html
==============================================================================
--- trunk/Scribus/doc/de/scripterapi-styles.html (original)
+++ trunk/Scribus/doc/de/scripterapi-styles.html Fri Apr 26 23:44:03 2019
@@ -105,7 +105,17 @@
</li>
</ul>
</p>
-<p>On a practical level, this is a challenging command to fully understand if you wish to assign a number of settings, since keeping track of where you are, and which kind of entry is needed (string vs number) is not easy. For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
+<p>Any style attribute not explicitly defined will have its value inherited from default character style.</p>
+<p>Due to the important number of arguments of this function, it is strongly advised to use Python keyword syntax when calling this function. For example if a style needs to alter only font size, do not use this syntax:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("New Style", "Arial Regular", 12)</code></li>
+</ul></p>
+<p>but use this syntax instead:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("New Style", fontsize=12)</code></li>
+</ul>
+</p>
+<p>For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
</dd>
<dt><a name="-createCustomLineStyle"><strong>createCustomLineStyle</strong></a>(...)</dt>
Modified: trunk/Scribus/doc/en/scripterapi-styles.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22969&path=/trunk/Scribus/doc/en/scripterapi-styles.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-styles.html (original)
+++ trunk/Scribus/doc/en/scripterapi-styles.html Fri Apr 26 23:44:03 2019
@@ -105,7 +105,17 @@
</li>
</ul>
</p>
-<p>On a practical level, this is a challenging command to fully understand if you wish to assign a number of settings, since keeping track of where you are, and which kind of entry is needed (string vs number) is not easy. For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
+<p>Any style attribute not explicitly defined will have its value inherited from default character style.</p>
+<p>Due to the important number of arguments of this function, it is strongly advised to use Python keyword syntax when calling this function. For example if a style needs to alter only font size, do not use this syntax:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("New Style", "Arial Regular", 12)</code></li>
+</ul></p>
+<p>but use this syntax instead:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("New Style", fontsize=12)</code></li>
+</ul>
+</p>
+<p>For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
</dd>
<dt><a name="-createCustomLineStyle"><strong>createCustomLineStyle</strong></a>(...)</dt>
Modified: trunk/Scribus/doc/fr/scripterapi-styles.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22969&path=/trunk/Scribus/doc/fr/scripterapi-styles.html
==============================================================================
--- trunk/Scribus/doc/fr/scripterapi-styles.html (original)
+++ trunk/Scribus/doc/fr/scripterapi-styles.html Fri Apr 26 23:44:03 2019
@@ -102,7 +102,17 @@
</li>
</ul>
</p>
-<p>On a practical level, this is a challenging command to fully understand if you wish to assign a number of settings, since keeping track of where you are, and which kind of entry is needed (string vs number) is not easy. For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
+<p>Tout atttribut de style non explicitement définie verra sa valeur héritée du style de caractère par défaut.</p>
+<p>Du fait du nombre important d'arguments de cette fonction, il est fortement conseillé d'utiliser la syntaxe par mots clés lors de son appel. Par example si vous souhaitez modifier uniquement la taille de police, n'appelez pas la fonction de la façon suivante:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("Nouveau Style", "Arial Regular", 12)</code></li>
+</ul></p>
+<p>mais utilisez plutôt cette syntaxe à la place:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("Nouveau Style", fontsize=12)</code></li>
+</ul>
+</p>
+<p>Pour plus de détails à ce sujet et notamment sur la façon de définir l'approche, veuillez consulter la page wiki <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
</dd>
<dt><a name="-createCustomLineStyle"><strong>createCustomLineStyle</strong></a>(...)</dt>
Modified: trunk/Scribus/doc/it/scripterapi-styles.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22969&path=/trunk/Scribus/doc/it/scripterapi-styles.html
==============================================================================
--- trunk/Scribus/doc/it/scripterapi-styles.html (original)
+++ trunk/Scribus/doc/it/scripterapi-styles.html Fri Apr 26 23:44:03 2019
@@ -105,7 +105,17 @@
</li>
</ul>
</p>
-<p>On a practical level, this is a challenging command to fully understand if you wish to assign a number of settings, since keeping track of where you are, and which kind of entry is needed (string vs number) is not easy. For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
+<p>Any style attribute not explicitly defined will have its value inherited from default character style.</p>
+<p>Due to the important number of arguments of this function, it is strongly advised to use Python keyword syntax when calling this function. For example if a style needs to alter only font size, do not use this syntax:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("New Style", "Arial Regular", 12)</code></li>
+</ul></p>
+<p>but use this syntax instead:
+<ul style="list-style-type:none">
+ <li><code>newStyle = createCharStyle("New Style", fontsize=12)</code></li>
+</ul>
+</p>
+<p>For some guidance on this showing in particular how to set tracking, see the wiki page <a href="https://wiki.scribus.net/canvas/Text_and_Text_Manipulation">Text and Text Manipulation</a>.</p>
</dd>
<dt><a name="-createCustomLineStyle"><strong>createCustomLineStyle</strong></a>(...)</dt>
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22969&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp Fri Apr 26 23:44:03 2019
@@ -8,10 +8,11 @@
#include "cmdstyle.h"
#include "cmdutil.h"
-#include "qbuffer.h"
-#include "qpixmap.h"
-//Added by qt3to4:
+#include <limits>
+
+#include <QBuffer>
#include <QList>
+#include <QPixmap>
#include "scribuscore.h"
#include "styles/paragraphstyle.h"
@@ -121,12 +122,22 @@
if (!checkHaveDocument())
return nullptr;
+ const double dbl_min = -std::numeric_limits<double>::max();
+
ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
const StyleSet<CharStyle>& charStyles = ScCore->primaryMainWindow()->doc->charStyles();
const CharStyle* defaultStyle = charStyles.getDefault();
- char *name = const_cast<char*>(""), *font = const_cast<char*>(""), *features = const_cast<char*>("inherit"), *fillColor = const_cast<char*>("Black"), *fontFeatures = const_cast<char*>(""), *strokeColor = const_cast<char*>("Black"), *language = const_cast<char*>("");
- double fontSize = defaultStyle->fontSize() / 10.0, fillShade = 1, strokeShade = 1, scaleH = 1, scaleV = 1, baselineOffset = 0, shadowXOffset = 0, shadowYOffset = 0, outlineWidth = 0, underlineOffset = 0, underlineWidth = 0, strikethruOffset = 0, strikethruWidth = 0, tracking = 0;
+ char *name = const_cast<char*>(""), *font = const_cast<char*>(""), *features = const_cast<char*>("inherit"), *fillColor = const_cast<char*>(""), *fontFeatures = const_cast<char*>(""), *strokeColor = const_cast<char*>("Black"), *language = const_cast<char*>("");
+ double fontSize = -1;
+ double fillShade = -1, strokeShade = -1;
+ double scaleH = -1, scaleV = -1;
+ double baselineOffset = dbl_min;
+ double shadowXOffset = dbl_min, shadowYOffset = dbl_min;
+ double outlineWidth = dbl_min, underlineOffset = dbl_min, underlineWidth = dbl_min;
+ double strikethruOffset = dbl_min, strikethruWidth = dbl_min;
+ double tracking = dbl_min;
+
if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesddddddddddddes", keywordargs,
"utf-8", &name, "utf-8", &font, &fontSize, "utf-8", &features,
"utf-8", &fillColor, &fillShade, "utf-8", &strokeColor, &strokeShade, &baselineOffset, &shadowXOffset,
@@ -141,53 +152,84 @@
}
QString realFont = QString(font);
- if (realFont.isEmpty())
- realFont = defaultStyle->font().scName();
-
- if (!currentDoc->AllFonts->contains(realFont))
- {
- PyErr_SetString(PyExc_ValueError, QObject::tr("Specified font is not available.", "python error").toLocal8Bit().constData());
- return nullptr;
+ if (!realFont.isEmpty())
+ {
+ if (!currentDoc->AllFonts->contains(realFont))
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("Specified font is not available.", "python error").toLocal8Bit().constData());
+ return nullptr;
+ }
}
const ColorList& docColors = currentDoc->PageColors;
QString qFillColor = QString(fillColor);
QString qStrokeColor = QString(strokeColor);
- if ((qFillColor != CommonStrings::None) && (!docColors.contains(qFillColor)))
- {
- PyErr_SetString(PyExc_ValueError, QObject::tr("Specified fill color is not available in document.", "python error").toLocal8Bit().constData());
- return nullptr;
- }
- if ((qStrokeColor != CommonStrings::None) && (!docColors.contains(qStrokeColor)))
- {
- PyErr_SetString(PyExc_ValueError, QObject::tr("Specified stroke color is not available in document.", "python error").toLocal8Bit().constData());
- return nullptr;
- }
-
+ if (!qFillColor.isEmpty())
+ {
+ if ((qFillColor != CommonStrings::None) && (!docColors.contains(qFillColor)))
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("Specified fill color is not available in document.", "python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+ }
+ if (!qStrokeColor.isEmpty())
+ {
+ if ((qStrokeColor != CommonStrings::None) && (!docColors.contains(qStrokeColor)))
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("Specified stroke color is not available in document.", "python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+ }
+
+ if (fillShade >= 0)
+ fillShade = qMax(0.0, qMin(fillShade, 1.0));
+ if (strokeShade >= 0)
+ strokeShade = qMax(0.0, qMin(strokeShade, 1.0));
QStringList featuresList = QString(features).split(',', QString::SkipEmptyParts);
+ QString qLanguage = QString(language);
CharStyle tmpCharStyle;
tmpCharStyle.setName(name);
- tmpCharStyle.setFont((*currentDoc->AllFonts)[realFont]);
- tmpCharStyle.setFontSize(fontSize * 10);
- tmpCharStyle.setFontFeatures(fontFeatures);
- tmpCharStyle.setFeatures(featuresList);
- tmpCharStyle.setFillColor(qFillColor);
- tmpCharStyle.setFillShade(fillShade * 100);
- tmpCharStyle.setStrokeColor(qStrokeColor);
- tmpCharStyle.setStrokeShade(strokeShade * 100);
- tmpCharStyle.setBaselineOffset(baselineOffset);
- tmpCharStyle.setShadowXOffset(shadowXOffset);
- tmpCharStyle.setShadowYOffset(shadowYOffset);
- tmpCharStyle.setOutlineWidth(outlineWidth);
- tmpCharStyle.setUnderlineOffset(underlineOffset);
- tmpCharStyle.setUnderlineWidth(underlineWidth);
- tmpCharStyle.setStrikethruOffset(strikethruOffset);
- tmpCharStyle.setStrikethruWidth(strikethruWidth);
- tmpCharStyle.setScaleH(scaleH * 1000);
- tmpCharStyle.setScaleV(scaleV * 1000);
- tmpCharStyle.setTracking(tracking);
- tmpCharStyle.setLanguage(QString(language));
+ if (!realFont.isEmpty())
+ tmpCharStyle.setFont((*currentDoc->AllFonts)[realFont]);
+ if (fontSize > 0)
+ tmpCharStyle.setFontSize(fontSize * 10);
+ if (fontFeatures != defaultStyle->fontFeatures())
+ tmpCharStyle.setFontFeatures(fontFeatures);
+ if (featuresList != defaultStyle->features())
+ tmpCharStyle.setFeatures(featuresList);
+ if (!qFillColor.isEmpty())
+ tmpCharStyle.setFillColor(qFillColor);
+ if (fillShade >= 0)
+ tmpCharStyle.setFillShade(fillShade * 100);
+ if (!qStrokeColor.isEmpty())
+ tmpCharStyle.setStrokeColor(qStrokeColor);
+ if (strokeShade >= 0)
+ tmpCharStyle.setStrokeShade(strokeShade * 100);
+ if (baselineOffset >= 0)
+ tmpCharStyle.setBaselineOffset(baselineOffset);
+ if (shadowXOffset != dbl_min)
+ tmpCharStyle.setShadowXOffset(shadowXOffset);
+ if (shadowYOffset != dbl_min)
+ tmpCharStyle.setShadowYOffset(shadowYOffset);
+ if (outlineWidth >= 0)
+ tmpCharStyle.setOutlineWidth(outlineWidth);
+ if (underlineOffset >= 0)
+ tmpCharStyle.setUnderlineOffset(underlineOffset);
+ if (underlineWidth >= 0)
+ tmpCharStyle.setUnderlineWidth(underlineWidth);
+ if (strikethruOffset >= 0)
+ tmpCharStyle.setStrikethruOffset(strikethruOffset);
+ if (strikethruWidth >= 0)
+ tmpCharStyle.setStrikethruWidth(strikethruWidth);
+ if (scaleH > 0)
+ tmpCharStyle.setScaleH(scaleH * 1000);
+ if (scaleV > 0)
+ tmpCharStyle.setScaleV(scaleV * 1000);
+ if (tracking != dbl_min)
+ tmpCharStyle.setTracking(tracking);
+ if (!qLanguage.isEmpty())
+ tmpCharStyle.setLanguage(qLanguage);
StyleSet<CharStyle> tmpStyleSet;
tmpStyleSet.create(tmpCharStyle);
More information about the scribus-commit
mailing list