Script which does SVG export?

classic Classic list List threaded Threaded
11 messages Options
HJH
Reply | Threaded
Open this post in threaded view
|

Script which does SVG export?

HJH
Hello

Is there a script which may be used as a start for doing SVG [1][2] export

--Hannes


[1] https://www.w3.org/Graphics/SVG/
[2] https://developer.mozilla.org/en-US/docs/Web/SVG
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

Hilaire Fernandes
Administrator
There are works done by a student.
http://smalltalkhub.com/#!/~YannLesage

Did not get the time to review it yet.
You are welcome to experiment it.

Hilaire

Le 08/09/2018 à 09:44, HJH [via Dr. Geo Forum] a écrit :

> Hello
>
> Is there a script which may be used as a start for doing SVG [1][2]
> export
>
> --Hannes
>
>
> [1] https://www.w3.org/Graphics/SVG/
> [2] https://developer.mozilla.org/en-US/docs/Web/SVG


Was this message helpful?
Tell us!
HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
The SVG exporter is in a very early stage. No DrGeo specific code yet.

drSVG export status

However during the construction of DrGeo geometric objects it seems to be straightforward to also create an SVG representation.

This needs an understanding how the construction of geometric objects works in DrGeo (description how the factory works).

HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
An idea could be to do it in the

    #finalizeXYZ:

methods. Or to have instead of

DrGeoCanvas(DrGeoSketch)>>postProcessing: aWrappedItem
        "Called after each item creation command, return a wrapped costume "
        ^ aWrappedItem


a new implementation

DrGeoCanvas(DrGeoSketch)>>postProcessing: aWrappedItem
        "Called after each item creation command, return a wrapped costume "

        aWrappedItem createSVG.
        ^ aWrappedItem


This needs more analysis and tracing how the geometry object construction works.

Possible hooks for SVG export


HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
If I take the example from http://forum.drgeo.eu/DrGeoII-object-model-Factory-DrGMathItemFactory-td4025481.html

It is

    | c ptM circle |
    c := DrGeoSketch minimal.
    ptM := c point: 0@0.
    ptM name: 'M'.
    circle := c circleCenter: ptM radius: 5.

And I change #postProcessing: to

DrGeoSketch>>
postProcessing: aWrappedItem
        "Called after each item creation command, return a wrapped costume "
        Transcript show: aWrappedItem printString.
        Transcript cr.
        ^ aWrappedItem


I get on the transcript window as result

    a DrGWrappedPoint
    a DrGWrappedValue
    a DrGWrappedFilledCurve

It seems that this mechanism could be used for generating an SVG representation of the constructed sketch.


HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
Alternatively a new presenter called

    DrGeoPresenterSVG

could be introduced.

Currently DrGeoSketch(DrGeoCanvas) has

    exportToBitmap: aFilename
    "Export to a PNG file"

    drgeo presenter
            exportToBitmap: aFilename asFileReference ensureDelete binaryWriteStream.


A method exportToSVG: could be added

    exportToSVG: aFilename
    "Export to a SVG file"

    drgeo presenterSVG
            exportToSVG: aFilename asFileReference ensureDelete writeStream.


This would make it necessary that the presenterSVG object traverses the geometry model. In the case in the previous post this is not necessary as it is done during construction. But not all information might be available at that time.

Probably worth to do some investigations by using some examples and compare the two cases.

HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
Geometry model access for SVG export could be done with something like

factory := c domain factory.
1 to: factory pool size do: [:n | Transcript show: (factory pool at: n) asSVG ;cr].     "(demo)"

But as you write in
http://forum.drgeo.eu/How-do-I-query-the-geometry-model-td4025479.html
the visit might better work by going  through the costume objects.



Factory access for SVG export
HJH
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

HJH
This post was updated on .

It seems that the costumes collection

c app costumes

is constructed in parallel to

c app domain factory pool

There is a need to find out where the information is kept if a geometric object is hidden or not.

But generally the costume objects seem to be a place where to put the svg generation code.

asSVGstring implemented in Costume objects Example script adapted from http://forum.drgeo.eu/Euclid-book-IV-proposition-15-td4025456.html See generated SVG example below (work in progress)

| c ptA ptB ptC
circleA circleB
ptD ptF ptG ptH
segAB rayBA rayFA
 lineAC |

 c := DrGeoCanvas minimal.
 c scale: 100.

 "Given is a segment AB"
 ptA := c point: -1@0.
 ptA name: 'A'.

 ptB := c point: 1@0.
 ptB name: 'B'.

 segAB := c segment: ptA to: ptB.

 "Use two circles to get point C"
 circleA := c circleCenter: ptA to: ptB.
 circleB := c circleCenter: ptB to: ptA.

 ptC := c intersectionOf: circleB and: circleA.
 ptC name: 'C'.


