Bug 119150 - svg file import problem (USE tag is not versatile enough)
Summary: svg file import problem (USE tag is not versatile enough)
Status: RESOLVED FIXED
Alias: None
Product: karbon
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Jan Hambrecht
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-29 00:51 UTC by Jiri Palecek
Modified: 2009-01-13 20:59 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
This is the file that fails to load (569.38 KB, text/svg)
2005-12-29 00:54 UTC, Jiri Palecek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Palecek 2005-12-29 00:51:34 UTC
Version:           1.4.2 (using KDE KDE 3.4.2)
Installed from:    Debian testing/unstable Packages
OS:                Linux

The "paris.svg" file from the gnome-games package
(contains the images of cards) opens garbled.
Comment 1 Jiri Palecek 2005-12-29 00:54:06 UTC
Created attachment 14058 [details]
This is the file that fails to load
Comment 2 Tim Beaulen 2005-12-29 12:36:29 UTC
Hello,

Thanks for the bug report.
I can confirm the problem(s).

From looking at the SVG code I can see at least one thing that we don't support yet:

<use transform="translate(576.5,430.5)" xlink:href="#sl"/>

The only use items we support yet are x, y and xlink:href
The transform item and other items like stroke are not yet supported.

They will be soon though
Comment 3 Tim Beaulen 2005-12-30 02:06:56 UTC
Wow this is a huge file.

While doing some tests while trying to correctly open this file:

Just creating and transforming all those objects with Karbon takes a long time :(

From my little debug window:
Finished parsing in 22204 milliseconds

And that's just creating and moving the objects around.

If I don't create the objects and only parse the svg data, I get:
Finished parsing in 1029 milliseconds

Conclusion:
Creating objects in Karbon is extremely expensive at the moment :(


Comment 4 Tim Beaulen 2005-12-31 16:09:18 UTC
SVN commit 492906 by beaulen:

Improved the svg import filter a little bit.

The use tag now understands the format attribute too, which means translating, scaling and rotating.

I also improved handling of the gradients (which was needed after updating the handling of the use tag).



I tried tens of svg files, from normal ones to very complex files.
I couldn't get any of those files to make Karbon crash. One made it hang though and several still don't open 100% correctly.

The file attached in bug report 119150 ( http://bugs.kde.org/show_bug.cgi?id=119150 ) Opens a little bit better too now, still not correctly though.

CCBUG:119150



 M  +376 -250  svgimport.cc  
 M  +7 -3      svgimport.h  
Comment 5 Tim Beaulen 2006-01-01 12:20:09 UTC
SVN commit 493039 by beaulen:

Don't try and reinvent the wheel.
VPath can perfectly parse the transform attribute.

This will load paris.svg from the bugreport http://bugs.kde.org/show_bug.cgi?id=119150 almost perfectly.
There does seem to be a problem with some paths though, especially the numbers on the cards.

This commit will break use cases where the style is in the use tag.
I'll fix that next.



 M  +17 -56    svgimport.cc


--- trunk/koffice/filters/karbon/svg/svgimport.cc #493038:493039
@@ -945,6 +945,9 @@

        if( !id.isEmpty() )
        {
+               addGraphicContext();
+               setupTransform( e );
+
                QString key = id.mid( 1 );

                if( !e.attribute( "x" ).isEmpty() && !e.attribute( "y" ).isEmpty() )
@@ -952,73 +955,31 @@
                        double tx = e.attribute( "x" ).toDouble();
                        double ty = e.attribute( "y" ).toDouble();

-                       m_gc.current()->matrix.reset();
                        m_gc.current()->matrix.translate(tx,ty);
                }
-               else if( !e.attribute( "transform" ).isEmpty() )
-               {
-                       QString xfrmStr = e.attribute( "transform" );
-
-                       int t = xfrmStr.find("translate");
-                       int s = xfrmStr.find("scale");
-                       int r = xfrmStr.find("rotate");

-                       m_gc.current()->matrix.reset();
-
-                       if(t > -1)
-                       {
-                               int tbegin = xfrmStr.find("(",t);
-                               int tend = xfrmStr.find(",",tbegin);
-                               double tx = xfrmStr.mid(tbegin+1,tend-tbegin-1).toDouble();
-                               tbegin = tend+1;
-                               tend = xfrmStr.find(")",tbegin);
-                               double ty = xfrmStr.mid(tbegin,tend-tbegin).toDouble();
-
-                               m_gc.current()->matrix.translate(tx,ty);
-                       }
-
-                       if(s > -1)
-                       {
-                               int sbegin = xfrmStr.find("(",s);
-                               int send = xfrmStr.find(")",sbegin);
-                               double sx = xfrmStr.mid(sbegin+1,send-sbegin-1).toDouble();
-
-                               m_gc.current()->matrix.scale(sx,-sx);
-                       }
-
-                       if(r > -1)
-                       {
-                               int rbegin = xfrmStr.find("(",r);
-                               int rend = xfrmStr.find(")",rbegin);
-                               double rx = xfrmStr.mid(rbegin+1,rend-rbegin-1).toDouble();
-
-                               m_gc.current()->matrix.rotate(rx);
-                       }
-
-               }
-
                if(m_defs.contains(key))
                {
                        QDomElement a = m_defs[key];
                        if(a.tagName() == "g" || a.tagName() == "a")
                                parseGroup( grp, a);
                        else
+                       {
                                createObject( grp, a );
-               }
-               else
-                       return;
+                               // Names are not unique, so findObject(objectname) will not always give the correct results.
+                               // Since we just created our object, it's the last one so get the last one.
+                               /*VObject *obj = 0L;
+                               if(grp)
+                                       obj = grp->objects().getLast(); //findObject(key, grp);
+                               else
+                                       obj = m_document.activeLayer()->objects().getLast();

-               // Names are not unique, so findObject(objectname) will not always give the correct results.
-               // Since we just created our object, it's the last one so get the last one.
-               VObject *obj = 0L;
-               if(grp)
-                       obj = grp->objects().getLast(); //findObject(key, grp);
-               else
-                       obj = m_document.activeLayer()->objects().getLast();
-
-               // Parse stroke and fill etc...
-               if(obj)
-                       parseStyle( obj, e );
+                               // Parse stroke and fill etc...
+                               /*if(obj)
+                                       parseStyle( obj, e );*/
+                       }
+               }
+               delete( m_gc.pop() );
        }
 }
Comment 6 Sven Langkamp 2009-01-12 03:01:53 UTC
SVN commit 909716 by langkamp:

fixed parsing of x and y attribute of the use tag

CCBUG:119150


 M  +2 -2      svgimport.cc  


WebSVN link: http://websvn.kde.org/?view=rev&revision=909716
Comment 7 Sven Langkamp 2009-01-13 20:59:20 UTC
Fixed in svn.