filters
- filters
- karbon
- applixgraphics
29#include <tqtextstream.h>
30#include <tqmessagebox.h>
31#include <KoFilterChain.h>
32#include <kgenericfactory.h>
35#include <applixgraphicimport.h>
37typedef KGenericFactory<APPLIXGRAPHICImport, KoFilter> APPLIXGRAPHICImportFactory;
38K_EXPORT_COMPONENT_FACTORY( libapplixgraphicimport, APPLIXGRAPHICImportFactory( "kofficefilters" ) )
50applixGraphicsLine::applixGraphicsLine()
57 for ( int i=0; i<5; i++)
76applixGraphicsRect::applixGraphicsRect() : applixGraphicsLine()
78 for ( int i=0; i<7;i++)
84 for ( int i=0; i<5;i++)
89 for ( int i=0; i<8;i++)
94 for ( int i=0; i<3;i++)
99 for ( int i=0; i<2;i++)
118APPLIXGRAPHICImport::APPLIXGRAPHICImport (KoFilter *, const char *, const TQStringList&) :
136KoFilter::ConversionStatus APPLIXGRAPHICImport::convert( const TQCString& from, const TQCString& to )
140 if (to!= "application/x-karbon" || from!= "application/x-applixgraphic")
141 return KoFilter::NotImplemented;
144 TQFile in (m_chain->inputFile());
145 if (!in.open (IO_ReadOnly) )
147 kdError(30502) << "Unable to open input file!" << endl;
149 return KoFilter::FileNotFound;
155 str += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
156 str += "<!DOCTYPE karbon>\n";
157 str += " <karbon mime=\"application/x-karbon\" version=\"2\" editor=\"APPLIXGRAPHICS import filter\">\n";
164 str += " <layer name=\"ag-layer\" visible=\"1\">\n";
166 TQTextStream stream(&in);
167 int step = in.size()/50;
170 int picture_rememberer = 0;
172 int vers[3] = { 0, 0, 0 };
177 mystr = stream.readLine ();
178 rueck = sscanf (( const char *) mystr.latin1() ,
179 "*BEGIN GRAPHICS VERSION=%d/%d ENCODING=%dBIT",
180 &vers[0], &vers[1], &vers[2]);
181 kdDebug (s_area) << "Versions info: " << vers[0] << vers[1] << vers[2] << endl;
186 kdDebug (s_area) << "Header not correkt - May be it is not an applixgraphics file" << endl;
187 kdDebug (s_area) << "Headerline: " << mystr << endl;
189 TQMessageBox::critical (0L, "Applixgraphics header problem",
190 TQString ( "The Applixgraphics header is not correct. "
191 "May be it is not an applixgraphics file! <BR>"
192 "This is the header line I did read:<BR><B>%1</B>").arg(mystr.latin1()),
196 return KoFilter::StupidError;
199 while (!stream.atEnd ())
204 mystr = stream.readLine ();
205 kdDebug (s_area) << "<<" << mystr << ">>" << endl;
207 if (mystr == "PICTURE") picture_rememberer = 1;
208 else if (mystr == "END PICTURE") picture_rememberer = 0;
212 else if ((mystr[0] == '.') && (picture_rememberer == 1))
216 kdDebug (s_area) << "StartPoint recognized <" << mystr << ">" << endl;
222 if (mystr.startsWith ( "LINE AT") )
225 applixGraphicsLine agLine;
229 kdDebug (s_area) << " Linie recognized: " << endl;
241 rueck = sscanf (( const char *) mystr.latin1(), "(%d,%d)",
242 &agLine.offX, &agLine.offY);
243 kdDebug (s_area) << " Offset -> x:" << agLine.offX << " y:" << agLine.offY << endl;
246 kdDebug (s_area) << "LINE tag not correkt" << endl;
247 kdDebug (s_area) << "LINE: <" << mystr << ">" << endl;
248 return KoFilter::StupidError;
256 mystr = stream.readLine ();
258 if (mystr.startsWith ( " RECOLOR ") )
260 kdDebug (s_area) << " Recolor ";
264 kdDebug (s_area) << "On" << endl;
265 agLine.reColor = true;
267 else if (mystr == "OFF")
269 kdDebug (s_area) << "Off" << endl;
270 agLine.reColor = false;
274 kdDebug (s_area) << "!!!!! Unknown RECOLOR item <" << mystr << ">" << endl;
277 else if (mystr.startsWith ( " THICKNESS ") )
279 kdDebug (s_area) << " Thickness: ";
280 mystr.remove (0, 11);
281 sscanf (( const char *) mystr.latin1(), "%d", &agLine.thickNess);
283 kdDebug (s_area) << agLine.thickNess << endl;
285 else if (mystr.startsWith ( " PNTS ") )
287 kdDebug (s_area) << " Pnts : ";
289 sscanf (( const char *) mystr.latin1(), "(%d,%d)(%d,%d)",
290 &agLine.ptX[0], &agLine.ptY[0], &agLine.ptX[1], &agLine.ptY[1]);
291 kdDebug (s_area) << agLine.ptX[0] << " " << agLine.ptY[0] << " " << agLine.ptX[1] << " " << agLine.ptY[1] << endl;
295 while ((mystr[0] != '.') && (mystr[0] != 'E'));
301 str += " <polyline arrow1=\"0\" arrow2=\"0\" >\n";
303 str += " <point x=\"" ;
304 str += TQString::number ((agLine.ptX[0] + agLine.offX)/FAKTOR);
306 str += TQString::number ((agLine.ptY[0] + agLine.offY)/FAKTOR);
310 str += " <point x=\"";
311 str += TQString::number ((agLine.ptX[1] + agLine.offX)/FAKTOR);
313 str += TQString::number ((agLine.ptY[1] + agLine.offY)/FAKTOR);
315 str += " <gobject fillstyle=\"0\" linewidth=\"1\" strokecolor=\"#000000\" strokestyle=\"1\" >\n";
316 str += " <matrix dx=\"0\" dy=\"0\" m21=\"0\" m22=\"1\" m11=\"1\" m12=\"0\" />\n";
317 str += " </gobject>\n";
321 str += " </polyline>\n";
328 if (mystr.startsWith ( "RPOL AT") )
331 applixGraphicsLine agLine;
336 kdDebug (s_area) << " RPOL recognized: " << endl;
339 rueck = sscanf (( const char *) mystr.latin1(), "(%d,%d)",
340 &agLine.offX, &agLine.offY);
341 kdDebug (s_area) << " Offset -> x:" << agLine.offX << " y:" << agLine.offY << endl;
344 kdDebug (s_area) << "RPOL tag not correkt " << endl;
345 kdDebug (s_area) << "RPOL: <" << mystr << ">" << endl;
346 return KoFilter::StupidError;
354 mystr = stream.readLine ();
356 if (mystr.startsWith ( " RECOLOR ") )
358 kdDebug (s_area) << " Recolor " ;
362 kdDebug (s_area) << "On" << endl;
363 agLine.reColor = true;
365 else if (mystr == "OFF")
367 kdDebug (s_area) << "Off" << endl;
368 agLine.reColor = false;
372 kdDebug (s_area) << "!!!!! Whats that <" << mystr << ">" << endl;
375 else if (mystr.startsWith ( " NSIDES") )
377 kdDebug (s_area) << " NSIDES: " ;
379 pos = sscanf (( const char *) mystr.latin1(), "%d", &nsides);
380 kdDebug (s_area) << nsides << "(" << pos << ")" << endl;
382 else if (mystr.startsWith ( " PNTS ") )
384 kdDebug (s_area) << " Pnts : ";
386 sscanf (( const char *) mystr.latin1(), "(%d,%d)(%d,%d)(%d,%d)(%d,%d)(%d,%d)",
387 &agLine.ptX[0], &agLine.ptY[0], &agLine.ptX[1], &agLine.ptY[1],
388 &agLine.ptX[2], &agLine.ptY[2], &agLine.ptX[3], &agLine.ptY[3],
389 &agLine.ptX[4], &agLine.ptY[4]);
390 kdDebug (s_area) << agLine.ptX[0] << " " << agLine.ptY[0] << " " <<
391 agLine.ptX[1] << " " << agLine.ptY[1] << " " <<
392 agLine.ptX[2] << " " << agLine.ptY[2] << " " <<
393 agLine.ptX[3] << " " << agLine.ptY[3] << " " <<
394 agLine.ptX[4] << " " << agLine.ptY[4] << endl;
399 while ((mystr[0] != '.') && (mystr[0] != 'E'));
408 int *x = new int[nsides];
409 int *y = new int[nsides];
410 a = agLine.ptX[2] / 2;
411 b = agLine.ptY[2] / 2;
412 for ( int i=0; i<nsides; i++)
414 x[i] = tqRound (a * cos (wink*M_PI/180));
415 y[i] = tqRound (b * sin (wink*M_PI/180));
416 wink += (360/nsides);
420 str += " <polyline arrow1=\"0\" arrow2=\"0\" >\n";
421 for ( int i=0; i<nsides; i++)
423 str += " <point x=\"" ;
424 str += TQString::number ((x[i] + agLine.offX)/FAKTOR);
426 str += TQString::number ((y[i] + agLine.offY)/FAKTOR);
430 str += " <gobject fillstyle=\"0\" linewidth=\"1\" strokecolor=\"#000000\" strokestyle=\"1\" >\n";
431 str += " <matrix dx=\"0\" dy=\"0\" m21=\"0\" m22=\"1\" m11=\"1\" m12=\"0\" />\n";
432 str += " </gobject>\n";
436 str += " </polyline>\n";
443 else if (mystr.startsWith ( "TXT AT") )
447 applixGraphicsLine agText;
449 kdDebug (s_area) << " Habe Text erkannt (keine Werte uebernommen)" << endl;
451 sscanf (( const char *) mystr.latin1(), "(%d,%d)",
452 &agText.offX, &agText.offY);
453 kdDebug (s_area) << " Offset -> x:" << agText.offX << " y:" << agText.offY << endl;
461 mystr = stream.readLine ();
463 if (mystr.startsWith ( " RECOLOR ") )
465 kdDebug (s_area) << " Recolor : ";
469 kdDebug (s_area) << "On" << endl;
470 agText.reColor = true;
472 else if (mystr == "OFF")
474 kdDebug (s_area) << "Off" << endl;
475 agText.reColor = false;
479 kdDebug (s_area) << "!!!!! Whats that <" << mystr << ">" << endl;
482 else if (mystr.startsWith ( " .STR") )
484 kdDebug (s_area) << " Textstring: ";
487 agText.str = stream.readLine ();
488 agText.str.remove (0, 3);
489 kdDebug (s_area) << agText.str;
491 else if (mystr.startsWith ( " THICKNESS ") )
493 kdDebug (s_area) << " Thickness: ";
494 mystr.remove (0, 11);
495 sscanf (( const char *) mystr.latin1(), "%d", &agText.thickNess);
496 kdDebug (s_area) << agText.thickNess << endl;
498 else if (mystr.startsWith ( " PNTS ") )
500 kdDebug (s_area) << " Pnts : ";
502 sscanf (( const char *) mystr.latin1(), "(%d,%d)(%d,%d)",
503 &agText.ptX[0], &agText.ptY[0], &agText.ptX[1], &agText.ptY[1]);
504 kdDebug (s_area) << agText.ptX[0] << " " << agText.ptY[0] << " " << agText.ptX[1] << " " << agText.ptY[1];
509 while ((mystr[0] != '.') && (mystr[0] != 'E'));
517 str += TQString::number (agText.offX);
519 str += TQString::number (agText.offY);
521 str += " <![CDATA[" + agText.str;
523 str += " <gobject fillstyle=\"0\" linewidth=\"1\" strokecolor=\"#000000\" strokestyle=\"1\" >\n";
524 str += " <matrix dx=\"119\" dy=\"310\" m21=\"0\" m22=\"1\" m11=\"1\" m12=\"0\" />\n";
525 str += " </gobject>\n";
533 else if (mystr.startsWith ( "RECT AT"))
535 applixGraphicsRect agRect;
537 kdDebug (s_area) << " Habe Rectangle erkannt " << endl;
539 rueck = sscanf (( const char *)mystr.latin1(), "(%d,%d)", &agRect.offX, &agRect.offY);
540 if (rueck < 1) kdDebug (s_area) << "Fehler im String <" << mystr.latin1() << ">" << endl;
541 kdDebug (s_area) << " Offset -> x:" << agRect.offX << " y:" << agRect.offY << endl;
549 mystr = stream.readLine ();
553 if (mystr.startsWith ( " RECOLOR ") )
555 kdDebug (s_area) <<( " Recolor : ");
558 { kdDebug (s_area) << "On" << endl; agRect.reColor = true;}
559 else if (mystr == "OFF")
560 { kdDebug (s_area) << "Off" << endl; agRect.reColor = false;}
563 kdDebug (s_area) << "!!!!! Whats that <" << mystr << ">" << endl;
567 else if (mystr.startsWith ( " BACKFILL ") )
569 kdDebug (s_area) <<( " Backfill: ");
570 mystr.remove (0, 12);
571 sscanf (( const char *)mystr.latin1(), "<%d %d %d %d %d %d %d>",
572 &agRect.bf[0], &agRect.bf[1], &agRect.bf[2],
573 &agRect.bf[3], &agRect.bf[4], &agRect.bf[5],
575 kdDebug (s_area) << agRect.bf[0] << " " << agRect.bf[1] << " " <<
576 agRect.bf[2] << " " << agRect.bf[3] << " " <<
577 agRect.bf[4] << " " << agRect.bf[5] << " " <<
582 else if (mystr.startsWith ( " LINEFILL ") )
584 kdDebug (s_area) << " Linefill: ";
585 mystr.remove (0, 12);
586 sscanf (( const char *)mystr.latin1(), "<%d %d %d %d %d %d %d>",
587 &agRect.lf[0], &agRect.lf[1], &agRect.lf[2],
588 &agRect.lf[3], &agRect.lf[4], &agRect.lf[5],
590 kdDebug (s_area) << agRect.lf[0] << " " << agRect.lf[1] << " " <<
591 agRect.lf[2] << " " << agRect.lf[3] << " " <<
592 agRect.lf[4] << " " << agRect.lf[5] << " " <<
597 else if (mystr.startsWith ( " SHADOW ") )
599 kdDebug (s_area) << " Shadow : ";
600 mystr.remove (0, 12);
601 sscanf (( const char *)mystr.latin1(), "<%d %d %d %d %d>",
602 &agRect.sh[0], &agRect.sh[1], &agRect.sh[2],
603 &agRect.sh[3], &agRect.sh[4]);
604 kdDebug (s_area) << agRect.sh[0] << " " << agRect.sh[1] << " " <<
605 agRect.sh[2] << " " << agRect.sh[3] << " " <<
609 else if (mystr.startsWith ( " PARA ") )
611 kdDebug (s_area) << " Para : ";
612 mystr.remove (0, 12);
613 sscanf (( const char *)mystr.latin1(), "<%d %d %d %d %d %d %d %d>",
614 &agRect.pa[0], &agRect.pa[1], &agRect.pa[2],
615 &agRect.pa[3], &agRect.pa[4], &agRect.pa[5],
616 &agRect.pa[6], &agRect.pa[7]);
617 kdDebug (s_area) << agRect.pa[0] << " " << agRect.pa[1] << " " <<
618 agRect.pa[2] << " " << agRect.pa[3] << " " <<
619 agRect.pa[4] << " " << agRect.pa[5] << " " <<
620 agRect.pa[6] << " " << agRect.pa[7] ;
624 else if (mystr.startsWith ( " THICKNESS ") )
626 kdDebug (s_area) << " Thickness: ";
627 mystr.remove (0, 11);
628 sscanf (( const char *) mystr.latin1(), "%d", &agRect.thickNess);
629 kdDebug (s_area) << agRect.thickNess << endl;
632 else if (mystr.startsWith ( " V_SPACE ") )
634 kdDebug (s_area) << " V_Space : ";
636 sscanf (( const char *)mystr.latin1(), "(%d %d %d)",
637 &agRect.vs[0], &agRect.vs[1], &agRect.vs[2]);
638 kdDebug (s_area) << agRect.vs[0] << " " << agRect.vs[1] << " " << agRect.vs[2];
641 else if (mystr.startsWith ( " XYRAD ") )
643 kdDebug (s_area) << " XYRad : ";
645 sscanf (( const char *)mystr.latin1(), "<%d %d>",
646 &agRect.xr[0], &agRect.xr[1]);
647 kdDebug (s_area) << agRect.xr[0] << " " << agRect.xr[1];
650 else if (mystr.startsWith ( " PNTS ") )
652 kdDebug (s_area) << " Pnts : ";
654 sscanf (( const char *)mystr.latin1(), "(%d,%d)(%d,%d)(%d,%d)(%d,%d)(%d,%d)",
655 &agRect.ptX[0], &agRect.ptY[0], &agRect.ptX[1], &agRect.ptY[1],
656 &agRect.ptX[2], &agRect.ptY[2], &agRect.ptX[3], &agRect.ptY[3],
657 &agRect.ptX[4], &agRect.ptY[4]);
658 kdDebug (s_area) << agRect.ptX[0] << " " << agRect.ptY[0] << " " <<
659 agRect.ptX[1] << " " << agRect.ptY[1] << " " <<
660 agRect.ptX[2] << " " << agRect.ptY[2] << " " <<
661 agRect.ptX[3] << " " << agRect.ptY[3] << " " <<
662 agRect.ptX[4] << " " << agRect.ptY[4] << endl;
667 while ((mystr[0] != '.') && (mystr[0] != 'E'));
673 str += " <rectangle ";
675 str += TQString::number ((agRect.offX)/FAKTOR);
677 str += TQString::number ((agRect.offY)/FAKTOR);
678 str += "\" width=\"" ;
679 str += TQString::number ((agRect.ptX[2])/FAKTOR);
680 str += "\" height=\"";
681 str += TQString::number ((agRect.ptY[2])/FAKTOR);
683 str += " <polyline arrow1=\"0\" arrow2=\"0\" >\n";
685 str += " <point x=\"" ;
686 str += TQString::number ((agRect.ptX[0] + agRect.offX)/FAKTOR) ;
688 str += TQString::number ((agRect.ptY[0] + agRect.offY)/FAKTOR) ;
691 str += " <point x=\"" ;
692 str += TQString::number ((agRect.ptX[0] + agRect.ptX[2] + agRect.offX)/FAKTOR) ;
694 str += TQString::number ((agRect.ptY[0] + agRect.offY)/FAKTOR) ;
697 str += " <point x=\"" ;
698 str += TQString::number ((agRect.ptX[0] + agRect.ptX[2] + agRect.offX)/FAKTOR) ;
700 str += TQString::number ((agRect.ptY[0] + agRect.ptY[2] + agRect.offY)/FAKTOR) ;
703 str += " <point x=\"" ;
704 str += TQString::number ((agRect.ptX[0] + agRect.offX)/FAKTOR) ;
706 str += TQString::number ((agRect.ptY[0] + agRect.ptY[2] + agRect.offY)/FAKTOR) ;
710 str += " <gobject fillstyle=\"0\" linewidth=\"1\" strokecolor=\"#000000\" strokestyle=\"1\" >\n";
711 str += " <matrix dx=\"0\" dy=\"0\" m21=\"0\" m22=\"1\" m11=\"1\" m12=\"0\" />\n";
712 str += " </gobject>\n";
713 str += " </polyline>\n";
714 str += " </rectangle>\n";
725 else if (mystr.startsWith ( "ELL AT"))
727 applixGraphicsRect agEll;
729 kdDebug (s_area) << " Habe ELL erkannt (keine Werte uebernommen " << endl;
731 sscanf (( const char *)mystr.latin1(), "(%d,%d)",
732 &agEll.offX, &agEll.offY);
733 kdDebug (s_area) << " Offset -> x:" << agEll.offX << " y:" << agEll.offY << endl;
740 mystr = stream.readLine ();
744 if (mystr.startsWith ( " RECOLOR ") )
746 kdDebug (s_area) << " Recolor: ";
750 kdDebug (s_area) << "On" << endl;
751 agEll.reColor = true;
753 else if (mystr == "OFF")
755 kdDebug (s_area) << "Off" << endl;
756 agEll.reColor = false;
760 kdDebug (s_area) << "!!!!! Whats that <" << mystr << ">" << endl;
763 else if (mystr.startsWith ( " PNTS ") )
765 kdDebug (s_area) <<( " Pnts : ");
768 sscanf (( const char *)mystr.latin1(), "(%d,%d)(%d,%d)(%d,%d)(%d,%d)(%d,%d)",
769 &agEll.ptX[0], &agEll.ptY[0], &agEll.ptX[1], &agEll.ptY[1],
770 &agEll.ptX[2], &agEll.ptY[2], &agEll.ptX[3], &agEll.ptY[3],
771 &agEll.ptX[4], &agEll.ptY[4]);
772 kdDebug (s_area) << agEll.ptX[0] << " " << agEll.ptY[0] << " " <<
773 agEll.ptX[1] << " " << agEll.ptY[1] << " " <<
774 agEll.ptX[2] << " " << agEll.ptY[2] << " " <<
775 agEll.ptX[3] << " " << agEll.ptY[3] << " " <<
776 agEll.ptX[4] << " " << agEll.ptY[4] << endl;
781 while ((mystr[0] != '.') && (mystr[0] != 'E'));
792 kdDebug (s_area) << "Unbekannt : " << mystr << endl;
802 emit sigProgress (value);
805 emit sigProgress(100);
807 str += " </layer>\n";
808 str += " </karbon>\n";
811 kdDebug (s_area) << "Text " << str.utf8() << endl;
813 KoStoreDevice* out= m_chain->storageFile( "root", KoStore::Write );
816 kdError(s_area) << "Unable to open output file!" << endl;
818 return KoFilter::StorageCreationError;
821 TQCString cstring = str.utf8();
822 out->writeBlock ( ( const char*)cstring, cstring.size() - 1 );
828#include <applixgraphicimport.moc>
|