[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Work on RTF export filter
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2003-08-30 17:37:38
[Download RAW message or body]

As I have forgotten to allow a review of what I have done for the RTF export 
filter, I have attached what I have done since the 2003-08-28.

The changes:
- use of \uc1 due to buggy RTF readers (including OOWriter.)
- remove bogus 1 for keyword like \b
- add table support (only tested with OOWriter 1.0.2.)

The table support is based on Johannes Wilm's patch:
http://lists.kde.org/?l=koffice-devel&m=105756234418255&w=2
(The RTF 1.6 stuff is still missing in the CVS compared to the patch.)

By the way: I have remove the old RTF export filter 
(koffice/filters/rtf/oldexport)

Have a nice day!
["rtf_export.diff" (text/x-diff)]

Index: ExportFilter.cc
===================================================================
RCS file: /home/kde/koffice/filters/kword/rtf/export/ExportFilter.cc,v
retrieving revision 2.60
retrieving revision 2.72
diff -u -r2.60 -r2.72
--- ExportFilter.cc	22 Aug 2003 17:16:17 -0000	2.60
+++ ExportFilter.cc	30 Aug 2003 17:29:20 -0000	2.72
@@ -1,4 +1,4 @@
-// $Header: /home/kde/koffice/filters/kword/rtf/export/ExportFilter.cc,v 2.60 \
2003/08/22 17:16:17 goutte Exp $ +// $Header: \
/home/kde/koffice/filters/kword/rtf/export/ExportFilter.cc,v 2.72 2003/08/30 17:29:20 \
goutte Exp $  
 /*
    This file is part of the KDE project
@@ -31,6 +31,7 @@
 #include <qregion.h> // for #include <kdebugclasses.h>
 #include <qimage.h>
 #include <qregexp.h>
+#include <qcolor.h>
 
 #include <klocale.h>
 #include <kdebug.h>
@@ -71,19 +72,72 @@
 {
 }
 
+static QString WritePositiveKeyword(const QString& keyword, const int value)
+{
+    QString str;
+    str += keyword;
+
+    if (value>0) // The value of the keyword cannot be negative
+        str += QString::number( value );
+    else
+        str += '0';
+
+    return str;
+}
+
+#define FULL_TABLE_SUPPORT
+
+QString RTFWorker::writeRow(const QString& textCellHeader, const QString& rowText, \
const FrameData& frame) +{
+#ifdef FULL_TABLE_SUPPORT
+    QString row;
+
+    row += "\\trowd\\trgaph60\\trql";  // start new row
+    row += WritePositiveKeyword("\\trrh", qRound(PT_TO_TWIP(frame.minHeight)));
+    row += WritePositiveKeyword("\\trleft", qRound(PT_TO_TWIP(frame.left) - \
m_paperMarginLeft)); +    //row += "\\trautofit0"; // ### VERIFY
+    row += textCellHeader;
+    row += " "; // End of keyword
+    row += rowText;
+
+    return row;
+#else
+    return QString::null;
+#endif
+}
+
+QString RTFWorker::writeBorder(const char whichBorder, const int borderWidth, const \
QColor& color) +{
+    QString str;
+    if (borderWidth > 0)
+    {
+        str += "\\clbrdr"; // Define border
+        str += whichBorder; // t=top, l=left, b=bottom, r=right
+        str += "\\brdrs\\brdrw"; // Single border; thickness
+        str += QString::number(borderWidth);
+        if (color.isValid())
+        {
+            str += lookupColor("\\brdrcf",color);
+        }
+    }
+    return str;
+}
 
 bool RTFWorker::makeTable(const FrameAnchor& anchor)
 {
-#undef FULL_TABLE_SUPPORT
     m_textBody += m_prefix;
+    QString rowText;
 
 #ifdef FULL_TABLE_SUPPORT
-    int rowCurrent=0;
-    m_textBody += "\\row";
-    m_textBody += m_eol;
+    int rowCurrent = 0;
+    bool firstCellInRow = true;
+    FrameData firstFrameData;
+    int debugCellCurrent = 0; //DEBUG
+    int debugRowCurrent = 0; //DEBUG
+    QString textCellHeader; // <celldef>
 
-    const bool oldInTable=m_inTable;
-    m_inTable=true;
+    const bool oldInTable = m_inTable;
+    m_inTable = true;
 #endif
 
     QValueList<TableCell>::ConstIterator itCell;
@@ -94,29 +148,60 @@
         // ### TODO: rowspan, colspan
         if (rowCurrent!=(*itCell).row)
         {
-            rowCurrent=(*itCell).row;
+            rowCurrent = (*itCell).row;
+            m_textBody += writeRow( textCellHeader, rowText, firstFrameData);
             m_textBody += "\\row";
             m_textBody += m_eol;
+            rowText = QString::null;
+            textCellHeader = QString::null;
+            firstCellInRow=true;
+            debugRowCurrent ++; // DEBUG
+            debugCellCurrent = 0; //DEBUG
         }
-        m_textBody += "\\trowd \\trgaph60 \\trleft-60";  // start new row
+
+        const FrameData& frame = (*itCell).frame;
+
+        if (firstCellInRow) // Not yet set, so set the position of the left border.
+        {
+            firstFrameData=frame;
+            firstCellInRow=false;
+        }
+
+        kdDebug(30515) << "Cell: " << debugRowCurrent << "," << debugCellCurrent
+            << " left: " << frame.left << " right: " << frame.right << " top: " << \
frame.top << " bottom " << frame.bottom << endl; +        textCellHeader += \
writeBorder('t',qRound(PT_TO_TWIP(frame.tWidth)),frame.tColor); +        \
textCellHeader += writeBorder('l',qRound(PT_TO_TWIP(frame.lWidth)),frame.lColor); +   \
textCellHeader += writeBorder('b',qRound(PT_TO_TWIP(frame.bWidth)),frame.bColor); +   \
textCellHeader += writeBorder('r',qRound(PT_TO_TWIP(frame.rWidth)),frame.rColor); +   \
textCellHeader += WritePositiveKeyword("\\cellx",qRound(PT_TO_TWIP(frame.right) - \
m_paperMarginRight)); //right border of cell  #endif
 
-        QValueList<ParaData> paraList = *(*itCell).paraList;
+        QString endOfParagraph;
+        QValueList<ParaData> *paraList = (*itCell).paraList;
         QValueList<ParaData>::ConstIterator it;
-        for (it=paraList.begin();it!=paraList.end();it++)
+        for (it=paraList->begin();it!=paraList->end();it++)
         {
-            m_textBody += ProcessParagraphData( \
                (*it).text,(*it).layout,(*it).formattingList);
-            m_textBody += m_eol;
-            m_textBody += "\\par";
+            rowText += endOfParagraph;
+            rowText += ProcessParagraphData( \
(*it).text,(*it).layout,(*it).formattingList); +            rowText += m_eol;
+            endOfParagraph += "\\par"; // The problem is that the last paragraph \
ends with \cell not with \par  }
 #ifdef FULL_TABLE_SUPPORT
-        m_textBody += "\\cell";
+        rowText += "\\cell";
+        debugCellCurrent ++; // DEBUG
+#else
+        m_textBody += rowText;
+        m_textBody += "\\par";
+        rowText = QString::null;
 #endif
     }
 
 #ifdef FULL_TABLE_SUPPORT
-    m_inTable=oldInTable;
-    m_textBody += "\\row\\par";  // delimit last row
+    m_textBody += writeRow( textCellHeader, rowText, firstFrameData);
+    //m_textBody += "\\row";
+    //m_textBody += m_eol;
+    m_inTable = oldInTable;
+    m_textBody += "\\par";  // delimit last row
     m_textBody += m_eol;
 #endif
     m_prefix = QString::null;
@@ -580,7 +665,7 @@
 
     // Note: we use \\ansicpg1252 because 1200 is not supposed to be supported
     // Note2: we assume using \\ansicpg1252 in RTFWorker::escapeRtfText
-    *m_streamOut << "{\\rtf1\\ansi\\ansicpg1252\\uc0\\deff0" << m_eol;
+    *m_streamOut << "{\\rtf1\\ansi\\ansicpg1252\\uc1\\deff0" << m_eol;
 
     // Default color table
     m_colorList
@@ -610,7 +695,16 @@
             *m_streamOut << "\\ftech";
         else if ( (strLower.find("script")>-1) )
             *m_streamOut << "\\fscript";
+
+#if 1
+        else
+        {
+            // We do not know the font type that we have and we cannot even tell if \
it is TrueType +            *m_streamOut << "\\fnil";
+        }
+#else
         else
+        // QFontInfo:styleHint() does not guess anything, it just returns what is in \
the QFont. Nothing put in, nothing gets out.  {
             switch (info.styleHint())
             {
@@ -637,6 +731,7 @@
                 }
             }
         }
+#endif
         *m_streamOut << "\\fcharset0\\fprq" << (info.fixedPitch()?1:2) << " "; // \
                font definition
         *m_streamOut << escapeRtfText(info.family()); // ### TODO: does RTF allows \
                brackets in the font names?
         *m_streamOut <<  ";}" << m_eol; // end font table entry
@@ -671,9 +766,13 @@
         it!=m_styleList.end();
         count++, it++)
     {
+        *m_streamOut << "{";
         if (count>0) // \s0 is not written out
             *m_streamOut << "\\s" << count;
 
+        *m_streamOut << layoutToRtf((*it),(*it),true);
+
+        // \snext must be the last keyword before the style name
         // Find the number of the following style
         uint counter=0;  // counts position in style table starting at 0
         QValueList < LayoutData > ::ConstIterator it2;
@@ -686,8 +785,8 @@
             }
         }
 
-        *m_streamOut << layoutToRtf((*it),(*it),true);
         *m_streamOut << " " << (*it).styleName << ";";
+        *m_streamOut << "}";
         *m_streamOut << m_eol;
     }
 
@@ -756,7 +855,7 @@
     }
 
     // Now add who we are in a \comment
-    QString revision("$Revision: 2.60 $");
+    QString revision("$Revision: 2.72 $");
     m_textDocInfo += "{\\comment ";
     m_textDocInfo += "Generated by KWord's RTF Export Filter";
     m_textDocInfo += revision.mid(10).replace('$',""); // has a leading and a \
trailing space. @@ -851,7 +950,7 @@
 			// encode this as decimal unicode
 			escapedText += "\\u";
             escapedText += QString::number ( ch, 10 );
-            escapedText += " ";
+            escapedText += "?"; // The \uc1 dummy character.
         }
         else
             escapedText += QCh ;
@@ -924,7 +1023,7 @@
         // Font style
         if ( formatData.italic )
         {
-            strElement+="\\i1";
+            strElement+="\\i";
         }
         else
         {
@@ -936,7 +1035,7 @@
     {
         if ( formatData.weight >= 75 )
         {
-            strElement+="\\b1";
+            strElement+="\\b";
         }
         else
         {
@@ -968,7 +1067,7 @@
             QString underlineValue = formatData.underlineValue;
             QString underlineStyle = formatData.underlineStyle;
             bool underlineWord = formatData.underlineWord;
-            QString ul = "\\ul1";  // fall-back: simple underline
+            QString ul ( "\\ul" );  // fall-back: simple underline
 
             if( underlineStyle.isEmpty() ) underlineStyle = "solid";
             if( underlineValue == "1" ) underlineValue = "single";
@@ -1006,13 +1105,13 @@
         if ( formatData.strikeout )
         {
             if( formatData.strikeoutType == "double" )
-                strElement+="\\striked1";
+                strElement+="\\striked";
             else
-                strElement+="\\strike1";
+                strElement+="\\strike";
         }
         else
         {
-            strElement+="\\strike0";
+            strElement+="\\strike0"; // ### TODO: \striked0 too?
         }
     }
 
Index: ExportFilter.h
===================================================================
RCS file: /home/kde/koffice/filters/kword/rtf/export/ExportFilter.h,v
retrieving revision 2.10
retrieving revision 2.13
diff -u -r2.10 -r2.13
--- ExportFilter.h	22 Aug 2003 17:16:17 -0000	2.10
+++ ExportFilter.h	30 Aug 2003 17:29:20 -0000	2.13
@@ -1,4 +1,4 @@
-// $Header: /home/kde/koffice/filters/kword/rtf/export/ExportFilter.h,v 2.10 \
2003/08/22 17:16:17 goutte Exp $ +// $Header: \
/home/kde/koffice/filters/kword/rtf/export/ExportFilter.h,v 2.13 2003/08/30 17:29:20 \
goutte Exp $  
 /*
    This file is part of the KDE project
@@ -25,7 +25,6 @@
 
 #include <qvaluestack.h>
 #include <qvaluelist.h>
-#include <qcolor.h>
 #include <qstringlist.h>
 
 #include <KWEFBaseWorker.h>
@@ -81,7 +80,8 @@
     QString lookupFont(const QString& fontName);
     QString lookupColor(const QString& markup, const QColor& color);
     QString lookupStyle(const QString& styleName, LayoutData& returnLayout);
-
+    QString writeRow(const QString& textCellHeader, const QString& rowText, const \
FrameData& frame); +    QString writeBorder(const char whichBorder, const int \
borderWidth, const QColor& color);  protected:
     QIODevice* m_ioDevice;
     QTextStream* m_streamOut;



_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic