r16448 by jghali - #9839: Crash when copying text frame from old doc

scribus-commit scribus-commit at lists.scribus.net
Sun Mar 13 21:00:34 CET 2011


Author: jghali
Date: Sun Mar 13 20:00:34 2011
New Revision: 16448

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16448
Log:
#9839: Crash when copying text frame from old doc
Do not read attributes specific to named character styles when reading anonymous charstyles

Modified:
    trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16448&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp Sun Mar 13 20:00:34 2011
@@ -1110,6 +1110,105 @@
 
 void Scribus134Format::readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
 {
+	static const QString CPARENT("CPARENT");
+	if (attrs.hasAttribute(CPARENT))
+		newStyle.setParent(attrs.valueAsString(CPARENT));
+
+	static const QString FONT("FONT");
+	if (attrs.hasAttribute(FONT))
+		newStyle.setFont(m_AvailableFonts->findFont(attrs.valueAsString(FONT), doc));
+	
+	static const QString FONTSIZE("FONTSIZE");
+	if (attrs.hasAttribute(FONTSIZE))
+		newStyle.setFontSize(qRound(attrs.valueAsDouble(FONTSIZE) * 10));
+	
+	static const QString FCOLOR("FCOLOR");
+	if (attrs.hasAttribute(FCOLOR))
+		newStyle.setFillColor(attrs.valueAsString(FCOLOR));
+	
+	static const QString KERN("KERN");
+	if (attrs.hasAttribute(KERN))
+		newStyle.setTracking(qRound(attrs.valueAsDouble(KERN) * 10));
+	
+	static const QString FSHADE("FSHADE");
+	if (attrs.hasAttribute(FSHADE))
+		newStyle.setFillShade(attrs.valueAsInt(FSHADE));
+	
+	static const QString EFFECTS("EFFECTS");
+	if (attrs.hasAttribute(EFFECTS))
+		newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECTS)).featureList());
+	
+	static const QString EFFECT("EFFECT");
+	if (attrs.hasAttribute(EFFECT))
+		newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECT)).featureList());
+	
+	static const QString FEATURES("FEATURES");
+	if (attrs.hasAttribute(FEATURES))
+		newStyle.setFeatures(attrs.valueAsString(FEATURES).split( " ", QString::SkipEmptyParts));
+	
+	static const QString SCOLOR("SCOLOR");
+	if (attrs.hasAttribute(SCOLOR))
+		newStyle.setStrokeColor(attrs.valueAsString(SCOLOR, CommonStrings::None));
+	
+	static const QString SSHADE("SSHADE");
+	if (attrs.hasAttribute(SSHADE))
+		newStyle.setStrokeShade(attrs.valueAsInt(SSHADE));
+	
+	static const QString SCALEH("SCALEH");
+	if (attrs.hasAttribute(SCALEH))
+		newStyle.setScaleH(qRound(attrs.valueAsDouble(SCALEH) * 10));
+	
+	static const QString SCALEV("SCALEV");
+	if (attrs.hasAttribute(SCALEV))
+		newStyle.setScaleV(qRound(attrs.valueAsDouble(SCALEV) * 10));
+	
+	static const QString BASEO("BASEO");
+	if (attrs.hasAttribute(BASEO))
+		newStyle.setBaselineOffset(qRound(attrs.valueAsDouble(BASEO) * 10));
+	
+	static const QString TXTSHX("TXTSHX");
+	if (attrs.hasAttribute(TXTSHX))
+		newStyle.setShadowXOffset(qRound(attrs.valueAsDouble(TXTSHX) * 10));
+	
+	static const QString TXTSHY("TXTSHY");
+	if (attrs.hasAttribute(TXTSHY))
+		newStyle.setShadowYOffset(qRound(attrs.valueAsDouble(TXTSHY) * 10));
+	
+	static const QString TXTOUT("TXTOUT");
+	if (attrs.hasAttribute(TXTOUT))
+		newStyle.setOutlineWidth(qRound(attrs.valueAsDouble(TXTOUT) * 10));
+	
+	static const QString TXTULP("TXTULP");
+	if (attrs.hasAttribute(TXTULP))
+		newStyle.setUnderlineOffset(qRound(attrs.valueAsDouble(TXTULP) * 10));
+	
+	static const QString TXTULW("TXTULW");
+	if (attrs.hasAttribute(TXTULW))
+		newStyle.setUnderlineWidth(qRound(attrs.valueAsDouble(TXTULW) * 10));
+	
+	static const QString TXTSTP("TXTSTP");
+	if (attrs.hasAttribute(TXTSTP))
+		newStyle.setStrikethruOffset(qRound(attrs.valueAsDouble(TXTSTP) * 10));
+	
+	static const QString TXTSTW("TXTSTW");
+	if (attrs.hasAttribute(TXTSTW))
+		newStyle.setStrikethruWidth(qRound(attrs.valueAsDouble(TXTSTW) * 10));
+
+	static const QString LANGUAGE("LANGUAGE");
+	if (attrs.hasAttribute(LANGUAGE))
+		newStyle.setLanguage(attrs.valueAsString(LANGUAGE));
+
+	static const QString SHORTCUT("SHORTCUT");
+	if (attrs.hasAttribute(SHORTCUT))
+		newStyle.setShortcut(attrs.valueAsString(SHORTCUT));
+
+	static const QString WORDTRACK("wordTrack");
+	if (attrs.hasAttribute(WORDTRACK))
+		newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK));
+}
+
+void Scribus134Format::readNamedCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
+{
 	static const QString CNAME("CNAME");
 	if (attrs.hasAttribute(CNAME))
 		newStyle.setName(attrs.valueAsString(CNAME));
@@ -1123,101 +1222,7 @@
 	else
 		newStyle.setDefaultStyle(false);
 
-	static const QString CPARENT("CPARENT");
-	if (attrs.hasAttribute(CPARENT))
-		newStyle.setParent(attrs.valueAsString(CPARENT));
-
-	static const QString FONT("FONT");
-	if (attrs.hasAttribute(FONT))
-		newStyle.setFont(m_AvailableFonts->findFont(attrs.valueAsString(FONT), doc));
-	
-	static const QString FONTSIZE("FONTSIZE");
-	if (attrs.hasAttribute(FONTSIZE))
-		newStyle.setFontSize(qRound(attrs.valueAsDouble(FONTSIZE) * 10));
-	
-	static const QString FCOLOR("FCOLOR");
-	if (attrs.hasAttribute(FCOLOR))
-		newStyle.setFillColor(attrs.valueAsString(FCOLOR));
-	
-	static const QString KERN("KERN");
-	if (attrs.hasAttribute(KERN))
-		newStyle.setTracking(qRound(attrs.valueAsDouble(KERN) * 10));
-	
-	static const QString FSHADE("FSHADE");
-	if (attrs.hasAttribute(FSHADE))
-		newStyle.setFillShade(attrs.valueAsInt(FSHADE));
-	
-	static const QString EFFECTS("EFFECTS");
-	if (attrs.hasAttribute(EFFECTS))
-		newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECTS)).featureList());
-	
-	static const QString EFFECT("EFFECT");
-	if (attrs.hasAttribute(EFFECT))
-		newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECT)).featureList());
-	
-	static const QString FEATURES("FEATURES");
-	if (attrs.hasAttribute(FEATURES))
-		newStyle.setFeatures(attrs.valueAsString(FEATURES).split( " ", QString::SkipEmptyParts));
-	
-	static const QString SCOLOR("SCOLOR");
-	if (attrs.hasAttribute(SCOLOR))
-		newStyle.setStrokeColor(attrs.valueAsString(SCOLOR, CommonStrings::None));
-	
-	static const QString SSHADE("SSHADE");
-	if (attrs.hasAttribute(SSHADE))
-		newStyle.setStrokeShade(attrs.valueAsInt(SSHADE));
-	
-	static const QString SCALEH("SCALEH");
-	if (attrs.hasAttribute(SCALEH))
-		newStyle.setScaleH(qRound(attrs.valueAsDouble(SCALEH) * 10));
-	
-	static const QString SCALEV("SCALEV");
-	if (attrs.hasAttribute(SCALEV))
-		newStyle.setScaleV(qRound(attrs.valueAsDouble(SCALEV) * 10));
-	
-	static const QString BASEO("BASEO");
-	if (attrs.hasAttribute(BASEO))
-		newStyle.setBaselineOffset(qRound(attrs.valueAsDouble(BASEO) * 10));
-	
-	static const QString TXTSHX("TXTSHX");
-	if (attrs.hasAttribute(TXTSHX))
-		newStyle.setShadowXOffset(qRound(attrs.valueAsDouble(TXTSHX) * 10));
-	
-	static const QString TXTSHY("TXTSHY");
-	if (attrs.hasAttribute(TXTSHY))
-		newStyle.setShadowYOffset(qRound(attrs.valueAsDouble(TXTSHY) * 10));
-	
-	static const QString TXTOUT("TXTOUT");
-	if (attrs.hasAttribute(TXTOUT))
-		newStyle.setOutlineWidth(qRound(attrs.valueAsDouble(TXTOUT) * 10));
-	
-	static const QString TXTULP("TXTULP");
-	if (attrs.hasAttribute(TXTULP))
-		newStyle.setUnderlineOffset(qRound(attrs.valueAsDouble(TXTULP) * 10));
-	
-	static const QString TXTULW("TXTULW");
-	if (attrs.hasAttribute(TXTULW))
-		newStyle.setUnderlineWidth(qRound(attrs.valueAsDouble(TXTULW) * 10));
-	
-	static const QString TXTSTP("TXTSTP");
-	if (attrs.hasAttribute(TXTSTP))
-		newStyle.setStrikethruOffset(qRound(attrs.valueAsDouble(TXTSTP) * 10));
-	
-	static const QString TXTSTW("TXTSTW");
-	if (attrs.hasAttribute(TXTSTW))
-		newStyle.setStrikethruWidth(qRound(attrs.valueAsDouble(TXTSTW) * 10));
-
-	static const QString LANGUAGE("LANGUAGE");
-	if (attrs.hasAttribute(LANGUAGE))
-		newStyle.setLanguage(attrs.valueAsString(LANGUAGE));
-
-	static const QString SHORTCUT("SHORTCUT");
-	if (attrs.hasAttribute(SHORTCUT))
-		newStyle.setShortcut(attrs.valueAsString(SHORTCUT));
-
-	static const QString WORDTRACK("wordTrack");
-	if (attrs.hasAttribute(WORDTRACK))
-		newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK));
+	readCharacterStyleAttrs(doc, attrs, newStyle);
 }
 
 void Scribus134Format::readParagraphStyle(ScribusDoc *doc, ScXmlStreamReader& reader, ParagraphStyle& newStyle, SCFonts &fonts)