"second intersection point of the circles"
 ptF := c altIntersectionOf: circleB and: circleA.
 ptF name: 'F'.



 "-- get additional points D, E, F and H with hidden helper lines"
 rayBA := c ray: ptB to: ptA.
 ptD := c altIntersectionOf: circleA  and: rayBA.
 ptD name: 'D'.
 rayBA hide.


 lineAC := c line: ptA to: ptC.
 ptG := c intersectionOf: circleA  and: lineAC.
 ptG name: 'G'.
 lineAC hide.


 rayFA := c ray: ptF to: ptA.
 ptH := c altIntersectionOf: circleA  and: rayFA.
 ptH name: 'H'.
 rayFA hide.


 c segment: ptB to: ptC.
 c segment: ptC to: ptH.
 c segment: ptH to: ptD.
 c segment: ptD to: ptG.
 c segment: ptG to: ptF.
 c segment: ptF to: ptB.

 c segment: ptC to: ptG.
 c segment: ptH to: ptF.
 c segment: ptD to: ptB.


 "circleB hide." 

c view area extent: 700@700.
c view area color: Color white.
c view area openInWorld.

SREObjectInspector inspect: c app.

"---------------------------------------------------------------"
" the SVG export part, needs to be put in an object later "
"---------------------------------------------------------------"

Transcript clear.
Transcript show: '<svg width="700" height="700" >'; cr.
Transcript show: '<g  transform="translate(350 350)">';cr.	
1 to: c app costumes size do: [:n | Transcript show: (c app costumes at: n) asSVGstring;cr].

Transcript show: '</g></svg>';cr.



--Hannes
<svg width="700" height="700" >
<g  transform="translate(350 350)">
<circle cx="-100.0" cy="0.0" r="5.0" fill="black" />
<circle cx="100.0" cy="0.0" r="5.0" fill="black" />
<line x1="-100.0" y1="0.0" x2="100.0" y2="0.0" stroke="red" />
<circle cx="-100.0" cy="0.0" r="200" fill="none" stroke="black" />
<circle cx="100.0" cy="0.0" r="200" fill="none" stroke="black" />
<circle cx="0.0" cy="173.21" r="5.0" fill="black" />
<circle cx="0.0" cy="-173.21" r="5.0" fill="black" />
<line x1="100.0" y1="0.0" x2="-200.0" y2="0.0" stroke="black" />
<circle cx="-300.0" cy="0.0" r="5.0" fill="black" />
<line x1="-100.0" y1="0.0" x2="100.0" y2="0.0" stroke="black" />
<circle cx="-200.0" cy="-173.21" r="5.0" fill="black" />
<line x1="0.0" y1="-173.21" x2="-100.0" y2="-173.21" stroke="black" />
<circle cx="-200.0" cy="173.21" r="5.0" fill="black" />
<line x1="100.0" y1="0.0" x2="0.0" y2="173.21" stroke="red" />
<line x1="0.0" y1="173.21" x2="-200.0" y2="173.21" stroke="red" />
<line x1="-200.0" y1="173.21" x2="-300.0" y2="0.0" stroke="red" />
<line x1="-300.0" y1="0.0" x2="-200.0" y2="-173.21" stroke="red" />
<line x1="-200.0" y1="-173.21" x2="0.0" y2="-173.21" stroke="red" />
<line x1="0.0" y1="-173.21" x2="100.0" y2="0.0" stroke="red" />
<line x1="0.0" y1="173.21" x2="-200.0" y2="-173.21" stroke="red" />
<line x1="-200.0" y1="173.21" x2="0.0" y2="-173.21" stroke="red" />
<line x1="-300.0" y1="0.0" x2="100.0" y2="0.0" stroke="red" />
</g></svg>
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

Hliaire Fernandes
Administrator
In reply to this post by HJH
There is also this package to check out:

http://smalltalkhub.com/#!/~YannLesage/DrGeoVisitor
Reply | Threaded
Open this post in threaded view
|

Re: Script which does SVG export

Hliaire Fernandes
Administrator
In reply to this post by HJH
The costume instances are the views and kept separately in the DrGeo costumes instance.

Each costume knows about its model (the math item), its morph in the Morphic representation, and its style.

Hilaire