00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #ifdef HAVE_UNISTD_H
00023 #include <unistd.h>
00024 #endif
00025
00026 #include <qmessagebox.h>
00027 #include <qstringlist.h>
00028 #include <qregexp.h>
00029 #include <qptrlist.h>
00030 #include <applixspreadimport.h>
00031 #include <kdebug.h>
00032 #include <math.h>
00033 #include <KoFilterChain.h>
00034 #include <kgenericfactory.h>
00035
00036 typedef KGenericFactory<APPLIXSPREADImport, KoFilter> APPLIXSPREADImportFactory;
00037 K_EXPORT_COMPONENT_FACTORY( libapplixspreadimport, APPLIXSPREADImportFactory( "kofficefilters" ) )
00038
00039
00040 APPLIXSPREADImport::APPLIXSPREADImport ( QObject *, const char* , const QStringList& )
00041 : KoFilter()
00042 {
00043 }
00044
00045 QString APPLIXSPREADImport::nextLine( QTextStream & stream )
00046 {
00047 QString s = stream.readLine();
00048 m_instep += s.length();
00049 if (m_instep > m_stepsize)
00050 {
00051 m_instep = 0;
00052 m_progress += 2;
00053 emit sigProgress( m_progress );
00054 }
00055 return s;
00056 }
00057
00058 KoFilter::ConversionStatus APPLIXSPREADImport::convert( const QCString& from, const QCString& to )
00059 {
00060
00061 if (to != "application/x-kspread" || from != "application/x-applixspread")
00062 return KoFilter::NotImplemented;
00063
00064 QFile in (m_chain->inputFile());
00065 if (!in.open(IO_ReadOnly))
00066 {
00067 kdError(30502) << "Unable to open input file!" << endl;
00068 in.close();
00069 return KoFilter::FileNotFound;
00070 }
00071
00072 QString str;
00073 QPtrList<t_mycolor> mcol;
00074
00075 str += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00076 str += "<!DOCTYPE spreadsheet>\n";
00077 str += "<spreadsheet mime=\"application/x-kspread\" editor=\"KSpread\" >\n";
00078 str += " <paper format=\"A4\" orientation=\"Portrait\" >\n";
00079 str += " <borders right=\"20\" left=\"20\" bottom=\"20\" top=\"20\" />\n";
00080 str += " <head/>\n";
00081 str += " <foot/>\n";
00082 str += " </paper>\n";
00083 str += " <locale positivePrefixCurrencySymbol=\"True\" negativeMonetarySignPosition=\"1\" negativePrefixCurrencySymbol=\"True\" fracDigits=\"2\" thousandsSeparator=\" \" dateFormat=\"%A, %e. %B %Y\" timeFormat=\"%H:%M:%S\" monetaryDecimalSymbol=\",\" weekStartsMonday=\"True\" currencySymbol=\"DM\" negativeSign=\"-\" positiveSign=\"\" positiveMonetarySignPosition=\"1\" decimalSymbol=\",\" monetaryThousandsSeparator=\" \" dateFormatShort=\"%d.%m.%Y\" />\n";
00084 str += " <map markerColumn=\"1\" activeTable=\"Table1\" markerRow=\"1\" >\n";
00085
00086
00087
00088
00089 QTextStream stream (&in);
00090 m_stepsize = in.size()/50;
00091 m_instep = 0;
00092 m_progress = 0;
00093 int pos;
00094 char ccol;
00095 int irow, icol;
00096 QString tabctr ;
00097 QString mystr, typestr, cellnostr, tabnostr;
00098 QStringList typefacetab;
00099
00100
00101 t_rc my_rc;
00102
00103
00104
00105
00106
00107
00108 if (! readHeader (stream)) return KoFilter::StupidError;
00109
00110
00111 while (!stream.atEnd ())
00112 {
00113
00114 mystr = nextLine( stream );
00115
00116 kdDebug()<<"INPUT : "<<mystr<<endl;
00117
00118
00119
00120
00121
00122 if (mystr.startsWith ("COLORMAP") )
00123 {
00124 readColormap (stream, mcol);
00125 }
00126
00127
00128
00129
00130 else if (mystr.startsWith ("TYPEFACE TABLE") )
00131 {
00132 readTypefaceTable (stream, typefacetab);
00133 }
00134
00135
00136
00137
00138 else if (mystr.startsWith ("View Start, Name:") )
00139 {
00140 readView (stream, mystr, my_rc);
00141 }
00142
00143
00144
00145
00146
00147 else if (mystr[0] == '(')
00148 {
00149 int fg=-1;
00150
00151
00152 mystr.remove (0, 1);
00153
00154 int alllenght;
00155 QString mystrn;
00156
00157
00158 alllenght = mystr.length ();
00159 if (alllenght >= 80-1)
00160 {
00161 kdDebug()<< " Line >= 80 chars \n";
00162 int ok = true;
00163 do
00164 {
00165 pos = in.at ();
00166 mystrn = nextLine( stream );
00167 if (mystrn[0] == ' ')
00168 {
00169 mystrn.remove (0, 1);
00170 mystr += mystrn;
00171 }
00172 else
00173 {
00174 in.at (pos);
00175 ok = false;
00176 }
00177 }
00178 while (ok == true);
00179
00180 }
00181
00182
00183
00184 pos = mystr.find (')');
00185 typestr = mystr.left (pos);
00186
00187
00188
00189 mystr.remove (0, pos+1);
00190
00191
00192
00193 pos = mystr.find (':');
00194
00195
00196 cellnostr = mystr.left (pos);
00197
00198
00199 mystr.remove (0, pos+1);
00200
00201
00202
00203
00204 pos = cellnostr.find ('!');
00205
00206
00207 tabnostr = cellnostr.left (pos);
00208
00209
00210 cellnostr.remove (0, pos+1);
00211
00212 int len = cellnostr.length ();
00213 char tmp[300], tmp1[300];
00214 int leni;
00215
00216
00217
00218 pos = cellnostr.find (QRegExp ("[0-9]"));
00219 kdDebug()<<" findpos :"<<pos<<endl;
00220
00221
00222
00223 QString rowstr;
00224 bool ok;
00225 int bla;
00226 rowstr = cellnostr.mid (pos, cellnostr.length()-pos);
00227 irow = rowstr.toInt(&ok);
00228
00229 kdDebug()<<" findpos :"<< rowstr<<" "<<irow<<endl;
00230 sscanf (cellnostr.latin1(), "%299s%d",tmp, &bla);
00231 sprintf (tmp1, "%d", irow);
00232 leni = strlen (tmp1);
00233 QString cellcolstr;
00234 cellcolstr = cellnostr;
00235 cellcolstr.remove (cellcolstr.length()-leni, leni);
00236
00237 kdDebug()<<" Info: length :"<<len<<" cellnostr :"<<cellnostr<<" tmp :"<<tmp<<" irow :"<<irow<<" cellcolstr :"<<cellcolstr<<endl;
00238
00239
00240 icol = translateColumnNumber (cellcolstr);
00241
00242
00243
00244
00245
00246
00247
00248
00249 mystr.remove (0, 1);
00250 tabnostr.remove (0, 1);
00251
00252
00253
00254 mystr.replace (QRegExp ("&"), "&");
00255 mystr.replace (QRegExp ("<"), "<");
00256 mystr.replace (QRegExp (">"), ">");
00257
00258
00259
00260 int foundSpecialCharakter;
00261 QChar newchar;
00262
00263 do
00264 {
00265
00266 foundSpecialCharakter = false;
00267
00268 pos = mystr.find ("^");
00269
00270
00271 if (pos > -1 )
00272 {
00273
00274 foundSpecialCharakter = true;
00275
00276
00277 newchar = specCharfind (mystr[pos+1], mystr[pos+2]);
00278
00279
00280 mystr.replace (pos, 3, newchar);
00281 }
00282
00283 }
00284 while (foundSpecialCharakter == true);
00285
00286
00287
00288
00289 QString typeFormStr;
00290 QString typeCharStr;
00291 QString typeCellStr;
00292
00293 int pos1 = typestr.find ("|");
00294 int pos2 = typestr.findRev ("|");
00295
00296
00297 typeFormStr = typestr.left (pos1);
00298
00299 typeCharStr = typestr.mid (pos1+1, pos2 - pos1 - 1);
00300
00301 typeCellStr = typestr.right (typestr.length() - pos2 - 1);
00302
00303
00304 if (tabctr != tabnostr)
00305 {
00306
00307 if (!(tabctr.isNull())) str += " </table>\n";
00308
00309 str += " <table columnnumber=\"0\" borders=\"0\" hide=\"0\" hidezero=\"0\" firstletterupper=\"0\" grid=\"1\" formular=\"0\" lcmode=\"0\" name=\"";
00310 str += tabnostr;
00311 str += "\" >\n";
00312
00313 tabctr = tabnostr;
00314
00315
00316 pos = my_rc.tabname.findIndex (tabnostr);
00317 if (pos > -1) str += my_rc.rc[pos];
00318 }
00319
00320 kdDebug()<<" Data : Text :"<<mystr<<" tab :"<<tabnostr<<" "<< cellnostr <<" " <<ccol<<" " << irow<<" "<< typeFormStr<<" " <<typeCharStr<<" " <<typeCellStr<<endl;
00321
00322
00323
00324
00325
00326 QStringList typeCharList;
00327 int bold=0, italic=0, underline=0, nn=0, fontsize=12, fontnr=-1;
00328
00329 typeCharList = QStringList::split (',', typeCharStr);
00330
00331 for (QStringList::Iterator it = typeCharList.begin();
00332 it != typeCharList.end(); ++it )
00333 {
00334
00335 kdDebug()<<" Char ("<<nn<<" ) >"<<*it<<"< "<<endl;
00336 nn++;
00337
00338 if ((*it) == "B")
00339 {
00340 kdDebug()<<" bold\n";
00341 bold = 1;
00342 }
00343 else if ((*it) == "I")
00344 {
00345
00346 kdDebug()<<" = italic\n";
00347 italic = 1;
00348 }
00349 else if ((*it) == "U")
00350 {
00351 kdDebug()<<" = underline\n";
00352 underline = 1;
00353 }
00354 else if ((*it).startsWith("FG") )
00355 {
00356 sscanf ((*it).latin1(), "FG%d", &fg);
00357 kdDebug()<<" = Colornr "<< fg<<endl;
00358 }
00359 else if ((*it).startsWith("TF") )
00360 {
00361 sscanf ((*it).latin1(), "TF%d", &fontnr);
00362 kdDebug()<<" = Font :"<<fontnr<<" "<<typefacetab[fontnr]<<endl;
00363 }
00364 else if ((*it).startsWith("P") )
00365 {
00366 sscanf ((*it).latin1(), "P%d", &fontsize);
00367 kdDebug()<<" = Fontsize "<<fontsize<<endl;
00368 }
00369 else
00370 {
00371
00372 kdDebug()<<" = ???\n";
00373 }
00374 }
00375 kdDebug()<<""<<endl;
00376
00377
00378
00379
00380
00381
00382 QStringList typeFormList;
00383 int align = 0, valign=0;
00384
00385 typeFormList = QStringList::split (',', typeFormStr);
00386 nn=0;
00387 for (QStringList::Iterator it = typeFormList.begin(); it != typeFormList.end(); ++it )
00388 {
00389
00390
00391
00392 nn++;
00393
00394 if ( (*it) == "1")
00395 {
00396 kdDebug()<< " = left align\n";
00397 align = 1;
00398 }
00399 else if ( (*it) == "2")
00400 {
00401 kdDebug()<< " = right align\n";
00402 align = 3;
00403 }
00404 else if ( (*it) == "3")
00405 {
00406 kdDebug()<< " = center align\n";
00407 align = 2;
00408 }
00409
00410
00411 else if ( (*it) == "VT")
00412 {
00413 kdDebug()<<" = top valign\n";
00414 valign = 1;
00415 }
00416 else if ( (*it) == "VC")
00417 {
00418 kdDebug()<<" = center valign\n";
00419 valign = 0;
00420 }
00421 else if ( (*it) == "VB")
00422 {
00423 kdDebug()<<" = bottom valign\n";
00424 valign = 3;
00425 }
00426 else
00427 {
00428 kdDebug()<<" = ???\n";
00429 }
00430 }
00431
00432
00433
00434
00435
00436 QStringList typeCellList;
00437 int topPenWidth=0, bottomPenWidth=0, leftPenWidth = 0, rightPenWidth = 0, fg_bg=-1;
00438 int topPenStyle=0, bottomPenStyle=0, leftPenStyle = 0, rightPenStyle = 0;
00439 int brushstyle=0, brushcolor=1;
00440 int topbrushstyle=0, topbrushcolor=1, topfg_bg=1;
00441 int leftbrushstyle=0, leftbrushcolor=1, leftfg_bg=1;
00442 int rightbrushstyle=0, rightbrushcolor=1, rightfg_bg=1;
00443 int bottombrushstyle=0, bottombrushcolor=1, bottomfg_bg=1;
00444
00445 typeCellList = QStringList::split (',', typeCellStr);
00446 nn=0;
00447 for ( QStringList::Iterator it = typeCellList.begin(); it != typeCellList.end(); ++it )
00448 {
00449
00450 printf (" Cell (%2d) >%s< ",
00451 nn, (*it).latin1() );
00452 nn++;
00453
00454 if ((*it)[0] == 'T')
00455 {
00456 kdDebug()<<" = top \n";
00457 transPenFormat ((*it), &topPenWidth, &topPenStyle);
00458
00459 if ((*it).length() > 2)
00460 {
00461 (*it).remove (0, 2);
00462 filterSHFGBG ((*it), &topbrushstyle, &topbrushcolor, &topfg_bg);
00463 }
00464
00465 }
00466
00467 else if ( (*it)[0] == 'B')
00468 {
00469 kdDebug()<<" = bottom \n";
00470 transPenFormat ((*it), &bottomPenWidth, &bottomPenStyle);
00471
00472 if ((*it).length() > 2)
00473 {
00474 (*it).remove (0, 2);
00475 filterSHFGBG ((*it), &bottombrushstyle, &bottombrushcolor, &bottomfg_bg);
00476 }
00477 }
00478
00479 else if ( (*it)[0] == 'L')
00480 {
00481 kdDebug()<<" = left \n";
00482 transPenFormat ((*it), &leftPenWidth, &leftPenStyle);
00483
00484 if ((*it).length() > 2)
00485 {
00486 (*it).remove (0, 2);
00487 filterSHFGBG ((*it), &leftbrushstyle, &leftbrushcolor, &leftfg_bg);
00488 }
00489 }
00490
00491 else if ( (*it)[0] == 'R')
00492 {
00493 kdDebug()<<" = right \n";
00494 transPenFormat ((*it), &rightPenWidth, &rightPenStyle);
00495
00496 if ((*it).length() > 2)
00497 {
00498 (*it).remove (0, 2);
00499 filterSHFGBG ((*it), &rightbrushstyle, &rightbrushcolor, &rightfg_bg);
00500 }
00501 }
00502
00503 else if ( ((*it).startsWith ("SH")) || ((*it).startsWith ("FG")) ||
00504 ((*it).startsWith ("BG")) )
00505 {
00506 kdDebug()<<" = \n";
00507 filterSHFGBG ((*it), &brushstyle, &fg_bg, &brushcolor);
00508 }
00509
00510 else
00511 {
00512 kdDebug()<<" = ???\n";
00513 }
00514
00515 }
00516
00517
00518
00519
00520
00521 QString col;
00522
00523
00524 str += " <cell row=\"" + QString::number (irow) + "\"";
00525 str += " column=\"" + QString::number (icol) + "\">\n";
00526 if (bold == 1 || italic == 1 || underline == 1 ||
00527 align != 0 || valign != 0 ||
00528 topPenStyle != 0 || bottomPenStyle != 0 ||
00529 leftPenStyle != 0 || rightPenStyle != 0 || fg !=-1 || fg_bg != -1 ||
00530 fontsize != 12 || brushstyle != 0 || fontnr != -1)
00531 {
00532 str += " <format";
00533 if (brushstyle != 0)
00534 {
00535 str += " brushstyle=\"" + QString::number(brushstyle) + "\" ";
00536 str += " brushcolor=\"";
00537 str += writeColor (mcol.at(brushcolor));
00538 str += "\"";
00539 }
00540
00541 if (align != 0) str += " align=\"" + QString::number(align) + "\" ";
00542 if (valign != 0) str += " alignY=\"" + QString::number(valign) + "\" ";
00543 if (fg_bg != -1)
00544 {
00545 str += " bgcolor=\"";
00546 str += writeColor (mcol.at(fg_bg));
00547 str += "\" ";
00548 }
00549 str += ">\n";
00550
00551
00552 if (fg != -1)
00553 {
00554 str += " <pen width=\"0\" style=\"1\" color=\"";
00555 str += writeColor (mcol.at(fg));
00556 str += "\" />\n";
00557 }
00558
00559
00560 if (leftPenWidth > 0)
00561 {
00562 str += " <left-border>\n";
00563 col = writeColor (mcol.at(leftfg_bg));
00564 writePen (str, leftPenWidth, leftPenStyle, col);
00565 str += " </left-border>\n";
00566 }
00567
00568
00569 if (rightPenWidth > 0)
00570 {
00571 str += " <right-border>\n";
00572 col = writeColor (mcol.at(rightfg_bg));
00573 writePen (str, rightPenWidth, rightPenStyle, col);
00574 str += " </right-border>\n";
00575 }
00576
00577
00578 if (bottomPenWidth > 0)
00579 {
00580 str += " <bottom-border>\n";
00581 col = writeColor (mcol.at(bottomfg_bg));
00582 writePen (str, bottomPenWidth, bottomPenStyle, col);
00583 str += " </bottom-border>\n";
00584 }
00585
00586
00587 if (topPenWidth > 0)
00588 {
00589 str += " <top-border>\n";
00590 col = writeColor (mcol.at(topfg_bg));
00591 writePen (str, topPenWidth, topPenStyle, col);
00592 str += " </top-border>\n";
00593 }
00594
00595
00596 if ((fontsize != 12) || (fontnr != -1))
00597 {
00598 str += " <font ";
00599
00600 if (fontsize != 12)
00601 {
00602 str += "size=\"";
00603 str += QString::number (fontsize);
00604 str += "\" ";
00605 }
00606
00607 if (fontnr != -1)
00608 {
00609 str += "family=\"";
00610 str += typefacetab[fontnr].latin1();
00611 str += "\" ";
00612 }
00613 str += "weight=\"0\"";
00614
00615 if (italic == 1) str += " italic=\"yes\"";
00616 if (bold == 1) str += " bold=\"yes\"";
00617 if (underline == 1) str += " underline=\"yes\"";
00618
00619 str +=" />\n";
00620 }
00621 str += " </format>\n";
00622 }
00623 str += " <text>" + mystr + "</text>\n";
00624 str += " </cell>\n";
00625 }
00626
00627 }
00628 emit sigProgress(100);
00629
00630 str += " </table>\n";
00631 str += " </map>\n";
00632 str += "</spreadsheet>\n";
00633
00634
00635 kdDebug ()<<"Text "<< str<<endl;
00636
00637 KoStoreDevice* out=m_chain->storageFile( "root", KoStore::Write );
00638
00639 if (!out)
00640 {
00641 kdError(38000) << "Unable to open output file!" << endl;
00642 in.close ();
00643 return KoFilter::StorageCreationError;
00644 }
00645
00646 QCString cstring = str.utf8();
00647 out->writeBlock ( cstring, cstring.length() );
00648
00649 in.close ();
00650 return KoFilter::OK;
00651 }
00652
00653
00654
00655
00656
00657
00658
00659 QChar
00660 APPLIXSPREADImport::specCharfind (QChar a, QChar b)
00661 {
00662 QChar chr;
00663
00664 if ( (a == 'n') && (b == 'p') ) chr = 'ß';
00665
00666
00667 else if ( (a == 'n') && (b == 'c') ) chr = 'Ò';
00668 else if ( (a == 'p') && (b == 'c') ) chr = 'ò';
00669
00670 else if ( (a == 'n') && (b == 'd') ) chr = 'Ó';
00671 else if ( (a == 'p') && (b == 'd') ) chr = 'ó';
00672
00673 else if ( (a == 'n') && (b == 'e') ) chr = 'Ô';
00674 else if ( (a == 'p') && (b == 'e') ) chr = 'ô';
00675
00676 else if ( (a == 'n') && (b == 'f') ) chr = 'Õ';
00677 else if ( (a == 'p') && (b == 'f') ) chr = 'õ';
00678
00679 else if ( (a == 'p') && (b == 'g') ) chr = 'ö';
00680 else if ( (a == 'n') && (b == 'g') ) chr = 'Ö';
00681
00682
00683
00684 else if ( (a == 'n') && (b == 'j') ) chr = 'Ù';
00685 else if ( (a == 'p') && (b == 'j') ) chr = 'ù';
00686
00687 else if ( (a == 'n') && (b == 'k') ) chr = 'Ú';
00688 else if ( (a == 'p') && (b == 'k') ) chr = 'ú';
00689
00690 else if ( (a == 'n') && (b == 'l') ) chr = 'Û';
00691 else if ( (a == 'p') && (b == 'l') ) chr = 'û';
00692
00693 else if ( (a == 'p') && (b == 'm') ) chr = 'ü';
00694 else if ( (a == 'n') && (b == 'm') ) chr = 'Ü';
00695
00696
00697
00698 else if ( (a == 'm') && (b == 'a') ) chr = 'À';
00699 else if ( (a == 'o') && (b == 'a') ) chr = 'à';
00700
00701 else if ( (a == 'm') && (b == 'b') ) chr = 'Á';
00702 else if ( (a == 'o') && (b == 'b') ) chr = 'á';
00703
00704 else if ( (a == 'm') && (b == 'c') ) chr = 'Â';
00705 else if ( (a == 'o') && (b == 'c') ) chr = 'â';
00706
00707 else if ( (a == 'm') && (b == 'd') ) chr = 'Ã';
00708 else if ( (a == 'o') && (b == 'd') ) chr = 'ã';
00709
00710 else if ( (a == 'm') && (b == 'e') ) chr = 'Ä';
00711 else if ( (a == 'o') && (b == 'e') ) chr = 'ä';
00712
00713 else if ( (a == 'm') && (b == 'f') ) chr = 'Å';
00714 else if ( (a == 'o') && (b == 'f') ) chr = 'å';
00715
00716 else if ( (a == 'm') && (b == 'g') ) chr = 'Æ';
00717 else if ( (a == 'o') && (b == 'g') ) chr = 'æ';
00718
00719
00720
00721 else if ( (a == 'm') && (b == 'i') ) chr = 'È';
00722 else if ( (a == 'o') && (b == 'i') ) chr = 'è';
00723
00724 else if ( (a == 'm') && (b == 'j') ) chr = 'É';
00725 else if ( (a == 'o') && (b == 'j') ) chr = 'é';
00726
00727 else if ( (a == 'm') && (b == 'k') ) chr = 'Ê';
00728 else if ( (a == 'o') && (b == 'k') ) chr = 'ê';
00729
00730 else if ( (a == 'm') && (b == 'l') ) chr = 'Ë';
00731 else if ( (a == 'o') && (b == 'l') ) chr = 'ë';
00732
00733
00734
00735
00736
00737
00738 else if ( (a == 'm') && (b == 'm') ) chr = 'Ì';
00739 else if ( (a == 'o') && (b == 'm') ) chr = 'ì';
00740
00741 else if ( (a == 'm') && (b == 'n') ) chr = 'Í';
00742 else if ( (a == 'o') && (b == 'n') ) chr = 'í';
00743
00744 else if ( (a == 'm') && (b == 'o') ) chr = 'Î';
00745 else if ( (a == 'o') && (b == 'o') ) chr = 'î';
00746
00747 else if ( (a == 'm') && (b == 'p') ) chr = 'Ï';
00748 else if ( (a == 'o') && (b == 'p') ) chr = 'ï';
00749
00750
00751 else if ( (a == 'n') && (b == 'b') ) chr = 'Ñ';
00752 else if ( (a == 'p') && (b == 'b') ) chr = 'ñ';
00753
00754
00755 else if ( (a == 'k') && (b == 'c') ) chr = '¢';
00756 else if ( (a == 'k') && (b == 'j') ) chr = '©';
00757 else if ( (a == 'l') && (b == 'f') ) chr = 'µ';
00758 else if ( (a == 'n') && (b == 'i') ) chr = 'Ø';
00759 else if ( (a == 'p') && (b == 'i') ) chr = 'ø';
00760
00761 else if ( (a == 'l') && (b == 'j') ) chr = '¹';
00762 else if ( (a == 'l') && (b == 'c') ) chr = '²';
00763 else if ( (a == 'l') && (b == 'd') ) chr = '³';
00764
00765 else if ( (a == 'l') && (b == 'm') ) chr = '¼';
00766 else if ( (a == 'l') && (b == 'n') ) chr = '½';
00767 else if ( (a == 'l') && (b == 'o') ) chr = '¾';
00768
00769 else if ( (a == 'l') && (b == 'a') ) chr = '°';
00770
00771 else if ( (a == 'k') && (b == 'o') ) chr = '®';
00772 else if ( (a == 'k') && (b == 'h') ) chr = '§';
00773 else if ( (a == 'k') && (b == 'd') ) chr = '£';
00774
00775 else if ( (a == 'p') && (b == 'a') ) chr = 'ð';
00776 else if ( (a == 'n') && (b == 'a') ) chr = 'Ð';
00777
00778 else if ( (a == 'l') && (b == 'l') ) chr = '»';
00779 else if ( (a == 'k') && (b == 'l') ) chr = '«';
00780
00781 else if ( (a == 'l') && (b == 'k') ) chr = 'º';
00782
00783 else if ( (a == 'l') && (b == 'h') ) chr = '·';
00784
00785 else if ( (a == 'k') && (b == 'b') ) chr = '¡';
00786
00787 else if ( (a == 'k') && (b == 'e') ) chr = '¤';
00788
00789 else if ( (a == 'l') && (b == 'b') ) chr = '±';
00790
00791 else if ( (a == 'l') && (b == 'p') ) chr = '¿';
00792
00793 else if ( (a == 'k') && (b == 'f') ) chr = '¥';
00794
00795 else if ( (a == 'p') && (b == 'o') ) chr = 'þ';
00796 else if ( (a == 'n') && (b == 'o') ) chr = 'Þ';
00797
00798 else if ( (a == 'n') && (b == 'n') ) chr = 'Ý';
00799 else if ( (a == 'p') && (b == 'n') ) chr = 'ý';
00800 else if ( (a == 'p') && (b == 'p') ) chr = 'ÿ';
00801
00802 else if ( (a == 'k') && (b == 'k') ) chr = 'ª';
00803
00804 else if ( (a == 'k') && (b == 'm') ) chr = '¬';
00805 else if ( (a == 'p') && (b == 'h') ) chr = '÷';
00806
00807 else if ( (a == 'k') && (b == 'g') ) chr = '|';
00808
00809 else if ( (a == 'l') && (b == 'e') ) chr = '\'';
00810
00811 else if ( (a == 'k') && (b == 'i') ) chr = '¨';
00812
00813 else if ( (a == 'k') && (b == 'n') ) chr = '';
00814
00815 else if ( (a == 'k') && (b == 'p') ) chr = '¯';
00816
00817 else if ( (a == 'l') && (b == 'g') ) chr = '¶';
00818
00819 else if ( (a == 'l') && (b == 'i') ) chr = '¸';
00820
00821 else if ( (a == 'm') && (b == 'h') ) chr = 'Ç';
00822 else if ( (a == 'o') && (b == 'h') ) chr = 'ç';
00823
00824 else if ( (a == 'n') && (b == 'h') ) chr = '×';
00825
00826 else if ( (a == 'k') && (b == 'a') ) chr = ' ';
00827
00828 else if ( (a == 'a') && (b == 'j') ) chr = '!';
00829
00830 else chr = '#';
00831
00832 return chr;
00833 }
00834
00835
00836
00837
00838
00839
00840 void
00841 APPLIXSPREADImport::writePen (QString &str, int penwidth, int penstyle, QString framecolor)
00842 {
00843 str += " <pen width=\"";
00844
00845
00846 str += QString::number (penwidth);
00847 str += "\" style=\"";
00848
00849
00850 str += QString::number (penstyle);
00851 str += "\" color=\"";
00852
00853
00854 str += framecolor;
00855 str += "\" />\n";
00856
00857 }
00858
00859
00860
00861
00862
00863
00864 QString
00865 APPLIXSPREADImport::writeColor (t_mycolor *mc)
00866 {
00867 char rgb[20];
00868
00869
00870
00871
00872
00873 sprintf (rgb, "#%02X%02X%02X", mc->r, mc->g, mc->b);
00874 QString bla = rgb;
00875
00876
00877 return bla;
00878 }
00879
00880
00881
00882
00883
00884
00885
00886 void
00887 APPLIXSPREADImport::readTypefaceTable (QTextStream &stream, QStringList &typefacetab)
00888 {
00889 int tftabCounter=0, ok;
00890 QString mystr;
00891
00892
00893 kdDebug()<<"Reading typeface table: \n";
00894
00895 ok = true;
00896 do
00897 {
00898 mystr = nextLine( stream );
00899 if (mystr == "END TYPEFACE TABLE" ) ok = false;
00900 else
00901 {
00902
00903 typefacetab.append(mystr);
00904 tftabCounter++;
00905 }
00906 }
00907 while (ok == true );
00908
00909 kdDebug()<<"... done \n";
00910 }
00911
00912
00913
00914
00915
00916
00917 void
00918 APPLIXSPREADImport::readColormap (QTextStream &stream, QPtrList<t_mycolor> &mcol)
00919 {
00920 int contcount, ok, pos;
00921
00922 QString colstr, mystr;
00923 kdDebug ()<<"Reading colormap: \n";
00924
00925 ok = true;
00926
00927 do
00928 {
00929
00930 mystr = nextLine( stream );
00931 mystr.stripWhiteSpace ();
00932
00933 if (mystr == "END COLORMAP") ok = false;
00934 else
00935 {
00936 kdDebug()<<" -> "<< mystr<<endl;
00937
00938
00939 contcount = mystr.contains (' ');
00940 kdDebug()<< "contcount: "<< contcount<<endl;
00941 contcount -= 5;
00942
00943
00944 pos = mystr.find (" 0 ");
00945
00946
00947 colstr = mystr.left (pos);
00948 mystr.remove (0, pos+1);
00949 mystr.stripWhiteSpace ();
00950
00951 t_mycolor *tmc = new t_mycolor;
00952
00953
00954 pos = sscanf (mystr.latin1(), "0 %d %d %d %d 0",
00955 &tmc->c, &tmc->m, &tmc->y, &tmc->k);
00956
00957 printf (" - <%-20s> <%-15s> <%3d> <%3d> <%3d> <%3d> pos: %d\n",
00958 mystr.latin1(),
00959 colstr.latin1(),
00960 tmc->c, tmc->m, tmc->y, tmc->k, pos);
00961
00962
00963 tmc->r = 255 - (tmc->c + tmc->k);
00964 if (tmc->r < 0) tmc->r = 0;
00965
00966 tmc->g = 255 - (tmc->m + tmc->k);
00967 if (tmc->g < 0) tmc->g = 0;
00968
00969 tmc->b = 255 - (tmc->y + tmc->k);
00970 if (tmc->b < 0) tmc->b = 0;
00971
00972 mcol.append (tmc);
00973 }
00974
00975 }
00976 while (ok == true );
00977
00978 kdDebug()<< "... done "<< mcol.count()<<endl;
00979
00980
00981 t_mycolor *emp;
00982 for (emp=mcol.first(); emp != 0; emp=mcol.next() )
00983 {
00984 printf (" c:%3d m:%3d y:%3d k:%3d r:%3d g:%3d b:%3d\n",
00985 emp->c, emp->m, emp->y, emp->k, emp->r, emp->g, emp->b);
00986 }
00987 }
00988
00989
00990
00991
00992
00993
00994
00995 void
00996 APPLIXSPREADImport::readView (QTextStream &stream, QString instr, t_rc &rc)
00997 {
00998 QString rowcolstr;
00999 QString mystr, tabname;
01000 int ok;
01001
01002 kdDebug()<<"Reading View\n";
01003
01004 tabname = instr;
01005
01006 tabname.remove (0, 19);
01007 tabname.remove (tabname.length()-2, 2);
01008 kdDebug()<< " - Table name: "<< tabname<<endl;
01009
01010 ok = true;
01011 do
01012 {
01013 mystr = nextLine( stream );
01014
01015 kdDebug()<<" "<< mystr<<endl;
01016 if (mystr.startsWith ("View End, Name:")) ok = false;
01017 else
01018 {
01019
01020 if (mystr.startsWith ("View Column Widths"))
01021 {
01022 kdDebug()<< " - Column Widths\n";
01023 mystr.remove (0, 20);
01024 kdDebug()<< " "<<mystr<<endl;
01025
01026 int colwidth, icolumn;
01027 char ccolumn;
01028
01029
01030 QStringList ColumnList;
01031 ColumnList = QStringList::split (' ', mystr);
01032
01033 for ( QStringList::Iterator it = ColumnList.begin(); it != ColumnList.end(); ++it )
01034 {
01035
01036 sscanf ((*it).latin1(), "%c:%d", &ccolumn, &colwidth);
01037 int len = (*it).length ();
01038 int pos = (*it).find (":");
01039 (*it).remove (pos, len-pos);
01040
01041 printf( " >%s<- -<%c><%d> \n", (*it).latin1(), ccolumn, colwidth);
01042
01043
01044 icolumn = translateColumnNumber (*it);
01045
01046
01047
01048 icolumn = icolumn * 5;
01049
01050
01051 rowcolstr += " <column width=\"";
01052 rowcolstr += QString::number (colwidth);
01053 rowcolstr += "\" column=\"";
01054 rowcolstr += QString::number (icolumn);
01055 rowcolstr += "\" >\n";
01056 rowcolstr += " <format/>\n";
01057 rowcolstr += " </column>\n";
01058 }
01059 }
01060
01061
01062 else if (mystr.startsWith ("View Row Heights"))
01063 {
01064 kdDebug()<< " - Row Heights\n";
01065 mystr.remove (0, 17);
01066 kdDebug()<<" "<< mystr<<endl;
01067
01068 int irow, rowheight;
01069
01070
01071 QStringList RowList;
01072 RowList = QStringList::split (' ', mystr);
01073
01074 for ( QStringList::Iterator it = RowList.begin(); it != RowList.end(); ++it )
01075 {
01076 sscanf ((*it).latin1(), " %d:%d",
01077 &irow, &rowheight);
01078 printf (" row: %2d height: %2d\n", irow, rowheight);
01079 if (rowheight > 32768) rowheight -= 32768;
01080 printf (" height: %2d\n", rowheight);
01081 rowcolstr += " <row row=\"";
01082 rowcolstr += QString::number (irow);
01083 rowcolstr += "\" height=\"";
01084 rowcolstr += QString::number (rowheight);
01085 rowcolstr += "\" >\n";
01086 rowcolstr += " <format/>\n";
01087 rowcolstr += " </row>\n";
01088 }
01089
01090
01091 }
01092 }
01093 }
01094 while (ok == true );
01095
01096
01097
01098 rc.tabname.append (tabname);
01099 rc.rc.append (rowcolstr);
01100
01101 printf ("%s %s\n", tabname.latin1(),
01102 rowcolstr.latin1());
01103
01104 printf ("...done \n\n");
01105 }
01106
01107
01108
01109
01110
01111
01112
01113
01114 void
01115 APPLIXSPREADImport::filterSHFGBG (QString it, int *style, int *bgcolor,
01116 int *fgcolor)
01117 {
01118 QString tmpstr;
01119 int pos;
01120 int m2=0, m3=0;
01121
01122
01123 pos = it.find ("SH");
01124 if (pos > -1)
01125 {
01126 tmpstr = it;
01127 if (pos > 0) tmpstr.remove(0, pos);
01128 pos = sscanf (tmpstr.latin1(), "SH%d",
01129 style);
01130
01131 printf ("style: %d(%d) ",
01132 *style, pos);
01133 }
01134
01135
01136
01137 pos = it.find ("FG");
01138 if (pos > -1)
01139 {
01140 tmpstr = it;
01141 if (pos > 0) tmpstr.remove(0, pos);
01142 pos = sscanf (tmpstr.latin1(), "FG%d",
01143 fgcolor);
01144 printf ("fg: %d(%d) ",
01145 *fgcolor, pos);
01146 m2=1;
01147 }
01148
01149
01150
01151 pos = it.find ("BG");
01152 if (pos > -1)
01153 {
01154 tmpstr = it;
01155 if (pos > 0) tmpstr.remove(0, pos);
01156 pos = sscanf (tmpstr.latin1(), "BG%d",
01157 bgcolor);
01158 printf ("bgcolor: %d(%d) ",
01159 *bgcolor, pos);
01160 m3=1;
01161 }
01162
01163
01164 printf ("\n");
01165
01166
01167
01168 if ((*style == 8) && (m2 == 1) && (m3 == 0))
01169 {
01170 *bgcolor = *fgcolor;
01171 }
01172
01173
01174
01175 if (*style != 0)
01176 {
01177 if (*style == 1) *style = 0;
01178 else if (*style == 2) *style = 7;
01179 else if (*style == 3) *style = 0;
01180 else if (*style == 4) *style = 4;
01181 else if (*style == 5) *style = 3;
01182 else if (*style == 6) *style = 2;
01183 else if (*style == 7) *style = 0;
01184 else if (*style == 8) *style = 0;
01185 else if (*style == 9) *style = 10;
01186 else if (*style == 10) *style = 9;
01187 else if (*style == 11) *style = 11;
01188 else if (*style == 12) *style = 12;
01189 else if (*style == 13) *style = 13;
01190 else if (*style == 14) *style = 14;
01191 else if (*style == 15) *style = 0;
01192 else if (*style == 16) *style = 0;
01193 else if (*style == 17) *style = 0;
01194 else if (*style == 18) *style = 0;
01195 else if (*style == 19) *style = 0;
01196 }
01197 }
01198
01199
01200
01201
01202
01203
01204 void
01205 APPLIXSPREADImport::transPenFormat (QString it, int *PenWidth, int *PenStyle)
01206 {
01207
01208 if ( it[1] == '1' )
01209 {
01210 *PenWidth = 1;
01211 *PenStyle = 1;
01212 }
01213
01214 else if ( it[1] == '2' )
01215 {
01216 *PenWidth = 2;
01217 *PenStyle = 1;
01218 }
01219
01220 else if ( it[1] == '3' )
01221 {
01222 *PenWidth = 3;
01223 *PenStyle = 1;
01224 }
01225
01226 else if ( it[1] == '4' )
01227 {
01228 *PenWidth = 1;
01229 *PenStyle = 3;
01230 }
01231
01232 else if ( it[1] == '5' )
01233 {
01234 *PenWidth = 5;
01235 *PenStyle = 1;
01236 }
01237
01238 printf ("frame (w:%d - s:%d) \n", *PenWidth, *PenStyle);
01239 }
01240
01241
01242
01243
01244
01245
01246
01247 int
01248 APPLIXSPREADImport::readHeader (QTextStream &stream)
01249 {
01250 QString mystr;
01251 int vers[3] = { 0, 0, 0 };
01252 int rueck;
01253
01254
01255
01256 mystr = nextLine (stream);
01257 rueck = sscanf (mystr.latin1(),
01258 "*BEGIN SPREADSHEETS VERSION=%d/%d ENCODING=%dBIT",
01259 &vers[0], &vers[1], &vers[2]);
01260 printf ("Versions info: %d %d %d\n", vers[0], vers[1], vers[2]);
01261
01262
01263 if (rueck <= 0)
01264 {
01265 printf ("Header not correkt - May be it is not an applixspreadsheet file\n");
01266 printf ("Headerline: <%s>\n", mystr.latin1());
01267
01268 QMessageBox::critical (0L, "Applix spreadsheet header problem",
01269 QString ("The Applix Spreadsheet header is not correct. "
01270 "May be it is not an applix spreadsheet file! <BR>"
01271 "This is the header line I did read:<BR><B>%1</B>").arg(mystr.latin1()),
01272 "Okay");
01273
01274
01275 return false;
01276 }
01277 else
01278 {
01279 return true;
01280 }
01281 }
01282
01283
01284
01285
01286
01287
01288 int
01289 APPLIXSPREADImport::translateColumnNumber (QString colstr)
01290 {
01291 int icol=0;
01292 int p, x, len;
01293
01294
01295 len = colstr.length ();
01296 p = len-1;
01297 x = 1;
01298
01299 printf ("HI 0 len:%d\n", len );
01300 while ((p >= 0))
01301 {
01302 printf ("HI 1 x:%d p:%d char:<%c>\n", x, p, colstr[p].latin1());
01303
01304 if ((colstr[p] >= 'A') && (colstr[p] <= 'Z'))
01305 {
01306 kdDebug ()<<" UPPER\n";
01307 icol = icol + ((int)pow ((double)x, 26) * (colstr[p].latin1() - 'A' + 1) );
01308 x++;
01309 }
01310
01311 else if ((colstr[p] >= 'a') && (colstr[p] <= 'z'))
01312 {
01313 kdDebug()<<" lower\n";
01314 icol = icol + ((int)pow ((double)x, 26) * (colstr[p].latin1() - 'a' + 1) );
01315 x++;
01316 }
01317 p--;
01318 kdDebug ()<< "HI 2\n";
01319
01320 }
01321
01322 printf ("translateColumnNumber : <%s> -> %d\n", colstr.latin1(), icol);
01323 return icol;
01324 }
01325
01326 #include <applixspreadimport.moc>