@@ -3489,7 +3494,7 @@
 		if (tagName == "CHARSTYLE")
 		{
 			cstyle.erase();
-			readCharacterStyleAttrs(doc, attrs, cstyle);
+			readNamedCharacterStyleAttrs(doc, attrs, cstyle);
 			docCharStyles.create(cstyle);
 		}
 	}

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16448&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h Sun Mar 13 20:00:34 2011
@@ -93,6 +93,7 @@
 		bool readCheckProfile(ScribusDoc* doc, ScXmlStreamAttributes& attrs);
 		bool readColor(ColorList& colors, ScXmlStreamAttributes& attrs);
 		void readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle);
+		void readNamedCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle);
 		bool readDocItemAttributes(ScribusDoc *doc, ScXmlStreamReader& reader);
 		bool readHyphen(ScribusDoc *doc, ScXmlStreamReader& reader);
 		bool readItemText(PageItem* item, ScXmlStreamAttributes& attrs, LastStyles* last, bool impo=false, bool VorLFound=false);

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16448&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp Sun Mar 13 20:00:34 2011
@@ -1899,19 +1899,6 @@
 
 void Scribus150Format::readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
 {
-	static const QString CNAME("CNAME");
-	if (attrs.hasAttribute(CNAME))
-		newStyle.setName(attrs.valueAsString(CNAME));
-
-	// The default style attribute must be correctly set before trying to assign a parent
-	static const QString DEFAULTSTYLE("DefaultStyle");
-	if (newStyle.hasName() && attrs.hasAttribute(DEFAULTSTYLE))
-		newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
-	else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle)
-		newStyle.setDefaultStyle(true);
-	else
-		newStyle.setDefaultStyle(false);
-
 	static const QString CPARENT("CPARENT");
 	if (attrs.hasAttribute(CPARENT))
 		newStyle.setParent(attrs.valueAsString(CPARENT));
