r22924 by jghali - When calling createCharStyle() without specifying font, use font from default character style instead of arbitrary "Times"

scribus-commit scribus-commit at lists.scribus.net
Wed Apr 3 21:22:24 UTC 2019


Author: jghali
Date: Wed Apr  3 21:22:23 2019
New Revision: 22924

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22924
Log:
When calling createCharStyle() without specifying font, use font from default character style instead of arbitrary "Times"

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22924&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdstyle.cpp	Wed Apr  3 21:22:23 2019
@@ -116,7 +116,7 @@
 		const_cast<char*>("tracking"),
 		const_cast<char*>("language"),
 		nullptr};
-	char *Name = const_cast<char*>(""), *Font = const_cast<char*>("Times"), *Features = const_cast<char*>("inherit"), *FillColor = const_cast<char*>("Black"), *FontFeatures = const_cast<char*>(""), *StrokeColor = const_cast<char*>("Black"), *Language = const_cast<char*>("");
+	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 = 200, 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;
 	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesddddddddddddes", keywordargs,
 																									"utf-8", &Name, "utf-8", &Font, &FontSize, "utf-8", &Features,
@@ -132,11 +132,28 @@
 		return nullptr;
 	}
 
+	QString RealFont = QString(Font);
+	if (RealFont.isEmpty())
+	{
+		const StyleSet<CharStyle>& charStyles = ScCore->primaryMainWindow()->doc->charStyles();
+		int index = charStyles.find(CommonStrings::DefaultCharacterStyle);
+		if (index < 0)
+			index = charStyles.find(CommonStrings::trDefaultCharacterStyle);
+		if (index >= 0)
+			RealFont = charStyles[index].font().scName();
+	}
+
+	if (!ScCore->primaryMainWindow()->doc->AllFonts->contains(RealFont))
+	{
+		PyErr_SetString(PyExc_ValueError, QObject::tr("Specified font is not available in font list.", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
 	QStringList FeaturesList = QString(Features).split(QString(","));
 
 	CharStyle TmpCharStyle;
 	TmpCharStyle.setName(Name);
-	TmpCharStyle.setFont((*ScCore->primaryMainWindow()->doc->AllFonts)[QString(Font)]);
+	TmpCharStyle.setFont((*ScCore->primaryMainWindow()->doc->AllFonts)[RealFont]);
 	TmpCharStyle.setFontSize(FontSize * 10);
 	TmpCharStyle.setFontFeatures(FontFeatures);
 	TmpCharStyle.setFeatures(FeaturesList);




More information about the scribus-commit mailing list