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.

791 lines
26KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2000 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 <tqptrlist.h>
  22. #include <applixwordimport.h>
  23. #include <applixwordimport.moc>
  24. #include <kdebug.h>
  25. #include <KoFilterChain.h>
  26. #include <kgenericfactory.h>
  27. typedef KGenericFactory<APPLIXWORDImport, KoFilter> APPLIXWORDImportFactory;
  28. K_EXPORT_COMPONENT_FACTORY( libapplixwordimport, APPLIXWORDImportFactory( "kofficefilters" ) )
  29. /******************************************************************************
  30. * class: APPLIXWORDImport function: APPLIXWORDImport *
  31. ******************************************************************************
  32. * *
  33. * Short description : Constructor *
  34. * *
  35. * *
  36. ******************************************************************************/
  37. APPLIXWORDImport::APPLIXWORDImport (KoFilter *, const char *, const TQStringList& ) :
  38. KoFilter()
  39. {
  40. }
  41. /******************************************************************************
  42. * class: APPLIXWORDImport function: nextLine *
  43. ******************************************************************************
  44. * *
  45. * Short description : Readline and update progressbar *
  46. * *
  47. * *
  48. ******************************************************************************/
  49. TQString
  50. APPLIXWORDImport::nextLine (TQTextStream & stream)
  51. {
  52. TQString s;
  53. // Read one Line
  54. s = stream.readLine();
  55. m_instep += s.length();
  56. if (m_instep > m_stepsize)
  57. {
  58. m_instep = 0;
  59. m_progress += 2;
  60. emit sigProgress (m_progress) ;
  61. }
  62. return s;
  63. }
  64. /******************************************************************************
  65. * class: APPLIXWORDImport function: filter *
  66. ******************************************************************************
  67. * *
  68. * Short description : *
  69. * *
  70. * *
  71. ******************************************************************************/
  72. KoFilter::ConversionStatus APPLIXWORDImport::convert( const TQCString& from, const TQCString& to )
  73. {
  74. if (to!="application/x-kword" || from!="application/x-applixword")
  75. return KoFilter::NotImplemented;
  76. TQFile in(m_chain->inputFile());
  77. if (!in.open (IO_ReadOnly))
  78. {
  79. kdError(30517) << "Unable to open input file!" << endl;
  80. in.close();
  81. return KoFilter::FileNotFound;
  82. }
  83. TQString str;
  84. str += "<?xml version=\"1.0\"?>\n";
  85. str += "<DOC author=\"Reginald Stadlbauer and Torben Weis\" email=\"reggie@kde.org and weis@kde.org\" editor=\"KWord\" mime=\"application/x-kword\">\n";
  86. str += " <PAPER format=\"1\" ptWidth=\"595\" ptHeight=\"841\" mmWidth =\"210\" mmHeight=\"297\" inchWidth =\"8.26772\" inchHeight=\"11.6929\" orientation=\"0\" columns=\"1\" ptColumnspc=\"2\" mmColumnspc=\"1\" inchColumnspc=\"0.0393701\" hType=\"0\" fType=\"0\" ptHeadBody=\"9\" ptFootBody=\"9\" mmHeadBody=\"3.5\" mmFootBody=\"3.5\" inchHeadBody=\"0.137795\" inchFootBody=\"0.137795\">\n";
  87. str += " <PAPERBORDERS mmLeft=\"10\" mmTop=\"15\" mmRight=\"10\" mmBottom=\"15\" ptLeft=\"28\" ptTop=\"42\" ptRight=\"28\" ptBottom=\"42\" inchLeft=\"0.393701\" inchTop=\"0.590551\" inchRight=\"0.393701\" inchBottom=\"0.590551\"/>\n";
  88. str += " </PAPER>\n";
  89. str += " <ATTRIBUTES processing=\"0\" standardpage=\"1\" hasHeader=\"0\" hasFooter=\"0\" />\n";
  90. str += " <FRAMESETS>\n";
  91. str += " <FRAMESET frameType=\"1\" autoCreateNewFrame=\"1\" frameInfo=\"0\" removeable=\"0\">\n";
  92. str += " <FRAME left=\"28\" top=\"42\" right=\"566\" bottom=\"798\" runaround=\"1\" runaGapPT=\"2\" runaGapMM=\"1\" runaGapINCH=\"0.0393701\" lWidth=\"1\" lRed=\"255\" lGreen=\"255\" lBlue=\"255\" lStyle=\"0\" rWidth=\"1\" rRed=\"255\" rGreen=\"255\" rBlue=\"255\" rStyle=\"0\" tWidth=\"1\" tRed=\"255\" tGreen=\"255\" tBlue=\"255\" tStyle=\"0\" bWidth=\"1\" bRed=\"255\" bGreen=\"255\" bBlue=\"255\" bStyle=\"0\" bkRed=\"255\" bkGreen=\"255\" bkBlue=\"255\" bleftpt=\"0\" bleftmm=\"0\" bleftinch=\"0\" brightpt=\"0\" brightmm=\"0\" brightinch=\"0\" btoppt=\"0\" btopmm=\"0\" btopinch=\"0\" bbottompt=\"0\" bbottommm=\"0\" bbottominch=\"0\"/>\n";
  93. TQTextStream stream (&in);
  94. m_stepsize = in.size()/50;
  95. m_instep = 0;
  96. m_progress = 0;
  97. int rueck;
  98. int pos, ok;
  99. char stylename[100];
  100. TQString mystr, textstr;
  101. TQPtrList<t_mycolor> mcol;
  102. TQStringList mcoltxt;
  103. /**************************************************************************
  104. * Read header *
  105. **************************************************************************/
  106. if (! readHeader (stream, in)) return KoFilter::StupidError;
  107. while (!stream.atEnd())
  108. {
  109. // Read one line
  110. mystr = readTagLine (stream, in);
  111. ok = true;
  112. /**********************************************************************
  113. * jump over start_styles if it exists *
  114. **********************************************************************/
  115. if (mystr == "<start_styles>")
  116. {
  117. printf ("Start styles\n");
  118. t_mycolor *col = new t_mycolor; // delete is in place
  119. TQString coltxt ;
  120. int zaehler = 0; // Note: "zaehler" means "counter" in English
  121. do
  122. {
  123. mystr = readTagLine (stream, in);
  124. if (mystr == "<end_styles>")
  125. {
  126. ok = false;
  127. kdDebug(30517)<<"End styles\n\n";
  128. }
  129. else
  130. {
  131. if (mystr.startsWith ("<color "))
  132. {
  133. mystr.remove (0, 8);
  134. pos = mystr.find ("\"");
  135. coltxt = mystr.left (pos);
  136. mystr.remove (0,pos+1);
  137. rueck = sscanf ((const char *) mystr.latin1() ,
  138. ":%d:%d:%d:%d>",
  139. &col->c, &col->m, &col->y, &col->k);
  140. kdDebug(30517)<<" Color " << zaehler<<" : "<<col->c << " " << col->m<< " "<< col->y<<" "<< col->k<<" "<<coltxt<<" "<<endl;
  141. zaehler ++;
  142. // Color transformation cmyk -> rgb
  143. col->r = 255 - (col->c + col->k);
  144. if (col->r < 0) col->r = 0;
  145. col->g = 255 - (col->m + col->k);
  146. if (col->g < 0) col->g = 0;
  147. col->b = 255 - (col->y + col->k);
  148. if (col->b < 0) col->b = 0;
  149. mcol.append (col);
  150. mcoltxt.append (coltxt);
  151. } //end if ...<col...
  152. } //end else
  153. } // end while
  154. while (ok == true);
  155. delete col;
  156. } // end if ...<start_styles>...
  157. /***********************************************************************
  158. * jump over embedded Applix docs *
  159. ***********************************************************************/
  160. else if (mystr == "<start_data Applix>")
  161. {
  162. kdDebug(30517)<<"\nEmbedded Applix object starts:\n";
  163. do
  164. {
  165. mystr = readTagLine (stream, in);
  166. if (mystr == "<end_data>") ok = false;
  167. else
  168. {
  169. kdDebug(30517)<<" "<<mystr<<endl;
  170. }
  171. }
  172. while (ok == true);
  173. kdDebug(30517)<<"Embedded Applix object ends\n\n";
  174. }
  175. /**********************************************************************
  176. * jump over header footer *
  177. **********************************************************************/
  178. else if (mystr.startsWith ("<start_hdrftr "))
  179. {
  180. kdDebug(30517)<<"\nHeader/Footer starts:\n";
  181. do
  182. {
  183. mystr = readTagLine (stream, in);
  184. if (mystr == "<end_hdrftr>") ok = false;
  185. else
  186. {
  187. kdDebug(30517)<<" "<<mystr<<endl;
  188. }
  189. }
  190. while (ok == true);
  191. kdDebug(30517)<<"\nHeader/Footer ends\n";
  192. }
  193. /**********************************************************************
  194. * found a paragraph string *
  195. **********************************************************************/
  196. else if (mystr.startsWith ("<P "))
  197. {
  198. sscanf ( (const char *) mystr.latin1(), "<P \"%99s\"", stylename);
  199. mystr.remove (0, 5+strlen(stylename));
  200. kdDebug(30517)<<" Para Name: "<< stylename<<endl;
  201. kdDebug(30517)<<" Rest: "<<mystr<<endl;
  202. }
  203. /**********************************************************************
  204. * found a textstring *
  205. **********************************************************************/
  206. else if (mystr.startsWith ("<T "))
  207. {
  208. TQString colname;
  209. // Remove starting tab info
  210. mystr.remove (0, 4);
  211. // Remove ending >
  212. mystr.remove (mystr.length()-1, 1);
  213. // Separate textstring "
  214. ok = true;
  215. int y=0;
  216. do
  217. {
  218. pos = mystr.find ("\"", y);
  219. kdDebug(30517)<<"POS:"<<pos<<" length:"<< mystr.length()<<" y:"<<y <<endl;
  220. kdDebug(30517)<<"< "<<mystr<<" >\n";
  221. if( (pos-1 > -1) && (mystr[pos-1] == '\\'))
  222. {
  223. kdDebug(30517)<<" No string end - but Gänsefüsschen\n";
  224. y=pos+1;
  225. }
  226. else
  227. {
  228. kdDebug(30517)<<" String end //\n";
  229. ok = false;
  230. }
  231. }
  232. while (ok == true);
  233. textstr = mystr.left (pos);
  234. mystr.remove (0, pos+1);
  235. mystr.stripWhiteSpace();
  236. kdDebug(30517) <<"Text:<" <<textstr <<" > "<< pos<<" Rest:<"<< mystr<<"> \n";
  237. // split format
  238. TQStringList typeList;
  239. typeList = TQStringList::split (' ', mystr);
  240. int fontsize=12, bold=0, italic=0, underline=0, colpos=-1;
  241. TQString fontname;
  242. int nn=0;
  243. for (TQStringList::Iterator it = typeList.begin(); it != typeList.end(); ++it )
  244. {
  245. kdDebug(30517) <<" No: "<< nn<< " > "<< (*it)<< "< = \n";
  246. // Looking for bold
  247. if ((*it) == "bold")
  248. {
  249. bold = 1;
  250. kdDebug(30517)<<"bold\n";
  251. }
  252. else if ((*it) == "no-bold")
  253. {
  254. bold = 0;
  255. kdDebug(30517)<<"no bold\n";
  256. }
  257. else if ((*it) == "italic")
  258. {
  259. italic = 1;
  260. kdDebug(30517)<<"italic\n";
  261. }
  262. else if ((*it) == "no-italic")
  263. {
  264. italic = 0;
  265. kdDebug(30517) <<"no italic\n";
  266. }
  267. else if ((*it) == "underline")
  268. {
  269. underline = 1;
  270. kdDebug(30517)<<"underline\n";
  271. }
  272. else if ((*it) == "no-underline")
  273. {
  274. underline = 0;
  275. kdDebug(30517) <<"no underline\n";
  276. }
  277. else if ((*it).startsWith ("size"))
  278. {
  279. (*it).remove (0, 5);
  280. sscanf ( (const char *) (*it).latin1(), "%d", &fontsize);
  281. kdDebug(30517)<<"fontsize: "<< fontsize<<endl;
  282. }
  283. else if ((*it).startsWith ("face"))
  284. {
  285. (*it).remove (0, 6);
  286. (*it).remove ((*it).length()-1, 1);
  287. fontname = *it;
  288. kdDebug(30517)<<"fontname: "<<fontname<<endl;
  289. }
  290. else if ((*it).startsWith ("color:"))
  291. {
  292. (*it).remove (0, 7);
  293. (*it).remove ((*it).length()-1, 1);
  294. colname = *it;
  295. colpos = mcoltxt.findIndex (colname);
  296. kdDebug(30517) <<" Color: "<< colname<<" "<< colpos <<" \n";
  297. }
  298. else
  299. {
  300. kdDebug(30517)<<" "<< (*it)<<endl;
  301. }
  302. }
  303. kdDebug(30517) <<"\n";
  304. // Replaces Part for & <>, applixwear special characters and qouts
  305. replaceSpecial (textstr);
  306. // add text inside
  307. str += " <PARAGRAPH>\n";
  308. str += " <TEXT>";
  309. str += textstr;
  310. str += "</TEXT>\n";
  311. if (bold == 1 || underline == 1 || italic == 1 || fontsize != 12 ||
  312. colpos != -1 || !fontname.isEmpty())
  313. {
  314. str += " <LAYOUT>\n";
  315. str += " <FORMAT>\n";
  316. if (!fontname.isEmpty())
  317. {
  318. str += " <FONT name=\"";
  319. str += fontname;
  320. str += "\" />\n";
  321. }
  322. if (fontsize != 1)
  323. {
  324. str += " <SIZE value=\"";
  325. str += TQString::number (fontsize);
  326. str += "\" />\n";
  327. }
  328. if (italic == 1)
  329. {
  330. str += " <ITALIC value=\"1\" />\n";
  331. }
  332. if (bold == 1)
  333. {
  334. str += " <WEIGHT value=\"75\" />\n";
  335. }
  336. if (underline == 1)
  337. {
  338. str += " <UNDERLINE value=\"1\" />\n";
  339. }
  340. if (colpos != -1)
  341. {
  342. t_mycolor *mc = new t_mycolor; // delete is in place
  343. mc = mcol.at(colpos);
  344. str += " <COLOR red=\"";
  345. str += TQString::number (mc->r);
  346. str += "\" green=\"";
  347. str += TQString::number (mc->g);
  348. str += "\" blue=\"";
  349. str += TQString::number (mc->b);
  350. str += "\" />\n";
  351. delete mc;
  352. }
  353. str += " </FORMAT>\n";
  354. str += " </LAYOUT>\n";
  355. }
  356. str += " </PARAGRAPH>\n";
  357. }
  358. }
  359. emit sigProgress(100);
  360. str += " </FRAMESET>\n";
  361. str += " </FRAMESETS>\n";
  362. str += "</DOC>\n";
  363. kdDebug(30517)<<"Text "<< str <<endl;
  364. KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write );
  365. if (!out)
  366. {
  367. kdError(30517) << "Unable to open output file!" << endl;
  368. in.close ();
  369. return KoFilter::StorageCreationError;
  370. }
  371. TQCString cstring = str.utf8 ();
  372. out->writeBlock ((const char*) cstring, cstring.length());
  373. in.close ();
  374. return KoFilter::OK;
  375. }
  376. /******************************************************************************
  377. * function: specCharfind *
  378. ******************************************************************************/
  379. TQChar
  380. APPLIXWORDImport::specCharfind (TQChar a, TQChar b)
  381. {
  382. TQChar chr;
  383. if ( (a == 'n') && (b == 'p') ) chr = 'ß';
  384. else if ( (a == 'n') && (b == 'c') ) chr = 'Ò';
  385. else if ( (a == 'p') && (b == 'c') ) chr = 'ò';
  386. else if ( (a == 'n') && (b == 'd') ) chr = 'Ó';
  387. else if ( (a == 'p') && (b == 'd') ) chr = 'ó';
  388. else if ( (a == 'n') && (b == 'e') ) chr = 'Ô';
  389. else if ( (a == 'p') && (b == 'e') ) chr = 'ô';
  390. else if ( (a == 'n') && (b == 'f') ) chr = 'Õ';
  391. else if ( (a == 'p') && (b == 'f') ) chr = 'õ';
  392. else if ( (a == 'p') && (b == 'g') ) chr = 'ö';
  393. else if ( (a == 'n') && (b == 'g') ) chr = 'Ö';
  394. else if ( (a == 'n') && (b == 'j') ) chr = 'Ù';
  395. else if ( (a == 'p') && (b == 'j') ) chr = 'ù';
  396. else if ( (a == 'n') && (b == 'k') ) chr = 'Ú';
  397. else if ( (a == 'p') && (b == 'k') ) chr = 'ú';
  398. else if ( (a == 'n') && (b == 'l') ) chr = 'Û';
  399. else if ( (a == 'p') && (b == 'l') ) chr = 'û';
  400. else if ( (a == 'p') && (b == 'm') ) chr = 'ü';
  401. else if ( (a == 'n') && (b == 'm') ) chr = 'Ü';
  402. else if ( (a == 'm') && (b == 'a') ) chr = 'À';
  403. else if ( (a == 'o') && (b == 'a') ) chr = 'à';
  404. else if ( (a == 'm') && (b == 'b') ) chr = 'Á';
  405. else if ( (a == 'o') && (b == 'b') ) chr = 'á';
  406. else if ( (a == 'm') && (b == 'c') ) chr = 'Â';
  407. else if ( (a == 'o') && (b == 'c') ) chr = 'â';
  408. else if ( (a == 'm') && (b == 'd') ) chr = 'Ã';
  409. else if ( (a == 'o') && (b == 'd') ) chr = 'ã';
  410. else if ( (a == 'm') && (b == 'e') ) chr = 'Ä';
  411. else if ( (a == 'o') && (b == 'e') ) chr = 'ä';
  412. else if ( (a == 'm') && (b == 'f') ) chr = 'Å';
  413. else if ( (a == 'o') && (b == 'f') ) chr = 'å';
  414. else if ( (a == 'm') && (b == 'g') ) chr = 'Æ';
  415. else if ( (a == 'o') && (b == 'g') ) chr = 'æ';
  416. else if ( (a == 'm') && (b == 'i') ) chr = 'È';
  417. else if ( (a == 'o') && (b == 'i') ) chr = 'è';
  418. else if ( (a == 'm') && (b == 'j') ) chr = 'É';
  419. else if ( (a == 'o') && (b == 'j') ) chr = 'é';
  420. else if ( (a == 'm') && (b == 'k') ) chr = 'Ê';
  421. else if ( (a == 'o') && (b == 'k') ) chr = 'ê';
  422. else if ( (a == 'm') && (b == 'l') ) chr = 'Ë';
  423. else if ( (a == 'o') && (b == 'l') ) chr = 'ë';
  424. else if ( (a == 'm') && (b == 'm') ) chr = 'Ì';
  425. else if ( (a == 'o') && (b == 'm') ) chr = 'ì';
  426. else if ( (a == 'm') && (b == 'n') ) chr = 'Í';
  427. else if ( (a == 'o') && (b == 'n') ) chr = 'í';
  428. else if ( (a == 'm') && (b == 'o') ) chr = 'Î';
  429. else if ( (a == 'o') && (b == 'o') ) chr = 'î';
  430. else if ( (a == 'm') && (b == 'p') ) chr = 'Ï';
  431. else if ( (a == 'o') && (b == 'p') ) chr = 'ï';
  432. else if ( (a == 'n') && (b == 'b') ) chr = 'Ñ';
  433. else if ( (a == 'p') && (b == 'b') ) chr = 'ñ';
  434. else if ( (a == 'k') && (b == 'c') ) chr = '¢';
  435. else if ( (a == 'k') && (b == 'j') ) chr = '©';
  436. else if ( (a == 'l') && (b == 'f') ) chr = 'µ';
  437. else if ( (a == 'n') && (b == 'i') ) chr = 'Ø';
  438. else if ( (a == 'p') && (b == 'i') ) chr = 'ø';
  439. else if ( (a == 'l') && (b == 'j') ) chr = '¹';
  440. else if ( (a == 'l') && (b == 'c') ) chr = '²';
  441. else if ( (a == 'l') && (b == 'd') ) chr = '³';
  442. else if ( (a == 'l') && (b == 'm') ) chr = '¼';
  443. else if ( (a == 'l') && (b == 'n') ) chr = '½';
  444. else if ( (a == 'l') && (b == 'o') ) chr = '¾';
  445. else if ( (a == 'l') && (b == 'a') ) chr = '°';
  446. else if ( (a == 'k') && (b == 'o') ) chr = '®';
  447. else if ( (a == 'k') && (b == 'h') ) chr = '§';
  448. else if ( (a == 'k') && (b == 'd') ) chr = '£';
  449. else if ( (a == 'p') && (b == 'a') ) chr = 'ð';
  450. else if ( (a == 'n') && (b == 'a') ) chr = 'Ð';
  451. else if ( (a == 'l') && (b == 'l') ) chr = '»';
  452. else if ( (a == 'k') && (b == 'l') ) chr = '«';
  453. else if ( (a == 'l') && (b == 'k') ) chr = 'º';
  454. else if ( (a == 'l') && (b == 'h') ) chr = '·';
  455. else if ( (a == 'k') && (b == 'b') ) chr = '¡';
  456. else if ( (a == 'k') && (b == 'e') ) chr = '¤';
  457. else if ( (a == 'l') && (b == 'b') ) chr = '±';
  458. else if ( (a == 'l') && (b == 'p') ) chr = '¿';
  459. else if ( (a == 'k') && (b == 'f') ) chr = '¥';
  460. else if ( (a == 'p') && (b == 'o') ) chr = 'þ';
  461. else if ( (a == 'n') && (b == 'o') ) chr = 'Þ';
  462. else if ( (a == 'n') && (b == 'n') ) chr = 'Ý';
  463. else if ( (a == 'p') && (b == 'n') ) chr = 'ý';
  464. else if ( (a == 'p') && (b == 'p') ) chr = 'ÿ';
  465. else if ( (a == 'k') && (b == 'k') ) chr = 'ª';
  466. else if ( (a == 'k') && (b == 'm') ) chr = '¬';
  467. else if ( (a == 'p') && (b == 'h') ) chr = '÷';
  468. else if ( (a == 'k') && (b == 'g') ) chr = '|';
  469. else if ( (a == 'l') && (b == 'e') ) chr = '\'';
  470. else if ( (a == 'k') && (b == 'i') ) chr = '¨';
  471. else if ( (a == 'k') && (b == 'n') ) chr = '­';
  472. else if ( (a == 'k') && (b == 'p') ) chr = '¯';
  473. else if ( (a == 'l') && (b == 'g') ) chr = '¶';
  474. else if ( (a == 'l') && (b == 'i') ) chr = '¸';
  475. else if ( (a == 'm') && (b == 'h') ) chr = 'Ç';
  476. else if ( (a == 'o') && (b == 'h') ) chr = 'ç';
  477. else if ( (a == 'n') && (b == 'h') ) chr = '×';
  478. else if ( (a == 'k') && (b == 'a') ) chr = ' ';
  479. else if ( (a == 'a') && (b == 'j') ) chr = '!';
  480. else chr = '#';
  481. return chr;
  482. }
  483. /******************************************************************************
  484. * class: APPLIXWORDImport function: readTagLine *
  485. ******************************************************************************
  486. * *
  487. * Short description : *
  488. * *
  489. * *
  490. ******************************************************************************/
  491. TQString
  492. APPLIXWORDImport::readTagLine (TQTextStream &stream, TQFile &in)
  493. {
  494. TQString mystrn, mystr;
  495. int ok, pos;
  496. // Read one line
  497. mystr = nextLine (stream);
  498. // Delete whitespaces
  499. mystr.stripWhiteSpace();
  500. // Look if the tag continues on the next line
  501. if ((mystr.length() == 80) && (mystr[mystr.length()-1] == '\\') )
  502. {
  503. ok = true;
  504. do
  505. {
  506. // Get the actual position in the file
  507. pos = in.at ();
  508. // Read next line
  509. mystrn = nextLine (stream);
  510. // Is the new line a new tag line
  511. if (mystrn[0] == ' ')
  512. {
  513. // remove the whitespace at the start of the new line
  514. mystrn.remove (0, 1);
  515. // remove the '/' at the end of the old line
  516. mystr.remove (mystr.length()-1, 1);
  517. // append the new line
  518. mystr += mystrn;
  519. }
  520. else
  521. {
  522. // was the newline a newtaglien the jump back
  523. in.at (pos);
  524. ok = false;
  525. }
  526. }
  527. while (ok == true);
  528. }
  529. return mystr;
  530. }
  531. /******************************************************************************
  532. * class: APPLIXWORDImport function: replaceSpecial *
  533. ******************************************************************************
  534. * *
  535. * Short description : *
  536. * *
  537. * *
  538. ******************************************************************************/
  539. void
  540. APPLIXWORDImport::replaceSpecial (TQString &textstr)
  541. {
  542. int ok, pos;
  543. // 1. Replace Part for this characters: <, >, &
  544. textstr.replace ('&', "&amp;");
  545. textstr.replace ('<', "&lt;");
  546. textstr.replace ('>', "&gt;");
  547. // 2. Replace part for this characters: applixwear qoutes
  548. ok = true;
  549. pos = 0;
  550. do
  551. {
  552. // Searching for an quote
  553. pos = textstr.find ('\"', pos);
  554. // Is it an textqoute ?
  555. if ((pos > -1) && (textstr[pos-1] == '\\'))
  556. {
  557. textstr.replace (pos-1, 2,"\"");
  558. }
  559. else
  560. {
  561. ok = false;
  562. }
  563. }
  564. while (ok == true);
  565. // 3. Replace part for Applix Characters
  566. int foundSpecialCharakter;
  567. TQChar newchar;
  568. do
  569. {
  570. // initialize
  571. foundSpecialCharakter = false;
  572. pos = textstr.find ("^");
  573. // is there a special character ?
  574. if (pos > -1 )
  575. {
  576. // i have found a special character !
  577. foundSpecialCharakter = true;
  578. // translate the applix special character
  579. newchar = specCharfind (textstr[pos+1], textstr[pos+2]);
  580. // replace the character
  581. textstr.replace (pos, 3, newchar);
  582. }
  583. }
  584. while (foundSpecialCharakter == true);
  585. }
  586. /******************************************************************************
  587. * class: APPLIXWORDImport function: readHeader *
  588. ******************************************************************************
  589. * *
  590. * Short description : *
  591. * *
  592. * *
  593. ******************************************************************************/
  594. int
  595. APPLIXWORDImport::readHeader (TQTextStream &stream, TQFile &in)
  596. {
  597. TQString mystr;
  598. int rueck;
  599. int vers[3] = { 0, 0, 0 };
  600. // Read Headline
  601. mystr = readTagLine (stream, in);
  602. // mystr = stream.readLine ();
  603. rueck = sscanf ((const char *) mystr.latin1() ,
  604. "*BEGIN WORDS VERSION=%d/%d ENCODING=%dBIT",
  605. &vers[0], &vers[1], &vers[2]);
  606. printf ("Versions info: %d %d %d\n", vers[0], vers[1], vers[2]);
  607. // Check the headline
  608. if (rueck <= 0)
  609. {
  610. printf ("Header not correkt - May be it is not an applixword file\n");
  611. printf ("Headerline: <%s>\n", (const char *) mystr.latin1());
  612. TQMessageBox::critical (0L, "Applixword header problem",
  613. TQString ("The Applixword header is not correct. "
  614. "May be it is not an applixword file! <BR>"
  615. "This is the header line I did read:<BR><B>%1</B>").arg(mystr.latin1()),
  616. "Okay");
  617. // i18n( "What is the separator used in this file ? First line is \n%1" ).arg(firstLine),
  618. return false;
  619. }
  620. else return true;
  621. }