r20461 by fschmid -
scribus-commit
scribus-commit at lists.scribus.net
Sun Oct 11 10:47:47 UTC 2015
Author: fschmid
Date: Sun Oct 11 10:47:47 2015
New Revision: 20461
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20461
Log:
Fixed Bug #13406: Paragraph Styles are not being imported from RTF files
Modified:
trunk/Scribus/scribus/third_party/rtf-qt/AbstractRtfOutput.h
trunk/Scribus/scribus/third_party/rtf-qt/DocumentDestination.cpp
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=20461&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 Sun Oct 11 10:47:47 2015
@@ -22,10 +22,9 @@
#include <QString>
#include <QVariant>
#include <QColor>
-#include <QTextImageFormat>
#include "FontTableEntry.h"
-#include "StyleSheetTableEntry.h"
+class ParagraphStyle;
/**
Namespace for the public interface for the RtfReader classes
*/
@@ -311,7 +310,8 @@
virtual void addTabStop( const int value, const int type ) = 0;
virtual void appendToColourTable( const QColor &colour ) = 0;
virtual void insertFontTableEntry( FontTableEntry fontTableEntry, quint32 fontTableIndex ) = 0;
- virtual void insertStyleSheetTableEntry( quint32 stylesheetTableIndex, StyleSheetTableEntry stylesheetTableEntry ) = 0;
+ virtual void insertStyleSheetTableEntry( quint32 stylesheetTableIndex, ParagraphStyle stylesheetTableEntry ) = 0;
+ virtual void useStyleSheetTableEntry(const int styleIndex) = 0;
virtual void startGroup();
virtual void endGroup();
Modified: trunk/Scribus/scribus/third_party/rtf-qt/DocumentDestination.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20461&path=/trunk/Scribus/scribus/third_party/rtf-qt/DocumentDestination.cpp
==============================================================================
--- trunk/Scribus/scribus/third_party/rtf-qt/DocumentDestination.cpp (original)
+++ trunk/Scribus/scribus/third_party/rtf-qt/DocumentDestination.cpp Sun Oct 11 10:47:47 2015
@@ -126,7 +126,7 @@
else if ((controlWord == "sb") && hasValue)
m_output->setSpaceBefore(value);
else if (controlWord == "sb")
- m_output->setSpaceAfter(0);
+ m_output->setSpaceBefore(0);
else if ((controlWord == "sa") && hasValue)
m_output->setSpaceAfter(value);
else if (controlWord == "sa")
@@ -160,9 +160,9 @@
m_charactersToSkip = m_uc_Value; /* TODO: this should be driven by \uc, default to 1 */
}
else if ((controlWord == "uc") && hasValue)
- {
m_uc_Value = value;
- }
+ else if ((controlWord == "s") && hasValue)
+ m_output->useStyleSheetTableEntry(value);
else if ((controlWord == "\'") && hasValue)
{
// qDebug() << "special character value:" << value;
Modified: trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20461&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 Sun Oct 11 10:47:47 2015
@@ -19,71 +19,190 @@
#include "rtfreader.h"
#include "controlword.h"
+#include "commonstrings.h"
namespace RtfReader
{
- StyleSheetDestination::StyleSheetDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) :
- Destination( reader, output, name )
- {
- m_currentStyleHandleNumber = 0; /* default */
- }
-
- StyleSheetDestination::~StyleSheetDestination()
- {
- }
-
- void StyleSheetDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value )
- {
- if ( controlWord == "ql" ) {
- m_style.setTextAlignment( LeftAligned);
- } else if ( ( controlWord == "li" ) && hasValue ) {
- m_style.setLeftIndent( value );
- } else if ( ( controlWord == "ri" ) && hasValue ) {
- m_style.setRightIndent( value );
- } else if ( controlWord == "ltrch" ) {
- m_style.setLayoutDirection( Qt::LeftToRight );
- } else if ( controlWord == "rtlch" ) {
- m_style.setLayoutDirection( Qt::RightToLeft );
- } else if ( ( controlWord == "s" ) && hasValue ) {
- m_currentStyleHandleNumber = value;
- } else if ( ( controlWord == "sb" ) && hasValue ) {
- m_style.setTopMargin( value );
- } else if ( controlWord == "sb" ) {
- // qDebug() << "space before default (0)";
- } else {
- if ( ControlWord::isDestination( controlWord ) ) {
- // qDebug() << "unhandled **Destination** control word in StyleSheetDestination:" << controlWord;
- } else {
- // qDebug() << "unhandled control word in StyleSheetDestination:" << controlWord;
- }
- }
- }
-
- void StyleSheetDestination::handlePlainText( const QByteArray &plainText )
- {
- if ( plainText == ";" ) {
- m_output->insertStyleSheetTableEntry( m_currentStyleHandleNumber, m_style );
- } else if ( plainText.endsWith( ";" ) ) {
- // probably a style name with a terminating delimiter
- int delimiterPosition = plainText.indexOf( ";" );
- if ( delimiterPosition == ( plainText.length() - 1) ) {
- // It is at the end, chop it off
- QString styleName = plainText.left( delimiterPosition );
- m_style.setStyleName( styleName );
- m_output->insertStyleSheetTableEntry( m_currentStyleHandleNumber, m_style );
- } else {
- // we were not expecting a name with a delimiter other than at the end
-// qDebug() << "Style name with embedded delimiter: " << plainText;
- }
- } else {
- // plain font name
- m_style.setStyleName( plainText );
- }
- }
-
- void StyleSheetDestination::aboutToEndDestination()
- {
+ StyleSheetDestination::StyleSheetDestination(Reader *reader, AbstractRtfOutput *output, const QString &name) : Destination(reader, output, name)
+ {
+ m_currentStyleHandleNumber = 0; /* default */
+ m_textStyle.setParent(CommonStrings::DefaultParagraphStyle);
+ m_textStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing);
+ m_textStyle.charStyle().setFontSize(120.0);
+ QList<ParagraphStyle::TabRecord> tbs;
+ tbs.clear();
+ m_textStyle.setTabValues(tbs);
+ }
+
+ StyleSheetDestination::~StyleSheetDestination()
+ {
+ }
+
+ void StyleSheetDestination::handleControlWord(const QString &controlWord, bool hasValue, const int value)
+ {
+ if (controlWord == "ql")
+ m_textStyle.setAlignment(ParagraphStyle::Leftaligned);
+ else if (controlWord == "qj")
+ m_textStyle.setAlignment(ParagraphStyle::Justified);
+ else if (controlWord == "qc")
+ m_textStyle.setAlignment(ParagraphStyle::Centered);
+ else if (controlWord == "qr")
+ m_textStyle.setAlignment(ParagraphStyle::Rightaligned);
+ else if ((controlWord == "li") && hasValue)
+ m_textStyle.setLeftMargin(pixelsFromTwips(value));
+ else if ((controlWord == "ri") && hasValue)
+ m_textStyle.setRightMargin(pixelsFromTwips(value));
+ else if ((controlWord == "sb") && hasValue)
+ m_textStyle.setGapBefore(pixelsFromTwips(value));
+ else if (controlWord == "sb")
+ m_textStyle.setGapBefore(pixelsFromTwips(0));
+ else if ((controlWord == "sa") && hasValue)
+ m_textStyle.setGapAfter(pixelsFromTwips(value));
+ else if (controlWord == "sa")
+ m_textStyle.setGapAfter(pixelsFromTwips(0));
+ else if (controlWord == "sl")
+ {
+ if (value == 0)
+ m_textStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing);
+ else
+ {
+ m_textStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing);
+ m_textStyle.setLineSpacing(pixelsFromTwips(qAbs(value)));
+ }
+ }
+ else if (controlWord == "fs")
+ {
+ if (hasValue && ( value != 0))
+ m_textStyle.charStyle().setFontSize(value * 5.0);
+ else
+ m_textStyle.charStyle().setFontSize(120.0);
+ }
+ else if (controlWord == "f")
+ m_textStyle.charStyle().setFontVariant(QString("%1").arg(value));
+ else if (controlWord == "ul")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_Underline;
+ else
+ styleEffects &= ~ScStyle_Underline;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "ulw")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_UnderlineWords;
+ else
+ styleEffects &= ~ScStyle_UnderlineWords;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "outl")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_Outline;
+ else
+ styleEffects &= ~ScStyle_Outline;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "shad")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_Shadowed;
+ else
+ styleEffects &= ~ScStyle_Shadowed;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "scaps")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_SmallCaps;
+ else
+ styleEffects &= ~ScStyle_SmallCaps;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "caps")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_AllCaps;
+ else
+ styleEffects &= ~ScStyle_AllCaps;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "strike")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ if (!hasValue || (hasValue && value != 0))
+ styleEffects |= ScStyle_Strikethrough;
+ else
+ styleEffects &= ~ScStyle_Strikethrough;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "super")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ styleEffects |= ScStyle_Superscript;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "sub")
+ {
+ StyleFlag styleEffects = m_textStyle.charStyle().effects();
+ styleEffects |= ScStyle_Subscript;
+ m_textStyle.charStyle().setFeatures(styleEffects.featureList());
+ }
+ else if (controlWord == "charscalex")
+ m_textStyle.charStyle().setScaleH(value * 10.0);
+ else if (controlWord == "dn")
+ m_textStyle.charStyle().setBaselineOffset((-value * 10000 / 2) / m_textStyle.charStyle().fontSize());
+ else if (controlWord == "up")
+ m_textStyle.charStyle().setBaselineOffset((value * 10000 / 2) / m_textStyle.charStyle().fontSize());
+ else if (controlWord == "expnd")
+ 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 == "s") && hasValue)
+ m_currentStyleHandleNumber = value;
+ // else
+ // qDebug() << "unhandled control word in StyleSheetDestination:" << controlWord;
+ }
+
+ void StyleSheetDestination::handlePlainText(const QByteArray &plainText)
+ {
+ if (plainText == ";")
+ m_output->insertStyleSheetTableEntry(m_currentStyleHandleNumber, m_textStyle);
+ else if (plainText.endsWith(";"))
+ {
+ // probably a style name with a terminating delimiter
+ int delimiterPosition = plainText.indexOf(";");
+ if (delimiterPosition == (plainText.length() - 1))
+ {
+ // It is at the end, chop it off
+ QString styleName = plainText.left(delimiterPosition);
+ m_textStyle.setName(styleName);
+ m_output->insertStyleSheetTableEntry(m_currentStyleHandleNumber, m_textStyle);
+ }
+ else
+ {
+ // we were not expecting a name with a delimiter other than at the end
+ //qDebug() << "Style name with embedded delimiter: " << plainText;
+ }
+ }
+ else
+ m_textStyle.setName(plainText);
+ }
+
+ void StyleSheetDestination::aboutToEndDestination()
+ {
// TODO
- }
+ }
+
+ double StyleSheetDestination::pixelsFromTwips(const int twips)
+ {
+ return twips / 1440.0 * 72.0;
+ }
}
Modified: trunk/Scribus/scribus/third_party/rtf-qt/StyleSheetDestination.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20461&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 Sun Oct 11 10:47:47 2015
@@ -22,26 +22,26 @@
#include <QColor>
#include "Destination.h"
-#include "StyleSheetTableEntry.h"
+#include "styles/charstyle.h"
+#include "styles/paragraphstyle.h"
namespace RtfReader
{
- class Reader;
+ class Reader;
class StyleSheetDestination: public Destination
- {
- public:
- StyleSheetDestination( Reader *reader, AbstractRtfOutput *output, const QString &name );
+ {
+ public:
+ StyleSheetDestination(Reader *reader, AbstractRtfOutput *output, const QString &name);
+ virtual ~StyleSheetDestination();
+ virtual void handleControlWord( const QString &controlWord, bool hasValue, const int value );
+ virtual void handlePlainText(const QByteArray &plainText );
+ virtual void aboutToEndDestination();
- virtual ~StyleSheetDestination();
-
- virtual void handleControlWord( const QString &controlWord, bool hasValue, const int value );
- virtual void handlePlainText(const QByteArray &plainText );
- virtual void aboutToEndDestination();
-
- protected:
- quint32 m_currentStyleHandleNumber;
- StyleSheetTableEntry m_style;
- };
+ protected:
+ double pixelsFromTwips(const int twips);
+ quint32 m_currentStyleHandleNumber;
+ ParagraphStyle m_textStyle;
+ };
}
#endif
Modified: trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20461&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 Oct 11 10:47:47 2015
@@ -376,9 +376,29 @@
}
- void SlaDocumentRtfOutput::insertStyleSheetTableEntry(quint32 stylesheetTableIndex, StyleSheetTableEntry stylesheetTableEntry)
- {
- // qDebug() << "insertStyleSheetTableEntry";
+ void SlaDocumentRtfOutput::insertStyleSheetTableEntry(quint32 stylesheetTableIndex, ParagraphStyle stylesheetTableEntry)
+ {
+ m_stylesTable.insert(stylesheetTableIndex, stylesheetTableEntry);
+ }
+
+ void SlaDocumentRtfOutput::useStyleSheetTableEntry(const int styleIndex)
+ {
+ if (m_stylesTable.contains(styleIndex))
+ {
+ ParagraphStyle newStyle = m_stylesTable[styleIndex];
+ 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();
+ m_textStyle.push(newStyle2);
+ m_textCharStyle.pop();
+ m_textCharStyle.push(newStyle2.charStyle());
+ }
}
void SlaDocumentRtfOutput::resetParagraphFormat()
Modified: trunk/Scribus/scribus/third_party/rtf-qt/sladocumentrtfoutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20461&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 Oct 11 10:47:47 2015
@@ -77,7 +77,8 @@
virtual void setTextDirectionRightToLeft();
virtual void appendToColourTable(const QColor &colour);
virtual void insertFontTableEntry(FontTableEntry fontTableEntry, quint32 fontTableIndex);
- virtual void insertStyleSheetTableEntry(quint32 stylesheetTableIndex, StyleSheetTableEntry stylesheetTableEntry);
+ virtual void insertStyleSheetTableEntry(quint32 stylesheetTableIndex, ParagraphStyle stylesheetTableEntry);
+ virtual void useStyleSheetTableEntry(const int styleIndex);
virtual void resetParagraphFormat();
virtual void resetCharacterProperties();
virtual void setParagraphAlignmentLeft();
@@ -104,6 +105,7 @@
QList<QString> m_colourTable;
QHash<int, FontTableEntry> m_fontTable;
QHash<int, FontTableEntry> m_fontTableReal;
+ QHash<int, ParagraphStyle> m_stylesTable;
QList<QByteArray> m_codecList;
};
}
More information about the scribus-commit
mailing list