r20509 by fschmid -

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 1 09:22:20 UTC 2015


Author: fschmid
Date: Sun Nov  1 09:22:20 2015
New Revision: 20509

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20509
Log:
RTF-Importer:
- Add support for Bold and Italic.
- Exit on end of file.

Modified:
    trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.cpp
    trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.h
    trunk/Scribus/scribus/third_party/rtf-qt/controlword.cpp
    trunk/Scribus/scribus/third_party/rtf-qt/rtfreader.cpp
    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/Tokenizer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20509&path=/trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.cpp	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.cpp	Sun Nov  1 09:22:20 2015
@@ -23,6 +23,11 @@
 {
 	Tokenizer::Tokenizer(QIODevice *inputDevice) : m_inputDevice(inputDevice)
 	{
+	}
+
+	bool Tokenizer::atEnd()
+	{
+		return m_inputDevice->atEnd();
 	}
 
 	void Tokenizer::pullControlWord(Token *token)

Modified: trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20509&path=/trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.h
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.h	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/Tokenizer.h	Sun Nov  1 09:22:20 2015
@@ -31,7 +31,7 @@
 	{
 		public:
 			explicit Tokenizer(QIODevice *inputDevice);
-			void setEncoding(QString enc);
+			bool atEnd();
 			Token fetchToken();
 		private:
 			void pullControl(Token *token);

Modified: trunk/Scribus/scribus/third_party/rtf-qt/controlword.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20509&path=/trunk/Scribus/scribus/third_party/rtf-qt/controlword.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/controlword.cpp	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/controlword.cpp	Sun Nov  1 09:22:20 2015
@@ -1894,6 +1894,7 @@
 	    ( m_name == "userprops" ) ||
 	    ( m_name == "mmathPr" ) ||
 		 ( m_name == "listtext" ) ||
+		 ( m_name == "footnote" ) ||
 	    ( m_name == "author" ) ) {
 	    return true;
 	}

Modified: trunk/Scribus/scribus/third_party/rtf-qt/rtfreader.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20509&path=/trunk/Scribus/scribus/third_party/rtf-qt/rtfreader.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/rtfreader.cpp	(original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/rtfreader.cpp	Sun Nov  1 09:22:20 2015
@@ -294,6 +294,8 @@
 				default:
 					qDebug() << "Unexpected token Type";
 			}
+			if (m_tokenizer->atEnd())
+				break;
 		}
 	}
 }

Modified: trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20509&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	Sun Nov  1 09:22:20 2015
@@ -51,6 +51,8 @@
 		else
 			m_codec = QTextCodec::codecForLocale();
 		m_keepn = false;
+		m_isBold = false;
+		m_isItalic = false;
 	}
 
 	SlaDocumentRtfOutput::~SlaDocumentRtfOutput()
@@ -186,28 +188,70 @@
 
 	void SlaDocumentRtfOutput::setFontItalic(const int value)
 	{
-	//	qDebug() << "setFontItalic";
+		m_isItalic = (value != 0);
+		int posC = m_item->itemText.length();
+		m_item->itemText.insertChars(posC, "B");
+		m_item->itemText.applyStyle(posC, m_textStyle.top());
+		m_item->itemText.applyCharStyle(posC, 1, m_textCharStyle.top());
+		QString fam = m_item->itemText.charStyle(posC).font().family();
+		m_item->itemText.removeChars(posC, 1);
+		if (fam.isEmpty())
+			return;
+		QStringList slist = PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts.fontMap[fam];
+		if (m_isItalic)
+		{
+			if (m_isBold)
+			{
+				if (slist.contains("Bold Italic"))
+					m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Bold Italic"]);
+			}
+			else if (slist.contains("Italic"))
+				m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Italic"]);
+		}
+		else
+		{
+			if (m_isBold)
+			{
+				if (slist.contains("Bold"))
+					m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Bold"]);
+			}
+			else if (slist.contains("Regular"))
+				m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Regular"]);
+		}
 	}
 
 	void SlaDocumentRtfOutput::setFontBold(const int value)
 	{
-	/*	QString fontName = m_textCharStyle.top().font().replacementName();
-		QString family = m_textCharStyle.top().font().family();
-		QStringList slist = PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts.fontMap[family];
-		if (value != 0)
-		{
-			slist.sort();
-			if (slist.count() > 0)
-			{
-				int reInd = slist.indexOf("Bold");
-				if (reInd < 0)
-					return;
-				else
-					fontName = m_textCharStyle.top().font().family() + " " + slist[reInd];
-				return;
-			}
-		}*/
-	//	qDebug() << "setFontBold";
+		m_isBold = (value != 0);
+		int posC = m_item->itemText.length();
+		m_item->itemText.insertChars(posC, "B");
+		m_item->itemText.applyStyle(posC, m_textStyle.top());
+		m_item->itemText.applyCharStyle(posC, 1, m_textCharStyle.top());
+		QString fam = m_item->itemText.charStyle(posC).font().family();
+		m_item->itemText.removeChars(posC, 1);
+		if (fam.isEmpty())
+			return;
+		QStringList slist = PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts.fontMap[fam];
+		if (m_isBold)
+		{
+			if (m_isItalic)
+			{
+				if (slist.contains("Bold Italic"))
+					m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Bold Italic"]);
+			}
+			else if (slist.contains("Bold"))
+				m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Bold"]);
+		}
+		else
+		{
+			if (m_isItalic)
+			{
+				if (slist.contains("Italic"))
+					m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Italic"]);
+			}
+			else if (slist.contains("Regular"))
+				m_textCharStyle.top().setFont(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts[fam + " Regular"]);
+		}
 	}
 
 	void SlaDocumentRtfOutput::setFontUnderline(const int value)

Modified: trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20509&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	Sun Nov  1 09:22:20 2015
@@ -113,6 +113,8 @@
 		QHash<int, ParagraphStyle> m_stylesTable;
 		QList<QByteArray> m_codecList;
 		bool m_keepn;
+		bool m_isBold;
+		bool m_isItalic;
 	};
 }
 #endif // SLADOCUMENTRTFOUTPUT_H




More information about the scribus-commit mailing list