KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1327 lines
38KB

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