r20466 by fschmid -

scribus-commit scribus-commit at lists.scribus.net
Thu Oct 15 20:46:32 UTC 2015


Author: fschmid
Date: Thu Oct 15 20:46:32 2015
New Revision: 20466

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20466
Log:
RTF Importer: parse Stylesheets more correctly.

Modified:
    trunk/Scribus/scribus/third_party/rtf-qt/AbstractRtfOutput.h
    trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.cpp
    trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.h
    trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp
    trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h

Modified: trunk/Scribus/scribus/third_party/rtf-qt/AbstractRtfOutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20466&path=/trunk/Scribus/scribus/third_party/rtf-qt/AbstractRtfOutput.h
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/AbstractRtfOutput.h	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/AbstractRtfOutput.h	Thu Oct 15 20:46:32 2015
@@ -314,6 +314,7 @@
 	virtual void appendToColourTable( const QColor &colour ) = 0;
 	virtual void insertFontTableEntry( FontTableEntry fontTableEntry, quint32 fontTableIndex ) = 0;
 	virtual void insertStyleSheetTableEntry( quint32 stylesheetTableIndex, ParagraphStyle stylesheetTableEntry ) = 0;
+	virtual void resolveStyleSheetParents(QHash<quint32, int> &parentSet) = 0;
 	virtual void useStyleSheetTableEntry(const int styleIndex) = 0;
 
 	virtual void startGroup();

Modified: trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20466&path=/trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.cpp	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.cpp	Thu Oct 15 20:46:32 2015
@@ -36,6 +36,7 @@
 		tbs.clear();
 		m_textStyle.setTabValues(tbs);
 		m_styleName = "";
+		m_currentStyleParent = -1;
 	}
 
 	StyleSheetDestination::~StyleSheetDestination()
@@ -168,6 +169,8 @@
 			m_textStyle.charStyle().setTracking((value * 10000 / 4) / m_textStyle.charStyle().fontSize());
 		else if (controlWord == "expndtw")
 			m_textStyle.charStyle().setTracking((pixelsFromTwips(value) * 10000) / m_textStyle.charStyle().fontSize());
+		else if (controlWord == "sbasedon")
+			m_currentStyleParent = value;
 		else if ((controlWord == "s") && hasValue)
 			m_currentStyleHandleNumber = value;
 	//	else
@@ -177,7 +180,20 @@
 	void StyleSheetDestination::handlePlainText(const QByteArray &plainText)
 	{
 		if (plainText == ";")
+		{
+			m_stylesTable.insert(m_currentStyleHandleNumber, m_currentStyleParent);
 			m_output->insertStyleSheetTableEntry(m_currentStyleHandleNumber, m_textStyle);
+			m_textStyle.erase();
+			m_textStyle.setParent(CommonStrings::DefaultParagraphStyle);
+			m_textStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing);
+			m_textStyle.charStyle().setFontVariant("");
+			m_textStyle.charStyle().setFontSize(120.0);
+			QList<ParagraphStyle::TabRecord> tbs;
+			tbs.clear();
+			m_textStyle.setTabValues(tbs);
+			m_styleName = "";
+			m_currentStyleParent = -1;
+		}
 		else if (plainText.endsWith(";"))
 		{
 			// probably a style name with a terminating delimiter
@@ -188,8 +204,18 @@
 				QByteArray styleName = plainText.left(delimiterPosition);
 				m_styleName.append(styleName);
 				m_textStyle.setName(m_output->getCurrentCodec()->toUnicode(m_styleName));
+				m_stylesTable.insert(m_currentStyleHandleNumber, m_currentStyleParent);
 				m_output->insertStyleSheetTableEntry(m_currentStyleHandleNumber, m_textStyle);
+				m_textStyle.erase();
+				m_textStyle.setParent(CommonStrings::DefaultParagraphStyle);
+				m_textStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing);
+				m_textStyle.charStyle().setFontVariant("");
+				m_textStyle.charStyle().setFontSize(120.0);
+				QList<ParagraphStyle::TabRecord> tbs;
+				tbs.clear();
+				m_textStyle.setTabValues(tbs);
 				m_styleName = "";
