diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/CMakeLists.txt b/filters/words/rtf/import/3rdparty/rtf-qt/src/CMakeLists.txt index bf36efaa9b9..2296933b148 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/CMakeLists.txt +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/CMakeLists.txt @@ -1,57 +1,58 @@ # To hide all the warnings from the generated itex2MML code if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC) add_definitions(-Wno-unused-parameter) endif () include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) #if(CMAKE_COMPILER_IS_GNUCXX) # list(APPEND CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") # list(APPEND CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage") #endif() set(RtfReader_LIB_SOURCES + rtfdebug.cpp rtfreader.cpp controlword.cpp AbstractRtfOutput.cpp AuthorPcdataDestination.cpp CategoryPcdataDestination.cpp ColorTableDestination.cpp CommentPcdataDestination.cpp CompanyPcdataDestination.cpp Destination.cpp DocumentCommentPcdataDestination.cpp DocumentDestination.cpp FontTableDestination.cpp GeneratorPcdataDestination.cpp HLinkBasePcdataDestination.cpp IgnoredDestination.cpp InfoDestination.cpp InfoTimeDestination.cpp InfoCreatedTimeDestination.cpp InfoPrintedTimeDestination.cpp InfoRevisedTimeDestination.cpp KeywordsPcdataDestination.cpp ManagerPcdataDestination.cpp OperatorPcdataDestination.cpp PcdataDestination.cpp PictDestination.cpp SubjectPcdataDestination.cpp StyleSheetDestination.cpp TextDocumentRtfOutput.cpp TitlePcdataDestination.cpp Token.cpp Tokenizer.cpp UserPropsDestination.cpp ) add_library(RtfReader SHARED ${RtfReader_LIB_SOURCES}) generate_export_header( RtfReader ) target_link_libraries(RtfReader Qt5::Gui) set_target_properties(RtfReader PROPERTIES VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION} ) install(TARGETS RtfReader ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp index 114c5ad2ac4..b5dffdaeda2 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/ColorTableDestination.cpp @@ -1,60 +1,61 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "ColorTableDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { ColorTableDestination::ColorTableDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ) { m_currentColor = Qt::black; // this is our default color } ColorTableDestination::~ColorTableDestination() {} void ColorTableDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( controlWord == "red" ) { m_currentColor.setRed( value ); } else if (controlWord == "green" ) { m_currentColor.setGreen( value ); } else if (controlWord == "blue" ) { m_currentColor.setBlue( value ); } else { - qDebug() << "unexpected control word in colortbl:" << controlWord; + qCDebug(lcRtf) << "unexpected control word in colortbl:" << controlWord; } } void ColorTableDestination::handlePlainText( const QString &plainText ) { if ( plainText == ";" ) { m_output->appendToColourTable( m_currentColor ); resetCurrentColor(); } else { - qDebug() << "unexpected text in ColorTableDestination:" << plainText; + qCDebug(lcRtf) << "unexpected text in ColorTableDestination:" << plainText; } } void ColorTableDestination::resetCurrentColor() { m_currentColor = Qt::black; } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/Destination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/Destination.cpp index f11615bbf11..e988b185db5 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/Destination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/Destination.cpp @@ -1,53 +1,54 @@ /* Copyright (C) 2008, 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "Destination.h" +#include "rtfdebug.h" #include namespace RtfReader { Destination::Destination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : m_name( name ), m_reader(reader), m_output( output ) { } Destination::~Destination() {} bool Destination::hasName( const QString &name ) { return m_name == name; } QString Destination::name() const { return m_name; } void Destination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { }; void Destination::handlePlainText( const QString &plainText ) { - qDebug() << "plain text:" << plainText << "in" << m_name; + qCDebug(lcRtf) << "plain text:" << plainText << "in" << m_name; }; void Destination::aboutToEndDestination() {}; } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/DocumentDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/DocumentDestination.cpp index 18dbbd9050c..7abf8904868 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/DocumentDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/DocumentDestination.cpp @@ -1,157 +1,158 @@ /* Copyright (C) 2010,2011 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "DocumentDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" #include "controlword.h" namespace RtfReader { DocumentDestination::DocumentDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ), m_charactersToSkip( 0 ) { } DocumentDestination::~DocumentDestination() { } void DocumentDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( controlWord == "par" ) { m_output->insertPar(); } else if ( controlWord == "tab" ) { m_output->insertTab(); } else if ( controlWord == "lquote" ) { m_output->insertLeftQuote(); } else if ( controlWord == "rquote" ) { m_output->insertRightQuote(); } else if ( controlWord == "ldblquote" ) { m_output->insertLeftDoubleQuote(); } else if ( controlWord == "rdblquote" ) { m_output->insertRightDoubleQuote(); } else if ( controlWord == "endash" ) { m_output->insertEnDash(); } else if ( controlWord == "emdash" ) { m_output->insertEmDash(); } else if ( controlWord == "enspace" ) { m_output->insertEnSpace(); } else if ( controlWord == "emspace" ) { m_output->insertEmSpace(); } else if ( controlWord == "bullet" ) { m_output->insertBullet(); } else if ( controlWord == "pard" ) { m_output->resetParagraphFormat(); } else if ( controlWord == "i" ) { m_output->setFontItalic( ! hasValue || ( hasValue && value != 0 ) ); } else if ( controlWord == "b" ) { m_output->setFontBold( ! hasValue || ( hasValue && value != 0 ) ); } else if ( controlWord == "ul" ) { m_output->setFontUnderline( ! hasValue || ( hasValue && value != 0 ) ); } else if ( controlWord == "fs" ) { if ( hasValue && ( value != 0 ) ) { m_output->setFontPointSize( value / 2.0 ); } else { m_output->setFontPointSize( 24.0 / 2.0 ); // use default } } else if ( controlWord == "cf" ) { m_output->setForegroundColour( value ); } else if ( controlWord == "cbpat" ) { m_output->setParagraphPatternBackgroundColour( value ); } else if ( controlWord == "highlight" ) { m_output->setHighlightColour( value ); } else if ( ( controlWord == "deff" ) && hasValue ) { m_output->setDefaultFont( value ); } else if ( controlWord == "f" ) { m_output->setFont( value ); } else if ( controlWord == "super" ) { m_output->setFontSuperscript(); } else if ( controlWord == "sub" ) { m_output->setFontSubscript(); } else if ( controlWord == "ql" ) { m_output->setParagraphAlignmentLeft(); } else if ( controlWord == "qj" ) { m_output->setParagraphAlignmentJustified(); } else if ( controlWord == "qc" ) { m_output->setParagraphAlignmentCentred(); } else if ( controlWord == "qr" ) { m_output->setParagraphAlignmentRight(); } else if ( ( controlWord == "fi" ) && hasValue ) { m_output->setFirstLineIndent( value ); } else if ( ( controlWord == "li" ) && hasValue ) { m_output->setLeftIndent( value ); } else if ( ( controlWord == "ri" ) && hasValue ) { m_output->setRightIndent( value ); } else if ( ( controlWord == "sb" ) && hasValue ) { m_output->setSpaceBefore( value ); } else if ( controlWord == "sb" ) { m_output->setSpaceAfter( 0 ); } else if ( ( controlWord == "sa" ) && hasValue ) { m_output->setSpaceAfter( value ); } else if ( controlWord == "sa" ) { m_output->setSpaceAfter( 0 ); } else if ( controlWord == "ltrch" ) { m_output->setTextDirectionLeftToRight(); } else if ( controlWord == "rtlch" ) { m_output->setTextDirectionRightToLeft(); } else if ( controlWord == "plain" ) { m_output->resetCharacterProperties(); } else if ( controlWord == "paperh" ) { m_output->setPageHeight( value ); } else if ( controlWord == "paperw" ) { m_output->setPageWidth( value ); } else if ( ( controlWord == "u" ) && hasValue ) { m_output->appendText( QChar( value ) ); m_charactersToSkip = 1; /* TODO: this should be driven by \uc, default to 1 */ } else if ( ( controlWord == "\'" ) && hasValue ) { - qDebug() << "special character value:" << value; + qCDebug(lcRtf) << "special character value:" << value; } else if ( controlWord == "*" ) { // handled elsewhere } else { if ( ControlWord::isDestination( controlWord ) ) { - qDebug() << "unhandled *Destination* control word in DocumentDestination:" << controlWord; + qCDebug(lcRtf) << "unhandled *Destination* control word in DocumentDestination:" << controlWord; } else { - qDebug() << "unhandled control word in DocumentDestination:" << controlWord; + qCDebug(lcRtf) << "unhandled control word in DocumentDestination:" << controlWord; } } } void DocumentDestination::handlePlainText( const QString &plainText ) { if ( m_charactersToSkip > 0 ) { - qDebug() << "skipping" << m_charactersToSkip << "of" << plainText; + qCDebug(lcRtf) << "skipping" << m_charactersToSkip << "of" << plainText; if ( m_charactersToSkip >= plainText.size() ) { m_charactersToSkip -= plainText.size(); return; } else if ( plainText.size() > m_charactersToSkip ) { QString partiallySkippedText( plainText ); partiallySkippedText.remove( 0, m_charactersToSkip ); m_output->appendText( partiallySkippedText ); m_charactersToSkip = 0; return; } } m_output->appendText( plainText ); } void DocumentDestination::aboutToEndDestination() { // TODO } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/FontTableDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/FontTableDestination.cpp index 7f8e700d6f0..ff8795ad21a 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/FontTableDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/FontTableDestination.cpp @@ -1,88 +1,89 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "FontTableDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { FontTableDestination::FontTableDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ) { } FontTableDestination::~FontTableDestination() { } void FontTableDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( controlWord == "f" ) { m_currentFontTableIndex = value; } else if ( controlWord == "froman" ) { m_fontTableEntry.setFontFamily( Roman ); } else if ( controlWord == "fswiss" ) { m_fontTableEntry.setFontFamily( Swiss ); } else if ( controlWord == "fnil" ) { m_fontTableEntry.setFontFamily( Nil ); } else if ( controlWord == "fmodern" ) { m_fontTableEntry.setFontFamily( Modern ); } else if ( controlWord == "fscript" ) { m_fontTableEntry.setFontFamily( Script ); } else if ( controlWord == "fdecor" ) { m_fontTableEntry.setFontFamily( Decor ); } else if ( controlWord == "ftech" ) { m_fontTableEntry.setFontFamily( Tech ); } else if ( controlWord == "fbidi" ) { m_fontTableEntry.setFontFamily( Bidi ); } else if ( controlWord == "fprq" ) { m_fontTableEntry.setFontPitch( static_cast(value) ); } else if ( controlWord == "fcharset" ) { // TODO: need to figure out how to sanely handle this } else { - qDebug() << "unhandled fonttbl control word:" << controlWord << "(" << value << ")"; + qCDebug(lcRtf) << "unhandled fonttbl control word:" << controlWord << "(" << value << ")"; } } void FontTableDestination::handlePlainText( const QString &plainText ) { if ( plainText == ";" ) { m_output->insertFontTableEntry( m_fontTableEntry, m_currentFontTableIndex ); } else if ( plainText.endsWith( ";" ) ) { // probably a font name with a terminating delimiter int delimiterPosition = plainText.indexOf( ";" ); if ( delimiterPosition == ( plainText.length() - 1) ) { // It is at the end, chop it off QString fontName = plainText.left( delimiterPosition ); m_fontTableEntry.setFontName( fontName ); m_output->insertFontTableEntry( m_fontTableEntry, m_currentFontTableIndex ); } else { // we were not expecting a name with a delimiter other than at the end - qDebug() << "Font name with embedded delimiter: " << plainText; + qCDebug(lcRtf) << "Font name with embedded delimiter: " << plainText; } } else { // plain font name m_fontTableEntry.setFontName( plainText ); } } void FontTableDestination::aboutToEndDestination() { // TODO } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoDestination.cpp index d8a796da86e..e2c4b938298 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoDestination.cpp @@ -1,59 +1,60 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "InfoDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { InfoDestination::InfoDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ) { } InfoDestination::~InfoDestination() {} void InfoDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( ( controlWord == "edmins" ) && hasValue ) { m_output->setTotalEditingTime( value ); } else if ( ( controlWord == "nofpages" ) && hasValue ) { m_output->setNumberOfPages( value ); } else if ( ( controlWord == "nofwords" ) && hasValue ) { m_output->setNumberOfWords( value ); } else if ( ( controlWord == "nofchars" ) && hasValue ) { m_output->setNumberOfCharacters( value ); } else if ( ( controlWord == "nofcharsws" ) && hasValue ) { m_output->setNumberOfCharactersWithoutSpaces( value ); } else if ( ( controlWord == "version" ) && hasValue ) { m_output->setVersionNumber( value ); } else if ( ( controlWord == "vern" ) && hasValue ) { m_output->setInternalVersionNumber( value ); } else if ( controlWord == "*" ) { // handled elsewhere } else { - qDebug() << "unexpected control word in InfoDestination:" << controlWord; + qCDebug(lcRtf) << "unexpected control word in InfoDestination:" << controlWord; } } void InfoDestination::handlePlainText( const QString &plainText ) { - qDebug() << "unexpected text in InfoDestination:" << plainText; + qCDebug(lcRtf) << "unexpected text in InfoDestination:" << plainText; } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoTimeDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoTimeDestination.cpp index db2ee8b457a..e567c88b395 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoTimeDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/InfoTimeDestination.cpp @@ -1,60 +1,61 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "InfoTimeDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { InfoTimeDestination::InfoTimeDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ) { } InfoTimeDestination::~InfoTimeDestination() { } void InfoTimeDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( controlWord == "yr" ) { m_year = value; } else if ( controlWord == "mo" ) { m_month = value; } else if ( controlWord == "dy" ) { m_day = value; } else if ( controlWord == "hr" ) { m_hour = value; } else if ( controlWord == "min" ) { m_minute = value; } else { - qDebug() << "unexpected control word in" << m_name << ": " << controlWord; + qCDebug(lcRtf) << "unexpected control word in" << m_name << ": " << controlWord; } } void InfoTimeDestination::handlePlainText( const QString &plainText ) { - qDebug() << "unexpected text in InfoTimeDestination:" << plainText; + qCDebug(lcRtf) << "unexpected text in InfoTimeDestination:" << plainText; } QDateTime InfoTimeDestination::dateTime() const { return QDateTime( QDate( m_year, m_month, m_day ), QTime( m_hour, m_minute, 0 ) ); } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/PcdataDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/PcdataDestination.cpp index 6f40620cd8d..e21cdb1baac 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/PcdataDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/PcdataDestination.cpp @@ -1,42 +1,43 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "PcdataDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { PcdataDestination::PcdataDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ) { } PcdataDestination::~PcdataDestination() { } void PcdataDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { - qDebug() << "unexpected control word in" << m_name << ": " << controlWord; + qCDebug(lcRtf) << "unexpected control word in" << m_name << ": " << controlWord; } void PcdataDestination::handlePlainText( const QString &plainText ) { m_pcdata = plainText; } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/PictDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/PictDestination.cpp index 568cdb9984d..64a812a768d 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/PictDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/PictDestination.cpp @@ -1,76 +1,77 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "PictDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { PictDestination::PictDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ) { } PictDestination::~PictDestination() { } void PictDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( controlWord == "jpegblip" ) { // handle this later } else if ( controlWord == "wmetafile" ) { - qDebug() << "todo: get WMF data"; + qCDebug(lcRtf) << "todo: get WMF data"; } else if ( controlWord == "picw" ) { - qDebug() << "pict width: " << value; + qCDebug(lcRtf) << "pict width: " << value; m_imageFormat.setWidth( value ); } else if ( controlWord == "pich" ) { - qDebug() << "pict height: " << value; + qCDebug(lcRtf) << "pict height: " << value; m_imageFormat.setHeight( value ); } else if ( controlWord == "picscalex" ) { - qDebug() << "X scale: " << value; + qCDebug(lcRtf) << "X scale: " << value; } else if ( controlWord == "picscaley" ) { - qDebug() << "Y scale: " << value; + qCDebug(lcRtf) << "Y scale: " << value; } else if ( controlWord == "piccropl" ) { - qDebug() << "Left crop:" << value; + qCDebug(lcRtf) << "Left crop:" << value; } else if ( controlWord == "piccropr" ) { - qDebug() << "Right crop:" << value; + qCDebug(lcRtf) << "Right crop:" << value; } else if ( controlWord == "piccropt" ) { - qDebug() << "Top crop:" << value; + qCDebug(lcRtf) << "Top crop:" << value; } else if ( controlWord == "piccropb" ) { - qDebug() << "Bottom crop:" << value; + qCDebug(lcRtf) << "Bottom crop:" << value; } else if ( controlWord == "pichgoal" ) { - qDebug() << "Goal Height:" << value; + qCDebug(lcRtf) << "Goal Height:" << value; } else if ( controlWord == "picwgoal" ) { - qDebug() << "Goal Width:" << value; + qCDebug(lcRtf) << "Goal Width:" << value; } else { - qDebug() << "unexpected control word in pict:" << controlWord; + qCDebug(lcRtf) << "unexpected control word in pict:" << controlWord; } } void PictDestination::handlePlainText( const QString &plainText ) { m_pictHexData += plainText.toLatin1(); } void PictDestination::aboutToEndDestination() { QImage image = QImage::fromData( QByteArray::fromHex( m_pictHexData ) ); m_output->createImage(image, m_imageFormat); } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/StyleSheetDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/StyleSheetDestination.cpp index 8a9ff59c90c..aaf57d2a778 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/StyleSheetDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/StyleSheetDestination.cpp @@ -1,89 +1,90 @@ /* Copyright (C) 2010, 2011 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "StyleSheetDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" #include "controlword.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)"; + qCDebug(lcRtf) << "space before default (0)"; } else { if ( ControlWord::isDestination( controlWord ) ) { - qDebug() << "unhandled **Destination** control word in StyleSheetDestination:" << controlWord; + qCDebug(lcRtf) << "unhandled **Destination** control word in StyleSheetDestination:" << controlWord; } else { - qDebug() << "unhandled control word in StyleSheetDestination:" << controlWord; + qCDebug(lcRtf) << "unhandled control word in StyleSheetDestination:" << controlWord; } } } void StyleSheetDestination::handlePlainText( const QString &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; + qCDebug(lcRtf) << "Style name with embedded delimiter: " << plainText; } } else { // plain font name m_style.setStyleName( plainText ); } } void StyleSheetDestination::aboutToEndDestination() { // TODO } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp index 8a3a2ba721e..6391550f503 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/TextDocumentRtfOutput.cpp @@ -1,338 +1,339 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "TextDocumentRtfOutput.h" +#include "rtfdebug.h" #include #include #include #include #include namespace RtfReader { TextDocumentRtfOutput::TextDocumentRtfOutput( QTextDocument *document ) : AbstractRtfOutput(), m_haveSetFont( false ), m_document( document ) { m_cursor = new QTextCursor( m_document ); QTextCharFormat defaultCharFormat; defaultCharFormat.setFontPointSize( 12 ); // default of 24 "half-points" m_textCharFormatStack.push( defaultCharFormat ); } TextDocumentRtfOutput::~TextDocumentRtfOutput() { delete m_cursor; } void TextDocumentRtfOutput::startGroup() { if ( ! m_haveSetFont ) { // TODO: think harder about how to deal with default font cases. setFont( m_defaultFontIndex ); } QTextCharFormat charFormat = m_textCharFormatStack.top(); // inherit all current properties m_textCharFormatStack.push( charFormat ); } void TextDocumentRtfOutput::endGroup() { m_textCharFormatStack.pop(); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::appendText( const QString &text ) { m_cursor->insertText( text ); } void TextDocumentRtfOutput::insertPar() { m_cursor->insertBlock(); } void TextDocumentRtfOutput::insertTab() { m_cursor->insertText( "\t" ); } void TextDocumentRtfOutput::insertLeftQuote() { m_cursor->insertText( QChar( 0x2018 ) ); } void TextDocumentRtfOutput::insertRightQuote() { m_cursor->insertText( QChar( 0x2019 ) ); } void TextDocumentRtfOutput::insertLeftDoubleQuote() { m_cursor->insertText( QChar( 0x201c ) ); } void TextDocumentRtfOutput::insertRightDoubleQuote() { m_cursor->insertText( QChar( 0x201d ) ); } void TextDocumentRtfOutput::insertEnDash() { m_cursor->insertText( QChar( 0x2013 ) ); } void TextDocumentRtfOutput::insertEmDash() { m_cursor->insertText( QChar( 0x2014 ) ); } void TextDocumentRtfOutput::insertEmSpace() { m_cursor->insertText( QChar( 0x2003 ) ); } void TextDocumentRtfOutput::insertEnSpace() { m_cursor->insertText( QChar( 0x2002 ) ); } void TextDocumentRtfOutput::insertBullet() { m_cursor->insertText( QChar( 0x2022 ) ); } void TextDocumentRtfOutput::setFontItalic( const int value ) { m_textCharFormatStack.top().setFontItalic( value != 0 ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setFontBold( const int value ) { int weight = QFont::Normal; if ( value != 0 ) { weight = QFont::Bold; } m_textCharFormatStack.top().setFontWeight( weight ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setFontUnderline( const int value ) { m_textCharFormatStack.top().setFontUnderline( value != 0 ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setFontPointSize( const int pointSize ) { m_textCharFormatStack.top().setFontPointSize( pointSize ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setForegroundColour( const int colourIndex ) { QColor colour = m_colourTable.value( colourIndex ); if ( colour.isValid() ) { m_textCharFormatStack.top().setForeground( colour ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } else { - qDebug() << "invalid colour at index:" << colourIndex; + qCDebug(lcRtf) << "invalid colour at index:" << colourIndex; } } 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() ); } else { - qDebug() << "invalid colour at index:" << colourIndex; + qCDebug(lcRtf) << "invalid colour at index:" << colourIndex; } } 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 { - qDebug() << "invalid colour at index:" << colourIndex; + qCDebug(lcRtf) << "invalid colour at index:" << colourIndex; } } void TextDocumentRtfOutput::setFont( const int fontIndex ) { if ( ! m_fontTable.contains( fontIndex ) ) { - qDebug() << "attempted to select fontIndex" << fontIndex << "not in the font table"; + qCDebug(lcRtf) << "attempted to select fontIndex" << fontIndex << "not in the font table"; return; } FontTableEntry fontEntry = m_fontTable.value( fontIndex ); - qDebug() << "selecting font:" << fontEntry.fontName(); + qCDebug(lcRtf) << "selecting font:" << fontEntry.fontName(); m_textCharFormatStack.top().setFontFamily( fontEntry.fontName() ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); m_haveSetFont = true; } void TextDocumentRtfOutput::setDefaultFont( const int fontIndex ) { m_defaultFontIndex = fontIndex; } void TextDocumentRtfOutput::appendToColourTable( const QColor &colour ) { m_colourTable.append( colour ); } void TextDocumentRtfOutput::insertFontTableEntry( FontTableEntry fontTableEntry, quint32 fontTableIndex ) { - // qDebug() << "inserting font entry:" << fontTableIndex << "with name:" << fontTableEntry.fontName(); + // qCDebug(lcRtf) << "inserting font entry:" << fontTableIndex << "with name:" << fontTableEntry.fontName(); m_fontTable.insert( fontTableIndex, fontTableEntry ); } void TextDocumentRtfOutput::insertStyleSheetTableEntry( quint32 stylesheetTableIndex, StyleSheetTableEntry stylesheetTableEntry ) { - qDebug() << "inserting stylesheet entry:" << stylesheetTableIndex << "with name:" << stylesheetTableEntry.styleName(); + qCDebug(lcRtf) << "inserting stylesheet entry:" << stylesheetTableIndex << "with name:" << stylesheetTableEntry.styleName(); m_stylesheetTable.insert( stylesheetTableIndex, stylesheetTableEntry ); } void TextDocumentRtfOutput::resetParagraphFormat() { m_paragraphFormat.setAlignment( Qt::AlignLeft ); m_paragraphFormat.setTextIndent( 0 ); m_paragraphFormat.setLeftMargin( 0 ); m_paragraphFormat.setRightMargin( 0 ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::resetCharacterProperties() { m_textCharFormatStack.top().setFontPointSize( 12 ); // default of 24 "half-points" m_textCharFormatStack.top().setFontWeight( QFont::Normal ); m_textCharFormatStack.top().setFontItalic( false ); m_textCharFormatStack.top().setFontUnderline( false ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setParagraphAlignmentLeft() { m_paragraphFormat.setAlignment( Qt::AlignLeft ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setParagraphAlignmentCentred() { m_paragraphFormat.setAlignment( Qt::AlignHCenter ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setParagraphAlignmentJustified() { m_paragraphFormat.setAlignment( Qt::AlignJustify ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setParagraphAlignmentRight() { m_paragraphFormat.setAlignment( Qt::AlignRight ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setLeftIndent( const int twips ) { m_paragraphFormat.setLeftMargin( pixelsFromTwips( twips ) ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setRightIndent( const int twips ) { m_paragraphFormat.setRightMargin( pixelsFromTwips( twips ) ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setSpaceBefore( const int twips ) { m_paragraphFormat.setTopMargin( pixelsFromTwips( twips ) ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setSpaceAfter( const int twips ) { m_paragraphFormat.setBottomMargin( pixelsFromTwips( twips ) ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setFirstLineIndent( const int twips ) { m_paragraphFormat.setTextIndent( pixelsFromTwips( twips ) ); m_cursor->setBlockFormat( m_paragraphFormat ); } void TextDocumentRtfOutput::setFontSuperscript() { m_textCharFormatStack.top().setVerticalAlignment( QTextCharFormat::AlignSuperScript ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setFontSubscript() { m_textCharFormatStack.top().setVerticalAlignment( QTextCharFormat::AlignSubScript ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setTextDirectionLeftToRight() { m_textCharFormatStack.top().setLayoutDirection( Qt::LeftToRight ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::setTextDirectionRightToLeft() { m_textCharFormatStack.top().setLayoutDirection( Qt::RightToLeft ); m_cursor->setCharFormat( m_textCharFormatStack.top() ); } void TextDocumentRtfOutput::createImage( const QImage &image, const QTextImageFormat &format ) { #if 0 QString imageUuid = QString( "rtfparser://" ) + QUuid::createUuid().toString(); m_document->addResource( QTextDocument::ImageResource, QUrl( imageUuid ), QVariant( image )); format.setName( imageUuid ); m_cursor->insertImage( format ); #else m_cursor->insertImage( image.scaled( format.width(), format.height() ) ); #endif } void TextDocumentRtfOutput::setPageHeight( const int pageHeight ) { - qDebug() << "setPageHeight: " << pageHeight << " (" << pageHeight/1440.0 << ")"; + qCDebug(lcRtf) << "setPageHeight: " << pageHeight << " (" << pageHeight/1440.0 << ")"; } void TextDocumentRtfOutput::setPageWidth( const int pageWidth ) { - qDebug() << "setPageWidth: " << pageWidth << " (" << pageWidth/1440.0 << ")"; + qCDebug(lcRtf) << "setPageWidth: " << pageWidth << " (" << pageWidth/1440.0 << ")"; } qreal TextDocumentRtfOutput::pixelsFromTwips( const int twips ) { qreal inches = twips / 1440.0; qreal pixels = inches * 96.0; return pixels; } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/Token.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/Token.cpp index 6f95c525c34..e79158212b9 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/Token.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/Token.cpp @@ -1,52 +1,51 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "Token.h" - -#include +#include "rtfdebug.h" namespace RtfReader { void Token::dump() const { switch ( type ) { case OpenGroup: - qDebug() << "token type: OpenGroup"; + qCDebug(lcRtf) << "token type: OpenGroup"; break; case CloseGroup: - qDebug() << "token type: CloseGroup"; + qCDebug(lcRtf) << "token type: CloseGroup"; break; case Control: - qDebug() << "token type: Control"; + qCDebug(lcRtf) << "token type: Control"; break; case Plain: - qDebug() << "token type: Plain"; + qCDebug(lcRtf) << "token type: Plain"; break; case Binary: - qDebug() << "token type: Binary"; + qCDebug(lcRtf) << "token type: Binary"; break; default: - qDebug() << "unexpected token type: " << type; + qCDebug(lcRtf) << "unexpected token type: " << type; } if ( type > CloseGroup ) { - qDebug() << "name: " << name; + qCDebug(lcRtf) << "name: " << name; if ( hasParameter ) { - qDebug() << "parameter: " << parameter; + qCDebug(lcRtf) << "parameter: " << parameter; } } } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/Tokenizer.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/Tokenizer.cpp index a60942a5d36..2cc0d66af3d 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/Tokenizer.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/Tokenizer.cpp @@ -1,132 +1,132 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "Tokenizer.h" +#include "rtfdebug.h" #include -#include namespace RtfReader { void Tokenizer::pullControlWord( Token *token ) { char next; while ( m_inputDevice->getChar( &next ) ) { if ( ( next == ' ' ) || ( next == '\r' ) || ( next == '\n' ) ) { break; } else if ( isalpha( next ) ) { token->name.append( next ); } else if ( isdigit( next ) || ( next == '-' ) ) { token->parameter.append( next ); token->hasParameter = true; } else { m_inputDevice->ungetChar( next ); break; } } } void Tokenizer::pullControlSymbol( Token *token) { if ( token->name == "\'" ) { char highNibbleHexDigit; char lowNibbleHexDigit; if ( m_inputDevice->getChar( &highNibbleHexDigit ) && m_inputDevice->getChar( &lowNibbleHexDigit ) && isxdigit( highNibbleHexDigit ) && isxdigit( lowNibbleHexDigit ) ) { QString hexDigits; hexDigits.append( QChar( highNibbleHexDigit ) ); hexDigits.append( QChar( lowNibbleHexDigit ) ); uint codepoint = hexDigits.toUInt(0, 16); token->type = Plain; token->name = QChar( codepoint ); } } else if ( token->name == "\\" ) { token->type = Plain; token->name = "\\"; } else if ( token->name == "*" ) { // don't need anything else here } else { - qDebug() << "unhandled control symbol in Tokenizer:" << token->name; + qCDebug(lcRtf) << "unhandled control symbol in Tokenizer:" << token->name; } } void Tokenizer::pullControl( Token *token ) { char c; m_inputDevice->getChar( &c ); token->name.append( c ); if ( isalpha( c ) ) { pullControlWord( token); } else { pullControlSymbol( token); } } void Tokenizer::pullPlainText( Token *token ) { char c; while ( m_inputDevice->getChar( &c ) ) { switch ( c ) { case '{' : case '}' : case '\\': m_inputDevice->ungetChar( c ); return; break; case '\r': case '\n': break; default: token->name.append( c ); } } } Token Tokenizer::fetchToken() { Token token; token.hasParameter = false; char c; while ( m_inputDevice->getChar( &c ) ) { switch ( c ) { case '{' : token.type = OpenGroup; return token; break; case '}' : token.type = CloseGroup; return token; break; case '\r': break; case '\n': break; case '\\': token.type = Control; pullControl( &token ); return token; break; default: token.type = Plain; token.name.append( c ); pullPlainText( &token ); return token; } } return token; } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/UserPropsDestination.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/UserPropsDestination.cpp index 12c9e33b182..98989ab1ee6 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/UserPropsDestination.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/UserPropsDestination.cpp @@ -1,73 +1,74 @@ /* Copyright (C) 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "UserPropsDestination.h" #include "rtfreader.h" +#include "rtfdebug.h" namespace RtfReader { UserPropsDestination::UserPropsDestination( Reader *reader, AbstractRtfOutput *output, const QString &name ) : Destination( reader, output, name ), m_nextPlainTextIsPropertyName( true ), m_propertyType( QVariant::String ) { } UserPropsDestination::~UserPropsDestination() {} void UserPropsDestination::handleControlWord( const QString &controlWord, bool hasValue, const int value ) { if ( controlWord == "propname" ) { m_nextPlainTextIsPropertyName = true; } else if ( ( controlWord == "proptype" ) && hasValue ) { if ( value == 30 ) { m_propertyType = QVariant::String; } else if ( value == 3 ) { m_propertyType = QVariant::Int; } else if ( value == 5 ) { m_propertyType = QVariant::Double; } else if ( value == 64 ) { m_propertyType = QVariant::Date; } else if ( value == 11 ) { m_propertyType = QVariant::Bool; } else { - qDebug() << "unhandled value type in UserPropsDestination:" << value; + qCDebug(lcRtf) << "unhandled value type in UserPropsDestination:" << value; } } else if ( controlWord == "staticval" ) { m_nextPlainTextIsPropertyName = false; } else { - qDebug() << "unexpected control word in UserPropsDestination:" << controlWord; + qCDebug(lcRtf) << "unexpected control word in UserPropsDestination:" << controlWord; } } void UserPropsDestination::handlePlainText( const QString &plainText ) { if ( m_nextPlainTextIsPropertyName ) { m_propertyName = plainText; } else { QVariant value; if ( m_propertyType == QVariant::String ) { value = QVariant( plainText ); } else { // TODO: Really need some examples of this stuff - int, float, date and boolean - qDebug() << "unhandled value type in UserPropsDestination:" << m_propertyType; + qCDebug(lcRtf) << "unhandled value type in UserPropsDestination:" << m_propertyType; } m_output->addUserProp( m_propertyName, value ); } } } diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfdebug.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfdebug.cpp new file mode 100644 index 00000000000..702c3592b16 --- /dev/null +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfdebug.cpp @@ -0,0 +1,3 @@ +#include "rtfdebug.h" + +Q_LOGGING_CATEGORY(lcRtf, "calligra.filter.rtf") diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfdebug.h b/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfdebug.h new file mode 100644 index 00000000000..de9aa2fa7a2 --- /dev/null +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfdebug.h @@ -0,0 +1,4 @@ +#include +#include + +Q_DECLARE_LOGGING_CATEGORY(lcRtf); diff --git a/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfreader.cpp b/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfreader.cpp index 734f9dfcf7a..8b7b6996463 100644 --- a/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfreader.cpp +++ b/filters/words/rtf/import/3rdparty/rtf-qt/src/rtfreader.cpp @@ -1,321 +1,322 @@ /* Copyright (C) 2008, 2010 Brad Hards This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include "rtfreader.h" +#include "rtfdebug.h" #include "controlword.h" #include "AbstractRtfOutput.h" #include "AuthorPcdataDestination.h" #include "CategoryPcdataDestination.h" #include "ColorTableDestination.h" #include "CommentPcdataDestination.h" #include "CompanyPcdataDestination.h" #include "DocumentCommentPcdataDestination.h" #include "DocumentDestination.h" #include "FontTableDestination.h" #include "GeneratorPcdataDestination.h" #include "HLinkBasePcdataDestination.h" #include "IgnoredDestination.h" #include "InfoDestination.h" #include "InfoCreatedTimeDestination.h" #include "InfoPrintedTimeDestination.h" #include "InfoRevisedTimeDestination.h" #include "KeywordsPcdataDestination.h" #include "ManagerPcdataDestination.h" #include "OperatorPcdataDestination.h" #include "PictDestination.h" #include "SubjectPcdataDestination.h" #include "StyleSheetDestination.h" #include "TitlePcdataDestination.h" #include "UserPropsDestination.h" #include #include #include namespace RtfReader { Reader::Reader( QObject *parent ): QObject ( parent ), m_inputDevice( 0 ) { } Reader::~Reader() { } bool Reader::open( const QString &filename ) { m_inputDevice = new QFile( filename, this ); bool result = m_inputDevice->open( QIODevice::ReadOnly ); return result; } void Reader::close() { if ( ! m_inputDevice ) return; m_inputDevice->close(); delete m_inputDevice; m_inputDevice = 0; } QString Reader::fileName() const { if ( m_inputDevice && m_inputDevice->exists() ) { return m_inputDevice->fileName(); } else { return QString(); } } bool Reader::parseTo( AbstractRtfOutput *output ) { if ( ( ! m_inputDevice ) || ( ! m_inputDevice->isOpen() ) ) { return false; } m_output = output; parseFile(); return true; } void Reader::parseFile() { m_tokenizer = new Tokenizer ( m_inputDevice ); if ( parseFileHeader() ) { parseDocument(); } delete m_tokenizer; } bool Reader::parseFileHeader() { bool result = true; Token token = m_tokenizer->fetchToken(); if (token.type != OpenGroup ) { - qDebug() << "Not an RTF file"; + qCDebug(lcRtf) << "Not an RTF file"; result = false; } token = m_tokenizer->fetchToken(); if ( token.type != Control ) { - qDebug() << "Not an RTF file - wrong document type"; + qCDebug(lcRtf) << "Not an RTF file - wrong document type"; result = false; } if ( ! headerFormatIsKnown( token.name, token.parameter.toInt() ) ) { - qDebug() << "Not a valid RTF file - unknown header"; + qCDebug(lcRtf) << "Not a valid RTF file - unknown header"; result = false; } return result; } bool Reader::headerFormatIsKnown( const QString &tokenName, int tokenValue ) { if ( tokenName != QString ( "rtf" ) ) { - qDebug() << "unknown / unexpected header token name:" << tokenName; + qCDebug(lcRtf) << "unknown / unexpected header token name:" << tokenName; return false; } if ( tokenValue != 1 ) { - qDebug() << "unknown / unexpected header token value:" << tokenValue; + qCDebug(lcRtf) << "unknown / unexpected header token value:" << tokenValue; return false; } return true; } Destination* Reader::makeDestination( const QString &destinationName ) { if ( destinationName == "colortbl" ) { return new ColorTableDestination( this, m_output, destinationName ); } else if ( destinationName == "creatim" ) { return new InfoCreatedTimeDestination( this, m_output, destinationName ); } else if ( destinationName == "printim" ) { return new InfoPrintedTimeDestination( this, m_output, destinationName ); } else if ( destinationName == "revtim" ) { return new InfoRevisedTimeDestination( this, m_output, destinationName ); } else if ( destinationName == "author" ) { return new AuthorPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "company" ) { return new CompanyPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "operator" ) { return new OperatorPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "comment" ) { return new CommentPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "doccomm" ) { return new DocumentCommentPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "title" ) { return new TitlePcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "subject" ) { return new SubjectPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "manager" ) { return new ManagerPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "category" ) { return new CategoryPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "keywords" ) { return new KeywordsPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "hlinkbase" ) { return new HLinkBasePcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "generator" ) { return new GeneratorPcdataDestination( this, m_output, destinationName ); } else if ( destinationName == "pict" ) { return new PictDestination( this, m_output, destinationName ); } else if ( destinationName == "fonttbl" ) { return new FontTableDestination( this, m_output, destinationName ); } else if ( destinationName == "stylesheet" ) { return new StyleSheetDestination( this, m_output, destinationName ); } else if ( destinationName == "rtf" ) { return new DocumentDestination( this, m_output, destinationName ); } else if ( destinationName == "info" ) { return new InfoDestination( this, m_output, destinationName ); } else if ( destinationName == "userprops" ) { return new UserPropsDestination( this, m_output, destinationName ); } else if ( destinationName == "ignorable" ) { return new IgnoredDestination( this, m_output, destinationName ); } - qDebug() << "creating plain old Destination for" << destinationName; + qCDebug(lcRtf) << "creating plain old Destination for" << destinationName; return new Destination( this, m_output, destinationName ); } void Reader::changeDestination( const QString &destinationName ) { if ( m_destinationStack.top()->name() == "ignorable" ) { // we don't change destinations inside ignored groups return; } - // qDebug() << m_debugIndent << "about to change destination to: " << destinationName; + // qCDebug(lcRtf) << m_debugIndent << "about to change destination to: " << destinationName; Destination *dest = makeDestination( destinationName ); m_destinationStack.push( dest ); m_stateStack.top().didChangeDestination = true; QStringList destStackElementNames; for (int i = 0; i < m_destinationStack.size(); ++i) { destStackElementNames << m_destinationStack.at(i)->name(); } - qDebug() << m_debugIndent << "destinationStack after changeDestination (" << destStackElementNames << ")"; + qCDebug(lcRtf) << m_debugIndent << "destinationStack after changeDestination (" << destStackElementNames << ")"; } void Reader::parseDocument() { class RtfGroupState state; // Push an end-of-file marker onto the stack state.endOfFile = true; m_stateStack.push( state ); // Set up the outer part of the destination stack Destination *dest = makeDestination( "rtf" ); m_destinationStack.push( dest ); m_stateStack.top().didChangeDestination = true; m_debugIndent = QString( '\t' ); // Parse RTF document bool atEndOfFile = false; m_nextSymbolMightBeDestination = false; RtfReader::ControlWord controlWord(""); while ( ! atEndOfFile ) { Token token = m_tokenizer->fetchToken(); // token.dump(); switch ( token.type ) { case OpenGroup: { // Store the current state on the stack RtfGroupState state; m_stateStack.push( state ); m_nextSymbolMightBeDestination = true; m_output->startGroup(); - // qDebug() << m_debugIndent << "opengroup"; + // qCDebug(lcRtf) << m_debugIndent << "opengroup"; m_debugIndent.append("\t"); break; } case CloseGroup: { QStringList destStackElementNames; for (int i = 0; i < m_destinationStack.size(); ++i) { destStackElementNames << m_destinationStack.at(i)->name(); } - // qDebug() << m_debugIndent << "closegroup ( destinationStack:" << destStackElementNames << ")"; + // qCDebug(lcRtf) << m_debugIndent << "closegroup ( destinationStack:" << destStackElementNames << ")"; m_debugIndent.remove(0, 1); state = m_stateStack.pop(); if ( state.endOfFile ) { atEndOfFile = true; } else { m_output->endGroup(); } if ( state.didChangeDestination ) { m_destinationStack.top()->aboutToEndDestination(); m_destinationStack.pop(); } destStackElementNames.clear(); for (int i = 0; i < m_destinationStack.size(); ++i) { destStackElementNames << m_destinationStack.at(i)->name(); } - // qDebug() << m_debugIndent << "destinationStack after CloseGroup: (" << destStackElementNames << ")"; + // qCDebug(lcRtf) << m_debugIndent << "destinationStack after CloseGroup: (" << destStackElementNames << ")"; m_nextSymbolMightBeDestination = true; break; } case Control: controlWord = ControlWord( token.name ); if ( ! controlWord.isKnown() ) { - qDebug() << "*** Unrecognised control word (not in spec 1.9.1): " << token.name; + qCDebug(lcRtf) << "*** Unrecognised control word (not in spec 1.9.1): " << token.name; } - // qDebug() << m_debugIndent << "got controlWord: " << token.name; - // qDebug() << m_debugIndent << "isDestination:" << controlWord.isDestination(); - // qDebug() << m_debugIndent << "isIgnorable:" << m_nextSymbolIsIgnorable; + // qCDebug(lcRtf) << m_debugIndent << "got controlWord: " << token.name; + // qCDebug(lcRtf) << m_debugIndent << "isDestination:" << controlWord.isDestination(); + // qCDebug(lcRtf) << m_debugIndent << "isIgnorable:" << m_nextSymbolIsIgnorable; if ( m_nextSymbolMightBeDestination && controlWord.isSupportedDestination() ) { m_nextSymbolMightBeDestination = false; m_nextSymbolIsIgnorable = false; changeDestination( token.name ); } else if ( m_nextSymbolMightBeDestination && m_nextSymbolIsIgnorable ) { // This is a control word we don't understand m_nextSymbolMightBeDestination = false; m_nextSymbolIsIgnorable = false; - qDebug() << "ignorable destination word:" << token.name; + qCDebug(lcRtf) << "ignorable destination word:" << token.name; changeDestination( "ignorable" ); } else { m_nextSymbolMightBeDestination = false; if ( token.name == "*" ) { m_nextSymbolMightBeDestination = true; m_nextSymbolIsIgnorable = true; } m_destinationStack.top()->handleControlWord( token.name, token.hasParameter, token.parameter.toInt() ); } break; case Plain: m_destinationStack.top()->handlePlainText( token.name ); break; case Binary: - qDebug() << "binary data:" << token.name; + qCDebug(lcRtf) << "binary data:" << token.name; default: - qDebug() << "Unexpected token Type"; + qCDebug(lcRtf) << "Unexpected token Type"; } } } }