filters

applixspreadimport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Enno Bartels <ebartels@nwn.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <config.h>
21
22#ifdef HAVE_UNISTD_H
23#include <unistd.h>
24#endif
25
26#include <tqmessagebox.h>
27#include <tqstringlist.h>
28#include <tqregexp.h>
29#include <tqptrlist.h>
30#include <applixspreadimport.h>
31#include <kdebug.h>
32#include <math.h>
33#include <KoFilterChain.h>
34#include <kgenericfactory.h>
35
36typedef KGenericFactory<APPLIXSPREADImport, KoFilter> APPLIXSPREADImportFactory;
37K_EXPORT_COMPONENT_FACTORY( libapplixspreadimport, APPLIXSPREADImportFactory( "kofficefilters" ) )
38
39
40APPLIXSPREADImport::APPLIXSPREADImport ( TQObject */*parent*/, const char* /*name*/, const TQStringList& )
41 : KoFilter()
42{
43}
44
45TQString APPLIXSPREADImport::nextLine( TQTextStream & stream )
46{
47 TQString s = stream.readLine();
48 m_instep += s.length();
49 if (m_instep > m_stepsize)
50 {
51 m_instep = 0;
52 m_progress += 2;
53 emit sigProgress( m_progress );
54 }
55 return s;
56}
57
58KoFilter::ConversionStatus APPLIXSPREADImport::convert( const TQCString& from, const TQCString& to )
59{
60
61 if (to != "application/x-kspread" || from != "application/x-applixspread")
62 return KoFilter::NotImplemented;
63
64 TQFile in (m_chain->inputFile());
65 if (!in.open(IO_ReadOnly))
66 {
67 kdError(30502) << "Unable to open input file!" << endl;
68 in.close();
69 return KoFilter::FileNotFound;
70 }
71
72 TQString str;
73 TQPtrList<t_mycolor> mcol;
74
75 str += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
76 str += "<!DOCTYPE spreadsheet>\n";
77 str += "<spreadsheet mime=\"application/x-kspread\" editor=\"KSpread\" >\n";
78 str += " <paper format=\"A4\" orientation=\"Portrait\" >\n";
79 str += " <borders right=\"20\" left=\"20\" bottom=\"20\" top=\"20\" />\n";
80 str += " <head/>\n";
81 str += " <foot/>\n";
82 str += " </paper>\n";
83 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";
84 str += " <map markerColumn=\"1\" activeTable=\"Table1\" markerRow=\"1\" >\n";
85// str += " <table columnnumber=\"0\" borders=\"0\" hide=\"0\" hidezero=\"0\" firstletterupper=\"0\" grid=\"1\" formular=\"0\" lcmode=\"0\" name=\"Tabelle1\" >\n";
86
87
88 // TQTextStream
89 TQTextStream stream (&in);
90 m_stepsize = in.size()/50;
91 m_instep = 0;
92 m_progress = 0;
93 int pos;
94 char ccol;
95 int irow, icol;
96 TQString tabctr ; // Tab control
97 TQString mystr, typestr, cellnostr, tabnostr;
98 TQStringList typefacetab;
99
100 // TQStringList rclist;
101 t_rc my_rc;
102
103
104
105 /**************************************************************************
106 * Read header *
107 **************************************************************************/
108 if (! readHeader (stream)) return KoFilter::StupidError;
109
110
111 while (!stream.atEnd ())
112 {
113 // Read one line
114 mystr = nextLine( stream );
115
116 kdDebug()<<"INPUT : "<<mystr<<endl;
117
118
119 /**********************************************************************
120 * Looking for the colormap *
121 **********************************************************************/
122 if (mystr.startsWith ("COLORMAP") )
123 {
124 readColormap (stream, mcol);
125 }
126
127 /**********************************************************************
128 * Looking for the typeface table *
129 **********************************************************************/
130 else if (mystr.startsWith ("TYPEFACE TABLE") )
131 {
132 readTypefaceTable (stream, typefacetab);
133 }
134
135 /**********************************************************************
136 * Looking for some View-Informations *
137 **********************************************************************/
138 else if (mystr.startsWith ("View Start, Name:") )
139 {
140 readView (stream, mystr, my_rc);
141 }
142
143
144 /**********************************************************************
145 * Detect ( at the first place of the Linie *
146 **********************************************************************/
147 else if (mystr[0] == '(')
148 {
149 int fg=-1; // fg = foregound
150
151 // Delete '('
152 mystr.remove (0, 1);
153
154 int alllength;
155 TQString mystrn;
156
157 // Remember length of the string
158 alllength = mystr.length ();
159 if (alllength >= 80-1)
160 {
161 kdDebug()<< " Line >= 80 chars \n";
162 int ok = true;
163 do
164 {
165 pos = in.at ();
166 mystrn = nextLine( stream );
167 if (mystrn[0] == ' ')
168 {
169 mystrn.remove (0, 1);
170 mystr += mystrn;
171 }
172 else
173 {
174 in.at (pos);
175 ok = false;
176 }
177 }
178 while (ok == true);
179
180 }
181
182
183 // Search for ')'
184 pos = mystr.find (')');
185 typestr = mystr.left (pos);
186
187
188 // Delete typeformat infos incl. Space
189 mystr.remove (0, pos+1);
190 // alllength = alllength - pos - 1;
191
192 // Search for ':'
193 pos = mystr.find (':');
194
195 // Copy cellnumber informations
196 cellnostr = mystr.left (pos);
197
198 // Delete cellnumber informations
199 mystr.remove (0, pos+1);
200 // alllength = alllength - pos - 1;
201
202
203 // Split Table and Cell Number
204 pos = cellnostr.find ('!');
205
206 // Copy tabnumber informations
207 tabnostr = cellnostr.left (pos);
208
209 // Delete cellnumber informations
210 cellnostr.remove (0, pos+1);
211
212 int len = cellnostr.length ();
213 char tmp[300], tmp1[300];
214 int leni;
215
216
217
218 pos = cellnostr.find (TQRegExp ("[0-9]"));
219 kdDebug()<<" findpos :"<<pos<<endl;
220
221
222
223 TQString rowstr;
224 bool ok;
225 int bla;
226 rowstr = cellnostr.mid (pos, cellnostr.length()-pos);
227 irow = rowstr.toInt(&ok);
228
229 kdDebug()<<" findpos :"<< rowstr<<" "<<irow<<endl;
230 sscanf (cellnostr.latin1(), "%299s%d",tmp, &bla);
231 sprintf (tmp1, "%d", irow);
232 leni = strlen (tmp1);
233 TQString cellcolstr;
234 cellcolstr = cellnostr;
235 cellcolstr.remove (cellcolstr.length()-leni, leni);
236
237 kdDebug()<<" Info: length :"<<len<<" cellnostr :"<<cellnostr<<" tmp :"<<tmp<<" irow :"<<irow<<" cellcolstr :"<<cellcolstr<<endl;
238
239 // Transformat ascii column to int column
240 icol = translateColumnNumber (cellcolstr);
241
242
243 // sscanf (cellnostr.latin1(), "%c%d",&ccol, &irow);
244
245 // Transformat ascii column to int column
246 // icol = ccol - 64;
247
248 // Remove first whitespace
249 mystr.remove (0, 1);
250 tabnostr.remove (0, 1);
251
252
253 // Replace part for this characters: <, >, &
254 mystr.replace (TQRegExp ("&"), "&amp;");
255 mystr.replace (TQRegExp ("<"), "&lt;");
256 mystr.replace (TQRegExp (">"), "&gt;");
257
258
259 // Replace part for Applix Characters
260 int foundSpecialCharakter;
261 TQChar newchar;
262
263 do
264 {
265 // initialize
266 foundSpecialCharakter = false;
267
268 pos = mystr.find ("^");
269
270 // is there a special character ?
271 if (pos > -1 )
272 {
273 // i have found a special character !
274 foundSpecialCharakter = true;
275
276 // translate the applix special character
277 newchar = specCharfind (mystr[pos+1], mystr[pos+2]);
278
279 // replace the character
280 mystr.replace (pos, 3, newchar);
281 }
282
283 }
284 while (foundSpecialCharakter == true);
285
286
287 // examine the typestring
288 // splitt typestring in 3 parts by an |
289 TQString typeFormStr;
290 TQString typeCharStr;
291 TQString typeCellStr;
292
293 int pos1 = typestr.find ("|");
294 int pos2 = typestr.findRev ("|");
295
296
297 typeFormStr = typestr.left (pos1);
298
299 typeCharStr = typestr.mid (pos1+1, pos2 - pos1 - 1);
300
301 typeCellStr = typestr.right (typestr.length() - pos2 - 1);
302
303 // Is it a new table
304 if (tabctr != tabnostr)
305 {
306 // is it not the first table
307 if (!(tabctr.isNull())) str += " </table>\n";
308
309 str += " <table columnnumber=\"0\" borders=\"0\" hide=\"0\" hidezero=\"0\" firstletterupper=\"0\" grid=\"1\" formular=\"0\" lcmode=\"0\" name=\"";
310 str += tabnostr;
311 str += "\" >\n";
312
313 tabctr = tabnostr;
314
315 // Searching for the rowcol part and adding to the hole string
316 pos = my_rc.tabname.findIndex (tabnostr);
317 if (pos > -1) str += my_rc.rc[pos];
318 }
319
320 kdDebug()<<" Data : Text :"<<mystr<<" tab :"<<tabnostr<<" "<< cellnostr <<" " <<ccol<<" " << irow<<" "<< typeFormStr<<" " <<typeCharStr<<" " <<typeCellStr<<endl;
321
322
323 /********************************************************************
324 * examine charakter format String, splitt it up in basic parts *
325 ********************************************************************/
326 TQStringList typeCharList;
327 int bold=0, italic=0, underline=0, nn=0, fontsize=12, fontnr=-1;
328
329 typeCharList = TQStringList::split (',', typeCharStr);
330
331 for (TQStringList::Iterator it = typeCharList.begin();
332 it != typeCharList.end(); ++it )
333 {
334 // Output
335 kdDebug()<<" Char ("<<nn<<" ) >"<<*it<<"< "<<endl;
336 nn++;
337
338 if ((*it) == "B")
339 {
340 kdDebug()<<" bold\n";
341 bold = 1;
342 }
343 else if ((*it) == "I")
344 {
345
346 kdDebug()<<" = italic\n";
347 italic = 1;
348 }
349 else if ((*it) == "U")
350 {
351 kdDebug()<<" = underline\n";
352 underline = 1;
353 }
354 else if ((*it).startsWith("FG") )
355 {
356 sscanf ((*it).latin1(), "FG%d", &fg);
357 kdDebug()<<" = Colornr "<< fg<<endl;
358 }
359 else if ((*it).startsWith("TF") )
360 {
361 sscanf ((*it).latin1(), "TF%d", &fontnr);
362 kdDebug()<<" = Font :"<<fontnr<<" "<<typefacetab[fontnr]<<endl;
363 }
364 else if ((*it).startsWith("P") )
365 {
366 sscanf ((*it).latin1(), "P%d", &fontsize);
367 kdDebug()<<" = Fontsize "<<fontsize<<endl;
368 }
369 else
370 {
371
372 kdDebug()<<" = ???\n";
373 }
374 }
375 kdDebug()<<""<<endl;
376
377
378
379 /********************************************************************
380 * examine pos format String, splitt it up in basic parts *
381 ********************************************************************/
382 TQStringList typeFormList;
383 int align = 0, valign=0;
384
385 typeFormList = TQStringList::split (',', typeFormStr);
386 nn=0;
387 for (TQStringList::Iterator it = typeFormList.begin(); it != typeFormList.end(); ++it )
388 {
389 // Output
390 //kdDebug()<< " Type (%2d) >%s< ",
391 // nn, (*it).latin1() );
392 nn++;
393 // Grep horizontal alignment
394 if ( (*it) == "1")
395 {
396 kdDebug()<< " = left align\n";
397 align = 1; // left
398 }
399 else if ( (*it) == "2")
400 {
401 kdDebug()<< " = right align\n";
402 align = 3; // right
403 }
404 else if ( (*it) == "3")
405 {
406 kdDebug()<< " = center align\n";
407 align = 2; // center
408 }
409
410 // Grep verticale alignment
411 else if ( (*it) == "VT")
412 {
413 kdDebug()<<" = top valign\n";
414 valign = 1; // top
415 }
416 else if ( (*it) == "VC")
417 {
418 kdDebug()<<" = center valign\n";
419 valign = 0; // center - default (2)
420 }
421 else if ( (*it) == "VB")
422 {
423 kdDebug()<<" = bottom valign\n";
424 valign = 3; // bottom
425 }
426 else
427 {
428 kdDebug()<<" = ???\n";
429 }
430 }
431
432
433 /********************************************************************
434 * examine cell format String, splitt it up in basic parts *
435 ********************************************************************/
436 TQStringList typeCellList;
437 int topPenWidth=0, bottomPenWidth=0, leftPenWidth = 0, rightPenWidth = 0, fg_bg=-1;
438 int topPenStyle=0, bottomPenStyle=0, leftPenStyle = 0, rightPenStyle = 0;
439 int brushstyle=0, brushcolor=1;
440 int topbrushstyle=0, topbrushcolor=1, topfg_bg=1;
441 int leftbrushstyle=0, leftbrushcolor=1, leftfg_bg=1;
442 int rightbrushstyle=0, rightbrushcolor=1, rightfg_bg=1;
443 int bottombrushstyle=0, bottombrushcolor=1, bottomfg_bg=1;
444
445 typeCellList = TQStringList::split (',', typeCellStr);
446 nn=0;
447 for ( TQStringList::Iterator it = typeCellList.begin(); it != typeCellList.end(); ++it )
448 {
449 // Output
450 printf (" Cell (%2d) >%s< ",
451 nn, (*it).latin1() );
452 nn++;
453
454 if ((*it)[0] == 'T')
455 {
456 kdDebug()<<" = top \n";
457 transPenFormat ((*it), &topPenWidth, &topPenStyle);
458
459 if ((*it).length() > 2)
460 {
461 (*it).remove (0, 2);
462 filterSHFGBG ((*it), &topbrushstyle, &topbrushcolor, &topfg_bg);
463 }
464
465 }
466
467 else if ( (*it)[0] == 'B')
468 {
469 kdDebug()<<" = bottom \n";
470 transPenFormat ((*it), &bottomPenWidth, &bottomPenStyle);
471
472 if ((*it).length() > 2)
473 {
474 (*it).remove (0, 2);
475 filterSHFGBG ((*it), &bottombrushstyle, &bottombrushcolor, &bottomfg_bg);
476 }
477 }
478
479 else if ( (*it)[0] == 'L')
480 {
481 kdDebug()<<" = left \n";
482 transPenFormat ((*it), &leftPenWidth, &leftPenStyle);
483
484 if ((*it).length() > 2)
485 {
486 (*it).remove (0, 2);
487 filterSHFGBG ((*it), &leftbrushstyle, &leftbrushcolor, &leftfg_bg);
488 }
489 }
490
491 else if ( (*it)[0] == 'R')
492 {
493 kdDebug()<<" = right \n";
494 transPenFormat ((*it), &rightPenWidth, &rightPenStyle);
495
496 if ((*it).length() > 2)
497 {
498 (*it).remove (0, 2);
499 filterSHFGBG ((*it), &rightbrushstyle, &rightbrushcolor, &rightfg_bg);
500 }
501 }
502
503 else if ( ((*it).startsWith ("SH")) || ((*it).startsWith ("FG")) ||
504 ((*it).startsWith ("BG")) )
505 {
506 kdDebug()<<" = \n";
507 filterSHFGBG ((*it), &brushstyle, &fg_bg, &brushcolor);
508 }
509
510 else
511 {
512 kdDebug()<<" = ???\n";
513 }
514
515 }
516
517
518
519
520
521 TQString col;
522
523 // create kspread fileformat output
524 str += " <cell row=\"" + TQString::number (irow) + "\"";
525 str += " column=\"" + TQString::number (icol) + "\">\n";
526 if (bold == 1 || italic == 1 || underline == 1 ||
527 align != 0 || valign != 0 ||
528 topPenStyle != 0 || bottomPenStyle != 0 ||
529 leftPenStyle != 0 || rightPenStyle != 0 || fg !=-1 || fg_bg != -1 ||
530 fontsize != 12 || brushstyle != 0 || fontnr != -1)
531 {
532 str += " <format";
533 if (brushstyle != 0)
534 {
535 str += " brushstyle=\"" + TQString::number(brushstyle) + "\" ";
536 str += " brushcolor=\"";
537 str += writeColor (mcol.at(brushcolor));
538 str += "\"";
539 }
540
541 if (align != 0) str += " align=\"" + TQString::number(align) + "\" ";
542 if (valign != 0) str += " alignY=\"" + TQString::number(valign) + "\" ";
543 if (fg_bg != -1)
544 {
545 str += " bgcolor=\"";
546 str += writeColor (mcol.at(fg_bg));
547 str += "\" ";
548 }
549 str += ">\n";
550
551 // Font color
552 if (fg != -1)
553 {
554 str += " <pen width=\"0\" style=\"1\" color=\"";
555 str += writeColor (mcol.at(fg));
556 str += "\" />\n";
557 }
558
559 // Left border
560 if (leftPenWidth > 0)
561 {
562 str += " <left-border>\n";
563 col = writeColor (mcol.at(leftfg_bg));
564 writePen (str, leftPenWidth, leftPenStyle, col);
565 str += " </left-border>\n";
566 }
567
568 // Right border
569 if (rightPenWidth > 0)
570 {
571 str += " <right-border>\n";
572 col = writeColor (mcol.at(rightfg_bg));
573 writePen (str, rightPenWidth, rightPenStyle, col);
574 str += " </right-border>\n";
575 }
576
577 // Bottom border
578 if (bottomPenWidth > 0)
579 {
580 str += " <bottom-border>\n";
581 col = writeColor (mcol.at(bottomfg_bg));
582 writePen (str, bottomPenWidth, bottomPenStyle, col);
583 str += " </bottom-border>\n";
584 }
585
586 // Top border
587 if (topPenWidth > 0)
588 {
589 str += " <top-border>\n";
590 col = writeColor (mcol.at(topfg_bg));
591 writePen (str, topPenWidth, topPenStyle, col);
592 str += " </top-border>\n";
593 }
594
595 // Font (size and family)
596 if ((fontsize != 12) || (fontnr != -1))
597 {
598 str += " <font ";
599 // Fontsize
600 if (fontsize != 12)
601 {
602 str += "size=\"";
603 str += TQString::number (fontsize);
604 str += "\" ";
605 }
606 // Fontfamily
607 if (fontnr != -1)
608 {
609 str += "family=\"";
610 str += typefacetab[fontnr].latin1();
611 str += "\" ";
612 }
613 str += "weight=\"0\"";
614
615 if (italic == 1) str += " italic=\"yes\"";
616 if (bold == 1) str += " bold=\"yes\"";
617 if (underline == 1) str += " underline=\"yes\"";
618
619 str +=" />\n";
620 }
621 str += " </format>\n";
622 }
623 str += " <text>" + mystr + "</text>\n";
624 str += " </cell>\n";
625 }
626
627 }
628 emit sigProgress(100);
629
630 str += " </table>\n";
631 str += " </map>\n";
632 str += "</spreadsheet>\n";
633// str += "</DOC>\n";
634
635 kdDebug ()<<"Text "<< str<<endl;
636
637 KoStoreDevice* out=m_chain->storageFile( "root", KoStore::Write );
638
639 if (!out)
640 {
641 kdError(38000/*30502*/) << "Unable to open output file!" << endl;
642 in.close ();
643 return KoFilter::StorageCreationError;
644 }
645
646 TQCString cstring = str.utf8();
647 out->writeBlock ( cstring, cstring.length() );
648
649 in.close ();
650 return KoFilter::OK;
651}
652
653
654
655
656/******************************************************************************
657 * function: specCharfind *
658 ******************************************************************************/
659TQChar
660APPLIXSPREADImport::specCharfind (TQChar a, TQChar b)
661{
662 TQChar chr;
663
664 if ( (a == 'n') && (b == 'p') ) chr = 'ß';
665
666
667 else if ( (a == 'n') && (b == 'c') ) chr = 'Ò';
668 else if ( (a == 'p') && (b == 'c') ) chr = 'ò';
669
670 else if ( (a == 'n') && (b == 'd') ) chr = 'Ó';
671 else if ( (a == 'p') && (b == 'd') ) chr = 'ó';
672
673 else if ( (a == 'n') && (b == 'e') ) chr = 'Ô';
674 else if ( (a == 'p') && (b == 'e') ) chr = 'ô';
675
676 else if ( (a == 'n') && (b == 'f') ) chr = 'Õ';
677 else if ( (a == 'p') && (b == 'f') ) chr = 'õ';
678
679 else if ( (a == 'p') && (b == 'g') ) chr = 'ö';
680 else if ( (a == 'n') && (b == 'g') ) chr = 'Ö';
681
682
683
684 else if ( (a == 'n') && (b == 'j') ) chr = 'Ù';
685 else if ( (a == 'p') && (b == 'j') ) chr = 'ù';
686
687 else if ( (a == 'n') && (b == 'k') ) chr = 'Ú';
688 else if ( (a == 'p') && (b == 'k') ) chr = 'ú';
689
690 else if ( (a == 'n') && (b == 'l') ) chr = 'Û';
691 else if ( (a == 'p') && (b == 'l') ) chr = 'û';
692
693 else if ( (a == 'p') && (b == 'm') ) chr = 'ü';
694 else if ( (a == 'n') && (b == 'm') ) chr = 'Ü';
695
696
697
698 else if ( (a == 'm') && (b == 'a') ) chr = 'À';
699 else if ( (a == 'o') && (b == 'a') ) chr = 'à';
700
701 else if ( (a == 'm') && (b == 'b') ) chr = 'Á';
702 else if ( (a == 'o') && (b == 'b') ) chr = 'á';
703
704 else if ( (a == 'm') && (b == 'c') ) chr = 'Â';
705 else if ( (a == 'o') && (b == 'c') ) chr = 'â';
706
707 else if ( (a == 'm') && (b == 'd') ) chr = 'Ã';
708 else if ( (a == 'o') && (b == 'd') ) chr = 'ã';
709
710 else if ( (a == 'm') && (b == 'e') ) chr = 'Ä';
711 else if ( (a == 'o') && (b == 'e') ) chr = 'ä';
712
713 else if ( (a == 'm') && (b == 'f') ) chr = 'Å';
714 else if ( (a == 'o') && (b == 'f') ) chr = 'å';
715
716 else if ( (a == 'm') && (b == 'g') ) chr = 'Æ';
717 else if ( (a == 'o') && (b == 'g') ) chr = 'æ';
718
719
720
721 else if ( (a == 'm') && (b == 'i') ) chr = 'È';
722 else if ( (a == 'o') && (b == 'i') ) chr = 'è';
723
724 else if ( (a == 'm') && (b == 'j') ) chr = 'É';
725 else if ( (a == 'o') && (b == 'j') ) chr = 'é';
726
727 else if ( (a == 'm') && (b == 'k') ) chr = 'Ê';
728 else if ( (a == 'o') && (b == 'k') ) chr = 'ê';
729
730 else if ( (a == 'm') && (b == 'l') ) chr = 'Ë';
731 else if ( (a == 'o') && (b == 'l') ) chr = 'ë';
732
733
734
735
736
737
738 else if ( (a == 'm') && (b == 'm') ) chr = 'Ì';
739 else if ( (a == 'o') && (b == 'm') ) chr = 'ì';
740
741 else if ( (a == 'm') && (b == 'n') ) chr = 'Í';
742 else if ( (a == 'o') && (b == 'n') ) chr = 'í';
743
744 else if ( (a == 'm') && (b == 'o') ) chr = 'Î';
745 else if ( (a == 'o') && (b == 'o') ) chr = 'î';
746
747 else if ( (a == 'm') && (b == 'p') ) chr = 'Ï';
748 else if ( (a == 'o') && (b == 'p') ) chr = 'ï';
749
750
751 else if ( (a == 'n') && (b == 'b') ) chr = 'Ñ';
752 else if ( (a == 'p') && (b == 'b') ) chr = 'ñ';
753
754
755 else if ( (a == 'k') && (b == 'c') ) chr = '¢';
756 else if ( (a == 'k') && (b == 'j') ) chr = '©';
757 else if ( (a == 'l') && (b == 'f') ) chr = 'µ';
758 else if ( (a == 'n') && (b == 'i') ) chr = 'Ø';
759 else if ( (a == 'p') && (b == 'i') ) chr = 'ø';
760
761 else if ( (a == 'l') && (b == 'j') ) chr = '¹';
762 else if ( (a == 'l') && (b == 'c') ) chr = '²';
763 else if ( (a == 'l') && (b == 'd') ) chr = '³';
764
765 else if ( (a == 'l') && (b == 'm') ) chr = '¼';
766 else if ( (a == 'l') && (b == 'n') ) chr = '½';
767 else if ( (a == 'l') && (b == 'o') ) chr = '¾';
768
769 else if ( (a == 'l') && (b == 'a') ) chr = '°';
770
771 else if ( (a == 'k') && (b == 'o') ) chr = '®';
772 else if ( (a == 'k') && (b == 'h') ) chr = '§';
773 else if ( (a == 'k') && (b == 'd') ) chr = '£';
774
775 else if ( (a == 'p') && (b == 'a') ) chr = 'ð';
776 else if ( (a == 'n') && (b == 'a') ) chr = 'Ð';
777
778 else if ( (a == 'l') && (b == 'l') ) chr = '»';
779 else if ( (a == 'k') && (b == 'l') ) chr = '«';
780
781 else if ( (a == 'l') && (b == 'k') ) chr = 'º';
782
783 else if ( (a == 'l') && (b == 'h') ) chr = '·';
784
785 else if ( (a == 'k') && (b == 'b') ) chr = '¡';
786
787 else if ( (a == 'k') && (b == 'e') ) chr = '¤';
788
789 else if ( (a == 'l') && (b == 'b') ) chr = '±';
790
791 else if ( (a == 'l') && (b == 'p') ) chr = '¿';
792
793 else if ( (a == 'k') && (b == 'f') ) chr = '¥';
794
795 else if ( (a == 'p') && (b == 'o') ) chr = 'þ';
796 else if ( (a == 'n') && (b == 'o') ) chr = 'Þ';
797
798 else if ( (a == 'n') && (b == 'n') ) chr = 'Ý';
799 else if ( (a == 'p') && (b == 'n') ) chr = 'ý';
800 else if ( (a == 'p') && (b == 'p') ) chr = 'ÿ';
801
802 else if ( (a == 'k') && (b == 'k') ) chr = 'ª';
803
804 else if ( (a == 'k') && (b == 'm') ) chr = '¬';
805 else if ( (a == 'p') && (b == 'h') ) chr = '÷';
806
807 else if ( (a == 'k') && (b == 'g') ) chr = '|';
808
809 else if ( (a == 'l') && (b == 'e') ) chr = '\'';
810
811 else if ( (a == 'k') && (b == 'i') ) chr = '¨';
812
813 else if ( (a == 'k') && (b == 'n') ) chr = '­';
814
815 else if ( (a == 'k') && (b == 'p') ) chr = '¯';
816
817 else if ( (a == 'l') && (b == 'g') ) chr = '¶';
818
819 else if ( (a == 'l') && (b == 'i') ) chr = '¸';
820
821 else if ( (a == 'm') && (b == 'h') ) chr = 'Ç';
822 else if ( (a == 'o') && (b == 'h') ) chr = 'ç';
823
824 else if ( (a == 'n') && (b == 'h') ) chr = '×';
825
826 else if ( (a == 'k') && (b == 'a') ) chr = ' ';
827
828 else if ( (a == 'a') && (b == 'j') ) chr = '!';
829
830 else chr = '#';
831
832 return chr;
833}
834
835
836
837/******************************************************************************
838 * function: writePen *
839 ******************************************************************************/
840void
841APPLIXSPREADImport::writePen (TQString &str, int penwidth, int penstyle, TQString framecolor)
842{
843 str += " <pen width=\"";
844
845 // width of the pen
846 str += TQString::number (penwidth);
847 str += "\" style=\"";
848
849 // style of the pen
850 str += TQString::number (penstyle);
851 str += "\" color=\"";
852
853 // color of the pen
854 str += framecolor;
855 str += "\" />\n";
856
857}
858
859
860
861/******************************************************************************
862 * function: writeColor *
863 ******************************************************************************/
864TQString
865APPLIXSPREADImport::writeColor (t_mycolor *mc)
866{
867 char rgb[20];
868
869// printf (" WriteColor: <%d>-<%d>-<%d> <%d>-<%d>-<%d>-<%d>\n",
870// mc->r, mc->g, mc->b,
871// mc->c, mc->m, mc->y, mc->k);
872
873 sprintf (rgb, "#%02X%02X%02X", mc->r, mc->g, mc->b);
874 TQString bla = rgb;
875
876
877 return bla;
878}
879
880
881
882
883/******************************************************************************
884 * function: readTypefaceTable *
885 ******************************************************************************/
886void
887APPLIXSPREADImport::readTypefaceTable (TQTextStream &stream, TQStringList &typefacetab)
888{
889 int tftabCounter=0, ok;
890 TQString mystr;
891
892 // Read the colormap
893 kdDebug()<<"Reading typeface table: \n";
894
895 ok = true;
896 do
897 {
898 mystr = nextLine( stream );
899 if (mystr == "END TYPEFACE TABLE" ) ok = false;
900 else
901 {
902 //printf (" %2d: <%s>\n", tftabCounter, mystr.latin1());
903 typefacetab.append(mystr);
904 tftabCounter++;
905 }
906 }
907 while (ok == true );
908
909 kdDebug()<<"... done \n";
910}
911
912
913
914/******************************************************************************
915 * function: readColormap *
916 ******************************************************************************/
917void
918APPLIXSPREADImport::readColormap (TQTextStream &stream, TQPtrList<t_mycolor> &mcol)
919{
920 int contcount, ok, pos;
921
922 TQString colstr, mystr;
923 kdDebug ()<<"Reading colormap: \n";
924
925 ok = true;
926
927 do
928 {
929
930 mystr = nextLine( stream );
931 mystr.stripWhiteSpace ();
932
933 if (mystr == "END COLORMAP") ok = false;
934 else
935 {
936 kdDebug()<<" -> "<< mystr<<endl;
937
938 // Count the number of whitespaces
939 contcount = mystr.contains (' ');
940 kdDebug()<< "contcount: "<< contcount<<endl;
941 contcount -= 5;
942
943 // Begin off interest
944 pos = mystr.find (" 0 ");
945
946 // get colorname
947 colstr = mystr.left (pos);
948 mystr.remove (0, pos+1);
949 mystr.stripWhiteSpace ();
950
951 t_mycolor *tmc = new t_mycolor;
952
953 // get sub colors
954 pos = sscanf (mystr.latin1(), "0 %d %d %d %d 0",
955 &tmc->c, &tmc->m, &tmc->y, &tmc->k);
956
957 printf (" - <%-20s> <%-15s> <%3d> <%3d> <%3d> <%3d> pos: %d\n",
958 mystr.latin1(),
959 colstr.latin1(),
960 tmc->c, tmc->m, tmc->y, tmc->k, pos);
961
962 // Color transformation cmyk -> rgb
963 tmc->r = 255 - (tmc->c + tmc->k);
964 if (tmc->r < 0) tmc->r = 0;
965
966 tmc->g = 255 - (tmc->m + tmc->k);
967 if (tmc->g < 0) tmc->g = 0;
968
969 tmc->b = 255 - (tmc->y + tmc->k);
970 if (tmc->b < 0) tmc->b = 0;
971
972 mcol.append (tmc);
973 }
974
975 }
976 while (ok == true );
977
978 kdDebug()<< "... done "<< mcol.count()<<endl;
979
980
981 t_mycolor *emp;
982 for (emp=mcol.first(); emp != 0; emp=mcol.next() )
983 {
984 printf (" c:%3d m:%3d y:%3d k:%3d r:%3d g:%3d b:%3d\n",
985 emp->c, emp->m, emp->y, emp->k, emp->r, emp->g, emp->b);
986 }
987}
988
989
990
991
992/******************************************************************************
993 * function: readColormap *
994 ******************************************************************************/
995void
996APPLIXSPREADImport::readView (TQTextStream &stream, TQString instr, t_rc &rc)
997{
998 TQString rowcolstr;
999 TQString mystr, tabname;
1000 int ok;
1001
1002 kdDebug()<<"Reading View\n";
1003
1004 tabname = instr;
1005
1006 tabname.remove (0, 19);
1007 tabname.remove (tabname.length()-2, 2);
1008 kdDebug()<< " - Table name: "<< tabname<<endl;
1009
1010 ok = true;
1011 do
1012 {
1013 mystr = nextLine( stream );
1014
1015 kdDebug()<<" "<< mystr<<endl;
1016 if (mystr.startsWith ("View End, Name:")) ok = false;
1017 else
1018 {
1019 // COLUMN Widths
1020 if (mystr.startsWith ("View Column Widths"))
1021 {
1022 kdDebug()<< " - Column Widths\n";
1023 mystr.remove (0, 20);
1024 kdDebug()<< " "<<mystr<<endl;
1025
1026 int colwidth, icolumn;
1027 char ccolumn;
1028
1029 // loop
1030 TQStringList ColumnList;
1031 ColumnList = TQStringList::split (' ', mystr);
1032
1033 for ( TQStringList::Iterator it = ColumnList.begin(); it != ColumnList.end(); ++it )
1034 {
1035
1036 sscanf ((*it).latin1(), "%c:%d", &ccolumn, &colwidth);
1037 int len = (*it).length ();
1038 int pos = (*it).find (":");
1039 (*it).remove (pos, len-pos);
1040
1041 printf( " >%s<- -<%c><%d> \n", (*it).latin1(), ccolumn, colwidth);
1042
1043 // Transformat ascii column to int column
1044 icolumn = translateColumnNumber (*it);
1045
1046 //icolumn = ccolumn - 64;
1047 // Translate the column width right from applix to kspread
1048 icolumn = icolumn * 5;
1049
1050
1051 rowcolstr += " <column width=\"";
1052 rowcolstr += TQString::number (colwidth);
1053 rowcolstr += "\" column=\"";
1054 rowcolstr += TQString::number (icolumn);
1055 rowcolstr += "\" >\n";
1056 rowcolstr += " <format/>\n";
1057 rowcolstr += " </column>\n";
1058 }
1059 }
1060
1061 // ROW Heights
1062 else if (mystr.startsWith ("View Row Heights"))
1063 {
1064 kdDebug()<< " - Row Heights\n";
1065 mystr.remove (0, 17);
1066 kdDebug()<<" "<< mystr<<endl;
1067
1068 int irow, rowheight;
1069
1070 // loop
1071 TQStringList RowList;
1072 RowList = TQStringList::split (' ', mystr);
1073
1074 for ( TQStringList::Iterator it = RowList.begin(); it != RowList.end(); ++it )
1075 {
1076 sscanf ((*it).latin1(), " %d:%d",
1077 &irow, &rowheight);
1078 printf (" row: %2d height: %2d\n", irow, rowheight);
1079 if (rowheight > 32768) rowheight -= 32768;
1080 printf (" height: %2d\n", rowheight);
1081 rowcolstr += " <row row=\"";
1082 rowcolstr += TQString::number (irow);
1083 rowcolstr += "\" height=\"";
1084 rowcolstr += TQString::number (rowheight);
1085 rowcolstr += "\" >\n";
1086 rowcolstr += " <format/>\n";
1087 rowcolstr += " </row>\n";
1088 }
1089
1090
1091 }
1092 } // else != END COLORMAP
1093 }
1094 while (ok == true );
1095
1096 // tabname append to my list
1097 // tabname append to my list
1098 rc.tabname.append (tabname);
1099 rc.rc.append (rowcolstr);
1100
1101 printf ("%s %s\n", tabname.latin1(),
1102 rowcolstr.latin1());
1103
1104 printf ("...done \n\n");
1105}
1106
1107
1108
1109
1110
1111/******************************************************************************
1112 * function: filterSHFGBG *
1113 ******************************************************************************/
1114void
1115APPLIXSPREADImport::filterSHFGBG (TQString it, int *style, int *bgcolor,
1116 int *fgcolor)
1117{
1118 TQString tmpstr;
1119 int pos;
1120 int m2=0, m3=0;
1121
1122 // filter SH = Brushstyle Background
1123 pos = it.find ("SH");
1124 if (pos > -1)
1125 {
1126 tmpstr = it;
1127 if (pos > 0) tmpstr.remove(0, pos);
1128 pos = sscanf (tmpstr.latin1(), "SH%d",
1129 style);
1130
1131 printf ("style: %d(%d) ",
1132 *style, pos);
1133 }
1134
1135
1136 // filter FG = FGCOLOR
1137 pos = it.find ("FG");
1138 if (pos > -1)
1139 {
1140 tmpstr = it;
1141 if (pos > 0) tmpstr.remove(0, pos);
1142 pos = sscanf (tmpstr.latin1(), "FG%d",
1143 fgcolor);
1144 printf ("fg: %d(%d) ",
1145 *fgcolor, pos);
1146 m2=1;
1147 }
1148
1149
1150 // filter BG = BGCOLOR
1151 pos = it.find ("BG");
1152 if (pos > -1)
1153 {
1154 tmpstr = it;
1155 if (pos > 0) tmpstr.remove(0, pos);
1156 pos = sscanf (tmpstr.latin1(), "BG%d",
1157 bgcolor);
1158 printf ("bgcolor: %d(%d) ",
1159 *bgcolor, pos);
1160 m3=1;
1161 }
1162
1163
1164 printf ("\n");
1165
1166
1167 // corrent the bgcolor to the fgcolor if the background is plain
1168 if ((*style == 8) && (m2 == 1) && (m3 == 0))
1169 {
1170 *bgcolor = *fgcolor;
1171 }
1172
1173
1174 // Translate brushstyle to kspread brushstyle
1175 if (*style != 0)
1176 {
1177 if (*style == 1) *style = 0;
1178 else if (*style == 2) *style = 7;
1179 else if (*style == 3) *style = 0;
1180 else if (*style == 4) *style = 4;
1181 else if (*style == 5) *style = 3;
1182 else if (*style == 6) *style = 2;
1183 else if (*style == 7) *style = 0;
1184 else if (*style == 8) *style = 0;
1185 else if (*style == 9) *style = 10;
1186 else if (*style == 10) *style = 9;
1187 else if (*style == 11) *style = 11;
1188 else if (*style == 12) *style = 12;
1189 else if (*style == 13) *style = 13;
1190 else if (*style == 14) *style = 14;
1191 else if (*style == 15) *style = 0;
1192 else if (*style == 16) *style = 0;
1193 else if (*style == 17) *style = 0;
1194 else if (*style == 18) *style = 0;
1195 else if (*style == 19) *style = 0;
1196 }
1197}
1198
1199
1200
1201/******************************************************************************
1202 * function: filterSHFGBG *
1203 ******************************************************************************/
1204void
1205APPLIXSPREADImport::transPenFormat (TQString it, int *PenWidth, int *PenStyle)
1206{
1207
1208 if ( it[1] == '1' )
1209 {
1210 *PenWidth = 1;
1211 *PenStyle = 1;
1212 }
1213
1214 else if ( it[1] == '2' )
1215 {
1216 *PenWidth = 2;
1217 *PenStyle = 1;
1218 }
1219
1220 else if ( it[1] == '3' )
1221 {
1222 *PenWidth = 3;
1223 *PenStyle = 1;
1224 }
1225
1226 else if ( it[1] == '4' )
1227 {
1228 *PenWidth = 1;
1229 *PenStyle = 3;
1230 }
1231
1232 else if ( it[1] == '5' )
1233 {
1234 *PenWidth = 5;
1235 *PenStyle = 1;
1236 }
1237
1238 printf ("frame (w:%d - s:%d) \n", *PenWidth, *PenStyle);
1239}
1240
1241
1242
1243
1244/******************************************************************************
1245 * function: readHeader *
1246 ******************************************************************************/
1247int
1248APPLIXSPREADImport::readHeader (TQTextStream &stream)
1249{
1250 TQString mystr;
1251 int vers[3] = { 0, 0, 0 };
1252 int rueck;
1253
1254
1255 // Read Headline
1256 mystr = nextLine (stream);
1257 rueck = sscanf (mystr.latin1(),
1258 "*BEGIN SPREADSHEETS VERSION=%d/%d ENCODING=%dBIT",
1259 &vers[0], &vers[1], &vers[2]);
1260 printf ("Versions info: %d %d %d\n", vers[0], vers[1], vers[2]);
1261
1262 // Check the headline
1263 if (rueck <= 0)
1264 {
1265 printf ("Header not correkt - May be it is not an applixspreadsheet file\n");
1266 printf ("Headerline: <%s>\n", mystr.latin1());
1267
1268 TQMessageBox::critical (0L, "Applix spreadsheet header problem",
1269 TQString ("The Applix Spreadsheet header is not correct. "
1270 "May be it is not an applix spreadsheet file! <BR>"
1271 "This is the header line I did read:<BR><B>%1</B>").arg(mystr.latin1()),
1272 "Okay");
1273
1274
1275 return false;
1276 }
1277 else
1278 {
1279 return true;
1280 }
1281}
1282
1283
1284
1285/******************************************************************************
1286 * function: translateRowNumber *
1287 ******************************************************************************/
1288int
1289APPLIXSPREADImport::translateColumnNumber (TQString colstr)
1290{
1291 int icol=0;
1292 int p, x, len;
1293
1294
1295 len = colstr.length ();
1296 p = len-1;
1297 x = 1;
1298
1299 printf ("HI 0 len:%d\n", len );
1300 while ((p >= 0))
1301 {
1302 printf ("HI 1 x:%d p:%d char:<%c>\n", x, p, colstr[p].latin1());
1303 // Upper chars
1304 if ((colstr[p] >= 'A') && (colstr[p] <= 'Z'))
1305 {
1306 kdDebug ()<<" UPPER\n";
1307 icol = icol + ((int)pow ((double)x, 26) * (colstr[p].latin1() - 'A' + 1) );
1308 x++;
1309 }
1310 // lower chars
1311 else if ((colstr[p] >= 'a') && (colstr[p] <= 'z'))
1312 {
1313 kdDebug()<<" lower\n";
1314 icol = icol + ((int)pow ((double)x, 26) * (colstr[p].latin1() - 'a' + 1) );
1315 x++;
1316 }
1317 p--;
1318 kdDebug ()<< "HI 2\n";
1319
1320 }
1321
1322 printf ("translateColumnNumber : <%s> -> %d\n", colstr.latin1(), icol);
1323 return icol;
1324}
1325
1326#include <applixspreadimport.moc>