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

List:       kde-commits
Subject:    koffice/filters/kword/applixword
From:       David Faure <faure () kde ! org>
Date:       2010-11-03 19:01:09
Message-ID: 20101103190109.6B427AC89B () svn ! kde ! org
[Download RAW message or body]

SVN commit 1192692 by dfaure:

Same fix here: the "seek back the iodevice" trick doesn't work anymore in Qt4, use a \
m_nextPendingLine instead.  Otherwise some lines from the start_styles section \
appeared as real paragraph in the converted document. Port away from deprecated \
methods.


 M  +51 -54    applixwordimport.cc  
 M  +3 -2      applixwordimport.h  


--- trunk/koffice/filters/kword/applixword/applixwordimport.cc #1192691:1192692
@@ -55,10 +55,14 @@
 QString
 APPLIXWORDImport::nextLine(QTextStream & stream)
 {
-    QString s;
+    if (!m_nextPendingLine.isNull()) {
+        const QString s = m_nextPendingLine;
+        m_nextPendingLine.clear();
+        return s;
+    }
 
     // Read one Line
-    s = stream.readLine();
+    QString s = stream.readLine();
 
     m_instep += s.length();
     if (m_instep > m_stepsize) {
@@ -98,13 +102,13 @@
 
     str += "<?xml version=\"1.0\"?>\n";
     str += "<DOC  author=\"Reginald Stadlbauer and Torben Weis\" \
email=\"reggie@kde.org and weis@kde.org\" editor=\"KWord\" \
                mime=\"application/x-kword\">\n";
-    str += " <PAPER format=\"1\" ptWidth=\"595\" ptHeight=\"841\" mmWidth =\"210\" \
mmHeight=\"297\" inchWidth =\"8.26772\" inchHeight=\"11.6929\" orientation=\"0\" \
columns=\"1\" ptColumnspc=\"2\" mmColumnspc=\"1\" inchColumnspc=\"0.0393701\" \
hType=\"0\" fType=\"0\" ptHeadBody=\"9\" ptFootBody=\"9\" mmHeadBody=\"3.5\" \
                mmFootBody=\"3.5\" inchHeadBody=\"0.137795\" \
                inchFootBody=\"0.137795\">\n";
-    str += "  <PAPERBORDERS mmLeft=\"10\" mmTop=\"15\" mmRight=\"10\" \
mmBottom=\"15\" ptLeft=\"28\" ptTop=\"42\" ptRight=\"28\" ptBottom=\"42\" \
inchLeft=\"0.393701\" inchTop=\"0.590551\" inchRight=\"0.393701\" \
inchBottom=\"0.590551\"/>\n"; +    str += " <PAPER format=\"1\" width=\"595\" \
height=\"841\" orientation=\"0\" columns=\"1\" columnspacing=\"2\" hType=\"0\" \
fType=\"0\" spHeadBody=\"9\" spFootBody=\"9\" >\n"; +    str += "  <PAPERBORDERS \
left=\"28\" top=\"42\" right=\"28\" bottom=\"42\" />\n";  str += " </PAPER>\n";
     str += " <ATTRIBUTES processing=\"0\" standardpage=\"1\" hasHeader=\"0\" \
hasFooter=\"0\" />\n";  str += " <FRAMESETS>\n";
     str += "  <FRAMESET frameType=\"1\" autoCreateNewFrame=\"1\" frameInfo=\"0\" \
                removeable=\"0\">\n";
-    str += "   <FRAME left=\"28\" top=\"42\" right=\"566\" bottom=\"798\" \
runaround=\"1\" runaGapPT=\"2\" runaGapMM=\"1\" runaGapINCH=\"0.0393701\"  \
lWidth=\"1\" lRed=\"255\" lGreen=\"255\" lBlue=\"255\" lStyle=\"0\"  rWidth=\"1\" \
rRed=\"255\" rGreen=\"255\" rBlue=\"255\" rStyle=\"0\"  tWidth=\"1\" tRed=\"255\" \
tGreen=\"255\" tBlue=\"255\" tStyle=\"0\"  bWidth=\"1\" bRed=\"255\" bGreen=\"255\" \
bBlue=\"255\" bStyle=\"0\" bkRed=\"255\" bkGreen=\"255\" bkBlue=\"255\" bleftpt=\"0\" \
bleftmm=\"0\" bleftinch=\"0\" brightpt=\"0\" brightmm=\"0\" brightinch=\"0\" \
btoppt=\"0\" btopmm=\"0\" btopinch=\"0\" bbottompt=\"0\" bbottommm=\"0\" \
bbottominch=\"0\"/>\n"; +    str += "   <FRAME left=\"28\" top=\"42\" right=\"566\" \
bottom=\"798\" runaround=\"1\" runaroundGap=\"2\" lWidth=\"1\" lRed=\"255\" \
lGreen=\"255\" lBlue=\"255\" lStyle=\"0\"  rWidth=\"1\" rRed=\"255\" rGreen=\"255\" \
rBlue=\"255\" rStyle=\"0\"  tWidth=\"1\" tRed=\"255\" tGreen=\"255\" tBlue=\"255\" \
tStyle=\"0\"  bWidth=\"1\" bRed=\"255\" bGreen=\"255\" bBlue=\"255\" bStyle=\"0\" \
bkRed=\"255\" bkGreen=\"255\" bkBlue=\"255\" bleftpt=\"0\" brightpt=\"0\" \
btoppt=\"0\" bbottompt=\"0\" />\n";  
 
     QTextStream stream(&in);
@@ -124,14 +128,16 @@
     /**************************************************************************
      * Read header                                                            *
      **************************************************************************/
-    if (! readHeader(stream, in)) return KoFilter::StupidError;
+    if (! readHeader(stream)) return KoFilter::StupidError;
 
 
     while (!stream.atEnd()) {
         // Read one line
-        mystr = readTagLine(stream, in);
+        mystr = readTagLine(stream);
         ok = true;
 
+        //kDebug() << "mystr=" << mystr;
+
         /**********************************************************************
          * jump over start_styles if it exists                                *
          **********************************************************************/
@@ -141,7 +147,7 @@
             QString    coltxt ;
             int zaehler = 0; // Note: "zaehler" means "counter" in English
             do {
-                mystr = readTagLine(stream, in);
+                mystr = readTagLine(stream);
                 if (mystr == "<end_styles>") {
                     ok = false;
                     kDebug(30517) << "End styles";
@@ -181,7 +187,7 @@
         else if (mystr == "<start_data Applix>") {
             kDebug(30517) << "\nEmbedded Applix object starts:";
             do {
-                mystr = readTagLine(stream, in);
+                mystr = readTagLine(stream);
                 if (mystr == "<end_data>") ok = false;
                 else {
                     kDebug(30517) << "" << mystr;
@@ -196,7 +202,7 @@
         else if (mystr.startsWith("<start_hdrftr ")) {
             kDebug(30517) << "\nHeader/Footer starts:";
             do {
-                mystr = readTagLine(stream, in);
+                mystr = readTagLine(stream);
                 if (mystr == "<end_hdrftr>") ok = false;
                 else {
                     kDebug(30517) << "" << mystr;
@@ -244,55 +250,54 @@
 
             textstr = mystr.left(pos);
             mystr.remove(0, pos + 1);
-            mystr.trimmed();
+            mystr = mystr.trimmed();
             kDebug(30517) << "Text:<" << textstr << " >" << pos << "  Rest:<" << \
mystr << ">";  
             // split format
-            QStringList typeList;
-            typeList = QStringList::split(' ', mystr);
+            const QStringList typeList = mystr.split(' ', QString::SkipEmptyParts);
 
             int fontsize = 12, bold = 0, italic = 0, underline = 0, colpos = -1;
             QString fontname;
             int nn = 0;
-            for (QStringList::Iterator it = typeList.begin(); it != typeList.end(); \
                ++it) {
-                kDebug(30517) << "   No:" << nn << "   >" << (*it) << "< =";
+            Q_FOREACH(const QString& type, typeList) {
+                kDebug(30517) << "   No:" << nn << "   >" << type << "< =";
 
                 // Looking for bold
-                if ((*it) == "bold") {
+                if (type == "bold") {
                     bold = 1;
                     kDebug(30517) << "bold";
-                } else if ((*it) == "no-bold") {
+                } else if (type == "no-bold") {
                     bold = 0;
                     kDebug(30517) << "no bold";
-                } else if ((*it) == "italic") {
+                } else if (type == "italic") {
                     italic = 1;
                     kDebug(30517) << "italic";
-                } else if ((*it) == "no-italic") {
+                } else if (type == "no-italic") {
                     italic = 0;
                     kDebug(30517) << "no italic";
-                } else if ((*it) == "underline") {
+                } else if (type == "underline") {
                     underline = 1;
                     kDebug(30517) << "underline";
-                } else if ((*it) == "no-underline") {
+                } else if (type == "no-underline") {
                     underline = 0;
                     kDebug(30517) << "no underline";
-                } else if ((*it).startsWith("size")) {
-                    (*it).remove(0, 5);
-                    sscanf((const char *)(*it).toLatin1(), "%d", &fontsize);
+                } else if (type.startsWith("size")) { // e.g. size:14
+                    //type.remove(0, 5);
+                    fontsize = type.mid(5).toInt();
                     kDebug(30517) << "fontsize:" << fontsize;
-                } else if ((*it).startsWith("face")) {
-                    (*it).remove(0, 6);
-                    (*it).remove((*it).length() - 1, 1);
-                    fontname = *it;
+                } else if (type.startsWith("face")) { // e.g. face:"Symbol"
+                    //type.remove(0, 6);
+                    //type.remove(type.length() - 1, 1);
+                    fontname = type.mid(6, type.length() - 6 - 1);
                     kDebug(30517) << "fontname:" << fontname;
-                } else if ((*it).startsWith("color:")) {
-                    (*it).remove(0, 7);
-                    (*it).remove((*it).length() - 1, 1);
-                    colname = *it;
+                } else if (type.startsWith("color:")) { // e.g. color:"Black"
+                    //type.remove(0, 7);
+                    //type.remove(type.length() - 1, 1);
+                    colname = type.mid(7, type.length() - 7 - 1);
                     colpos = mcoltxt.indexOf(colname);
                     kDebug(30517) << "  Color:" << colname << "" << colpos << "";
                 } else {
-                    kDebug(30517) << "" << (*it);
+                    kDebug(30517) << "" << type;
                 }
 
 
@@ -569,40 +574,34 @@
  *                                                                            *
  ******************************************************************************/
 QString
-APPLIXWORDImport::readTagLine(QTextStream &stream, QFile &in)
+APPLIXWORDImport::readTagLine(QTextStream &stream)
 {
-    QString mystrn, mystr;
-    int     ok, pos;
-
     // Read one line
-    mystr = nextLine(stream);
+    QString mystr = nextLine(stream);
 
     // Delete whitespaces
-    mystr.trimmed();
+    mystr = mystr.trimmed();
 
     // Look if the tag continues on the next line
     if ((mystr.length() == 80) && (mystr[mystr.length()-1] == '\\')) {
-        ok = true;
+        bool ok = true;
         do {
-            // Get the actual position in the file
-            pos = in.at();
-
             // Read next line
-            mystrn = nextLine(stream);
+            QString mystrn = nextLine(stream);
 
             // Is the new line a new tag line
             if (mystrn[0] == ' ') {
                 // remove the whitespace at the start of the new line
                 mystrn.remove(0, 1);
 
-                // remove the '/' at the end of the old line
+                // remove the '\' at the end of the old line
                 mystr.remove(mystr.length() - 1, 1);
 
                 // append the new line
                 mystr += mystrn;
             } else {
-                // was the newline a newtaglien the jump back
-                in.at(pos);
+                // keep this line for later
+                m_nextPendingLine = mystrn;
                 ok = false;
             }
         } while (ok == true);
@@ -638,9 +637,9 @@
     pos = 0;
     do {
         // Searching for an quote
-        pos = textstr.find('\"', pos);
+        pos = textstr.indexOf('\"', pos);
 
-        // Is it an textqoute ?
+        // Is it a textquote ?
         if ((pos > -1) && (textstr[pos-1] == '\\')) {
             textstr.replace(pos - 1, 2, "\"");
         } else {
@@ -658,7 +657,7 @@
         // initialize
         foundSpecialCharakter = false;
 
-        pos = textstr.find("^");
+        pos = textstr.indexOf('^');
 
         // is there a special character ?
         if (pos > -1) {
@@ -685,16 +684,14 @@
  *                                                                            *
  ******************************************************************************/
 int
-APPLIXWORDImport::readHeader(QTextStream &stream, QFile &in)
+APPLIXWORDImport::readHeader(QTextStream &stream)
 {
-    QString mystr;
     int     rueck;
     int     vers[3] = { 0, 0, 0 };
 
     // Read Headline
-    mystr = readTagLine(stream, in);
+    QString mystr = readTagLine(stream);
 
-    // mystr = stream.readLine ();
     rueck = sscanf((const char *) mystr.toLatin1() ,
                    "*BEGIN WORDS VERSION=%d/%d ENCODING=%dBIT",
                    &vers[0], &vers[1], &vers[2]);
--- trunk/koffice/filters/kword/applixword/applixwordimport.h #1192691:1192692
@@ -55,15 +55,16 @@
 
 protected:
     QChar   specCharfind(QChar , QChar);
-    QString readTagLine(QTextStream &, QFile &);
+    QString readTagLine(QTextStream &);
     void    replaceSpecial(QString &);
     QString nextLine(QTextStream &);
-    int     readHeader(QTextStream &stream, QFile &);
+    int     readHeader(QTextStream &stream);
 
 private:
     int m_stepsize;
     int m_instep;
     int m_progress;
+    QString m_nextPendingLine;
 
 };
 #endif // APPLIXWORDIMPORT_H


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

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