+				m_currentStyleParent = -1;
 			}
 			else
 			{
@@ -203,6 +229,7 @@
 
 	void StyleSheetDestination::aboutToEndDestination()
 	{
+		m_output->resolveStyleSheetParents(m_stylesTable);
 	}
 
 	double StyleSheetDestination::pixelsFromTwips(const int twips)

Modified: trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20466&path=/trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.h
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.h	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.h	Thu Oct 15 20:46:32 2015
@@ -40,8 +40,10 @@
 		protected:
 			double pixelsFromTwips(const int twips);
 			quint32 		m_currentStyleHandleNumber;
+			int			m_currentStyleParent;
 			ParagraphStyle m_textStyle;
 			QByteArray m_styleName;
+			QHash<quint32, int> m_stylesTable;
 	};
 }
 

Modified: trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20466&path=/trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp	Thu Oct 15 20:46:32 2015
@@ -381,23 +381,45 @@
 	{
 		QString newName = m_item->itemName() + ":" + stylesheetTableEntry.name();
 		stylesheetTableEntry.setName(newName);
+		if (stylesheetTableEntry.charStyle().fontVariant() != "")
+		{
+			int fontInd = stylesheetTableEntry.charStyle().fontVariant().toInt();
+			stylesheetTableEntry.charStyle().setFontVariant("");
+			if (m_fontTable.contains(fontInd))
+			{
+				FontTableEntry fontTableEntry = m_fontTable[fontInd];
+				QString fontName = getFontName(fontTableEntry.fontName());
+				stylesheetTableEntry.charStyle().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fontName]);
+				fontTableEntry.setFontName(fontName);
+				m_fontTableReal.insert(fontInd, fontTableEntry);
+			}
+		}
+		StyleSet<ParagraphStyle>tmp;
+		tmp.create(stylesheetTableEntry);
+		m_Doc->redefineStyles(tmp, false);
 		m_stylesTable.insert(stylesheetTableIndex, stylesheetTableEntry);
 	}
 
+	void SlaDocumentRtfOutput::resolveStyleSheetParents(QHash<quint32, int> &parentSet)
+	{
+		for (QHash<quint32, int>::iterator it = parentSet.begin(); it != parentSet.end(); ++it)
+		{
+			if (it.value() >= 0)
+			{
+				ParagraphStyle old = m_Doc->paragraphStyle(m_stylesTable[it.key()].name());
+				old.setParent(m_stylesTable[it.value()].name());
+				StyleSet<ParagraphStyle>tmp2;
+				tmp2.create(old);
+				m_Doc->redefineStyles(tmp2, false);
+				m_stylesTable.insert(it.key(), old);
+			}
+		}
+	}
+
 	void SlaDocumentRtfOutput::useStyleSheetTableEntry(const int styleIndex)
 	{
 		if (m_stylesTable.contains(styleIndex))
 		{
-			ParagraphStyle newStyle = m_stylesTable[styleIndex];
-			if (newStyle.charStyle().fontVariant() != "")
-			{
-				int fontInd = newStyle.charStyle().fontVariant().toInt();
-				newStyle.charStyle().setFontVariant("");
-				setFont(fontInd);
-			}
-			StyleSet<ParagraphStyle>tmp;
-			tmp.create(newStyle);
-			m_Doc->redefineStyles(tmp, false);
 			ParagraphStyle newStyle2;
 			newStyle2.setParent(m_stylesTable[styleIndex].name());
 			m_textStyle.pop();

Modified: trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20466&path=/trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h	Thu Oct 15 20:46:32 2015
@@ -78,6 +78,7 @@
 		virtual void appendToColourTable(const QColor &colour);
 		virtual void insertFontTableEntry(FontTableEntry fontTableEntry, quint32 fontTableIndex);
 		virtual void insertStyleSheetTableEntry(quint32 stylesheetTableIndex, ParagraphStyle stylesheetTableEntry);
+		virtual void resolveStyleSheetParents(QHash<quint32, int> &parentSet);
 		virtual void useStyleSheetTableEntry(const int styleIndex);
 		virtual void resetParagraphFormat();
 		virtual void resetCharacterProperties();




More information about the scribus-commit mailing list