diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.h b/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.h --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.h +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.h @@ -42,6 +42,7 @@ // The colour that is currently being built QColor m_currentColor; + bool m_colorSet; }; } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp @@ -23,31 +23,35 @@ namespace RtfReader { ColorTableDestination::ColorTableDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : - Destination( reader, output, name ) + Destination( reader, output, name ), m_currentColor(Qt::black), m_colorSet(false) { - m_currentColor = Qt::black; // this is our default color } ColorTableDestination::~ColorTableDestination() {} void ColorTableDestination::handleControlWord( const QByteArray &controlWord, bool hasValue, const int value ) { + bool handled = true; if ( controlWord == "red" ) { m_currentColor.setRed( value ); } else if (controlWord == "green" ) { m_currentColor.setGreen( value ); } else if (controlWord == "blue" ) { m_currentColor.setBlue( value ); } else { + handled = false; qCDebug(lcRtf) << "unexpected control word in colortbl:" << controlWord; } + if ( handled ) { + m_colorSet = true; + } } void ColorTableDestination::handlePlainText( const QByteArray &plainText ) { if ( plainText == ";" ) { - m_output->appendToColourTable( m_currentColor ); + m_output->appendToColourTable( m_colorSet ? m_currentColor : QColor() ); resetCurrentColor(); } else { qCDebug(lcRtf) << "unexpected text in ColorTableDestination:" << plainText; @@ -57,5 +61,6 @@ void ColorTableDestination::resetCurrentColor() { m_currentColor = Qt::black; + m_colorSet = false; } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp @@ -161,33 +161,33 @@ { QColor colour = m_colourTable.value( colourIndex ); if ( colour.isValid() ) { - m_textCharFormatStack.top().setForeground( colour ); - m_cursor->setCharFormat( m_textCharFormatStack.top() ); + m_textCharFormatStack.top().setForeground( colour ); } else { - qCDebug(lcRtf) << "invalid colour at index:" << colourIndex; + m_textCharFormatStack.top().clearForeground(); } + m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setHighlightColour( const int colourIndex ) { QColor colour = m_colourTable.value( colourIndex ); if ( colour.isValid() ) { - m_textCharFormatStack.top().setBackground( colour ); - m_cursor->setCharFormat( m_textCharFormatStack.top() ); + m_textCharFormatStack.top().setBackground( colour ); } else { - qCDebug(lcRtf) << "invalid colour at index:" << colourIndex; + m_textCharFormatStack.top().clearBackground(); } + m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setParagraphPatternBackgroundColour( const int colourIndex ) { QColor colour = m_colourTable.value( colourIndex ); if ( colour.isValid() ) { m_paragraphFormat.setBackground( colour ); - m_cursor->setBlockFormat( m_paragraphFormat ); } else { - qCDebug(lcRtf) << "invalid colour at index:" << colourIndex; + m_paragraphFormat.clearBackground(); } + m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setFont( const int fontIndex )