26#include <tqmessagebox.h>
28#include <applixwordimport.h>
29#include <applixwordimport.moc>
31#include <KoFilterChain.h>
32#include <kgenericfactory.h>
34typedef KGenericFactory<APPLIXWORDImport, KoFilter> APPLIXWORDImportFactory;
35K_EXPORT_COMPONENT_FACTORY( libapplixwordimport, APPLIXWORDImportFactory(
"kofficefilters" ) )
46APPLIXWORDImport::APPLIXWORDImport (KoFilter *, const
char *, const TQStringList& ) :
60APPLIXWORDImport::nextLine (TQTextStream & stream)
65 s = stream.readLine();
67 m_instep += s.length();
68 if (m_instep > m_stepsize)
72 emit sigProgress (m_progress) ;
88KoFilter::ConversionStatus APPLIXWORDImport::convert(
const TQCString& from,
const TQCString& to )
91 if (to!=
"application/x-kword" || from!=
"application/x-applixword")
92 return KoFilter::NotImplemented;
94 TQFile in(m_chain->inputFile());
95 if (!in.open (IO_ReadOnly))
97 kdError(30517) <<
"Unable to open input file!" << endl;
99 return KoFilter::FileNotFound;
105 str +=
"<?xml version=\"1.0\"?>\n";
106 str +=
"<DOC author=\"Reginald Stadlbauer and Torben Weis\" email=\"reggie@kde.org and weis@kde.org\" editor=\"KWord\" mime=\"application/x-kword\">\n";
107 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";
108 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";
109 str +=
" </PAPER>\n";
110 str +=
" <ATTRIBUTES processing=\"0\" standardpage=\"1\" hasHeader=\"0\" hasFooter=\"0\" />\n";
111 str +=
" <FRAMESETS>\n";
112 str +=
" <FRAMESET frameType=\"1\" autoCreateNewFrame=\"1\" frameInfo=\"0\" removeable=\"0\">\n";
113 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";
116 TQTextStream stream (&in);
118 m_stepsize = in.size()/50;
125 TQString mystr, textstr;
126 TQPtrList<t_mycolor> mcol;
127 TQStringList mcoltxt;
132 if (! readHeader (stream, in))
return KoFilter::StupidError;
135 while (!stream.atEnd())
138 mystr = readTagLine (stream, in);
144 if (mystr ==
"<start_styles>")
146 printf (
"Start styles\n");
147 t_mycolor *col =
new t_mycolor;
152 mystr = readTagLine (stream, in);
153 if (mystr ==
"<end_styles>")
156 kdDebug(30517)<<
"End styles\n\n";
160 if (mystr.startsWith (
"<color "))
163 pos = mystr.find (
"\"");
164 coltxt = mystr.left (pos);
165 mystr.remove (0,pos+1);
166 rueck = sscanf ((
const char *) mystr.latin1() ,
168 &col->c, &col->m, &col->y, &col->k);
169 kdDebug(30517)<<
" Color " << zaehler<<
" : "<<col->c <<
" " << col->m<<
" "<< col->y<<
" "<< col->k<<
" "<<coltxt<<
" "<<endl;
173 col->r = 255 - (col->c + col->k);
174 if (col->r < 0) col->r = 0;
176 col->g = 255 - (col->m + col->k);
177 if (col->g < 0) col->g = 0;
179 col->b = 255 - (col->y + col->k);
180 if (col->b < 0) col->b = 0;
183 mcoltxt.append (coltxt);
193 else if (mystr ==
"<start_data Applix>")
195 kdDebug(30517)<<
"\nEmbedded Applix object starts:\n";
198 mystr = readTagLine (stream, in);
199 if (mystr ==
"<end_data>") ok =
false;
202 kdDebug(30517)<<
" "<<mystr<<endl;
206 kdDebug(30517)<<
"Embedded Applix object ends\n\n";
212 else if (mystr.startsWith (
"<start_hdrftr "))
214 kdDebug(30517)<<
"\nHeader/Footer starts:\n";
217 mystr = readTagLine (stream, in);
218 if (mystr ==
"<end_hdrftr>") ok =
false;
221 kdDebug(30517)<<
" "<<mystr<<endl;
225 kdDebug(30517)<<
"\nHeader/Footer ends\n";
230 else if (mystr.startsWith (
"<P "))
232 sscanf ( (
const char *) mystr.latin1(),
"<P \"%99s\"", stylename);
233 mystr.remove (0, 5+strlen(stylename));
234 kdDebug(30517)<<
" Para Name: "<< stylename<<endl;
235 kdDebug(30517)<<
" Rest: "<<mystr<<endl;
240 else if (mystr.startsWith (
"<T "))
248 mystr.remove (mystr.length()-1, 1);
255 pos = mystr.find (
"\"", y);
256 kdDebug(30517)<<
"POS:"<<pos<<
" length:"<< mystr.length()<<
" y:"<<y <<endl;
258 kdDebug(30517)<<
"< "<<mystr<<
" >\n";
259 if( (pos-1 > -1) && (mystr[pos-1] ==
'\\'))
261 kdDebug(30517)<<
" No string end - but Gänsefüsschen\n";
266 kdDebug(30517)<<
" String end //\n";
272 textstr = mystr.left (pos);
273 mystr.remove (0, pos+1);
274 mystr.stripWhiteSpace();
275 kdDebug(30517) <<
"Text:<" <<textstr <<
" > "<< pos<<
" Rest:<"<< mystr<<
"> \n";
278 TQStringList typeList;
279 typeList = TQStringList::split (
' ', mystr);
281 int fontsize=12, bold=0, italic=0, underline=0, colpos=-1;
284 for (TQStringList::Iterator it = typeList.begin(); it != typeList.end(); ++it )
286 kdDebug(30517) <<
" No: "<< nn<<
" > "<< (*it)<<
"< = \n";
292 kdDebug(30517)<<
"bold\n";
294 else if ((*it) ==
"no-bold")
297 kdDebug(30517)<<
"no bold\n";
299 else if ((*it) ==
"italic")
302 kdDebug(30517)<<
"italic\n";
304 else if ((*it) ==
"no-italic")
307 kdDebug(30517) <<
"no italic\n";
309 else if ((*it) ==
"underline")
312 kdDebug(30517)<<
"underline\n";
314 else if ((*it) ==
"no-underline")
317 kdDebug(30517) <<
"no underline\n";
319 else if ((*it).startsWith (
"size"))
322 sscanf ( (
const char *) (*it).latin1(),
"%d", &fontsize);
323 kdDebug(30517)<<
"fontsize: "<< fontsize<<endl;
325 else if ((*it).startsWith (
"face"))
328 (*it).remove ((*it).length()-1, 1);
330 kdDebug(30517)<<
"fontname: "<<fontname<<endl;
332 else if ((*it).startsWith (
"color:"))
335 (*it).remove ((*it).length()-1, 1);
337 colpos = mcoltxt.findIndex (colname);
338 kdDebug(30517) <<
" Color: "<< colname<<
" "<< colpos <<
" \n";
342 kdDebug(30517)<<
" "<< (*it)<<endl;
347 kdDebug(30517) <<
"\n";
350 replaceSpecial (textstr);
354 str +=
" <PARAGRAPH>\n";
359 if (bold == 1 || underline == 1 || italic == 1 || fontsize != 12 ||
360 colpos != -1 || !fontname.isEmpty())
362 str +=
" <LAYOUT>\n";
363 str +=
" <FORMAT>\n";
364 if (!fontname.isEmpty())
366 str +=
" <FONT name=\"";
373 str +=
" <SIZE value=\"";
374 str += TQString::number (fontsize);
380 str +=
" <ITALIC value=\"1\" />\n";
385 str +=
" <WEIGHT value=\"75\" />\n";
390 str +=
" <UNDERLINE value=\"1\" />\n";
395 t_mycolor *mc =
new t_mycolor;
396 mc = mcol.at(colpos);
397 str +=
" <COLOR red=\"";
399 str += TQString::number (mc->r);
400 str +=
"\" green=\"";
401 str += TQString::number (mc->g);
403 str += TQString::number (mc->b);
408 str +=
" </FORMAT>\n";
409 str +=
" </LAYOUT>\n";
411 str +=
" </PARAGRAPH>\n";
415 emit sigProgress(100);
417 str +=
" </FRAMESET>\n";
418 str +=
" </FRAMESETS>\n";
420 kdDebug(30517)<<
"Text "<< str <<endl;
422 KoStoreDevice* out = m_chain->storageFile(
"root", KoStore::Write );
425 kdError(30517) <<
"Unable to open output file!" << endl;
427 return KoFilter::StorageCreationError;
430 TQCString cstring = str.utf8 ();
432 out->writeBlock ((
const char*) cstring, cstring.length());
443APPLIXWORDImport::specCharfind (TQChar a, TQChar b)
447 if ( (a ==
'n') && (b ==
'p') ) chr =
'ß';
450 else if ( (a ==
'n') && (b ==
'c') ) chr =
'Ò';
451 else if ( (a ==
'p') && (b ==
'c') ) chr =
'ò';
453 else if ( (a ==
'n') && (b ==
'd') ) chr =
'Ó';
454 else if ( (a ==
'p') && (b ==
'd') ) chr =
'ó';
456 else if ( (a ==
'n') && (b ==
'e') ) chr =
'Ô';
457 else if ( (a ==
'p') && (b ==
'e') ) chr =
'ô';
459 else if ( (a ==
'n') && (b ==
'f') ) chr =
'Õ';
460 else if ( (a ==
'p') && (b ==
'f') ) chr =
'õ';
462 else if ( (a ==
'p') && (b ==
'g') ) chr =
'ö';
463 else if ( (a ==
'n') && (b ==
'g') ) chr =
'Ö';
467 else if ( (a ==
'n') && (b ==
'j') ) chr =
'Ù';
468 else if ( (a ==
'p') && (b ==
'j') ) chr =
'ù';
470 else if ( (a ==
'n') && (b ==
'k') ) chr =
'Ú';
471 else if ( (a ==
'p') && (b ==
'k') ) chr =
'ú';
473 else if ( (a ==
'n') && (b ==
'l') ) chr =
'Û';
474 else if ( (a ==
'p') && (b ==
'l') ) chr =
'û';
476 else if ( (a ==
'p') && (b ==
'm') ) chr =
'ü';
477 else if ( (a ==
'n') && (b ==
'm') ) chr =
'Ü';
481 else if ( (a ==
'm') && (b ==
'a') ) chr =
'À';
482 else if ( (a ==
'o') && (b ==
'a') ) chr =
'à';
484 else if ( (a ==
'm') && (b ==
'b') ) chr =
'Á';
485 else if ( (a ==
'o') && (b ==
'b') ) chr =
'á';
487 else if ( (a ==
'm') && (b ==
'c') ) chr =
'Â';
488 else if ( (a ==
'o') && (b ==
'c') ) chr =
'â';
490 else if ( (a ==
'm') && (b ==
'd') ) chr =
'Ã';
491 else if ( (a ==
'o') && (b ==
'd') ) chr =
'ã';
493 else if ( (a ==
'm') && (b ==
'e') ) chr =
'Ä';
494 else if ( (a ==
'o') && (b ==
'e') ) chr =
'ä';
496 else if ( (a ==
'm') && (b ==
'f') ) chr =
'Å';
497 else if ( (a ==
'o') && (b ==
'f') ) chr =
'å';
499 else if ( (a ==
'm') && (b ==
'g') ) chr =
'Æ';
500 else if ( (a ==
'o') && (b ==
'g') ) chr =
'æ';
504 else if ( (a ==
'm') && (b ==
'i') ) chr =
'È';
505 else if ( (a ==
'o') && (b ==
'i') ) chr =
'è';
507 else if ( (a ==
'm') && (b ==
'j') ) chr =
'É';
508 else if ( (a ==
'o') && (b ==
'j') ) chr =
'é';
510 else if ( (a ==
'm') && (b ==
'k') ) chr =
'Ê';
511 else if ( (a ==
'o') && (b ==
'k') ) chr =
'ê';
513 else if ( (a ==
'm') && (b ==
'l') ) chr =
'Ë';
514 else if ( (a ==
'o') && (b ==
'l') ) chr =
'ë';
521 else if ( (a ==
'm') && (b ==
'm') ) chr =
'Ì';
522 else if ( (a ==
'o') && (b ==
'm') ) chr =
'ì';
524 else if ( (a ==
'm') && (b ==
'n') ) chr =
'Í';
525 else if ( (a ==
'o') && (b ==
'n') ) chr =
'í';
527 else if ( (a ==
'm') && (b ==
'o') ) chr =
'Î';
528 else if ( (a ==
'o') && (b ==
'o') ) chr =
'î';
530 else if ( (a ==
'm') && (b ==
'p') ) chr =
'Ï';
531 else if ( (a ==
'o') && (b ==
'p') ) chr =
'ï';
534 else if ( (a ==
'n') && (b ==
'b') ) chr =
'Ñ';
535 else if ( (a ==
'p') && (b ==
'b') ) chr =
'ñ';
538 else if ( (a ==
'k') && (b ==
'c') ) chr =
'¢';
539 else if ( (a ==
'k') && (b ==
'j') ) chr =
'©';
540 else if ( (a ==
'l') && (b ==
'f') ) chr =
'µ';
541 else if ( (a ==
'n') && (b ==
'i') ) chr =
'Ø';
542 else if ( (a ==
'p') && (b ==
'i') ) chr =
'ø';
544 else if ( (a ==
'l') && (b ==
'j') ) chr =
'¹';
545 else if ( (a ==
'l') && (b ==
'c') ) chr =
'²';
546 else if ( (a ==
'l') && (b ==
'd') ) chr =
'³';
548 else if ( (a ==
'l') && (b ==
'm') ) chr =
'¼';
549 else if ( (a ==
'l') && (b ==
'n') ) chr =
'½';
550 else if ( (a ==
'l') && (b ==
'o') ) chr =
'¾';
552 else if ( (a ==
'l') && (b ==
'a') ) chr =
'°';
554 else if ( (a ==
'k') && (b ==
'o') ) chr =
'®';
555 else if ( (a ==
'k') && (b ==
'h') ) chr =
'§';
556 else if ( (a ==
'k') && (b ==
'd') ) chr =
'£';
558 else if ( (a ==
'p') && (b ==
'a') ) chr =
'ð';
559 else if ( (a ==
'n') && (b ==
'a') ) chr =
'Ð';
561 else if ( (a ==
'l') && (b ==
'l') ) chr =
'»';
562 else if ( (a ==
'k') && (b ==
'l') ) chr =
'«';
564 else if ( (a ==
'l') && (b ==
'k') ) chr =
'º';
566 else if ( (a ==
'l') && (b ==
'h') ) chr =
'·';
568 else if ( (a ==
'k') && (b ==
'b') ) chr =
'¡';
570 else if ( (a ==
'k') && (b ==
'e') ) chr =
'¤';
572 else if ( (a ==
'l') && (b ==
'b') ) chr =
'±';
574 else if ( (a ==
'l') && (b ==
'p') ) chr =
'¿';
576 else if ( (a ==
'k') && (b ==
'f') ) chr =
'¥';
578 else if ( (a ==
'p') && (b ==
'o') ) chr =
'þ';
579 else if ( (a ==
'n') && (b ==
'o') ) chr =
'Þ';
581 else if ( (a ==
'n') && (b ==
'n') ) chr =
'Ý';
582 else if ( (a ==
'p') && (b ==
'n') ) chr =
'ý';
583 else if ( (a ==
'p') && (b ==
'p') ) chr =
'ÿ';
585 else if ( (a ==
'k') && (b ==
'k') ) chr =
'ª';
587 else if ( (a ==
'k') && (b ==
'm') ) chr =
'¬';
588 else if ( (a ==
'p') && (b ==
'h') ) chr =
'÷';
590 else if ( (a ==
'k') && (b ==
'g') ) chr =
'|';
592 else if ( (a ==
'l') && (b ==
'e') ) chr =
'\'';
594 else if ( (a ==
'k') && (b ==
'i') ) chr =
'¨';
596 else if ( (a ==
'k') && (b ==
'n') ) chr =
'';
598 else if ( (a ==
'k') && (b ==
'p') ) chr =
'¯';
600 else if ( (a ==
'l') && (b ==
'g') ) chr =
'¶';
602 else if ( (a ==
'l') && (b ==
'i') ) chr =
'¸';
604 else if ( (a ==
'm') && (b ==
'h') ) chr =
'Ç';
605 else if ( (a ==
'o') && (b ==
'h') ) chr =
'ç';
607 else if ( (a ==
'n') && (b ==
'h') ) chr =
'×';
609 else if ( (a ==
'k') && (b ==
'a') ) chr =
' ';
611 else if ( (a ==
'a') && (b ==
'j') ) chr =
'!';
629APPLIXWORDImport::readTagLine (TQTextStream &stream, TQFile &in)
631 TQString mystrn, mystr;
635 mystr = nextLine (stream);
638 mystr.stripWhiteSpace();
641 if ((mystr.length() == 80) && (mystr[mystr.length()-1] ==
'\\') )
650 mystrn = nextLine (stream);
653 if (mystrn[0] ==
' ')
656 mystrn.remove (0, 1);
659 mystr.remove (mystr.length()-1, 1);
689APPLIXWORDImport::replaceSpecial (TQString &textstr)
694 textstr.replace (
'&',
"&");
695 textstr.replace (
'<',
"<");
696 textstr.replace (
'>',
">");
705 pos = textstr.find (
'\"', pos);
708 if ((pos > -1) && (textstr[pos-1] ==
'\\'))
710 textstr.replace (pos-1, 2,
"\"");
722 int foundSpecialCharakter;
728 foundSpecialCharakter =
false;
730 pos = textstr.find (
"^");
736 foundSpecialCharakter =
true;
739 newchar = specCharfind (textstr[pos+1], textstr[pos+2]);
742 textstr.replace (pos, 3, newchar);
745 while (foundSpecialCharakter ==
true);
759APPLIXWORDImport::readHeader (TQTextStream &stream, TQFile &in)
763 int vers[3] = { 0, 0, 0 };
766 mystr = readTagLine (stream, in);
769 rueck = sscanf ((
const char *) mystr.latin1() ,
770 "*BEGIN WORDS VERSION=%d/%d ENCODING=%dBIT",
771 &vers[0], &vers[1], &vers[2]);
772 printf (
"Versions info: %d %d %d\n", vers[0], vers[1], vers[2]);
777 printf (
"Header not correkt - May be it is not an applixword file\n");
778 printf (
"Headerline: <%s>\n", (
const char *) mystr.latin1());
780 TQMessageBox::critical (0L,
"Applixword header problem",
781 TQString (
"The Applixword header is not correct. "
782 "May be it is not an applixword file! <BR>"
783 "This is the header line I did read:<BR><B>%1</B>").arg(mystr.latin1()),