@@ -2009,6 +1996,24 @@
 		newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK));
 }
 
+void Scribus150Format::readNamedCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
+{
+	static const QString CNAME("CNAME");
+	if (attrs.hasAttribute(CNAME))
+		newStyle.setName(attrs.valueAsString(CNAME));
+
+	// The default style attribute must be correctly set before trying to assign a parent
+	static const QString DEFAULTSTYLE("DefaultStyle");
+	if (newStyle.hasName() && attrs.hasAttribute(DEFAULTSTYLE))
+		newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
+	else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle)
+		newStyle.setDefaultStyle(true);
+	else
+		newStyle.setDefaultStyle(false);
+
+	readCharacterStyleAttrs(doc, attrs, newStyle);
+}
+
 void Scribus150Format::readParagraphStyle(ScribusDoc *doc, ScXmlStreamReader& reader, ParagraphStyle& newStyle, SCFonts &fonts)
 {
 	ScXmlStreamAttributes attrs = reader.scAttributes();
@@ -4495,7 +4500,7 @@
 		if (tagName == "CHARSTYLE")
 		{
 			cstyle.erase();
-			readCharacterStyleAttrs(doc, attrs, cstyle);
+			readNamedCharacterStyleAttrs(doc, attrs, cstyle);
 			docCharStyles.create(cstyle);
 		}
 	}

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16448&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h Sun Mar 13 20:00:34 2011
@@ -101,6 +101,7 @@
 		bool readColor(ColorList& colors, ScXmlStreamAttributes& attrs);
 		bool readGradient(ScribusDoc *doc, VGradient &gra, ScXmlStreamReader& reader);
 		void readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle);
+		void readNamedCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle);
 		bool readDocItemAttributes(ScribusDoc *doc, ScXmlStreamReader& reader);
 		bool readHyphen(ScribusDoc *doc, ScXmlStreamReader& reader);
 		bool readItemText(PageItem* item, ScXmlStreamAttributes& attrs, LastStyles* last);




More information about the scribus-commit mailing list