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


Here I am trying to visualize a SVG figure generic enough to cover
many other SVG figures. Currently I use the SVG logo: 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:

but fails with: "Error: cannot resolve url:"

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

| tree view |
view := RTView new.
tree := XMLDOMParser parseURL:
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?


Moose-dev mailing list
[hidden email]