How to visualize any SVG

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to visualize any SVG

hernanmd
Hi,

Here I am trying to visualize a SVG figure generic enough to cover
many other SVG figures. Currently I use the SVG logo:
https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg which
contains SVG paths, rect, circles and polygons.

First I tried to parse with the Athens-SVG included in Pharo 6.1:

AthensSceneView new
        scene: (AthensSVGConverter fromURL:
'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg');
        openInWindow

but fails with: "Error: cannot resolve url: http://www.w3.org/Graphics/SVG/"

So I quickly switched to Roassal SVG.

The SVG examples does not cover for example specified colors but they
are replaced with Color random.

Also using this expression it seems there is no support for "circle" type.

RTSVGEntity withAllSubclasses
        collect: [ : s | s hasSubclasses not ifTrue: [ s new type ] ]
        as: Set) reject: #isNil

with that in mind I tried to parse the SVG logo with the following
terrible script which only support paths but can read named or hex
colors

| tree view |
view := RTView new.
tree := XMLDOMParser parseURL:
'https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg'.
view := RTView new.
(tree allElementsSelect: [ :e | e isElementNamed: #path ])
    elementsDo: [ : node |
            | elem color colorAtt |
            color := (node includesAttribute: 'fill')
                ifTrue: [ Color fromHexString: (((colorAtt := node
attributeAt: 'fill') beginsWith: '#') ifTrue: [ colorAtt allButFirst ]
ifFalse: [ colorAtt ]) ]
                ifFalse: [ Color random ].
            elem := (RTSVGPath new
                        path: (node attributeAt: 'd');
                        fillColor: color;
                        scale: 1) element model: (node attributeAt: 'title').
            elem @ RTPopup.
            view add: elem ].
view inspect

However adding support for circle, rect, polygon, etc. is becoming too
complicated this way :)

Is there some other recommended way how to approach this?

Cheers,

HernĂ¡n
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev